Make these part of RSP class.

This commit is contained in:
irisz64
2025-09-01 09:17:28 +02:00
parent b8d691efb8
commit b0e65ce0aa
2 changed files with 118 additions and 114 deletions

View File

@@ -256,6 +256,13 @@ struct RSP {
FORCE_INLINE void ReleaseSemaphore() { semaphore = false; }
void special(const u32 instr);
void regimm(const u32 instr);
void lwc2(const u32 instr);
void swc2(const u32 instr);
void cop2(const u32 instr);
void cop0(const u32 instr);
void add(u32 instr);
void addi(u32 instr);
void and_(u32 instr);

View File

@@ -2,196 +2,197 @@
#include <log.hpp>
namespace n64 {
FORCE_INLINE void special(MI &mi, RSP &rsp, const u32 instr) {
void RSP::special(const u32 instr) {
MI& mi = Core::GetMem().mmio.mi;
switch (const u8 mask = instr & 0x3f) {
case 0x00:
if (instr != 0) {
rsp.sll(instr);
sll(instr);
}
break;
case 0x02:
rsp.srl(instr);
srl(instr);
break;
case 0x03:
rsp.sra(instr);
sra(instr);
break;
case 0x04:
rsp.sllv(instr);
sllv(instr);
break;
case 0x06:
rsp.srlv(instr);
srlv(instr);
break;
case 0x07:
rsp.srav(instr);
srav(instr);
break;
case 0x08:
rsp.jr(instr);
jr(instr);
break;
case 0x09:
rsp.jalr(instr);
jalr(instr);
break;
case 0x0D:
rsp.spStatus.halt = true;
rsp.steps = 0;
rsp.spStatus.broke = true;
if (rsp.spStatus.interruptOnBreak) {
spStatus.halt = true;
steps = 0;
spStatus.broke = true;
if (spStatus.interruptOnBreak) {
mi.InterruptRaise(MI::Interrupt::SP);
}
break;
case 0x20:
case 0x21:
rsp.add(instr);
add(instr);
break;
case 0x22:
case 0x23:
rsp.sub(instr);
sub(instr);
break;
case 0x24:
rsp.and_(instr);
and_(instr);
break;
case 0x25:
rsp.or_(instr);
or_(instr);
break;
case 0x26:
rsp.xor_(instr);
xor_(instr);
break;
case 0x27:
rsp.nor(instr);
nor(instr);
break;
case 0x2A:
rsp.slt(instr);
slt(instr);
break;
case 0x2B:
rsp.sltu(instr);
sltu(instr);
break;
default:
panic("Unhandled RSP special instruction ({:06b})", mask);
}
}
FORCE_INLINE void regimm(RSP &rsp, const u32 instr) {
void RSP::regimm(const u32 instr) {
switch (const u8 mask = instr >> 16 & 0x1F) {
case 0x00:
rsp.b(instr, rsp.gpr[RS(instr)] < 0);
b(instr, gpr[RS(instr)] < 0);
break;
case 0x01:
rsp.b(instr, rsp.gpr[RS(instr)] >= 0);
b(instr, gpr[RS(instr)] >= 0);
break;
case 0x10:
rsp.blink(instr, rsp.gpr[RS(instr)] < 0);
blink(instr, gpr[RS(instr)] < 0);
break;
case 0x11:
rsp.blink(instr, rsp.gpr[RS(instr)] >= 0);
blink(instr, gpr[RS(instr)] >= 0);
break;
default:
panic("Unhandled RSP regimm instruction ({:05b})", mask);
}
}
FORCE_INLINE void lwc2(RSP &rsp, const u32 instr) {
void RSP::lwc2(const u32 instr) {
switch (const u8 mask = instr >> 11 & 0x1F) {
case 0x00:
rsp.lbv(instr);
lbv(instr);
break;
case 0x01:
rsp.lsv(instr);
lsv(instr);
break;
case 0x02:
rsp.llv(instr);
llv(instr);
break;
case 0x03:
rsp.ldv(instr);
ldv(instr);
break;
case 0x04:
rsp.lqv(instr);
lqv(instr);
break;
case 0x05:
rsp.lrv(instr);
lrv(instr);
break;
case 0x06:
rsp.lpv(instr);
lpv(instr);
break;
case 0x07:
rsp.luv(instr);
luv(instr);
break;
case 0x08:
rsp.lhv(instr);
lhv(instr);
break;
case 0x09:
rsp.lfv(instr);
lfv(instr);
break;
case 0x0A:
break;
case 0x0B:
rsp.ltv(instr);
ltv(instr);
break;
default:
panic("Unhandled RSP LWC2 {:05b}", mask);
}
}
FORCE_INLINE void swc2(RSP &rsp, const u32 instr) {
void RSP::swc2(const u32 instr) {
switch (const u8 mask = instr >> 11 & 0x1F) {
case 0x00:
rsp.sbv(instr);
sbv(instr);
break;
case 0x01:
rsp.ssv(instr);
ssv(instr);
break;
case 0x02:
rsp.slv(instr);
slv(instr);
break;
case 0x03:
rsp.sdv(instr);
sdv(instr);
break;
case 0x04:
rsp.sqv(instr);
sqv(instr);
break;
case 0x05:
rsp.srv(instr);
srv(instr);
break;
case 0x06:
rsp.spv(instr);
spv(instr);
break;
case 0x07:
rsp.suv(instr);
suv(instr);
break;
case 0x08:
rsp.shv(instr);
shv(instr);
break;
case 0x09:
rsp.sfv(instr);
sfv(instr);
break;
case 0x0A:
rsp.swv(instr);
swv(instr);
break;
case 0x0B:
rsp.stv(instr);
stv(instr);
break;
default:
panic("Unhandled RSP SWC2 {:05b}", mask);
}
}
FORCE_INLINE void cop2(RSP &rsp, const u32 instr) {
void RSP::cop2(const u32 instr) {
const u8 mask_sub = instr >> 21 & 0x1F;
switch (const u8 mask = instr & 0x3F) {
case 0x00:
if (instr >> 25 & 1) {
rsp.vmulf(instr);
vmulf(instr);
} else {
switch (mask_sub) {
case 0x00:
rsp.mfc2(instr);
mfc2(instr);
break;
case 0x02:
rsp.cfc2(instr);
cfc2(instr);
break;
case 0x04:
rsp.mtc2(instr);
mtc2(instr);
break;
case 0x06:
rsp.ctc2(instr);
ctc2(instr);
break;
default:
panic("Unhandled RSP COP2 sub ({:05b})", mask_sub);
@@ -199,141 +200,141 @@ FORCE_INLINE void cop2(RSP &rsp, const u32 instr) {
}
break;
case 0x01:
rsp.vmulu(instr);
vmulu(instr);
break;
case 0x02:
rsp.vrndp(instr);
vrndp(instr);
break;
case 0x03:
rsp.vmulq(instr);
vmulq(instr);
break;
case 0x04:
rsp.vmudl(instr);
vmudl(instr);
break;
case 0x05:
rsp.vmudm(instr);
vmudm(instr);
break;
case 0x06:
rsp.vmudn(instr);
vmudn(instr);
break;
case 0x07:
rsp.vmudh(instr);
vmudh(instr);
break;
case 0x08:
rsp.vmacf(instr);
vmacf(instr);
break;
case 0x09:
rsp.vmacu(instr);
vmacu(instr);
break;
case 0x0A:
rsp.vrndn(instr);
vrndn(instr);
break;
case 0x0B:
rsp.vmacq(instr);
vmacq(instr);
break;
case 0x0C:
rsp.vmadl(instr);
vmadl(instr);
break;
case 0x0D:
rsp.vmadm(instr);
vmadm(instr);
break;
case 0x0E:
rsp.vmadn(instr);
vmadn(instr);
break;
case 0x0F:
rsp.vmadh(instr);
vmadh(instr);
break;
case 0x10:
rsp.vadd(instr);
vadd(instr);
break;
case 0x11:
rsp.vsub(instr);
vsub(instr);
break;
case 0x12:
rsp.vzero(instr);
vzero(instr);
break;
case 0x13:
rsp.vabs(instr);
vabs(instr);
break;
case 0x14:
rsp.vaddc(instr);
vaddc(instr);
break;
case 0x15:
rsp.vsubc(instr);
vsubc(instr);
break;
case 0x16 ... 0x1C:
case 0x1E:
case 0x1F:
case 0x2E:
case 0x2F:
rsp.vzero(instr);
vzero(instr);
break;
case 0x1D:
rsp.vsar(instr);
vsar(instr);
break;
case 0x20:
rsp.vlt(instr);
vlt(instr);
break;
case 0x21:
rsp.veq(instr);
veq(instr);
break;
case 0x22:
rsp.vne(instr);
vne(instr);
break;
case 0x23:
rsp.vge(instr);
vge(instr);
break;
case 0x24:
rsp.vcl(instr);
vcl(instr);
break;
case 0x25:
rsp.vch(instr);
vch(instr);
break;
case 0x26:
rsp.vcr(instr);
vcr(instr);
break;
case 0x27:
rsp.vmrg(instr);
vmrg(instr);
break;
case 0x28:
rsp.vand(instr);
vand(instr);
break;
case 0x29:
rsp.vnand(instr);
vnand(instr);
break;
case 0x2A:
rsp.vor(instr);
vor(instr);
break;
case 0x2B:
rsp.vnor(instr);
vnor(instr);
break;
case 0x2C:
rsp.vxor(instr);
vxor(instr);
break;
case 0x2D:
rsp.vnxor(instr);
vnxor(instr);
break;
case 0x31:
rsp.vrcpl(instr);
vrcpl(instr);
break;
case 0x35:
rsp.vrsql(instr);
vrsql(instr);
break;
case 0x32:
case 0x36:
rsp.vrcph(instr);
vrcph(instr);
break;
case 0x30:
rsp.vrcp(instr);
vrcp(instr);
break;
case 0x33:
rsp.vmov(instr);
vmov(instr);
break;
case 0x34:
rsp.vrsq(instr);
vrsq(instr);
break;
case 0x38 ... 0x3E:
rsp.vzero(instr);
vzero(instr);
break;
case 0x37:
case 0x3F:
@@ -343,18 +344,14 @@ FORCE_INLINE void cop2(RSP &rsp, const u32 instr) {
}
}
FORCE_INLINE void cop0(Mem &mem, const u32 instr) {
MMIO &mmio = mem.mmio;
RSP &rsp = mmio.rsp;
RDP &rdp = mmio.rdp;
void RSP::cop0(const u32 instr) {
if ((instr & 0x7FF) == 0) {
switch (const u8 mask = instr >> 21 & 0x1F) {
case 0x00:
rsp.mfc0(rdp, instr);
mfc0(Core::GetMem().mmio.rdp, instr);
break;
case 0x04:
rsp.mtc0(instr);
mtc0(instr);
break;
default:
panic("Unhandled RSP COP0 ({:05b})", mask);
@@ -370,10 +367,10 @@ void RSP::Exec(const u32 instr) {
MI &mi = mmio.mi;
switch (const u8 mask = instr >> 26 & 0x3F) {
case 0x00:
special(mi, *this, instr);
special(instr);
break;
case 0x01:
regimm(*this, instr);
regimm(instr);
break;
case 0x02:
j(instr);
@@ -416,10 +413,10 @@ void RSP::Exec(const u32 instr) {
lui(instr);
break;
case 0x10:
cop0(mem, instr);
cop0(instr);
break;
case 0x12:
cop2(*this, instr);
cop2(instr);
break;
case 0x20:
lb(instr);
@@ -447,10 +444,10 @@ void RSP::Exec(const u32 instr) {
sw(instr);
break;
case 0x32:
lwc2(*this, instr);
lwc2(instr);
break;
case 0x3A:
swc2(*this, instr);
swc2(instr);
break;
default:
mem.DumpIMEM();