Skip to content

Commit

Permalink
Rsp: Use RSP Register Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
project64 committed Sep 28, 2023
1 parent bd1ec4f commit ac3e0f8
Show file tree
Hide file tree
Showing 19 changed files with 188 additions and 324 deletions.
Expand Up @@ -172,6 +172,10 @@ void SPRegistersHandler::SetHalt(void)
{
}

void SPRegistersHandler::DmaReadDone(uint32_t /*End*/)
{
}

void SPRegistersHandler::SystemReset(void)
{
SP_RD_LEN_REG = 0x00000FF8;
Expand Down
Expand Up @@ -70,6 +70,7 @@ class SPRegistersHandler :
void ClearSPInterrupt(void);
void SetSPInterrupt(void);
void SetHalt(void);
void DmaReadDone(uint32_t End);
void SystemReset(void);

uint8_t m_IMEM[0x1000];
Expand Down
2 changes: 1 addition & 1 deletion Source/Project64-plugin-spec/Rsp.h
@@ -1,7 +1,7 @@
#pragma once
#include "Base.h"

typedef struct
typedef struct _RSP_INFO
{
void * hInst;
int MemoryBswaped; // If this is set to TRUE, then the memory has been pre-bswap'd on a DWORD (32-bit) boundary
Expand Down
4 changes: 2 additions & 2 deletions Source/Project64-rsp-core/Project64-rsp-core.vcxproj
Expand Up @@ -42,14 +42,14 @@
<ItemGroup>
<ClCompile Include="cpu\RspClamp.cpp" />
<ClCompile Include="cpu\RSPCpu.cpp" />
<ClCompile Include="cpu\RspDma.cpp" />
<ClCompile Include="cpu\RSPiInstruction.cpp" />
<ClCompile Include="cpu\RSPInterpreterCPU.cpp" />
<ClCompile Include="cpu\RSPInterpreterOps.cpp" />
<ClCompile Include="cpu\RspLog.cpp" />
<ClCompile Include="cpu\RspMemory.cpp" />
<ClCompile Include="cpu\RSPRegister.cpp" />
<ClCompile Include="cpu\RSPRegisterHandler.cpp" />
<ClCompile Include="cpu\RSPRegisterHandlerPlugin.cpp" />
<ClCompile Include="cpu\RspTypes.cpp" />
<ClCompile Include="Recompiler\Mmx.cpp" />
<ClCompile Include="Recompiler\RspProfiling.cpp" />
Expand All @@ -66,14 +66,14 @@
<ItemGroup>
<ClInclude Include="cpu\RspClamp.h" />
<ClInclude Include="cpu\RSPCpu.h" />
<ClInclude Include="cpu\RspDma.h" />
<ClInclude Include="cpu\RSPInstruction.h" />
<ClInclude Include="cpu\RSPInterpreterCPU.h" />
<ClInclude Include="cpu\RSPInterpreterOps.h" />
<ClInclude Include="cpu\RspLog.h" />
<ClInclude Include="cpu\RspMemory.h" />
<ClInclude Include="cpu\RSPOpcode.h" />
<ClInclude Include="cpu\RSPRegisterHandler.h" />
<ClInclude Include="cpu\RSPRegisterHandlerPlugin.h" />
<ClInclude Include="cpu\RSPRegisters.h" />
<ClInclude Include="cpu\RspTypes.h" />
<ClInclude Include="Recompiler\RspProfiling.h" />
Expand Down
12 changes: 6 additions & 6 deletions Source/Project64-rsp-core/Project64-rsp-core.vcxproj.filters
Expand Up @@ -90,15 +90,15 @@
<ClCompile Include="Recompiler\RspProfiling.cpp">
<Filter>Source Files\Recompiler</Filter>
</ClCompile>
<ClCompile Include="cpu\RspDma.cpp">
<Filter>Source Files\cpu</Filter>
</ClCompile>
<ClCompile Include="cpu\RspClamp.cpp">
<Filter>Source Files\cpu</Filter>
</ClCompile>
<ClCompile Include="cpu\RSPRegisterHandler.cpp">
<Filter>Source Files\cpu</Filter>
</ClCompile>
<ClCompile Include="cpu\RSPRegisterHandlerPlugin.cpp">
<Filter>Source Files\cpu</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="cpu\RSPInstruction.h">
Expand Down Expand Up @@ -152,14 +152,14 @@
<ClInclude Include="Recompiler\RspProfiling.h">
<Filter>Header Files\Recompiler</Filter>
</ClInclude>
<ClInclude Include="cpu\RspDma.h">
<Filter>Header Files\cpu</Filter>
</ClInclude>
<ClInclude Include="cpu\RspClamp.h">
<Filter>Header Files\cpu</Filter>
</ClInclude>
<ClInclude Include="cpu\RSPRegisterHandler.h">
<Filter>Header Files\cpu</Filter>
</ClInclude>
<ClInclude Include="cpu\RSPRegisterHandlerPlugin.h">
<Filter>Header Files\cpu</Filter>
</ClInclude>
</ItemGroup>
</Project>
85 changes: 49 additions & 36 deletions Source/Project64-rsp-core/Recompiler/RspRecompilerOps.cpp
Expand Up @@ -9,7 +9,6 @@
#include <Project64-rsp-core/cpu/RSPInterpreterCPU.h>
#include <Project64-rsp-core/cpu/RSPInterpreterOps.h>
#include <Project64-rsp-core/cpu/RSPRegisters.h>
#include <Project64-rsp-core/cpu/RspDma.h>
#include <Project64-rsp-core/cpu/RspLog.h>
#include <Project64-rsp-core/cpu/RspMemory.h>
#include <Project64-rsp-core/cpu/RspTypes.h>
Expand Down Expand Up @@ -2102,19 +2101,23 @@ void Compile_Cop0_MF(void)
}
else
{
CompilerWarning("MF error\nWeird Delay Slot.\n\nNextInstruction = %X\nEmulation will now stop", NextInstruction);
CompilerWarning(stdstr_f("MF error\nWeird Delay Slot.\n\nNextInstruction = %X\nEmulation will now stop", NextInstruction).c_str());
BreakPoint();
}
return;
#else
switch (RSPOpC.rd)
{
case 0:
MoveVariableToX86reg(RSPInfo.SP_MEM_ADDR_REG, "SP_MEM_ADDR_REG", x86_EAX);
MoveConstToX86reg((uint32_t)(g_RSPRegisterHandler.get()), x86_ECX);
PushImm32("RSPRegister_MEM_ADDR", RSPRegister_MEM_ADDR);
Call_Direct(AddressOf(&RSPRegisterHandlerPlugin::ReadReg), "RSPRegisterHandlerPlugin::ReadReg");
MoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW, GPR_Name(RSPOpC.rt));
break;
case 1:
MoveVariableToX86reg(RSPInfo.SP_DRAM_ADDR_REG, "SP_DRAM_ADDR_REG", x86_EAX);
MoveConstToX86reg((uint32_t)(g_RSPRegisterHandler.get()), x86_ECX);
PushImm32("RSPRegister_DRAM_ADDR", RSPRegister_DRAM_ADDR);
Call_Direct(AddressOf(&RSPRegisterHandlerPlugin::ReadReg), "RSPRegisterHandlerPlugin::ReadReg");
MoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW, GPR_Name(RSPOpC.rt));
break;
case 5:
Expand All @@ -2126,32 +2129,10 @@ void Compile_Cop0_MF(void)
MoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW, GPR_Name(RSPOpC.rt));
break;
case 4:
MoveVariableToX86reg(&RSP_MfStatusCount, "RSP_MfStatusCount", x86_ECX);
MoveVariableToX86reg(RSPInfo.SP_STATUS_REG, "SP_STATUS_REG", x86_EAX);
if (Mfc0Count != 0)
{
CompConstToX86reg(x86_ECX, Mfc0Count);
JbLabel8("label", 10);
MoveConstToVariable(0, &RSP_Running, "RSP_Running");
}
IncX86reg(x86_ECX);
MoveConstToX86reg((uint32_t)(g_RSPRegisterHandler.get()), x86_ECX);
PushImm32("RSPRegister_STATUS", RSPRegister_STATUS);
Call_Direct(AddressOf(&RSPRegisterHandlerPlugin::ReadReg), "RSPRegisterHandlerPlugin::ReadReg");
MoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW, GPR_Name(RSPOpC.rt));
MoveX86regToVariable(x86_ECX, &RSP_MfStatusCount, "RSP_MfStatusCount");
if (NextInstruction == RSPPIPELINE_NORMAL)
{
MoveConstToVariable(CompilePC + 4, PrgCount, "RSP PC");
Ret();
NextInstruction = RSPPIPELINE_FINISH_SUB_BLOCK;
}
else if (NextInstruction == RSPPIPELINE_DELAY_SLOT)
{
NextInstruction = RSPPIPELINE_DELAY_SLOT_EXIT;
}
else
{
CompilerWarning(stdstr_f("MF error\nWeird Delay Slot.\n\nNextInstruction = %X\nEmulation will now stop", NextInstruction).c_str());
BreakPoint();
}
break;
case 7:
if (AudioHle || GraphicsHle || SemaphoreExit == 0)
Expand Down Expand Up @@ -2242,30 +2223,62 @@ void Compile_Cop0_MT(void)
}
else
{
CompilerWarning("MF error\nWeird Delay Slot.\n\nNextInstruction = %X\nEmulation will now stop", NextInstruction);
CompilerWarning(stdstr_f("MF error\nWeird Delay Slot.\n\nNextInstruction = %X\nEmulation will now stop", NextInstruction).c_str());
BreakPoint();
}
}
#else
switch (RSPOpC.rd)
{
case 0:
MoveConstToX86reg((uint32_t)(g_RSPRegisterHandler.get()), x86_ECX);
MoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].UW, GPR_Name(RSPOpC.rt), x86_EAX);
MoveX86regToVariable(x86_EAX, RSPInfo.SP_MEM_ADDR_REG, "SP_MEM_ADDR_REG");
Push(x86_EAX);
PushImm32("RSPRegister_MEM_ADDR", RSPRegister_MEM_ADDR);
Call_Direct(AddressOf(&RSPRegisterHandlerPlugin::WriteReg), "RSPRegisterHandlerPlugin::WriteReg");
break;
case 1:
MoveConstToX86reg((uint32_t)(g_RSPRegisterHandler.get()), x86_ECX);
MoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].UW, GPR_Name(RSPOpC.rt), x86_EAX);
MoveX86regToVariable(x86_EAX, RSPInfo.SP_DRAM_ADDR_REG, "SP_DRAM_ADDR_REG");
Push(x86_EAX);
PushImm32("RSPRegister_DRAM_ADDR", RSPRegister_DRAM_ADDR);
Call_Direct(AddressOf(&RSPRegisterHandlerPlugin::WriteReg), "RSPRegisterHandlerPlugin::WriteReg");
break;
case 2:
MoveConstToX86reg((uint32_t)(g_RSPRegisterHandler.get()), x86_ECX);
MoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].UW, GPR_Name(RSPOpC.rt), x86_EAX);
MoveX86regToVariable(x86_EAX, RSPInfo.SP_RD_LEN_REG, "SP_RD_LEN_REG");
Call_Direct(SP_DMA_READ, "SP_DMA_READ");
Push(x86_EAX);
PushImm32("RSPRegister_RD_LEN", RSPRegister_RD_LEN);
Call_Direct(AddressOf(&RSPRegisterHandlerPlugin::WriteReg), "RSPRegisterHandlerPlugin::WriteReg");
break;
case 3:
MoveConstToX86reg((uint32_t)(g_RSPRegisterHandler.get()), x86_ECX);
MoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].UW, GPR_Name(RSPOpC.rt), x86_EAX);
Push(x86_EAX);
PushImm32("RSPRegister_WR_LEN", RSPRegister_WR_LEN);
Call_Direct(AddressOf(&RSPRegisterHandlerPlugin::WriteReg), "RSPRegisterHandlerPlugin::WriteReg");
break;
case 4:
MoveConstToX86reg((uint32_t)(g_RSPRegisterHandler.get()), x86_ECX);
MoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].UW, GPR_Name(RSPOpC.rt), x86_EAX);
MoveX86regToVariable(x86_EAX, RSPInfo.SP_WR_LEN_REG, "SP_WR_LEN_REG");
Call_Direct(SP_DMA_WRITE, "SP_DMA_WRITE");
Push(x86_EAX);
PushImm32("RSPRegister_STATUS", RSPRegister_STATUS);
Call_Direct(AddressOf(&RSPRegisterHandlerPlugin::WriteReg), "RSPRegisterHandlerPlugin::WriteReg");
if (NextInstruction == RSPPIPELINE_NORMAL)
{
MoveConstToVariable(CompilePC + 4, PrgCount, "RSP PC");
Ret();
NextInstruction = RSPPIPELINE_FINISH_BLOCK;
}
else if (NextInstruction == RSPPIPELINE_DELAY_SLOT)
{
NextInstruction = RSPPIPELINE_DELAY_SLOT_EXIT;
}
else
{
CompilerWarning(stdstr_f("MF error\nWeird Delay Slot.\n\nNextInstruction = %X\nEmulation will now stop", NextInstruction).c_str());
BreakPoint();
}
break;
case 7:
MoveConstToVariable(0, RSPInfo.SP_SEMAPHORE_REG, "SP_SEMAPHORE_REG");
Expand Down
12 changes: 12 additions & 0 deletions Source/Project64-rsp-core/Recompiler/X86.cpp
Expand Up @@ -3320,3 +3320,15 @@ void XorX86RegToVariable(void * Variable, char * VariableName, int x86reg)
}
PUTDSTPTR(RecompPos, Variable);
}

