]> Shamusworld >> Repos - thunder/commitdiff
Added missing files... D'oh!
authorShamus Hammons <jlhamm@acm.org>
Thu, 13 Aug 2009 13:55:41 +0000 (13:55 +0000)
committerShamus Hammons <jlhamm@acm.org>
Thu, 13 Aug 2009 13:55:41 +0000 (13:55 +0000)
src/dis6809.cpp [new file with mode: 0755]
src/dis6809.h [new file with mode: 0755]
src/thunder.cpp

diff --git a/src/dis6809.cpp b/src/dis6809.cpp
new file mode 100755 (executable)
index 0000000..d598e2c
--- /dev/null
@@ -0,0 +1,393 @@
+//
+// 6809 disassembler
+//
+// by James L. Hammons
+//
+// (c) 2004 Underground Software
+//
+
+#include "dis6809.h"
+
+#include <stdio.h>
+#include <string.h>
+//#include "v6809.h"
+#include "log.h"
+
+using namespace std;
+
+// External shit
+
+//NO MORE!!! extern V6809REGS mainCPU;//Hm.
+
+static char op_mat1[256] = {
+       1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
+       0, 0, 5, 5, 0, 0, 4, 4, 0, 5, 8, 0, 8, 5, 6, 6,
+       3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+       7, 7, 7, 7, 6, 6, 6, 6, 0, 5, 5, 5, 8, 5, 5, 5,
+       5, 0, 0, 5, 5, 0, 5, 5, 5, 5, 5, 0, 5, 5, 0, 5,
+       5, 0, 0, 5, 5, 0, 5, 5, 5, 5, 5, 0, 5, 5, 0, 5,
+       7, 0, 0, 7, 7, 0, 7, 7, 7, 7, 7, 0, 7, 7, 7, 7,
+       2, 0, 0, 2, 2, 0, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2,
+       8, 8, 8, 9, 8, 8, 8, 0, 8, 8, 8, 8, 9, 3, 9, 0,
+       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+       7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+       8, 8, 8, 9, 8, 8, 8, 0, 8, 8, 8, 8, 9, 0, 9, 0,
+       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+       7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
+},
+
+op_mat2[256] = {
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 9, 0,
+       0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1,
+       0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 7, 7,
+       0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 2,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2
+},
+
+op_mat3[256] = {
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0,
+       0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
+       0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0,
+       0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+static char mnemonics[256][6] = {
+       "NEG  ","???  ","???  ","COM  ","LSR  ","???  ","ROR  ","ASR  ",
+       "LSL  ","ROL  ","DEC  ","???  ","INC  ","TST  ","JMP  ","CLR  ",
+       "PAGE1","PAGE2","NOP  ","SYNC ","???  ","???  ","LBRA ","LBSR ",
+       "???  ","DAA  ","ORCC ","???  ","ANDCC","SEX  ","EXG  ","TFR  ",
+       "BRA  ","BRN  ","BHI  ","BLS  ","BHS  ","BLO  ","BNE  ","BEQ  ",
+       "BVC  ","BVS  ","BPL  ","BMI  ","BGE  ","BLT  ","BGT  ","BLE  ",
+       "LEAX ","LEAY ","LEAS ","LEAU ","PSHS ","PULS ","PSHU ","PULU ",
+       "???  ","RTS  ","ABX  ","RTI  ","CWAI ","MUL  ","RESET","SWI  ",
+       "NEGA ","???  ","???  ","COMA ","LSRA ","???  ","RORA ","ASRA ",
+       "LSLA ","ROLA ","DECA ","???  ","INCA ","TSTA ","???  ","CLRA ",
+       "NEGB ","???  ","???  ","COMB ","LSRB ","???  ","RORB ","ASRB ",
+       "LSLB ","ROLB ","DECB ","???  ","INCB ","TSTB ","???  ","CLRB ",
+       "NEG  ","???  ","???  ","COM  ","LSR  ","???  ","ROR  ","ASR  ",
+       "LSL  ","ROL  ","DEC  ","???  ","INC  ","TST  ","JMP  ","CLR  ",
+       "NEG  ","???  ","???  ","COM  ","LSR  ","???  ","ROR  ","ASR  ",
+       "LSL  ","ROL  ","DEC  ","???  ","INC  ","TST  ","JMP  ","CLR  ",
+       "SUBA ","CMPA ","SCBA ","SUBD ","ANDA ","BITA ","LDA  ","???  ",
+       "EORA ","ADCA ","ORA  ","ADDA ","CMPX ","BSR  ","LDX  ","???  ",
+       "SUBA ","CMPA ","SBCA ","SUBD ","ANDA ","BITA ","LDA  ","STA  ",
+       "EORA ","ADCA ","ORA  ","ADDA ","CMPX ","JSR  ","LDX  ","STX  ",
+       "SUBA ","CMPA ","SBCA ","SUBD ","ANDA ","BITA ","LDA  ","STA  ",
+       "EORA ","ADCA ","ORA  ","ADDA ","CMPX ","JSR  ","LDX  ","STX  ",
+       "SUBA ","CMPA ","SBCA ","SUBD ","ANDA ","BITA ","LDA  ","STA  ",
+       "EORA ","ADCA ","ORA  ","ADDA ","CMPX ","JSR  ","LDX  ","STX  ",
+       "SUBB ","CMPB ","SCBB ","ADDD ","ANDB ","BITB ","LDB  ","???  ",
+       "EORB ","ADCB ","ORB  ","ADDB ","LDD  ","???  ","LDU  ","???  ",
+       "SUBB ","CMPB ","SBCB ","ADDD ","ANDB ","BITB ","LDB  ","STB  ",
+       "EORB ","ADCB ","ORB  ","ADDB ","LDD  ","STD  ","LDU  ","STU  ",
+       "SUBB ","CMPB ","SBCB ","ADDD ","ANDB ","BITB ","LDB  ","STB  ",
+       "EORB ","ADCB ","ORB  ","ADDB ","LDD  ","STD  ","LDU  ","STU  ",
+       "SUBB ","CMPB ","SBCB ","ADDD ","ANDB ","BITB ","LDB  ","STB  ",
+       "EORB ","ADCB ","ORB  ","ADDB ","LDD  ","STD  ","LDU  ","STU  "
+},
+
+mnemonics2[256][6] = {
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","LBRN ","LBHI ","LBLS ","LBHS ","LBLO ","LBNE ","LBEQ ",
+       "LBVC ","LBVS ","LBPL ","LBMI ","LBGE ","LBLT ","LBGT ","LBLE ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","SWI2 ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","CMPD ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","CMPY ","???  ","LDY  ","???  ",
+       "???  ","???  ","???  ","CMPD ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","CMPY ","???  ","LDY  ","STY  ",
+       "???  ","???  ","???  ","CMPD ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","CMPY ","???  ","LDY  ","STY  ",
+       "???  ","???  ","???  ","CMPD ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","CMPY ","???  ","LDY  ","STY  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","LDS  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","LDS  ","STS  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","LDS  ","STS  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","LDS  ","STS  "
+},
+
+mnemonics3[256][6] = {
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","SWI3 ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","CMPU ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","CMPS ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","CMPU ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","CMPS ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","CMPU ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","CMPS ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","CMPU ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","CMPS ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  ",
+       "???  ","???  ","???  ","???  ","???  ","???  ","???  ","???  "
+},
+
+tregs[16][3] = {
+       "D",  "X", "Y",  "U",  "S",  "PC", "??", "??",
+       "A",  "B", "CC", "DP", "??", "??", "??", "??"
+},
+
+iregs[4][2] = {"X", "Y", "U", "S" };
+
+//
+// Display bytes in mem in hex
+//
+static void DisplayBytes(V6809REGS regs, uint16 src, uint32 dst)
+{
+       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++)
+       {
+               WriteLog("%02X ", regs.RdMem(i));
+               cnt++;                                                                                  // Bump counter...
+       }
+
+       for(int i=cnt; i<5; i++)                                                        // Pad the leftover spaces...
+               WriteLog("   ");
+}
+
+//
+// Decode a 6809 instruction at 'addr'
+//
+//int Decode6809(uint16 pc)
+int Decode6809(V6809REGS regs)
+{
+       char outbuf[80], mnem[6], tmp[30];
+       uint8 opcode2, operand;
+
+       uint16 addr = regs.pc, offset;
+
+       uint8 opcode = regs.RdMem(addr++);                              // Get the opcode
+       uint8 admode = op_mat1[opcode];                                         // addressing mode
+       strcpy(mnem, mnemonics[opcode]);                                        // Copy page 1 opcode
+
+       if (opcode == 0x10)                                                                     // Extended opcode?
+       {
+               opcode2 = regs.RdMem(addr++);                           // Then get next byte
+               admode = op_mat2[opcode2];                                              // And use it as index into 'op_mat2'
+               strcpy(mnem, mnemonics2[opcode2]);                              // Overwrite mnemonic
+       }
+       else if (opcode == 0x11)                                                        // Same as above...
+       {
+               opcode2 = regs.RdMem(addr++);
+               admode = op_mat3[opcode2];
+               strcpy(mnem, mnemonics3[opcode2]);                              // Overwrite mnemonic
+       }
+
+       switch (admode)                                                                         // Decode it...
+       {
+       case 0:                                                                                         // Illegal
+               sprintf(outbuf, "???");
+               break;
+       case 1:                                                                                         // Zero page
+               sprintf(outbuf, "%s $%02X", mnem, regs.RdMem(addr++));
+               break;
+       case 2:                                                                                         // Absolute
+//             sprintf(outbuf, "%s $%04X", mnem, (regs.RdMem(addr++) << 8) | regs.RdMem(addr++));
+               offset = (regs.RdMem(addr) << 8) | regs.RdMem(addr + 1);
+               addr += 2;
+               sprintf(outbuf, "%s $%04X", mnem, offset);
+               break;
+       case 3:                                                                                         // Relative
+//DISNOWOK--FIX
+//             sprintf(outbuf, "%s $%04X", mnem, ++addr + (int16)((int8)regs.RdMem(addr)));
+               offset = addr + 1 + (int16)(int8)regs.RdMem(addr);
+               addr++;
+               sprintf(outbuf, "%s $%04X", mnem, offset);
+               break;
+       case 4:                                                                                         // Long Relative
+//             sprintf(outbuf, "%s $%04X", mnem, addr + (int16)((regs.RdMem(addr++) << 8) | regs.RdMem(addr++)) + 2);
+               offset = addr + (int16)((regs.RdMem(addr) << 8) | regs.RdMem(addr + 1)) + 2;
+               addr += 2;
+               sprintf(outbuf, "%s $%04X", mnem, offset);
+               break;
+       case 5:                                                                                         // Inherent
+               sprintf(outbuf, "%s ", mnem);
+               break;
+       case 6:                                                                                         // Txfr/exchg/push/pull
+               operand = regs.RdMem(addr++);                           // Get txfr/exg/push/pull byte
+               if ((opcode == 0x1E) || (opcode == 0x1F))               // Is it TXF/EXG?
+                       sprintf(tmp, "%s,%s", tregs[operand >> 4], tregs[operand & 0x0F]);
+               else
+               {
+                       tmp[0] = 0;
+                       if (operand & 0x01)  strcat(tmp, "CC ");
+                       if (operand & 0x02)  strcat(tmp, "A ");
+                       if (operand & 0x04)  strcat(tmp, "B ");
+                       if (operand & 0x08)  strcat(tmp, "DP ");
+                       if (operand & 0x10)  strcat(tmp, "X ");
+                       if (operand & 0x20)  strcat(tmp, "Y ");
+                       if (operand & 0x40)  (((opcode == 0x34) || (opcode == 0x35)) ? strcat(tmp, "U ") : strcat(tmp, "S "));
+                       if (operand & 0x80)  strcat(tmp, "PC");
+               }
+
+               sprintf(outbuf, "%s %s", mnem, tmp);
+               break;
+       case 7:                                                                                         // Indexed (the tough one!)
+       {
+               operand = regs.RdMem(addr++);                           // Get IDX byte
+               uint8 reg = ((operand & 0x60) >> 5), idxind = ((operand & 0x10) >> 4),
+                       lo_nyb = (operand & 0x0F),  boff;
+               uint16 woff;
+
+               strcpy(tmp, "??");
+               if (!(operand & 0x80))                                                  // Hi bit set? Then decode 4 bit offset
+                       sprintf(tmp, "(%d),%s", (idxind ? -(16-lo_nyb) : lo_nyb), iregs[reg]);
+               else                                                                                    // Add the ($nnnn,R) code dude...
+               {
+                       if (idxind)
+                       {
+                               switch(lo_nyb)
+                               {
+                               case 1:   sprintf(tmp, "(,%s++)", iregs[reg]);  break;
+                               case 3:   sprintf(tmp, "(,--%s)", iregs[reg]);  break;
+                               case 4:   sprintf(tmp, "(,%s)", iregs[reg]);  break;
+                               case 5:   sprintf(tmp, "(B,%s)", iregs[reg]);  break;
+                               case 6:   sprintf(tmp, "(A,%s)", iregs[reg]);  break;
+                               case 8:
+                                       boff = regs.RdMem(addr++);
+                                       sprintf(tmp, "($%02X,%s)", boff, iregs[reg]);
+                                       break;
+                               case 9:
+                                       woff = (regs.RdMem(addr) << 8) | regs.RdMem(addr + 1);
+                                       addr += 2;
+                                       sprintf(tmp, "($%04X,%s)", woff, iregs[reg]);
+                                       break;
+                               case 11:  sprintf(tmp, "(D,%s)", iregs[reg]);  break;
+                               case 12:
+                                       boff = regs.RdMem(addr++);
+                                       sprintf(tmp, "($%02X,PC)", boff);
+                                       break;
+                               case 13:
+                                       woff = (regs.RdMem(addr) << 8) | regs.RdMem(addr + 1);
+                                       addr += 2;
+                                       sprintf(tmp, "($%04X,PC)", woff);
+                                       break;
+                               case 15:
+                                       woff = (regs.RdMem(addr) << 8) | regs.RdMem(addr + 1);
+                                       addr += 2;
+                                       sprintf(tmp, "[$%04X]", woff);
+                                       break;
+                               default:
+                                       strcpy(tmp, "??");
+                               }
+                       }
+                       else
+                       {
+                               switch(lo_nyb)
+                               {
+                               case 0:   sprintf(tmp, ",%s+", iregs[reg]);  break;
+                               case 1:   sprintf(tmp, ",%s++", iregs[reg]);  break;
+                               case 2:   sprintf(tmp, ",-%s", iregs[reg]);  break;
+                               case 3:   sprintf(tmp, ",--%s", iregs[reg]);  break;
+                               case 4:   sprintf(tmp, ",%s", iregs[reg]);  break;
+                               case 5:   sprintf(tmp, "(B),%s", iregs[reg]);  break;
+                               case 6:   sprintf(tmp, "(A),%s", iregs[reg]);  break;
+                               case 8:
+                                       boff = regs.RdMem(addr++);
+                                       sprintf(tmp, "($%02X),%s", boff, iregs[reg]);
+                                       break;
+                               case 9:
+                                       woff = (regs.RdMem(addr) << 8) | regs.RdMem(addr + 1);
+                                       addr += 2;
+                                       sprintf(tmp, "($%04X),%s", woff, iregs[reg]);
+                                       break;
+                               case 11:
+                                       sprintf(tmp, "(D),%s", iregs[reg]);
+                                       break;
+                               case 12:
+                                       boff = regs.RdMem(addr++);
+                                       sprintf(tmp, "($%02X),PC", boff);
+                                       break;
+                               case 13:
+                                       woff = (regs.RdMem(addr) << 8) | regs.RdMem(addr + 1);
+                                       addr += 2;
+                                       sprintf(tmp, "($%04X),PC", woff);
+                                       break;
+                               default:
+                                       strcpy(tmp, "??");
+                               }
+                       }
+               }
+               sprintf(outbuf, "%s %s", mnem, tmp);
+               break;
+       }
+       case 8:                                                                                         // Immediate
+               sprintf(outbuf, "%s #$%02X", mnem, regs.RdMem(addr++));
+               break;
+       case 9:                                                                                         // Long Immediate
+//             sprintf(outbuf, "%s #$%04X", mnem, (regs.RdMem(addr++) << 8) | regs.RdMem(addr++));
+               offset = (regs.RdMem(addr) << 8) | regs.RdMem(addr + 1);
+               addr += 2;
+               sprintf(outbuf, "%s #$%04X", mnem, offset);
+               break;
+       }
+
+       DisplayBytes(regs, regs.pc, addr);                                                              // Show bytes
+       WriteLog("%s", outbuf);                                                         // Display opcode & addressing, etc.
+
+       return addr - regs.pc;
+}
diff --git a/src/dis6809.h b/src/dis6809.h
new file mode 100755 (executable)
index 0000000..04d2e6c
--- /dev/null
@@ -0,0 +1,17 @@
+//
+// DIS6809.H
+//
+// by James L. Hammons
+// (C) 2004 Underground Software
+//
+
+#ifndef __DIS6809_H__
+#define __DIS6809_H__
+
+//#include "types.h"
+#include "v6809.h"
+
+//int Decode6809(uint16);
+int Decode6809(V6809REGS);
+
+#endif // __DIS6809_H__
index 17ea566f26774da6ad315789ed1df2f5584a855e..8ee60f525a32c1fe713f3f9ce2fe5d3ac2710caf 100755 (executable)
@@ -9,9 +9,10 @@
 // WHO  WHEN        WHAT
 // ---  ----------  ------------------------------------------------------------
 // JLH  07/23/2009  Added changelog ;-)
