]> Shamusworld >> Repos - rmac/blobdiff - debug.c
Add support for 64-bit evaluations.
[rmac] / debug.c
diff --git a/debug.c b/debug.c
index 7e60196089b68d11d0c6dbdf823e68a77e70d284..87861b976c7ea5c3f456e2ca50876979269e743f 100644 (file)
--- a/debug.c
+++ b/debug.c
@@ -1,7 +1,7 @@
 //
-// RMAC - Reboot's Macro Assembler for the Atari Jaguar Console System
+// RMAC - Reboot's Macro Assembler for all Atari computers
 // DEBUG.C - Debugging Messages
-// Copyright (C) 199x Landon Dyer, 2011-2012 Reboot and Friends
+// Copyright (C) 199x Landon Dyer, 2011-2017 Reboot and Friends
 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
 // Source utilised with the kind permission of Landon Dyer
 //
@@ -43,12 +43,12 @@ TOKEN * printexpr(TOKEN * tp)
                        switch ((int)*tp++)
                        {
                        case SYMBOL:
-//                             printf("`%s' ", ((SYM *)*tp)->sname);
-                               printf("`%s' ", symbolPtr[*tp]->sname);
+                               printf("'%s' ", symbolPtr[*tp]->sname);
                                tp++;
                                break;
                        case CONST:
-                               printf("$%X ", *tp++);
+                               printf("$%lX ", ((uint64_t)tp[0] << 32) | (uint64_t)tp[1]);
+                               tp += 2;
                                break;
                        case ACONST:
                                printf("ACONST=($%X,$%X) ", *tp, tp[1]);
@@ -61,7 +61,6 @@ TOKEN * printexpr(TOKEN * tp)
                }
        }
 
-//     printf(";\n");
        return tp + 1;
 }
 
