nvm ill just shove it into hblank

This commit is contained in:
Jaklyy 2024-04-21 11:31:12 -04:00
parent 36f555db33
commit 424c5755ea
3 changed files with 17 additions and 22 deletions

View File

@ -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>&& 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);
}
@ -884,6 +880,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)
{
// draw
@ -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)

View File

@ -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;

View File

@ -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];
}