GPU: Improve CRTC hblank accuracy

And implement Timer0 gating, it was missing previously.
This commit is contained in:
Stenzek
2024-04-27 21:50:18 +10:00
parent 5d20f4514d
commit 3be02c53c1
3 changed files with 157 additions and 75 deletions

View File

@ -67,10 +67,8 @@ public:
enum : u16
{
NTSC_TICKS_PER_LINE = 3413,
NTSC_HSYNC_TICKS = 200,
NTSC_TOTAL_LINES = 263,
PAL_TICKS_PER_LINE = 3406,
PAL_HSYNC_TICKS = 200, // actually one more on odd lines
PAL_TOTAL_LINES = 314,
};
@ -183,8 +181,19 @@ public:
bool ConvertDisplayCoordinatesToBeamTicksAndLines(float display_x, float display_y, float x_scale, u32* out_tick,
u32* out_line) const;
// Returns the current beam position.
void GetBeamPosition(u32* out_ticks, u32* out_line);
// Returns the number of system clock ticks until the specified tick/line.
TickCount GetSystemTicksUntilTicksAndLine(u32 ticks, u32 line);
// Returns the number of visible lines.
ALWAYS_INLINE u16 GetCRTCActiveStartLine() const { return m_crtc_state.vertical_display_start; }
ALWAYS_INLINE u16 GetCRTCActiveEndLine() const { return m_crtc_state.vertical_display_end; }
// Returns the video clock frequency.
TickCount GetCRTCFrequency() const;
u16 GetCRTCDotClockDivider() const { return m_crtc_state.dot_clock_divider; }
// Dumps raw VRAM to a file.
bool DumpVRAMToFile(const char* filename);
@ -517,8 +526,10 @@ protected:
u16 vertical_display_start;
u16 vertical_display_end;
u16 horizontal_active_start;
u16 horizontal_active_end;
u16 horizontal_total;
u16 horizontal_sync_start; // <- not currently saved to state, so we don't have to bump the version
u16 vertical_total;
TickCount fractional_ticks;
@ -533,6 +544,12 @@ protected:
u8 interlaced_field; // 0 = odd, 1 = even
u8 interlaced_display_field;
u8 active_line_lsb;
ALWAYS_INLINE void UpdateHBlankFlag()
{
in_hblank =
(current_tick_in_scanline < horizontal_active_start || current_tick_in_scanline >= horizontal_active_end);
}
} m_crtc_state = {};
BlitterState m_blitter_state = BlitterState::Idle;