X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libpcsxcore%2Fgte.c;h=3ae216f42eb9894e9235a96b67e4f43c8c10031c;hb=3df12a81179acad8406f1791ff716c76caefed31;hp=8ef601a5dfc05f65fd6dab47bf663bef829bb9a3;hpb=8cb04d2205b117d583b3cc4085fab4a285b74ce2;p=pcsx_rearmed.git diff --git a/libpcsxcore/gte.c b/libpcsxcore/gte.c index 8ef601a5..3ae216f4 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 (regs->CP2C.p[26].sw.l) +#define gteH (regs->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) @@ -170,7 +176,7 @@ #ifndef FLAGLESS -static inline s32 BOUNDS_(psxCP2Regs *regs, s64 n_value, s64 n_max, int n_maxflag, s64 n_min, int n_minflag) { +static inline s64 BOUNDS_(psxCP2Regs *regs, s64 n_value, s64 n_max, int n_maxflag, s64 n_min, int n_minflag) { if (n_value > n_max) { gteFLAG |= n_maxflag; } else if (n_value < n_min) { @@ -254,11 +260,21 @@ 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 -static inline u32 MFC2(int reg) { +u32 MFC2(int reg) { psxCP2Regs *regs = &psxRegs.CP2; switch (reg) { case 1: @@ -293,7 +309,7 @@ static inline u32 MFC2(int reg) { return psxRegs.CP2D.r[reg]; } -static inline void MTC2(u32 value, int reg) { +void MTC2(u32 value, int reg) { psxCP2Regs *regs = &psxRegs.CP2; switch (reg) { case 15: @@ -339,7 +355,7 @@ static inline void MTC2(u32 value, int reg) { } } -static inline void CTC2(u32 value, int reg) { +void CTC2(u32 value, int reg) { switch (reg) { case 4: case 12: