O2Hawk: Get interrupts working

This commit is contained in:
alyosha-tas 2019-12-09 16:45:36 -05:00
parent 4e381d944b
commit 8e139b4b5b
7 changed files with 111 additions and 39 deletions

View File

@ -26,11 +26,11 @@ namespace BizHawk.Emulation.Common.Components.I8048
"MOV A,P7", // 0f
"INC @R0", // 10
"INC @R1", // 11
"JPB 0", // 12
"JPB 0,i8", // 12
"ADC A,i8", // 13
"CALL 0,i8", // 14
"DI", // 15
"JP TF", // 16
"JP TF,i8", // 16
"INC A", // 17
"INC R0", // 18
"INC R1", // 19
@ -46,7 +46,7 @@ namespace BizHawk.Emulation.Common.Components.I8048
"MOV A,i8", // 23
"JP 2K 1,i8", // 24
"EN", // 25
"JP !T0", // 26
"JP !T0,i8", // 26
"CLR A", // 27
"XCH A,R0", // 28
"XCH A,R1", // 29
@ -58,11 +58,11 @@ namespace BizHawk.Emulation.Common.Components.I8048
"XCH A,R7", // 2f
"XCHD A,@R0", // 30
"XCHD A,@R1", // 31
"JPB 1", // 32
"JPB 1,i8", // 32
"???", // 33
"CALL 1,i8", // 34
"DN", // 35
"JP T0", // 36
"JP T0,i8", // 36
"COM A", // 37
"???", // 38
"OUT P1", // 39
@ -78,7 +78,7 @@ namespace BizHawk.Emulation.Common.Components.I8048
"OR A,i8", // 43
"JP 2K 2,i8", // 44
"START CNT", // 45
"JP NT1", // 46
"JP NT1,i8", // 46
"SWP", // 47
"OR A,R0", // 48
"OR A,R1", // 49
@ -90,11 +90,11 @@ namespace BizHawk.Emulation.Common.Components.I8048
"OR A,R7", // 4f
"AND A,@R0", // 50
"AND A,@R1", // 51
"JPB 2", // 52
"JPB 2,i8", // 52
"AND A,i8", // 53
"CALL 2,i8", // 54
"START TIM", // 55
"JP T1", // 56
"JP T1,i8", // 56
"DAA", // 57
"AND A,R0", // 58
"AND A,R1", // 59
@ -122,11 +122,11 @@ namespace BizHawk.Emulation.Common.Components.I8048
"ADD A,R7", // 6f
"ADC A,@R0", // 70
"ADC A,@R1", // 71
"JPB 3", // 72
"JPB 3,i8", // 72
"???", // 73
"CALL 3,i8", // 74
"ENT0 CLK", // 75
"JP F1", // 76
"JP F1,i8", // 76
"ROR", // 77
"ADC A,R0", // 78
"ADC A,R1", // 79
@ -142,7 +142,7 @@ namespace BizHawk.Emulation.Common.Components.I8048
"RET", // 83
"JP 2K 4,i8", // 84
"CLR F0", // 85
"JP !IRQ", // 86
"JP !IRQ,i8", // 86
"???", // 87
"OR BUS,i8", // 88
"OR P1,i8", // 89
@ -154,7 +154,7 @@ namespace BizHawk.Emulation.Common.Components.I8048
"OR P7,A", // 8f
"MOVX @R0,A", // 90
"MOVX @R1,A", // 91
"JPB 4", // 92
"JPB 4,i8", // 92
"RETR", // 93
"CALL 4,i8", // 94
"COM F0", // 95
@ -186,11 +186,11 @@ namespace BizHawk.Emulation.Common.Components.I8048
"MOV R7,A", // af
"???", // b0
"???", // b1
"JPB 5", // b2
"JPP A", // b3
"JPB 5,i8", // b2
"JPP A,i8", // b3
"CALL 5,i8", // b4
"COM F1", // b5
"JP F0", // b6
"JP F0,i8", // b6
"???", // b7
"MOV R0,i8", // b8
"MOV R1,i8", // b9
@ -206,7 +206,7 @@ namespace BizHawk.Emulation.Common.Components.I8048
"???", // c3
"JP 2K 6,i8", // c4
"SEL RB 0", // c5
"JP A==0", // c6
"JP A==0,i8", // c6
"MOV A,PSW", // c7
"DEC R0", // c8
"DEC R1", // c9
@ -218,7 +218,7 @@ namespace BizHawk.Emulation.Common.Components.I8048
"DEC R7", // cf
"XOR A,@R0", // d0
"XOR A,@R1", // d1
"JPB 6", // d2
"JPB 6,i8", // d2
"XOR A,i8", // d3
"CALL 6,i8", // d4
"SEL RB 1", // d5
@ -238,7 +238,7 @@ namespace BizHawk.Emulation.Common.Components.I8048
"MOV3 A,@A", // e3
"JP 2K 7,i8", // e4
"SEL MB 0", // e5
"JP NC", // e6
"JP NC,i8", // e6
"ROL", // e7
"DJNZ R0,i8", // e8
"DJNZ R1,i8", // e9
@ -250,11 +250,11 @@ namespace BizHawk.Emulation.Common.Components.I8048
"DJNZ R7,i8", // ef
"MOV A,@R0", // f0
"MOV A,@R1", // f1
"JPB 7", // f2
"JPB 7,i8", // f2
"???", // f3
"CALL 7,i8", // f4
"SEL MB 1", // f5
"JP C", // f6
"JP C,i8", // f6
"RLC", // f7
"MOV A,R0", // f8
"MOV A,R1", // f9

