Implement "lag frame" flag and counter (#949)

* Implement "lag frame" flag and counter, and expose flag and both frame counters. BizHawk wants these.

* Track frame count and lag frames while the system isn't running.
This commit is contained in:
SuuperW
2021-01-21 14:26:27 -06:00
committed by GitHub
parent 8a068c2294
commit d42ca1ec4b
3 changed files with 94 additions and 74 deletions

View File

@ -77,6 +77,8 @@ ARMv5* ARM9;
ARMv4* ARM7;
u32 NumFrames;
u32 NumLagFrames;
bool LagFrameFlag;
u64 LastSysClockCycles;
u64 FrameStartTimestamp;
@ -765,6 +767,11 @@ bool DoSavestate(Savestate* file)
file->Var64(&LastSysClockCycles);
file->Var64(&FrameStartTimestamp);
file->Var32(&NumFrames);
if (file->IsAtleastVersion(7, 1))
{
file->Var32(&NumLagFrames);
file->Bool32(&LagFrameFlag);
}
// TODO: save KeyInput????
file->Var16(&KeyCnt);
@ -910,9 +917,10 @@ u32 RunFrame()
{
FrameStartTimestamp = SysTimestamp;
if (!Running) return 263; // dorp
if (CPUStop & 0x40000000) return 263;
LagFrameFlag = true;
bool runFrame = Running && !(CPUStop & 0x40000000);
if (runFrame)
{
GPU::StartFrame();
while (Running && GPU::TotalScanlines==0)
@ -999,10 +1007,18 @@ u32 RunFrame()
SPU::TransferOutput();
NDSCart::FlushSRAMFile();
}
// 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.
NumFrames++;
if (LagFrameFlag)
NumLagFrames++;
if (runFrame)
return GPU::TotalScanlines;
else
return 263;
}
u32 RunFrame()
@ -2787,8 +2803,8 @@ u8 ARM9IORead8(u32 addr)
{
switch (addr)
{
case 0x04000130: return KeyInput & 0xFF;
case 0x04000131: return (KeyInput >> 8) & 0xFF;
case 0x04000130: LagFrameFlag = false; return KeyInput & 0xFF;
case 0x04000131: LagFrameFlag = false; return (KeyInput >> 8) & 0xFF;
case 0x04000132: return KeyCnt & 0xFF;
case 0x04000133: return KeyCnt >> 8;
@ -2889,7 +2905,7 @@ u16 ARM9IORead16(u32 addr)
case 0x0400010C: return TimerGetCounter(3);
case 0x0400010E: return Timers[3].Cnt;
case 0x04000130: return KeyInput & 0xFFFF;
case 0x04000130: LagFrameFlag = false; return KeyInput & 0xFFFF;
case 0x04000132: return KeyCnt;
case 0x04000180: return IPCSync9;
@ -3007,7 +3023,7 @@ u32 ARM9IORead32(u32 addr)
case 0x04000108: return TimerGetCounter(2) | (Timers[2].Cnt << 16);
case 0x0400010C: return TimerGetCounter(3) | (Timers[3].Cnt << 16);
case 0x04000130: return (KeyInput & 0xFFFF) | (KeyCnt << 16);
case 0x04000130: LagFrameFlag = false; return (KeyInput & 0xFFFF) | (KeyCnt << 16);
case 0x04000180: return IPCSync9;
case 0x04000184: return ARM9IORead16(addr);

View File

@ -140,6 +140,10 @@ extern int CurCPU;
extern u8 ARM9MemTimings[0x40000][4];
extern u8 ARM7MemTimings[0x20000][4];
extern u32 NumFrames;
extern u32 NumLagFrames;
extern bool LagFrameFlag;
extern u64 ARM9Timestamp, ARM9Target;
extern u64 ARM7Timestamp, ARM7Target;
extern u32 ARM9ClockShift;

View File

@ -23,7 +23,7 @@
#include "types.h"
#define SAVESTATE_MAJOR 7
#define SAVESTATE_MINOR 0
#define SAVESTATE_MINOR 1
class Savestate
{