diff --git a/src/NDS.cpp b/src/NDS.cpp index 04af0079..183903bf 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -1760,54 +1760,55 @@ u32 NDS::RunFrame() u64 target = NextTarget(); ARM9Target = target << ARM9ClockShift; + ARM7Target = target; - while (std::max(std::max(ARM9Timestamp, DMA9Timestamp), A9ContentionTS << ARM9ClockShift) < ARM9Target) + while (((std::max(std::max(ARM9Timestamp, DMA9Timestamp), A9ContentionTS << ARM9ClockShift) < ARM9Target) && (ARM9.MRTrack.Type == MainRAMType::Null)) + || (ARM7Timestamp < ARM7Target) && (ARM7.MRTrack.Type == MainRAMType::Null)) { - CurCPU = 0; - RunTimers(0); - GPU.GPU3D.Run(); + while (std::max(std::max(ARM9Timestamp, DMA9Timestamp), A9ContentionTS << ARM9ClockShift) < ARM9Target) + { + CurCPU = 0; + RunTimers(0); + GPU.GPU3D.Run(); - if (CPUStop & CPUStop_GXStall) - { - // GXFIFO stall - s32 cycles = GPU.GPU3D.CyclesToRunFor(); - DMA9Timestamp = std::min(ARM9Target, std::max(ARM9Timestamp, DMA9Timestamp)+(cycles<(*this); - dsi.RunNDMAs(0); + DMAs[0].Run(); + if (!(CPUStop & CPUStop_GXStall) && (ARM9.MRTrack.Type == MainRAMType::Null)) DMAs[1].Run(); + if (!(CPUStop & CPUStop_GXStall) && (ARM9.MRTrack.Type == MainRAMType::Null)) DMAs[2].Run(); + if (!(CPUStop & CPUStop_GXStall) && (ARM9.MRTrack.Type == MainRAMType::Null)) DMAs[3].Run(); + if (ConsoleType == 1) + { + auto& dsi = dynamic_cast(*this); + dsi.RunNDMAs(0); + } + } + else + { + //if (ARM9.abt) ARM9Timestamp = ARM9Target; + ARM9.Execute(); } } - else - { - //if (ARM9.abt) ARM9Timestamp = ARM9Target; - ARM9.Execute(); - } + + //printf("MAIN LOOP: 9 %lli %lli %08X %08llX %i 7 %lli %lli %08X %08llX %i\n", ARM9Timestamp, ARM9Target, ARM9.PC, ARM9.CurInstr, (u8)ARM9.MRTrack.Type, ARM7Timestamp, ARM7Target, ARM7.R[15], ARM7.CurInstr, (u8)ARM7.MRTrack.Type); + + RunTimers(0); + GPU.GPU3D.Run(); + + if (MainRAMHandle()) break; } - //printf("MAIN LOOP: 9 %lli %08X %08llX %i 7 %lli %08X %08llX %i %i %08X\n", ARM9Timestamp>>ARM9ClockShift, ARM9.PC, ARM9.CurInstr, (u8)ARM9.MRTrack.Type, ARM7Timestamp, ARM7.R[15], ARM7.CurInstr, (u8)ARM7.MRTrack.Type, IME[1], IE[1]); - - RunTimers(0); - GPU.GPU3D.Run(); - - MainRAMHandle(); - - target = std::max(std::max(ARM9Timestamp, DMA9Timestamp) >> ARM9ClockShift, A9ContentionTS); - if (target == ARM7Timestamp) target++; - - while (ARM7Timestamp < target) + while (ARM7Timestamp < ARM7Target) { - ARM7Target = target; - //printf("A7 LOOP: %lli %lli\n", ARM9Timestamp>>ARM9ClockShift, ARM7Timestamp); + //printf("A7 LOOP: 9 %lli %lli %08X %08llX %i 7 %lli %lli %08X %08llX %i\n", ARM9Timestamp, ARM9Target, ARM9.PC, ARM9.CurInstr, (u8)ARM9.MRTrack.Type, ARM7Timestamp, ARM7Target, ARM7.R[15], ARM7.CurInstr, (u8)ARM7.MRTrack.Type); CurCPU = 1; RunTimers(1); @@ -1838,7 +1839,7 @@ u32 NDS::RunFrame() } } - RunSystem(target); + RunSystem(ARM7Target); if (CPUStop & CPUStop_Sleep) { @@ -1860,7 +1861,6 @@ u32 NDS::RunFrame() SPU.TransferOutput(); break; } - //printf("MAIN LOOP: 9 %lli %08X %08llX %i 7 %lli %08X %08llX %i %i %08X\n", ARM9Timestamp>>ARM9ClockShift, ARM9.PC, ARM9.CurInstr, (u8)ARM9.MRTrack.Type, ARM7Timestamp, ARM7.R[15], ARM7.CurInstr, (u8)ARM7.MRTrack.Type, IME[1], IE[1]); // In the context of TASes, frame count is traditionally the primary measure of emulated time, // so it needs to be tracked even if NDS is powered off. @@ -1894,13 +1894,11 @@ u32 NDS::RunFrame() void NDS::Reschedule(u64 target) { - if (CurCPU == 0) + if (target < ARM7Target) { - if (target < (ARM9Target >> ARM9ClockShift)) - ARM9Target = (target << ARM9ClockShift); - } - else if (target < ARM7Target) ARM7Target = target; + ARM9Target = (target << ARM9ClockShift); + } } void NDS::RegisterEventFuncs(u32 id, void* that, const std::initializer_list& funcs)