]> Shamusworld >> Repos - stargem2/blobdiff - src/dis6809.cpp
Finally fixed problems with demo mode.
[stargem2] / src / dis6809.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 320f9f2..f2a9a76
@@ -1,15 +1,14 @@
 //
 // 6809 disassembler
 //
-// by James L. Hammons
-//
-// (c) 2004 Underground Software
+// by James Hammons
+// (C) 2004 Underground Software
 //
 
 #include "dis6809.h"
 
 #include <stdio.h>
-#include <string>
+#include <string.h>
 #include "v6809.h"
 #include "log.h"
 
@@ -191,36 +190,37 @@ iregs[4][2] = {"X", "Y", "U", "S" };
 //
 // Display bytes in mem in hex
 //
-static void DisplayBytes(uint16 src, uint32 dst)
+static void DisplayBytes(uint16_t src, uint32_t dst)
 {
+       char buf[20], buf2[20];
+
+       buf[0] = 0;
        WriteLog("%04X: ", src);
-       uint8 cnt = 0;                                                                          // Init counter...
 
        if (src > dst)
                dst += 0x10000;                                                                 // That should fix the FFFF bug...
 
-       for(uint32 i=src; i<dst; i++)
+       for(uint32_t i=src; i<dst; i++)
        {
-               WriteLog("%02X ", mainCPU.RdMem(i));
-               cnt++;                                                                                  // Bump counter...
+               sprintf(buf2, "%02X ", mainCPU.RdMem(i));
+               strcat(buf, buf2);
        }
 
-       for(int i=cnt; i<5; i++)                                                        // Pad the leftover spaces...
-               WriteLog("   ");
+       WriteLog("%-12s", buf);                                                         // WAS: 15
 }
 
 //
 // Decode a 6809 instruction at 'addr'
 //
