Skip to content

Commit

Permalink
GBCHawk: Halt test rom work, ppu still needs re-work
Browse files Browse the repository at this point in the history
  • Loading branch information
alyosha-tas committed May 4, 2018
1 parent d4eb3da commit e29b741
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
33 changes: 24 additions & 9 deletions BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,15 @@ public void ExecuteOne(ref byte interrupt_src, byte interrupt_enable)
IDLE,
GBC_INTERRUPT };
*/
INTERRUPT_GBC_NOP();
if (!Halt_bug_3)
{
INTERRUPT_GBC_NOP();
}
else
{
INTERRUPT_();
Halt_bug_3 = false;
}
}
else
{
Expand All @@ -324,16 +332,26 @@ public void ExecuteOne(ref byte interrupt_src, byte interrupt_enable)
if (OnExecFetch != null) OnExecFetch(RegPC);
if (TraceCallback != null && !CB_prefix) TraceCallback(State());


if (is_GBC)
{
// extra 4 cycles for GBC
cur_instr = new ushort[]
if (Halt_bug_3)
{
RegPC++;
FetchInstruction(ReadMemory(RegPC));
Halt_bug_3 = false;
}
else
{
cur_instr = new ushort[]
{IDLE,
IDLE,
IDLE,
OP };
}
}
else
else
{
if (Halt_bug_3)
{
Expand Down Expand Up @@ -363,11 +381,9 @@ public void ExecuteOne(ref byte interrupt_src, byte interrupt_enable)
else
{
cur_instr = new ushort[]
{
IDLE,
{IDLE,
HALT_CHK,
IDLE,

IDLE,
HALT, 0 };
}

Expand Down Expand Up @@ -492,12 +508,11 @@ public void ExecuteOne(ref byte interrupt_src, byte interrupt_enable)
instr_pntr = 0;
break;
case HALT_CHK:
// only used when exiting HALT from GBC, an extra NOP is added to avoid HALT bug
I_use = FlagI;
if (Halt_bug_2 && I_use)
{
RegPC--;
if (!interrupts_enabled) { Halt_bug_3 = true; }
Halt_bug_3 = true;
}

Halt_bug_2 = false;
Expand Down
9 changes: 3 additions & 6 deletions BizHawk.Emulation.Cores/CPUs/LR35902/Tables_Direct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ private void HALT_()
{IDLE,
IDLE,
IDLE,
IDLE,
IDLE,
IDLE,
IDLE,
OP};
OP_G};
}
else
{ // if interrupts are disabled,
Expand All @@ -112,7 +108,8 @@ private void HALT_()
HALT_CHK,
IDLE,
HALT, 0 };
skip_once = true;

if (!is_GBC) { skip_once = true; }
// If the interrupt flag is not currently set, but it does get set in the first check
// then a bug is triggered
// With interrupts enabled, this runs the halt command twice
Expand Down
6 changes: 3 additions & 3 deletions BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public override void tick()

// also, the LCD does not enter mode 2 on scanline 0 when first turned on
no_scan = true;
cycle = 8;
cycle = 4;
}

// the VBL stat is continuously asserted
Expand All @@ -420,7 +420,7 @@ public override void tick()
}
}

if ((cycle == 4) && (LY == 144)) {
if ((cycle == 0) && (LY == 144)) {

HBL_INT = false;

Expand Down Expand Up @@ -454,7 +454,7 @@ public override void tick()
// there is no mode 2 (presumably it missed the trigger)
// mode 3 is very short, probably in some self test mode before turning on?

if (cycle == 12)
if (cycle == 8)
{
LYC_INT = false;
STAT &= 0xFB;
Expand Down

0 comments on commit e29b741

Please sign in to comment.