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("$%lX ", ((uint64_t)tp[0] << 32) | (uint64_t)tp[1]);
54 printf("ACONST=($%X,$%X) ", *tp, tp[1]);
58 printf("%c ", (char)tp[-1]);
69 // Dump data in a chunk (and maybe others) in the appropriate format
71 int chdump(CHUNK * ch, int format)
75 printf("chloc=$%08X, chsize=$%X\n", ch->chloc, ch->ch_size);
76 mdump(ch->chptr, ch->ch_size, format, ch->chloc);
85 // Dump fixup records in printable format
87 int fudump(CHUNK * ch)
94 uint8_t * ep = ch->chptr + ch->ch_size;
98 uint16_t attr = *p.wp++;
99 uint32_t loc = *p.lp++;
100 uint16_t file = *p.wp++;
101 uint16_t line = *p.wp++;
103 printf("$%04X $%08X %d.%d: ", (int)attr, loc, (int)file, (int)line);
107 uint16_t esiz = *p.wp++;
108 printf("(%d long) ", (int)esiz);
109 p.tk = printexpr(p.tk);
113 printf("`%s' ;", (*p.sy)->sname);
117 if ((attr & 0x0F00) == FU_JR)
119 printf(" *=$%X", *p.lp);
147 for(mch=firstmch; mch!=NULL; mch=mch->mcnext)
149 printf("mch=$%p mcptr=$%08X mcalloc=$%X mcused=$%X\n",
150 mch, (mch->mcptr.lw), mch->mcalloc, (mch->mcused));
170 printf("m=$%04X to=%d loc=$%X from=%d siz=%s",
171 w, w & 0x00FF, loc, from, (w & MLONG) ? "long" : "word");
174 printf(" sym=`%s'", symbol->sname);
185 // Dump memory from 'start' for 'count' bytes; `flg' is the following ORed
191 // if `base' is not -1, then print it at the start of each line, incremented
194 int mdump(char * start, LONG count, int flg, LONG base)
199 for(i=0; i<(int)count;)
216 printf("%08X ", base);
222 printf("%02X ", start[i] & 0xff);
226 printf("%02X%02X ", start[i] & 0xff, start[i+1] & 0xff);
230 printf("%02X%02X%02X%02X ", start[i] & 0xff, start[i+1] & 0xff,
231 start[i+2] & 0xff, start[i+3] & 0xff);
239 base += 1 << (flg & 3);
242 // Print remaining bit of ASCII; the hairy expression computes the number
243 // of spaces to print to make the ASCII line up nicely.
246 k = ((16 - (i - j)) / (1 << (flg & 3))) * siztab[flg & 3];
264 // Dump list of tokens on stdout in printable form
266 int dumptok(TOKEN * tk)
277 printf("REG=%u", *tk++ - 128);
283 case CONST: // CONST <value>
284 printf("CONST=%lu", ((uint64_t)tk[0] << 32) | (uint64_t)tk[1]);
287 case STRING: // STRING <address>
288 printf("STRING='%s'", string[*tk++]);
290 case SYMBOL: // SYMBOL <address>
291 printf("SYMBOL='%s'", string[*tk++]);
293 case EOL: // End of line
296 case TKEOF: // End of file (or macro)
321 printf("%c", (int)tk[-1]);
332 void DumpTokens(TOKEN * tokenBuffer)
334 // printf("Tokens [%X]: ", sloc);
336 for(TOKEN * t=tokenBuffer; *t!=EOL; t++)
340 else if (*t == CONST)
342 printf("[CONST: $%lX]", ((uint64_t)t[1] << 32) | (uint64_t)t[2]);
345 else if (*t == ACONST)
347 printf("[ACONST: $%X, $%X]", (uint32_t)t[1], (uint32_t)t[2]);
350 else if (*t == STRING)
353 printf("[STRING:\"%s\"]", string[*t]);
355 else if (*t == SYMBOL)
358 printf("[SYMBOL:\"%s\"]", string[*t]);
362 else if (*t == TKEOF)
364 else if (*t == DEQUALS)
370 else if (*t == DCOLON)
382 else if (*t == UNMINUS)
392 else if (*t == ENDEXPR)
394 else if (*t == CR_ABSCOUNT)
395 printf("[CR_ABSCOUNT]");
396 else if (*t == CR_DEFINED)
397 printf("[CR_DEFINED]");
398 else if (*t == CR_REFERENCED)
399 printf("[CR_REFERENCED]");
400 else if (*t == CR_STREQ)
401 printf("[CR_STREQ]");
402 else if (*t == CR_MACDEF)
403 printf("[CR_MACDEF]");
404 else if (*t == CR_TIME)
406 else if (*t == CR_DATE)
408 else if (*t >= 0x20 && *t <= 0x2F)
409 printf("[%c]", (char)*t);
410 else if (*t >= 0x3A && *t <= 0x3F)
411 printf("[%c]", (char)*t);
412 else if (*t >= 0x80 && *t <= 0x87)
413 printf("[D%u]", ((uint32_t)*t) - 0x80);
414 else if (*t >= 0x88 && *t <= 0x8F)
415 printf("[A%u]", ((uint32_t)*t) - 0x88);
417 printf("[%X:%c]", (uint32_t)*t, (char)*t);
427 int dump_everything(void)
429 for(int i=1; i<NSECTS; i++)
431 if (sect[i].scattr & SUSED)
433 printf("Section %d sloc=$%X\n", i, sect[i].sloc);
435 chdump(sect[i].sfcode, 1);
438 fudump(sect[i].sffix);
444 printf("\nMarks:\n");
445 mudump(); // Dump marks