+// JLH  08/12/2009  Stabilized emulation so that it works
 //
 
-#define THUNDER_VERSION       "0.9.9"
+#define THUNDER_VERSION                "0.9.9"
 
 #include <iostream>
 #include <iomanip>
 //#include <conio.h>                   // For getch()
 #include <curses.h>                    // For getch()
 #include <time.h>
-#include "SDL.h"                                                                               // Get yer SDL out...!
+#include "SDL.h"                                                               // Get yer SDL out...!
 #include "types.h"
 #include "v6809.h"
 #include "screen.h"
 #include "gui.h"
 #include "log.h"
 
-using namespace std;                                                                   // Yes!
+using namespace std;                                                   // Yes!
 
 #if 0
 #define ROM1  "RT3-1B.ROM"
@@ -102,17 +103,17 @@ uint8 chr_rom[0x60000];                                                   // Character ROM pointer
 
 V6809REGS cpu1, cpu2;
 
-bool trace1 = false;                 // ditto...
-bool looking_at_rom = true;         // true = R1, false = R2
-uint32 banksw1, banksw2;             // Bank switch addresses
-uint16 game_over_switch;              // Game over delay
-uint16 dpc;                           // Debug pc reg...
-bool show_scr = true;            // Whether or not to show background
-bool enable_cpu = true;          // Whether or not to enable CPUs
-bool irqGoA = true;              // IRQ switch for CPU #1
-bool irqGoB = true;              // IRQ switch for CPU #2
-
-uint16 refresh_ = 0;                // Crappy global screen stuff...
+bool trace1 = false;                                                   // ditto...
+bool looking_at_rom = true;                                            // true = R1, false = R2
+uint32 banksw1, banksw2;                                               // Bank switch addresses
+uint16 game_over_switch;                                               // Game over delay
+uint16 dpc;                                                                            // Debug pc reg...
+bool show_scr = true;                                                  // Whether or not to show background
+bool enable_cpu = true;                                                        // Whether or not to enable CPUs
+bool irqGoA = true;                                                            // IRQ switch for CPU #1
+bool irqGoB = true;                                                            // IRQ switch for CPU #2
+
+uint16 refresh_ = 0;                                                   // Crappy global screen stuff...
 bool refresh2 = true;
 
 uint32 psg_lens[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
@@ -124,7 +125,7 @@ uint32 fm_lens[14] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 uint8 * fm_adrs[14];
 
 fstream tr;    // Tracelog hook
-uint16    pcx;   // Where we at?
+uint16 pcx;   // Where we at?
 
 static uint8 * keys;                                                   // SDL raw keyboard matrix
 
@@ -324,7 +325,7 @@ void WrMem(uint16 addr, uint8 b)
     //}
     tr << endl;
   }//*/