View File

@ -87,6 +87,8 @@ namespace BizHawk.Emulation.Common.Components.I8048
public const ushort DEA = 77;
public const ushort RD_P = 78;
public const ushort WR_P = 79;
public const ushort EM = 80;
public const ushort DM = 81;
public I8048()
{
@ -322,10 +324,10 @@ namespace BizHawk.Emulation.Common.Components.I8048
MB = 1 << 11;
break;
case SEL_RB0:
RB = 0;
FlagBS = false; // register bank also changed here
break;
case SEL_RB1:
RB = 24;
FlagBS = true; // register bank also changed here
break;
case INC_RAM:
reg_d_ad = cur_instr[instr_pntr++];
@ -431,21 +433,37 @@ namespace BizHawk.Emulation.Common.Components.I8048
WritePort(reg_d_ad, (byte)Regs[reg_l_ad]);
Regs[PX + reg_d_ad] = Regs[reg_l_ad];
break;
case EM:
INT_MSTR = true;
break;
case DM:
INT_MSTR = false;
break;
}
if (++irq_pntr == IRQS)
{
// then regular IRQ
if ((IRQPending && IntEn) | (TIRQPending && TimIntEn))
if (IRQPending && IntEn && INT_MSTR)
{
IRQPending = false;
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====IRQ====", RegisterInfo = "" }); }
IRQ_();
IRQ_(0);
IRQCallback();
instr_pntr = irq_pntr = 0;
}
}
else if (TIRQPending && TimIntEn && INT_MSTR)
{
TIRQPending = false;
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====TIRQ====", RegisterInfo = "" }); }
IRQ_(1);
IRQCallback();
instr_pntr = irq_pntr = 0;
}
// otherwise start the next instruction
else
{
@ -569,6 +587,7 @@ namespace BizHawk.Emulation.Common.Components.I8048
ser.Sync(nameof(TimIntEn), ref TimIntEn);
ser.Sync(nameof(IRQPending), ref IRQPending);
ser.Sync(nameof(TIRQPending), ref TIRQPending);
ser.Sync(nameof(INT_MSTR), ref INT_MSTR);
ser.Sync(nameof(instr_pntr), ref instr_pntr);
ser.Sync(nameof(cur_instr), ref cur_instr, false);

View File

@ -4,23 +4,35 @@ namespace BizHawk.Emulation.Common.Components.I8048
{
public partial class I8048
{
private void IRQ_()
private void IRQ_(ushort src)
{
Regs[ADDR] = 0xFFF8;
PopulateCURINSTR(IDLE,
IDLE,
IDLE,
RD_INC, ALU, ADDR,
RD_INC, ALU2, ADDR,
SET_ADDR, PC, ALU, ALU2);
if (src == 0)
{
Regs[ALU] = 0x0003;
}
else
{
Regs[ALU] = 0x0007;
}
IRQS = 19;
PopulateCURINSTR(DM,
IDLE,
IDLE,
IDLE,
IDLE,
IDLE,
PUSH,
IDLE,
SET_ADDR, PC, ALU, 0);
IRQS = 9;
}
public bool IRQPending;
public bool TIRQPending;
public bool IntEn;
public bool TimIntEn;
public bool INT_MSTR;
public Action IRQCallback = delegate () { };
@ -28,6 +40,7 @@ namespace BizHawk.Emulation.Common.Components.I8048
{
IntEn = false;
TimIntEn = false;
INT_MSTR = true;
}
}
}

View File

@ -140,7 +140,7 @@ namespace BizHawk.Emulation.Common.Components.I8048
IDLE,
IDLE,
PULL,
IDLE,
EM,
IDLE,
IDLE,
IDLE);

