#define gteop (psxRegs.code & 0x1ffffff)
+#ifndef FLAGLESS
+
static inline s64 BOUNDS(s64 n_value, s64 n_max, int n_maxflag, s64 n_min, int n_minflag) {
if (n_value > n_max) {
gteFLAG |= n_maxflag;
return ret;
}
+static inline u32 limE(u32 result) {
+ if (result > 0x1ffff) {
+ gteFLAG |= (1 << 31) | (1 << 17);
+ return 0x1ffff;
+ }
+ return result;
+}
+
+#else
+
+#define BOUNDS(a, ...) (a)
+
+static inline s32 LIM(s32 value, s32 max, s32 min, u32 flag_unused) {
+ s32 ret = value;
+ if (value > max)
+ ret = max;
+ else if (value < min)
+ ret = min;
+ return ret;
+}
+
+static inline u32 limE(u32 result) {
+ if (result > 0x1ffff)
+ return 0x1ffff;
+ return result;
+}
+
+#endif
+
#define A1(a) BOUNDS((a), 0x7fffffff, (1 << 30), -(s64)0x80000000, (1 << 31) | (1 << 27))
#define A2(a) BOUNDS((a), 0x7fffffff, (1 << 29), -(s64)0x80000000, (1 << 31) | (1 << 26))
#define A3(a) BOUNDS((a), 0x7fffffff, (1 << 28), -(s64)0x80000000, (1 << 31) | (1 << 25))
#define limC3(a) LIM((a), 0x00ff, 0x0000, (1 << 19))
#define limD(a) LIM((a), 0xffff, 0x0000, (1 << 31) | (1 << 18))
-static inline u32 limE(u32 result) {
- if (result > 0x1ffff) {
- gteFLAG |= (1 << 31) | (1 << 17);
- return 0x1ffff;
- }
- return result;
-}
-
#define F(a) BOUNDS((a), 0x7fffffff, (1 << 31) | (1 << 16), -(s64)0x80000000, (1 << 31) | (1 << 15))
#define limG1(a) LIM((a), 0x3ff, -0x400, (1 << 31) | (1 << 14))
#define limG2(a) LIM((a), 0x3ff, -0x400, (1 << 31) | (1 << 13))
-#define limH(a) LIM((a), 0xfff, 0x000, (1 << 12))
+#define limH(a) LIM((a), 0x1000, 0x0000, (1 << 12))
#include "gte_divider.h"
+#ifndef FLAGLESS
+
static inline u32 MFC2(int reg) {
switch (reg) {
case 1:
break;
case 28:
- case 30:
- return 0;
-
case 29:
psxRegs.CP2D.r[reg] = LIM(gteIR1 >> 7, 0x1f, 0, 0) |
(LIM(gteIR2 >> 7, 0x1f, 0, 0) << 5) |
}
break;
- case 7:
- case 29:
case 31:
return;
psxMemWrite32(_oB_, MFC2(_Rt_));
}
+#endif // FLAGLESS
+
+#if 0
+#define DIVIDE DIVIDE_
+static u32 DIVIDE_(s16 n, u16 d) {
+ if (n >= 0 && n < d * 2) {
+ s32 n_ = n;
+ return ((n_ << 16) + d / 2) / d;
+ //return (u32)((float)(n_ << 16) / (float)d + (float)0.5);
+ }
+ return 0xffffffff;
+}
+#endif
+
void gteRTPS() {
int quotient;
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)) >> 12);
- gteIR0 = limH(gteMAC0);
+ gteMAC0 = F((s64)gteDQB + ((s64)gteDQA * quotient));
+ gteIR0 = limH(gteMAC0 >> 12);
}
void gteRTPT() {
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)) >> 12);
- gteIR0 = limH(gteMAC0);
+ gteMAC0 = F((s64)gteDQB + ((s64)gteDQA * quotient));
+ gteIR0 = limH(gteMAC0 >> 12);
}
void gteMVMVA() {
gteMAC1 = A1((gteIR1 * gteIR1) >> shift);
gteMAC2 = A2((gteIR2 * gteIR2) >> shift);
gteMAC3 = A3((gteIR3 * gteIR3) >> shift);
- gteIR1 = limB1(gteMAC1 >> shift, lm);
- gteIR2 = limB2(gteMAC2 >> shift, lm);
- gteIR3 = limB3(gteMAC3 >> shift, lm);
+ gteIR1 = limB1(gteMAC1, lm);
+ gteIR2 = limB2(gteMAC2, lm);
+ gteIR3 = limB3(gteMAC3, lm);
}
void gteNCCS() {