]> git.sur5r.net Git - cc65/blob - src/cc65/codeent.c
Added first provisions for a code size factor check in the optimizer
[cc65] / src / cc65 / codeent.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 codeent.c                                 */
4 /*                                                                           */
5 /*                            Code segment entry                             */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2001     Ullrich von Bassewitz                                        */
10 /*              Wacholderweg 14                                              */
11 /*              D-70597 Stuttgart                                            */
12 /* EMail:       uz@musoftware.de                                             */
13 /*                                                                           */
14 /*                                                                           */
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.                                    */
18 /*                                                                           */
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:                            */
22 /*                                                                           */
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              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #include <stdlib.h>
37 #include <string.h>
38
39 /* common */
40 #include "chartype.h"
41 #include "check.h"
42 #include "xmalloc.h"
43 #include "xsprintf.h"
44
45 /* cc65 */
46 #include "codeinfo.h"
47 #include "error.h"
48 #include "global.h"
49 #include "codelab.h"
50 #include "opcodes.h"
51 #include "codeent.h"
52
53
54
55 /*****************************************************************************/
56 /*                                   Data                                    */
57 /*****************************************************************************/
58
59
60
61 /* Empty argument */
62 static char EmptyArg[] = "";
63
64
65
66 /*****************************************************************************/
67 /*                             Helper functions                              */
68 /*****************************************************************************/
69
70
71
72 static void FreeArg (char* Arg)
73 /* Free a code entry argument */
74 {
75     if (Arg != EmptyArg) {
76         xfree (Arg);
77     }
78 }
79
80
81
82 static char* GetArgCopy (const char* Arg)
83 /* Create an argument copy for assignment */
84 {
85     if (Arg && Arg[0] != '\0') {
86         /* Create a copy */
87         return xstrdup (Arg);
88     } else {
89         /* Use the empty argument string */
90         return EmptyArg;
91     }
92 }
93
94
95
96 static int NumArg (const char* Arg, unsigned long* Num)
97 /* If the given argument is numerical, convert it and return true. Otherwise
98  * set Num to zero and return false.
99  */
100 {
101     char* End;
102     unsigned long Val;
103
104     /* Determine the base */
105     int Base = 10;
106     if (*Arg == '$') {
107         ++Arg;
108         Base = 16;
109     } else if (*Arg == '%') {
110         ++Arg;
111         Base = 2;
112     }
113
114     /* Convert the value. strtol is not exactly what we want here, but it's
115      * cheap and may be replaced by something fancier later.
116      */
117     Val = strtoul (Arg, &End, Base);
118
119     /* Check if the conversion was successful */
120     if (*End != '\0') {
121
122         /* Could not convert */
123         *Num = 0;
124         return 0;
125
126     } else {
127
128         /* Conversion ok */
129         *Num = Val;
130         return 1;
131
132     }
133 }
134
135
136
137 static void SetUseChgInfo (CodeEntry* E, const OPCDesc* D)
138 /* Set the Use and Chg in E */
139 {
140     const ZPInfo* Info;
141
142     /* If this is a subroutine call, or a jump to an external function,
143      * lookup the information about this function and use it. The jump itself
144      * does not change any registers, so we don't need to use the data from D.
145      */
146     if ((E->Info & (OF_BRA | OF_CALL)) != 0 && E->JumpTo == 0) {
147         /* A subroutine call or jump to external symbol (function exit) */
148         GetFuncInfo (E->Arg, &E->Use, &E->Chg);
149     } else {
150         /* Some other instruction. Use the values from the opcode description
151          * plus addressing mode info.
152          */
153         E->Use = D->Use | GetAMUseInfo (E->AM);
154         E->Chg = D->Chg;
155
156         /* Check for special zero page registers used */
157         switch (E->AM) {
158
159             case AM65_ZP:
160             case AM65_ABS:
161             /* Be conservative: */
162             case AM65_ZPX:
163             case AM65_ABSX:
164             case AM65_ABSY:
165                 Info = GetZPInfo (E->Arg);
166                 if (Info && Info->ByteUse != REG_NONE) {
167                     if (E->OPC == OP65_ASL || E->OPC == OP65_DEC ||
168                         E->OPC == OP65_INC || E->OPC == OP65_LSR ||
169                         E->OPC == OP65_ROL || E->OPC == OP65_ROR ||
170                         E->OPC == OP65_TRB || E->OPC == OP65_TSB) {
171                         /* The zp loc is both, input and output */
172                         E->Chg |= Info->ByteUse;
173                         E->Use |= Info->ByteUse;
174                     } else if ((E->Info & OF_STORE) != 0) {
175                         /* Just output */
176                         E->Chg |= Info->ByteUse;
177                     } else {
178                         /* Input only */
179                         E->Use |= Info->ByteUse;
180                     }
181                 }
182                 break;
183
184             case AM65_ZPX_IND:
185             case AM65_ZP_INDY:
186             case AM65_ZP_IND:
187                 Info = GetZPInfo (E->Arg);
188                 if (Info && Info->ByteUse != REG_NONE) {
189                     /* These addressing modes will never change the zp loc */
190                     E->Use |= Info->WordUse;
191                 }
192                 break;
193
194             default:
195                 /* Keep gcc silent */
196                 break;
197         }
198     }
199 }
200
201
202
203 /*****************************************************************************/
204 /*                                   Code                                    */
205 /*****************************************************************************/
206
207
208
209 CodeEntry* NewCodeEntry (opc_t OPC, am_t AM, const char* Arg,
210                          CodeLabel* JumpTo, LineInfo* LI)
211 /* Create a new code entry, initialize and return it */
212 {
213     /* Get the opcode description */
214     const OPCDesc* D = GetOPCDesc (OPC);
215
216     /* Allocate memory */
217     CodeEntry* E = xmalloc (sizeof (CodeEntry));
218
219     /* Initialize the fields */
220     E->OPC    = D->OPC;
221     E->AM     = AM;
222     E->Arg    = GetArgCopy (Arg);
223     E->Flags  = NumArg (E->Arg, &E->Num)? CEF_NUMARG : 0;
224     E->Info   = D->Info;
225     E->Size   = GetInsnSize (E->OPC, E->AM);
226     E->JumpTo = JumpTo;
227     E->LI     = UseLineInfo (LI);
228     E->RI     = 0;
229     SetUseChgInfo (E, D);
230     InitCollection (&E->Labels);
231
232     /* If we have a label given, add this entry to the label */
233     if (JumpTo) {
234         CollAppend (&JumpTo->JumpFrom, E);
235     }
236
237     /* Return the initialized struct */
238     return E;
239 }
240
241
242
243 void FreeCodeEntry (CodeEntry* E)
244 /* Free the given code entry */
245 {
246     /* Free the string argument if we have one */
247     FreeArg (E->Arg);
248
249     /* Cleanup the collection */
250     DoneCollection (&E->Labels);
251
252     /* Release the line info */
253     ReleaseLineInfo (E->LI);
254
255     /* Delete the register info */
256     CE_FreeRegInfo (E);
257
258     /* Free the entry */
259     xfree (E);
260 }
261
262
263
264 void CE_ReplaceOPC (CodeEntry* E, opc_t OPC)
265 /* Replace the opcode of the instruction. This will also replace related info,
266  * Size, Use and Chg, but it will NOT update any arguments or labels.
267  */
268 {
269     /* Get the opcode descriptor */
270     const OPCDesc* D = GetOPCDesc (OPC);
271
272     /* Replace the opcode */
273     E->OPC  = OPC;
274     E->Info = D->Info;
275     E->Size = GetInsnSize (E->OPC, E->AM);
276     SetUseChgInfo (E, D);
277 }
278
279
280
281 int CodeEntriesAreEqual (const CodeEntry* E1, const CodeEntry* E2)
282 /* Check if both code entries are equal */
283 {
284     return E1->OPC == E2->OPC && E1->AM == E2->AM && strcmp (E1->Arg, E2->Arg) == 0;
285 }
286
287
288
289 void CE_AttachLabel (CodeEntry* E, CodeLabel* L)
290 /* Attach the label to the entry */
291 {
292     /* Add it to the entries label list */
293     CollAppend (&E->Labels, L);
294
295     /* Tell the label about it's owner */
296     L->Owner = E;
297 }
298
299
300
301 void CE_MoveLabel (CodeLabel* L, CodeEntry* E)
302 /* Move the code label L from it's former owner to the code entry E. */
303 {
304     /* Delete the label from the owner */
305     CollDeleteItem (&L->Owner->Labels, L);
306
307     /* Set the new owner */
308     CollAppend (&E->Labels, L);
309     L->Owner = E;
310 }
311
312
313
314 void CE_SetNumArg (CodeEntry* E, long Num)
315 /* Set a new numeric argument for the given code entry that must already
316  * have a numeric argument.
317  */
318 {
319     char Buf[16];
320
321     /* Check that the entry has a numerical argument */
322     CHECK (E->Flags & CEF_NUMARG);
323
324     /* Make the new argument string */
325     if (E->Size == 2) {
326         Num &= 0xFF;
327         xsprintf (Buf, sizeof (Buf), "$%02X", (unsigned) Num);
328     } else if (E->Size == 3) {
329         Num &= 0xFFFF;
330         xsprintf (Buf, sizeof (Buf), "$%04X", (unsigned) Num);
331     } else {
332         Internal ("Invalid instruction size in CE_SetNumArg");
333     }
334
335     /* Free the old argument */
336     FreeArg (E->Arg);
337
338     /* Assign the new one */
339     E->Arg = GetArgCopy (Buf);
340
341     /* Use the new numerical value */
342     E->Num = Num;
343 }
344
345
346
347 int CE_KnownImm (const CodeEntry* E)
348 /* Return true if the argument of E is a known immediate value */
349 {
350     return (E->AM == AM65_IMM && (E->Flags & CEF_NUMARG) != 0);
351 }
352
353
354
355 void CE_FreeRegInfo (CodeEntry* E)
356 /* Free an existing register info struct */
357 {
358     if (E->RI) {
359         FreeRegInfo (E->RI);
360         E->RI = 0;
361     }
362 }
363
364
365
366 void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs)
367 /* Generate register info for this instruction. If an old info exists, it is
368  * overwritten.
369  */
370 {
371     /* Pointers to the register contents */
372     RegContents* In;
373     RegContents* Out;
374
375     /* Function register usage */
376     unsigned short Use, Chg;
377
378     /* If we don't have a register info struct, allocate one. */
379     if (E->RI == 0) {
380         E->RI = NewRegInfo (InputRegs);
381     } else {
382         if (InputRegs) {
383             E->RI->In  = *InputRegs;
384         } else {
385             RC_Invalidate (&E->RI->In);
386         }
387         E->RI->Out2 = E->RI->Out = E->RI->In;
388     }
389
390     /* Get pointers to the register contents */
391     In  = &E->RI->In;
392     Out = &E->RI->Out;
393
394     /* Handle the different instructions */
395     switch (E->OPC) {
396
397         case OP65_ADC:
398             /* We don't know the value of the carry, so the result is
399              * always unknown.
400              */
401             Out->RegA = -1;
402             break;
403
404         case OP65_AND:
405             if (In->RegA >= 0) {
406                 if (CE_KnownImm (E)) {
407                     Out->RegA = In->RegA & (short) E->Num;
408                 } else {
409                     Out->RegA = -1;
410                 }
411             }
412             break;
413
414         case OP65_ASL:
415             if (E->AM == AM65_ACC && In->RegA >= 0) {
416                 Out->RegA = (In->RegA << 1) & 0xFF;
417             } else if (E->AM == AM65_ZP) {
418                 if ((E->Chg & REG_SREG_LO) != 0 && In->SRegLo >= 0) {
419                     Out->SRegLo = (In->SRegLo << 1) & 0xFF;
420                 } else if ((E->Chg & REG_SREG_HI) != 0 && In->SRegHi >= 0) {
421                     Out->SRegHi = (In->SRegHi << 1) & 0xFF;
422                 }
423             }
424             break;
425
426         case OP65_BCC:
427             break;
428
429         case OP65_BCS:
430             break;
431
432         case OP65_BEQ:
433             break;
434
435         case OP65_BIT:
436             break;
437
438         case OP65_BMI:
439             break;
440
441         case OP65_BNE:
442             break;
443
444         case OP65_BPL:
445             break;
446
447         case OP65_BRA:
448             break;
449
450         case OP65_BRK:
451             break;
452
453         case OP65_BVC:
454             break;
455
456         case OP65_BVS:
457             break;
458
459         case OP65_CLC:
460             break;
461
462         case OP65_CLD:
463             break;
464
465         case OP65_CLI:
466             break;
467
468         case OP65_CLV:
469             break;
470
471         case OP65_CMP:
472             break;
473
474         case OP65_CPX:
475             break;
476
477         case OP65_CPY:
478             break;
479
480         case OP65_DEA:
481             if (In->RegA >= 0) {
482                 Out->RegA = (In->RegA - 1) & 0xFF;
483             }
484             break;
485
486         case OP65_DEC:
487             if (E->AM == AM65_ACC && In->RegA >= 0) {
488                 Out->RegA = (In->RegA - 1) & 0xFF;
489             } else if (E->AM == AM65_ZP) {
490                 if ((E->Chg & REG_SREG_LO) != 0 && In->SRegLo >= 0) {
491                     Out->SRegLo = (In->SRegLo - 1) & 0xFF;
492                 } else if ((E->Chg & REG_SREG_HI) != 0 && In->SRegHi >= 0) {
493                     Out->SRegHi = (In->SRegHi - 1) & 0xFF;
494                 }
495             }
496             break;
497
498         case OP65_DEX:
499             if (In->RegX >= 0) {
500                 Out->RegX = (In->RegX - 1) & 0xFF;
501             }
502             break;
503
504         case OP65_DEY:
505             if (In->RegY >= 0) {
506                 Out->RegY = (In->RegY - 1) & 0xFF;
507             }
508             break;
509
510         case OP65_EOR:
511             if (In->RegA >= 0) {
512                 if (CE_KnownImm (E)) {
513                     Out->RegA = In->RegA ^ (short) E->Num;
514                 } else {
515                     Out->RegA = -1;
516                 }
517             }
518             break;
519
520         case OP65_INA:
521             if (In->RegA >= 0) {
522                 Out->RegA = (In->RegA + 1) & 0xFF;
523             }
524             break;
525
526         case OP65_INC:
527             if (E->AM == AM65_ACC && In->RegA >= 0) {
528                 Out->RegA = (In->RegA + 1) & 0xFF;
529             } else if (E->AM == AM65_ZP) {
530                 if ((E->Chg & REG_SREG_LO) != 0 && In->SRegLo >= 0) {
531                     Out->SRegLo = (In->SRegLo + 1) & 0xFF;
532                 } else if ((E->Chg & REG_SREG_HI) != 0 && In->SRegHi >= 0) {
533                     Out->SRegHi = (In->SRegHi + 1) & 0xFF;
534                 }
535             }
536             break;
537
538         case OP65_INX:
539             if (In->RegX >= 0) {
540                 Out->RegX = (In->RegX + 1) & 0xFF;
541             }
542             break;
543
544         case OP65_INY:
545             if (In->RegY >= 0) {
546                 Out->RegY = (In->RegY + 1) & 0xFF;
547             }
548             break;
549
550         case OP65_JCC:
551             break;
552
553         case OP65_JCS:
554             break;
555
556         case OP65_JEQ:
557             break;
558
559         case OP65_JMI:
560             break;
561
562         case OP65_JMP:
563             break;
564
565         case OP65_JNE:
566             break;
567
568         case OP65_JPL:
569             break;
570
571         case OP65_JSR:
572             /* Get the code info for the function */
573             GetFuncInfo (E->Arg, &Use, &Chg);
574             if (Chg & REG_A) {
575                 Out->RegA = -1;
576             }
577             if (Chg & REG_X) {
578                 Out->RegX = -1;
579             }
580             if (Chg & REG_Y) {
581                 Out->RegY = -1;
582             }
583             if (Chg & REG_SREG_LO) {
584                 Out->SRegLo = -1;
585             }
586             if (Chg & REG_SREG_HI) {
587                 Out->SRegHi = -1;
588             }
589             break;
590
591         case OP65_JVC:
592             break;
593
594         case OP65_JVS:
595             break;
596
597         case OP65_LDA:
598             if (CE_KnownImm (E)) {
599                 Out->RegA = (unsigned char) E->Num;
600             } else if (E->AM == AM65_ZP) {
601                 if (E->Use & REG_SREG_LO) {
602                     Out->RegA = In->SRegLo;
603                 } else if (E->Use & REG_SREG_HI) {
604                     Out->RegA = In->SRegHi;
605                 } else {
606                     Out->RegA = -1;
607                 }
608             } else {
609                 /* A is now unknown */
610                 Out->RegA = -1;
611             }
612             break;
613
614         case OP65_LDX:
615             if (CE_KnownImm (E)) {
616                 Out->RegX = (unsigned char) E->Num;
617             } else if (E->AM == AM65_ZP) {
618                 if (E->Use & REG_SREG_LO) {
619                     Out->RegX = In->SRegLo;
620                 } else if (E->Use & REG_SREG_HI) {
621                     Out->RegX = In->SRegHi;
622                 } else {
623                     Out->RegX = -1;
624                 }
625             } else {
626                 /* X is now unknown */
627                 Out->RegX = -1;
628             }
629             break;
630
631         case OP65_LDY:
632             if (CE_KnownImm (E)) {
633                 Out->RegY = (unsigned char) E->Num;
634             } else if (E->AM == AM65_ZP) {
635                 if (E->Use & REG_SREG_LO) {
636                     Out->RegY = In->SRegLo;
637                 } else if (E->Use & REG_SREG_HI) {
638                     Out->RegY = In->SRegHi;
639                 } else {
640                     Out->RegY = -1;
641                 }
642             } else {
643                 /* Y is now unknown */
644                 Out->RegY = -1;
645             }
646             break;
647
648         case OP65_LSR:
649             if (E->AM == AM65_ACC && In->RegA >= 0) {
650                 Out->RegA = (In->RegA >> 1) & 0xFF;
651             } else if (E->AM == AM65_ZP) {
652                 if ((E->Chg & REG_SREG_LO) != 0 && In->SRegLo >= 0) {
653                     Out->SRegLo = (In->SRegLo >> 1) & 0xFF;
654                 } else if (E->Chg & REG_SREG_HI) {
655                     Out->SRegHi = (In->SRegHi >> 1) & 0xFF;
656                 }
657             }
658             break;
659
660         case OP65_NOP:
661             break;
662
663         case OP65_ORA:
664             if (In->RegA >= 0) {
665                 if (CE_KnownImm (E)) {
666                     Out->RegA = In->RegA | (short) E->Num;
667                 } else {
668                     /* A is now unknown */
669                     Out->RegA = -1;
670                 }
671             }
672             break;
673
674         case OP65_PHA:
675             break;
676
677         case OP65_PHP:
678             break;
679
680         case OP65_PHX:
681             break;
682
683         case OP65_PHY:
684             break;
685
686         case OP65_PLA:
687             Out->RegA = -1;
688             break;
689
690         case OP65_PLP:
691             break;
692
693         case OP65_PLX:
694             Out->RegX = -1;
695             break;
696
697         case OP65_PLY:
698             Out->RegY = -1;
699             break;
700
701         case OP65_ROL:
702             if (E->AM == AM65_ACC) {
703                 Out->RegA = -1;
704             } else if (E->AM == AM65_ZP) {
705                 if (E->Chg & REG_SREG_LO) {
706                     Out->SRegLo = -1;
707                 } else if (E->Chg & REG_SREG_HI) {
708                     Out->SRegHi = -1;
709                 }
710             }
711             break;
712
713         case OP65_ROR:
714             if (E->AM == AM65_ACC) {
715                 Out->RegA = -1;
716             } else if (E->AM == AM65_ZP) {
717                 if (E->Chg & REG_SREG_LO) {
718                     Out->SRegLo = -1;
719                 } else if (E->Chg & REG_SREG_HI) {
720                     Out->SRegHi = -1;
721                 }
722             }
723             break;
724
725         case OP65_RTI:
726             break;
727
728         case OP65_RTS:
729             break;
730
731         case OP65_SBC:
732             /* We don't know the value of the carry bit */
733             Out->RegA = -1;
734             break;
735
736         case OP65_SEC:
737             break;
738
739         case OP65_SED:
740             break;
741
742         case OP65_SEI:
743             break;
744
745         case OP65_STA:
746             if (E->AM == AM65_ZP) {
747                 if (E->Chg & REG_SREG_LO) {
748                     Out->SRegLo = In->RegA;
749                 } else if (E->Chg & REG_SREG_HI) {
750                     Out->SRegHi = In->RegA;
751                 }
752             }
753             break;
754
755         case OP65_STX:
756             if (E->AM == AM65_ZP) {
757                 if (E->Chg & REG_SREG_LO) {
758                     Out->SRegLo = In->RegX;
759                 } else if (E->Chg & REG_SREG_HI) {
760                     Out->SRegHi = In->RegX;
761                 }
762             }
763             break;
764
765         case OP65_STY:
766             if (E->AM == AM65_ZP) {
767                 if (E->Chg & REG_SREG_LO) {
768                     Out->SRegLo = In->RegY;
769                 } else if (E->Chg & REG_SREG_HI) {
770                     Out->SRegHi = In->RegY;
771                 }
772             }
773             break;
774
775         case OP65_TAX:
776             Out->RegX = In->RegA;
777             break;
778
779         case OP65_TAY:
780             Out->RegY = In->RegA;
781             break;
782
783         case OP65_TRB:
784             /* For now... */
785             Out->RegA = -1;
786             break;
787
788         case OP65_TSB:
789             /* For now... */
790             Out->RegA = -1;
791             break;
792
793         case OP65_TSX:
794             Out->RegX = -1;
795             break;
796
797         case OP65_TXA:
798             Out->RegA = In->RegX;
799             break;
800
801         case OP65_TXS:
802             break;
803
804         case OP65_TYA:
805             Out->RegA = In->RegY;
806             break;
807
808         default:
809             break;
810
811     }
812 }
813
814
815
816 static char* RegInfoDesc (unsigned U, char* Buf)
817 /* Return a string containing register info */
818 {
819     Buf[0] = '\0';
820
821     strcat (Buf, U & REG_SREG_HI? "H" : "_");
822     strcat (Buf, U & REG_SREG_LO? "L" : "_");
823     strcat (Buf, U & REG_A?       "A" : "_");
824     strcat (Buf, U & REG_X?       "X" : "_");
825     strcat (Buf, U & REG_Y?       "Y" : "_");
826     strcat (Buf, U & REG_TMP1?    "T1" : "__");
827     strcat (Buf, U & REG_PTR1?    "1" : "_");
828     strcat (Buf, U & REG_PTR2?    "2" : "_");
829     strcat (Buf, U & REG_SAVE?    "V"  : "_");
830
831     return Buf;
832 }
833
834
835
836 void CE_Output (const CodeEntry* E, FILE* F)
837 /* Output the code entry to a file */
838 {
839     const OPCDesc* D;
840     unsigned Chars;
841     const char* Target;
842
843     /* If we have a label, print that */
844     unsigned LabelCount = CollCount (&E->Labels);
845     unsigned I;
846     for (I = 0; I < LabelCount; ++I) {
847         CL_Output (CollConstAt (&E->Labels, I), F);
848     }
849
850     /* Get the opcode description */
851     D = GetOPCDesc (E->OPC);
852
853     /* Print the mnemonic */
854     Chars = fprintf (F, "\t%s", D->Mnemo);
855
856     /* Print the operand */
857     switch (E->AM) {
858
859         case AM_IMP:
860         case AM65_IMP:
861             /* implicit */
862             break;
863
864         case AM65_ACC:
865             /* accumulator */
866             Chars += fprintf (F, "%*sa", 9-Chars, "");
867             break;
868
869         case AM_IMM:
870         case AM65_IMM:
871             /* immidiate */
872             Chars += fprintf (F, "%*s#%s", 9-Chars, "", E->Arg);
873             break;
874
875         case AM_ABS:
876         case AM65_ZP:
877         case AM65_ABS:
878             /* zeropage and absolute */
879             Chars += fprintf (F, "%*s%s", 9-Chars, "", E->Arg);
880             break;
881
882         case AM65_ZPX:
883         case AM65_ABSX:
884             /* zeropage,X and absolute,X */
885             Chars += fprintf (F, "%*s%s,x", 9-Chars, "", E->Arg);
886             break;
887
888         case AM65_ABSY:
889             /* absolute,Y */
890             Chars += fprintf (F, "%*s%s,y", 9-Chars, "", E->Arg);
891             break;
892
893         case AM65_ZPX_IND:
894             /* (zeropage,x) */
895             Chars += fprintf (F, "%*s(%s,x)", 9-Chars, "", E->Arg);
896             break;
897
898         case AM65_ZP_INDY:
899             /* (zeropage),y */
900             Chars += fprintf (F, "%*s(%s),y", 9-Chars, "", E->Arg);
901             break;
902
903         case AM65_ZP_IND:
904             /* (zeropage) */
905             Chars += fprintf (F, "%*s(%s)", 9-Chars, "", E->Arg);
906             break;
907
908         case AM65_BRA:
909             /* branch */
910             Target = E->JumpTo? E->JumpTo->Name : E->Arg;
911             Chars += fprintf (F, "%*s%s", 9-Chars, "", Target);
912             break;
913
914         default:
915             Internal ("Invalid addressing mode");
916
917     }
918
919     /* Print usage info if requested by the debugging flag */
920     if (Debug) {
921         char Use [128];
922         char Chg [128];
923         fprintf (F,
924                  "%*s; USE: %-20s CHG: %-20s SIZE: %u\n",
925                  30-Chars, "",
926                  RegInfoDesc (E->Use, Use),
927                  RegInfoDesc (E->Chg, Chg),
928                  E->Size);
929     } else {
930         /* Terminate the line */
931         fprintf (F, "\n");
932     }
933 }
934
935
936
937
938
939