diff --git a/src/GPU.cpp b/src/GPU.cpp index bb3d57fd..acbc9f17 100644 --- a/src/GPU.cpp +++ b/src/GPU.cpp @@ -33,14 +33,12 @@ using Platform::LogLevel; #define LINE_CYCLES (355*6) #define HBLANK_CYCLES (48+(256*6)) #define FRAME_CYCLES (LINE_CYCLES * 263) -#define READ_CYCLES (520) // CHECKME: Probably off by a little bit enum { LCD_StartHBlank = 0, LCD_StartScanline, LCD_FinishFrame, - LCD_ReadScanline, }; @@ -75,7 +73,6 @@ GPU::GPU(melonDS::NDS& nds, std::unique_ptr&& renderer3d, std::uniqu NDS.RegisterEventFunc(Event_LCD, LCD_StartHBlank, MemberEventFunc(GPU, StartHBlank)); NDS.RegisterEventFunc(Event_LCD, LCD_StartScanline, MemberEventFunc(GPU, StartScanline)); NDS.RegisterEventFunc(Event_LCD, LCD_FinishFrame, MemberEventFunc(GPU, FinishFrame)); - NDS.RegisterEventFunc(Event_LCD, LCD_ReadScanline, MemberEventFunc(GPU, ReadScanline)); NDS.RegisterEventFunc(Event_DisplayFIFO, 0, MemberEventFunc(GPU, DisplayFIFO)); NDS.RegisterEventFunc(Event_DisplayFIFO, 0, MemberEventFunc(GPU, DisplayFIFO)); @@ -89,7 +86,6 @@ GPU::~GPU() noexcept NDS.UnregisterEventFunc(Event_LCD, LCD_StartHBlank); NDS.UnregisterEventFunc(Event_LCD, LCD_StartScanline); NDS.UnregisterEventFunc(Event_LCD, LCD_FinishFrame); - NDS.UnregisterEventFunc(Event_LCD, LCD_ReadScanline); NDS.UnregisterEventFunc(Event_DisplayFIFO, 0); } @@ -883,6 +879,11 @@ void GPU::StartHBlank(u32 line) noexcept { DispStat[0] |= (1<<1); DispStat[1] |= (1<<1); + + // not the correct timing, but... close enough i guess? + int scanline = (VCount == 262 ? 0 : (line+1)); + GPU3D.ScanlineSync(scanline); + if (GPU3D.UnderflowFlagVCount == scanline) GPU3D.DispCnt |= (1<<12); if (VCount < 192) { @@ -915,10 +916,10 @@ void GPU::StartHBlank(u32 line) noexcept if (DispStat[0] & (1<<4)) NDS.SetIRQ(0, IRQ_HBlank); if (DispStat[1] & (1<<4)) NDS.SetIRQ(1, IRQ_HBlank); - if (VCount == 262 || VCount < 191) // this is probably wrong, but i haven't dug deep enough to prove it yet - NDS.ScheduleEvent(Event_LCD, true, (LINE_CYCLES - HBLANK_CYCLES - READ_CYCLES), LCD_ReadScanline, line); - else + if (VCount < 262) NDS.ScheduleEvent(Event_LCD, true, (LINE_CYCLES - HBLANK_CYCLES), LCD_StartScanline, line+1); + else + NDS.ScheduleEvent(Event_LCD, true, (LINE_CYCLES - HBLANK_CYCLES), LCD_FinishFrame, line+1); } void GPU::FinishFrame(u32 lines) noexcept @@ -953,19 +954,6 @@ void GPU::BlankFrame() noexcept TotalScanlines = 263; } -void GPU::ReadScanline(u32 line) noexcept -{ - int scanline; - scanline = (VCount == 262 ? 0 : (line+1)); - GPU3D.ScanlineSync(scanline); - if (GPU3D.UnderflowFlagVCount == scanline) GPU3D.DispCnt |= (1<<12); - - if (VCount != 262) - NDS.ScheduleEvent(Event_LCD, true, READ_CYCLES, LCD_StartScanline, line+1); - else - NDS.ScheduleEvent(Event_LCD, true, READ_CYCLES, LCD_FinishFrame, line+1); -} - void GPU::StartScanline(u32 line) noexcept { if (line == 0) diff --git a/src/GPU.h b/src/GPU.h index e1f4b89d..780d5e01 100644 --- a/src/GPU.h +++ b/src/GPU.h @@ -506,7 +506,6 @@ public: void BlankFrame() noexcept; void StartScanline(u32 line) noexcept; void StartHBlank(u32 line) noexcept; - void ReadScanline(u32 line) noexcept; void DisplayFIFO(u32 x) noexcept; diff --git a/src/GPU3D_Soft.cpp b/src/GPU3D_Soft.cpp index d99bbba6..eca3fa5b 100644 --- a/src/GPU3D_Soft.cpp +++ b/src/GPU3D_Soft.cpp @@ -2158,7 +2158,7 @@ void SoftRenderer::RenderThreadFunc(GPU& gpu) } void SoftRenderer::ScanlineSync(int line) { - if (RenderThreadRunning.load(std::memory_order_relaxed)) + if (Accuracy && RenderThreadRunning.load(std::memory_order_relaxed)) { if (line < 192) // We need a scanline, so let's wait for the render thread to finish it. @@ -2170,6 +2170,14 @@ void SoftRenderer::ScanlineSync(int line) u32* SoftRenderer::GetLine(int line) { + if (!Accuracy && RenderThreadRunning.load(std::memory_order_relaxed)) + { + if (line < 192) + // We need a scanline, so let's wait for the render thread to finish it. + // (both threads process scanlines from top-to-bottom, + // so we don't need to wait for a specific row) + Platform::Semaphore_Wait(Sema_ScanlineCount); + } return &FinalBuffer[line * ScanlineWidth]; }