2 // RMAC - Reboot's Macro Assembler for all Atari computers
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]);
330 void DumpTokens(TOKEN * tokenBuffer)
332 // printf("Tokens [%X]: ", sloc);
334 for(TOKEN * t=tokenBuffer; *t!=EOL; t++)
338 else if (*t == CONST)
341 printf("[CONST: $%X]", (uint32_t)*t);
343 else if (*t == ACONST)
345 printf("[ACONST: $%X, $%X]", (uint32_t)t[1], (uint32_t)t[2]);
348 else if (*t == STRING)
351 printf("[STRING:\"%s\"]", string[*t]);
353 else if (*t == SYMBOL)
356 printf("[SYMBOL:\"%s\"]", string[*t]);
360 else if (*t == TKEOF)
362 else if (*t == DEQUALS)
368 else if (*t == DCOLON)
380 else if (*t == UNMINUS)
390 else if (*t == ENDEXPR)
392 else if (*t == CR_ABSCOUNT)
393 printf("[CR_ABSCOUNT]");
394 else if (*t == CR_DEFINED)
395 printf("[CR_DEFINED]");
396 else if (*t == CR_REFERENCED)
397 printf("[CR_REFERENCED]");
398 else if (*t == CR_STREQ)
399 printf("[CR_STREQ]");
400 else if (*t == CR_MACDEF)
401 printf("[CR_MACDEF]");
402 else if (*t == CR_TIME)
404 else if (*t == CR_DATE)
406 else if (*t >= 0x20 && *t <= 0x2F)
407 printf("[%c]", (char)*t);
408 else if (*t >= 0x3A && *t <= 0x3F)
409 printf("[%c]", (char)*t);
410 else if (*t >= 0x80 && *t <= 0x87)
411 printf("[D%u]", ((uint32_t)*t) - 0x80);
412 else if (*t >= 0x88 && *t <= 0x8F)
413 printf("[A%u]", ((uint32_t)*t) - 0x88);
415 printf("[%X:%c]", (uint32_t)*t, (char)*t);
425 int dump_everything(void)
427 for(int i=1; i<NSECTS; i++)
429 if (sect[i].scattr & SUSED)
431 printf("Section %d sloc=$%X\n", i, sect[i].sloc);
433 chdump(sect[i].sfcode, 1);
436 fudump(sect[i].sffix);
442 printf("\nMarks:\n");
443 mudump(); // Dump marks