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 };
26 if (c < 0x20 || c >= 0x7F)
36 // Print expression, return ptr to just past the ENDEXPR
38 TOKEN * printexpr(TOKEN * tokenptr)
42 while (*tokenptr != ENDEXPR)
44 switch ((int)*tokenptr++)
47 printf("'%s' ", symbolPtr[*tokenptr]->sname);
52 printf("$%lX ", *tp.u64++);
56 printf("ACONST=($%X,$%X) ", *tokenptr, tokenptr[1]);
60 printf("%c ", (char)tokenptr[-1]);
71 // Dump data in a chunk (and maybe others) in the appropriate format
73 int chdump(CHUNK * ch, int format)
77 printf("chloc=$%08X, chsize=$%X\n", ch->chloc, ch->ch_size);
78 mdump(ch->chptr, ch->ch_size, format, ch->chloc);
87 // Dump fixup records in printable format
89 int fudump(CHUNK * ch)
96 uint8_t * ep = ch->chptr + ch->ch_size;
100 uint16_t attr = *p.wp++;
101 uint32_t loc = *p.lp++;
102 uint16_t file = *p.wp++;
103 uint16_t line = *p.wp++;
105 printf("$%04X $%08X %d.%d: ", (int)attr, loc, (int)file, (int)line);
109 uint16_t esiz = *p.wp++;
110 printf("(%d long) ", (int)esiz);
111 p.tk = printexpr(p.tk);
115 printf("`%s' ;", (*p.sy)->sname);
119 if ((attr & 0x0F00) == FU_JR)
121 printf(" *=$%X", *p.lp);
149 for(mch=firstmch; mch!=NULL; mch=mch->mcnext)
151 printf("mch=$%p mcptr=$%08X mcalloc=$%X mcused=$%X\n",
152 mch, (mch->mcptr.lw), mch->mcalloc, (mch->mcused));
172 printf("m=$%04X to=%d loc=$%X from=%d siz=%s",
173 w, w & 0x00FF, loc, from, (w & MLONG) ? "long" : "word");
176 printf(" sym=`%s'", symbol->sname);
187 // Dump memory from 'start' for 'count' bytes; `flg' is the following ORed
193 // if `base' is not -1, then print it at the start of each line, incremented
196 int mdump(char * start, LONG count, int flg, LONG base)
201 for(i=0; i<(int)count;)
218 printf("%08X ", base);
224 printf("%02X ", start[i] & 0xFF);
228 printf("%02X%02X ", start[i] & 0xFF, start[i+1] & 0xFF);
232 printf("%02X%02X%02X%02X ", start[i] & 0xFF, start[i+1] & 0xFF,
233 start[i+2] & 0xFF, start[i+3] & 0xFF);
241 base += 1 << (flg & 3);
244 // Print remaining bit of ASCII; the hairy expression computes the number
245 // of spaces to print to make the ASCII line up nicely.
248 k = ((16 - (i - j)) / (1 << (flg & 3))) * siztab[flg & 3];
266 // Dump list of tokens on stdout in printable form
268 int dumptok(TOKEN * tk)
279 printf("REG=%u", *tk++ - 128);
285 case CONST: // CONST <value>
287 printf("CONST=%lu", *tp.u64++);
290 case STRING: // STRING <address>
291 printf("STRING='%s'", string[*tk++]);
293 case SYMBOL: // SYMBOL <address>
294 printf("SYMBOL='%s'", string[*tk++]);
296 case EOL: // End of line
299 case TKEOF: // End of file (or macro)
324 printf("%c", (int)tk[-1]);
335 void DumpTokens(TOKEN * tokenBuffer)
337 // printf("Tokens [%X]: ", sloc);
339 for(TOKEN * t=tokenBuffer; *t!=EOL; t++)
343 else if (*t == CONST)
346 printf("[CONST: $%lX]", *tp.u64);
349 else if (*t == ACONST)
351 printf("[ACONST: $%X, $%X]", (uint32_t)t[1], (uint32_t)t[2]);
354 else if (*t == STRING)
357 printf("[STRING:\"%s\"]", string[*t]);
359 else if (*t == SYMBOL)
362 printf("[SYMBOL:\"%s\"]", string[*t]);
366 else if (*t == TKEOF)
368 else if (*t == DEQUALS)
374 else if (*t == DCOLON)
386 else if (*t == UNMINUS)
396 else if (*t == ENDEXPR)
398 else if (*t == CR_ABSCOUNT)
399 printf("[CR_ABSCOUNT]");
400 else if (*t == CR_DEFINED)
401 printf("[CR_DEFINED]");
402 else if (*t == CR_REFERENCED)
403 printf("[CR_REFERENCED]");
404 else if (*t == CR_STREQ)
405 printf("[CR_STREQ]");
406 else if (*t == CR_MACDEF)
407 printf("[CR_MACDEF]");
408 else if (*t == CR_TIME)
410 else if (*t == CR_DATE)
412 else if (*t >= 0x20 && *t <= 0x2F)
413 printf("[%c]", (char)*t);
414 else if (*t >= 0x3A && *t <= 0x3F)
415 printf("[%c]", (char)*t);
416 else if (*t >= 0x80 && *t <= 0x87)
417 printf("[D%u]", ((uint32_t)*t) - 0x80);
418 else if (*t >= 0x88 && *t <= 0x8F)
419 printf("[A%u]", ((uint32_t)*t) - 0x88);
421 printf("[%X:%c]", (uint32_t)*t, (char)*t);
431 int dump_everything(void)
433 for(int i=1; i<NSECTS; i++)
435 if (sect[i].scattr & SUSED)
437 printf("Section %d sloc=$%X\n", i, sect[i].sloc);
439 chdump(sect[i].sfcode, 1);
442 fudump(sect[i].sffix);
448 printf("\nMarks:\n");
449 mudump(); // Dump marks