2 // RMAC - Reboot's Macro Assembler for the Atari Jaguar Console System
3 // DEBUG.C - Debugging Messages
4 // Copyright (C) 199x Landon Dyer, 2011-2012 Reboot and Friends
5 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
6 // Source Utilised with the Kind Permission of Landon Dyer
17 static int siztab[4] = { 3, 5, 9, 9 };
25 if (c < 0x20 || c >= 0x7F)
35 // Print expression, return ptr to just past the ENDEXPR
37 TOKEN * printexpr(TOKEN * tp)
41 while (*tp != ENDEXPR)
46 // printf("`%s' ", ((SYM *)*tp)->sname);
47 printf("`%s' ", symbolPtr[*tp]->sname);
51 printf("$%X ", *tp++);
54 printf("ACONST=($%X,$%X) ", *tp, tp[1]);
58 printf("%c ", (char)tp[-1]);
70 // Dump data in a chunk (and maybe others) in the appropriate format
72 int chdump(CHUNK * ch, int format)
76 printf("chloc=$%08X, chsize=$%X\n", ch->chloc, ch->ch_size);
77 mdump(ch->chptr, ch->ch_size, format, ch->chloc);
86 // Dump fixup records in printable format
88 int fudump(CHUNK * ch)
99 ep = ch->chptr + ch->ch_size;
108 printf("$%04X $%08X %d.%d: ", (int)attr, loc, (int)file, (int)line);
113 printf("(%d long) ", (int)esiz);
114 p.tk = printexpr(p.tk);
118 // printf("`%s' ;\n", (*p.sy)->sname);
119 printf("`%s' ;", (*p.sy)->sname);
123 if ((attr & 0x0F00) == FU_JR)
125 printf(" *=$%X", *p.lp);
153 for(mch=firstmch; mch!=NULL; mch=mch->mcnext)
155 printf("mch=$%p mcptr=$%08X mcalloc=$%X mcused=$%X\n",
156 mch, (mch->mcptr.lw), mch->mcalloc, (mch->mcused));
176 printf("m=$%04X to=%d loc=$%X from=%d siz=%s",
177 w, w & 0x00FF, loc, from, (w & MLONG) ? "long" : "word");
180 printf(" sym=`%s'", symbol->sname);
191 // Dump memory from 'start' for 'count' bytes; `flg' is the following ORed together:
196 // if `base' is not -1, then print it at the start of each line, incremented accordingly.
198 int mdump(char * start, LONG count, int flg, LONG base)
203 for(i=0; i<(int)count;)
220 printf("%08X ", base);
226 printf("%02X ", start[i] & 0xff);
230 printf("%02X%02X ", start[i] & 0xff, start[i+1] & 0xff);
234 printf("%02X%02X%02X%02X ", start[i] & 0xff, start[i+1] & 0xff,
235 start[i+2] & 0xff, start[i+3] & 0xff);
243 base += 1 << (flg & 3);
246 // Print remaining bit of ascii; the hairy expression computes the number of
247 // spaces to print to make the ascii line up nicely.
250 k = ((16 - (i - j)) / (1 << (flg & 3))) * siztab[flg & 3];
268 // Dump list of tokens on stdout in printable form
270 int dumptok(TOKEN * tk)
281 printf("REG=%u", *tk++ - 128);
287 case CONST: // CONST <value>
288 printf("CONST=%u", *tk++);
290 case STRING: // STRING <address>
291 printf("STRING='%s'", string[*tk++]);
293 case SYMBOL: // SYMBOL <address>
294 printf("SYMBOL='%s'", string[*tk++]);
296 case EOL: // End of line
299 case TKEOF: // End of file (or macro)
324 printf("%c", (int)tk[-1]);
338 int dump_everything(void)
342 for(i=1; i<NSECTS; i++)
344 if (sect[i].scattr & SUSED)
346 printf("Section %d sloc=$%X\n", i, sect[i].sloc);
348 chdump(sect[i].sfcode, 1);
351 fudump(sect[i].sffix);
357 printf("\nMarks:\n");
358 mudump(); // Dump marks
359 // printf("Total memory allocated=$%X\n", amemtot);