-#if 1
+#if 0
        if (addr == 0x4182)
        {
                WriteLog("\nWriteMem: CPU #1 writing $%02X to $4182!\n\n", b);
@@ -358,16 +359,13 @@ void WrMem(uint16 addr, uint8 b)
                        BlitChar(screen, chr_rom, gram1);
                        refresh_ = (refresh2 ? 1 : 0);                          // 60/30 Hz...
                }
-//Seems they're more regular than this...
-//             irqGoA = true; // Will this work??? no...
-//             cpu1.cpuFlags |= V6809_ASSERT_LINE_IRQ;//wil wok???
+
                // IRQ Ack (may also be frame go...
-//             cpu1.cpuFlags &= ~V6809_ASSERT_LINE_IRQ;
+               ClearLineOfCurrentV6809(V6809_ASSERT_LINE_IRQ);
 #if 1
        if (disasm)
                WriteLog("WriteMem: CPU #1 Acknowledging IRQ...\n", b);
 #endif
-               ClearLineOfCurrentV6809(V6809_ASSERT_LINE_IRQ);
        }
 }
 
@@ -420,17 +418,13 @@ void WrMemB(uint16 addr, uint8 b)
     //}
     tr << endl;
   }//*/
-#if 1
+#if 0
        if (addr == 0x0182)
        {
                WriteLog("\nWriteMem: CPU #2 writing $%02X to $0182 ($4182)!\n\n", b);
        }
 #endif
 
