2 // RMAC - Reboot's Macro Assembler for the Atari Jaguar Console System
3 // DEBUG.C - Debugging Messages
4 // Copyright (C) 199x Landon Dyer, 2011-2017 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' ", symbolPtr[*tp]->sname);
50 printf("$%X ", *tp++);
53 printf("ACONST=($%X,$%X) ", *tp, tp[1]);
57 printf("%c ", (char)tp[-1]);
68 // Dump data in a chunk (and maybe others) in the appropriate format
70 int chdump(CHUNK * ch, int format)
74 printf("chloc=$%08X, chsize=$%X\n", ch->chloc, ch->ch_size);
75 mdump(ch->chptr, ch->ch_size, format, ch->chloc);
84 // Dump fixup records in printable format
86 int fudump(CHUNK * ch)
93 uint8_t * ep = ch->chptr + ch->ch_size;
97 uint16_t attr = *p.wp++;
98 uint32_t loc = *p.lp++;
99 uint16_t file = *p.wp++;
100 uint16_t line = *p.wp++;
102 printf("$%04X $%08X %d.%d: ", (int)attr, loc, (int)file, (int)line);
106 uint16_t esiz = *p.wp++;
107 printf("(%d long) ", (int)esiz);
108 p.tk = printexpr(p.tk);
112 printf("`%s' ;", (*p.sy)->sname);
116 if ((attr & 0x0F00) == FU_JR)
118 printf(" *=$%X", *p.lp);
146 for(mch=firstmch; mch!=NULL; mch=mch->mcnext)
148 printf("mch=$%p mcptr=$%08X mcalloc=$%X mcused=$%X\n",
149 mch, (mch->mcptr.lw), mch->mcalloc, (mch->mcused));
169 printf("m=$%04X to=%d loc=$%X from=%d siz=%s",
170 w, w & 0x00FF, loc, from, (w & MLONG) ? "long" : "word");
173 printf(" sym=`%s'", symbol->sname);
184 // Dump memory from 'start' for 'count' bytes; `flg' is the following ORed
190 // if `base' is not -1, then print it at the start of each line, incremented
193 int mdump(char * start, LONG count, int flg, LONG base)
198 for(i=0; i<(int)count;)
215 printf("%08X ", base);
221 printf("%02X ", start[i] & 0xff);
225 printf("%02X%02X ", start[i] & 0xff, start[i+1] & 0xff);
229 printf("%02X%02X%02X%02X ", start[i] & 0xff, start[i+1] & 0xff,
230 start[i+2] & 0xff, start[i+3] & 0xff);
238 base += 1 << (flg & 3);
241 // Print remaining bit of ASCII; the hairy expression computes the number
242 // of spaces to print to make the ASCII line up nicely.
245 k = ((16 - (i - j)) / (1 << (flg & 3))) * siztab[flg & 3];
263 // Dump list of tokens on stdout in printable form
265 int dumptok(TOKEN * tk)
276 printf("REG=%u", *tk++ - 128);
282 case CONST: // CONST <value>
283 printf("CONST=%u", *tk++);
285 case STRING: // STRING <address>
286 printf("STRING='%s'", string[*tk++]);
288 case SYMBOL: // SYMBOL <address>
289 printf("SYMBOL='%s'", string[*tk++]);
291 case EOL: // End of line
294 case TKEOF: // End of file (or macro)
319 printf("%c", (int)tk[-1]);
333 int dump_everything(void)
335 for(int i=1; i<NSECTS; i++)
337 if (sect[i].scattr & SUSED)
339 printf("Section %d sloc=$%X\n", i, sect[i].sloc);
341 chdump(sect[i].sfcode, 1);
344 fudump(sect[i].sffix);
350 printf("\nMarks:\n");
351 mudump(); // Dump marks