MC6800: disassembler and cleanup

This commit is contained in:
alyosha-tas 2019-07-07 17:32:14 -04:00
parent 53dd500875
commit 5b2ed7e4ff
6 changed files with 149 additions and 202 deletions

View File

@ -8,40 +8,40 @@ namespace BizHawk.Emulation.Common.Components.MC6800
{
static string[] table =
{
"NEG DP+i8", // 00
"???", // 01
"???", // 00
"NOP", // 01
"???", // 02
"COM DP+i8", // 03
"LSR DP+i8", // 04
"???", // 03
"???", // 04
"???", // 05
"ROR DP+i8", // 06
"ASR DP+i8", // 07
"ASL DP+i8", // 08
"ROL DP+i8", // 09
"DEC DP+i8", // 0a
"???", // 0b
"INC DP+i8", // 0c
"TST DP+i8", // 0d
"JMP DP+i8", // 0e
"CLR DP+i8", // 0f
"PAGE 2", // 10
"PAGE 3", // 11
"NOP", // 12
"SYNC", // 13
"TAP", // 06
"TPA", // 07
"INX", // 08
"DEX", // 09
"CLV", // 0a
"SEV", // 0b
"CLC", // 0c
"SEC", // 0d
"CLI", // 0e
"SEI", // 0f
"SBA", // 10
"CBA", // 11
"???", // 12
"???", // 13
"???", // 14
"???", // 15
"LBRA i16", // 16
"LBSR i16", // 17
"TAB", // 16
"TBA", // 17
"???", // 18
"DAA", // 19
"ORCC i8", // 1a
"???", // 1b
"ANDCC i8", // 1c
"SEX", // 1d
"EXG i8", // 1e
"TFR i8", // 1f
"???", // 1a
"ABA", // 1b
"???", // 1c
"???", // 1d
"???", // 1e
"???", // 1f
"BRA i8", // 20
"BRN i8", // 21
"???", // 21
"BHI i8", // 22
"BLS i8", // 23
"BHS i8", // 24
@ -56,22 +56,22 @@ namespace BizHawk.Emulation.Common.Components.MC6800
"BLT i8", // 2d
"BGT i8", // 2e
"BLE i8", // 2f
"LEAX ix16", // 30
"LEAY ix16", // 31
"LEAS ix16", // 32
"LEAU ix16", // 33
"PSHS i8", // 34
"PULS i8", // 35
"PSHU i8", // 36
"PULU i8", // 37
"TSX", // 30
"INS", // 31
"PULA", // 32
"PULB", // 33
"DES", // 34
"TXS", // 35
"PSHA", // 36
"PSHB", // 37
"???", // 38
"RTS", // 39
"ABX", // 3a
"???", // 3a
"RTI", // 3b
"CWAI i8", // 3c
"MUL", // 3d
"???", // 3e
"SWI1", // 3f
"???", // 3c
"???", // 3d
"WAI", // 3e
"SWI", // 3f
"NEG A", // 40
"???", // 41
"???", // 42
@ -139,7 +139,7 @@ namespace BizHawk.Emulation.Common.Components.MC6800
"SUB A,i8", // 80
"CMP A,i8", // 81
"SBC A,i8", // 82
"SUB D,i16", // 83
"???", // 83
"AND A,i8", // 84
"BIT A,i8", // 85
"LD A,i8", // 86
@ -150,12 +150,12 @@ namespace BizHawk.Emulation.Common.Components.MC6800
"ADD A,i8", // 8b
"CMP X,i16", // 8c
"BSR i8", // 8d
"LD X,i16", // 8e
"LD SP,i16", // 8e
"???", // 8f
"SUB A,DP+i8", // 90
"CMP A,DP+i8", // 91
"SBC A,DP+i8", // 92
"SUB D,DP+i8", // 93
"???", // 93
"AND A,DP+i8", // 94
"BIT A,DP+i8", // 95
"LD A,DP+i8", // 96
@ -165,13 +165,13 @@ namespace BizHawk.Emulation.Common.Components.MC6800
"OR A,DP+i8", // 9a
"ADD A,DP+i8", // 9b
"CMP X,DP+i8", // 9c
"JSR DP+i8", // 9d
"LD X,DP+i8", // 9e
"ST X,DP+i8", // 9f
"???", // 9d
"LD SP,DP+i8", // 9e
"ST SP,DP+i8", // 9f
"SUB A,ix16", // a0
"CMP A,ix16", // a1
"SBC A,ix16", // a2
"SUB D,ix16", // a3
"???", // a3
"AND A,ix16", // a4
"BIT A,ix16", // a5
"LD A,ix16", // a6
@ -182,12 +182,12 @@ namespace BizHawk.Emulation.Common.Components.MC6800
"ADD A,ix16", // ab
"CMP X,ix16", // ac
"JSR ix16", // ad
"LD X,ix16", // ae
"ST X,ix16", // af
"LD SP,ix16", // ae
"ST SP,ix16", // af
"SUB A,ex16", // b0
"CMP A,ex16", // b1
"SBC A,ex16", // b2
"SUB D,ex16", // b3
"???", // b3
"AND A,ex16", // b4
"BIT A,ex16", // b5
"LD A,ex16", // b6
@ -198,12 +198,12 @@ namespace BizHawk.Emulation.Common.Components.MC6800
"ADD A,ex16", // bb
"CMP X,ex16", // bc
"JSR ex16", // bd
"LD X,ex16", // be
"ST X,ex16", // bf
"LD SP,ex16", // be
"ST SP,ex16", // bf
"SUB B,i8", // c0
"CMP B,i8", // c1
"SBC B,i8", // c2
"ADD D,i16", // c3
"???", // c3
"AND B,i8", // c4
"BIT B,i8", // c5
"LD B,i8", // c6
@ -212,14 +212,14 @@ namespace BizHawk.Emulation.Common.Components.MC6800
"ADC B,i8", // c9
"OR B,i8", // ca
"ADD B,i8", // cb
"LD D,i16", // cc
"???", // cc
"???", // cd
"LD U,i16", // ce
"LD X,i16", // ce
"???", // cf
"SUB B,DP+i8", // d0
"CMP B,DP+i8", // d1
"SBC B,DP+i8", // d2
"ADD D,DP+i8", // d3
"???", // d3
"AND B,DP+i8", // d4
"BIT B,DP+i8", // d5
"LD B,DP+i8", // d6
@ -228,14 +228,14 @@ namespace BizHawk.Emulation.Common.Components.MC6800
"ADC B,DP+i8", // d9
"OR B,DP+i8", // da
"ADD B,DP+i8", // db
"LD D,DP+i8", // dc
"ST D,DP+i8", // dd
"LD U,DP+i8", // de
"ST U,DP+i8", // df
"???", // dc
"???", // dd
"LD X,DP+i8", // de
"ST X,DP+i8", // df
"SUB B,ix16", // e0
"CMP B,ix16", // e1
"SBC B,ix16", // e2
"ADD D,ix16", // e3
"???", // e3
"AND B,ix16", // e4
"BIT B,ix16", // e5
"LD B,ix16", // e6
@ -244,14 +244,14 @@ namespace BizHawk.Emulation.Common.Components.MC6800
"ADC B,ix16", // e9
"OR B,ix16", // ea
"ADD B,ix16", // eb
"LD D,ix16", // ec
"ST D,ix16", // ed
"LD U,ix16", // ee
"ST U,ix16", // ef
"???", // ec
"???", // ed
"LD X,ix16", // ee
"ST X,ix16", // ef
"SUB B,ex16", // f0
"CMP B,ex16", // f1
"SBC B,ex16", // f2
"ADD D,ex16", // f3
"???", // f3
"AND B,ex16", // f4
"BIT B,ex16", // f5
"LD B,ex16", // f6
@ -260,10 +260,10 @@ namespace BizHawk.Emulation.Common.Components.MC6800
"ADC B,ex16", // f9
"OR B,ex16", // fa
"ADD B,ex16", // fb
"LD D,ex16", // fc
"ST D,ex16", // fd
"LD U,ex16", // fe
"ST U,ex16", // ff
"???", // fc
"???", // fd
"LD X,ex16", // fe
"ST X,ex16", // ff
};
public static string Disassemble(ushort addr, Func<ushort, byte> reader, out ushort size)

View File

@ -45,8 +45,8 @@ namespace BizHawk.Emulation.Common.Components.MC6800
case 0x13: ILLEGAL(); break; // ILLEGAL
case 0x14: ILLEGAL(); break; // ILLEGAL
case 0x15: ILLEGAL(); break; // ILLEGAL
case 0x16: REG_OP(TAB, A); break; // LBRA (Relative)
case 0x17: REG_OP(TBA, A); break; // LBSR (Relative)
case 0x16: REG_OP(TAB, A); break; // TAB (Inherent)
case 0x17: REG_OP(TBA, A); break; // TBA (Inherent)
case 0x18: ILLEGAL(); break; // ILLEGAL
case 0x19: REG_OP(DA, A); break; // DAA (Inherent)
case 0x1A: ILLEGAL(); break; // ILLEGAL

View File

@ -65,12 +65,13 @@ namespace BizHawk.Emulation.Common.Components.MC6800
private void INDEX_OP_JSR()
{
PopulateCURINSTR(TR, ADDR, PC,
DEC16, SP,
IDLE,
IDLE,
TR, PC, IDX_EA,
WR_DEC_LO, SP, ADDR,
WR_HI, SP, ADDR);
WR_DEC_HI, SP, ADDR);
IRQS = 5;
IRQS = 6;
}
private void INDEX_OP_LD()

