Skip to content

Commit

Permalink
md: add internalStep function for 32x recompiler
Browse files Browse the repository at this point in the history
Allows in-block calls to step() to become an increment which to be
actioned in bulk at the end of the recompiler block
  • Loading branch information
LukeUsher committed Feb 6, 2025
1 parent 1323a62 commit 048d0e3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
16 changes: 8 additions & 8 deletions ares/md/m32x/bus-internal.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
auto M32X::readInternal(n1 upper, n1 lower, n32 address, n16 data) -> n16 {
if(address >= 0x0000'0000 && address <= 0x0000'3fff) {
if(shm.active()) shm.step(1); if(shs.active()) shs.step(1);
if(shm.active()) shm.internalStep(1); if(shs.active()) shs.internalStep(1);
if(shm.active()) return shm.bootROM[address >> 1];
if(shs.active()) return shs.bootROM[address >> 1];
}
Expand All @@ -12,17 +12,17 @@ auto M32X::readInternal(n1 upper, n1 lower, n32 address, n16 data) -> n16 {
if(address >= 0x0200'0000 && address <= 0x023f'ffff) {
while(dreq.vram) {
// SH2 ROM accesses stall while RV is set
if(shm.active()) shm.step(1);
if(shs.active()) shs.step(1);
if(shm.active()) shm.internalStep(1);
if(shs.active()) shs.internalStep(1);
}

// TODO: SH2 ROM accesses need to stall while the m68k is on the bus
if(shm.active()) shm.step(6); if(shs.active()) shs.step(6);
if(shm.active()) shm.internalStep(6); if(shs.active()) shs.internalStep(6);
return cartridge.child->read(upper, lower, address, data);
}

if(address >= 0x0400'0000 && address <= 0x0405'ffff) {
if(shm.active()) shm.step(5); if(shs.active()) shs.step(5);
if(shm.active()) shm.internalStep(5); if(shs.active()) shs.internalStep(5);
return vdp.bbram[address >> 1 & 0xffff];
}

Expand All @@ -41,15 +41,15 @@ auto M32X::writeInternal(n1 upper, n1 lower, n32 address, n16 data) -> void {
if(address >= 0x0400'0000 && address <= 0x0401'ffff) {
if (!vdp.framebufferAccess) return;
if(!data && (!upper || !lower)) return; //8-bit 0x00 writes do not go through
if(shm.active()) shm.step(4); if(shs.active()) shs.step(4);
if(shm.active()) shm.internalStep(4); if(shs.active()) shs.internalStep(4);
if(upper) vdp.bbram[address >> 1 & 0xffff].byte(1) = data.byte(1);
if(lower) vdp.bbram[address >> 1 & 0xffff].byte(0) = data.byte(0);
return;
}

if(address >= 0x0402'0000 && address <= 0x0403'ffff) {
if (!vdp.framebufferAccess) return;
if(shm.active()) shm.step(4); if(shs.active()) shs.step(4);
if(shm.active()) shm.internalStep(4); if(shs.active()) shs.internalStep(4);
if(upper && data.byte(1)) vdp.bbram[address >> 1 & 0xffff].byte(1) = data.byte(1);
if(lower && data.byte(0)) vdp.bbram[address >> 1 & 0xffff].byte(0) = data.byte(0);
return;
Expand All @@ -58,7 +58,7 @@ auto M32X::writeInternal(n1 upper, n1 lower, n32 address, n16 data) -> void {
if(address >= 0x0404'0000 && address <= 0x0405'ffff) {
if (!vdp.framebufferAccess) return;
if(!data && (!upper || !lower)) return; //8-bit 0x00 writes do not go through
if(shm.active()) shm.step(4); if(shs.active()) shs.step(4);
if(shm.active()) shm.internalStep(4); if(shs.active()) shs.internalStep(4);
if(upper) vdp.bbram[address >> 1 & 0xffff].byte(1) = data.byte(1);
if(lower) vdp.bbram[address >> 1 & 0xffff].byte(0) = data.byte(0);
return;
Expand Down
8 changes: 4 additions & 4 deletions ares/md/m32x/io-internal.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
auto M32X::readInternalIO(n1 upper, n1 lower, n29 address, n16 data) -> n16 {
if(shm.active()) shm.step(1); if(shs.active()) shs.step(1);
if(shm.active()) shm.internalStep(1); if(shs.active()) shs.internalStep(1);

//interrupt mask
if(address == 0x4000) {
Expand Down Expand Up @@ -152,15 +152,15 @@ auto M32X::readInternalIO(n1 upper, n1 lower, n29 address, n16 data) -> n16 {

//palette
if(address >= 0x4200 && address <= 0x43ff) {
if(shm.active()) shm.step(4); if(shs.active()) shs.step(4);
if(shm.active()) shm.internalStep(4); if(shs.active()) shs.internalStep(4);
data = vdp.cram[address >> 1 & 0xff];
}

return data;
}

auto M32X::writeInternalIO(n1 upper, n1 lower, n29 address, n16 data) -> void {
if(shm.active()) shm.step(1); if(shs.active()) shs.step(1);
if(shm.active()) shm.internalStep(1); if(shs.active()) shs.internalStep(1);

//interrupt mask
if(address == 0x4000) {
Expand Down Expand Up @@ -338,7 +338,7 @@ auto M32X::writeInternalIO(n1 upper, n1 lower, n29 address, n16 data) -> void {
//palette
if(address >= 0x4200 && address <= 0x43ff) {
if (!vdp.framebufferAccess) return;
if(shm.active()) shm.step(4); if(shs.active()) shs.step(4);
if(shm.active()) shm.internalStep(4); if(shs.active()) shs.internalStep(4);
if(upper) vdp.cram[address >> 1 & 0xff].byte(1) = data.byte(1);
if(lower) vdp.cram[address >> 1 & 0xff].byte(0) = data.byte(0);
}
Expand Down
1 change: 1 addition & 0 deletions ares/md/m32x/m32x.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct M32X {
auto main() -> void;
auto instructionPrologue(u16 instruction) -> void override;
auto step(u32 clocks) -> void override;
auto internalStep(u32 clocks) -> void;
auto power(bool reset) -> void;
auto restart() -> void;
auto syncOtherSh2() -> void;
Expand Down
9 changes: 9 additions & 0 deletions ares/md/m32x/sh7604.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ auto M32X::SH7604::instructionPrologue(u16 instruction) -> void {
debugger.instruction(instruction);
}

auto M32X::SH7604::internalStep(u32 clocks) -> void {
if(SH2::Accuracy::Recompiler && m32x.shm.recompiler.enabled) {
regs.CCR += clocks;
return;
}

step(clocks);
}

auto M32X::SH7604::step(u32 clocks) -> void {
SH2::frt.run(clocks);
SH2::wdt.run(clocks);
Expand Down

0 comments on commit 048d0e3

Please sign in to comment.