-// Bah. Dunno if this is accurate or not!
-//     if (addr == 0x8800)
-//             irqGoB = true;                                                                  // Will it work??? no...
-//             cpu2.cpuFlags |= V6809_ASSERT_LINE_IRQ;//wil wok???
        if (addr == 0x6000)
                SpawnSound(GAMESOUND, gram1[0x6200], 0);                // Do voice chan 1
        if (addr == 0x6400)
@@ -457,12 +451,11 @@ void WrMemB(uint16 addr, uint8 b)
        if (addr == 0x8800)
        {
                // IRQ Ack (may also be frame go...)
-//             cpu2.cpuFlags &= ~V6809_ASSERT_LINE_IRQ;
+               ClearLineOfCurrentV6809(V6809_ASSERT_LINE_IRQ);
 #if 1
        if (disasm)
                WriteLog("WriteMem: CPU #2 Acknowledging IRQ...\n", b);
 #endif
-               ClearLineOfCurrentV6809(V6809_ASSERT_LINE_IRQ);
        }
 }
 
@@ -893,7 +886,6 @@ void LoadPSGs(void)
                if (fp)
                {
                        len = GetWAVLength(fp);                                         // Get WAV data length...
-
                        psg_adrs[i] = new uint8[len];                           // Attempt to allocate space...
 
                        if (psg_adrs[i] != NULL)
@@ -935,7 +927,6 @@ void LoadFMs(void)
                if (fp)
                {
                        len = GetWAVLength(fp);                                         // Get WAV length...
-
                        fm_adrs[i] = new uint8[len];                                    // Attempt to allocate space...
 
                        if (fm_adrs[i] != NULL)
@@ -1554,7 +1545,7 @@ WriteLog("About to enter main loop...\n");
 //          refresh_ = (refresh2 ? 1 : 0);    // 60/30 Hz...
 //        }
 
-#if 1
+#if 0
 //temp, for testing...
 BlitChar(screen, chr_rom, gram1);
 #endif
@@ -1687,6 +1678,10 @@ BlitChar(screen, chr_rom, gram1);
 }
 
 #if 0
+Hitachi uC runs at 6.144 MHz
+YM2151 runs at 3.579580 MHz
+
+
 Rolling Thunder Memory map
 --------------------------
 Most of the decoding is done by custom chips (CUS47 and CUS41), so the memory