Skip to content

Commit

Permalink
SNES: Add support for ST018 coprocessor
Browse files Browse the repository at this point in the history
Used by a single game: Hayazashi Nidan Morita Shougi 2
  • Loading branch information
SourMesen committed Dec 29, 2024
1 parent 43afe79 commit 8d6830a
Show file tree
Hide file tree
Showing 70 changed files with 3,132 additions and 185 deletions.
16 changes: 16 additions & 0 deletions Core/Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@
<ClInclude Include="SMS\SmsPsg.h" />
<ClInclude Include="SMS\SmsTypes.h" />
<ClInclude Include="SMS\SmsVdp.h" />
<ClInclude Include="Shared\ArmEnums.h" />
<ClInclude Include="SNES\Coprocessors\ST018\ArmV3Cpu.h" />
<ClInclude Include="SNES\Coprocessors\ST018\ArmV3Types.h" />
<ClInclude Include="SNES\Coprocessors\ST018\St018.h" />
<ClInclude Include="SNES\Coprocessors\ST018\St018Types.h" />
<ClInclude Include="SNES\Debugger\DummyArmV3Cpu.h" />
<ClInclude Include="SNES\Debugger\St018Debugger.h" />
<ClInclude Include="SNES\Debugger\St018DisUtils.h" />
<ClInclude Include="SNES\Debugger\TraceLogger\St018TraceLogger.h" />
<ClInclude Include="SNES\DSP\DspInterpolation.h" />
<ClInclude Include="SNES\DSP\Dsp.h" />
<ClInclude Include="NES\Debugger\NesCodeDataLogger.h" />
Expand Down Expand Up @@ -794,6 +803,7 @@
<ClCompile Include="Debugger\BaseEventManager.cpp" />
<ClCompile Include="Debugger\CdlManager.cpp" />
<ClCompile Include="Debugger\DisassemblySearch.cpp" />
<ClCompile Include="Debugger\ExpressionEvaluator.St018.cpp" />
<ClCompile Include="Debugger\ExpressionEvaluator.Ws.cpp" />
<ClCompile Include="Debugger\ExpressionEvaluator.Cx4.cpp" />
<ClCompile Include="Debugger\ExpressionEvaluator.Gameboy.cpp" />
Expand Down Expand Up @@ -938,6 +948,9 @@
<ClCompile Include="SMS\SmsPsg.cpp" />
<ClCompile Include="SMS\SmsVdp.cpp" />
<ClCompile Include="SNES\AluMulDiv.cpp" />
<ClCompile Include="SNES\Coprocessors\ST018\ArmV3Cpu.cpp" />
<ClCompile Include="SNES\Coprocessors\ST018\St018.cpp" />
<ClCompile Include="SNES\Debugger\DummyArmV3Cpu.cpp" />
<ClCompile Include="SNES\Debugger\DummySnesCpu.cpp" />
<ClCompile Include="SNES\Debugger\DummySpc.cpp" />
<ClCompile Include="SNES\Debugger\SnesPpuTools.cpp" />
Expand All @@ -956,6 +969,9 @@
<ClCompile Include="Debugger\CallstackManager.cpp" />
<ClCompile Include="Shared\CheatManager.cpp" />
<ClCompile Include="Debugger\CodeDataLogger.cpp" />
<ClCompile Include="SNES\Debugger\St018Debugger.cpp" />
<ClCompile Include="SNES\Debugger\St018DisUtils.cpp" />
<ClCompile Include="SNES\Debugger\TraceLogger\St018TraceLogger.cpp" />
<ClCompile Include="SNES\DSP\Dsp.cpp" />
<ClCompile Include="SNES\DSP\DspVoice.cpp" />
<ClCompile Include="SNES\SnesConsole.cpp" />
Expand Down
51 changes: 51 additions & 0 deletions Core/Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -2943,6 +2943,33 @@
<ClInclude Include="GBA\GbaCpuMultiply.h">
<Filter>GBA</Filter>
</ClInclude>
<ClInclude Include="SNES\Coprocessors\ST018\St018.h">
<Filter>SNES\Coprocessors\ST018</Filter>
</ClInclude>
<ClInclude Include="SNES\Coprocessors\ST018\St018Types.h">
<Filter>SNES\Coprocessors\ST018</Filter>
</ClInclude>
<ClInclude Include="SNES\Coprocessors\ST018\ArmV3Cpu.h">
<Filter>SNES\Coprocessors\ST018</Filter>
</ClInclude>
<ClInclude Include="SNES\Coprocessors\ST018\ArmV3Types.h">
<Filter>SNES\Coprocessors\ST018</Filter>
</ClInclude>
<ClInclude Include="SNES\Debugger\St018Debugger.h">
<Filter>SNES\Debugger</Filter>
</ClInclude>
<ClInclude Include="SNES\Debugger\TraceLogger\St018TraceLogger.h">
<Filter>SNES\Debugger\TraceLogger</Filter>
</ClInclude>
<ClInclude Include="SNES\Debugger\DummyArmV3Cpu.h">
<Filter>SNES\Debugger</Filter>
</ClInclude>
<ClInclude Include="SNES\Debugger\St018DisUtils.h">
<Filter>SNES\Debugger</Filter>
</ClInclude>
<ClInclude Include="Shared\ArmEnums.h">
<Filter>Shared</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Shared\Video\RotateFilter.cpp">
Expand Down Expand Up @@ -3284,6 +3311,27 @@
<ClCompile Include="NES\Mappers\Homebrew\Rainbow.cpp">
<Filter>NES\Mappers\Homebrew</Filter>
</ClCompile>
<ClCompile Include="SNES\Coprocessors\ST018\St018.cpp">
<Filter>SNES\Coprocessors\ST018</Filter>
</ClCompile>
<ClCompile Include="SNES\Coprocessors\ST018\ArmV3Cpu.cpp">
<Filter>SNES\Coprocessors\ST018</Filter>
</ClCompile>
<ClCompile Include="SNES\Debugger\St018Debugger.cpp">
<Filter>SNES\Debugger</Filter>
</ClCompile>
<ClCompile Include="SNES\Debugger\TraceLogger\St018TraceLogger.cpp">
<Filter>SNES\Debugger\TraceLogger</Filter>
</ClCompile>
<ClCompile Include="SNES\Debugger\DummyArmV3Cpu.cpp">
<Filter>SNES\Debugger</Filter>
</ClCompile>
<ClCompile Include="Debugger\ExpressionEvaluator.St018.cpp">
<Filter>Debugger</Filter>
</ClCompile>
<ClCompile Include="SNES\Debugger\St018DisUtils.cpp">
<Filter>SNES\Debugger</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="PCE">
Expand Down Expand Up @@ -3406,5 +3454,8 @@
<Filter Include="WS\APU">
<UniqueIdentifier>{e8ed2b40-f0e0-4dc5-89b7-9acc460359c8}</UniqueIdentifier>
</Filter>
<Filter Include="SNES\Coprocessors\ST018">
<UniqueIdentifier>{387c0b44-8063-45e8-a28a-b6d9e27b5a3f}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>
12 changes: 11 additions & 1 deletion Core/Debugger/DebugUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class DebugUtilities
case CpuType::Sa1: return MemoryType::Sa1Memory;
case CpuType::Gsu: return MemoryType::GsuMemory;
case CpuType::Cx4: return MemoryType::Cx4Memory;
case CpuType::St018: return MemoryType::St018Memory;
case CpuType::Gameboy: return MemoryType::GameboyMemory;
case CpuType::Nes: return MemoryType::NesMemory;
case CpuType::Pce: return MemoryType::PceMemory;
Expand All @@ -36,6 +37,7 @@ class DebugUtilities
case CpuType::Sa1: return 6;
case CpuType::Gsu: return 6;
case CpuType::Cx4: return 6;
case CpuType::St018: return 8;
case CpuType::Gameboy: return 4;
case CpuType::Nes: return 4;
case CpuType::Pce: return 4;
Expand Down Expand Up @@ -85,7 +87,13 @@ class DebugUtilities
case MemoryType::Cx4DataRam:
case MemoryType::Cx4Memory:
return CpuType::Cx4;


