Skip to content

Commit

Permalink
Push changes
Browse files Browse the repository at this point in the history
  • Loading branch information
liuk7071 committed Nov 7, 2024
1 parent a95f467 commit e10dd65
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion external/Panda3DS/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Logger {

// Our loggers here. Enable/disable by toggling the template param
static auto cpuTraceLogger = Logger<false>("[CPU TRACE] ");
static auto dmaLogger = Logger<false>("[ DMA ] ");
static auto dmaLogger = Logger<true> ("[ DMA ] ");
static auto gpuLogger = Logger<false>("[ GPU ] ");
static auto cdromLogger = Logger<true> ("[ CDROM ] ");

Expand Down
14 changes: 10 additions & 4 deletions src/cdrom/cdrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -276,7 +276,11 @@ u32 CDROM::readSectorWord() {
std::memcpy(&word, &sector[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;
}
Expand Down Expand Up @@ -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();
Expand Down
9 changes: 6 additions & 3 deletions src/cdrom/cdrom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions src/cpu/backends/interpreter/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,14 @@ void Interpreter::step(CpuCore* core, Memory* mem, Disassembler* disassembler) {
mem->write<u32>(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);
}
Expand Down
6 changes: 5 additions & 1 deletion src/dma/dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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<u32>(addr, memory->cdrom->readSectorWord());
if (ch.chcr.step == (u32)Step::Forward)
addr += 4;
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion src/scheduler/scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ class Scheduler {
};

pqueue<Event> 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);
};

0 comments on commit e10dd65

Please sign in to comment.