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);
144 for(mch=firstmch; mch!=NULL; mch=mch->mcnext)
146 printf("mch=$%08ux mcptr=$%08ux mcalloc=$%ux mcused=$%x\n",
170 printf("m=$%04x to=%d loc=$%ux from=%d siz=%s",
171 w, w & 0x00ff, loc, from, (w & MLONG) ? "long" : "word");
174 printf(" sym=`%s'", symbol->sname);
185 // Dump memory from 'start' for 'count' bytes; `flg' is the following ORed together:
190 // if `base' is not -1, then print it at the start of each line, incremented accordingly.
192 int mdump(char * start, LONG count, int flg, LONG base)
197 for(i=0; i<(int)count;)
214 printf("%08ux ", base);
220 printf("%02x ", start[i] & 0xff);
224 printf("%02x%02x ", start[i] & 0xff, start[i+1] & 0xff);
228 printf("%02x%02x%02x%02x ", start[i] & 0xff, start[i+1] & 0xff,
229 start[i+2] & 0xff, start[i+3] & 0xff);
237 base += 1 << (flg & 3);
240 // Print remaining bit of ascii; the hairy expression computes the number of
241 // spaces to print to make the ascii line up nicely.
244 k = ((16 - (i - j)) / (1 << (flg & 3))) * siztab[flg & 3];
262 // Dump list of tokens on stdout in printable form
264 int dumptok(TOKEN * tk)
275 printf("REG=%ud", *tk++ - 128);
281 case CONST: // CONST <value>
282 printf("CONST=%ud", *tk++);
284 case STRING: // STRING <address>
285 // printf("STRING='%s'", (char *)*tk++);
286 printf("STRING='%s'", string[*tk++]);
288 case SYMBOL: // SYMBOL <address>
289 // printf("SYMBOL='%s'", (char *)*tk++);
290 printf("SYMBOL='%s'", string[*tk++]);
292 case EOL: // End of line
295 case TKEOF: // End of file (or macro)
320 printf("%c", (int)tk[-1]);
334 int dump_everything(void)
338 for(i=1; i<NSECTS; i++)
340 if (sect[i].scattr & SUSED)
342 printf("Section %d sloc=$%ux\n", i, sect[i].sloc);
344 chdump(sect[i].sfcode, 1);
347 fudump(sect[i].sffix);
353 printf("\nMarks:\n");
354 mudump(); // Dump marks
355 printf("Total memory allocated=$%ux\n", amemtot);