View File

@ -69,7 +69,20 @@ namespace BizHawk.Emulation.Common.Components.I8048
public bool FlagBS
{
get { return (Regs[PSW] & 0x10) != 0; }
set { Regs[PSW] = (byte)((Regs[PSW] & ~0x10) | (value ? 0x10 : 0x00)); }
set
{
// change register bank also
Regs[PSW] = (byte)((Regs[PSW] & ~0x10) | (value ? 0x10 : 0x00));
if (value & 0x10 > 0)
{
RB = 24;
}
else
{
RB = 0;
}
}
}
public bool FlagF0

View File

@ -18,7 +18,7 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
{
if (addr < 0x8000)
{
return Core._rom[addr];
return Core._rom[addr & (Core._rom.Length - 1)];
}
else
{

View File

@ -112,6 +112,7 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
else if (addr == 0xA0)
{
VDC_ctrl = value;
Console.WriteLine(value + " " + Core.cpu.TotalExecutedCycles);
}
else if (addr == 0xA1)
{
@ -136,13 +137,16 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
cycle++;
// drawing cycles
if ((cycle >= 43) && !VBL)
if (cycle >= 43)
{
if (cycle == 43)
{
HBL = false;
// trigger timer tick if enabled
if (Core.cpu.counter_en) { Core.cpu.T1 = false; }
//if (VDC_ctrl.Bit(0)) { Core.cpu.IRQPending = false; }
Core.cpu.IRQPending = false;
if (LY == 0) { VDC_status |= 0x08; }
}
}
@ -151,7 +155,7 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
{
cycle = 0;
HBL = true;
if (VDC_ctrl.Bit(0)) { Core.cpu.IRQPending = true;}
// trigger timer tick if enabled
if (Core.cpu.counter_en) { Core.cpu.T1 = true; }
@ -162,9 +166,11 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
LY = 0;
HBL = false;
VBL = true;
if (!VDC_ctrl.Bit(0)) { Core.cpu.IRQPending = true; }
}
if (LY == 22) { VBL = false; }
if (LY == 1) { VDC_status &= 0xF7; }
}
}
@ -267,6 +273,27 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
0x00, 0x00, 0x00, 0x54, 0x54, 0xFF, 0x7E, // (boat 3 unk) 0x3F
};
public static readonly uint[] Color_Palette =
{
0xFF006D07, //green
0xFF56C469, // light green
0xFF2AAABE, // blue-green
0xFF77E6EB, // light blue-green
0xFF1A37BE, // blue
0xFF5C80F6, // light blue
0xFF94309F, // violet
0xFFDC84D4, // light violet
0xFF790000, // red
0xFFC75151, // light red
0xFF77670B, // yellow
0xFFC6B869, // light yellow
0xFF676767, // grey
0xFFCECECE, // light grey
0xFF000000, // black
0xFFFFFFFF, // white
};
public void SyncState(Serializer ser)
{