2 // RMAC - Reboot's Macro Assembler for the Atari Jaguar Console System
3 // DEBUG.C - Debugging Messages
4 // Copyright (C) 199x Landon Dyer, 2011 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};
17 // --- Print 'c' Visibly ---------------------------------------------------------------------------
22 if (c < 0x20 || c >= 0x7f)
31 // --- 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("$%lx ", *tp++);
50 printf("ACONST=($%lx,$%lx) ", *tp, tp[1]);
54 printf("%c ", (char)tp[-1]);
65 // --- Dump data in a chunk (and maybe others) in the appropriate format ---------------------------
68 int chdump(CHUNK * ch, int format)
72 printf("chloc=$%08lx, chsize=$%lx\n", ch->chloc, ch->ch_size);
73 mdump(ch->chptr, ch->ch_size, format, ch->chloc);
81 // --- Dump fixup records in printable format ------------------------------------------------------
84 int fudump(CHUNK * ch)
95 ep = ch->chptr + ch->ch_size;
104 printf("$%04x $%08lx %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);
126 // --- Dump marks ----------------------------------------------------------------------------------
140 for(mch=firstmch; mch!=NULL; mch=mch->mcnext)
142 printf("mch=$%08lx mcptr=$%08lx mcalloc=$%lx mcused=$%x\n",
143 (unsigned long int)mch,
144 (unsigned long int)(mch->mcptr.lw),
146 (unsigned int)(mch->mcused));
166 printf("m=$%04x to=%d loc=$%lx from=%d siz=%s",
167 w, w & 0x00ff, loc, from, (w & MLONG) ? "long" : "word");
170 printf(" sym=`%s'", symbol->sname);
180 // -------------------------------------------------------------------------------------------------
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.
187 // -------------------------------------------------------------------------------------------------
190 int mdump(char *start, LONG count, int flg, LONG base) {
194 for(i = 0; i < (int)count;) {
204 printf("%08lx ", base);
209 printf("%02x ", start[i] & 0xff);
213 printf("%02x%02x ", start[i] & 0xff, start[i+1] & 0xff);
217 printf("%02x%02x%02x%02x ", start[i] & 0xff, start[i+1] & 0xff,
218 start[i+2] & 0xff, start[i+3] & 0xff);
226 base += 1 << (flg & 3);
229 // Print remaining bit of ascii; the hairy expression computes the number of
230 // spaces to print to make the ascii line up nicely.
232 k = ((16 - (i - j)) / (1 << (flg & 3))) * siztab[flg & 3];
245 // --- Dump list of tokens on stdout in printable form ---------------------------------------------
248 int dumptok(TOKEN * tk)
259 printf("REG=%ld", *tk++ - 128);
265 case CONST: // CONST <value>
266 printf("CONST=%ld", *tk++);
268 case STRING: // STRING <address>
269 printf("STRING='%s'", (char *)*tk++);
271 case SYMBOL: // SYMBOL <address>
272 printf("SYMBOL='%s'", (char *)*tk++);
274 case EOL: // End of line
277 case TKEOF: // End of file (or macro)
302 printf("%c", (int)tk[-1]);
313 // --- Dump Everything -----------------------------------------------------------------------------
316 int dump_everything(void) {
319 for(i = 1; i < NSECTS; ++i)
320 if(sect[i].scattr & SUSED) {
321 printf("Section %d sloc=$%lx\n", i, sect[i].sloc);
323 chdump(sect[i].sfcode, 1);
326 fudump(sect[i].sffix);
331 printf("\nMarks:\n");
332 mudump(); // Dump marks
333 printf("Total memory allocated=$%lx\n", amemtot);