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 /*****************************************************************************/
53 /*****************************************************************************/
55 /*****************************************************************************/
59 /*****************************************************************************/
61 /*****************************************************************************/
65 CodeEntry* NewCodeEntry (const OPCDesc* D, am_t AM, const char* Arg, CodeLabel* JumpTo)
66 /* Create a new code entry, initialize and return it */
69 CodeEntry* E = xmalloc (sizeof (CodeEntry));
71 /* Initialize the fields */
74 E->Size = GetInsnSize (E->OPC, E->AM);
76 E->Arg = (Arg && Arg[0] != '\0')? xstrdup (Arg) : 0;
80 if (E->OPC == OPC_JSR && E->Arg) {
81 /* A subroutine call */
82 E->Info |= GetFuncInfo (E->Arg);
84 /* Some other instruction */
85 E->Info |= GetAMUseInfo (AM);
88 InitCollection (&E->Labels);
90 /* If we have a label given, add this entry to the label */
92 CollAppend (&JumpTo->JumpFrom, E);
95 /* Return the initialized struct */
101 void FreeCodeEntry (CodeEntry* E)
102 /* Free the given code entry */
104 /* Free the string argument if we have one */
107 /* Cleanup the collection */
108 DoneCollection (&E->Labels);
116 int CodeEntryHasLabel (const CodeEntry* E)
117 /* Check if the given code entry has labels attached */
119 return (CollCount (&E->Labels) > 0);
124 void OutputCodeEntry (FILE* F, const CodeEntry* E)
125 /* Output the code entry to a file */
130 /* If we have a label, print that */
131 unsigned LabelCount = CollCount (&E->Labels);
133 for (I = 0; I < LabelCount; ++I) {
134 OutputCodeLabel (F, CollConstAt (&E->Labels, I));
137 /* Get the opcode description */
138 D = GetOPCDesc (E->OPC);
140 /* Print the mnemonic */
141 Chars = fprintf (F, "\t%s", D->Mnemo);
143 /* Print the operand */
152 Chars += fprintf (F, "%*sa", 9-Chars, "");
157 Chars += fprintf (F, "%*s#%s", 9-Chars, "", E->Arg);
162 /* zeropage and absolute */
163 Chars += fprintf (F, "%*s%s", 9-Chars, "", E->Arg);
168 /* zeropage,X and absolute,X */
169 Chars += fprintf (F, "%*s%s,x", 9-Chars, "", E->Arg);
174 Chars += fprintf (F, "%*s%s,y", 9-Chars, "", E->Arg);
179 Chars += fprintf (F, "%*s(%s,x)", 9-Chars, "", E->Arg);
184 Chars += fprintf (F, "%*s(%s),y", 9-Chars, "", E->Arg);
189 Chars += fprintf (F, "%*s(%s)", 9-Chars, "", E->Arg);
194 CHECK (E->JumpTo != 0);
195 Chars += fprintf (F, "%*s%s", 9-Chars, "", E->JumpTo->Name);
199 Internal ("Invalid addressing mode");
203 /* Print usage info if requested by the debugging flag */
206 "%*s; USE: %c%c%c CHG: %c%c%c",
208 (E->Info & CI_USE_A)? 'A' : '_',
209 (E->Info & CI_USE_X)? 'X' : '_',
210 (E->Info & CI_USE_Y)? 'Y' : '_',
211 (E->Info & CI_CHG_A)? 'A' : '_',
212 (E->Info & CI_CHG_X)? 'X' : '_',
213 (E->Info & CI_CHG_Y)? 'Y' : '_');
216 /* Terminate the line */