View File

@ -8,7 +8,7 @@ namespace BizHawk.Emulation.Common.Components.MC6800
{
Regs[ADDR] = 0xFFF8;
PopulateCURINSTR(IDLE,
SET_E,
IDLE,
DEC16, SP,
WR_DEC_LO, SP, PC,
WR_DEC_HI, SP, PC,
@ -29,7 +29,7 @@ namespace BizHawk.Emulation.Common.Components.MC6800
{
Regs[ADDR] = 0xFFFC;
PopulateCURINSTR(IDLE,
SET_E,
IDLE,
DEC16, SP,
WR_DEC_LO, SP, PC,
WR_DEC_HI, SP, PC,
@ -38,7 +38,7 @@ namespace BizHawk.Emulation.Common.Components.MC6800
WR_DEC_LO, SP, B,
WR_DEC_LO, SP, A,
WR, SP, CC,
SET_F_I,
SET_I,
RD_INC, ALU, ADDR,
RD_INC, ALU2, ADDR,
SET_ADDR, PC, ALU, ALU2);
@ -48,14 +48,13 @@ namespace BizHawk.Emulation.Common.Components.MC6800
public bool NMIPending;
public bool IRQPending;
public bool IN_SYNC;
public Action IRQCallback = delegate () { };
public Action NMICallback = delegate () { };
private void ResetInterrupts()
{
IN_SYNC = false;
}
}
}

View File

@ -13,6 +13,7 @@ namespace BizHawk.Emulation.Common.Components.MC6800
public const ushort RD = 2;
public const ushort WR = 3;
public const ushort TR = 4;
public const ushort SET_ADDR = 5;
public const ushort ADD8 = 6;
public const ushort SUB8 = 7;
public const ushort ADC8 = 8;
@ -33,53 +34,45 @@ namespace BizHawk.Emulation.Common.Components.MC6800
public const ushort LSR = 23;
public const ushort BIT = 24;
public const ushort WAI = 25;
public const ushort SYNC = 26;
public const ushort RD_INC = 27;
public const ushort RD_INC_OP = 28;
public const ushort WR_DEC_LO = 29;
public const ushort WR_DEC_HI = 30;
public const ushort WR_HI = 31;
public const ushort SET_ADDR = 32;
public const ushort NEG = 33;
public const ushort TST = 34;
public const ushort CLR = 35;
public const ushort ADD8BR = 41;
public const ushort JPE = 44;
public const ushort IDX_DCDE = 45;
public const ushort IDX_OP_BLD = 46;
public const ushort EA_8 = 47;
public const ushort EA_16 = 48;
public const ushort WR_DEC_LO_OP = 51;
public const ushort WR_DEC_HI_OP = 52;
public const ushort WR_HI_INC = 53;
public const ushort SET_F_I = 55;
public const ushort SET_I = 56;
public const ushort SET_E = 57;
public const ushort ANDCC = 58;
public const ushort CMP8 = 59;
public const ushort CMP16 = 62;
public const ushort LD_8 = 64;
public const ushort LD_16 = 65;
public const ushort CLR_E = 67;
public const ushort TAP = 68;
public const ushort TPA = 69;
public const ushort INX = 70;
public const ushort DEX = 71;
public const ushort CLV = 72;
public const ushort SEV = 73;
public const ushort CLC = 74;
public const ushort SEC = 75;
public const ushort CLI = 76;
public const ushort SEI = 77;
public const ushort SBA = 78;
public const ushort CBA = 79;
public const ushort TAB = 80;
public const ushort TBA = 81;
public const ushort ABA = 82;
public const ushort TSX = 83;
public const ushort INS = 84;
public const ushort DES = 85;
public const ushort TXS = 86;
public const ushort RD_INC = 26;
public const ushort RD_INC_OP = 27;
public const ushort WR_DEC_LO = 28;
public const ushort WR_DEC_HI = 29;
public const ushort WR_HI = 31;
public const ushort NEG = 32;
public const ushort TST = 33;
public const ushort CLR = 34;
public const ushort ADD8BR = 35;
public const ushort JPE = 36;
public const ushort IDX_DCDE = 37;
public const ushort IDX_OP_BLD = 38;
public const ushort EA_8 = 39;
public const ushort EA_16 = 40;
public const ushort WR_HI_INC = 41;
public const ushort SET_I = 42;
public const ushort CMP8 = 43;
public const ushort CMP16 = 44;
public const ushort LD_8 = 45;
public const ushort LD_16 = 46;
public const ushort TAP = 47;
public const ushort TPA = 48;
public const ushort INX = 49;
public const ushort DEX = 50;
public const ushort CLV = 51;
public const ushort SEV = 52;
public const ushort CLC = 53;
public const ushort SEC = 54;
public const ushort CLI = 55;
public const ushort SEI = 56;
public const ushort SBA = 57;
public const ushort CBA = 58;
public const ushort TAB = 59;
public const ushort TBA = 60;
public const ushort ABA = 61;
public const ushort TSX = 62;
public const ushort INS = 63;
public const ushort DES = 64;
public const ushort TXS = 65;
public MC6800()
{
@ -242,9 +235,6 @@ namespace BizHawk.Emulation.Common.Components.MC6800
case LD_16:
LD_16_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++], cur_instr[instr_pntr++]);
break;
case ANDCC:
Regs[CC] &= Regs[instr_pntr++];
break;
}
break;
case WR:
@ -256,14 +246,6 @@ namespace BizHawk.Emulation.Common.Components.MC6800
case WR_DEC_HI:
Write_Dec_HI_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]);
break;
case WR_DEC_LO_OP:
Write_Dec_Lo_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]);
instr_pntr++;
break;
case WR_DEC_HI_OP:
Write_Dec_HI_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]);
instr_pntr++;
break;
case WR_HI:
Write_Hi_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]);
break;
@ -305,21 +287,9 @@ namespace BizHawk.Emulation.Common.Components.MC6800
case CLR:
CLR_Func(cur_instr[instr_pntr++]);
break;
case SET_F_I:
FlagI = true;
break;
case SET_I:
FlagI = true;
break;
case SET_E:
FlagE = true;
break;
case CLR_E:
FlagE = false;
break;
case ANDCC:
Regs[CC] &= Regs[instr_pntr++];
break;
case ADD8BR:
ADD8BR_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]);
break;
@ -499,12 +469,6 @@ namespace BizHawk.Emulation.Common.Components.MC6800
}
instr_pntr = 0;
break;
case SYNC:
IN_SYNC = true;
IRQS = 1;
instr_pntr = irq_pntr = 0;
PopulateCURINSTR(SYNC);
break;
}
if (++irq_pntr == IRQS)
@ -516,7 +480,6 @@ namespace BizHawk.Emulation.Common.Components.MC6800
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====NMI====", RegisterInfo = "" }); }
IN_SYNC = false;
NMI_();
NMICallback();
instr_pntr = irq_pntr = 0;
@ -530,22 +493,10 @@ namespace BizHawk.Emulation.Common.Components.MC6800
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====IRQ====", RegisterInfo = "" }); }
IN_SYNC = false;
IRQ_();
IRQCallback();
instr_pntr = irq_pntr = 0;
}
else if (IN_SYNC)
{
IRQPending = false;
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====SYNC====", RegisterInfo = "" }); }
IN_SYNC = false;
IRQS = 1;
instr_pntr = irq_pntr = 0;
PopulateCURINSTR(IDLE);
}
}
// otherwise start the next instruction
else
@ -631,7 +582,6 @@ namespace BizHawk.Emulation.Common.Components.MC6800
{
ser.BeginSection("MC6809");
ser.Sync(nameof(IN_SYNC), ref IN_SYNC);
ser.Sync(nameof(NMIPending), ref NMIPending);
ser.Sync(nameof(IRQPending), ref IRQPending);

View File

@ -159,18 +159,17 @@ namespace BizHawk.Emulation.Common.Components.MC6800
{
PopulateCURINSTR(RD_INC, ALU, PC,
RD_INC_OP, ALU2, PC, SET_ADDR, ADDR, ALU, ALU2,
IDLE,
RD_INC, ALU, ADDR,
RD_INC_OP, ALU2, ADDR, LD_16, dest, ALU, ALU2);
IRQS = 5;
IRQS = 4;
}
private void EXT_OP_ST_16(ushort src)
{
PopulateCURINSTR(RD_INC, ALU, PC,
RD_INC_OP, ALU2, PC, SET_ADDR, ADDR, ALU, ALU2,
IDLE,
RD_INC, ALU2, PC,
SET_ADDR, ADDR, ALU, ALU2,
WR_HI_INC, ADDR, src,
WR_DEC_LO, ADDR, src);
@ -201,14 +200,15 @@ namespace BizHawk.Emulation.Common.Components.MC6800
private void JSR_EXT()
{
PopulateCURINSTR(RD_INC, ALU, PC,
RD_INC_OP, ALU2, PC, SET_ADDR, ADDR, ALU, ALU2,
RD_INC, ALU2, PC,
SET_ADDR, ADDR, ALU, ALU2,
TR, ALU, PC,
DEC16, SP,
IDLE,
TR, PC, ADDR,
WR_DEC_LO, SP, ALU,
WR_HI, SP, ALU);
WR_DEC_HI, SP, ALU);
IRQS = 7;
IRQS = 8;
}
private void BR_(bool cond)
@ -234,18 +234,19 @@ namespace BizHawk.Emulation.Common.Components.MC6800
PopulateCURINSTR(RD_INC, ALU, PC,
TR, ADDR, PC,
ADD8BR, PC, ALU,
DEC16, SP,
IDLE,
IDLE,
WR_DEC_LO, SP, ADDR,
WR_HI, SP, ADDR);
WR_DEC_HI, SP, ADDR);
IRQS = 6;
IRQS = 7;
}
private void RTS()
{
PopulateCURINSTR(IDLE,
PopulateCURINSTR(INC16, SP,
RD_INC, ALU, SP,
RD_INC, ALU2, SP,
RD, ALU2, SP,
SET_ADDR, PC, ALU, ALU2);
IRQS = 4;
@ -253,16 +254,17 @@ namespace BizHawk.Emulation.Common.Components.MC6800
private void RTI()
{
PopulateCURINSTR(IDLE,
PopulateCURINSTR(INC16, SP,
RD_INC_OP, CC, SP, JPE,
RD_INC, A, SP,
RD_INC, B, SP,
RD_INC, A, SP,
RD_INC, ALU, SP,
RD_INC_OP, ALU2, SP, SET_ADDR, X, ALU, ALU2,
RD_INC, ALU, SP,
RD_INC_OP, ALU2, SP, SET_ADDR, PC, ALU, ALU2);
RD, ALU2, SP,
SET_ADDR, PC, ALU, ALU2);
IRQS = 14;
IRQS = 9;
}
private void PSH_(ushort src)
@ -286,38 +288,33 @@ namespace BizHawk.Emulation.Common.Components.MC6800
private void SWI1()
{
Regs[ADDR] = 0xFFFA;
PopulateCURINSTR(SET_E,
DEC16, SP,
PopulateCURINSTR(IDLE,
WR_DEC_LO, SP, PC,
WR_DEC_HI, SP, PC,
WR_DEC_LO, SP, X,
WR_DEC_HI, SP, X,
WR_DEC_LO, SP, B,
WR_DEC_LO, SP, A,
WR, SP, CC,
SET_F_I,
WR_DEC_LO, SP, B,
WR_DEC_LO, SP, CC,
SET_I,
RD_INC, ALU, ADDR,
RD_INC, ALU2, ADDR,
SET_ADDR, PC, ALU, ALU2);
RD_INC_OP, ALU2, ADDR, SET_ADDR, PC, ALU, ALU2);
IRQS = 18;
IRQS = 11;
}
private void WAI_()
{
PopulateCURINSTR(RD_INC_OP, ALU, PC, ANDCC, ALU,
SET_E,
DEC16, SP,
WR_DEC_LO, SP, PC,
PopulateCURINSTR(WR_DEC_LO, SP, PC,
WR_DEC_HI, SP, PC,
WR_DEC_LO, SP, X,
WR_DEC_HI, SP, X,
WR_DEC_LO, SP, B,
WR_DEC_LO, SP, A,
WR, SP, CC,
WR_DEC_LO, SP, B,
WR_DEC_LO, SP, CC,
WAI);
IRQS = 16;
IRQS = 8;
}
}
}