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' ;", (*p.sy)->sname);
122 if ((attr & 0x0F00) == FU_JR)
124 printf(" *=$%X", *p.lp);
152 for(mch=firstmch; mch!=NULL; mch=mch->mcnext)
154 printf("mch=$%p mcptr=$%08X mcalloc=$%X mcused=$%X\n",
155 mch, (mch->mcptr.lw), mch->mcalloc, (mch->mcused));
175 printf("m=$%04X to=%d loc=$%X from=%d siz=%s",
176 w, w & 0x00FF, loc, from, (w & MLONG) ? "long" : "word");
179 printf(" sym=`%s'", symbol->sname);
190 // Dump memory from 'start' for 'count' bytes; `flg' is the following ORed
196 // if `base' is not -1, then print it at the start of each line, incremented
199 int mdump(char * start, LONG count, int flg, LONG base)
204 for(i=0; i<(int)count;)
221 printf("%08X ", base);
227 printf("%02X ", start[i] & 0xff);
231 printf("%02X%02X ", start[i] & 0xff, start[i+1] & 0xff);
235 printf("%02X%02X%02X%02X ", start[i] & 0xff, start[i+1] & 0xff,
236 start[i+2] & 0xff, start[i+3] & 0xff);
244 base += 1 << (flg & 3);
247 // Print remaining bit of ASCII; the hairy expression computes the number
248 // of spaces to print to make the ASCII line up nicely.
251 k = ((16 - (i - j)) / (1 << (flg & 3))) * siztab[flg & 3];
269 // Dump list of tokens on stdout in printable form
271 int dumptok(TOKEN * tk)
282 printf("REG=%u", *tk++ - 128);
288 case CONST: // CONST <value>
289 printf("CONST=%u", *tk++);
291 case STRING: // STRING <address>
292 printf("STRING='%s'", string[*tk++]);
294 case SYMBOL: // SYMBOL <address>
295 printf("SYMBOL='%s'", string[*tk++]);
297 case EOL: // End of line
300 case TKEOF: // End of file (or macro)
325 printf("%c", (int)tk[-1]);
339 int dump_everything(void)
343 for(i=1; i<NSECTS; i++)
345 if (sect[i].scattr & SUSED)
347 printf("Section %d sloc=$%X\n", i, sect[i].sloc);
349 chdump(sect[i].sfcode, 1);
352 fudump(sect[i].sffix);
358 printf("\nMarks:\n");
359 mudump(); // Dump marks
360 // printf("Total memory allocated=$%X\n", amemtot);