X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=libpcsxcore%2Fgte.c;h=d342822539c670d357740856c715e991feb74eb4;hp=31213ef5be7ddfc086d126a39a3cf02cc403e1b0;hb=81dbbf4cbb16fc6c9a82a5b91e102c8005c5726a;hpb=90f000f6c23cf8a17c14c0149de4916ea63f373e diff --git a/libpcsxcore/gte.c b/libpcsxcore/gte.c index 31213ef5..d3428225 100644 --- a/libpcsxcore/gte.c +++ b/libpcsxcore/gte.c @@ -149,7 +149,13 @@ #define gteBFC (((s32 *)regs->CP2C.r)[23]) #define gteOFX (((s32 *)regs->CP2C.r)[24]) #define gteOFY (((s32 *)regs->CP2C.r)[25]) -#define gteH (regs->CP2C.p[26].sw.l) +// senquack - gteH register is u16, not s16, and used in GTE that way. +// HOWEVER when read back by CPU using CFC2, it will be incorrectly +// sign-extended by bug in original hardware, according to Nocash docs +// GTE section 'Screen Offset and Distance'. The emulator does this +// sign extension when it is loaded to GTE by CTC2. +//#define gteH (psxRegs.CP2C.p[26].sw.l) +#define gteH (psxRegs.CP2C.p[26].w.l) #define gteDQA (regs->CP2C.p[27].sw.l) #define gteDQB (((s32 *)regs->CP2C.r)[28]) #define gteZSF3 (regs->CP2C.p[29].sw.l) @@ -254,10 +260,47 @@ static inline u32 limE_(psxCP2Regs *regs, u32 result) { #define A3U(x) (x) #endif + +//senquack - n param should be unsigned (will be 'gteH' reg which is u16) +#ifdef GTE_USE_NATIVE_DIVIDE +INLINE u32 DIVIDE(u16 n, u16 d) { + if (n < d * 2) { + return ((u32)n << 16) / d; + } + return 0xffffffff; +} +#else #include "gte_divider.h" +#endif // GTE_USE_NATIVE_DIVIDE #ifndef FLAGLESS +const char gte_cycletab[64] = { + /* 1 2 3 4 5 6 7 8 9 a b c d e f */ + 0, 15, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 6, 0, 0, 0, + 8, 8, 8, 19, 13, 0, 44, 0, 0, 0, 0, 17, 11, 0, 14, 0, + 30, 0, 0, 0, 0, 0, 0, 0, 5, 8, 17, 0, 0, 5, 6, 0, + 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 39, +}; + +// warning: called by the dynarec +int gteCheckStallRaw(u32 op_cycles, psxRegisters *regs) { + u32 left = regs->gteBusyCycle - regs->cycle; + int stall = 0; + + if (left <= 44) { + //printf("c %2u stall %2u %u\n", op_cycles, left, regs->cycle); + regs->cycle = regs->gteBusyCycle; + stall = left; + } + regs->gteBusyCycle = regs->cycle + op_cycles; + return stall; +} + +void gteCheckStall(u32 op) { + gteCheckStallRaw(gte_cycletab[op], &psxRegs); +} + static inline u32 MFC2(int reg) { psxCP2Regs *regs = &psxRegs.CP2; switch (reg) { @@ -305,9 +348,10 @@ static inline void MTC2(u32 value, int reg) { case 28: gteIRGB = value; - gteIR1 = (value & 0x1f) << 7; - gteIR2 = (value & 0x3e0) << 2; - gteIR3 = (value & 0x7c00) >> 3; + // not gteIR1 etc. just to be consistent with dynarec + regs->CP2D.n.ir1 = (value & 0x1f) << 7; + regs->CP2D.n.ir2 = (value & 0x3e0) << 2; + regs->CP2D.n.ir3 = (value & 0x7c00) >> 3; break; case 30: @@ -385,6 +429,7 @@ void gteLWC2() { } void gteSWC2() { + gteCheckStall(0); psxMemWrite32(_oB_, MFC2(_Rt_)); } @@ -404,6 +449,7 @@ static u32 DIVIDE_(s16 n, u16 d) { void gteRTPS(psxCP2Regs *regs) { int quotient; + s64 tmp; #ifdef GTE_LOG GTE_LOG("GTE RTPS\n"); @@ -426,14 +472,16 @@ void gteRTPS(psxCP2Regs *regs) { gteSX2 = limG1(F((s64)gteOFX + ((s64)gteIR1 * quotient)) >> 16); gteSY2 = limG2(F((s64)gteOFY + ((s64)gteIR2 * quotient)) >> 16); - gteMAC0 = F((s64)gteDQB + ((s64)gteDQA * quotient)); - gteIR0 = limH(gteMAC0 >> 12); + tmp = (s64)gteDQB + ((s64)gteDQA * quotient); + gteMAC0 = F(tmp); + gteIR0 = limH(tmp >> 12); } void gteRTPT(psxCP2Regs *regs) { int quotient; int v; s32 vx, vy, vz; + s64 tmp; #ifdef GTE_LOG GTE_LOG("GTE RTPT\n"); @@ -456,8 +504,10 @@ void gteRTPT(psxCP2Regs *regs) { fSX(v) = limG1(F((s64)gteOFX + ((s64)gteIR1 * quotient)) >> 16); fSY(v) = limG2(F((s64)gteOFY + ((s64)gteIR2 * quotient)) >> 16); } - gteMAC0 = F((s64)gteDQB + ((s64)gteDQA * quotient)); - gteIR0 = limH(gteMAC0 >> 12); + + tmp = (s64)gteDQB + ((s64)gteDQA * quotient); + gteMAC0 = F(tmp); + gteIR0 = limH(tmp >> 12); } void gteMVMVA(psxCP2Regs *regs) {