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 /*****************************************************************************/
47 /*****************************************************************************/
49 /*****************************************************************************/
53 /*****************************************************************************/
55 /*****************************************************************************/
59 CodeEntry* NewCodeEntry (const OPCDesc* D, am_t AM)
60 /* Create a new code entry, initialize and return it */
63 CodeEntry* E = xmalloc (sizeof (CodeEntry));
65 /* Initialize the fields */
68 E->Size = GetInsnSize (E->OPC, E->AM);
74 InitCollection (&E->Labels);
76 /* Return the initialized struct */
82 void FreeCodeEntry (CodeEntry* E)
83 /* Free the given code entry */
85 /* ## Free the string argument if we have one */
87 /* Cleanup the collection */
88 DoneCollection (&E->Labels);
96 void OutputCodeEntry (FILE* F, const CodeEntry* E)
97 /* Output the code entry to a file */
101 /* If we have a label, print that */
102 unsigned LabelCount = CollCount (&E->Labels);
104 for (I = 0; I < LabelCount; ++I) {
105 OutputCodeLabel (F, CollConstAt (&E->Labels, I));
108 /* Get the opcode description */
109 D = GetOPCDesc (E->OPC);
111 /* Print the mnemonic */
112 fprintf (F, "\t%s", D->Mnemo);
114 /* Print the operand */
118 /* implicit + accumulator */
123 fprintf (F, "\t#%s", E->Arg.Expr);
129 /* zeropage, absolute and branch */
130 fprintf (F, "\t%s", E->Arg.Expr);
135 /* zeropage,X and absolute,X */
136 fprintf (F, "\t%s,x", E->Arg.Expr);
141 fprintf (F, "\t%s,y", E->Arg.Expr);
146 fprintf (F, "\t(%s,x)", E->Arg.Expr);
151 fprintf (F, "\t(%s),y", E->Arg.Expr);
156 fprintf (F, "\t(%s)", E->Arg.Expr);
160 Internal ("Invalid addressing mode");
164 /* Terminate the line */