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("$%ux ", *tp++);
54 printf("ACONST=($%ux,$%ux) ", *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=$%08ux, chsize=$%ux\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 $%08ux %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);
122 if ((attr & 0x0F00) == FU_JR)
147 for(mch=firstmch; mch!=NULL; mch=mch->mcnext)
149 printf("mch=$%08ux mcptr=$%08ux mcalloc=$%ux mcused=$%x\n",
173 printf("m=$%04x to=%d loc=$%ux from=%d siz=%s",
174 w, w & 0x00ff, loc, from, (w & MLONG) ? "long" : "word");
177 printf(" sym=`%s'", symbol->sname);
188 // Dump memory from 'start' for 'count' bytes; `flg' is the following ORed together:
193 // if `base' is not -1, then print it at the start of each line, incremented accordingly.
195 int mdump(char * start, LONG count, int flg, LONG base)
200 for(i=0; i<(int)count;)
217 printf("%08ux ", base);
223 printf("%02x ", start[i] & 0xff);
227 printf("%02x%02x ", start[i] & 0xff, start[i+1] & 0xff);
231 printf("%02x%02x%02x%02x ", start[i] & 0xff, start[i+1] & 0xff,
232 start[i+2] & 0xff, start[i+3] & 0xff);
240 base += 1 << (flg & 3);
243 // Print remaining bit of ascii; the hairy expression computes the number of
244 // spaces to print to make the ascii line up nicely.
247 k = ((16 - (i - j)) / (1 << (flg & 3))) * siztab[flg & 3];
265 // Dump list of tokens on stdout in printable form
267 int dumptok(TOKEN * tk)
278 printf("REG=%ud", *tk++ - 128);
284 case CONST: // CONST <value>
285 printf("CONST=%ud", *tk++);
287 case STRING: // STRING <address>
288 // printf("STRING='%s'", (char *)*tk++);
289 printf("STRING='%s'", string[*tk++]);
291 case SYMBOL: // SYMBOL <address>
292 // printf("SYMBOL='%s'", (char *)*tk++);
293 printf("SYMBOL='%s'", string[*tk++]);
295 case EOL: // End of line
298 case TKEOF: // End of file (or macro)
323 printf("%c", (int)tk[-1]);
337 int dump_everything(void)
341 for(i=1; i<NSECTS; i++)
343 if (sect[i].scattr & SUSED)
345 printf("Section %d sloc=$%ux\n", i, sect[i].sloc);
347 chdump(sect[i].sfcode, 1);
350 fudump(sect[i].sffix);
356 printf("\nMarks:\n");
357 mudump(); // Dump marks
358 printf("Total memory allocated=$%ux\n", amemtot);