Port perspective.c from sm64

This commit is contained in:
rozlette
2020-01-17 01:04:40 -06:00
parent e74e227113
commit 7f4a682072
5 changed files with 57 additions and 18 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ build/src/boot_O2_g3_trapuv/%: OPTIMIZATION := -O2 -g3
build/src/code/%: CFLAGS := $(CFLAGS) -Wab,-r4300_mul
build/src/actors/%: CFLAGS := $(CFLAGS) -Wab,-r4300_mul
build/src/boot_O2_g3_trapuv/%: CFLAGS := $(CFLAGS) -trapuv
test.txt: OPTIMIZATION := -O2 -g3
test.txt: OPTIMIZATION := -O2
test.txt: CC := $(QEMU_IRIX) -L $(IRIX_71_ROOT) $(IRIX_71_ROOT)/usr/bin/cc
test.txt: CFLAGS := $(CFLAGS) -Wab,-r4300_mul
+6 -9
View File
@@ -313,7 +313,7 @@ void func_8008A660(void); // func_8008A660
void osInitialize(void); // func_8008A6FC
void func_8008A9A8(void); // func_8008A9A8
void* osViGetNextFramebuffer(void); // func_8008AA10
void guPerspectiveF(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); // func_8008AA50
void guPerspectiveF(float mf[4][4], u16* perspNorm, float fovy, float aspect, float near, float far, float scale); // func_8008AA50
void guPerspective(Mtx* m, u16* perspNorm, float fovy, float aspect, float near, float far, float scale); // func_8008AC80
s32 __osSpRawStartDma(s32 direction, u32 devAddr, void* dramAddr, u32 size); // func_8008ACE0
s32 __osSiRawStartDma(s32 direction, void* dramAddr); // func_8008AD70
@@ -327,11 +327,11 @@ void func_8008B044(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_
void func_8008B3C0(void); // func_8008B3C0
void func_8008B490(void); // func_8008B490
void func_8008B554(void); // func_8008B554
void guMtxIdentF(f32* mf); // func_8008B600
void guMtxIdentF(float mf[4][4]); // func_8008B600
void osViSetMode(OSViMode* modep); // func_8008B650
void __osGetConfig(void); // func_8008B6B0
void __osSetConfig(void); // func_8008B6C0
void guLookAtF(float* mf, float xEye, float yEye, float zEye, float xAt, float yAt, float zAt, float xUp, float yUp, float zUp); // func_8008B6D0
void guLookAtF(float mf[4][4], float xEye, float yEye, float zEye, float xAt, float yAt, float zAt, float xUp, float yUp, float zUp); // func_8008B6D0
void guLookAt(Mtx* m, float xEye, float yEye, float zEye, float xAt, float yAt, float zAt, float xUp, float yUp, float zUp); // func_8008B974
void func_8008B9F0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); // func_8008B9F0
void func_8008BD24(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE1 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); // func_8008BD24
@@ -359,7 +359,7 @@ f32 sqrtf(f32 __x); // func_8008D700
void func_8008D710(void); // func_8008D710
s32 osContStartQuery(OSMesgQueue* mq); // func_8008D730
void osContGetQuery(OSContStatus* data); // func_8008D7AC
void guLookAtHiliteF(f32* mf, LookAt* l, Hilite* h, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp, f32 xl1, f32 yl1, f32 zl1, f32 xl2, f32 yl2, f32 zl2, s32 twidth, s32 theight); // func_8008D7D0
void guLookAtHiliteF(float mf[4][4], UNK_PTR l, int* h, float xEye, float yEye, float zEye, float xAt, float yAt, float zAt, float xUp, float yUp, float zUp, float xl1, float yl1, float zl1, float xl2, float yl2, float zl2, int twidth, int theight); // func_8008D7D0
void guLookAtHilite(Mtx* m, LookAt* l, Hilite* h, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp, f32 xl1, f32 yl1, f32 zl1, f32 xl2, f32 yl2, f32 zl2, s32 twidth, s32 theight); // func_8008DF90
int _Printf(printf_func pfn, void* arg, char* fmt, char* ap); // func_8008E050
void func_8008E698(void); // func_8008E698
@@ -393,7 +393,7 @@ void func_800900C0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_
void osSpTaskYielded(void); // func_800902A0
s32 memcmp(void* __s1, void* __s2, size_t __n); // func_80090300
OSTime osGetTime(void); // func_80090420
void guRotateF(float* mf, float a, float x, float y, float z); // func_800904B0
void guRotateF(float mf[4][4], float a, float x, float y, float z); // func_800904B0
void guRotate(Mtx* m, float a, float x, float y, float z); // func_80090634
void __osSetGlobalIntMask(void); // func_80090680
void func_800906D0(void); // func_800906D0
@@ -468,7 +468,7 @@ __OSViContext* __osViGetCurrentContext(void); // func_800955B0
void osWritebackDCacheAll(void); // func_800955C0
OSThread* __osGetCurrFaultedThread(void); // func_800955F0
void func_80095600(void); // func_80095600
void guMtxF2L(void); // func_80095740
void guMtxF2L(float mf[4][4], Mtx* m); // func_80095740
void osStartThread(OSThread* param_1); // func_800957B0
void osViSetYScale(f32 param_1); // func_80095900
void osViSetXScale(f32 xscale); // func_80095950
@@ -486,7 +486,6 @@ void func_80096410(void); // func_80096410
void func_800964D0(void); // func_800964D0
s32 __osSpSetPc(u32 data); // func_80096510
void func_80096540(void); // func_80096540
// UNK_RET func_80096770(UNK_ARGS);
void func_800967A0(void); // func_800967A0
u32 __osGetWatchLo(void); // func_80096810
void __osSetWatchLo(u32 value); // func_80096820
@@ -3738,8 +3737,6 @@ void func_8019AB40(void); // func_8019AB40
void func_8019AC10(void); // func_8019AC10
void func_8019ACEC(void); // func_8019ACEC
void func_8019ADBC(void); // func_8019ADBC
// UNK_RET func_8019AE40(UNK_ARGS);
// UNK_RET func_8019AEC0(UNK_ARGS);
void func_8019AF00(void); // func_8019AF00
void func_8019AF58(void); // func_8019AF58
void func_8019AFE8(void); // func_8019AFE8
+2 -2
View File
@@ -59,7 +59,7 @@ SECTIONS
build/asm/writebackdcache.o(.text)
build/asm/initialize.o(.text)
build/asm/vigetnextframebuf.o(.text)
build/asm/perspective.o(.text)
build/src/libultra/gu/perspective.o(.text)
build/src/libultra/io/sprawdma.o(.text)
build/asm/sirawdma.o(.text)
build/asm/boot_0x8008AE20.o(.text)
@@ -218,7 +218,7 @@ SECTIONS
build/asm/boot_rodata_setintmask.o(.text)
build/src/libultra/gu/sinf.o(.rodata)
build/asm/boot_rodata_exceptasm.o(.text)
build/asm/boot_rodata_perspective.o(.text)
build/src/libultra/gu/perspective.o(.rodata)
build/asm/boot_rodata_0x8008C260.o(.text)
build/asm/boot_rodata_lookathil.o(.text)
build/asm/boot_rodata_xprintf.o(.text)
+42
View File
@@ -0,0 +1,42 @@
#include <ultra64.h>
#include <global.h>
void guPerspectiveF(float mf[4][4], u16* perspNorm, float fovy, float aspect, float near, float far, float scale) {
float cot;
int i;
int j;
guMtxIdentF(mf);
fovy *= 3.1415926 / 180.0;
cot = __cosf(fovy / 2) / __sinf(fovy / 2);
mf[0][0] = cot / aspect;
mf[1][1] = cot;
mf[2][2] = (near + far) / (near - far);
mf[2][3] = -1;
mf[3][2] = 2 * near * far / (near - far);
mf[3][3] = 0.0f;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
mf[i][j] *= scale;
}
}
if (perspNorm != NULL) {
if (near + far <= 2.0) {
*perspNorm = 65535;
} else {
*perspNorm = (double) (1 << 17) / (near + far);
if (*perspNorm <= 0) {
*perspNorm = 1;
}
}
}
}
void guPerspective(Mtx* m, u16* perspNorm, float fovy, float aspect, float near, float far, float scale) {
float mf[4][4];
guPerspectiveF(mf, perspNorm, fovy, aspect, near, far, scale);
guMtxF2L(mf, m);
}
+6 -6
View File
@@ -310,7 +310,7 @@
0x8008A6FC:("osInitialize","void","void"),
0x8008A9A8:("func_8008A9A8","void","void"),
0x8008AA10:("osViGetNextFramebuffer","void*","void"),
0x8008AA50:("guPerspectiveF","void","UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7"),
0x8008AA50:("guPerspectiveF","void","float mf[4][4], u16* perspNorm, float fovy, float aspect, float near, float far, float scale"),
0x8008AC80:("guPerspective","void","Mtx* m, u16* perspNorm, float fovy, float aspect, float near, float far, float scale"),
0x8008ACE0:("__osSpRawStartDma","s32","s32 direction, u32 devAddr, void* dramAddr, u32 size"),
0x8008AD70:("__osSiRawStartDma","s32","s32 direction, void* dramAddr"),
@@ -324,11 +324,11 @@
0x8008B3C0:("func_8008B3C0","void","void"),
0x8008B490:("func_8008B490","void","void"),
0x8008B554:("func_8008B554","void","void"),
0x8008B600:("guMtxIdentF","void","f32* mf"),
0x8008B600:("guMtxIdentF","void","float mf[4][4]"),
0x8008B650:("osViSetMode","void","OSViMode* modep"),
0x8008B6B0:("__osGetConfig","void","void"),
0x8008B6C0:("__osSetConfig","void","void"),
0x8008B6D0:("guLookAtF","void","float* mf, float xEye, float yEye, float zEye, float xAt, float yAt, float zAt, float xUp, float yUp, float zUp"),
0x8008B6D0:("guLookAtF","void","float mf[4][4], float xEye, float yEye, float zEye, float xAt, float yAt, float zAt, float xUp, float yUp, float zUp"),
0x8008B974:("guLookAt","void","Mtx* m, float xEye, float yEye, float zEye, float xAt, float yAt, float zAt, float xUp, float yUp, float zUp"),
0x8008B9F0:("func_8008B9F0","void","UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7"),
0x8008BD24:("func_8008BD24","void","UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE1 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7"),
@@ -356,7 +356,7 @@
0x8008D710:("func_8008D710","void","void"),
0x8008D730:("osContStartQuery","s32","OSMesgQueue* mq"),
0x8008D7AC:("osContGetQuery","void","OSContStatus* data"),
0x8008D7D0:("guLookAtHiliteF","void","f32* mf, LookAt* l, Hilite* h, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp, f32 xl1, f32 yl1, f32 zl1, f32 xl2, f32 yl2, f32 zl2, s32 twidth, s32 theight"),
0x8008D7D0:("guLookAtHiliteF","void","float mf[4][4], UNK_PTR l, int* h, float xEye, float yEye, float zEye, float xAt, float yAt, float zAt, float xUp, float yUp, float zUp, float xl1, float yl1, float zl1, float xl2, float yl2, float zl2, int twidth, int theight"),
0x8008DF90:("guLookAtHilite","void","Mtx* m, LookAt* l, Hilite* h, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp, f32 xl1, f32 yl1, f32 zl1, f32 xl2, f32 yl2, f32 zl2, s32 twidth, s32 theight"),
0x8008E050:("_Printf","int","printf_func pfn, void* arg, char* fmt, char* ap"),
0x8008E698:("func_8008E698","void","void"),
@@ -390,7 +390,7 @@
0x800902A0:("osSpTaskYielded","void","void"),
0x80090300:("memcmp","s32","void* __s1, void* __s2, size_t __n"),
0x80090420:("osGetTime","OSTime","void"),
0x800904B0:("guRotateF","void","float* mf, float a, float x, float y, float z"),
0x800904B0:("guRotateF","void","float mf[4][4], float a, float x, float y, float z"),
0x80090634:("guRotate","void","Mtx* m, float a, float x, float y, float z"),
0x80090680:("__osSetGlobalIntMask","void","void"),
0x800906D0:("func_800906D0","void","void"),
@@ -465,7 +465,7 @@
0x800955C0:("osWritebackDCacheAll","void","void"),
0x800955F0:("__osGetCurrFaultedThread","OSThread*","void"),
0x80095600:("func_80095600","void","void"),
0x80095740:("guMtxF2L","void","void"),
0x80095740:("guMtxF2L","void","float mf[4][4], Mtx* m"),
0x800957B0:("osStartThread","void","OSThread* param_1"),
0x80095900:("osViSetYScale","void","f32 param_1"),
0x80095950:("osViSetXScale","void","f32 xscale"),