Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

n64: step rsp dma during rsp execution #1722

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ares/n64/cpu/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ auto CPU::synchronize() -> void {

queue.step(clocks, [](u32 event) {
switch(event) {
case Queue::RSP_DMA: return rsp.dmaTransferStep();
case Queue::PI_DMA_Read: return pi.dmaFinished();
case Queue::PI_DMA_Write: return pi.dmaFinished();
case Queue::PI_BUS_Write: return pi.writeFinished();
Expand Down
1 change: 0 additions & 1 deletion ares/n64/n64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ namespace ares::Nintendo64 {

struct Queue : priority_queue<u32[512]> {
enum : u32 {
RSP_DMA,
PI_DMA_Read,
PI_DMA_Write,
PI_BUS_Write,
Expand Down
21 changes: 17 additions & 4 deletions ares/n64/rsp/dma.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
auto RSP::dmaTransferStart(void) -> void {
auto RSP::dmaQueue(u32 clocks, Thread& thread) -> void {
dma.clock = (Thread::clock - thread.clock) - clocks;
}

auto RSP::dmaStep(u32 clocks) -> void {
if(dma.busy.any()) {
dma.clock += clocks;
if(dma.clock >= 0) {
dmaTransferStep();
}
}
}

auto RSP::dmaTransferStart(Thread& thread) -> void {
if(dma.busy.any()) return;
if(dma.full.any()) {
dma.current = dma.pending;
dma.busy = dma.full;
dma.full = {0,0};
queue.insert(Queue::RSP_DMA, (dma.current.length+8) / 8 * 3);
dmaQueue((dma.current.length+8) / 8 * 3, thread);
}
}

Expand Down Expand Up @@ -39,10 +52,10 @@ auto RSP::dmaTransferStep() -> void {
if(dma.current.count) {
dma.current.count -= 1;
dma.current.dramAddress += dma.current.skip;
queue.insert(Queue::RSP_DMA, (dma.current.length+8) / 8 * 3);
dmaQueue((dma.current.length+8) / 8 * 3, *this);
} else {
dma.busy = {0,0};
dma.current.length = 0xFF8;
dmaTransferStart();
dmaTransferStart(*this);
}
}
4 changes: 2 additions & 2 deletions ares/n64/rsp/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ auto RSP::ioWrite(u32 address, u32 data_, Thread& thread) -> void {
dma.full.read = 1;
dma.full.write = 0;
// printf("RSP DMA Read: %08x => %08x %08x\n", dma.pending.dramAddress, dma.pending.pbusAddress, dma.pending.length);
dmaTransferStart();
dmaTransferStart(thread);
}

if(address == 3) {
Expand All @@ -112,7 +112,7 @@ auto RSP::ioWrite(u32 address, u32 data_, Thread& thread) -> void {
dma.pending.originPc = dma.pending.originCpu ? cpu.ipu.pc : (u64)rsp.ipu.r[31].u32;
dma.full.write = 1;
dma.full.read = 0;
dmaTransferStart();
dmaTransferStart(thread);
}

if(address == 4) {
Expand Down
11 changes: 9 additions & 2 deletions ares/n64/rsp/rsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ auto RSP::unload() -> void {

auto RSP::main() -> void {
while(Thread::clock < 0) {
if(status.halted) return step(128);
instruction();
auto clock = Thread::clock;

if(status.halted) {
step(128);
} else {
instruction();
}

dmaStep(Thread::clock - clock);
}
}

Expand Down
6 changes: 5 additions & 1 deletion ares/n64/rsp/rsp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ struct RSP : Thread, Memory::RCP<RSP> {
} pipeline;

//dma.cpp
auto dmaTransferStart() -> void;
auto dmaQueue(u32 clocks, Thread& thread) -> void;
auto dmaStep(u32 clocks) -> void;
auto dmaTransferStart(Thread& thread) -> void;
auto dmaTransferStep() -> void;

//io.cpp
Expand Down Expand Up @@ -240,6 +242,8 @@ struct RSP : Thread, Memory::RCP<RSP> {

auto any() -> n1 { return read | write; }
} busy, full;

s64 clock;
} dma;

struct Status : Memory::RCP<Status> {
Expand Down
1 change: 1 addition & 0 deletions ares/n64/rsp/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ auto RSP::serialize(serializer& s) -> void {
s(dma.busy.write);
s(dma.full.read);
s(dma.full.write);
s(dma.clock);

s(status.semaphore);
s(status.halted);
Expand Down
2 changes: 1 addition & 1 deletion ares/n64/system/serialization.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
static const string SerializerVersion = "v135";
static const string SerializerVersion = "v141.1";

auto System::serialize(bool synchronize) -> serializer {
serializer s;
Expand Down
Loading