From 5e6972e4dae1cc9523b722eea7849fea198393d0 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Sun, 16 Oct 2022 21:40:58 +0200 Subject: [PATCH] Emulator: Fix PPU clocks and LCD offsets --- src/loader.cpp | 4 ++-- src/ppu.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/loader.cpp b/src/loader.cpp index 3dbb304..433595f 100644 --- a/src/loader.cpp +++ b/src/loader.cpp @@ -43,9 +43,9 @@ void Loader::init() { destroy(); - Emu::the().init(8000000); + Emu::the().init(4000000); - auto cpu = std::make_shared(8000000); + auto cpu = std::make_shared(4000000); auto ppu = std::make_shared(4000000); Emu::the().addProcessingUnit("CPU", cpu); diff --git a/src/ppu.cpp b/src/ppu.cpp index 5fdfb4d..4742968 100644 --- a/src/ppu.cpp +++ b/src/ppu.cpp @@ -48,7 +48,7 @@ void PPU::update() case State::OAMSearch: // OAM logic goes here.. - if (m_clocks_into_frame % 20 == 0) { + if (m_clocks_into_frame % 80 == 0) { m_state = State::PixelTransfer; } break; @@ -64,26 +64,26 @@ void PPU::update() case State::HBlank: // H-Blank logic goes here.. - if (m_clocks_into_frame % (20 + 43 + 51) == 0) { + if (m_clocks_into_frame % (80 + 172 + 204) == 0) { + m_lcd_y_coordinate++; if (m_lcd_y_coordinate == 144) { m_state = State::VBlank; } else { m_state = State::OAMSearch; } - m_lcd_y_coordinate++; } break; case State::VBlank: // V-Blank logic goes here.. - if (m_clocks_into_frame % (20 + 43 + 51) == 0) { + if (m_clocks_into_frame % (80 + 172 + 204) == 0) { + m_lcd_y_coordinate++; if (m_lcd_y_coordinate == 154) { m_lcd_y_coordinate = 0; m_clocks_into_frame = 0; m_state = State::OAMSearch; } - m_lcd_y_coordinate++; } break;