1
0
Fork 0
mirror of https://github.com/melonDS-emu/melonDS.git synced 2025-03-06 21:00:31 +01:00

improve timer irqs

This commit is contained in:
Jaklyy 2024-12-27 15:39:09 -05:00
parent c9e7eec2b5
commit a919e7b6af
2 changed files with 22 additions and 27 deletions

View file

@ -2168,43 +2168,37 @@ void NDS::SetGBASlotTimings()
} }
void NDS::UpdateIRQ(u32 cpu) void NDS::UpdateIRQ(u32 cpu, s32 delay)
{ {
ARM& arm = cpu ? (ARM&)ARM7 : (ARM&)ARM9; ARM& arm = cpu ? (ARM&)ARM7 : (ARM&)ARM9;
u64 time; u64 time;
if (CurCPU == 0) if (CurCPU == 0)
{ {
time = (std::max(ARM9Timestamp, DMA9Timestamp) >> ARM9ClockShift) + 4; time = (std::max(ARM9Timestamp, DMA9Timestamp) >> ARM9ClockShift) + 4 + delay;
} }
else if (CurCPU == 1) else if (CurCPU == 1)
{ {
time = ARM7Timestamp + 4; time = ARM7Timestamp + 4 + delay;
} }
else else
{ {
time = SysTimestamp + 4; time = SysTimestamp + 4 + delay;
} }
if (IME[cpu] & 0x1) if (IME[cpu] & 0x1)
{ {
/*arm.IRQ = !!(IE[cpu] & IF[cpu]); if ((IE[cpu] & IF[cpu]))
if ((ConsoleType == 1) && cpu)
arm.IRQ |= !!(IE2 & IF2);*/
{ {
if ((IE[cpu] & IF[cpu])) if (time < arm.IRQTimestamp) arm.IRQTimestamp = time;
{ }
if (time < arm.IRQTimestamp) arm.IRQTimestamp = time; else if (((ConsoleType == 1) && cpu) && (IE2 & IF2))
} {
else if (((ConsoleType == 1) && cpu) && (IE2 & IF2)) if (time < arm.IRQTimestamp) arm.IRQTimestamp = time;
{ }
if (time < arm.IRQTimestamp) arm.IRQTimestamp = time; else
} {
else arm.IRQTimestamp = UINT64_MAX;
{
arm.IRQTimestamp = UINT64_MAX;
}
} }
} }
else else
@ -2215,10 +2209,10 @@ void NDS::UpdateIRQ(u32 cpu)
if (cpu == 0) arm.IRQTimestamp <<= ARM9ClockShift; if (cpu == 0) arm.IRQTimestamp <<= ARM9ClockShift;
} }
void NDS::SetIRQ(u32 cpu, u32 irq) void NDS::SetIRQ(u32 cpu, u32 irq, s32 delay)
{ {
IF[cpu] |= (1 << irq); IF[cpu] |= (1 << irq);
UpdateIRQ(cpu); UpdateIRQ(cpu, delay);
if ((cpu == 1) && (CPUStop & CPUStop_Sleep)) if ((cpu == 1) && (CPUStop & CPUStop_Sleep))
{ {
@ -2455,9 +2449,10 @@ void NDS::HandleTimerOverflow(u32 tid)
{ {
Timer* timer = &Timers[tid]; Timer* timer = &Timers[tid];
timer->Counter += (timer->Reload << 10);
if (timer->Cnt & (1<<6)) if (timer->Cnt & (1<<6))
SetIRQ(tid >> 2, IRQ_Timer0 + (tid & 0x3)); SetIRQ(tid >> 2, IRQ_Timer0 + (tid & 0x3), -(timer->Counter >> timer->CycleShift));
timer->Counter += (timer->Reload << 10);
if ((tid & 0x3) == 3) if ((tid & 0x3) == 3)
return; return;

View file

@ -440,8 +440,8 @@ public: // TODO: Encapsulate the rest of these members
void MapSharedWRAM(u8 val); void MapSharedWRAM(u8 val);
void UpdateIRQ(u32 cpu); void UpdateIRQ(u32 cpu, s32 delay = 0);
void SetIRQ(u32 cpu, u32 irq); void SetIRQ(u32 cpu, u32 irq, s32 delay = 0);
void ClearIRQ(u32 cpu, u32 irq); void ClearIRQ(u32 cpu, u32 irq);
void SetIRQ2(u32 irq); void SetIRQ2(u32 irq);
void ClearIRQ2(u32 irq); void ClearIRQ2(u32 irq);