2020-03-31 18:55:57 +02:00
|
|
|
|
#include "LIBGTE.H"
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "EMULATOR.H"
|
|
|
|
|
#include "EMULATOR_PRIVATE.H"
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
2020-05-06 06:02:09 +02:00
|
|
|
|
#include "LIBMATH.H"
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-15 14:27:12 +02:00
|
|
|
|
#include "INLINE_C.H"
|
2020-05-22 12:26:19 +02:00
|
|
|
|
#include "GTEREG.H"
|
|
|
|
|
|
|
|
|
|
#include "GTE/rcossin_tbl.h"
|
|
|
|
|
#include "GTE/ratan_tbl.h"
|
|
|
|
|
#include "GTE/sqrt_tbl.h"
|
2020-04-15 14:27:12 +02:00
|
|
|
|
|
2020-05-20 15:48:19 +02:00
|
|
|
|
#define ONE 4096
|
|
|
|
|
#define FIXED(a) ((a) / ONE)
|
2020-05-18 08:34:10 +02:00
|
|
|
|
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#define WIDE_SCREEN (0)
|
|
|
|
|
|
2020-05-22 12:26:19 +02:00
|
|
|
|
#if !defined(GTE_EXTERNAL)
|
|
|
|
|
|
2020-03-31 18:55:57 +02:00
|
|
|
|
GTERegisters gteRegs;
|
|
|
|
|
|
|
|
|
|
#define GTE_SF(op) ((op >> 19) & 1)
|
|
|
|
|
#define GTE_MX(op) ((op >> 17) & 3)
|
|
|
|
|
#define GTE_V(op) ((op >> 15) & 3)
|
|
|
|
|
#define GTE_CV(op) ((op >> 13) & 3)
|
|
|
|
|
#define GTE_LM(op) ((op >> 10) & 1)
|
|
|
|
|
#define GTE_FUNCT(op) (op & 63)
|
|
|
|
|
|
|
|
|
|
#define gteop(code) (code & 0x1ffffff)
|
|
|
|
|
|
|
|
|
|
#define VX(n) (n < 3 ? gteRegs.CP2D.p[ n << 1 ].sw.l : IR1)
|
|
|
|
|
#define VY(n) (n < 3 ? gteRegs.CP2D.p[ n << 1 ].sw.h : IR2)
|
|
|
|
|
#define VZ(n) (n < 3 ? gteRegs.CP2D.p[ (n << 1) + 1 ].sw.l : IR3)
|
|
|
|
|
#define MX11(n) (n < 3 ? gteRegs.CP2C.p[ (n << 3) ].sw.l : -R << 4)
|
|
|
|
|
#define MX12(n) (n < 3 ? gteRegs.CP2C.p[ (n << 3) ].sw.h : R << 4)
|
|
|
|
|
#define MX13(n) (n < 3 ? gteRegs.CP2C.p[ (n << 3) + 1 ].sw.l : IR0)
|
|
|
|
|
#define MX21(n) (n < 3 ? gteRegs.CP2C.p[ (n << 3) + 1 ].sw.h : R13)
|
|
|
|
|
#define MX22(n) (n < 3 ? gteRegs.CP2C.p[ (n << 3) + 2 ].sw.l : R13)
|
|
|
|
|
#define MX23(n) (n < 3 ? gteRegs.CP2C.p[ (n << 3) + 2 ].sw.h : R13)
|
|
|
|
|
#define MX31(n) (n < 3 ? gteRegs.CP2C.p[ (n << 3) + 3 ].sw.l : R22)
|
|
|
|
|
#define MX32(n) (n < 3 ? gteRegs.CP2C.p[ (n << 3) + 3 ].sw.h : R22)
|
|
|
|
|
#define MX33(n) (n < 3 ? gteRegs.CP2C.p[ (n << 3) + 4 ].sw.l : R22)
|
|
|
|
|
#define CV1(n) (n < 3 ? gteRegs.CP2C.p[ (n << 3) + 5 ].sd : 0)
|
|
|
|
|
#define CV2(n) (n < 3 ? gteRegs.CP2C.p[ (n << 3) + 6 ].sd : 0)
|
|
|
|
|
#define CV3(n) (n < 3 ? gteRegs.CP2C.p[ (n << 3) + 7 ].sd : 0)
|
|
|
|
|
|
|
|
|
|
#ifndef max
|
|
|
|
|
# define max(a, b) ((a) > (b) ? (a) : (b))
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef min
|
|
|
|
|
# define min(a, b) ((a) < (b) ? (a) : (b))
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void InitGeom()
|
|
|
|
|
{
|
2020-04-23 09:25:56 +02:00
|
|
|
|
//_patch_gte(); //Extern
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#if 0
|
2020-04-23 09:25:56 +02:00
|
|
|
|
mfc0 $v0, SR
|
|
|
|
|
lui $v1, 0x4000
|
|
|
|
|
or $v0, $v1
|
|
|
|
|
mtc0 $v0, SR
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
2020-05-22 12:26:19 +02:00
|
|
|
|
ZSF3 = 341;
|
2020-04-23 09:25:56 +02:00
|
|
|
|
ZSF4 = 256;
|
|
|
|
|
H = 1000;
|
|
|
|
|
DQA = -98;
|
|
|
|
|
DQB = 340;
|
|
|
|
|
OFX = 0;
|
|
|
|
|
OFY = 0;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetGeomOffset(int ofx, int ofy)
|
|
|
|
|
{
|
2020-04-23 09:25:56 +02:00
|
|
|
|
OFX = ofx << 16;
|
|
|
|
|
OFY = ofy << 16;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetGeomScreen(int h)
|
|
|
|
|
{
|
2020-04-23 09:25:56 +02:00
|
|
|
|
H = h;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int m_sf;
|
|
|
|
|
static long long m_mac0;
|
|
|
|
|
static long long m_mac3;
|
|
|
|
|
|
|
|
|
|
unsigned int gte_leadingzerocount(unsigned int lzcs) {
|
2020-04-23 09:25:56 +02:00
|
|
|
|
unsigned int lzcr = 0;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if ((lzcs & 0x80000000) == 0)
|
|
|
|
|
lzcs = ~lzcs;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
while ((lzcs & 0x80000000) != 0) {
|
|
|
|
|
lzcr++;
|
|
|
|
|
lzcs <<= 1;
|
|
|
|
|
}
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
return lzcr;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int LIM(int value, int max, int min, unsigned int flag) {
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (value > max) {
|
|
|
|
|
FLAG |= flag;
|
|
|
|
|
return max;
|
|
|
|
|
}
|
|
|
|
|
else if (value < min) {
|
|
|
|
|
FLAG |= flag;
|
|
|
|
|
return min;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-15 14:27:12 +02:00
|
|
|
|
unsigned int MFC2(int reg)
|
|
|
|
|
{
|
2020-03-31 18:55:57 +02:00
|
|
|
|
switch (reg) {
|
|
|
|
|
case 1:
|
|
|
|
|
case 3:
|
|
|
|
|
case 5:
|
|
|
|
|
case 8:
|
|
|
|
|
case 9:
|
|
|
|
|
case 10:
|
|
|
|
|
case 11:
|
|
|
|
|
gteRegs.CP2D.p[reg].d = (int)gteRegs.CP2D.p[reg].sw.l;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
|
case 16:
|
|
|
|
|
case 17:
|
|
|
|
|
case 18:
|
|
|
|
|
case 19:
|
|
|
|
|
gteRegs.CP2D.p[reg].d = (unsigned int)gteRegs.CP2D.p[reg].w.l;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 15:
|
|
|
|
|
gteRegs.CP2D.p[reg].d = SXY2;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 28:
|
|
|
|
|
case 29:
|
|
|
|
|
gteRegs.CP2D.p[reg].d = LIM(IR1 >> 7, 0x1f, 0, 0) | (LIM(IR2 >> 7, 0x1f, 0, 0) << 5) | (LIM(IR3 >> 7, 0x1f, 0, 0) << 10);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return gteRegs.CP2D.p[reg].d;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-15 15:47:00 +02:00
|
|
|
|
int MFC2_S(int reg)
|
|
|
|
|
{
|
|
|
|
|
// FIXME: Is that modifiers should be signed too?
|
|
|
|
|
switch (reg) {
|
|
|
|
|
case 1:
|
|
|
|
|
case 3:
|
|
|
|
|
case 5:
|
|
|
|
|
case 8:
|
|
|
|
|
case 9:
|
|
|
|
|
case 10:
|
|
|
|
|
case 11:
|
|
|
|
|
gteRegs.CP2D.p[reg].d = (int)gteRegs.CP2D.p[reg].sw.l;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
|
case 16:
|
|
|
|
|
case 17:
|
|
|
|
|
case 18:
|
|
|
|
|
case 19:
|
|
|
|
|
gteRegs.CP2D.p[reg].d = (unsigned int)gteRegs.CP2D.p[reg].w.l;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 15:
|
|
|
|
|
gteRegs.CP2D.p[reg].d = SXY2;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 28:
|
|
|
|
|
case 29:
|
|
|
|
|
gteRegs.CP2D.p[reg].d = LIM(IR1 >> 7, 0x1f, 0, 0) | (LIM(IR2 >> 7, 0x1f, 0, 0) << 5) | (LIM(IR3 >> 7, 0x1f, 0, 0) << 10);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return gteRegs.CP2D.p[reg].sd;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-15 14:27:12 +02:00
|
|
|
|
void MTC2(unsigned int value, int reg) {
|
2020-03-31 18:55:57 +02:00
|
|
|
|
switch (reg) {
|
|
|
|
|
case 15:
|
|
|
|
|
SXY0 = SXY1;
|
|
|
|
|
SXY1 = SXY2;
|
|
|
|
|
SXY2 = value;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 28:
|
|
|
|
|
IR1 = (value & 0x1f) << 7;
|
|
|
|
|
IR2 = (value & 0x3e0) << 2;
|
|
|
|
|
IR3 = (value & 0x7c00) >> 3;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 30:
|
|
|
|
|
LZCR = gte_leadingzerocount(value);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 31:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gteRegs.CP2D.p[reg].d = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-15 15:47:00 +02:00
|
|
|
|
void MTC2_S(int value, int reg) {
|
|
|
|
|
switch (reg) {
|
|
|
|
|
case 15:
|
|
|
|
|
SXY0 = SXY1;
|
|
|
|
|
SXY1 = SXY2;
|
|
|
|
|
SXY2 = value;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 28:
|
|
|
|
|
IR1 = (value & 0x1f) << 7;
|
|
|
|
|
IR2 = (value & 0x3e0) << 2;
|
|
|
|
|
IR3 = (value & 0x7c00) >> 3;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 30:
|
|
|
|
|
LZCR = gte_leadingzerocount(value);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 31:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gteRegs.CP2D.p[reg].sd = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-15 14:27:12 +02:00
|
|
|
|
void CTC2(unsigned int value, int reg) {
|
2020-03-31 18:55:57 +02:00
|
|
|
|
switch (reg) {
|
|
|
|
|
case 4:
|
|
|
|
|
case 12:
|
|
|
|
|
case 20:
|
|
|
|
|
case 26:
|
|
|
|
|
case 27:
|
|
|
|
|
case 29:
|
|
|
|
|
case 30:
|
|
|
|
|
value = (int)(short)value;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 31:
|
|
|
|
|
value = value & 0x7ffff000;
|
|
|
|
|
if ((value & 0x7f87e000) != 0)
|
|
|
|
|
value |= 0x80000000;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gteRegs.CP2C.p[reg].d = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-15 15:47:00 +02:00
|
|
|
|
void CTC2_S(int value, int reg) {
|
|
|
|
|
switch (reg) {
|
|
|
|
|
case 4:
|
|
|
|
|
case 12:
|
|
|
|
|
case 20:
|
|
|
|
|
case 26:
|
|
|
|
|
case 27:
|
|
|
|
|
case 29:
|
|
|
|
|
case 30:
|
|
|
|
|
value = (int)(short)value;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 31:
|
|
|
|
|
value = value & 0x7ffff000;
|
|
|
|
|
if ((value & 0x7f87e000) != 0)
|
|
|
|
|
value |= 0x80000000;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gteRegs.CP2C.p[reg].sd = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-15 14:50:49 +02:00
|
|
|
|
unsigned int CFC2(int reg)
|
|
|
|
|
{
|
|
|
|
|
// TODO: correct functionality
|
|
|
|
|
|
|
|
|
|
return gteRegs.CP2C.p[reg].d;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-15 15:47:00 +02:00
|
|
|
|
int CFC2_S(int reg)
|
|
|
|
|
{
|
|
|
|
|
// TODO: correct functionality
|
|
|
|
|
|
|
|
|
|
return gteRegs.CP2C.p[reg].sd;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#define _oB_ (gteRegs.GPR.r[_Rs_] + _Imm_)
|
|
|
|
|
|
|
|
|
|
inline long long gte_shift(long long a, int sf) {
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (sf > 0)
|
|
|
|
|
return a >> 12;
|
|
|
|
|
else if (sf < 0)
|
|
|
|
|
return a << 12;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
return a;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int BOUNDS(/*int44*/long long value, int max_flag, int min_flag) {
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (value/*.positive_overflow()*/ > (long long)0x7ffffffffff)
|
|
|
|
|
FLAG |= max_flag;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (value/*.negative_overflow()*/ < (long long)-0x8000000000)
|
|
|
|
|
FLAG |= min_flag;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
return int(gte_shift(value/*.value()*/, m_sf));
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned int gte_divide(unsigned short numerator, unsigned short denominator)
|
|
|
|
|
{
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (numerator < (denominator * 2))
|
|
|
|
|
{
|
|
|
|
|
static unsigned char table[] =
|
|
|
|
|
{
|
|
|
|
|
0xff, 0xfd, 0xfb, 0xf9, 0xf7, 0xf5, 0xf3, 0xf1, 0xef, 0xee, 0xec, 0xea, 0xe8, 0xe6, 0xe4, 0xe3,
|
|
|
|
|
0xe1, 0xdf, 0xdd, 0xdc, 0xda, 0xd8, 0xd6, 0xd5, 0xd3, 0xd1, 0xd0, 0xce, 0xcd, 0xcb, 0xc9, 0xc8,
|
|
|
|
|
0xc6, 0xc5, 0xc3, 0xc1, 0xc0, 0xbe, 0xbd, 0xbb, 0xba, 0xb8, 0xb7, 0xb5, 0xb4, 0xb2, 0xb1, 0xb0,
|
|
|
|
|
0xae, 0xad, 0xab, 0xaa, 0xa9, 0xa7, 0xa6, 0xa4, 0xa3, 0xa2, 0xa0, 0x9f, 0x9e, 0x9c, 0x9b, 0x9a,
|
|
|
|
|
0x99, 0x97, 0x96, 0x95, 0x94, 0x92, 0x91, 0x90, 0x8f, 0x8d, 0x8c, 0x8b, 0x8a, 0x89, 0x87, 0x86,
|
|
|
|
|
0x85, 0x84, 0x83, 0x82, 0x81, 0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78, 0x77, 0x75, 0x74,
|
|
|
|
|
0x73, 0x72, 0x71, 0x70, 0x6f, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x69, 0x68, 0x67, 0x66, 0x65, 0x64,
|
|
|
|
|
0x63, 0x62, 0x61, 0x60, 0x5f, 0x5e, 0x5d, 0x5d, 0x5c, 0x5b, 0x5a, 0x59, 0x58, 0x57, 0x56, 0x55,
|
|
|
|
|
0x54, 0x53, 0x53, 0x52, 0x51, 0x50, 0x4f, 0x4e, 0x4d, 0x4d, 0x4c, 0x4b, 0x4a, 0x49, 0x48, 0x48,
|
|
|
|
|
0x47, 0x46, 0x45, 0x44, 0x43, 0x43, 0x42, 0x41, 0x40, 0x3f, 0x3f, 0x3e, 0x3d, 0x3c, 0x3c, 0x3b,
|
|
|
|
|
0x3a, 0x39, 0x39, 0x38, 0x37, 0x36, 0x36, 0x35, 0x34, 0x33, 0x33, 0x32, 0x31, 0x31, 0x30, 0x2f,
|
|
|
|
|
0x2e, 0x2e, 0x2d, 0x2c, 0x2c, 0x2b, 0x2a, 0x2a, 0x29, 0x28, 0x28, 0x27, 0x26, 0x26, 0x25, 0x24,
|
|
|
|
|
0x24, 0x23, 0x22, 0x22, 0x21, 0x20, 0x20, 0x1f, 0x1e, 0x1e, 0x1d, 0x1d, 0x1c, 0x1b, 0x1b, 0x1a,
|
|
|
|
|
0x19, 0x19, 0x18, 0x18, 0x17, 0x16, 0x16, 0x15, 0x15, 0x14, 0x14, 0x13, 0x12, 0x12, 0x11, 0x11,
|
|
|
|
|
0x10, 0x0f, 0x0f, 0x0e, 0x0e, 0x0d, 0x0d, 0x0c, 0x0c, 0x0b, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08,
|
|
|
|
|
0x07, 0x07, 0x06, 0x06, 0x05, 0x05, 0x04, 0x04, 0x03, 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00,
|
|
|
|
|
0x00
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int shift = gte_leadingzerocount(denominator) - 16;
|
|
|
|
|
|
|
|
|
|
int r1 = (denominator << shift) & 0x7fff;
|
|
|
|
|
int r2 = table[((r1 + 0x40) >> 7)] + 0x101;
|
|
|
|
|
int r3 = ((0x80 - (r2 * (r1 + 0x8000))) >> 8) & 0x1ffff;
|
|
|
|
|
unsigned int reciprocal = ((r2 * r3) + 0x80) >> 8;
|
|
|
|
|
|
|
|
|
|
return (unsigned int)((((unsigned long long)reciprocal * (numerator << shift)) + 0x8000) >> 16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0xffffffff;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Setting bits 12 & 19-22 in FLAG does not set bit 31 */
|
|
|
|
|
|
|
|
|
|
int A1(/*int44*/long long a) { return BOUNDS(a, (1 << 31) | (1 << 30), (1 << 31) | (1 << 27)); }
|
|
|
|
|
int A2(/*int44*/long long a) { return BOUNDS(a, (1 << 31) | (1 << 29), (1 << 31) | (1 << 26)); }
|
|
|
|
|
int A3(/*int44*/long long a) { m_mac3 = a; return BOUNDS(a, (1 << 31) | (1 << 28), (1 << 31) | (1 << 25)); }
|
|
|
|
|
int Lm_B1(int a, int lm) { return LIM(a, 0x7fff, -0x8000 * !lm, (1 << 31) | (1 << 24)); }
|
|
|
|
|
int Lm_B2(int a, int lm) { return LIM(a, 0x7fff, -0x8000 * !lm, (1 << 31) | (1 << 23)); }
|
|
|
|
|
int Lm_B3(int a, int lm) { return LIM(a, 0x7fff, -0x8000 * !lm, (1 << 22)); }
|
|
|
|
|
|
|
|
|
|
int Lm_B3_sf(long long value, int sf, int lm) {
|
2020-04-23 09:25:56 +02:00
|
|
|
|
int value_sf = int(gte_shift(value, sf));
|
|
|
|
|
int value_12 = int(gte_shift(value, 1));
|
|
|
|
|
int max = 0x7fff;
|
|
|
|
|
int min = 0;
|
|
|
|
|
if (lm == 0)
|
|
|
|
|
min = -0x8000;
|
|
|
|
|
|
|
|
|
|
if (value_12 < -0x8000 || value_12 > 0x7fff)
|
|
|
|
|
FLAG |= (1 << 22);
|
|
|
|
|
|
|
|
|
|
if (value_sf > max)
|
|
|
|
|
return max;
|
|
|
|
|
else if (value_sf < min)
|
|
|
|
|
return min;
|
|
|
|
|
|
|
|
|
|
return value_sf;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Lm_C1(int a) { return LIM(a, 0x00ff, 0x0000, (1 << 21)); }
|
|
|
|
|
int Lm_C2(int a) { return LIM(a, 0x00ff, 0x0000, (1 << 20)); }
|
|
|
|
|
int Lm_C3(int a) { return LIM(a, 0x00ff, 0x0000, (1 << 19)); }
|
2020-03-31 19:09:22 +02:00
|
|
|
|
int Lm_D(long long a, int sf) { return LIM(int(gte_shift(a, sf)), 0xffff, 0x0000, (1 << 31) | (1 << 18)); }
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
|
|
|
|
unsigned int Lm_E(unsigned int result) {
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (result == 0xffffffff) {
|
|
|
|
|
FLAG |= (1 << 31) | (1 << 17);
|
|
|
|
|
return 0x1ffff;
|
|
|
|
|
}
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (result > 0x1ffff)
|
|
|
|
|
return 0x1ffff;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
return result;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long long F(long long a) {
|
2020-04-23 09:25:56 +02:00
|
|
|
|
m_mac0 = a;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (a > 0x7fffffffLL)
|
|
|
|
|
FLAG |= (1 << 31) | (1 << 16);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (a < -0x80000000LL)
|
|
|
|
|
FLAG |= (1 << 31) | (1 << 15);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
return a;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Lm_G1(long long a) {
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (a > 0x3ff) {
|
|
|
|
|
FLAG |= (1 << 31) | (1 << 14);
|
|
|
|
|
return 0x3ff;
|
|
|
|
|
}
|
|
|
|
|
if (a < -0x400) {
|
|
|
|
|
FLAG |= (1 << 31) | (1 << 14);
|
|
|
|
|
return -0x400;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return int(a);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Lm_G2(long long a) {
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (a > 0x3ff) {
|
|
|
|
|
FLAG |= (1 << 31) | (1 << 13);
|
|
|
|
|
return 0x3ff;
|
|
|
|
|
}
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (a < -0x400) {
|
|
|
|
|
FLAG |= (1 << 31) | (1 << 13);
|
|
|
|
|
return -0x400;
|
|
|
|
|
}
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
return int(a);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Lm_G1_ia(long long a) {
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (a > 0x3ffffff)
|
|
|
|
|
return 0x3ffffff;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (a < -0x4000000)
|
|
|
|
|
return -0x4000000;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
return int(a);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Lm_G2_ia(long long a) {
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (a > 0x3ffffff)
|
|
|
|
|
return 0x3ffffff;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (a < -0x4000000)
|
|
|
|
|
return -0x4000000;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
return int(a);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Lm_H(long long value, int sf) {
|
2020-04-23 09:25:56 +02:00
|
|
|
|
long long value_sf = gte_shift(value, sf);
|
|
|
|
|
int value_12 = int(gte_shift(value, 1));
|
|
|
|
|
int max = 0x1000;
|
|
|
|
|
int min = 0x0000;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (value_sf < min || value_sf > max)
|
|
|
|
|
FLAG |= (1 << 12);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (value_12 > max)
|
|
|
|
|
return max;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (value_12 < min)
|
|
|
|
|
return min;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
return value_12;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-22 17:42:21 +02:00
|
|
|
|
#ifdef PGXP
|
|
|
|
|
HalfVector3D g_FP_SXYZ0; // direct access PGXP without table lookup
|
|
|
|
|
HalfVector3D g_FP_SXYZ1;
|
|
|
|
|
HalfVector3D g_FP_SXYZ2;
|
|
|
|
|
|
|
|
|
|
PGXPVData g_pgxpCache[65535];
|
|
|
|
|
int g_pgxpVertexIndex = 0;
|
|
|
|
|
|
|
|
|
|
void PGXP_ClearCache()
|
|
|
|
|
{
|
|
|
|
|
g_pgxpVertexIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PGXP_GetCacheData(PGXPVData& out, uint lookup, ushort indexhint)
|
|
|
|
|
{
|
|
|
|
|
if (indexhint == 0xFFFF)
|
|
|
|
|
{
|
|
|
|
|
out.z = 1.0f;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int start = indexhint - 8; // index hint allows us to start from specific index
|
|
|
|
|
|
|
|
|
|
for (int i = max(0, start); i < g_pgxpVertexIndex; i++)
|
|
|
|
|
{
|
|
|
|
|
if (g_pgxpCache[i].lookup == lookup)
|
|
|
|
|
{
|
|
|
|
|
out = g_pgxpCache[i];
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fill with default values
|
|
|
|
|
out.z = 1.0f;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-22 18:38:52 +02:00
|
|
|
|
void PGXP_UpdateCacheLookup(uint old_lookup, uint new_lookup, float new_z, ushort indexhint)
|
|
|
|
|
{
|
|
|
|
|
if (indexhint == 0xFFFF)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int start = indexhint - 8; // index hint allows us to start from specific index
|
|
|
|
|
|
|
|
|
|
for (int i = max(0, start); i < g_pgxpVertexIndex; i++)
|
|
|
|
|
{
|
|
|
|
|
if (g_pgxpCache[i].lookup == old_lookup)
|
|
|
|
|
{
|
|
|
|
|
if (new_z >= 0)
|
|
|
|
|
g_pgxpCache[i].z = new_z;
|
|
|
|
|
|
|
|
|
|
g_pgxpCache[i].lookup = new_lookup;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-22 17:42:21 +02:00
|
|
|
|
#endif // PGXP
|
|
|
|
|
|
2020-03-31 18:55:57 +02:00
|
|
|
|
int docop2(int op) {
|
2020-04-23 09:25:56 +02:00
|
|
|
|
int v;
|
|
|
|
|
int lm;
|
|
|
|
|
int cv;
|
|
|
|
|
int mx;
|
|
|
|
|
int h_over_sz3 = 0;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
lm = GTE_LM(gteop(op));
|
|
|
|
|
m_sf = GTE_SF(gteop(op));
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
FLAG = 0;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
switch (GTE_FUNCT(gteop(op))) {
|
|
|
|
|
case 0x00:
|
|
|
|
|
case 0x01:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x RTPS", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
MAC1 = A1(/*int44*/(long long)((long long)TRX << 12) + (R11 * VX0) + (R12 * VY0) + (R13 * VZ0));
|
|
|
|
|
MAC2 = A2(/*int44*/(long long)((long long)TRY << 12) + (R21 * VX0) + (R22 * VY0) + (R23 * VZ0));
|
|
|
|
|
MAC3 = A3(/*int44*/(long long)((long long)TRZ << 12) + (R31 * VX0) + (R32 * VY0) + (R33 * VZ0));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3_sf(m_mac3, m_sf, lm);
|
|
|
|
|
SZ0 = SZ1;
|
|
|
|
|
SZ1 = SZ2;
|
|
|
|
|
SZ2 = SZ3;
|
|
|
|
|
SZ3 = Lm_D(m_mac3, 1);
|
|
|
|
|
h_over_sz3 = Lm_E(gte_divide(H, SZ3));
|
|
|
|
|
SXY0 = SXY1;
|
|
|
|
|
SXY1 = SXY2;
|
|
|
|
|
SX2 = int(Lm_G1(F((long long)OFX + ((long long)IR1 * h_over_sz3)) >> 16));
|
|
|
|
|
SY2 = int(Lm_G2(F((long long)OFY + ((long long)IR2 * h_over_sz3)) >> 16));
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
|
|
|
|
#if defined(PGXP)
|
2020-05-22 17:42:21 +02:00
|
|
|
|
{
|
|
|
|
|
g_FP_SXYZ0 = g_FP_SXYZ1;
|
|
|
|
|
g_FP_SXYZ1 = g_FP_SXYZ2;
|
|
|
|
|
|
|
|
|
|
g_FP_SXYZ2.x = (double(OFX) + double(float(IR1) * float(h_over_sz3))) / float(1 << 16);
|
|
|
|
|
g_FP_SXYZ2.y = (double(OFY) + double(float(IR2) * float(h_over_sz3))) / float(1 << 16);
|
|
|
|
|
g_FP_SXYZ2.z = float(max(SZ3, H / 2)) / float(1 << 16);
|
|
|
|
|
|
|
|
|
|
PGXPVData vdata;
|
2020-05-22 18:38:52 +02:00
|
|
|
|
vdata.lookup = PGXP_LOOKUP_HALF(g_FP_SXYZ2.x, g_FP_SXYZ2.y); // hash short values
|
2020-05-22 17:42:21 +02:00
|
|
|
|
vdata.z = g_FP_SXYZ2.z; // store Z
|
|
|
|
|
|
|
|
|
|
g_pgxpCache[g_pgxpVertexIndex++] = vdata;
|
|
|
|
|
}
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
2020-03-31 19:09:22 +02:00
|
|
|
|
MAC0 = int(F((long long)DQB + ((long long)DQA * h_over_sz3)));
|
2020-03-31 18:55:57 +02:00
|
|
|
|
IR0 = Lm_H(m_mac0, 1);
|
2020-04-23 09:25:56 +02:00
|
|
|
|
return 1;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
case 0x06:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x NCLIP", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
MAC0 = int(F((long long)(SX0 * SY1) + (SX1 * SY2) + (SX2 * SY0) - (SX0 * SY2) - (SX1 * SY0) - (SX2 * SY1)));
|
|
|
|
|
return 1;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
case 0x0c:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x OP", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
MAC1 = A1((long long)(R22 * IR3) - (R33 * IR2));
|
|
|
|
|
MAC2 = A2((long long)(R33 * IR1) - (R11 * IR3));
|
|
|
|
|
MAC3 = A3((long long)(R11 * IR2) - (R22 * IR1));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
return 1;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
case 0x10:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x DPCS", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
MAC1 = A1((R << 16) + (IR0 * Lm_B1(A1(((long long)RFC << 12) - (R << 16)), 0)));
|
|
|
|
|
MAC2 = A2((G << 16) + (IR0 * Lm_B2(A2(((long long)GFC << 12) - (G << 16)), 0)));
|
|
|
|
|
MAC3 = A3((B << 16) + (IR0 * Lm_B3(A3(((long long)BFC << 12) - (B << 16)), 0)));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
RGB0 = RGB1;
|
|
|
|
|
RGB1 = RGB2;
|
|
|
|
|
CD2 = CODE;
|
|
|
|
|
R2 = Lm_C1(MAC1 >> 4);
|
|
|
|
|
G2 = Lm_C2(MAC2 >> 4);
|
|
|
|
|
B2 = Lm_C3(MAC3 >> 4);
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case 0x11:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x INTPL", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
MAC1 = A1((IR1 << 12) + (IR0 * Lm_B1(A1(((long long)RFC << 12) - (IR1 << 12)), 0)));
|
|
|
|
|
MAC2 = A2((IR2 << 12) + (IR0 * Lm_B2(A2(((long long)GFC << 12) - (IR2 << 12)), 0)));
|
|
|
|
|
MAC3 = A3((IR3 << 12) + (IR0 * Lm_B3(A3(((long long)BFC << 12) - (IR3 << 12)), 0)));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
RGB0 = RGB1;
|
|
|
|
|
RGB1 = RGB2;
|
|
|
|
|
CD2 = CODE;
|
|
|
|
|
R2 = Lm_C1(MAC1 >> 4);
|
|
|
|
|
G2 = Lm_C2(MAC2 >> 4);
|
|
|
|
|
B2 = Lm_C3(MAC3 >> 4);
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case 0x12:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x MVMVA", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
mx = GTE_MX(gteop(op));
|
|
|
|
|
v = GTE_V(gteop(op));
|
|
|
|
|
cv = GTE_CV(gteop(op));
|
|
|
|
|
|
|
|
|
|
switch (cv) {
|
|
|
|
|
case 2:
|
|
|
|
|
MAC1 = A1((long long)(MX12(mx) * VY(v)) + (MX13(mx) * VZ(v)));
|
|
|
|
|
MAC2 = A2((long long)(MX22(mx) * VY(v)) + (MX23(mx) * VZ(v)));
|
|
|
|
|
MAC3 = A3((long long)(MX32(mx) * VY(v)) + (MX33(mx) * VZ(v)));
|
|
|
|
|
Lm_B1(A1(((long long)CV1(cv) << 12) + (MX11(mx) * VX(v))), 0);
|
|
|
|
|
Lm_B2(A2(((long long)CV2(cv) << 12) + (MX21(mx) * VX(v))), 0);
|
|
|
|
|
Lm_B3(A3(((long long)CV3(cv) << 12) + (MX31(mx) * VX(v))), 0);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
MAC1 = A1(/*int44*/(long long)((long long)CV1(cv) << 12) + (MX11(mx) * VX(v)) + (MX12(mx) * VY(v)) + (MX13(mx) * VZ(v)));
|
|
|
|
|
MAC2 = A2(/*int44*/(long long)((long long)CV2(cv) << 12) + (MX21(mx) * VX(v)) + (MX22(mx) * VY(v)) + (MX23(mx) * VZ(v)));
|
|
|
|
|
MAC3 = A3(/*int44*/(long long)((long long)CV3(cv) << 12) + (MX31(mx) * VX(v)) + (MX32(mx) * VY(v)) + (MX33(mx) * VZ(v)));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case 0x13:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x NCDS", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
MAC1 = A1((long long)(L11 * VX0) + (L12 * VY0) + (L13 * VZ0));
|
|
|
|
|
MAC2 = A2((long long)(L21 * VX0) + (L22 * VY0) + (L23 * VZ0));
|
|
|
|
|
MAC3 = A3((long long)(L31 * VX0) + (L32 * VY0) + (L33 * VZ0));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
MAC1 = A1(/*int44*/(long long)((long long)RBK << 12) + (LR1 * IR1) + (LR2 * IR2) + (LR3 * IR3));
|
|
|
|
|
MAC2 = A2(/*int44*/(long long)((long long)GBK << 12) + (LG1 * IR1) + (LG2 * IR2) + (LG3 * IR3));
|
|
|
|
|
MAC3 = A3(/*int44*/(long long)((long long)BBK << 12) + (LB1 * IR1) + (LB2 * IR2) + (LB3 * IR3));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
MAC1 = A1(((R << 4) * IR1) + (IR0 * Lm_B1(A1(((long long)RFC << 12) - ((R << 4) * IR1)), 0)));
|
|
|
|
|
MAC2 = A2(((G << 4) * IR2) + (IR0 * Lm_B2(A2(((long long)GFC << 12) - ((G << 4) * IR2)), 0)));
|
|
|
|
|
MAC3 = A3(((B << 4) * IR3) + (IR0 * Lm_B3(A3(((long long)BFC << 12) - ((B << 4) * IR3)), 0)));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
RGB0 = RGB1;
|
|
|
|
|
RGB1 = RGB2;
|
|
|
|
|
CD2 = CODE;
|
|
|
|
|
R2 = Lm_C1(MAC1 >> 4);
|
|
|
|
|
G2 = Lm_C2(MAC2 >> 4);
|
|
|
|
|
B2 = Lm_C3(MAC3 >> 4);
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case 0x14:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x CDP", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
MAC1 = A1(/*int44*/(long long)((long long)RBK << 12) + (LR1 * IR1) + (LR2 * IR2) + (LR3 * IR3));
|
|
|
|
|
MAC2 = A2(/*int44*/(long long)((long long)GBK << 12) + (LG1 * IR1) + (LG2 * IR2) + (LG3 * IR3));
|
|
|
|
|
MAC3 = A3(/*int44*/(long long)((long long)BBK << 12) + (LB1 * IR1) + (LB2 * IR2) + (LB3 * IR3));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
MAC1 = A1(((R << 4) * IR1) + (IR0 * Lm_B1(A1(((long long)RFC << 12) - ((R << 4) * IR1)), 0)));
|
|
|
|
|
MAC2 = A2(((G << 4) * IR2) + (IR0 * Lm_B2(A2(((long long)GFC << 12) - ((G << 4) * IR2)), 0)));
|
|
|
|
|
MAC3 = A3(((B << 4) * IR3) + (IR0 * Lm_B3(A3(((long long)BFC << 12) - ((B << 4) * IR3)), 0)));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
RGB0 = RGB1;
|
|
|
|
|
RGB1 = RGB2;
|
|
|
|
|
CD2 = CODE;
|
|
|
|
|
R2 = Lm_C1(MAC1 >> 4);
|
|
|
|
|
G2 = Lm_C2(MAC2 >> 4);
|
|
|
|
|
B2 = Lm_C3(MAC3 >> 4);
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case 0x16:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x NCDT", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
for (v = 0; v < 3; v++) {
|
|
|
|
|
MAC1 = A1((long long)(L11 * VX(v)) + (L12 * VY(v)) + (L13 * VZ(v)));
|
|
|
|
|
MAC2 = A2((long long)(L21 * VX(v)) + (L22 * VY(v)) + (L23 * VZ(v)));
|
|
|
|
|
MAC3 = A3((long long)(L31 * VX(v)) + (L32 * VY(v)) + (L33 * VZ(v)));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
MAC1 = A1(/*int44*/(long long)((long long)RBK << 12) + (LR1 * IR1) + (LR2 * IR2) + (LR3 * IR3));
|
|
|
|
|
MAC2 = A2(/*int44*/(long long)((long long)GBK << 12) + (LG1 * IR1) + (LG2 * IR2) + (LG3 * IR3));
|
|
|
|
|
MAC3 = A3(/*int44*/(long long)((long long)BBK << 12) + (LB1 * IR1) + (LB2 * IR2) + (LB3 * IR3));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
MAC1 = A1(((R << 4) * IR1) + (IR0 * Lm_B1(A1(((long long)RFC << 12) - ((R << 4) * IR1)), 0)));
|
|
|
|
|
MAC2 = A2(((G << 4) * IR2) + (IR0 * Lm_B2(A2(((long long)GFC << 12) - ((G << 4) * IR2)), 0)));
|
|
|
|
|
MAC3 = A3(((B << 4) * IR3) + (IR0 * Lm_B3(A3(((long long)BFC << 12) - ((B << 4) * IR3)), 0)));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
RGB0 = RGB1;
|
|
|
|
|
RGB1 = RGB2;
|
|
|
|
|
CD2 = CODE;
|
|
|
|
|
R2 = Lm_C1(MAC1 >> 4);
|
|
|
|
|
G2 = Lm_C2(MAC2 >> 4);
|
|
|
|
|
B2 = Lm_C3(MAC3 >> 4);
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case 0x1b:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x NCCS", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
MAC1 = A1((long long)(L11 * VX0) + (L12 * VY0) + (L13 * VZ0));
|
|
|
|
|
MAC2 = A2((long long)(L21 * VX0) + (L22 * VY0) + (L23 * VZ0));
|
|
|
|
|
MAC3 = A3((long long)(L31 * VX0) + (L32 * VY0) + (L33 * VZ0));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
MAC1 = A1(/*int44*/(long long)((long long)RBK << 12) + (LR1 * IR1) + (LR2 * IR2) + (LR3 * IR3));
|
|
|
|
|
MAC2 = A2(/*int44*/(long long)((long long)GBK << 12) + (LG1 * IR1) + (LG2 * IR2) + (LG3 * IR3));
|
|
|
|
|
MAC3 = A3(/*int44*/(long long)((long long)BBK << 12) + (LB1 * IR1) + (LB2 * IR2) + (LB3 * IR3));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
MAC1 = A1((R << 4) * IR1);
|
|
|
|
|
MAC2 = A2((G << 4) * IR2);
|
|
|
|
|
MAC3 = A3((B << 4) * IR3);
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
RGB0 = RGB1;
|
|
|
|
|
RGB1 = RGB2;
|
|
|
|
|
CD2 = CODE;
|
|
|
|
|
R2 = Lm_C1(MAC1 >> 4);
|
|
|
|
|
G2 = Lm_C2(MAC2 >> 4);
|
|
|
|
|
B2 = Lm_C3(MAC3 >> 4);
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case 0x1c:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x CC", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
MAC1 = A1(/*int44*/(long long)(((long long)RBK) << 12) + (LR1 * IR1) + (LR2 * IR2) + (LR3 * IR3));
|
|
|
|
|
MAC2 = A2(/*int44*/(long long)(((long long)GBK) << 12) + (LG1 * IR1) + (LG2 * IR2) + (LG3 * IR3));
|
|
|
|
|
MAC3 = A3(/*int44*/(long long)(((long long)BBK) << 12) + (LB1 * IR1) + (LB2 * IR2) + (LB3 * IR3));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
MAC1 = A1((R << 4) * IR1);
|
|
|
|
|
MAC2 = A2((G << 4) * IR2);
|
|
|
|
|
MAC3 = A3((B << 4) * IR3);
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
RGB0 = RGB1;
|
|
|
|
|
RGB1 = RGB2;
|
|
|
|
|
CD2 = CODE;
|
|
|
|
|
R2 = Lm_C1(MAC1 >> 4);
|
|
|
|
|
G2 = Lm_C2(MAC2 >> 4);
|
|
|
|
|
B2 = Lm_C3(MAC3 >> 4);
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case 0x1e:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x NCS", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
MAC1 = A1((long long)(L11 * VX0) + (L12 * VY0) + (L13 * VZ0));
|
|
|
|
|
MAC2 = A2((long long)(L21 * VX0) + (L22 * VY0) + (L23 * VZ0));
|
|
|
|
|
MAC3 = A3((long long)(L31 * VX0) + (L32 * VY0) + (L33 * VZ0));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
MAC1 = A1(/*int44*/(long long)((long long)RBK << 12) + (LR1 * IR1) + (LR2 * IR2) + (LR3 * IR3));
|
|
|
|
|
MAC2 = A2(/*int44*/(long long)((long long)GBK << 12) + (LG1 * IR1) + (LG2 * IR2) + (LG3 * IR3));
|
|
|
|
|
MAC3 = A3(/*int44*/(long long)((long long)BBK << 12) + (LB1 * IR1) + (LB2 * IR2) + (LB3 * IR3));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
RGB0 = RGB1;
|
|
|
|
|
RGB1 = RGB2;
|
|
|
|
|
CD2 = CODE;
|
|
|
|
|
R2 = Lm_C1(MAC1 >> 4);
|
|
|
|
|
G2 = Lm_C2(MAC2 >> 4);
|
|
|
|
|
B2 = Lm_C3(MAC3 >> 4);
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case 0x20:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x NCT", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
for (v = 0; v < 3; v++) {
|
|
|
|
|
MAC1 = A1((long long)(L11 * VX(v)) + (L12 * VY(v)) + (L13 * VZ(v)));
|
|
|
|
|
MAC2 = A2((long long)(L21 * VX(v)) + (L22 * VY(v)) + (L23 * VZ(v)));
|
|
|
|
|
MAC3 = A3((long long)(L31 * VX(v)) + (L32 * VY(v)) + (L33 * VZ(v)));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
MAC1 = A1(/*int44*/(long long)((long long)RBK << 12) + (LR1 * IR1) + (LR2 * IR2) + (LR3 * IR3));
|
|
|
|
|
MAC2 = A2(/*int44*/(long long)((long long)GBK << 12) + (LG1 * IR1) + (LG2 * IR2) + (LG3 * IR3));
|
|
|
|
|
MAC3 = A3(/*int44*/(long long)((long long)BBK << 12) + (LB1 * IR1) + (LB2 * IR2) + (LB3 * IR3));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
RGB0 = RGB1;
|
|
|
|
|
RGB1 = RGB2;
|
|
|
|
|
CD2 = CODE;
|
|
|
|
|
R2 = Lm_C1(MAC1 >> 4);
|
|
|
|
|
G2 = Lm_C2(MAC2 >> 4);
|
|
|
|
|
B2 = Lm_C3(MAC3 >> 4);
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case 0x28:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x SQR", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
MAC1 = A1(IR1 * IR1);
|
|
|
|
|
MAC2 = A2(IR2 * IR2);
|
|
|
|
|
MAC3 = A3(IR3 * IR3);
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
return 1;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
case 0x29:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x DPCL", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
MAC1 = A1(((R << 4) * IR1) + (IR0 * Lm_B1(A1(((long long)RFC << 12) - ((R << 4) * IR1)), 0)));
|
|
|
|
|
MAC2 = A2(((G << 4) * IR2) + (IR0 * Lm_B2(A2(((long long)GFC << 12) - ((G << 4) * IR2)), 0)));
|
|
|
|
|
MAC3 = A3(((B << 4) * IR3) + (IR0 * Lm_B3(A3(((long long)BFC << 12) - ((B << 4) * IR3)), 0)));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
RGB0 = RGB1;
|
|
|
|
|
RGB1 = RGB2;
|
|
|
|
|
CD2 = CODE;
|
|
|
|
|
R2 = Lm_C1(MAC1 >> 4);
|
|
|
|
|
G2 = Lm_C2(MAC2 >> 4);
|
|
|
|
|
B2 = Lm_C3(MAC3 >> 4);
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case 0x2a:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x DPCT", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
for (v = 0; v < 3; v++) {
|
|
|
|
|
MAC1 = A1((R0 << 16) + (IR0 * Lm_B1(A1(((long long)RFC << 12) - (R0 << 16)), 0)));
|
|
|
|
|
MAC2 = A2((G0 << 16) + (IR0 * Lm_B2(A2(((long long)GFC << 12) - (G0 << 16)), 0)));
|
|
|
|
|
MAC3 = A3((B0 << 16) + (IR0 * Lm_B3(A3(((long long)BFC << 12) - (B0 << 16)), 0)));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
RGB0 = RGB1;
|
|
|
|
|
RGB1 = RGB2;
|
|
|
|
|
CD2 = CODE;
|
|
|
|
|
R2 = Lm_C1(MAC1 >> 4);
|
|
|
|
|
G2 = Lm_C2(MAC2 >> 4);
|
|
|
|
|
B2 = Lm_C3(MAC3 >> 4);
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case 0x2d:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x AVSZ3", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
MAC0 = int(F((long long)(ZSF3 * SZ1) + (ZSF3 * SZ2) + (ZSF3 * SZ3)));
|
|
|
|
|
OTZ = Lm_D(m_mac0, 1);
|
|
|
|
|
return 1;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
case 0x2e:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x AVSZ4", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
MAC0 = int(F((long long)(ZSF4 * SZ0) + (ZSF4 * SZ1) + (ZSF4 * SZ2) + (ZSF4 * SZ3)));
|
|
|
|
|
OTZ = Lm_D(m_mac0, 1);
|
|
|
|
|
return 1;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
case 0x30:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x RTPT", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-05-22 17:42:21 +02:00
|
|
|
|
for (v = 0; v < 3; v++)
|
|
|
|
|
{
|
2020-04-23 09:25:56 +02:00
|
|
|
|
MAC1 = A1(/*int44*/(long long)((long long)TRX << 12) + (R11 * VX(v)) + (R12 * VY(v)) + (R13 * VZ(v)));
|
|
|
|
|
MAC2 = A2(/*int44*/(long long)((long long)TRY << 12) + (R21 * VX(v)) + (R22 * VY(v)) + (R23 * VZ(v)));
|
|
|
|
|
MAC3 = A3(/*int44*/(long long)((long long)TRZ << 12) + (R31 * VX(v)) + (R32 * VY(v)) + (R33 * VZ(v)));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3_sf(m_mac3, m_sf, lm);
|
|
|
|
|
SZ0 = SZ1;
|
|
|
|
|
SZ1 = SZ2;
|
|
|
|
|
SZ2 = SZ3;
|
|
|
|
|
SZ3 = Lm_D(m_mac3, 1);
|
|
|
|
|
h_over_sz3 = Lm_E(gte_divide(H, SZ3));
|
|
|
|
|
SXY0 = SXY1;
|
|
|
|
|
SXY1 = SXY2;
|
|
|
|
|
SX2 = Lm_G1(F((long long)OFX + ((long long)IR1 * h_over_sz3)) >> 16);
|
|
|
|
|
SY2 = Lm_G2(F((long long)OFY + ((long long)IR2 * h_over_sz3)) >> 16);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
|
|
|
|
#if defined(PGXP)
|
2020-05-22 17:42:21 +02:00
|
|
|
|
g_FP_SXYZ0 = g_FP_SXYZ1;
|
|
|
|
|
g_FP_SXYZ1 = g_FP_SXYZ2;
|
|
|
|
|
|
|
|
|
|
g_FP_SXYZ2.x = (double(OFX) + double(float(IR1) * float(h_over_sz3))) / float(1 << 16);
|
|
|
|
|
g_FP_SXYZ2.y = (double(OFY) + double(float(IR2) * float(h_over_sz3))) / float(1 << 16);
|
|
|
|
|
g_FP_SXYZ2.z = float(max(SZ3, H / 2)) / float(1 << 16);
|
|
|
|
|
|
|
|
|
|
PGXPVData vdata;
|
|
|
|
|
vdata.lookup = g_FP_SXYZ2.x.sh | (g_FP_SXYZ2.y.sh << 16); // hash short values
|
|
|
|
|
vdata.z = g_FP_SXYZ2.z; // store Z
|
|
|
|
|
|
|
|
|
|
g_pgxpCache[g_pgxpVertexIndex++] = vdata;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
2020-04-23 09:25:56 +02:00
|
|
|
|
}
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
MAC0 = int(F((long long)DQB + ((long long)DQA * h_over_sz3)));
|
|
|
|
|
IR0 = Lm_H(m_mac0, 1);
|
|
|
|
|
return 1;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
case 0x3d:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x GPF", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
MAC1 = A1(IR0 * IR1);
|
|
|
|
|
MAC2 = A2(IR0 * IR2);
|
|
|
|
|
MAC3 = A3(IR0 * IR3);
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
RGB0 = RGB1;
|
|
|
|
|
RGB1 = RGB2;
|
|
|
|
|
CD2 = CODE;
|
|
|
|
|
R2 = Lm_C1(MAC1 >> 4);
|
|
|
|
|
G2 = Lm_C2(MAC2 >> 4);
|
|
|
|
|
B2 = Lm_C3(MAC3 >> 4);
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case 0x3e:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x GPL", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
MAC1 = A1(gte_shift(MAC1, -m_sf) + (IR0 * IR1));
|
|
|
|
|
MAC2 = A2(gte_shift(MAC2, -m_sf) + (IR0 * IR2));
|
|
|
|
|
MAC3 = A3(gte_shift(MAC3, -m_sf) + (IR0 * IR3));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
RGB0 = RGB1;
|
|
|
|
|
RGB1 = RGB2;
|
|
|
|
|
CD2 = CODE;
|
|
|
|
|
R2 = Lm_C1(MAC1 >> 4);
|
|
|
|
|
G2 = Lm_C2(MAC2 >> 4);
|
|
|
|
|
B2 = Lm_C3(MAC3 >> 4);
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case 0x3f:
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#ifdef GTE_LOG
|
2020-04-23 09:25:56 +02:00
|
|
|
|
GTELOG("%08x NCCT", op);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
for (v = 0; v < 3; v++) {
|
|
|
|
|
MAC1 = A1((long long)(L11 * VX(v)) + (L12 * VY(v)) + (L13 * VZ(v)));
|
|
|
|
|
MAC2 = A2((long long)(L21 * VX(v)) + (L22 * VY(v)) + (L23 * VZ(v)));
|
|
|
|
|
MAC3 = A3((long long)(L31 * VX(v)) + (L32 * VY(v)) + (L33 * VZ(v)));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
MAC1 = A1(/*int44*/(long long)((long long)RBK << 12) + (LR1 * IR1) + (LR2 * IR2) + (LR3 * IR3));
|
|
|
|
|
MAC2 = A2(/*int44*/(long long)((long long)GBK << 12) + (LG1 * IR1) + (LG2 * IR2) + (LG3 * IR3));
|
|
|
|
|
MAC3 = A3(/*int44*/(long long)((long long)BBK << 12) + (LB1 * IR1) + (LB2 * IR2) + (LB3 * IR3));
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
MAC1 = A1((R << 4) * IR1);
|
|
|
|
|
MAC2 = A2((G << 4) * IR2);
|
|
|
|
|
MAC3 = A3((B << 4) * IR3);
|
|
|
|
|
IR1 = Lm_B1(MAC1, lm);
|
|
|
|
|
IR2 = Lm_B2(MAC2, lm);
|
|
|
|
|
IR3 = Lm_B3(MAC3, lm);
|
|
|
|
|
RGB0 = RGB1;
|
|
|
|
|
RGB1 = RGB2;
|
|
|
|
|
CD2 = CODE;
|
|
|
|
|
R2 = Lm_C1(MAC1 >> 4);
|
|
|
|
|
G2 = Lm_C2(MAC2 >> 4);
|
|
|
|
|
B2 = Lm_C3(MAC3 >> 4);
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
return 0;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-22 12:26:19 +02:00
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
// Mednafen/BeetlePSX GTE
|
|
|
|
|
#include "GTE/gte.h"
|
|
|
|
|
#include "GTE/pgxp/pgxp_main.h"
|
|
|
|
|
|
|
|
|
|
unsigned int gte_leadingzerocount(unsigned int lzcs) {
|
|
|
|
|
unsigned int lzcr = 0;
|
|
|
|
|
|
|
|
|
|
if ((lzcs & 0x80000000) == 0)
|
|
|
|
|
lzcs = ~lzcs;
|
|
|
|
|
|
|
|
|
|
while ((lzcs & 0x80000000) != 0) {
|
|
|
|
|
lzcr++;
|
|
|
|
|
lzcs <<= 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return lzcr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool g_Initialized = false;
|
|
|
|
|
|
|
|
|
|
void InitGeom()
|
|
|
|
|
{
|
|
|
|
|
if (!g_Initialized)
|
|
|
|
|
{
|
|
|
|
|
GTE_Init();
|
|
|
|
|
GTE_Power();
|
|
|
|
|
|
|
|
|
|
g_Initialized = true;
|
|
|
|
|
PGXP_Init();
|
|
|
|
|
|
|
|
|
|
PGXP_EnableModes(PGXP_MODE_MEMORY | PGXP_VERTEX_CACHE | PGXP_TEXTURE_CORRECTION);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GTE_WriteCR(29, 341); // ZSF3, ZSF4
|
|
|
|
|
GTE_WriteCR(30, 256);
|
|
|
|
|
GTE_WriteCR(26, 1000); // H
|
|
|
|
|
|
|
|
|
|
CTC2_S(-98, 27); // DQA
|
|
|
|
|
CTC2_S(340, 28); // DQB
|
|
|
|
|
|
|
|
|
|
CTC2(24, 0); // OFX, OFY
|
|
|
|
|
CTC2(25, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetGeomOffset(int ofx, int ofy)
|
|
|
|
|
{
|
|
|
|
|
CTC2(*(uint*)&ofx, 24);
|
|
|
|
|
CTC2(*(uint*)&ofy, 25);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetGeomScreen(int h)
|
|
|
|
|
{
|
|
|
|
|
CTC2(*(uint*)&h, 26);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int docop2(int op)
|
|
|
|
|
{
|
|
|
|
|
return GTE_Instruction(*(uint*)&op);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MTC2(unsigned int value, int reg)
|
|
|
|
|
{
|
|
|
|
|
GTE_WriteDR(reg, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MTC2_S(int value, int reg)
|
|
|
|
|
{
|
|
|
|
|
GTE_WriteDR(reg, *(uint*)&value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint MFC2(int reg)
|
|
|
|
|
{
|
|
|
|
|
return GTE_ReadDR(reg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CTC2(unsigned int value, int reg)
|
|
|
|
|
{
|
|
|
|
|
GTE_WriteCR(reg, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CTC2_S(int value, int reg)
|
|
|
|
|
{
|
|
|
|
|
GTE_WriteCR(reg, *(uint*)&value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint CFC2(int reg)
|
|
|
|
|
{
|
|
|
|
|
return GTE_ReadCR(reg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CFC2_S(int reg)
|
|
|
|
|
{
|
|
|
|
|
uint value = CFC2(reg);
|
|
|
|
|
return *(int*)&value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // OLD_GTE
|
|
|
|
|
|
2020-03-31 18:55:57 +02:00
|
|
|
|
void SetRotMatrix(MATRIX* m)
|
|
|
|
|
{
|
2020-05-22 12:26:19 +02:00
|
|
|
|
gte_SetRotMatrix(m);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetLightMatrix(MATRIX* m)
|
|
|
|
|
{
|
2020-05-22 12:26:19 +02:00
|
|
|
|
gte_SetLightMatrix(m);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetColorMatrix(MATRIX* m)
|
|
|
|
|
{
|
2020-05-22 12:26:19 +02:00
|
|
|
|
gte_SetColorMatrix(m);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetTransMatrix(MATRIX* m)
|
|
|
|
|
{
|
2020-05-22 12:26:19 +02:00
|
|
|
|
gte_SetTransMatrix(m);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define MAX_NUM_MATRICES 20
|
|
|
|
|
int matrixLevel = 0;
|
|
|
|
|
MATRIX stack[MAX_NUM_MATRICES];//unk_410
|
|
|
|
|
MATRIX* currentMatrix = &stack[0];//unk_40C
|
|
|
|
|
|
|
|
|
|
void PushMatrix()
|
|
|
|
|
{
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (matrixLevel < 20)
|
|
|
|
|
{
|
|
|
|
|
MATRIX* m = &stack[matrixLevel];//$t7
|
2020-05-22 12:26:19 +02:00
|
|
|
|
|
|
|
|
|
gte_ReadRotMatrix(m);
|
|
|
|
|
gte_sttr(m->t);
|
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
currentMatrix++;
|
|
|
|
|
matrixLevel++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("Error: Can't push matrix,stack(max 20) is full!\n");
|
|
|
|
|
}
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PopMatrix()
|
|
|
|
|
{
|
2020-04-23 09:25:56 +02:00
|
|
|
|
if (matrixLevel > 0)
|
|
|
|
|
{
|
|
|
|
|
currentMatrix--;
|
|
|
|
|
matrixLevel--;
|
|
|
|
|
MATRIX* m = &stack[matrixLevel];//$t7
|
2020-05-22 12:26:19 +02:00
|
|
|
|
|
|
|
|
|
gte_SetRotMatrix(m);
|
|
|
|
|
gte_SetTransMatrix(m);
|
2020-04-23 09:25:56 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("Error: Can't pop matrix,stack is empty!\n");
|
|
|
|
|
}
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long RotTransPers(struct SVECTOR* v0, long* sxy, long* p, long* flag)
|
|
|
|
|
{
|
2020-05-22 12:26:19 +02:00
|
|
|
|
gte_ldv0(v0);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
docop2(0x180001);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-05-22 12:26:19 +02:00
|
|
|
|
gte_stsxy(sxy);
|
|
|
|
|
gte_stdp(p);
|
|
|
|
|
gte_stflg(flag);
|
|
|
|
|
|
|
|
|
|
int z;
|
|
|
|
|
gte_stsz(&z);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-05-22 12:26:19 +02:00
|
|
|
|
return z >> 2;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RotTrans(struct SVECTOR* v0, VECTOR* v1, long* flag)
|
|
|
|
|
{
|
2020-04-23 09:25:56 +02:00
|
|
|
|
UNIMPLEMENTED();
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NormalColorDpq(struct SVECTOR* v0, struct CVECTOR* v1, long p, struct CVECTOR* v2)
|
|
|
|
|
{
|
2020-04-23 09:25:56 +02:00
|
|
|
|
UNIMPLEMENTED();
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NormalColorCol(struct SVECTOR* v0, struct CVECTOR* v1, struct CVECTOR* v2)
|
|
|
|
|
{
|
2020-04-23 09:25:56 +02:00
|
|
|
|
UNIMPLEMENTED();
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long RotAverageNclip4(struct SVECTOR* v0, struct SVECTOR* v1, struct SVECTOR* v2, struct SVECTOR* v3, long* sxy0/*arg_10*/, long* sxy1/*arg_14*/, long* sxy2/*arg_18*/, long* sxy3/*arg_1C*/, long* p/*arg_20*/, long* otz/*arg_24*/, long* flag/*arg_28*/)
|
|
|
|
|
{
|
2020-05-22 12:26:19 +02:00
|
|
|
|
gte_ldv3(v0,v1,v2);
|
2020-04-23 09:25:56 +02:00
|
|
|
|
docop2(0x280030);
|
2020-05-22 12:26:19 +02:00
|
|
|
|
gte_stflg(flag);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
docop2(0x1400006);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-05-22 12:26:19 +02:00
|
|
|
|
int opz;
|
|
|
|
|
gte_stopz(&opz);
|
|
|
|
|
|
|
|
|
|
if (opz > 0)
|
2020-04-23 09:25:56 +02:00
|
|
|
|
{
|
2020-05-22 12:26:19 +02:00
|
|
|
|
gte_stsxy3(sxy0, sxy1, sxy2);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-05-22 12:26:19 +02:00
|
|
|
|
gte_ldv0(v3);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
docop2(0x180001);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-05-22 12:26:19 +02:00
|
|
|
|
gte_stsxy(sxy3);
|
|
|
|
|
gte_stdp(p);
|
|
|
|
|
gte_stflg(flag);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
|
docop2(0x168002E);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
2020-05-22 12:26:19 +02:00
|
|
|
|
gte_stotz(otz);
|
2020-04-23 09:25:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-22 12:26:19 +02:00
|
|
|
|
return opz;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-15 14:27:12 +02:00
|
|
|
|
// TODO: to INLINE_C EMULATOR macros
|
|
|
|
|
|
2020-03-31 18:55:57 +02:00
|
|
|
|
MATRIX* MulMatrix0(MATRIX* m0, MATRIX* m1, MATRIX* m2)
|
|
|
|
|
{
|
2020-05-20 09:17:57 +02:00
|
|
|
|
#if 0
|
2020-04-19 04:16:03 +02:00
|
|
|
|
gte_MulMatrix0(m0, m1, m2);
|
2020-05-20 09:17:57 +02:00
|
|
|
|
#else
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD>ł<EFBFBD>m0==m2<6D>̎<EFBFBD><CC8E><EFBFBD><EFBFBD>o<EFBFBD>C */
|
|
|
|
|
int vx, vy, vz;
|
|
|
|
|
MATRIX tmp;
|
|
|
|
|
/* <20>̂<EFBFBD>m0<6D><30>tmp<6D>ɃR<C983>s<EFBFBD>[ */
|
|
|
|
|
if (m0 == m2) {
|
|
|
|
|
tmp = *m0; m0 = &tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vx = m1->m[0][0];
|
|
|
|
|
vy = m1->m[1][0];
|
|
|
|
|
vz = m1->m[2][0];
|
2020-05-20 15:48:19 +02:00
|
|
|
|
m2->m[0][0] = FIXED(m0->m[0][0] * vx + m0->m[0][1] * vy + m0->m[0][2] * vz);
|
|
|
|
|
m2->m[1][0] = FIXED(m0->m[1][0] * vx + m0->m[1][1] * vy + m0->m[1][2] * vz);
|
|
|
|
|
m2->m[2][0] = FIXED(m0->m[2][0] * vx + m0->m[2][1] * vy + m0->m[2][2] * vz);
|
2020-05-20 09:17:57 +02:00
|
|
|
|
vx = m1->m[0][1];
|
|
|
|
|
vy = m1->m[1][1];
|
|
|
|
|
vz = m1->m[2][1];
|
2020-05-20 15:48:19 +02:00
|
|
|
|
m2->m[0][1] = FIXED(m0->m[0][0] * vx + m0->m[0][1] * vy + m0->m[0][2] * vz);
|
|
|
|
|
m2->m[1][1] = FIXED(m0->m[1][0] * vx + m0->m[1][1] * vy + m0->m[1][2] * vz);
|
|
|
|
|
m2->m[2][1] = FIXED(m0->m[2][0] * vx + m0->m[2][1] * vy + m0->m[2][2] * vz);
|
2020-05-20 09:17:57 +02:00
|
|
|
|
vx = m1->m[0][2];
|
|
|
|
|
vy = m1->m[1][2];
|
|
|
|
|
vz = m1->m[2][2];
|
2020-05-20 15:48:19 +02:00
|
|
|
|
m2->m[0][2] = FIXED(m0->m[0][0] * vx + m0->m[0][1] * vy + m0->m[0][2] * vz);
|
|
|
|
|
m2->m[1][2] = FIXED(m0->m[1][0] * vx + m0->m[1][1] * vy + m0->m[1][2] * vz);
|
|
|
|
|
m2->m[2][2] = FIXED(m0->m[2][0] * vx + m0->m[2][1] * vy + m0->m[2][2] * vz);
|
2020-05-20 09:17:57 +02:00
|
|
|
|
#endif
|
2020-04-15 14:27:12 +02:00
|
|
|
|
|
|
|
|
|
return m2;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MATRIX* MulMatrix(MATRIX* m0, MATRIX* m1)
|
|
|
|
|
{
|
2020-04-23 09:25:56 +02:00
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
|
return NULL;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MATRIX* MulMatrix2(MATRIX* m0, MATRIX* m1)
|
|
|
|
|
{
|
2020-04-23 09:25:56 +02:00
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
|
return NULL;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetBackColor(long rbk, long gbk, long bbk)
|
|
|
|
|
{
|
2020-04-23 09:25:56 +02:00
|
|
|
|
UNIMPLEMENTED();
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetFarColor(long rfc, long gfc, long bfc)
|
|
|
|
|
{
|
2020-04-23 09:25:56 +02:00
|
|
|
|
UNIMPLEMENTED();
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-18 08:34:10 +02:00
|
|
|
|
#define APPLYMATRIX(m,v0,v1) {\
|
|
|
|
|
int vx = v0->vx;\
|
|
|
|
|
int vy = v0->vy;\
|
|
|
|
|
int vz = v0->vz;\
|
2020-05-20 15:48:19 +02:00
|
|
|
|
v1->vx = FIXED(m->m[0][0]*vx + m->m[0][1]*vy + m->m[0][2]*vz );\
|
|
|
|
|
v1->vy = FIXED(m->m[1][0]*vx + m->m[1][1]*vy + m->m[1][2]*vz );\
|
|
|
|
|
v1->vz = FIXED(m->m[2][0]*vx + m->m[2][1]*vy + m->m[2][2]*vz );\
|
2020-05-18 08:34:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VECTOR *ApplyMatrix(MATRIX *m, SVECTOR *v0, VECTOR *v1)
|
2020-03-31 18:55:57 +02:00
|
|
|
|
{
|
2020-05-18 08:34:10 +02:00
|
|
|
|
APPLYMATRIX(m, v0, v1)
|
|
|
|
|
return v1;
|
|
|
|
|
}
|
2020-04-23 09:25:56 +02:00
|
|
|
|
|
2020-05-18 08:34:10 +02:00
|
|
|
|
VECTOR *ApplyRotMatrix(SVECTOR *v0, VECTOR *v1)
|
|
|
|
|
{
|
|
|
|
|
MATRIX temp;
|
|
|
|
|
gte_ReadRotMatrix(&temp);
|
2020-04-23 09:25:56 +02:00
|
|
|
|
|
2020-05-18 08:34:10 +02:00
|
|
|
|
MATRIX* m = &temp;
|
2020-04-23 09:25:56 +02:00
|
|
|
|
|
2020-05-18 08:34:10 +02:00
|
|
|
|
APPLYMATRIX(m, v0, v1);
|
|
|
|
|
return v1;
|
|
|
|
|
}
|
2020-04-23 09:25:56 +02:00
|
|
|
|
|
2020-05-18 08:34:10 +02:00
|
|
|
|
VECTOR *ApplyRotMatrixLV(VECTOR *v0, VECTOR *v1)
|
|
|
|
|
{
|
|
|
|
|
MATRIX temp;
|
|
|
|
|
gte_ReadRotMatrix(&temp);
|
2020-04-23 09:25:56 +02:00
|
|
|
|
|
2020-05-18 08:34:10 +02:00
|
|
|
|
MATRIX* m = &temp;
|
|
|
|
|
|
|
|
|
|
APPLYMATRIX(m, v0, v1);
|
|
|
|
|
return v1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SVECTOR *ApplyMatrixSV(MATRIX *m, SVECTOR *v0, SVECTOR *v1)
|
|
|
|
|
{
|
|
|
|
|
APPLYMATRIX(m, v0, v1)
|
|
|
|
|
return v1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VECTOR *ApplyMatrixLV(MATRIX *m, VECTOR *v0, VECTOR *v1)
|
|
|
|
|
{
|
|
|
|
|
APPLYMATRIX(m, v0, v1)
|
|
|
|
|
return v1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MATRIX* RotMatrix(struct SVECTOR* r, MATRIX* m)
|
|
|
|
|
{
|
|
|
|
|
int c0,c1,c2;
|
|
|
|
|
int s0,s1,s2;
|
|
|
|
|
int s2p0,s2m0,c2p0,c2m0;
|
|
|
|
|
int s2c0,s2s0,c2c0,c2s0;
|
|
|
|
|
|
|
|
|
|
c0=rcos(r->vx);
|
|
|
|
|
c1=rcos(r->vy);
|
|
|
|
|
c2=rcos(r->vz);
|
|
|
|
|
s0=rsin(r->vx);
|
|
|
|
|
s1=rsin(r->vy);
|
|
|
|
|
s2=rsin(r->vz);
|
|
|
|
|
s2p0=rsin( r->vz + r->vx );
|
|
|
|
|
s2m0=rsin( r->vz - r->vx );
|
|
|
|
|
c2p0=rcos( r->vz + r->vx );
|
|
|
|
|
c2m0=rcos( r->vz - r->vx );
|
|
|
|
|
s2c0 = (s2p0+s2m0)/2;
|
|
|
|
|
c2s0 = (s2p0-s2m0)/2;
|
|
|
|
|
s2s0 = (c2m0-c2p0)/2;
|
|
|
|
|
c2c0 = (c2m0+c2p0)/2;
|
|
|
|
|
|
2020-05-20 15:48:19 +02:00
|
|
|
|
m->m[0][0]= FIXED(c2*c1);
|
|
|
|
|
m->m[1][0]= s2c0 + FIXED(c2s0*s1);
|
|
|
|
|
m->m[2][0]= s2s0 - FIXED(c2c0*s1);
|
|
|
|
|
m->m[0][1]= -FIXED(s2*c1);
|
|
|
|
|
m->m[1][1]= c2c0 - FIXED(s2s0*s1);
|
|
|
|
|
m->m[2][1]= c2s0 + FIXED(s2c0*s1);
|
2020-05-18 08:34:10 +02:00
|
|
|
|
m->m[0][2]= s1;
|
2020-05-20 15:48:19 +02:00
|
|
|
|
m->m[1][2]= -FIXED(c1*s0);
|
|
|
|
|
m->m[2][2]= FIXED(c1*c0);
|
2020-05-18 08:34:10 +02:00
|
|
|
|
|
|
|
|
|
return m;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 20:18:21 +02:00
|
|
|
|
MATRIX* RotMatrixYXZ(struct SVECTOR* r, MATRIX* m)
|
|
|
|
|
{
|
|
|
|
|
int iVar1;
|
|
|
|
|
int iVar2;
|
|
|
|
|
short sVar3;
|
|
|
|
|
uint uVar4;
|
|
|
|
|
int iVar5;
|
|
|
|
|
int iVar6;
|
|
|
|
|
int iVar7;
|
|
|
|
|
int iVar8;
|
|
|
|
|
|
|
|
|
|
uVar4 = (r->vx);
|
|
|
|
|
|
|
|
|
|
if ((int)uVar4 < 0)
|
|
|
|
|
{
|
|
|
|
|
iVar6 = *(int *)(rcossin_tbl + (-uVar4 & 0xfff) * 2);
|
|
|
|
|
sVar3 = (short)iVar6;
|
|
|
|
|
iVar5 = -(int)sVar3;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
iVar6 = *(int *)(rcossin_tbl + (uVar4 & 0xfff) * 2);
|
|
|
|
|
iVar5 = (int)(short)iVar6;
|
|
|
|
|
sVar3 = -(short)iVar6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iVar6 = iVar6 >> 0x10;
|
|
|
|
|
uVar4 = (r->vy);
|
|
|
|
|
|
|
|
|
|
if ((int)uVar4 < 0)
|
|
|
|
|
{
|
|
|
|
|
iVar7 = *(int *)(rcossin_tbl + (-uVar4 & 0xfff) * 2);
|
|
|
|
|
iVar1 = -(int)(short)iVar7;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
iVar7 = *(int *)(rcossin_tbl + (uVar4 & 0xfff) * 2);
|
|
|
|
|
iVar1 = (int)(short)iVar7;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iVar7 = iVar7 >> 0x10;
|
|
|
|
|
uVar4 = (r->vz);
|
2020-05-20 15:48:19 +02:00
|
|
|
|
|
2020-04-16 20:18:21 +02:00
|
|
|
|
m->m[1][2] = sVar3;
|
2020-05-20 15:48:19 +02:00
|
|
|
|
m->m[0][2] = FIXED(iVar1 * iVar6);
|
|
|
|
|
sVar3 = FIXED(iVar7 * iVar6);
|
2020-04-16 20:18:21 +02:00
|
|
|
|
|
|
|
|
|
if ((int)uVar4 < 0)
|
|
|
|
|
{
|
|
|
|
|
m->m[2][2] = sVar3;
|
|
|
|
|
iVar8 = *(int *)(rcossin_tbl + (-uVar4 & 0xfff) * 2);
|
|
|
|
|
iVar2 = -(int)(short)iVar8;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m->m[2][2] = sVar3;
|
|
|
|
|
iVar8 = *(int *)(rcossin_tbl + (uVar4 & 0xfff) * 2);
|
|
|
|
|
iVar2 = (int)(short)iVar8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iVar8 = iVar8 >> 0x10;
|
2020-05-20 15:48:19 +02:00
|
|
|
|
|
|
|
|
|
m->m[1][0] = FIXED(iVar2 * iVar6);
|
|
|
|
|
m->m[1][1] = FIXED(iVar8 * iVar6);
|
|
|
|
|
iVar6 = FIXED(iVar1 * iVar5);
|
|
|
|
|
m->m[0][0] = FIXED(iVar7 * iVar8) + FIXED(iVar6 * iVar2);
|
|
|
|
|
m->m[0][1] = FIXED(iVar6 * iVar8) - FIXED(iVar7 * iVar2);
|
|
|
|
|
iVar5 = FIXED(iVar7 * iVar5);
|
|
|
|
|
m->m[2][1] = FIXED(iVar1 * iVar2) + FIXED(iVar5 * iVar8);
|
|
|
|
|
m->m[2][0] = FIXED(iVar5 * iVar2) - FIXED(iVar1 * iVar8);
|
2020-04-16 20:18:21 +02:00
|
|
|
|
|
|
|
|
|
return m;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-17 00:53:42 +02:00
|
|
|
|
MATRIX* RotMatrixX(long r, MATRIX *m)
|
|
|
|
|
{
|
2020-05-20 09:17:57 +02:00
|
|
|
|
int s0 = rsin(r);
|
|
|
|
|
int c0 = rcos(r);
|
|
|
|
|
int t1, t2;
|
|
|
|
|
t1 = m->m[1][0];
|
|
|
|
|
t2 = m->m[2][0];
|
2020-05-20 15:48:19 +02:00
|
|
|
|
m->m[1][0] = FIXED(t1*c0 - t2 * s0);
|
|
|
|
|
m->m[2][0] = FIXED(t1*s0 + t2 * c0);
|
2020-05-20 09:17:57 +02:00
|
|
|
|
t1 = m->m[1][1];
|
|
|
|
|
t2 = m->m[2][1];
|
2020-05-20 15:48:19 +02:00
|
|
|
|
m->m[1][1] = FIXED(t1*c0 - t2 * s0);
|
|
|
|
|
m->m[2][1] = FIXED(t1*s0 + t2 * c0);
|
2020-05-20 09:17:57 +02:00
|
|
|
|
t1 = m->m[1][2];
|
|
|
|
|
t2 = m->m[2][2];
|
2020-05-20 15:48:19 +02:00
|
|
|
|
m->m[1][2] = FIXED(t1*c0 - t2 * s0);
|
|
|
|
|
m->m[2][2] = FIXED(t1*s0 + t2 * c0);
|
2020-05-22 12:26:19 +02:00
|
|
|
|
|
2020-04-17 00:53:42 +02:00
|
|
|
|
return m;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 20:18:21 +02:00
|
|
|
|
MATRIX* RotMatrixY(long r, MATRIX *m)
|
|
|
|
|
{
|
2020-05-20 09:17:57 +02:00
|
|
|
|
int s0 = rsin(r);
|
|
|
|
|
int c0 = rcos(r);
|
|
|
|
|
int t1, t2;
|
|
|
|
|
t1 = m->m[0][0];
|
|
|
|
|
t2 = m->m[2][0];
|
2020-05-20 15:48:19 +02:00
|
|
|
|
m->m[0][0] = FIXED(t1*c0 + t2 * s0);
|
|
|
|
|
m->m[2][0] = FIXED(-t1 * s0 + t2 * c0);
|
2020-05-20 09:17:57 +02:00
|
|
|
|
t1 = m->m[0][1];
|
|
|
|
|
t2 = m->m[2][1];
|
2020-05-20 15:48:19 +02:00
|
|
|
|
m->m[0][1] = FIXED(t1*c0 + t2 * s0);
|
|
|
|
|
m->m[2][1] = FIXED(-t1 * s0 + t2 * c0);
|
2020-05-20 09:17:57 +02:00
|
|
|
|
t1 = m->m[0][2];
|
|
|
|
|
t2 = m->m[2][2];
|
2020-05-20 15:48:19 +02:00
|
|
|
|
m->m[0][2] = FIXED(t1*c0 + t2 * s0);
|
|
|
|
|
m->m[2][2] = FIXED(-t1 * s0 + t2 * c0);
|
2020-05-22 12:26:19 +02:00
|
|
|
|
|
2020-04-17 00:53:42 +02:00
|
|
|
|
return m;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MATRIX* RotMatrixZ(long r, MATRIX *m)
|
|
|
|
|
{
|
2020-05-20 09:17:57 +02:00
|
|
|
|
int s0 = rsin(r);
|
|
|
|
|
int c0 = rcos(r);
|
|
|
|
|
int t1,t2;
|
|
|
|
|
t1 = m->m[0][0];
|
|
|
|
|
t2 = m->m[1][0];
|
2020-05-20 15:48:19 +02:00
|
|
|
|
m->m[0][0] = FIXED(t1*c0 - t2*s0);
|
|
|
|
|
m->m[1][0] = FIXED(t1*s0 + t2*c0);
|
2020-05-20 09:17:57 +02:00
|
|
|
|
t1 = m->m[0][1];
|
|
|
|
|
t2 = m->m[1][1];
|
2020-05-20 15:48:19 +02:00
|
|
|
|
m->m[0][1] = FIXED(t1*c0 - t2*s0);
|
|
|
|
|
m->m[1][1] = FIXED(t1*s0 + t2*c0);
|
2020-05-20 09:17:57 +02:00
|
|
|
|
t1 = m->m[0][2];
|
|
|
|
|
t2 = m->m[1][2];
|
2020-05-20 15:48:19 +02:00
|
|
|
|
m->m[0][2] = FIXED(t1*c0 - t2*s0);
|
|
|
|
|
m->m[1][2] = FIXED(t1*s0 + t2*c0);
|
2020-05-22 12:26:19 +02:00
|
|
|
|
|
2020-04-16 20:18:21 +02:00
|
|
|
|
return m;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-31 18:55:57 +02:00
|
|
|
|
MATRIX* TransMatrix(MATRIX* m, VECTOR* v)
|
|
|
|
|
{
|
2020-05-18 08:34:10 +02:00
|
|
|
|
m->t[0] = v->vx;
|
|
|
|
|
m->t[1] = v->vy;
|
|
|
|
|
m->t[2] = v->vz;
|
2020-04-23 09:25:56 +02:00
|
|
|
|
return m;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MATRIX* ScaleMatrix(MATRIX* m, VECTOR* v)
|
|
|
|
|
{
|
2020-05-20 15:48:19 +02:00
|
|
|
|
m->m[0][0] = FIXED(m->m[0][0] * v->vx);
|
|
|
|
|
m->m[0][1] = FIXED(m->m[0][1] * v->vx);
|
|
|
|
|
m->m[0][2] = FIXED(m->m[0][2] * v->vx);
|
|
|
|
|
m->m[1][0] = FIXED(m->m[1][0] * v->vy);
|
|
|
|
|
m->m[1][1] = FIXED(m->m[1][1] * v->vy);
|
|
|
|
|
m->m[1][2] = FIXED(m->m[1][2] * v->vy);
|
|
|
|
|
m->m[2][0] = FIXED(m->m[2][0] * v->vz);
|
|
|
|
|
m->m[2][1] = FIXED(m->m[2][1] * v->vz);
|
|
|
|
|
m->m[2][2] = FIXED(m->m[2][2] * v->vz);
|
2020-05-18 08:34:10 +02:00
|
|
|
|
return m;
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetDQA(int iDQA)
|
|
|
|
|
{
|
2020-05-22 12:26:19 +02:00
|
|
|
|
CTC2(*(uint*)&iDQA, 27);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetDQB(int iDQB)
|
|
|
|
|
{
|
2020-05-22 12:26:19 +02:00
|
|
|
|
CTC2(*(uint*)&iDQB, 28);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetFogNear(long a, long h)
|
|
|
|
|
{
|
2020-04-23 09:25:56 +02:00
|
|
|
|
//Error division by 0
|
|
|
|
|
assert(h != 0);
|
|
|
|
|
int depthQ = -(((a << 2) + a) << 6);
|
|
|
|
|
assert(h != -1 && depthQ != 0x8000);
|
|
|
|
|
SetDQA(depthQ / h);
|
|
|
|
|
SetDQB(20971520);
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-20 05:01:22 +02:00
|
|
|
|
int isin(int x)
|
2020-04-15 14:27:12 +02:00
|
|
|
|
{
|
2020-04-20 05:01:22 +02:00
|
|
|
|
|
|
|
|
|
#define qN 10
|
|
|
|
|
#define qA 12
|
|
|
|
|
#define B 19900
|
|
|
|
|
#define C 3516
|
|
|
|
|
|
|
|
|
|
int c, x2, y;
|
|
|
|
|
|
|
|
|
|
c = x << (30 - qN); // Semi-circle info into carry.
|
|
|
|
|
x -= 1 << qN; // sine -> cosine calc
|
|
|
|
|
|
|
|
|
|
x = x << (31 - qN); // Mask with PI
|
|
|
|
|
x = x >> (31 - qN); // Note: SIGNED shift! (to qN)
|
|
|
|
|
|
|
|
|
|
x = x * x >> (2 * qN - 14); // x=x^2 To Q14
|
|
|
|
|
|
|
|
|
|
y = B - (x*C >> 14); // B - x^2*C
|
|
|
|
|
y = (1 << qA) - (x*y >> 16); // A - x^2*(B-x^2*C)
|
|
|
|
|
|
|
|
|
|
return c >= 0 ? y : -y;
|
2020-04-15 14:27:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-31 18:55:57 +02:00
|
|
|
|
int rsin(int a)
|
|
|
|
|
{
|
2020-05-20 09:17:57 +02:00
|
|
|
|
#if 0
|
2020-04-20 05:01:22 +02:00
|
|
|
|
return isin(a);
|
2020-05-20 09:17:57 +02:00
|
|
|
|
#else
|
|
|
|
|
if (a < 0)
|
|
|
|
|
return -rcossin_tbl[(-a & 0xfffU) * 2];
|
|
|
|
|
|
|
|
|
|
return rcossin_tbl[(a & 0xfffU) * 2];
|
|
|
|
|
#endif
|
2020-04-15 14:27:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rcos(int a)
|
|
|
|
|
{
|
2020-05-20 09:17:57 +02:00
|
|
|
|
#if 0
|
2020-04-20 05:01:22 +02:00
|
|
|
|
return isin(a + 1024);
|
2020-05-20 09:17:57 +02:00
|
|
|
|
#else
|
|
|
|
|
if (a < 0)
|
|
|
|
|
return rcossin_tbl[(-a & 0xfffU) * 2 + 1];
|
|
|
|
|
|
|
|
|
|
return rcossin_tbl[(a & 0xfffU) * 2 + 1];
|
|
|
|
|
#endif
|
2020-03-31 18:55:57 +02:00
|
|
|
|
}
|
2020-04-16 21:48:28 +02:00
|
|
|
|
|
|
|
|
|
long ratan2(long y, long x)
|
|
|
|
|
{
|
2020-05-20 09:17:57 +02:00
|
|
|
|
#if 0 // don't use it
|
2020-05-06 06:02:09 +02:00
|
|
|
|
const double ONE_BY_2048 = 1.0 / 2048;
|
|
|
|
|
const double CONV = 2048.0 / M_PI;
|
|
|
|
|
|
|
|
|
|
float real = atan2(double(y) * ONE_BY_2048, double(x) * ONE_BY_2048);
|
|
|
|
|
return real * CONV;
|
|
|
|
|
#else
|
2020-05-20 09:17:57 +02:00
|
|
|
|
long v;
|
|
|
|
|
ulong ang;
|
|
|
|
|
|
|
|
|
|
bool xlt0 = x < 0;
|
|
|
|
|
bool ylt0 = y < 0;
|
2020-05-06 06:02:09 +02:00
|
|
|
|
|
2020-05-20 09:17:57 +02:00
|
|
|
|
if (x == 0 && y == 0)
|
|
|
|
|
return 0;
|
2020-04-16 21:48:28 +02:00
|
|
|
|
|
2020-05-06 06:02:09 +02:00
|
|
|
|
if (x < 0)
|
2020-04-16 21:48:28 +02:00
|
|
|
|
x = -x;
|
2020-05-06 06:02:09 +02:00
|
|
|
|
|
|
|
|
|
if (y < 0)
|
2020-04-16 21:48:28 +02:00
|
|
|
|
y = -y;
|
|
|
|
|
|
2020-05-20 09:17:57 +02:00
|
|
|
|
if (y < x)
|
|
|
|
|
{
|
|
|
|
|
if (((ulong)y & 0x7fe00000U) == 0)
|
|
|
|
|
ang = (y * 1024) / x;
|
|
|
|
|
else
|
|
|
|
|
ang = y / (x / 1024);
|
2020-05-06 06:02:09 +02:00
|
|
|
|
|
2020-05-20 09:17:57 +02:00
|
|
|
|
v = ratan_tbl[ang];
|
|
|
|
|
}
|
|
|
|
|
else
|
2020-04-16 21:48:28 +02:00
|
|
|
|
{
|
2020-05-20 09:17:57 +02:00
|
|
|
|
if(((ulong)x & 0x7fe00000U) == 0)
|
|
|
|
|
ang = (x * 1024) / y;
|
2020-04-16 21:48:28 +02:00
|
|
|
|
else
|
2020-05-20 09:17:57 +02:00
|
|
|
|
ang = x / (y / 1024);
|
|
|
|
|
|
|
|
|
|
v = 1024 - ratan_tbl[ang];
|
2020-04-16 21:48:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-20 09:17:57 +02:00
|
|
|
|
if (xlt0)
|
|
|
|
|
v = 2048 - v;
|
|
|
|
|
|
|
|
|
|
if (ylt0)
|
|
|
|
|
v = -v;
|
2020-05-06 06:02:09 +02:00
|
|
|
|
|
2020-05-20 09:17:57 +02:00
|
|
|
|
return v;
|
2020-05-06 06:02:09 +02:00
|
|
|
|
#endif
|
2020-04-26 09:04:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long SquareRoot0(long a)
|
|
|
|
|
{
|
2020-05-09 06:30:46 +02:00
|
|
|
|
#if 1
|
|
|
|
|
return sqrtl(a);
|
|
|
|
|
#else
|
|
|
|
|
// THIS SQUARE ROOT SEEMS TO BE BUGGED
|
2020-04-26 09:43:58 +02:00
|
|
|
|
int v0, v1, t0, t1, t2, t3, t4;
|
2020-04-26 09:04:31 +02:00
|
|
|
|
|
2020-04-26 09:43:58 +02:00
|
|
|
|
v0 = gte_leadingzerocount(a);
|
2020-04-26 09:04:31 +02:00
|
|
|
|
|
2020-04-26 09:43:58 +02:00
|
|
|
|
if (v0 != 32)
|
2020-04-26 09:04:31 +02:00
|
|
|
|
{
|
2020-04-26 09:43:58 +02:00
|
|
|
|
t0 = v0 & 1;
|
|
|
|
|
v1 = -2;
|
|
|
|
|
t2 = v0 & v1;
|
2020-04-26 09:04:31 +02:00
|
|
|
|
|
2020-04-26 09:43:58 +02:00
|
|
|
|
t1 = 31 - t2;
|
|
|
|
|
t1 -= t2;
|
|
|
|
|
t1 >>= 1;
|
|
|
|
|
|
|
|
|
|
t3 = t2 - 24;
|
|
|
|
|
|
|
|
|
|
if (t3 < 0)
|
|
|
|
|
{
|
|
|
|
|
t3 = 24 - t2;
|
|
|
|
|
t4 = a >> t3;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
t4 = a << t3;
|
|
|
|
|
}
|
2020-04-26 09:04:31 +02:00
|
|
|
|
|
2020-04-26 09:43:58 +02:00
|
|
|
|
return (SQRT[t4 - 64] << t1) >> 12;
|
2020-04-26 09:04:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
2020-05-09 06:30:46 +02:00
|
|
|
|
#endif
|
2020-04-16 21:48:28 +02:00
|
|
|
|
}
|