@@ -88,28 +87,24 @@ int chdump(CHUNK * ch, int format)
 int fudump(CHUNK * ch)
 {
        PTR p;
-       char * ep;
-       WORD attr, esiz;
-       WORD line, file;
-       LONG loc;
 
        for(; ch!=NULL;)
        {
                p.cp = ch->chptr;
-               ep = ch->chptr + ch->ch_size;
+               uint8_t * ep = ch->chptr + ch->ch_size;
 
                while (p.cp < ep)
                {
-                       attr = *p.wp++;
-                       loc = *p.lp++;
-                       file = *p.wp++;
-                       line = *p.wp++;
+                       uint16_t attr = *p.wp++;
+                       uint32_t loc = *p.lp++;
+                       uint16_t file = *p.wp++;
+                       uint16_t line = *p.wp++;
 
                        printf("$%04X $%08X %d.%d: ", (int)attr, loc, (int)file, (int)line);
 
                        if (attr & FU_EXPR)
                        {
-                               esiz = *p.wp++;
+                               uint16_t esiz = *p.wp++;
                                printf("(%d long) ", (int)esiz);
                                p.tk = printexpr(p.tk);
                        }
@@ -155,7 +150,7 @@ int mudump(void)
                        mch, (mch->mcptr.lw), mch->mcalloc, (mch->mcused));
 
                p = mch->mcptr;
-               
+
                for(;;)
                {
                        w = *p.wp++;
@@ -192,7 +187,7 @@ int mudump(void)
 // 0 - bytes
 // 1 - words
 // 2 - longwords
-// 
+//
 // if `base' is not -1, then print it at the start of each line, incremented
 // accordingly.
 //
@@ -209,7 +204,7 @@ int mdump(char * start, LONG count, int flg, LONG base)
                        {
                                printf("  ");
 
-                               while(j < i)
+                               while (j < i)
                                visprt(start[j++]);
 
                                putchar('\n');
@@ -225,7 +220,7 @@ int mdump(char * start, LONG count, int flg, LONG base)
                {
                case 0:
                        printf("%02X ", start[i] & 0xff);
-                       ++i;
+                       i++;
                        break;
                case 1:
                        printf("%02X%02X ", start[i] & 0xff, start[i+1] & 0xff);
@@ -250,12 +245,12 @@ int mdump(char * start, LONG count, int flg, LONG base)
        {
                k = ((16 - (i - j)) / (1 << (flg & 3))) * siztab[flg & 3];
 
-               while(k--)
+               while (k--)
                        putchar(' ');
 
                printf("  ");
 
-               while(j < i)
+               while (j < i)
                        visprt(start[j++]);
 
                putchar('\n');
@@ -286,39 +281,40 @@ int dumptok(TOKEN * tk)
                switch ((int)*tk++)
                {
                case CONST:                                        // CONST <value>
-                       printf("CONST=%u", *tk++);
+                       printf("CONST=%lu", ((uint64_t)tk[0] << 32) | (uint64_t)tk[1]);
+                       tk += 2;
                        break;
                case STRING:                                       // STRING <address>
                        printf("STRING='%s'", string[*tk++]);
                        break;
-               case SYMBOL:                                       // SYMBOL <address> 
+               case SYMBOL:                                       // SYMBOL <address>
                        printf("SYMBOL='%s'", string[*tk++]);
                        break;
-               case EOL:                                          // End of line 
+               case EOL:                                          // End of line
                        printf("EOL");
                        break;
                case TKEOF:                                        // End of file (or macro)
                        printf("TKEOF");
                        break;
-               case DEQUALS:                                      // == 
+               case DEQUALS:                                      // ==
                        printf("DEQUALS");
                        break;
-               case DCOLON:                                       // :: 
+               case DCOLON:                                       // ::
                        printf("DCOLON");
                        break;
-               case GE:                                           // >= 
+               case GE:                                           // >=
                        printf("GE");
                        break;
-               case LE:                                           // <= 
+               case LE:                                           // <=
                        printf("LE");
                        break;
-               case NE:                                           // <> or != 
+               case NE:                                           // <> or !=
                        printf("NE");
                        break;
-               case SHR:                                          // >> 
+               case SHR:                                          // >>
                        printf("SHR");
                        break;
-               case SHL:                                          // << 
+               case SHL:                                          // <<
                        printf("SHL");
                        break;
                default:
@@ -333,14 +329,104 @@ int dumptok(TOKEN * tk)
 }
 
 
+void DumpTokens(TOKEN * tokenBuffer)
+{
+//     printf("Tokens [%X]: ", sloc);
+
+       for(TOKEN * t=tokenBuffer; *t!=EOL; t++)
+       {
+               if (*t == COLON)
+                       printf("[COLON]");
+               else if (*t == CONST)
+               {
+                       printf("[CONST: $%lX]", ((uint64_t)t[1] << 32) | (uint64_t)t[2]);
+                       t += 2;
+               }
+               else if (*t == ACONST)
+               {
+                       printf("[ACONST: $%X, $%X]", (uint32_t)t[1], (uint32_t)t[2]);
+                       t += 2;
+               }
+               else if (*t == STRING)
+               {
+                       t++;
+                       printf("[STRING:\"%s\"]", string[*t]);
+               }
+               else if (*t == SYMBOL)
+               {
+                       t++;
+                       printf("[SYMBOL:\"%s\"]", string[*t]);
+               }
+               else if (*t == EOS)
+                       printf("[EOS]");
+               else if (*t == TKEOF)
+                       printf("[TKEOF]");
+               else if (*t == DEQUALS)
+                       printf("[DEQUALS]");
+               else if (*t == SET)
+                       printf("[SET]");
+               else if (*t == REG)
+                       printf("[REG]");
+               else if (*t == DCOLON)
+                       printf("[DCOLON]");
+               else if (*t == GE)
+                       printf("[GE]");
+               else if (*t == LE)
+                       printf("[LE]");
+               else if (*t == NE)
+                       printf("[NE]");
+               else if (*t == SHR)
+                       printf("[SHR]");
+               else if (*t == SHL)
+                       printf("[SHL]");
+               else if (*t == UNMINUS)
+                       printf("[UNMINUS]");
+               else if (*t == DOTB)
+                       printf("[DOTB]");
+               else if (*t == DOTW)
+                       printf("[DOTW]");
+               else if (*t == DOTL)
+                       printf("[DOTL]");
+               else if (*t == DOTI)
+                       printf("[DOTI]");
+               else if (*t == ENDEXPR)
+                       printf("[ENDEXPR]");
+               else if (*t == CR_ABSCOUNT)
+                       printf("[CR_ABSCOUNT]");
+               else if (*t == CR_DEFINED)
+                       printf("[CR_DEFINED]");
+               else if (*t == CR_REFERENCED)
+                       printf("[CR_REFERENCED]");
+               else if (*t == CR_STREQ)
+                       printf("[CR_STREQ]");
+               else if (*t == CR_MACDEF)
+                       printf("[CR_MACDEF]");
+               else if (*t == CR_TIME)
+                       printf("[CR_TIME]");
+               else if (*t == CR_DATE)
+                       printf("[CR_DATE]");
+               else if (*t >= 0x20 && *t <= 0x2F)
+                       printf("[%c]", (char)*t);
+               else if (*t >= 0x3A && *t <= 0x3F)
+                       printf("[%c]", (char)*t);
+               else if (*t >= 0x80 && *t <= 0x87)
+                       printf("[D%u]", ((uint32_t)*t) - 0x80);
+               else if (*t >= 0x88 && *t <= 0x8F)
+                       printf("[A%u]", ((uint32_t)*t) - 0x88);
+               else
+                       printf("[%X:%c]", (uint32_t)*t, (char)*t);
+       }
+
+       printf("[EOL]\n");
+}
+
+
 //
 // Dump everything
 //
 int dump_everything(void)
 {
-       int i;
-
-       for(i=1; i<NSECTS; i++)
+       for(int i=1; i<NSECTS; i++)
        {
                if (sect[i].scattr & SUSED)
                {
@@ -357,7 +443,7 @@ int dump_everything(void)
 
        printf("\nMarks:\n");
        mudump();                                                               // Dump marks
-//     printf("Total memory allocated=$%X\n", amemtot);
 
        return 0;
 }
+