diff --git a/external/Panda3DS/logger.hpp b/external/Panda3DS/logger.hpp index b8fd0a3..2ae3e49 100644 --- a/external/Panda3DS/logger.hpp +++ b/external/Panda3DS/logger.hpp @@ -25,7 +25,7 @@ class Logger { // Our loggers here. Enable/disable by toggling the template param static auto cpuTraceLogger = Logger("[CPU TRACE] "); -static auto dmaLogger = Logger("[ DMA ] "); +static auto dmaLogger = Logger ("[ DMA ] "); static auto gpuLogger = Logger("[ GPU ] "); static auto cdromLogger = Logger ("[ CDROM ] "); diff --git a/src/cdrom/cdrom.cpp b/src/cdrom/cdrom.cpp index c699b14..88a5762 100644 --- a/src/cdrom/cdrom.cpp +++ b/src/cdrom/cdrom.cpp @@ -67,7 +67,7 @@ void CDROM::executeCommand(u8 data) { secondResponse.push(statusCode.raw); scheduler->push(&int3, scheduler->time + int3Delay, this); - scheduler->push(&int2, scheduler->time + int3Delay + int2Delay, this); + scheduler->push(&int2, scheduler->time + int3Delay + 50000, this); log("Init\n"); break; @@ -133,7 +133,7 @@ void CDROM::executeCommand(u8 data) { Helpers::panic("[ FATAL ] Unimplemented CDROM test subfunc 0x%02x\n", subFunc); } - scheduler->push(&int3, scheduler->time + int3Delay, this); + scheduler->push(&int3, scheduler->time + int3Delay / 15, this); log("Test\n"); break; @@ -193,7 +193,7 @@ void CDROM::int2(void* classptr) { // Second response if (cdrom->secondResponse.size()) { - Helpers::debugAssert(!cdrom->response.size(), "[ FATAL ] CDROM INT2 before first response was read (probably not supposed to happen...?"); + //Helpers::debugAssert(!cdrom->response.size(), "[ FATAL ] CDROM INT2 before first response was read (probably not supposed to happen...?)"); cdrom->response = cdrom->secondResponse; cdrom->statusReg.rslrrdy = 1; // Response fifo not empty @@ -276,7 +276,11 @@ u32 CDROM::readSectorWord() { std::memcpy(&word, §or[sectorCur], sizeof(u32)); sectorCur += sizeof(u32); - if (sectorCur == sectorSize) statusReg.drqsts = 0; + if (sectorCur == (mode.sectorSize ? sectorSize - 0xC : sectorSizeDataOnly)) { + statusReg.drqsts = 0; + sectorCur = 0; + log("--- Read all data ---\n"); + } return word; } @@ -310,6 +314,8 @@ u8 CDROM::readIF() { } void CDROM::writeIF(u8 data) { + log("ACK\n"); + intFlag &= ~(data & 0x1f); if (data & (1 << 6)) { // "CLRPRM" clear parameter fifo while (params.size()) params.pop(); diff --git a/src/cdrom/cdrom.hpp b/src/cdrom/cdrom.hpp index b122f88..e07a437 100644 --- a/src/cdrom/cdrom.hpp +++ b/src/cdrom/cdrom.hpp @@ -11,14 +11,17 @@ constexpr u64 cpuSpeed = 33868800; constexpr u64 readTime = cpuSpeed / 75; constexpr u64 readTimeDoubleSpeed = readTime / 2; +constexpr size_t operator""_MS(unsigned long long int x) { return (cpuSpeed / 1000) * x; } + // I don't know if these are ok????? -constexpr u64 int3Delay = cpuSpeed / 15000; -constexpr u64 int2Delay = int3Delay * 2; -constexpr u64 getIDDelay = 33868; +constexpr u64 int3Delay = 8_MS; +constexpr u64 int2Delay = int3Delay + 8_MS; +constexpr u64 getIDDelay = 32000; constexpr u64 seekTime = 75000; // Currently stubbed seeking time to this for all seeks constexpr u64 sectorSize = 0x930; +constexpr u64 sectorSizeDataOnly = 0x800; class CDROM { public: diff --git a/src/cpu/backends/interpreter/interpreter.cpp b/src/cpu/backends/interpreter/interpreter.cpp index 3db77a9..e57a3bb 100644 --- a/src/cpu/backends/interpreter/interpreter.cpp +++ b/src/cpu/backends/interpreter/interpreter.cpp @@ -470,6 +470,14 @@ void Interpreter::step(CpuCore* core, Memory* mem, Disassembler* disassembler) { mem->write(address & ~3, dataTemp | rtTemp); break; } + case CpuOpcodes::Opcode::LWC2: { + // TODO + break; + } + case CpuOpcodes::Opcode::SWC2: { + // TODO + break; + } default: Helpers::panic("[ FATAL ] Unimplemented primary instruction 0x%02x (raw: 0x%08x)\n", instr.primaryOpc.Value(), instr.raw); } diff --git a/src/dma/dma.cpp b/src/dma/dma.cpp index b993ad3..ddd7d81 100644 --- a/src/dma/dma.cpp +++ b/src/dma/dma.cpp @@ -57,6 +57,10 @@ void DMA::gpuDMA(Memory* memory) { } break; } + case (u32)Direction::ToRam: { + // TODO + break; + } default: Helpers::panic("[DMA] Unimplemented GPU Sync DMA direction %d\n", ch.chcr.dir.Value()); } @@ -109,7 +113,7 @@ void DMA::cdromDMA(Memory* memory) { u32 addr = ch.madr & 0x1ffffc; u32 bc = ch.bcr.bc; if (!bc) bc = 0x10000; - while (bc-- > 1) { + while (bc-- > 0) { memory->write(addr, memory->cdrom->readSectorWord()); if (ch.chcr.step == (u32)Step::Forward) addr += 4; diff --git a/src/main.cpp b/src/main.cpp index cb6e7a3..fbf1ee8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,6 +11,7 @@ int main(int argc, char** argv) { printf("ChonkyStation\n"); PlayStation playstation = PlayStation(argv[1], argv[2]); + playstation.switchCpuBackend(Cpu::Backend::Interpreter); if (argc >= 4) { playstation.sideloadExecutable(argv[3]); diff --git a/src/scheduler/scheduler.hpp b/src/scheduler/scheduler.hpp index 8d598d1..927a70a 100644 --- a/src/scheduler/scheduler.hpp +++ b/src/scheduler/scheduler.hpp @@ -57,6 +57,6 @@ class Scheduler { }; pqueue events; - void push(void (*functionPtr)(void*), u64 time, void* data, std::string name = "Default"); + void push(void (*functionPtr)(void*), u64 time, void* data, std::string name = "Unnamed event"); void deleteAllEventsOfName(std::string name); }; \ No newline at end of file