2 // RMAC - Reboot's Macro Assembler for all Atari computers
3 // DEBUG.C - Debugging Messages
4 // Copyright (C) 199x Landon Dyer, 2011-2018 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
18 static int siztab[4] = { 3, 5, 9, 9 };
27 if (c < 0x20 || c >= 0x7F)
37 // Print expression, return ptr to just past the ENDEXPR
39 TOKEN * printexpr(TOKEN * tokenptr)
43 while (*tokenptr != ENDEXPR)
45 switch ((int)*tokenptr++)
48 printf("'%s' ", symbolPtr[*tokenptr]->sname);
53 printf("$%lX ", *tp.u64++);
57 printf("ACONST=($%X,$%X) ", *tokenptr, tokenptr[1]);
61 printf("%c ", (char)tokenptr[-1]);
72 // Dump data in a chunk (and maybe others) in the appropriate format
74 int chdump(CHUNK * ch, int format)
78 printf("chloc=$%08X, chsize=$%X\n", ch->chloc, ch->ch_size);
79 mdump(ch->chptr, ch->ch_size, format, ch->chloc);
88 // Dump fixup records in printable format
90 int fudump(FIXUP * fup)
94 uint32_t attr = fup->attr;
95 uint32_t loc = fup->loc;
96 uint16_t file = fup->fileno;
97 uint16_t line = fup->lineno;
99 printf("$%08X $%08X %d.%d: ", attr, loc, (int)file, (int)line);
103 uint16_t esiz = ExpressionLength(fup->expr);
104 printf("(%d long) ", (int)esiz);
105 printexpr(fup->expr);
108 printf("`%s' ;", fup->symbol->sname);
110 if ((attr & FUMASKRISC) == FU_JR)
111 printf(" *=$%X", fup->orgaddr);
136 for(mch=firstmch; mch!=NULL; mch=mch->mcnext)
138 printf("mch=$%p mcptr=$%08X mcalloc=$%X mcused=$%X\n",
139 mch, (mch->mcptr.lw), mch->mcalloc, (mch->mcused));
159 printf("m=$%04X to=%d loc=$%X from=%d siz=%s",
160 w, w & 0x00FF, loc, from, (w & MLONG) ? "long" : "word");
163 printf(" sym=`%s'", symbol->sname);
174 // Dump memory from 'start' for 'count' bytes; `flg' is the following ORed
180 // if `base' is not -1, then print it at the start of each line, incremented
183 int mdump(char * start, LONG count, int flg, LONG base)
188 for(i=0; i<(int)count;)
205 printf("%08X ", base);
211 printf("%02X ", start[i] & 0xFF);
215 printf("%02X%02X ", start[i] & 0xFF, start[i+1] & 0xFF);
219 printf("%02X%02X%02X%02X ", start[i] & 0xFF, start[i+1] & 0xFF,
220 start[i+2] & 0xFF, start[i+3] & 0xFF);
228 base += 1 << (flg & 3);
231 // Print remaining bit of ASCII; the hairy expression computes the number
232 // of spaces to print to make the ASCII line up nicely.
235 k = ((16 - (i - j)) / (1 << (flg & 3))) * siztab[flg & 3];
253 // Dump list of tokens on stdout in printable form
255 int dumptok(TOKEN * tk)
266 printf("REG=%u", *tk++ - 128);
272 case CONST: // CONST <value>
274 printf("CONST=%lu", *tp.u64++);
277 case STRING: // STRING <address>
278 printf("STRING='%s'", string[*tk++]);
280 case SYMBOL: // SYMBOL <address>
281 printf("SYMBOL='%s'", string[*tk++]);
283 case EOL: // End of line
286 case TKEOF: // End of file (or macro)
311 printf("%c", (int)tk[-1]);
322 void DumpTokens(TOKEN * tokenBuffer)
324 // printf("Tokens [%X]: ", sloc);
326 for(TOKEN * t=tokenBuffer; *t!=EOL; t++)
330 else if (*t == CONST)
333 printf("[CONST: $%lX]", *tp.u64);
336 else if (*t == ACONST)
338 printf("[ACONST: $%X, $%X]", (uint32_t)t[1], (uint32_t)t[2]);
341 else if (*t == STRING)
344 printf("[STRING:\"%s\"]", string[*t]);
346 else if (*t == SYMBOL)
349 printf("[SYMBOL:\"%s\"]", string[*t]);
353 else if (*t == TKEOF)
355 else if (*t == DEQUALS)
361 else if (*t == DCOLON)
373 else if (*t == UNMINUS)
383 else if (*t == ENDEXPR)
385 else if (*t == CR_ABSCOUNT)
386 printf("[CR_ABSCOUNT]");
387 else if (*t == CR_DEFINED)
388 printf("[CR_DEFINED]");
389 else if (*t == CR_REFERENCED)
390 printf("[CR_REFERENCED]");
391 else if (*t == CR_STREQ)
392 printf("[CR_STREQ]");
393 else if (*t == CR_MACDEF)
394 printf("[CR_MACDEF]");
395 else if (*t == CR_TIME)
397 else if (*t == CR_DATE)
399 else if (*t >= 0x20 && *t <= 0x2F)
400 printf("[%c]", (char)*t);
401 else if (*t >= 0x3A && *t <= 0x3F)
402 printf("[%c]", (char)*t);
403 else if (*t >= 0x80 && *t <= 0x87)
404 printf("[D%u]", ((uint32_t)*t) - 0x80);
405 else if (*t >= 0x88 && *t <= 0x8F)
406 printf("[A%u]", ((uint32_t)*t) - 0x88);
408 printf("[%X:%c]", (uint32_t)*t, (char)*t);
418 int dump_everything(void)
420 for(int i=1; i<NSECTS; i++)
422 if (sect[i].scattr & SUSED)
424 printf("Section %d sloc=$%X\n", i, sect[i].sloc);
426 chdump(sect[i].sfcode, 1);
429 fudump(sect[i].sffix);
435 printf("\nMarks:\n");
436 mudump(); // Dump marks