1 ////////////////////////////////////////////////////////////////////////////////////////////////////
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
13 static int siztab[4] = {3, 5, 9, 9};
16 // --- Print 'c' Visibly ---------------------------------------------------------------------------
20 if(c < 0x20 || c >= 0x7f)
29 // --- Print expression, return ptr to just past the ENDEXPR ---------------------------------------
32 TOKEN *printexpr(TOKEN *tp) {
37 printf("`%s' ", ((SYM *)*tp)->sname);
41 printf("$%lx ", *tp++);
44 printf("ACONST=($%lx,$%lx) ", *tp, tp[1]);
48 printf("%c ", (char)tp[-1]);
56 // --- Dump data in a chunk (and maybe others) in the appropriate format ---------------------------
59 int chdump(CHUNK *ch, int format) {
61 printf("chloc=$%08lx, chsize=$%lx\n", ch->chloc, ch->ch_size);
62 mdump(ch->chptr, ch->ch_size, format, ch->chloc);
70 // --- Dump fixup records in printable format ------------------------------------------------------
73 int fudump(CHUNK *ch) {
82 ep = ch->chptr + ch->ch_size;
89 printf("$%04x $%08lx %d.%d: ", (int)attr, loc, (int)file, (int)line);
93 printf("(%d long) ", (int)esiz);
94 p.tk = printexpr(p.tk);
96 printf("`%s' ;\n", (*p.sy)->sname);
107 // --- Dump marks ----------------------------------------------------------------------------------
119 for(mch = firstmch; mch != NULL; mch = mch->mcnext) {
120 printf("mch=$%08lx mcptr=$%08lx mcalloc=$%lx mcused=$%x\n",
141 printf("m=$%04x to=%d loc=$%lx from=%d siz=%s",
142 w, w & 0x00ff, loc, from, (w & MLONG) ? "long" : "word");
145 printf(" sym=`%s'", symbol->sname);
154 // -------------------------------------------------------------------------------------------------
155 // Dump memory from 'start' for 'count' bytes; `flg' is the following ORed together:
160 // if `base' is not -1, then print it at the start of each line, incremented accordingly.
161 // -------------------------------------------------------------------------------------------------
164 int mdump(char *start, LONG count, int flg, LONG base) {
168 for(i = 0; i < (int)count;) {
178 printf("%08lx ", base);
183 printf("%02x ", start[i] & 0xff);
187 printf("%02x%02x ", start[i] & 0xff, start[i+1] & 0xff);
191 printf("%02x%02x%02x%02x ", start[i] & 0xff, start[i+1] & 0xff,
192 start[i+2] & 0xff, start[i+3] & 0xff);
200 base += 1 << (flg & 3);
203 // Print remaining bit of ascii; the hairy expression computes the number of
204 // spaces to print to make the ascii line up nicely.
206 k = ((16 - (i - j)) / (1 << (flg & 3))) * siztab[flg & 3];
219 // --- Dump list of tokens on stdout in printable form ---------------------------------------------
222 int dumptok(TOKEN *tk) {
230 printf("REG=%ld", *tk++ - 128);
235 case CONST: // CONST <value>
236 printf("CONST=%ld", *tk++);
238 case STRING: // STRING <address>
239 printf("STRING='%s'", *tk++);
241 case SYMBOL: // SYMBOL <address>
242 printf("SYMBOL='%s'", *tk++);
244 case EOL: // End of line
247 case TKEOF: // End of file (or macro)
272 printf("%c", tk[-1]);
282 // --- Dump Everything -----------------------------------------------------------------------------
285 int dump_everything(void) {
288 for(i = 1; i < NSECTS; ++i)
289 if(sect[i].scattr & SUSED) {
290 printf("Section %d sloc=$%lx\n", i, sect[i].sloc);
292 chdump(sect[i].sfcode, 1);
295 fudump(sect[i].sffix);
300 printf("\nMarks:\n");
301 mudump(); // Dump marks
302 printf("Total memory allocated=$%lx\n", amemtot);