GPU: Simplify hsync handling

Fixes character lighting in Monkey Hero.
This commit is contained in:
Connor McLaughlin 2020-08-17 01:21:52 +10:00
parent 4e62b32d60
commit f65651823e
2 changed files with 10 additions and 4 deletions

View file

@ -449,6 +449,7 @@ void GPU::UpdateCRTCConfig()
cs.vertical_total = PAL_TOTAL_LINES; cs.vertical_total = PAL_TOTAL_LINES;
cs.current_scanline %= PAL_TOTAL_LINES; cs.current_scanline %= PAL_TOTAL_LINES;
cs.horizontal_total = PAL_TICKS_PER_LINE; cs.horizontal_total = PAL_TICKS_PER_LINE;
cs.horizontal_sync_start = PAL_HSYNC_TICKS;
cs.current_tick_in_scanline %= PAL_TICKS_PER_LINE; cs.current_tick_in_scanline %= PAL_TICKS_PER_LINE;
} }
else else
@ -456,9 +457,12 @@ void GPU::UpdateCRTCConfig()
cs.vertical_total = NTSC_TOTAL_LINES; cs.vertical_total = NTSC_TOTAL_LINES;
cs.current_scanline %= NTSC_TOTAL_LINES; cs.current_scanline %= NTSC_TOTAL_LINES;
cs.horizontal_total = NTSC_TICKS_PER_LINE; cs.horizontal_total = NTSC_TICKS_PER_LINE;
cs.horizontal_sync_start = NTSC_HSYNC_TICKS;
cs.current_tick_in_scanline %= NTSC_TICKS_PER_LINE; cs.current_tick_in_scanline %= NTSC_TICKS_PER_LINE;
} }
cs.in_hblank = (cs.current_tick_in_scanline >= cs.horizontal_sync_start);
const u8 horizontal_resolution_index = m_GPUSTAT.horizontal_resolution_1 | (m_GPUSTAT.horizontal_resolution_2 << 2); const u8 horizontal_resolution_index = m_GPUSTAT.horizontal_resolution_1 | (m_GPUSTAT.horizontal_resolution_2 << 2);
cs.dot_clock_divider = dot_clock_dividers[horizontal_resolution_index]; cs.dot_clock_divider = dot_clock_dividers[horizontal_resolution_index];
cs.horizontal_display_start = std::min<u16>(cs.regs.X1, cs.horizontal_total); cs.horizontal_display_start = std::min<u16>(cs.regs.X1, cs.horizontal_total);
@ -682,8 +686,8 @@ void GPU::CRTCTickEvent(TickCount ticks)
{ {
// short path when we execute <1 line.. this shouldn't occur often. // short path when we execute <1 line.. this shouldn't occur often.
const bool old_hblank = m_crtc_state.in_hblank; const bool old_hblank = m_crtc_state.in_hblank;
const bool new_hblank = m_crtc_state.current_tick_in_scanline < m_crtc_state.horizontal_display_start || const bool new_hblank = (m_crtc_state.current_tick_in_scanline >= m_crtc_state.horizontal_sync_start);
m_crtc_state.current_tick_in_scanline >= m_crtc_state.horizontal_display_end; m_crtc_state.in_hblank = new_hblank;
if (!old_hblank && new_hblank && g_timers.IsUsingExternalClock(HBLANK_TIMER_INDEX)) if (!old_hblank && new_hblank && g_timers.IsUsingExternalClock(HBLANK_TIMER_INDEX))
g_timers.AddTicks(HBLANK_TIMER_INDEX, 1); g_timers.AddTicks(HBLANK_TIMER_INDEX, 1);
@ -699,8 +703,7 @@ void GPU::CRTCTickEvent(TickCount ticks)
#endif #endif
const bool old_hblank = m_crtc_state.in_hblank; const bool old_hblank = m_crtc_state.in_hblank;
const bool new_hblank = m_crtc_state.current_tick_in_scanline < m_crtc_state.horizontal_display_start || const bool new_hblank = (m_crtc_state.current_tick_in_scanline >= m_crtc_state.horizontal_sync_start);
m_crtc_state.current_tick_in_scanline >= m_crtc_state.horizontal_display_end;
m_crtc_state.in_hblank = new_hblank; m_crtc_state.in_hblank = new_hblank;
if (g_timers.IsUsingExternalClock(HBLANK_TIMER_INDEX)) if (g_timers.IsUsingExternalClock(HBLANK_TIMER_INDEX))
{ {

View file

@ -102,8 +102,10 @@ public:
enum : u16 enum : u16
{ {
NTSC_TICKS_PER_LINE = 3413, NTSC_TICKS_PER_LINE = 3413,
NTSC_HSYNC_TICKS = 200,
NTSC_TOTAL_LINES = 263, NTSC_TOTAL_LINES = 263,
PAL_TICKS_PER_LINE = 3406, PAL_TICKS_PER_LINE = 3406,
PAL_HSYNC_TICKS = 200, // actually one more on odd lines
PAL_TOTAL_LINES = 314, PAL_TOTAL_LINES = 314,
}; };
@ -683,6 +685,7 @@ protected:
u16 display_vram_height; u16 display_vram_height;
u16 horizontal_total; u16 horizontal_total;
u16 horizontal_sync_start; // <- not currently saved to state, so we don't have to bump the version
u16 horizontal_active_start; u16 horizontal_active_start;
u16 horizontal_active_end; u16 horizontal_active_end;
u16 horizontal_display_start; u16 horizontal_display_start;