diff --git a/BizHawk.Emulation.Cores/CPUs/LR35902/Interrupts.cs b/BizHawk.Emulation.Cores/CPUs/LR35902/Interrupts.cs index e20cbcd90e..51c926aec8 100644 --- a/BizHawk.Emulation.Cores/CPUs/LR35902/Interrupts.cs +++ b/BizHawk.Emulation.Cores/CPUs/LR35902/Interrupts.cs @@ -25,10 +25,6 @@ namespace BizHawk.Emulation.Common.Components.LR35902 { cur_instr = new ushort[] {IDLE, - IDLE, - IDLE, - IDLE, - IDLE, DEC16, SPl, SPh, IDLE, WR, SPl, SPh, PCh, @@ -40,6 +36,10 @@ namespace BizHawk.Emulation.Common.Components.LR35902 IDLE, IDLE, IDLE, + IDLE, + IDLE, + IDLE, + IDLE, TR, PCl, W, ASGN, PCh, 0, IDLE, @@ -50,10 +50,6 @@ namespace BizHawk.Emulation.Common.Components.LR35902 { cur_instr = new ushort[] {IDLE, - IDLE, - IDLE, - IDLE, - IDLE, DEC16, SPl, SPh, IDLE, WR, SPl, SPh, PCh, @@ -72,6 +68,10 @@ namespace BizHawk.Emulation.Common.Components.LR35902 IDLE, IDLE, IDLE, + IDLE, + IDLE, + IDLE, + IDLE, OP }; } diff --git a/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs b/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs index c4b39bfeb5..c2f18c8f6e 100644 --- a/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs +++ b/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs @@ -70,7 +70,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 ResetInterrupts(); TotalExecutedCycles = 8; stop_check = false; - cur_instr = new ushort[] { OP }; + cur_instr = new ushort[] { IDLE, IDLE, HALT_CHK, OP }; } // Memory Access @@ -127,7 +127,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 } } - if (FlagI && interrupts_enabled && !CB_prefix && !jammed) + if (I_use && interrupts_enabled && !CB_prefix && !jammed) { interrupts_enabled = false; @@ -501,6 +501,8 @@ namespace BizHawk.Emulation.Common.Components.LR35902 { RegPC--; Halt_bug_3 = true; + Console.WriteLine("Halt_bug_3"); + Console.WriteLine(totalExecutedCycles); } Halt_bug_2 = false; diff --git a/BizHawk.Emulation.Cores/CPUs/LR35902/Tables_Direct.cs b/BizHawk.Emulation.Cores/CPUs/LR35902/Tables_Direct.cs index eb3346900f..b7dd1ccb0e 100644 --- a/BizHawk.Emulation.Cores/CPUs/LR35902/Tables_Direct.cs +++ b/BizHawk.Emulation.Cores/CPUs/LR35902/Tables_Direct.cs @@ -12,7 +12,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 cur_instr = new ushort[] {IDLE, IDLE, - IDLE, + HALT_CHK, OP }; } @@ -25,7 +25,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 INC16, src_l, src_h, IDLE, IDLE, - IDLE, + HALT_CHK, OP }; } @@ -39,7 +39,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 DEC16, src_l, src_h, IDLE, IDLE, - IDLE, + HALT_CHK, OP }; } @@ -52,7 +52,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 ADD16, dest_l, dest_h, src_l, src_h, IDLE, IDLE, - IDLE, + HALT_CHK, OP }; } @@ -61,7 +61,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 cur_instr = new ushort[] {operation, dest, src, IDLE, - IDLE, + HALT_CHK, OP }; } @@ -134,7 +134,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 ASGN, Z, 0, IDLE, ADDS, PCl, PCh, W, Z, - IDLE, + HALT_CHK, OP }; } else @@ -146,7 +146,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 RD, Z, PCl, PCh, IDLE, INC16, PCl, PCh, - IDLE, + HALT_CHK, OP }; } } @@ -170,7 +170,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 TR, PCl, W, IDLE, TR, PCh, Z, - IDLE, + HALT_CHK, OP }; } else @@ -186,7 +186,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 RD, Z, PCl, PCh, IDLE, INC16, PCl, PCh, - IDLE, + HALT_CHK, OP }; } } @@ -208,7 +208,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 IDLE, IDLE, IDLE, - IDLE, + HALT_CHK, OP }; } @@ -229,7 +229,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 EI_RETI, IDLE, IDLE, - IDLE, + HALT_CHK, OP }; } @@ -257,7 +257,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 IDLE, IDLE, IDLE, - IDLE, + HALT_CHK, OP }; } else @@ -269,7 +269,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 IDLE, IDLE, IDLE, - IDLE, + HALT_CHK, OP }; } } @@ -298,10 +298,10 @@ namespace BizHawk.Emulation.Common.Components.LR35902 IDLE, IDLE, DEC16, SPl, SPh, - WR, SPl, SPh, PCl, - IDLE, + WR, SPl, SPh, PCl, TR, PCl, W, TR, PCh, Z, + HALT_CHK, OP }; } else @@ -317,7 +317,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 RD, Z, PCl, PCh, IDLE, INC16, PCl, PCh, - IDLE, + HALT_CHK, OP }; } } @@ -327,7 +327,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 cur_instr = new ushort[] {operation, src, IDLE, - IDLE, + HALT_CHK, OP }; } @@ -336,7 +336,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 cur_instr = new ushort[] {operation, bit, src, IDLE, - IDLE, + HALT_CHK, OP }; } @@ -357,7 +357,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 WR, SPl, SPh, src_l, IDLE, IDLE, - IDLE, + HALT_CHK, OP }; } @@ -379,7 +379,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 RD, src_h, SPl, SPh, IDLE, INC16, SPl, SPh, - IDLE, + HALT_CHK, OP }; } else @@ -395,7 +395,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 RD, src_h, SPl, SPh, IDLE, INC16, SPl, SPh, - IDLE, + HALT_CHK, OP }; } } @@ -415,9 +415,9 @@ namespace BizHawk.Emulation.Common.Components.LR35902 IDLE, IDLE, WR, SPl, SPh, PCl, - IDLE, ASGN, PCh, 0, ASGN, PCl, n, + HALT_CHK, OP }; } @@ -435,7 +435,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 cur_instr = new ushort[] {DI, IDLE, - IDLE, + HALT_CHK, OP }; } @@ -444,7 +444,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 cur_instr = new ushort[] {EI, IDLE, - IDLE, + HALT_CHK, OP }; } @@ -452,8 +452,8 @@ namespace BizHawk.Emulation.Common.Components.LR35902 { cur_instr = new ushort[] {TR, PCl, L, - IDLE, TR, PCh, H, + HALT_CHK, OP }; } @@ -474,7 +474,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 ADDS, SPl, SPh, W, Z, IDLE, IDLE, - IDLE, + HALT_CHK, OP }; } @@ -487,7 +487,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 TR, SPl, L, IDLE, TR, SPh, H, - IDLE, + HALT_CHK, OP }; } @@ -500,11 +500,11 @@ namespace BizHawk.Emulation.Common.Components.LR35902 RD, W, PCl, PCh, IDLE, INC16, PCl, PCh, - IDLE, TR, H, SPh, TR, L, SPl, ASGN, Z, 0, ADDS, L, H, W, Z, + HALT_CHK, OP }; } diff --git a/BizHawk.Emulation.Cores/CPUs/LR35902/Tables_Indirect.cs b/BizHawk.Emulation.Cores/CPUs/LR35902/Tables_Indirect.cs index 79d2e67341..c1f68bc4f1 100644 --- a/BizHawk.Emulation.Cores/CPUs/LR35902/Tables_Indirect.cs +++ b/BizHawk.Emulation.Cores/CPUs/LR35902/Tables_Indirect.cs @@ -14,8 +14,8 @@ IDLE, WR, src_l, src_h, Z, IDLE, - IDLE, IDLE, + HALT_CHK, OP }; } @@ -32,7 +32,7 @@ WR, src_l, src_h, Z, IDLE, IDLE, - IDLE, + HALT_CHK, OP }; } @@ -45,7 +45,7 @@ RD, Z, src_l, src_h, IDLE, operation, bit, Z, - IDLE, + HALT_CHK, OP }; } @@ -56,9 +56,9 @@ IDLE, IDLE, RD, Z, src_l, src_h, - IDLE, operation, dest, Z, INC16, src_l, src_h, + HALT_CHK, OP }; } @@ -71,7 +71,7 @@ RD, Z, src_l, src_h, IDLE, operation, dest, Z, - IDLE, + HALT_CHK, OP }; } @@ -96,7 +96,7 @@ WR, W, Z, dest_h, IDLE, IDLE, - IDLE, + HALT_CHK, OP }; } @@ -109,7 +109,7 @@ WR, dest_l, dest_h, src, IDLE, INC16, dest_l, dest_h, - IDLE, + HALT_CHK, OP }; } @@ -122,7 +122,7 @@ WR, dest_l, dest_h, src, IDLE, DEC16, dest_l, dest_h, - IDLE, + HALT_CHK, OP }; } @@ -134,8 +134,8 @@ IDLE, WR, dest_l, dest_h, src, IDLE, - IDLE, IDLE, + HALT_CHK, OP }; } @@ -152,7 +152,7 @@ WR, dest_l, dest_h, Z, IDLE, IDLE, - IDLE, + HALT_CHK, OP }; } @@ -165,7 +165,7 @@ RD, dest, src_l, src_h, IDLE, INC16, src_l, src_h, - IDLE, + HALT_CHK, OP }; } @@ -178,7 +178,7 @@ RD, dest, src_l, src_h, IDLE, INC16, src_l, src_h, - IDLE, + HALT_CHK, OP }; } @@ -191,7 +191,7 @@ RD, dest, src_l, src_h, IDLE, DEC16, src_l, src_h, - IDLE, + HALT_CHK, OP }; } @@ -208,7 +208,7 @@ RD, dest_h, src_l, src_h, IDLE, INC16, src_l, src_h, - IDLE, + HALT_CHK, OP }; } @@ -225,7 +225,7 @@ WR, src_l, src_h, Z, IDLE, IDLE, - IDLE, + HALT_CHK, OP }; } @@ -242,7 +242,7 @@ WR, src_l, src_h, Z, IDLE, IDLE, - IDLE, + HALT_CHK, OP }; } @@ -259,8 +259,8 @@ ASGN, Z , 0xFF, RD, dest, W, Z, IDLE, - IDLE, IDLE, + HALT_CHK, OP }; } @@ -277,7 +277,7 @@ WR, W, Z, src, IDLE, IDLE, - IDLE, + HALT_CHK, OP }; } @@ -289,8 +289,8 @@ ASGN, Z , 0xFF, RD, dest, C, Z, IDLE, - IDLE, IDLE, + HALT_CHK, OP }; } @@ -302,8 +302,8 @@ ASGN, Z , 0xFF, WR, C, Z, src, IDLE, - IDLE, IDLE, + HALT_CHK, OP }; } @@ -323,8 +323,8 @@ IDLE, RD, dest, W, Z, IDLE, - IDLE, IDLE, + HALT_CHK, OP }; } @@ -345,7 +345,7 @@ WR, W, Z, src, IDLE, IDLE, - IDLE, + HALT_CHK, OP }; } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs index 7370214a3b..c7c5068f87 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs @@ -124,7 +124,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk // These things all tick twice as fast in GBC double speed mode ppu.DMA_tick(); timer.tick_1(); - serialport.serial_transfer_tick(); + serialport.serial_transfer_tick(); cpu.ExecuteOne(ref REG_FF0F, REG_FFFF); timer.tick_2(); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs index 00eb0d539e..b627310025 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs @@ -335,7 +335,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk if (cycle >= 452) { - OAM_access_read = false; + if (LY != 144) { OAM_access_read = false; } OAM_scan(cycle - 452); } } @@ -924,14 +924,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { if (LCDC.Bit(2)) { - y = LY - (SL_sprites[sl_use_index * 4] - 16); + y = LY_actual - (SL_sprites[sl_use_index * 4] - 16); y = 15 - y; sprite_sel[0] = Core.VRAM[(SL_sprites[sl_use_index * 4 + 2] & 0xFE) * 16 + y * 2]; sprite_sel[1] = Core.VRAM[(SL_sprites[sl_use_index * 4 + 2] & 0xFE) * 16 + y * 2 + 1]; } else { - y = LY - (SL_sprites[sl_use_index * 4] - 16); + y = LY_actual - (SL_sprites[sl_use_index * 4] - 16); y = 7 - y; sprite_sel[0] = Core.VRAM[SL_sprites[sl_use_index * 4 + 2] * 16 + y * 2]; sprite_sel[1] = Core.VRAM[SL_sprites[sl_use_index * 4 + 2] * 16 + y * 2 + 1]; @@ -941,13 +941,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { if (LCDC.Bit(2)) { - y = LY - (SL_sprites[sl_use_index * 4] - 16); + y = LY_actual - (SL_sprites[sl_use_index * 4] - 16); sprite_sel[0] = Core.VRAM[(SL_sprites[sl_use_index * 4 + 2] & 0xFE) * 16 + y * 2]; sprite_sel[1] = Core.VRAM[(SL_sprites[sl_use_index * 4 + 2] & 0xFE) * 16 + y * 2 + 1]; } else { - y = LY - (SL_sprites[sl_use_index * 4] - 16); + y = LY_actual - (SL_sprites[sl_use_index * 4] - 16); sprite_sel[0] = Core.VRAM[SL_sprites[sl_use_index * 4 + 2] * 16 + y * 2]; sprite_sel[1] = Core.VRAM[SL_sprites[sl_use_index * 4 + 2] * 16 + y * 2 + 1]; } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Timer.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Timer.cs index 1a6aa88e0a..4107a8da63 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Timer.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Timer.cs @@ -93,6 +93,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk write_ignore = 4; TMA_coincidence = true; + } + else if (pending_reload == 1 && !reload_block) + { + // set interrupts if (Core.REG_FFFF.Bit(2)) { Core.cpu.FlagI = true; } Core.REG_FF0F |= 0x04;