void * GetAddressOf_(int value, ...)
{
void * Address;

va_list ap;
va_start(ap, value);
Address = va_arg(ap, void *);
va_end(ap);

return Address;
}
3 changes: 3 additions & 0 deletions Source/Project64-rsp-core/Recompiler/X86.h
Expand Up @@ -268,3 +268,6 @@ void SseShuffleReg(int Dest, int Source, uint8_t Immed);

void x86_SetBranch32b(void * Jumpuint8_t, void * Destination);
void x86_SetBranch8b(void * Jumpuint8_t, void * Destination);

void * GetAddressOf_(int32_t value, ...);
#define AddressOf(Addr) GetAddressOf_(5, (Addr))
4 changes: 4 additions & 0 deletions Source/Project64-rsp-core/cpu/RSPCpu.cpp
Expand Up @@ -4,6 +4,9 @@
#include <Project64-rsp-core/RSPInfo.h>
#include <Project64-rsp-core/Settings/RspSettings.h>
#include <Project64-rsp-core/cpu/RSPRegisters.h>
#include <memory>

class RSPRegisterHandler;

UDWORD EleSpec[16], Indx[16];
RSPOpcode RSPOpC;
Expand All @@ -24,6 +27,7 @@ void BuildRecompilerCPU(void);
CriticalSection g_CPUCriticalSection;
uint32_t Mfc0Count, SemaphoreExit = 0;
RSPCpuType g_CPUCore = InterpreterCPU;
std::unique_ptr<RSPRegisterHandlerPlugin> g_RSPRegisterHandler;

void SetCPU(RSPCpuType core)
{
Expand Down
5 changes: 4 additions & 1 deletion Source/Project64-rsp-core/cpu/RSPCpu.h
@@ -1,5 +1,7 @@
#include "RSPOpcode.h"
#include "RSPRegisterHandlerPlugin.h"
#include "RspTypes.h"
#include <memory>

enum RSPCpuType
{
Expand All @@ -26,4 +28,5 @@ void SetCPU(RSPCpuType core);
void Build_RSP(void);

extern uint32_t Mfc0Count, SemaphoreExit;
extern RSPCpuType g_CPUCore;
extern RSPCpuType g_CPUCore;
extern std::unique_ptr<RSPRegisterHandlerPlugin> g_RSPRegisterHandler;

0 comments on commit ac3e0f8

Please sign in to comment.