actually, just decomp cos/sin/mod

This commit is contained in:
Roshan Padaki 2023-09-24 04:13:21 -04:00
parent c8a7778224
commit 9ec6e1403f
No known key found for this signature in database
GPG Key ID: F359650FB0B5FB90
12 changed files with 101 additions and 188 deletions

View File

@ -1297,7 +1297,7 @@ _080467BE:
adds r0, r7
str r0, [r2, 0x4]
ldr r0, [sp, 0x10]
bl sub_8009C7C
bl sin_abs_4096
lsls r1, r0, 1
adds r1, r0
lsls r1, 2
@ -1809,7 +1809,7 @@ _08046BAA:
adds r0, r4, 0
bl IncreaseEntityPixelPos
mov r0, r10
bl sub_8009C7C
bl sin_abs_4096
add r2, sp, 0x20
adds r2, r5
lsls r1, r0, 1

View File

@ -755,7 +755,7 @@ _08047726:
adds r0, 0xFF
_08047732:
asrs r0, 8
bl sub_8009C7C
bl sin_abs_4096
ldr r2, [sp, 0x30]
adds r1, r0, 0
muls r1, r2

View File

@ -5299,7 +5299,7 @@ _080551F2:
adds r1, r5, 0
mov r2, r8
mov r3, r9
bl EncoreMoveAction
bl EncoreMoveAction
b _080554BA
_08055200:
adds r0, r7, 0
@ -8219,7 +8219,7 @@ _0805694A:
adds r0, 0xFF
_0805695E:
asrs r0, 8
bl sub_8009C7C
bl sin_abs_4096
ldr r2, [sp, 0x38]
adds r3, r0, 0
muls r3, r2

View File

@ -408,7 +408,7 @@ _0807D0DE:
ldr r0, [sp, 0x10]
str r4, [r0, 0x4]
mov r0, r8
bl sub_8009C7C
bl sin_abs_4096
lsls r1, r0, 1
adds r1, r0
lsls r1, 2
@ -1406,7 +1406,7 @@ _0807D8B0:
adds r0, r4, 0
bl IncreaseEntityPixelPos
mov r0, r10
bl sub_8009C7C
bl sin_abs_4096
add r2, sp, 0x20
adds r2, r5
lsls r1, r0, 1

View File

@ -2173,7 +2173,7 @@ _0807F794:
cmp r0, 0
beq _0807F7E6
ldr r0, [sp, 0x100]
bl sub_8009C7C
bl sin_abs_4096
lsls r0, 5
mov r3, r8
str r0, [r3, 0x1C]

View File

