diff options
author | StapleButter <thetotalworm@gmail.com> | 2018-12-12 02:48:37 +0100 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2018-12-12 02:48:37 +0100 |
commit | e7a4fe11ed7eb6a4b4d3cc3cc3c31d0e90722ba7 (patch) | |
tree | ac7fa78d6cb7274144f087229b24e804d9dfe332 /src | |
parent | d92c7e79df1eecf5c287cf76011dcb4cd4228ebc (diff) |
add nocashPrint type shit
Diffstat (limited to 'src')
-rw-r--r-- | src/ARMInterpreter_ALU.cpp | 9 | ||||
-rw-r--r-- | src/NDS.cpp | 126 | ||||
-rw-r--r-- | src/NDS.h | 1 |
3 files changed, 136 insertions, 0 deletions
diff --git a/src/ARMInterpreter_ALU.cpp b/src/ARMInterpreter_ALU.cpp index 9bfcbd1..f70763d 100644 --- a/src/ARMInterpreter_ALU.cpp +++ b/src/ARMInterpreter_ALU.cpp @@ -1501,6 +1501,15 @@ void T_MOV_HIREG(ARM* cpu) { cpu->R[rd] = cpu->R[rs]; } + + // nocash-style debugging hook + if ((cpu->CurInstr & 0xFFFF) == 0x46E4 && // mov r12, r12 + (cpu->NextInstr[0] & 0xF800) == 0xE000 && // branch + (cpu->NextInstr[1] & 0xFFFF) == 0x6464) + { + u32 addr = cpu->R[15] + 2; + NDS::NocashPrint(cpu->Num, addr); + } } diff --git a/src/NDS.cpp b/src/NDS.cpp index 48b2ec4..54a52b3 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -71,6 +71,10 @@ u8 ARM7MemTimings[0x20000][4]; ARMv5* ARM9; ARMv4* ARM7; +u32 NumFrames; +u64 SysClockCycles; +u64 LastSysClockCycles; + s32 CurIterationCycles; s32 ARM7Offset; int CurCPU; @@ -387,6 +391,9 @@ void Reset() dbg_CyclesTimer7 = 0; #endif // DEBUG_CHECK_DESYNC + SysClockCycles = 0; + LastSysClockCycles = 0; + f = melon_fopen_local("bios9.bin", "rb"); if (!f) { @@ -838,6 +845,9 @@ u32 RunFrame() RunLooseTimers(1, ndscyclestorun); RunSystem(ndscyclestorun); + + SysClockCycles += ndscyclestorun; + LastSysClockCycles += ndscyclestorun; } #ifdef DEBUG_CHECK_DESYNC @@ -849,6 +859,8 @@ u32 RunFrame() dbg_CyclesTimer7-dbg_CyclesSys); #endif + NumFrames++; + return GPU::TotalScanlines; } @@ -1095,6 +1107,120 @@ u32 GetPC(u32 cpu) return cpu ? ARM7->R[15] : ARM9->R[15]; } +u64 GetSysClockCycles(int num) +{ + u64 ret; + + if (num == 0) + { + ret = SysClockCycles; + + if (CurCPU == 1) ret += (ARM9->Cycles >> 1); + else if (CurCPU == 2) ret += ARM7->Cycles; + } + else + { + ret = LastSysClockCycles; + + if (CurCPU == 1) + { + ret += (ARM9->Cycles >> 1); + LastSysClockCycles = -(ARM9->Cycles >> 1); + } + else if (CurCPU == 2) + { + ret += ARM7->Cycles; + LastSysClockCycles = -ARM7->Cycles; + } + } + + return ret; +} + +void NocashPrint(u32 ncpu, u32 addr) +{ + // addr: u16 flags (TODO: research? libnds doesn't use those) + // addr+2: debug string + + addr += 2; + + ARM* cpu = ncpu ? (ARM*)ARM7 : (ARM*)ARM9; + u8 (*readfn)(u32) = ncpu ? NDS::ARM7Read8 : NDS::ARM9Read8; + + char output[1024]; + int ptr = 0; + + for (int i = 0; i < 120 && ptr < 1023; ) + { + char ch = readfn(addr++); + i++; + + if (ch == '%') + { + char cmd[16]; int j; + for (j = 0; j < 15; ) + { + char ch2 = readfn(addr++); + i++; + if (i >= 120) break; + if (ch2 == '%') break; + cmd[j++] = ch2; + } + cmd[j] = '\0'; + + char subs[64]; + + if (cmd[0] == 'r') + { + if (!strcmp(cmd, "r0")) sprintf(subs, "%08X", cpu->R[0]); + else if (!strcmp(cmd, "r1")) sprintf(subs, "%08X", cpu->R[1]); + else if (!strcmp(cmd, "r2")) sprintf(subs, "%08X", cpu->R[2]); + else if (!strcmp(cmd, "r3")) sprintf(subs, "%08X", cpu->R[3]); + else if (!strcmp(cmd, "r4")) sprintf(subs, "%08X", cpu->R[4]); + else if (!strcmp(cmd, "r5")) sprintf(subs, "%08X", cpu->R[5]); + else if (!strcmp(cmd, "r6")) sprintf(subs, "%08X", cpu->R[6]); + else if (!strcmp(cmd, "r7")) sprintf(subs, "%08X", cpu->R[7]); + else if (!strcmp(cmd, "r8")) sprintf(subs, "%08X", cpu->R[8]); + else if (!strcmp(cmd, "r9")) sprintf(subs, "%08X", cpu->R[9]); + else if (!strcmp(cmd, "r10")) sprintf(subs, "%08X", cpu->R[10]); + else if (!strcmp(cmd, "r11")) sprintf(subs, "%08X", cpu->R[11]); + else if (!strcmp(cmd, "r12")) sprintf(subs, "%08X", cpu->R[12]); + else if (!strcmp(cmd, "r13")) sprintf(subs, "%08X", cpu->R[13]); + else if (!strcmp(cmd, "r14")) sprintf(subs, "%08X", cpu->R[14]); + else if (!strcmp(cmd, "r15")) sprintf(subs, "%08X", cpu->R[15]); + } + else + { + if (!strcmp(cmd, "sp")) sprintf(subs, "%08X", cpu->R[13]); + else if (!strcmp(cmd, "lr")) sprintf(subs, "%08X", cpu->R[14]); + else if (!strcmp(cmd, "pc")) sprintf(subs, "%08X", cpu->R[15]); + else if (!strcmp(cmd, "frame")) sprintf(subs, "%d", NumFrames); + else if (!strcmp(cmd, "scanline")) sprintf(subs, "%d", GPU::VCount); + else if (!strcmp(cmd, "totalclks")) sprintf(subs, "%lu", GetSysClockCycles(0)); + else if (!strcmp(cmd, "lastclks")) sprintf(subs, "%lu", GetSysClockCycles(1)); + else if (!strcmp(cmd, "zeroclks")) + { + sprintf(subs, ""); + GetSysClockCycles(1); + } + } + + int slen = strlen(subs); + if ((ptr+slen) > 1023) slen = 1023-ptr; + strncpy(&output[ptr], subs, slen); + ptr += slen; + } + else + { + output[ptr++] = ch; + if (ch == '\0') break; + } + } + + output[ptr] = '\0'; + printf("%s", output); +} + void HandleTimerOverflow(u32 tid) @@ -170,6 +170,7 @@ void GXFIFOStall(); void GXFIFOUnstall(); u32 GetPC(u32 cpu); +void NocashPrint(u32 cpu, u32 addr); bool DMAsInMode(u32 cpu, u32 mode); bool DMAsRunning(u32 cpu); |