case MemoryType::St018Memory:
case MemoryType::St018PrgRom:
case MemoryType::St018DataRom:
case MemoryType::St018WorkRam:
return CpuType::St018;

case MemoryType::GbPrgRom:
case MemoryType::GbWorkRam:
case MemoryType::GbCartRam:
Expand Down Expand Up @@ -222,6 +230,8 @@ class DebugUtilities
case MemoryType::PcePrgRom:
case MemoryType::DspDataRom:
case MemoryType::DspProgramRom:
case MemoryType::St018PrgRom:
case MemoryType::St018DataRom:
case MemoryType::SpcRom:
case MemoryType::SmsPrgRom:
case MemoryType::SmsBootRom:
Expand Down
21 changes: 19 additions & 2 deletions Core/Debugger/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
#include "SNES/Coprocessors/GSU/GsuTypes.h"
#include "SNES/Coprocessors/CX4/Cx4Types.h"
#include "SNES/Coprocessors/DSP/NecDspTypes.h"
#include "SNES/Coprocessors/ST018/ArmV3Types.h"
#include "SNES/Debugger/SnesDebugger.h"
#include "SNES/Debugger/SpcDebugger.h"
#include "SNES/Debugger/GsuDebugger.h"
#include "SNES/Debugger/St018Debugger.h"
#include "SNES/Debugger/NecDspDebugger.h"
#include "SNES/Debugger/Cx4Debugger.h"
#include "NES/Debugger/NesDebugger.h"
Expand Down Expand Up @@ -91,6 +93,7 @@ Debugger::Debugger(Emulator* emu, IConsole* console)
case CpuType::Sa1: debugger.reset(new SnesDebugger(this, CpuType::Sa1)); break;
case CpuType::Gsu: debugger.reset(new GsuDebugger(this)); break;
case CpuType::Cx4: debugger.reset(new Cx4Debugger(this)); break;
case CpuType::St018: debugger.reset(new St018Debugger(this)); break;
case CpuType::Gameboy: debugger.reset(new GbDebugger(this)); break;
case CpuType::Nes: debugger.reset(new NesDebugger(this)); break;
case CpuType::Pce: debugger.reset(new PceDebugger(this)); break;
Expand Down Expand Up @@ -178,6 +181,7 @@ uint64_t Debugger::GetCpuCycleCount()
case CpuType::Sa1: return GetDebugger<type, SnesDebugger>()->GetCpuCycleCount();
case CpuType::Gsu: return GetDebugger<type, GsuDebugger>()->GetCpuCycleCount();
case CpuType::Cx4: return GetDebugger<type, Cx4Debugger>()->GetCpuCycleCount();
case CpuType::St018: return GetDebugger<type, St018Debugger>()->GetCpuCycleCount();
case CpuType::Gameboy: return GetDebugger<type, GbDebugger>()->GetCpuCycleCount();
case CpuType::Nes: return GetDebugger<type, NesDebugger>()->GetCpuCycleCount();
case CpuType::Pce: return GetDebugger<type, PceDebugger>()->GetCpuCycleCount();
Expand Down Expand Up @@ -225,6 +229,7 @@ void Debugger::ProcessInstruction()
case CpuType::Sa1: GetDebugger<type, SnesDebugger>()->ProcessInstruction(); break;
case CpuType::Gsu: GetDebugger<type, GsuDebugger>()->ProcessInstruction(); break;
case CpuType::Cx4: GetDebugger<type, Cx4Debugger>()->ProcessInstruction(); break;
case CpuType::St018: GetDebugger<type, St018Debugger>()->ProcessInstruction(); break;
case CpuType::Gameboy: GetDebugger<type, GbDebugger>()->ProcessInstruction(); break;
case CpuType::Nes: GetDebugger<type, NesDebugger>()->ProcessInstruction(); break;
case CpuType::Pce: GetDebugger<type, PceDebugger>()->ProcessInstruction(); break;
Expand Down Expand Up @@ -258,6 +263,7 @@ void Debugger::ProcessMemoryRead(uint32_t addr, T& value, MemoryOperationType op
case CpuType::Sa1: GetDebugger<CpuType::Sa1, SnesDebugger>()->ProcessRead(addr, value, opType); break;
case CpuType::Gsu: GetDebugger<CpuType::Gsu, GsuDebugger>()->ProcessRead(addr, value, opType); break;
case CpuType::Cx4: GetDebugger<CpuType::Cx4, Cx4Debugger>()->ProcessRead(addr, value, opType); break;
case CpuType::St018: GetDebugger<CpuType::St018, St018Debugger>()->ProcessRead<accessWidth>(addr, value, opType); break;
case CpuType::Gameboy: GetDebugger<CpuType::Gameboy, GbDebugger>()->ProcessRead(addr, value, opType); break;
case CpuType::Nes: GetDebugger<CpuType::Nes, NesDebugger>()->ProcessRead(addr, value, opType); break;
case CpuType::Pce: GetDebugger<CpuType::Pce, PceDebugger>()->ProcessRead(addr, value, opType); break;
Expand Down Expand Up @@ -290,6 +296,7 @@ bool Debugger::ProcessMemoryWrite(uint32_t addr, T& value, MemoryOperationType o
case CpuType::Sa1: GetDebugger<CpuType::Sa1, SnesDebugger>()->ProcessWrite(addr, value, opType); break;
case CpuType::Gsu: GetDebugger<CpuType::Gsu, GsuDebugger>()->ProcessWrite(addr, value, opType); break;
case CpuType::Cx4: GetDebugger<CpuType::Cx4, Cx4Debugger>()->ProcessWrite(addr, value, opType); break;
case CpuType::St018: GetDebugger<CpuType::St018, St018Debugger>()->ProcessWrite<accessWidth>(addr, value, opType); break;
case CpuType::Gameboy: GetDebugger<CpuType::Gameboy, GbDebugger>()->ProcessWrite(addr, value, opType); break;
case CpuType::Nes: GetDebugger<CpuType::Nes, NesDebugger>()->ProcessWrite(addr, value, opType); break;
case CpuType::Pce: GetDebugger<CpuType::Pce, PceDebugger>()->ProcessWrite(addr, value, opType); break;
Expand Down Expand Up @@ -768,6 +775,7 @@ bool Debugger::IsDebugWindowOpened(CpuType cpuType)
case CpuType::Sa1: return _settings->CheckDebuggerFlag(DebuggerFlags::Sa1DebuggerEnabled);
case CpuType::Gsu: return _settings->CheckDebuggerFlag(DebuggerFlags::GsuDebuggerEnabled);
case CpuType::Cx4: return _settings->CheckDebuggerFlag(DebuggerFlags::Cx4DebuggerEnabled);
case CpuType::St018: return _settings->CheckDebuggerFlag(DebuggerFlags::St018DebuggerEnabled);
case CpuType::Gameboy: return _settings->CheckDebuggerFlag(DebuggerFlags::GbDebuggerEnabled);
case CpuType::Nes: return _settings->CheckDebuggerFlag(DebuggerFlags::NesDebuggerEnabled);
case CpuType::Pce: return _settings->CheckDebuggerFlag(DebuggerFlags::PceDebuggerEnabled);
Expand Down Expand Up @@ -819,6 +827,7 @@ void Debugger::GetCpuState(BaseState &dstState, CpuType cpuType)
case CpuType::Sa1: memcpy(&dstState, &srcState, sizeof(SnesCpuState)); break;
case CpuType::Gsu: memcpy(&dstState, &srcState, sizeof(GsuState)); break;
case CpuType::Cx4: memcpy(&dstState, &srcState, sizeof(Cx4State)); break;
case CpuType::St018: memcpy(&dstState, &srcState, sizeof(ArmV3CpuState)); break;
case CpuType::Gameboy: memcpy(&dstState, &srcState, sizeof(GbCpuState)); break;
case CpuType::Nes: memcpy(&dstState, &srcState, sizeof(NesCpuState)); break;
case CpuType::Pce: memcpy(&dstState, &srcState, sizeof(PceCpuState)); break;
Expand All @@ -839,6 +848,7 @@ void Debugger::SetCpuState(BaseState& srcState, CpuType cpuType)
case CpuType::Sa1: memcpy(&dstState, &srcState, sizeof(SnesCpuState)); break;
case CpuType::Gsu: memcpy(&dstState, &srcState, sizeof(GsuState)); break;
case CpuType::Cx4: memcpy(&dstState, &srcState, sizeof(Cx4State)); break;
case CpuType::St018: memcpy(&dstState, &srcState, sizeof(ArmV3CpuState)); break;
case CpuType::Gameboy: memcpy(&dstState, &srcState, sizeof(GbCpuState)); break;
case CpuType::Nes: memcpy(&dstState, &srcState, sizeof(NesCpuState)); break;
case CpuType::Pce: memcpy(&dstState, &srcState, sizeof(PceCpuState)); break;
Expand All @@ -861,7 +871,8 @@ void Debugger::GetPpuState(BaseState& state, CpuType cpuType)
case CpuType::NecDsp:
case CpuType::Sa1:
case CpuType::Gsu:
case CpuType::Cx4: {
case CpuType::Cx4:
case CpuType::St018: {
GetDebugger<CpuType::Snes, SnesDebugger>()->GetPpuState(state);
break;
}
Expand Down Expand Up @@ -907,7 +918,8 @@ void Debugger::SetPpuState(BaseState& state, CpuType cpuType)
case CpuType::NecDsp:
case CpuType::Sa1:
case CpuType::Gsu:
case CpuType::Cx4: {
case CpuType::Cx4:
case CpuType::St018: {
GetDebugger<CpuType::Snes, SnesDebugger>()->SetPpuState(state);
break;
}
Expand Down Expand Up @@ -1168,6 +1180,7 @@ template void Debugger::ProcessInstruction<CpuType::Spc>();
template void Debugger::ProcessInstruction<CpuType::Gsu>();
template void Debugger::ProcessInstruction<CpuType::NecDsp>();
template void Debugger::ProcessInstruction<CpuType::Cx4>();
template void Debugger::ProcessInstruction<CpuType::St018>();
template void Debugger::ProcessInstruction<CpuType::Gameboy>();
template void Debugger::ProcessInstruction<CpuType::Nes>();
template void Debugger::ProcessInstruction<CpuType::Pce>();
Expand All @@ -1183,6 +1196,8 @@ template void Debugger::ProcessMemoryRead<CpuType::Gsu>(uint32_t addr, uint8_t&
template void Debugger::ProcessMemoryRead<CpuType::NecDsp>(uint32_t addr, uint32_t& value, MemoryOperationType opType);
template void Debugger::ProcessMemoryRead<CpuType::NecDsp>(uint32_t addr, uint16_t& value, MemoryOperationType opType);
template void Debugger::ProcessMemoryRead<CpuType::Cx4>(uint32_t addr, uint8_t& value, MemoryOperationType opType);
template void Debugger::ProcessMemoryRead<CpuType::St018, 1>(uint32_t addr, uint32_t& value, MemoryOperationType opType);
template void Debugger::ProcessMemoryRead<CpuType::St018, 4>(uint32_t addr, uint32_t& value, MemoryOperationType opType);
template void Debugger::ProcessMemoryRead<CpuType::Gameboy>(uint32_t addr, uint8_t& value, MemoryOperationType opType);
template void Debugger::ProcessMemoryRead<CpuType::Nes>(uint32_t addr, uint8_t& value, MemoryOperationType opType);
template void Debugger::ProcessMemoryRead<CpuType::Pce>(uint32_t addr, uint8_t& value, MemoryOperationType opType);
Expand All @@ -1200,6 +1215,8 @@ template bool Debugger::ProcessMemoryWrite<CpuType::Spc, 1, MemoryAccessFlags::D
template bool Debugger::ProcessMemoryWrite<CpuType::Gsu>(uint32_t addr, uint8_t& value, MemoryOperationType opType);
template bool Debugger::ProcessMemoryWrite<CpuType::NecDsp>(uint32_t addr, uint16_t& value, MemoryOperationType opType);
template bool Debugger::ProcessMemoryWrite<CpuType::Cx4>(uint32_t addr, uint8_t& value, MemoryOperationType opType);
template bool Debugger::ProcessMemoryWrite<CpuType::St018, 1>(uint32_t addr, uint32_t& value, MemoryOperationType opType);
template bool Debugger::ProcessMemoryWrite<CpuType::St018, 4>(uint32_t addr, uint32_t& value, MemoryOperationType opType);
template bool Debugger::ProcessMemoryWrite<CpuType::Gameboy>(uint32_t addr, uint8_t& value, MemoryOperationType opType);
template bool Debugger::ProcessMemoryWrite<CpuType::Nes>(uint32_t addr, uint8_t& value, MemoryOperationType opType);
template bool Debugger::ProcessMemoryWrite<CpuType::Pce>(uint32_t addr, uint8_t& value, MemoryOperationType opType);
Expand Down
24 changes: 24 additions & 0 deletions Core/Debugger/Disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "SNES/SpcTypes.h"
#include "SNES/Coprocessors/GSU/GsuTypes.h"
#include "SNES/Coprocessors/CX4/Cx4Types.h"
#include "SNES/Coprocessors/ST018/ArmV3Types.h"
#include "Gameboy/GbTypes.h"
#include "GBA/GbaTypes.h"
#include "NES/NesTypes.h"
Expand Down Expand Up @@ -312,6 +313,8 @@ void Disassembler::GetLineData(DisassemblyResult& row, CpuType type, MemoryType
data.Flags = row.Flags;
data.LineCpuType = type;

//TODO move color logic to UI and complete missing data?

switch(row.Address.Type) {
default: break;
case MemoryType::GbPrgRom:
Expand Down Expand Up @@ -461,6 +464,27 @@ void Disassembler::GetLineData(DisassemblyResult& row, CpuType type, MemoryType
break;
}

case CpuType::St018:
{
ArmV3CpuState state = (ArmV3CpuState&)_debugger->GetCpuStateRef(lineCpuType);
if(!disInfo.IsInitialized()) {
disInfo = DisassemblyInfo(row.Address.Address, state.CPSR.ToInt32(), CpuType::St018, row.Address.Type, _memoryDumper);
} else {
data.Flags |= LineFlags::VerifiedCode;
}

data.OpSize = disInfo.GetOpSize();

state.Pipeline.Execute.Address = (uint32_t)row.CpuAddress;
state.R[15] = state.Pipeline.Execute.Address + (data.OpSize * 2);

data.EffectiveAddress = disInfo.GetEffectiveAddress(_debugger, &state, lineCpuType);
if(showMemoryValues && data.EffectiveAddress.ValueSize >= 0) {
data.Value = disInfo.GetMemoryValue(data.EffectiveAddress, _memoryDumper, memType);
}
break;
}

case CpuType::Gameboy:
{
GbCpuState state = (GbCpuState&)_debugger->GetCpuStateRef(lineCpuType);
Expand Down
Loading

0 comments on commit 8d6830a

Please sign in to comment.