@ -5,177 +5,6 @@
.text
thumb_func_start FastMod3
@ return arg % 3
@ Has a lookup table up to 0x100
FastMod3:
push {lr}
adds r1, r0, 0
cmp r1, 0xFF
ble _08009C6C
movs r1, 0x3
bl __modsi3
b _08009C72
_08009C6C:
ldr r0, =gFastMod3Lookup
adds r0, r1, r0
ldrb r0, [r0]
_08009C72:
pop {r1}
bx r1
.pool
thumb_func_end FastMod3
thumb_func_start sub_8009C7C
sub_8009C7C:
push {lr}
adds r2, r0, 0
movs r3, 0xC0
lsls r3, 4
adds r1, r2, 0
ands r1, r3
movs r0, 0x80
lsls r0, 3
cmp r1, r0
beq _08009CB8
cmp r1, r0
bgt _08009C9A
cmp r1, 0
beq _08009CA8
b _08009CFC
_08009C9A:
movs r0, 0x80
lsls r0, 4
cmp r1, r0
beq _08009CD0
cmp r1, r3
beq _08009CE0
b _08009CFC
_08009CA8:
ldr r0, _08009CB0
ldr r1, _08009CB4
ands r1, r2
b _08009CBE
.align 2, 0
_08009CB0: .4byte gFastSinLookup
_08009CB4: .4byte 0x000003ff
_08009CB8:
ldr r0, _08009CC8
ldr r1, _08009CCC
bics r1, r2
_08009CBE:
lsls r1, 1
adds r1, r0
movs r2, 0
ldrsh r0, [r1, r2]
b _08009CFE
.align 2, 0
_08009CC8: .4byte gFastSinLookup
_08009CCC: .4byte 0x000003ff
_08009CD0:
ldr r0, _08009CD8
ldr r1, _08009CDC
ands r1, r2
b _08009CE6
.align 2, 0
_08009CD8: .4byte gFastSinLookup
_08009CDC: .4byte 0x000003ff
_08009CE0:
ldr r0, _08009CF4
ldr r1, _08009CF8
bics r1, r2
_08009CE6:
lsls r1, 1
adds r1, r0
movs r2, 0
ldrsh r0, [r1, r2]
negs r0, r0
b _08009CFE
.align 2, 0
_08009CF4: .4byte gFastSinLookup
_08009CF8: .4byte 0x000003ff
_08009CFC:
movs r0, 0
_08009CFE:
pop {r1}
bx r1
thumb_func_end sub_8009C7C
thumb_func_start sub_8009D04
sub_8009D04:
push {lr}
adds r2, r0, 0
movs r3, 0xC0
lsls r3, 4
adds r1, r2, 0
ands r1, r3
movs r0, 0x80
lsls r0, 3
cmp r1, r0
beq _08009D40
cmp r1, r0
bgt _08009D22
cmp r1, 0
beq _08009D30
b _08009D84
_08009D22:
movs r0, 0x80
lsls r0, 4
cmp r1, r0
beq _08009D50
cmp r1, r3
beq _08009D6C
b _08009D84
_08009D30:
ldr r0, _08009D38
ldr r1, _08009D3C
bics r1, r2
b _08009D72
.align 2, 0
_08009D38: .4byte gFastSinLookup
_08009D3C: .4byte 0x000003ff
_08009D40:
ldr r0, _08009D48
ldr r1, _08009D4C
ands r1, r2
b _08009D56
.align 2, 0
_08009D48: .4byte gFastSinLookup
_08009D4C: .4byte 0x000003ff
_08009D50:
ldr r0, _08009D64
ldr r1, _08009D68
bics r1, r2
_08009D56:
lsls r1, 1
adds r1, r0
movs r2, 0
ldrsh r0, [r1, r2]
negs r0, r0
b _08009D86
.align 2, 0
_08009D64: .4byte gFastSinLookup
_08009D68: .4byte 0x000003ff
_08009D6C:
ldr r0, _08009D7C
ldr r1, _08009D80
ands r1, r2
_08009D72:
lsls r1, 1
adds r1, r0
movs r2, 0
ldrsh r0, [r1, r2]
b _08009D86
.align 2, 0
_08009D7C: .4byte gFastSinLookup
_08009D80: .4byte 0x000003ff
_08009D84:
movs r0, 0
_08009D86:
pop {r1}
bx r1
thumb_func_end sub_8009D04
thumb_func_start sub_8009D8C
sub_8009D8C:
push {lr}

View File

