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 /*****************************************************************************/
51 /*****************************************************************************/
53 /*****************************************************************************/
57 /*****************************************************************************/
59 /*****************************************************************************/
63 CodeEntry* NewCodeEntry (const OPCDesc* D, am_t AM, CodeLabel* JumpTo)
64 /* Create a new code entry, initialize and return it */
67 CodeEntry* E = xmalloc (sizeof (CodeEntry));
69 /* Initialize the fields */
72 E->Size = GetInsnSize (E->OPC, E->AM);
76 E->Usage = D->Info & (CI_MASK_USE | CI_MASK_CHG);
78 InitCollection (&E->Labels);
80 /* If we have a label given, add this entry to the label */
82 CollAppend (&JumpTo->JumpFrom, E);
85 /* Return the initialized struct */
91 void FreeCodeEntry (CodeEntry* E)
92 /* Free the given code entry */
94 /* ## Free the string argument if we have one */
96 /* Cleanup the collection */
97 DoneCollection (&E->Labels);
105 void OutputCodeEntry (FILE* F, const CodeEntry* E)
106 /* Output the code entry to a file */
110 /* If we have a label, print that */
111 unsigned LabelCount = CollCount (&E->Labels);
113 for (I = 0; I < LabelCount; ++I) {
114 OutputCodeLabel (F, CollConstAt (&E->Labels, I));
117 /* Get the opcode description */
118 D = GetOPCDesc (E->OPC);
120 /* Print the mnemonic */
121 fprintf (F, "\t%s", D->Mnemo);
123 /* Print the operand */
137 fprintf (F, "\t#%s", E->Arg.Expr);
142 /* zeropage and absolute */
143 fprintf (F, "\t%s", E->Arg.Expr);
148 /* zeropage,X and absolute,X */
149 fprintf (F, "\t%s,x", E->Arg.Expr);
154 fprintf (F, "\t%s,y", E->Arg.Expr);
159 fprintf (F, "\t(%s,x)", E->Arg.Expr);
164 fprintf (F, "\t(%s),y", E->Arg.Expr);
169 fprintf (F, "\t(%s)", E->Arg.Expr);
174 CHECK (E->JumpTo != 0);
175 fprintf (F, "\t%s", E->JumpTo->Name);
179 Internal ("Invalid addressing mode");
183 /* Terminate the line */