Skip to content

Commit

Permalink
[DMG] Trigger STAT-LYC IRQs whenever LYC is rewritten. Also trigger L…
Browse files Browse the repository at this point in the history
…ine 153 and Line 0 STAT-LYCs IRQs on Line 153
  • Loading branch information
shonumi committed Dec 18, 2016
1 parent c105dd0 commit 613aced
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/dmg/lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1997,16 +1997,22 @@ void DMG_LCD::step(int cpu_clock)
lcd_stat.current_scanline++;

//By line 153, LCD has actually reached the top of the screen again
//It will sit at Line 0 for 456 before entering Mode 2 properly
//Line 0 STAT-LYC IRQs should be triggered here
//LY will read 153 for only a few cycles, then go to 0 for the rest of the scanline
//Line 153 and Line 0 STAT-LYC IRQs should be triggered here
if(lcd_stat.current_scanline == 153)
{
//Do a scanline compare for Line 153 now
mem->memory_map[REG_LY] = lcd_stat.current_scanline;
scanline_compare();

//Set LY to 0, also trigger Line 0 STAT-LYC IRQ if necessary
//Technically this should fire 8 cycles into the scanline
lcd_stat.current_scanline = 0;
mem->memory_map[REG_LY] = lcd_stat.current_scanline;
scanline_compare();
}

//After sitting on Line 0 for 456 cycles, reset LCD clock, scanline count
//After Line 153 reset LCD clock, scanline count
else if(lcd_stat.current_scanline == 1)
{
lcd_stat.lcd_clock -= 70224;
Expand Down
15 changes: 15 additions & 0 deletions src/dmg/mmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,21 @@ void DMG_MMU::write_u8(u16 address, u8 value)
lcd_stat->current_scanline = 0;
}

//LYC
else if(address == REG_LYC)
{
memory_map[REG_LYC] = value;

//Perform LY-LYC compare immediately
if(memory_map[REG_LY] == memory_map[REG_LYC])
{
memory_map[REG_STAT] |= 0x4;
if(memory_map[REG_STAT] & 0x40) { memory_map[IF_FLAG] |= 2; }
}

else { memory_map[REG_STAT] &= ~0x4; }
}

//LCDC
else if(address == REG_LCDC)
{
Expand Down

1 comment on commit 613aced

@shonumi
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pretty much fixes everything that was wrong with Sagaia. Line 153 STAT-LYC IRQs let the game boot, and LYC rewrites fix the broken BG if scrolling too low during gameplay.

Please sign in to comment.