1 /*****************************************************************************/
5 /* Code segment entry */
9 /* (C) 2001 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
52 /*****************************************************************************/
54 /*****************************************************************************/
58 /*****************************************************************************/
60 /*****************************************************************************/
64 CodeEntry* NewCodeEntry (const OPCDesc* D, am_t AM, CodeLabel* JumpTo)
65 /* Create a new code entry, initialize and return it */
68 CodeEntry* E = xmalloc (sizeof (CodeEntry));
70 /* Initialize the fields */
73 E->Size = GetInsnSize (E->OPC, E->AM);
78 E->Info = D->Info | GetAMUseInfo (AM);
80 InitCollection (&E->Labels);
82 /* If we have a label given, add this entry to the label */
84 CollAppend (&JumpTo->JumpFrom, E);
87 /* Return the initialized struct */
93 void FreeCodeEntry (CodeEntry* E)
94 /* Free the given code entry */
96 /* Free the string argument if we have one */
99 /* Cleanup the collection */
100 DoneCollection (&E->Labels);
108 int CodeEntryHasLabel (const CodeEntry* E)
109 /* Check if the given code entry has labels attached */
111 return (CollCount (&E->Labels) > 0);
116 void OutputCodeEntry (FILE* F, const CodeEntry* E)
117 /* Output the code entry to a file */
122 /* If we have a label, print that */
123 unsigned LabelCount = CollCount (&E->Labels);
125 for (I = 0; I < LabelCount; ++I) {
126 OutputCodeLabel (F, CollConstAt (&E->Labels, I));
129 /* Get the opcode description */
130 D = GetOPCDesc (E->OPC);
132 /* Print the mnemonic */
133 Chars = fprintf (F, "\t%s", D->Mnemo);
135 /* Print the operand */
144 Chars += fprintf (F, "%*sa", 9-Chars, "");
149 Chars += fprintf (F, "%*s#%s", 9-Chars, "", E->Arg);
154 /* zeropage and absolute */
155 Chars += fprintf (F, "%*s%s", 9-Chars, "", E->Arg);
160 /* zeropage,X and absolute,X */
161 Chars += fprintf (F, "%*s%s,x", 9-Chars, "", E->Arg);
166 Chars += fprintf (F, "%*s%s,y", 9-Chars, "", E->Arg);
171 Chars += fprintf (F, "%*s(%s,x)", 9-Chars, "", E->Arg);
176 Chars += fprintf (F, "%*s(%s),y", 9-Chars, "", E->Arg);
181 Chars += fprintf (F, "%*s(%s)", 9-Chars, "", E->Arg);
186 CHECK (E->JumpTo != 0);
187 Chars += fprintf (F, "%*s%s", 9-Chars, "", E->JumpTo->Name);
191 Internal ("Invalid addressing mode");
195 /* Print usage info if requested by the debugging flag */
198 "%*s; USE: %c%c%c CHG: %c%c%c",
200 (E->Info & CI_USE_A)? 'A' : '_',
201 (E->Info & CI_USE_X)? 'X' : '_',
202 (E->Info & CI_USE_Y)? 'Y' : '_',
203 (E->Info & CI_CHG_A)? 'A' : '_',
204 (E->Info & CI_CHG_X)? 'X' : '_',
205 (E->Info & CI_CHG_Y)? 'Y' : '_');
208 /* Terminate the line */