-int Decode6809(uint16 pc)
+int Decode6809(uint16_t pc)
 {
        char outbuf[80], mnem[6], tmp[30];
-       uint8 opcode2, operand;
+       uint8_t opcode2, operand;
 
-       uint16 addr = pc;
+       uint16_t addr = pc, offset;
 
-       uint8 opcode = mainCPU.RdMem(addr++);                           // Get the opcode
-       uint8 admode = op_mat1[opcode];                                         // addressing mode
+       uint8_t opcode = mainCPU.RdMem(addr++);                         // Get the opcode
+       uint8_t admode = op_mat1[opcode];                                       // addressing mode
        strcpy(mnem, mnemonics[opcode]);                                        // Copy page 1 opcode
 
        if (opcode == 0x10)                                                                     // Extended opcode?
@@ -245,13 +245,23 @@ int Decode6809(uint16 pc)
                sprintf(outbuf, "%s $%02X", mnem, mainCPU.RdMem(addr++));
                break;
        case 2:                                                                                         // Absolute
-               sprintf(outbuf, "%s $%04X", mnem, (mainCPU.RdMem(addr++) << 8) | mainCPU.RdMem(addr++));
+//             sprintf(outbuf, "%s $%04X", mnem, (mainCPU.RdMem(addr++) << 8) | mainCPU.RdMem(addr++));
+               offset = (mainCPU.RdMem(addr) << 8) | mainCPU.RdMem(addr + 1);
+               addr += 2;
+               sprintf(outbuf, "%s $%04X", mnem, offset);
                break;
        case 3:                                                                                         // Relative
-               sprintf(outbuf, "%s $%04X", mnem, ++addr + (int16)(int8)mainCPU.RdMem(addr));
+//DISNOWOK--FIX
+//             sprintf(outbuf, "%s $%04X", mnem, ++addr + (int16)((int8)mainCPU.RdMem(addr)));
+               offset = addr + 1 + (int16_t)(int8_t)mainCPU.RdMem(addr);
+               addr++;
+               sprintf(outbuf, "%s $%04X", mnem, offset);
                break;
        case 4:                                                                                         // Long Relative
-               sprintf(outbuf, "%s $%04X", mnem, addr + (int16)((mainCPU.RdMem(addr++) << 8) | mainCPU.RdMem(addr++)) + 2);
+//             sprintf(outbuf, "%s $%04X", mnem, addr + (int16)((mainCPU.RdMem(addr++) << 8) | mainCPU.RdMem(addr++)) + 2);
+               offset = addr + (int16_t)((mainCPU.RdMem(addr) << 8) | mainCPU.RdMem(addr + 1)) + 2;
+               addr += 2;
+               sprintf(outbuf, "%s $%04X", mnem, offset);
                break;
        case 5:                                                                                         // Inherent
                sprintf(outbuf, "%s ", mnem);
@@ -278,9 +288,9 @@ int Decode6809(uint16 pc)
        case 7:                                                                                         // Indexed (the tough one!)
        {
                operand = mainCPU.RdMem(addr++);                                // Get IDX byte
-               uint8 reg = ((operand & 0x60) >> 5), idxind = ((operand & 0x10) >> 4),
+               uint8_t reg = ((operand & 0x60) >> 5), idxind = ((operand & 0x10) >> 4),
                        lo_nyb = (operand & 0x0F),  boff;
-               uint16 woff;
+               uint16_t woff;
 
                strcpy(tmp, "??");
                if (!(operand & 0x80))                                                  // Hi bit set? Then decode 4 bit offset
@@ -301,7 +311,8 @@ int Decode6809(uint16 pc)
                                        sprintf(tmp, "($%02X,%s)", boff, iregs[reg]);
                                        break;
                                case 9:
-                                       woff = (mainCPU.RdMem(addr++) << 8) | mainCPU.RdMem(addr++);
+                                       woff = (mainCPU.RdMem(addr) << 8) | mainCPU.RdMem(addr + 1);
+                                       addr += 2;
                                        sprintf(tmp, "($%04X,%s)", woff, iregs[reg]);
                                        break;
                                case 11:  sprintf(tmp, "(D,%s)", iregs[reg]);  break;
@@ -309,12 +320,14 @@ int Decode6809(uint16 pc)
                                        boff = mainCPU.RdMem(addr++);
                                        sprintf(tmp, "($%02X,PC)", boff);
                                        break;
-                               case 13:  
-                                       woff = (mainCPU.RdMem(addr++) << 8) | mainCPU.RdMem(addr++);
+                               case 13:
+                                       woff = (mainCPU.RdMem(addr) << 8) | mainCPU.RdMem(addr + 1);
+                                       addr += 2;
                                        sprintf(tmp, "($%04X,PC)", woff);
                                        break;
                                case 15:
-                                       woff = (mainCPU.RdMem(addr++) << 8) | mainCPU.RdMem(addr++);
+                                       woff = (mainCPU.RdMem(addr) << 8) | mainCPU.RdMem(addr + 1);
+                                       addr += 2;
                                        sprintf(tmp, "[$%04X]", woff);
                                        break;
                                default:
@@ -337,7 +350,8 @@ int Decode6809(uint16 pc)
                                        sprintf(tmp, "($%02X),%s", boff, iregs[reg]);
                                        break;
                                case 9:
-                                       woff = (mainCPU.RdMem(addr++) << 8) | mainCPU.RdMem(addr++);
+                                       woff = (mainCPU.RdMem(addr) << 8) | mainCPU.RdMem(addr + 1);
+                                       addr += 2;
                                        sprintf(tmp, "($%04X),%s", woff, iregs[reg]);
                                        break;
                                case 11:
@@ -347,8 +361,9 @@ int Decode6809(uint16 pc)
                                        boff = mainCPU.RdMem(addr++);
                                        sprintf(tmp, "($%02X),PC", boff);
                                        break;
-                               case 13:  
-                                       woff = (mainCPU.RdMem(addr++) << 8) | mainCPU.RdMem(addr++);
+                               case 13:
+                                       woff = (mainCPU.RdMem(addr) << 8) | mainCPU.RdMem(addr + 1);
+                                       addr += 2;
                                        sprintf(tmp, "($%04X),PC", woff);
                                        break;
                                default:
@@ -363,12 +378,15 @@ int Decode6809(uint16 pc)
                sprintf(outbuf, "%s #$%02X", mnem, mainCPU.RdMem(addr++));
                break;
        case 9:                                                                                         // Long Immediate
-               sprintf(outbuf, "%s #$%04X", mnem, (mainCPU.RdMem(addr++) << 8) | mainCPU.RdMem(addr++));
+//             sprintf(outbuf, "%s #$%04X", mnem, (mainCPU.RdMem(addr++) << 8) | mainCPU.RdMem(addr++));
+               offset = (mainCPU.RdMem(addr) << 8) | mainCPU.RdMem(addr + 1);
+               addr += 2;
+               sprintf(outbuf, "%s #$%04X", mnem, offset);
                break;
        }
 
        DisplayBytes(pc, addr);                                                         // Show bytes
-       WriteLog("%s", outbuf);                                                         // Display opcode & addressing, etc.
+       WriteLog("%-17s", outbuf);                                                      // Display opcode & addressing, etc.
 
        return addr - pc;
 }