From 29c49a20636b77e558fb2363120830a01331e8c0 Mon Sep 17 00:00:00 2001 From: zilmar Date: Thu, 22 Aug 2024 17:32:05 +0930 Subject: [PATCH] RSP: Remove PrgCount as a global --- .../Recompiler/RspRecompilerCPU.cpp | 20 +++++----- .../Recompiler/RspRecompilerOps.cpp | 38 +++++++++---------- .../Recompiler/RspRecompilerOps.h | 1 + Source/Project64-rsp-core/cpu/RSPCpu.cpp | 3 +- Source/Project64-rsp-core/cpu/RSPCpu.h | 2 +- Source/Project64-rsp/RSP Command.cpp | 12 +++--- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/Source/Project64-rsp-core/Recompiler/RspRecompilerCPU.cpp b/Source/Project64-rsp-core/Recompiler/RspRecompilerCPU.cpp index dca168238..4b8ff9ab8 100644 --- a/Source/Project64-rsp-core/Recompiler/RspRecompilerCPU.cpp +++ b/Source/Project64-rsp-core/Recompiler/RspRecompilerCPU.cpp @@ -663,7 +663,7 @@ Resolves all the collected branches, x86 style void CRSPRecompiler::LinkBranches(RSP_BLOCK * Block) { - uint32_t OrigPrgCount = *PrgCount; + uint32_t OrigPrgCount = *m_System.m_SP_PC_REG; uint32_t Count, Target; uint32_t * JumpWord; uint8_t * X86Code; @@ -682,7 +682,7 @@ void CRSPRecompiler::LinkBranches(RSP_BLOCK * Block) if (!X86Code) { - *PrgCount = Target; + *m_System.m_SP_PC_REG = Target; CPU_Message(""); CPU_Message("===== (Generate code: %04X) =====", Target); Save = *Block; @@ -703,7 +703,7 @@ void CRSPRecompiler::LinkBranches(RSP_BLOCK * Block) CPU_Message("Linked RSP branch from x86: %08X, to RSP: %X / x86: %08X", JumpWord, Target, X86Code); } - *PrgCount = OrigPrgCount; + *m_System.m_SP_PC_REG = OrigPrgCount; CPU_Message("***** Done linking branches *****"); CPU_Message(""); } @@ -813,7 +813,7 @@ void CRSPRecompiler::CompilerRSPBlock(void) uint8_t * IMEM_SAVE = (uint8_t *)malloc(0x1000); const size_t X86BaseAddress = (size_t)RecompPos; NextInstruction = RSPPIPELINE_NORMAL; - CompilePC = *PrgCount; + CompilePC = *m_System.m_SP_PC_REG; memset(&m_CurrentBlock, 0, sizeof(m_CurrentBlock)); m_CurrentBlock.StartPC = CompilePC; @@ -946,15 +946,15 @@ void CRSPRecompiler::CompilerRSPBlock(void) break; } - if (CompilePC >= EndPC && *PrgCount != 0 && EndPC != *PrgCount) + if (CompilePC >= EndPC && *m_System.m_SP_PC_REG != 0 && EndPC != *m_System.m_SP_PC_REG) { CompilePC = 0; - EndPC = *PrgCount; + EndPC = *m_System.m_SP_PC_REG; } } while (NextInstruction != RSPPIPELINE_FINISH_BLOCK && (CompilePC < EndPC || NextInstruction == RSPPIPELINE_DELAY_SLOT || NextInstruction == RSPPIPELINE_DELAY_SLOT_DONE)); if (CompilePC >= EndPC) { - MoveConstToVariable((CompilePC & 0xFFC), PrgCount, "RSP PC"); + MoveConstToVariable((CompilePC & 0xFFC), m_System.m_SP_PC_REG, "RSP PC"); Ret(); } CPU_Message("===== End of recompiled code ====="); @@ -979,7 +979,7 @@ void CRSPRecompiler::RunCPU(void) while (RSP_Running) { - Block = (uint8_t *)*(JumpTable + (*PrgCount >> 2)); + Block = (uint8_t *)*(JumpTable + (*m_System.m_SP_PC_REG >> 2)); if (Block == NULL) { @@ -1010,7 +1010,7 @@ void CRSPRecompiler::RunCPU(void) CompilerRSPBlock(); #endif - Block = (uint8_t *)*(JumpTable + (*PrgCount >> 2)); + Block = (uint8_t *)*(JumpTable + (*m_System.m_SP_PC_REG >> 2)); // We are done compiling, but we may have references // to fill in still either from this block, or jumps @@ -1025,7 +1025,7 @@ void CRSPRecompiler::RunCPU(void) if (Profiling && IndvidualBlock) { - StartTimer(*PrgCount); + StartTimer(*m_System.m_SP_PC_REG); } #if defined(_M_IX86) && defined(_MSC_VER) diff --git a/Source/Project64-rsp-core/Recompiler/RspRecompilerOps.cpp b/Source/Project64-rsp-core/Recompiler/RspRecompilerOps.cpp index 57998b6b6..6e4112e28 100644 --- a/Source/Project64-rsp-core/Recompiler/RspRecompilerOps.cpp +++ b/Source/Project64-rsp-core/Recompiler/RspRecompilerOps.cpp @@ -141,7 +141,7 @@ void BreakPoint() *(RecompPos++) = 0xCC; } -void CompileBranchExit(uint32_t TargetPC, uint32_t ContinuePC) +void CRSPRecompilerOps::CompileBranchExit(uint32_t TargetPC, uint32_t ContinuePC) { uint32_t * X86Loc = NULL; @@ -149,12 +149,12 @@ void CompileBranchExit(uint32_t TargetPC, uint32_t ContinuePC) CompConstToVariable(true, &BranchCompare, "BranchCompare"); JeLabel32("BranchEqual", 0); X86Loc = (uint32_t *)(RecompPos - 4); - MoveConstToVariable(ContinuePC, PrgCount, "RSP PC"); + MoveConstToVariable(ContinuePC, m_System.m_SP_PC_REG, "RSP PC"); Ret(); CPU_Message("BranchEqual:"); x86_SetBranch32b(X86Loc, RecompPos); - MoveConstToVariable(TargetPC, PrgCount, "RSP PC"); + MoveConstToVariable(TargetPC, m_System.m_SP_PC_REG, "RSP PC"); Ret(); } @@ -198,7 +198,7 @@ void CRSPRecompilerOps::J(void) } else if (NextInstruction == RSPPIPELINE_DELAY_SLOT_EXIT_DONE) { - MoveConstToVariable((m_OpCode.target << 2) & 0xFFC, PrgCount, "RSP PC"); + MoveConstToVariable((m_OpCode.target << 2) & 0xFFC, m_System.m_SP_PC_REG, "RSP PC"); NextInstruction = RSPPIPELINE_FINISH_SUB_BLOCK; Ret(); } @@ -225,7 +225,7 @@ void CRSPRecompilerOps::JAL(void) char Str[40]; sprintf(Str, "%03X", (m_OpCode.target << 2) & 0xFFC); Push(x86_EAX); - PushImm32(Str, *PrgCount); + PushImm32(Str, *m_System.m_SP_PC_REG); Call_Direct((void *)StartTimer, "StartTimer"); AddConstToX86Reg(x86_ESP, 4); Pop(x86_EAX); @@ -236,7 +236,7 @@ void CRSPRecompilerOps::JAL(void) } else if (NextInstruction == RSPPIPELINE_DELAY_SLOT_EXIT_DONE) { - MoveConstToVariable((m_OpCode.target << 2) & 0xFFC, PrgCount, "RSP PC"); + MoveConstToVariable((m_OpCode.target << 2) & 0xFFC, m_System.m_SP_PC_REG, "RSP PC"); NextInstruction = RSPPIPELINE_FINISH_SUB_BLOCK; Ret(); } @@ -1480,7 +1480,7 @@ void CRSPRecompilerOps::Special_SRAV(void) void UpdateAudioTimer() { /* char Label[100]; - sprintf(Label,"COMMAND: %02X (PC = %08X)",m_GPR[1].UW >> 1, *PrgCount); + sprintf(Label,"COMMAND: %02X (PC = %08X)",m_GPR[1].UW >> 1, *m_System.m_SP_PC_REG); StartTimer(Label);*/ } @@ -1491,16 +1491,16 @@ void CRSPRecompilerOps::Special_JR(void) if (NextInstruction == RSPPIPELINE_NORMAL) { CPU_Message(" %X %s", CompilePC, RSPInstruction(CompilePC, m_OpCode.Value).NameAndParam().c_str()); - // Transfer destination to location pointed to by PrgCount + // Transfer destination to location pointed to by m_System.m_SP_PC_REG MoveVariableToX86reg(&m_GPR[m_OpCode.rs].W, GPR_Name(m_OpCode.rs), x86_EAX); AndConstToX86Reg(x86_EAX, 0xFFC); - MoveX86regToVariable(x86_EAX, PrgCount, "RSP PC"); + MoveX86regToVariable(x86_EAX, m_System.m_SP_PC_REG, "RSP PC"); ChangedPC = true; NextInstruction = RSPPIPELINE_DO_DELAY_SLOT; } else if (NextInstruction == RSPPIPELINE_DELAY_SLOT_DONE) { - MoveVariableToX86reg(PrgCount, "RSP PC", x86_EAX); + MoveVariableToX86reg(m_System.m_SP_PC_REG, "RSP PC", x86_EAX); if (Profiling && IndvidualBlock) { Push(x86_EAX); @@ -1552,13 +1552,13 @@ void CRSPRecompilerOps::Special_JALR(void) CPU_Message(" %X %s", CompilePC, RSPInstruction(CompilePC, m_OpCode.Value).NameAndParam().c_str()); MoveVariableToX86reg(&m_GPR[m_OpCode.rs].W, GPR_Name(m_OpCode.rs), x86_EAX); AndConstToX86Reg(x86_EAX, 0xFFC); - MoveX86regToVariable(x86_EAX, PrgCount, "RSP PC"); + MoveX86regToVariable(x86_EAX, m_System.m_SP_PC_REG, "RSP PC"); MoveConstToVariable(Const, &m_GPR[m_OpCode.rd].W, GPR_Name(m_OpCode.rd)); NextInstruction = RSPPIPELINE_DO_DELAY_SLOT; } else if (NextInstruction == RSPPIPELINE_DELAY_SLOT_DONE) { - MoveVariableToX86reg(PrgCount, "RSP PC", x86_EAX); + MoveVariableToX86reg(m_System.m_SP_PC_REG, "RSP PC", x86_EAX); AddVariableToX86reg(x86_EAX, &JumpTable, "JumpTable"); MoveX86regPointerToX86reg(x86_EAX, x86_EAX); @@ -1589,7 +1589,7 @@ void CRSPRecompilerOps::Special_BREAK(void) Cheat_r4300iOpcode(&RSPOp::Special_BREAK, "RSPOp::Special_BREAK"); if (NextInstruction == RSPPIPELINE_NORMAL) { - MoveConstToVariable(CompilePC + 4, PrgCount, "RSP PC"); + MoveConstToVariable(CompilePC + 4, m_System.m_SP_PC_REG, "RSP PC"); Ret(); NextInstruction = RSPPIPELINE_FINISH_SUB_BLOCK; } @@ -2181,7 +2181,7 @@ void CRSPRecompilerOps::Cop0_MF(void) Cheat_r4300iOpcode(RSP_Cop0_MF, "RSP_Cop0_MF"); if (NextInstruction == RSPPIPELINE_NORMAL) { - MoveConstToVariable(CompilePC + 4, PrgCount, "RSP PC"); + MoveConstToVariable(CompilePC + 4, m_System.m_SP_PC_REG, "RSP PC"); Ret(); NextInstruction = RSPPIPELINE_FINISH_SUB_BLOCK; } @@ -2249,7 +2249,7 @@ void CRSPRecompilerOps::Cop0_MF(void) MoveX86regToVariable(x86_EAX, &m_GPR[m_OpCode.rt].W, GPR_Name(m_OpCode.rt)); if (NextInstruction == RSPPIPELINE_NORMAL) { - MoveConstToVariable(CompilePC + 4, PrgCount, "RSP PC"); + MoveConstToVariable(CompilePC + 4, m_System.m_SP_PC_REG, "RSP PC"); Ret(); NextInstruction = RSPPIPELINE_FINISH_SUB_BLOCK; } @@ -2317,7 +2317,7 @@ void CRSPRecompilerOps::Cop0_MT(void) { if (NextInstruction == RSPPIPELINE_NORMAL) { - MoveConstToVariable(CompilePC + 4, PrgCount, "RSP PC"); + MoveConstToVariable(CompilePC + 4, m_System.m_SP_PC_REG, "RSP PC"); Ret(); NextInstruction = RSPPIPELINE_FINISH_BLOCK; } @@ -2370,7 +2370,7 @@ void CRSPRecompilerOps::Cop0_MT(void) Call_Direct(AddressOf(&RSPRegisterHandlerPlugin::WriteReg), "RSPRegisterHandlerPlugin::WriteReg"); if (NextInstruction == RSPPIPELINE_NORMAL) { - MoveConstToVariable(CompilePC + 4, PrgCount, "RSP PC"); + MoveConstToVariable(CompilePC + 4, m_System.m_SP_PC_REG, "RSP PC"); Ret(); NextInstruction = RSPPIPELINE_FINISH_BLOCK; } @@ -2440,7 +2440,7 @@ void CRSPRecompilerOps::Cop0_MT(void) JeLabel8("DontExit", 0); Jump = RecompPos - 1; - MoveConstToVariable(CompilePC + 4, PrgCount, "RSP PC"); + MoveConstToVariable(CompilePC + 4, m_System.m_SP_PC_REG, "RSP PC"); Ret(); CPU_Message("DontExit:"); @@ -7242,7 +7242,7 @@ void CRSPRecompilerOps::UnknownOpcode(void) { CPU_Message(" %X Unhandled Opcode: %s", CompilePC, RSPInstruction(CompilePC, m_OpCode.Value).NameAndParam().c_str()); NextInstruction = RSPPIPELINE_FINISH_BLOCK; - MoveConstToVariable(CompilePC, PrgCount, "RSP PC"); + MoveConstToVariable(CompilePC, m_System.m_SP_PC_REG, "RSP PC"); MoveConstToVariable(m_OpCode.Value, &m_OpCode.Value, "m_OpCode.Value"); MoveConstToX86reg((uint32_t) & (RSPSystem.m_Op), x86_ECX); Call_Direct(AddressOf(&RSPOp::UnknownOpcode), "&RSPOp::UnknownOpcode"); diff --git a/Source/Project64-rsp-core/Recompiler/RspRecompilerOps.h b/Source/Project64-rsp-core/Recompiler/RspRecompilerOps.h index 973a8577f..7b058cd24 100644 --- a/Source/Project64-rsp-core/Recompiler/RspRecompilerOps.h +++ b/Source/Project64-rsp-core/Recompiler/RspRecompilerOps.h @@ -168,6 +168,7 @@ private: void RSP_Element2Mmx(int MmxReg); void RSP_MultiElement2Mmx(int MmxReg1, int MmxReg2); + void CompileBranchExit(uint32_t TargetPC, uint32_t ContinuePC); bool Compile_Vector_VMULF_MMX(void); bool Compile_Vector_VMUDL_MMX(void); bool Compile_Vector_VMUDM_MMX(void); diff --git a/Source/Project64-rsp-core/cpu/RSPCpu.cpp b/Source/Project64-rsp-core/cpu/RSPCpu.cpp index d4778b495..6c4c6ca7c 100644 --- a/Source/Project64-rsp-core/cpu/RSPCpu.cpp +++ b/Source/Project64-rsp-core/cpu/RSPCpu.cpp @@ -12,7 +12,7 @@ class RSPRegisterHandler; UDWORD EleSpec[16], Indx[16]; -uint32_t *PrgCount, NextInstruction, RSP_Running; +uint32_t NextInstruction, RSP_Running; void BuildRecompilerCPU(void); @@ -97,7 +97,6 @@ void Build_RSP(void) Indx[i].B[7 - z] = Temp; } } - PrgCount = RSPInfo.SP_PC_REG; } /* diff --git a/Source/Project64-rsp-core/cpu/RSPCpu.h b/Source/Project64-rsp-core/cpu/RSPCpu.h index 50d3b99ea..fb6e7b718 100644 --- a/Source/Project64-rsp-core/cpu/RSPCpu.h +++ b/Source/Project64-rsp-core/cpu/RSPCpu.h @@ -13,7 +13,7 @@ enum RSPCpuType extern UDWORD EleSpec[16], Indx[16]; -extern uint32_t *PrgCount, RSP_Running; +extern uint32_t RSP_Running; void SetCPU(RSPCpuType core); void Build_RSP(void); diff --git a/Source/Project64-rsp/RSP Command.cpp b/Source/Project64-rsp/RSP Command.cpp index 63f2d63c3..c9cc812fa 100644 --- a/Source/Project64-rsp/RSP Command.cpp +++ b/Source/Project64-rsp/RSP Command.cpp @@ -123,7 +123,7 @@ int DisplayRSPCommand(DWORD location, int InsertPos) RSP_LW_IMEM(location, &OpCode); status = 0; - if (location == *PrgCount) + if (location == *RSPInfo.SP_PC_REG) { status = RSP_Status_PC; } @@ -320,7 +320,7 @@ void DrawRSPCommand(LPARAM lParam) DisplayError("Failed to sprintf from item %u.", ditem->itemID); } - if (*PrgCount == RSPCommandLine[ditem->itemID].Location) + if (*RSPInfo.SP_PC_REG == RSPCommandLine[ditem->itemID].Location) { ResetColor = true; hBrush = (HBRUSH)(COLOR_HIGHLIGHT + 1); @@ -335,7 +335,7 @@ void DrawRSPCommand(LPARAM lParam) if (CheckForRSPBPoint(RSPCommandLine[ditem->itemID].Location)) { ResetColor = true; - if (*PrgCount == RSPCommandLine[ditem->itemID].Location) + if (*RSPInfo.SP_PC_REG == RSPCommandLine[ditem->itemID].Location) { SetTextColor(ditem->hDC, RGB(255, 0, 0)); } @@ -417,11 +417,11 @@ void Enable_RSP_Commands_Window(void) si.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; si.nMin = 0; si.nMax = (0x1000 >> 2) - 1; - si.nPos = (*PrgCount >> 2); + si.nPos = (*RSPInfo.SP_PC_REG >> 2); si.nPage = 30; SetScrollInfo(hScrlBar, SB_CTL, &si, true); - SetRSPCommandViewto(*PrgCount); + SetRSPCommandViewto(*RSPInfo.SP_PC_REG); SetForegroundWindow(RSPCommandshWnd); } } @@ -743,7 +743,7 @@ void RSP_Commands_Setup(HWND hDlg) SendMessage(hList, LB_SETITEMHEIGHT, (WPARAM)0, (LPARAM)MAKELPARAM(14, 0)); } - sprintf(Location, "%03X", PrgCount ? *PrgCount : 0); + sprintf(Location, "%03X", RSPInfo.SP_PC_REG ? *RSPInfo.SP_PC_REG : 0); hAddress = CreateWindowExA(0, "EDIT", Location, WS_CHILD | ES_UPPERCASE | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 375, 17, 36, 18, hDlg, (HMENU)IDC_ADDRESS, (HINSTANCE)hinstDLL, NULL); if (hAddress) {