2 // RMAC - Macro Assembler for all Atari computers
3 // DEBUG.C - Debugging Messages
4 // Copyright (C) 199x Landon Dyer, 2011-2021 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
19 static int siztab[4] = { 3, 5, 9, 9 };
28 if (c < 0x20 || c >= 0x7F)
38 // Print expression, return ptr to just past the ENDEXPR
40 TOKEN * printexpr(TOKEN * tokenptr)
44 while (*tokenptr != ENDEXPR)
46 switch ((int)*tokenptr++)
49 printf("'%s' ", symbolPtr[*tokenptr]->sname);
54 printf("$%lX ", *tp.u64++);
58 printf("ACONST=($%X,$%X) ", *tokenptr, tokenptr[1]);
62 printf("%c ", (char)tokenptr[-1]);
73 // Dump data in a chunk (and maybe others) in the appropriate format
75 int chdump(CHUNK * ch, int format)
79 printf("chloc=$%08X, chsize=$%X\n", ch->chloc, ch->ch_size);
80 mdump(ch->chptr, ch->ch_size, format, ch->chloc);
89 // Dump fixup records in printable format
91 int fudump(FIXUP * fup)
95 uint32_t attr = fup->attr;
96 uint32_t loc = fup->loc;
97 uint16_t file = fup->fileno;
98 uint16_t line = fup->lineno;
100 printf("$%08X $%08X %d.%d: ", attr, loc, (int)file, (int)line);
104 uint16_t esiz = ExpressionLength(fup->expr);
105 printf("(%d long) ", (int)esiz);
106 printexpr(fup->expr);
109 printf("`%s' ;", fup->symbol->sname);
111 if ((attr & FUMASKRISC) == FU_JR)
112 printf(" *=$%X", fup->orgaddr);
137 for(mch=firstmch; mch!=NULL; mch=mch->mcnext)
139 printf("mch=$%p mcptr=$%08X mcalloc=$%X mcused=$%X\n",
140 mch, (mch->mcptr.lw), mch->mcalloc, (mch->mcused));
160 printf("m=$%04X to=%d loc=$%X from=%d siz=%s",
161 w, w & 0x00FF, loc, from, (w & MLONG) ? "long" : "word");
164 printf(" sym=`%s'", symbol->sname);
175 // Dump memory from 'start' for 'count' bytes; `flg' is the following ORed
181 // if `base' is not -1, then print it at the start of each line, incremented
184 int mdump(char * start, LONG count, int flg, LONG base)
189 for(i=0; i<(int)count;)
206 printf("%08X ", base);
212 printf("%02X ", start[i] & 0xFF);
216 printf("%02X%02X ", start[i] & 0xFF, start[i+1] & 0xFF);
220 printf("%02X%02X%02X%02X ", start[i] & 0xFF, start[i+1] & 0xFF,
221 start[i+2] & 0xFF, start[i+3] & 0xFF);
227 base += 1 << (flg & 3);
230 // Print remaining bit of ASCII; the hairy expression computes the number
231 // of spaces to print to make the ASCII line up nicely.
234 k = ((16 - (i - j)) / (1 << (flg & 3))) * siztab[flg & 3];
252 // Dump list of tokens on stdout in printable form
254 int dumptok(TOKEN * tk)
265 printf("REG=%u", *tk++ - 128);
271 case CONST: // CONST <value>
273 printf("CONST=%lu", *tp.u64++);
276 case STRING: // STRING <address>
277 printf("STRING='%s'", string[*tk++]);
279 case SYMBOL: // SYMBOL <address>
280 printf("SYMBOL='%s'", string[*tk++]);
282 case EOL: // End of line
285 case TKEOF: // End of file (or macro)
310 printf("%c", (int)tk[-1]);
321 void DumpTokens(TOKEN * tokenBuffer)
323 // printf("Tokens [%X]: ", sloc);
325 for(TOKEN * t=tokenBuffer; *t!=EOL; t++)
329 else if (*t == CONST)
332 printf("[CONST: $%lX]", *tp.u64);
335 else if (*t == ACONST)
337 printf("[ACONST: $%X, $%X]", (uint32_t)t[1], (uint32_t)t[2]);
340 else if (*t == STRING)
343 printf("[STRING:\"%s\"]", string[*t]);
345 else if (*t == SYMBOL)
348 printf("[SYMBOL:\"%s\"]", string[*t]);
352 else if (*t == TKEOF)
354 else if (*t == DEQUALS)
360 else if (*t == DCOLON)
372 else if (*t == UNMINUS)
382 else if (*t == ENDEXPR)
384 else if (*t == CR_ABSCOUNT)
385 printf("[CR_ABSCOUNT]");
386 else if (*t == CR_FILESIZE)
387 printf("[CR_FILESIZE]");
388 else if (*t == CR_DEFINED)
389 printf("[CR_DEFINED]");
390 else if (*t == CR_REFERENCED)
391 printf("[CR_REFERENCED]");
392 else if (*t == CR_STREQ)
393 printf("[CR_STREQ]");
394 else if (*t == CR_MACDEF)
395 printf("[CR_MACDEF]");
396 else if (*t == CR_TIME)
398 else if (*t == CR_DATE)
400 else if (*t >= 0x20 && *t <= 0x2F)
401 printf("[%c]", (char)*t);
402 else if (*t >= 0x3A && *t <= 0x3F)
403 printf("[%c]", (char)*t);
404 else if (*t >= 0x80 && *t <= 0x87)
405 printf("[D%u]", ((uint32_t)*t) - 0x80);
406 else if (*t >= 0x88 && *t <= 0x8F)
407 printf("[A%u]", ((uint32_t)*t) - 0x88);
409 printf("[%X:%c]", (uint32_t)*t, (char)*t);
419 int dump_everything(void)
422 if ((currentorg[1] - currentorg[0]) == 0)
423 sect[M6502].sfcode = NULL;
425 for(int i=1; i<NSECTS; i++)
427 if (sect[i].scattr & SUSED)
429 printf("Section %d sloc=$%X\n", i, sect[i].sloc);
431 chdump(sect[i].sfcode, 1);
434 fudump(sect[i].sffix);
440 printf("\nMarks:\n");
441 mudump(); // Dump marks