GBHawk: Speed switch timing fix.

This commit is contained in:
alyosha-tas 2020-05-18 15:43:51 -04:00
parent e075012b70
commit c96a233d5d
4 changed files with 34 additions and 21 deletions

View File

@ -576,7 +576,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
// exit halt / stop loop // exit halt / stop loop
instr_table[256 * 60 * 2 + 60] = IDLE; instr_table[256 * 60 * 2 + 60] = IDLE;
instr_table[256 * 60 * 2 + 60 + 1] = IDLE; instr_table[256 * 60 * 2 + 60 + 1] = IDLE;
instr_table[256 * 60 * 2 + 60 + 2] = IDLE; instr_table[256 * 60 * 2 + 60 + 2] = HALT_CHK;
instr_table[256 * 60 * 2 + 60 + 3] = OP; instr_table[256 * 60 * 2 + 60 + 3] = OP;
// skipped loop // skipped loop

View File

@ -425,7 +425,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
if (!stop_check) if (!stop_check)
{ {
// Z contains the second stop byte, not sure if it's useful at all // Z contains the second stop byte, not sure if it's useful at all
stop_time = SpeedFunc(Regs[Z]); stop_time = SpeedFunc(0);
stop_check = true; stop_check = true;
} }
@ -433,6 +433,11 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
if (stop_time > 0) if (stop_time > 0)
{ {
if (stop_time == (32768 - 43))
{
SpeedFunc(1);
}
stop_time--; stop_time--;
if (stop_time == 0) if (stop_time == 0)

View File

@ -101,10 +101,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{ {
// These things all tick twice as fast in GBC double speed mode // These things all tick twice as fast in GBC double speed mode
// Note that DMA is halted when the CPU is halted // Note that DMA is halted when the CPU is halted
if (ppu.DMA_start && !cpu.halted && !cpu.stopped) { ppu.DMA_tick(); }
serialport.serial_transfer_tick();
cpu.ExecuteOne();
timer.tick();
if (double_speed) if (double_speed)
{ {
@ -113,17 +109,22 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
cpu.ExecuteOne(); cpu.ExecuteOne();
timer.tick(); timer.tick();
} }
if (ppu.DMA_start && !cpu.halted && !cpu.stopped) { ppu.DMA_tick(); }
serialport.serial_transfer_tick();
cpu.ExecuteOne();
timer.tick();
} }
else else
{ {
cpu.TotalExecutedCycles++;
timer.tick();
if (double_speed) if (double_speed)
{ {
cpu.TotalExecutedCycles++; cpu.TotalExecutedCycles++;
timer.tick(); timer.tick();
} }
cpu.TotalExecutedCycles++;
timer.tick();
} }
if (in_vblank && !in_vblank_old) if (in_vblank && !in_vblank_old)
@ -253,6 +254,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
// Switch Speed (GBC only) // Switch Speed (GBC only)
public int SpeedFunc(int temp) public int SpeedFunc(int temp)
{
if (temp == 0)
{ {
if (is_GBC) if (is_GBC)
{ {
@ -260,8 +263,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{ {
speed_switch = false; speed_switch = false;
Console.WriteLine("Speed Switch: " + cpu.TotalExecutedCycles); Console.WriteLine("Speed Switch: " + cpu.TotalExecutedCycles);
int ret = double_speed ? (32768 - 20) : (32768 - 20); // actual time needs checking int ret = double_speed ? 32768 - 20 : 32768 - 20; // actual time needs checking
double_speed = !double_speed;
return ret; return ret;
} }
@ -272,6 +274,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
// if we are in GB mode, return 0, cannot switch speed // if we are in GB mode, return 0, cannot switch speed
return 0; return 0;
} }
else
{
double_speed = !double_speed;
return 0;
}
}
public void GetControllerState(IController controller) public void GetControllerState(IController controller)
{ {

View File

@ -101,7 +101,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
case 0xFF4D: case 0xFF4D:
if (GBC_compat) if (GBC_compat)
{ {
ret = (byte)(((double_speed ? 1 : 0) << 7) + ((speed_switch ? 1 : 0))); ret = (byte)(((double_speed ? 1 : 0) << 7) | (speed_switch ? 1 : 0) | 0x7E);
} }
else else
{ {