1 /*****************************************************************************/
5 /* Code segment entry */
9 /* (C) 2001-2003 Ullrich von Bassewitz */
10 /* Römerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
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 /*****************************************************************************/
42 #include "debugflag.h"
56 /*****************************************************************************/
58 /*****************************************************************************/
63 static char EmptyArg[] = "";
67 /*****************************************************************************/
68 /* Helper functions */
69 /*****************************************************************************/
73 static void FreeArg (char* Arg)
74 /* Free a code entry argument */
76 if (Arg != EmptyArg) {
83 static char* GetArgCopy (const char* Arg)
84 /* Create an argument copy for assignment */
86 if (Arg && Arg[0] != '\0') {
90 /* Use the empty argument string */
97 static int NumArg (const char* Arg, unsigned long* Num)
98 /* If the given argument is numerical, convert it and return true. Otherwise
99 * set Num to zero and return false.
105 /* Determine the base */
110 } else if (*Arg == '%') {
115 /* Convert the value. strtol is not exactly what we want here, but it's
116 * cheap and may be replaced by something fancier later.
118 Val = strtoul (Arg, &End, Base);
120 /* Check if the conversion was successful */
123 /* Could not convert */
138 static void SetUseChgInfo (CodeEntry* E, const OPCDesc* D)
139 /* Set the Use and Chg in E */
143 /* If this is a subroutine call, or a jump to an external function,
144 * lookup the information about this function and use it. The jump itself
145 * does not change any registers, so we don't need to use the data from D.
147 if ((E->Info & (OF_BRA | OF_CALL)) != 0 && E->JumpTo == 0) {
148 /* A subroutine call or jump to external symbol (function exit) */
149 GetFuncInfo (E->Arg, &E->Use, &E->Chg);
151 /* Some other instruction. Use the values from the opcode description
152 * plus addressing mode info.
154 E->Use = D->Use | GetAMUseInfo (E->AM);
157 /* Check for special zero page registers used */
161 if (E->OPC == OP65_ASL || E->OPC == OP65_DEC ||
162 E->OPC == OP65_INC || E->OPC == OP65_LSR ||
163 E->OPC == OP65_ROL || E->OPC == OP65_ROR) {
164 /* A is changed by these insns */
171 /* Be conservative: */
175 Info = GetZPInfo (E->Arg);
176 if (Info && Info->ByteUse != REG_NONE) {
177 if (E->OPC == OP65_ASL || E->OPC == OP65_DEC ||
178 E->OPC == OP65_INC || E->OPC == OP65_LSR ||
179 E->OPC == OP65_ROL || E->OPC == OP65_ROR ||
180 E->OPC == OP65_TRB || E->OPC == OP65_TSB) {
181 /* The zp loc is both, input and output */
182 E->Chg |= Info->ByteUse;
183 E->Use |= Info->ByteUse;
184 } else if ((E->Info & OF_STORE) != 0) {
186 E->Chg |= Info->ByteUse;
189 E->Use |= Info->ByteUse;
197 Info = GetZPInfo (E->Arg);
198 if (Info && Info->ByteUse != REG_NONE) {
199 /* These addressing modes will never change the zp loc */
200 E->Use |= Info->WordUse;
205 /* Keep gcc silent */
213 /*****************************************************************************/
215 /*****************************************************************************/
219 const char* MakeHexArg (unsigned Num)
220 /* Convert Num into a string in the form $XY, suitable for passing it as an
221 * argument to NewCodeEntry, and return a pointer to the string.
222 * BEWARE: The function returns a pointer to a static buffer, so the value is
223 * gone if you call it twice (and apart from that it's not thread and signal
228 xsprintf (Buf, sizeof (Buf), "$%02X", (unsigned char) Num);
234 CodeEntry* NewCodeEntry (opc_t OPC, am_t AM, const char* Arg,
235 CodeLabel* JumpTo, LineInfo* LI)
236 /* Create a new code entry, initialize and return it */
238 /* Get the opcode description */
239 const OPCDesc* D = GetOPCDesc (OPC);
241 /* Allocate memory */
242 CodeEntry* E = xmalloc (sizeof (CodeEntry));
244 /* Initialize the fields */
247 E->Size = GetInsnSize (E->OPC, E->AM);
248 E->Arg = GetArgCopy (Arg);
249 E->Flags = NumArg (E->Arg, &E->Num)? CEF_NUMARG : 0; /* Needs E->Arg */
252 E->LI = UseLineInfo (LI);
254 SetUseChgInfo (E, D);
255 InitCollection (&E->Labels);
257 /* If we have a label given, add this entry to the label */
259 CollAppend (&JumpTo->JumpFrom, E);
262 /* Return the initialized struct */
268 void FreeCodeEntry (CodeEntry* E)
269 /* Free the given code entry */
271 /* Free the string argument if we have one */
274 /* Cleanup the collection */
275 DoneCollection (&E->Labels);
277 /* Release the line info */
278 ReleaseLineInfo (E->LI);
280 /* Delete the register info */
289 void CE_ReplaceOPC (CodeEntry* E, opc_t OPC)
290 /* Replace the opcode of the instruction. This will also replace related info,
291 * Size, Use and Chg, but it will NOT update any arguments or labels.
294 /* Get the opcode descriptor */
295 const OPCDesc* D = GetOPCDesc (OPC);
297 /* Replace the opcode */
300 E->Size = GetInsnSize (E->OPC, E->AM);
301 SetUseChgInfo (E, D);
306 int CodeEntriesAreEqual (const CodeEntry* E1, const CodeEntry* E2)
307 /* Check if both code entries are equal */
309 return E1->OPC == E2->OPC && E1->AM == E2->AM && strcmp (E1->Arg, E2->Arg) == 0;
314 void CE_AttachLabel (CodeEntry* E, CodeLabel* L)
315 /* Attach the label to the entry */
317 /* Add it to the entries label list */
318 CollAppend (&E->Labels, L);
320 /* Tell the label about it's owner */
326 void CE_MoveLabel (CodeLabel* L, CodeEntry* E)
327 /* Move the code label L from it's former owner to the code entry E. */
329 /* Delete the label from the owner */
330 CollDeleteItem (&L->Owner->Labels, L);
332 /* Set the new owner */
333 CollAppend (&E->Labels, L);
339 void CE_SetNumArg (CodeEntry* E, long Num)
340 /* Set a new numeric argument for the given code entry that must already
341 * have a numeric argument.
346 /* Check that the entry has a numerical argument */
347 CHECK (E->Flags & CEF_NUMARG);
349 /* Make the new argument string */
352 xsprintf (Buf, sizeof (Buf), "$%02X", (unsigned) Num);
353 } else if (E->Size == 3) {
355 xsprintf (Buf, sizeof (Buf), "$%04X", (unsigned) Num);
357 Internal ("Invalid instruction size in CE_SetNumArg");
360 /* Free the old argument */
363 /* Assign the new one */
364 E->Arg = GetArgCopy (Buf);
366 /* Use the new numerical value */
372 int CE_KnownImm (const CodeEntry* E)
373 /* Return true if the argument of E is a known immediate value */
375 return (E->AM == AM65_IMM && (E->Flags & CEF_NUMARG) != 0);
380 int CE_UseLoadFlags (const CodeEntry* E)
381 /* Return true if the instruction uses any flags that are set by a load of
382 * a register (N and Z).
385 /* A branch will use the flags */
386 if (E->Info & OF_FBRA) {
390 /* Call of a boolean transformer routine will also use the flags */
391 if (E->OPC == OP65_JSR) {
392 /* Get the condition that is evaluated and check it */
393 switch (FindBoolCmpCond (E->Arg)) {
402 /* Will use the N or Z flags */
406 case CMP_UGE: /* Uses only carry */
407 case CMP_ULT: /* Dito */
408 default: /* No bool transformer subroutine */
419 void CE_FreeRegInfo (CodeEntry* E)
420 /* Free an existing register info struct */
430 void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs)
431 /* Generate register info for this instruction. If an old info exists, it is
435 /* Pointers to the register contents */
439 /* Function register usage */
440 unsigned short Use, Chg;
442 /* If we don't have a register info struct, allocate one. */
444 E->RI = NewRegInfo (InputRegs);
447 E->RI->In = *InputRegs;
449 RC_Invalidate (&E->RI->In);
451 E->RI->Out2 = E->RI->Out = E->RI->In;
454 /* Get pointers to the register contents */
458 /* Handle the different instructions */
462 /* We don't know the value of the carry, so the result is
465 Out->RegA = UNKNOWN_REGVAL;
469 if (RegValIsKnown (In->RegA)) {
470 if (CE_KnownImm (E)) {
471 Out->RegA = In->RegA & (short) E->Num;
472 } else if (E->AM == AM65_ZP) {
473 switch (GetKnownReg (E->Use & REG_ZP, In)) {
475 Out->RegA = In->RegA & In->Tmp1;
478 Out->RegA = In->RegA & In->Ptr1Lo;
481 Out->RegA = In->RegA & In->Ptr1Hi;
484 Out->RegA = In->RegA & In->SRegLo;
487 Out->RegA = In->RegA & In->SRegHi;
490 Out->RegA = UNKNOWN_REGVAL;
494 Out->RegA = UNKNOWN_REGVAL;
500 if (E->AM == AM65_ACC && RegValIsKnown (In->RegA)) {
501 Out->RegA = (In->RegA << 1) & 0xFF;
502 } else if (E->AM == AM65_ZP) {
503 switch (GetKnownReg (E->Chg & REG_ZP, In)) {
505 Out->Tmp1 = (In->Tmp1 << 1) & 0xFF;
508 Out->Ptr1Lo = (In->Ptr1Lo << 1) & 0xFF;
511 Out->Ptr1Hi = (In->Ptr1Hi << 1) & 0xFF;
514 Out->SRegLo = (In->SRegLo << 1) & 0xFF;
517 Out->SRegHi = (In->SRegHi << 1) & 0xFF;
520 } else if (E->AM == AM65_ZPX) {
521 /* Invalidates all ZP registers */
522 RC_InvalidateZP (Out);
581 if (RegValIsKnown (In->RegA)) {
582 Out->RegA = (In->RegA - 1) & 0xFF;
587 if (E->AM == AM65_ACC && RegValIsKnown (In->RegA)) {
588 Out->RegA = (In->RegA - 1) & 0xFF;
589 } else if (E->AM == AM65_ZP) {
590 switch (GetKnownReg (E->Chg & REG_ZP, In)) {
592 Out->Tmp1 = (In->Tmp1 - 1) & 0xFF;
595 Out->Ptr1Lo = (In->Ptr1Lo - 1) & 0xFF;
598 Out->Ptr1Hi = (In->Ptr1Hi - 1) & 0xFF;
601 Out->SRegLo = (In->SRegLo - 1) & 0xFF;
604 Out->SRegHi = (In->SRegHi - 1) & 0xFF;
607 } else if (E->AM == AM65_ZPX) {
608 /* Invalidates all ZP registers */
609 RC_InvalidateZP (Out);
614 if (RegValIsKnown (In->RegX)) {
615 Out->RegX = (In->RegX - 1) & 0xFF;
620 if (RegValIsKnown (In->RegY)) {
621 Out->RegY = (In->RegY - 1) & 0xFF;
626 if (RegValIsKnown (In->RegA)) {
627 if (CE_KnownImm (E)) {
628 Out->RegA = In->RegA ^ (short) E->Num;
629 } else if (E->AM == AM65_ZP) {
630 switch (GetKnownReg (E->Use & REG_ZP, In)) {
632 Out->RegA = In->RegA ^ In->Tmp1;
635 Out->RegA = In->RegA ^ In->Ptr1Lo;
638 Out->RegA = In->RegA ^ In->Ptr1Hi;
641 Out->RegA = In->RegA ^ In->SRegLo;
644 Out->RegA = In->RegA ^ In->SRegHi;
647 Out->RegA = UNKNOWN_REGVAL;
651 Out->RegA = UNKNOWN_REGVAL;
657 if (RegValIsKnown (In->RegA)) {
658 Out->RegA = (In->RegA + 1) & 0xFF;
663 if (E->AM == AM65_ACC && RegValIsKnown (In->RegA)) {
664 Out->RegA = (In->RegA + 1) & 0xFF;
665 } else if (E->AM == AM65_ZP) {
666 switch (GetKnownReg (E->Chg & REG_ZP, In)) {
668 Out->Tmp1 = (In->Tmp1 + 1) & 0xFF;
671 Out->Ptr1Lo = (In->Ptr1Lo + 1) & 0xFF;
674 Out->Ptr1Hi = (In->Ptr1Hi + 1) & 0xFF;
677 Out->SRegLo = (In->SRegLo + 1) & 0xFF;
680 Out->SRegHi = (In->SRegHi + 1) & 0xFF;
683 } else if (E->AM == AM65_ZPX) {
684 /* Invalidates all ZP registers */
685 RC_InvalidateZP (Out);
690 if (RegValIsKnown (In->RegX)) {
691 Out->RegX = (In->RegX + 1) & 0xFF;
696 if (RegValIsKnown (In->RegY)) {
697 Out->RegY = (In->RegY + 1) & 0xFF;
723 /* Get the code info for the function */
724 GetFuncInfo (E->Arg, &Use, &Chg);
726 Out->RegA = UNKNOWN_REGVAL;
729 Out->RegX = UNKNOWN_REGVAL;
732 Out->RegY = UNKNOWN_REGVAL;
734 if (Chg & REG_TMP1) {
735 Out->Tmp1 = UNKNOWN_REGVAL;
737 if (Chg & REG_PTR1_LO) {
738 Out->Ptr1Lo = UNKNOWN_REGVAL;
740 if (Chg & REG_PTR1_HI) {
741 Out->Ptr1Hi = UNKNOWN_REGVAL;
743 if (Chg & REG_SREG_LO) {
744 Out->SRegLo = UNKNOWN_REGVAL;
746 if (Chg & REG_SREG_HI) {
747 Out->SRegHi = UNKNOWN_REGVAL;
749 /* ## FIXME: Quick hack for some known functions: */
750 if (strcmp (E->Arg, "tosandax") == 0) {
757 } else if (strcmp (E->Arg, "tosorax") == 0) {
758 if (In->RegA == 0xFF) {
761 if (In->RegX == 0xFF) {
764 } else if (FindBoolCmpCond (E->Arg) != CMP_INV) {
776 if (CE_KnownImm (E)) {
777 Out->RegA = (unsigned char) E->Num;
778 } else if (E->AM == AM65_ZP) {
779 switch (GetKnownReg (E->Use & REG_ZP, In)) {
781 Out->RegA = In->Tmp1;
784 Out->RegA = In->Ptr1Lo;
787 Out->RegA = In->Ptr1Hi;
790 Out->RegA = In->SRegLo;
793 Out->RegA = In->SRegHi;
796 Out->RegA = UNKNOWN_REGVAL;
800 /* A is now unknown */
801 Out->RegA = UNKNOWN_REGVAL;
806 if (CE_KnownImm (E)) {
807 Out->RegX = (unsigned char) E->Num;
808 } else if (E->AM == AM65_ZP) {
809 switch (GetKnownReg (E->Use & REG_ZP, In)) {
811 Out->RegX = In->Tmp1;
814 Out->RegX = In->Ptr1Lo;
817 Out->RegX = In->Ptr1Hi;
820 Out->RegX = In->SRegLo;
823 Out->RegX = In->SRegHi;
826 Out->RegX = UNKNOWN_REGVAL;
830 /* X is now unknown */
831 Out->RegX = UNKNOWN_REGVAL;
836 if (CE_KnownImm (E)) {
837 Out->RegY = (unsigned char) E->Num;
838 } else if (E->AM == AM65_ZP) {
839 switch (GetKnownReg (E->Use & REG_ZP, In)) {
841 Out->RegY = In->Tmp1;
844 Out->RegY = In->Ptr1Lo;
847 Out->RegY = In->Ptr1Hi;
850 Out->RegY = In->SRegLo;
853 Out->RegY = In->SRegHi;
856 Out->RegY = UNKNOWN_REGVAL;
860 /* Y is now unknown */
861 Out->RegY = UNKNOWN_REGVAL;
866 if (E->AM == AM65_ACC && RegValIsKnown (In->RegA)) {
867 Out->RegA = (In->RegA >> 1) & 0xFF;
868 } else if (E->AM == AM65_ZP) {
869 switch (GetKnownReg (E->Chg & REG_ZP, In)) {
871 Out->Tmp1 = (In->Tmp1 >> 1) & 0xFF;
874 Out->Ptr1Lo = (In->Ptr1Lo >> 1) & 0xFF;
877 Out->Ptr1Hi = (In->Ptr1Hi >> 1) & 0xFF;
880 Out->SRegLo = (In->SRegLo >> 1) & 0xFF;
883 Out->SRegHi = (In->SRegHi >> 1) & 0xFF;
886 } else if (E->AM == AM65_ZPX) {
887 /* Invalidates all ZP registers */
888 RC_InvalidateZP (Out);
896 if (RegValIsKnown (In->RegA)) {
897 if (CE_KnownImm (E)) {
898 Out->RegA = In->RegA | (short) E->Num;
899 } else if (E->AM == AM65_ZP) {
900 switch (GetKnownReg (E->Use & REG_ZP, In)) {
902 Out->RegA = In->RegA | In->Tmp1;
905 Out->RegA = In->RegA | In->Ptr1Lo;
908 Out->RegA = In->RegA | In->Ptr1Hi;
911 Out->RegA = In->RegA | In->SRegLo;
914 Out->RegA = In->RegA | In->SRegHi;
917 Out->RegA = UNKNOWN_REGVAL;
921 /* A is now unknown */
922 Out->RegA = UNKNOWN_REGVAL;
940 Out->RegA = UNKNOWN_REGVAL;
947 Out->RegX = UNKNOWN_REGVAL;
951 Out->RegY = UNKNOWN_REGVAL;
955 /* We don't know the value of the carry bit */
956 if (E->AM == AM65_ACC) {
957 Out->RegA = UNKNOWN_REGVAL;
958 } else if (E->AM == AM65_ZP) {
959 switch (GetKnownReg (E->Chg & REG_ZP, In)) {
961 Out->Tmp1 = UNKNOWN_REGVAL;
964 Out->Ptr1Lo = UNKNOWN_REGVAL;
967 Out->Ptr1Hi = UNKNOWN_REGVAL;
970 Out->SRegLo = UNKNOWN_REGVAL;
973 Out->SRegHi = UNKNOWN_REGVAL;
976 } else if (E->AM == AM65_ZPX) {
977 /* Invalidates all ZP registers */
978 RC_InvalidateZP (Out);
983 /* We don't know the value of the carry bit */
984 if (E->AM == AM65_ACC) {
985 Out->RegA = UNKNOWN_REGVAL;
986 } else if (E->AM == AM65_ZP) {
987 switch (GetKnownReg (E->Chg & REG_ZP, In)) {
989 Out->Tmp1 = UNKNOWN_REGVAL;
992 Out->Ptr1Lo = UNKNOWN_REGVAL;
995 Out->Ptr1Hi = UNKNOWN_REGVAL;
998 Out->SRegLo = UNKNOWN_REGVAL;
1001 Out->SRegHi = UNKNOWN_REGVAL;
1004 } else if (E->AM == AM65_ZPX) {
1005 /* Invalidates all ZP registers */
1006 RC_InvalidateZP (Out);
1017 /* We don't know the value of the carry bit */
1018 Out->RegA = UNKNOWN_REGVAL;
1031 if (E->AM == AM65_ZP) {
1032 switch (GetKnownReg (E->Chg & REG_ZP, 0)) {
1034 Out->Tmp1 = In->RegA;
1037 Out->Ptr1Lo = In->RegA;
1040 Out->Ptr1Hi = In->RegA;
1043 Out->SRegLo = In->RegA;
1046 Out->SRegHi = In->RegA;
1049 } else if (E->AM == AM65_ZPX) {
1050 /* Invalidates all ZP registers */
1051 RC_InvalidateZP (Out);
1056 if (E->AM == AM65_ZP) {
1057 switch (GetKnownReg (E->Chg & REG_ZP, 0)) {
1059 Out->Tmp1 = In->RegX;
1062 Out->Ptr1Lo = In->RegX;
1065 Out->Ptr1Hi = In->RegX;
1068 Out->SRegLo = In->RegX;
1071 Out->SRegHi = In->RegX;
1074 } else if (E->AM == AM65_ZPX) {
1075 /* Invalidates all ZP registers */
1076 RC_InvalidateZP (Out);
1081 if (E->AM == AM65_ZP) {
1082 switch (GetKnownReg (E->Chg & REG_ZP, 0)) {
1084 Out->Tmp1 = In->RegY;
1087 Out->Ptr1Lo = In->RegY;
1090 Out->Ptr1Hi = In->RegY;
1093 Out->SRegLo = In->RegY;
1096 Out->SRegHi = In->RegY;
1099 } else if (E->AM == AM65_ZPX) {
1100 /* Invalidates all ZP registers */
1101 RC_InvalidateZP (Out);
1106 if (E->AM == AM65_ZP) {
1107 switch (GetKnownReg (E->Chg & REG_ZP, 0)) {
1124 } else if (E->AM == AM65_ZPX) {
1125 /* Invalidates all ZP registers */
1126 RC_InvalidateZP (Out);
1131 Out->RegX = In->RegA;
1135 Out->RegY = In->RegA;
1139 if (E->AM == AM65_ZPX) {
1140 /* Invalidates all ZP registers */
1141 RC_InvalidateZP (Out);
1142 } else if (E->AM == AM65_ZP) {
1143 if (RegValIsKnown (In->RegA)) {
1144 switch (GetKnownReg (E->Chg & REG_ZP, In)) {
1146 Out->Tmp1 &= ~In->RegA;
1149 Out->Ptr1Lo &= ~In->RegA;
1152 Out->Ptr1Hi &= ~In->RegA;
1155 Out->SRegLo &= ~In->RegA;
1158 Out->SRegHi &= ~In->RegA;
1162 switch (GetKnownReg (E->Chg & REG_ZP, In)) {
1164 Out->Tmp1 = UNKNOWN_REGVAL;
1167 Out->Ptr1Lo = UNKNOWN_REGVAL;
1170 Out->Ptr1Hi = UNKNOWN_REGVAL;
1173 Out->SRegLo = UNKNOWN_REGVAL;
1176 Out->SRegHi = UNKNOWN_REGVAL;
1184 if (E->AM == AM65_ZPX) {
1185 /* Invalidates all ZP registers */
1186 RC_InvalidateZP (Out);
1187 } else if (E->AM == AM65_ZP) {
1188 if (RegValIsKnown (In->RegA)) {
1189 switch (GetKnownReg (E->Chg & REG_ZP, In)) {
1191 Out->Tmp1 |= In->RegA;
1194 Out->Ptr1Lo |= In->RegA;
1197 Out->Ptr1Hi |= In->RegA;
1200 Out->SRegLo |= In->RegA;
1203 Out->SRegHi |= In->RegA;
1207 switch (GetKnownReg (E->Chg & REG_ZP, In)) {
1209 Out->Tmp1 = UNKNOWN_REGVAL;
1212 Out->Ptr1Lo = UNKNOWN_REGVAL;
1215 Out->Ptr1Hi = UNKNOWN_REGVAL;
1218 Out->SRegLo = UNKNOWN_REGVAL;
1221 Out->SRegHi = UNKNOWN_REGVAL;
1229 Out->RegX = UNKNOWN_REGVAL;
1233 Out->RegA = In->RegX;
1240 Out->RegA = In->RegY;
1251 static char* RegInfoDesc (unsigned U, char* Buf)
1252 /* Return a string containing register info */
1256 strcat (Buf, U & REG_SREG_HI? "H" : "_");
1257 strcat (Buf, U & REG_SREG_LO? "L" : "_");
1258 strcat (Buf, U & REG_A? "A" : "_");
1259 strcat (Buf, U & REG_X? "X" : "_");
1260 strcat (Buf, U & REG_Y? "Y" : "_");
1261 strcat (Buf, U & REG_TMP1? "T1" : "__");
1262 strcat (Buf, U & REG_PTR1? "1" : "_");
1263 strcat (Buf, U & REG_PTR2? "2" : "_");
1264 strcat (Buf, U & REG_SAVE? "V" : "_");
1265 strcat (Buf, U & REG_SP? "S" : "_");
1272 void CE_Output (const CodeEntry* E, FILE* F)
1273 /* Output the code entry to a file */
1279 /* If we have a label, print that */
1280 unsigned LabelCount = CollCount (&E->Labels);
1282 for (I = 0; I < LabelCount; ++I) {
1283 CL_Output (CollConstAt (&E->Labels, I), F);
1286 /* Get the opcode description */
1287 D = GetOPCDesc (E->OPC);
1289 /* Print the mnemonic */
1290 Chars = fprintf (F, "\t%s", D->Mnemo);
1292 /* Print the operand */
1302 Chars += fprintf (F, "%*sa", 9-Chars, "");
1308 Chars += fprintf (F, "%*s#%s", 9-Chars, "", E->Arg);
1314 /* zeropage and absolute */
1315 Chars += fprintf (F, "%*s%s", 9-Chars, "", E->Arg);
1320 /* zeropage,X and absolute,X */
1321 Chars += fprintf (F, "%*s%s,x", 9-Chars, "", E->Arg);
1326 Chars += fprintf (F, "%*s%s,y", 9-Chars, "", E->Arg);
1331 Chars += fprintf (F, "%*s(%s,x)", 9-Chars, "", E->Arg);
1336 Chars += fprintf (F, "%*s(%s),y", 9-Chars, "", E->Arg);
1341 Chars += fprintf (F, "%*s(%s)", 9-Chars, "", E->Arg);
1346 Target = E->JumpTo? E->JumpTo->Name : E->Arg;
1347 Chars += fprintf (F, "%*s%s", 9-Chars, "", Target);
1351 Internal ("Invalid addressing mode");
1355 /* Print usage info if requested by the debugging flag */
1360 "%*s; USE: %-12s CHG: %-12s SIZE: %u\n",
1362 RegInfoDesc (E->Use, Use),
1363 RegInfoDesc (E->Chg, Chg),
1366 /* Terminate the line */