@ -68,6 +68,7 @@ SECTIONS {
asm/text.o(.text);
src/code_8009804.o(.text);
asm/code_8009804.o(.text);
src/math.o(.text);
asm/file_system.o(.text);
src/file_system.o(.text);
src/decompress.o(.text);
@ -389,6 +390,7 @@ SECTIONS {
{
data/data_code_2.o(.rodata);
data/data.o(.rodata);
src/math.o(.rodata);
src/file_system.o(.rodata);
src/decompress.o(.rodata);
data/data_80B9BB8.o(.rodata);

View File

@ -28,8 +28,8 @@ extern const s16 gUnknown_80B82AA[16 * 10];
extern const s16 gUnknown_80B83EA[16 * 10];
// code_8009804.s
extern s32 sub_8009C7C(s32);
extern s32 sub_8009D04(s32);
extern s32 sin_abs_4096(s32);
extern s32 cos_4096(s32);
static void sub_800561C(struct unkStructFor800561C *, s32, s32, u8 *);
s32 *sub_8005674(struct unkStructFor800561C *, s32);
@ -527,7 +527,7 @@ void sub_8005838(s32 *a0, u8 kind)
*r3++ = *r2++;
*r3++ = 256;
}
{
{
s32 r8;
s32 iVar3;
s32 sp14;
@ -550,20 +550,20 @@ void sub_8005838(s32 *a0, u8 kind)
val1 = gUnknown_2026E40;
val2 = gUnknown_2026E44;
val3 = gUnknown_2026E48;
spC = 0x400 / (val3 / 256 + 1);
iVar11 = val2 / 256;
j = iVar11;
k = iVar11;
for (sp10 = 0; sp10 < 0x400; sp10 += spC) {
tmp1 = val3 * sub_8009C7C(sp10) / 256;
tmp1 = val3 * sin_abs_4096(sp10) / 256;
sp14 = (val2 + tmp1) / 256;
r8 = (val2 - tmp1) / 256;
if (j < sp14 || k > r8) {
tmp2 = val3 * sub_8009D04(sp10) / 256;
tmp2 = val3 * cos_4096(sp10) / 256;
iVar5 = (val1 - tmp2) / 256;
iVar3 = (val1 + tmp2) / 256;
@ -1558,7 +1558,7 @@ NAKED void sub_8005838(s32 *a0, u8 kind)
"_08005F62:\n"
"\tadds r0, r3, 0\n"
"\tstr r3, [sp, 0x10]\n"
"\tbl sub_8009C7C\n"
"\tbl sin_abs_4096\n"
"\tldr r1, [sp, 0x8]\n"
"\tmuls r0, r1\n"
"\tldr r3, [sp, 0x10]\n"
@ -1594,7 +1594,7 @@ NAKED void sub_8005838(s32 *a0, u8 kind)
"_08005FA4:\n"
"\tadds r0, r3, 0\n"
"\tstr r3, [sp, 0x10]\n"
"\tbl sub_8009D04\n"
"\tbl cos_4096\n"
"\tldr r2, [sp, 0x8]\n"
"\tmuls r0, r2\n"
"\tldr r3, [sp, 0x10]\n"
@ -1750,4 +1750,4 @@ void sub_80060EC(void)
gUnknown_2026E50 = !gUnknown_2026E50;
SetBldAlphaReg((gUnknown_2026E4E & 0x1F00) >> 8, gUnknown_2026E4E & 0x1F);
gUnknown_2026E38 = TRUE;
}
}

41
src/math.c Normal file
View File

@ -0,0 +1,41 @@
#include "global.h"
#include "math.h"
extern u8 gFastMod3Lookup[];
extern s16 gFastSinLookup[];
u32 fast_mod_3(s32 x) {
if (x < 0x100) {
return gFastMod3Lookup[x];
}
return x % 3;
}
s32 sin_abs_4096(s32 x) {
switch (x & 0xc00) {
case 0x000:
return gFastSinLookup[x & 0x3ff];
case 0x400:
return gFastSinLookup[0x3ff - (x & 0x3ff)];
case 0x800:
return -gFastSinLookup[x & 0x3ff];
case 0xc00:
return -gFastSinLookup[0x3ff - (x & 0x3ff)];
}
return 0;
}
s32 cos_4096(s32 x) {
switch (x & 0xc00) {
case 0x000:
return gFastSinLookup[0x3ff - (x & 0x3ff)];
case 0x400:
return -gFastSinLookup[x & 0x3ff];
case 0x800:
return -gFastSinLookup[0x3ff - (x & 0x3ff)];
case 0xc00:
return gFastSinLookup[x & 0x3ff];
}
return 0;
}

39
src/math.h Normal file
View File

@ -0,0 +1,39 @@
#ifndef GUARD_MATH_H
#define GUARD_MATH_H
/**
* This function computes a value modulo 3, using a lookup table for values less
* than 0x100.
*
* @warning This function performs an invalid memory access if x < 0.
* Hopefully it's never actually used.
*
* @param s32 x The value to get modulo 3. Must be non-negative.
*
* @return u32 The value of x modulo 3.
*/
u32 fast_mod_3(s32 x);
/**
* This function computes the sine of the absolute value of x using a lookup
* table. The period of the function is 4096, and the range is [-256, 256].
*
* @param s32 x The value to get the sine of.
*
* @return s32 `floor(256 * sin(pi * abs(x) / 2048))`
*/
s32 sin_abs_4096(s32 x);
/**
* This function computes the cosine of the absolute value of x using a lookup
* table. The period of the function is 4096, and the range is [-256, 256].
*
* @note Mathematically, `cos(abs(t)) = cos(t)`, unlike the case in `sin_abs_4096()` above.
*
* @param s32 x The value to get the cosine of.
*
* @return s32 `floor(256 * cos(pi * x / 2048))`
*/
s32 cos_4096(s32 x);
#endif // GUARD_MATH_H

View File

@ -155,6 +155,7 @@ gUnknown_202D240: /* 202D240 (code_8009804) */
gUnknown_202D2A0: /* 202D2A0 (code_8009804) */
.space 0x4
.include "src/math.o"
.include "src/file_system.o"
.include "src/decompress.o"
.include "src/main.o"

View File

@ -43,6 +43,7 @@ gUnknown_203B08C: /* 203B08C */
gUnknown_203B090: /* 203B090 */
.space 0x4
.include "src/math.o"
.include "src/file_system.o"
.include "src/main.o"