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
14 static int siztab[4] = {3, 5, 9, 9};
22 if (c < 0x20 || c >= 0x7F)
32 // Print expression, return ptr to just past the ENDEXPR
34 TOKEN * printexpr(TOKEN * tp)
38 while (*tp != ENDEXPR)
43 printf("`%s' ", ((SYM *)*tp)->sname);
47 printf("$%ux ", *tp++);
50 printf("ACONST=($%ux,$%ux) ", *tp, tp[1]);
54 printf("%c ", (char)tp[-1]);
66 // Dump data in a chunk (and maybe others) in the appropriate format
68 int chdump(CHUNK * ch, int format)
72 printf("chloc=$%08ux, chsize=$%ux\n", ch->chloc, ch->ch_size);
73 mdump(ch->chptr, ch->ch_size, format, ch->chloc);
82 // Dump fixup records in printable format
84 int fudump(CHUNK * ch)
95 ep = ch->chptr + ch->ch_size;
104 printf("$%04x $%08ux %d.%d: ", (int)attr, loc, (int)file, (int)line);
109 printf("(%d long) ", (int)esiz);
110 p.tk = printexpr(p.tk);
114 printf("`%s' ;\n", (*p.sy)->sname);
140 for(mch=firstmch; mch!=NULL; mch=mch->mcnext)
142 printf("mch=$%08ux mcptr=$%08ux mcalloc=$%ux mcused=$%x\n",
166 printf("m=$%04x to=%d loc=$%ux from=%d siz=%s",
167 w, w & 0x00ff, loc, from, (w & MLONG) ? "long" : "word");
170 printf(" sym=`%s'", symbol->sname);
181 // Dump memory from 'start' for 'count' bytes; `flg' is the following ORed together:
186 // if `base' is not -1, then print it at the start of each line, incremented accordingly.
188 int mdump(char * start, LONG count, int flg, LONG base)
193 for(i=0; i<(int)count;)
210 printf("%08ux ", base);
216 printf("%02x ", start[i] & 0xff);
220 printf("%02x%02x ", start[i] & 0xff, start[i+1] & 0xff);
224 printf("%02x%02x%02x%02x ", start[i] & 0xff, start[i+1] & 0xff,
225 start[i+2] & 0xff, start[i+3] & 0xff);
233 base += 1 << (flg & 3);
236 // Print remaining bit of ascii; the hairy expression computes the number of
237 // spaces to print to make the ascii line up nicely.
240 k = ((16 - (i - j)) / (1 << (flg & 3))) * siztab[flg & 3];
258 // Dump list of tokens on stdout in printable form
260 int dumptok(TOKEN * tk)
271 printf("REG=%ud", *tk++ - 128);
277 case CONST: // CONST <value>
278 printf("CONST=%ud", *tk++);
280 case STRING: // STRING <address>
281 printf("STRING='%s'", (char *)*tk++);
283 case SYMBOL: // SYMBOL <address>
284 printf("SYMBOL='%s'", (char *)*tk++);
286 case EOL: // End of line
289 case TKEOF: // End of file (or macro)
314 printf("%c", (int)tk[-1]);
328 int dump_everything(void)
332 for(i = 1; i < NSECTS; ++i)
334 if (sect[i].scattr & SUSED)
336 printf("Section %d sloc=$%ux\n", i, sect[i].sloc);
338 chdump(sect[i].sfcode, 1);
341 fudump(sect[i].sffix);
347 printf("\nMarks:\n");
348 mudump(); // Dump marks
349 printf("Total memory allocated=$%ux\n", amemtot);