Fix fossil specials

This commit is contained in:
DizzyEggg 2018-11-19 17:15:28 +01:00
parent 95d3c180cc
commit 6a5b20ee8a

View File

@ -32,7 +32,7 @@ struct Struct8617DA4
struct Struct203CF10 struct Struct203CF10
{ {
u8 *buffer; u8 *buffer;
u8 curr_buffer_index; u8 currIndex;
}; };
struct DynamicSpriteFrameImage struct DynamicSpriteFrameImage
@ -147,7 +147,7 @@ EWRAM_DATA static struct Struct203CF10 *sUnknown_0203CF10 = NULL;
EWRAM_DATA static u16 *sUnknown_0203CF14 = NULL; EWRAM_DATA static u16 *sUnknown_0203CF14 = NULL;
// IWRAM bss // IWRAM bss
IWRAM_DATA u16 gUnknown_030012A8[8]; IWRAM_DATA static u16 gUnknown_030012A8[8];
// text // text
void sub_81BEB24(void) void sub_81BEB24(void)
@ -261,7 +261,7 @@ static void sub_81BED50(u8 taskId)
if (gTasks[taskId].data[1] > 1) if (gTasks[taskId].data[1] > 1)
{ {
index = gTasks[taskId].data[3]; index = gTasks[taskId].data[3];
sUnknown_0203CF10[index].buffer = (u8 *)Alloc(INNER_BUFFER_LENGTH); sUnknown_0203CF10[index].buffer = Alloc(INNER_BUFFER_LENGTH);
for (i = 0; i <= (INNER_BUFFER_LENGTH - 1); i++) for (i = 0; i <= (INNER_BUFFER_LENGTH - 1); i++)
sUnknown_0203CF10[index].buffer[i] = i; sUnknown_0203CF10[index].buffer[i] = i;
for (i = 0; i <= (INNER_BUFFER_LENGTH - 1); i++) for (i = 0; i <= (INNER_BUFFER_LENGTH - 1); i++)
@ -284,10 +284,10 @@ static void sub_81BED50(u8 taskId)
for (j = 0; j < 1; j++) for (j = 0; j < 1; j++)
{ {
sub_81BF2B8(sUnknown_0203CF04, sub_81BF2B8(sUnknown_0203CF04,
((((OUTER_BUFFER_LENGTH - 1) - i) * INNER_BUFFER_LENGTH) + sUnknown_0203CF10[i].buffer[(sUnknown_0203CF10[i].curr_buffer_index)++]), ((((OUTER_BUFFER_LENGTH - 1) - i) * INNER_BUFFER_LENGTH) + sUnknown_0203CF10[i].buffer[(sUnknown_0203CF10[i].currIndex)++]),
0, INNER_BUFFER_LENGTH, 1); 0, INNER_BUFFER_LENGTH, 1);
} }
if (sUnknown_0203CF10[i].curr_buffer_index > (INNER_BUFFER_LENGTH - 1)) if (sUnknown_0203CF10[i].currIndex > (INNER_BUFFER_LENGTH - 1))
{ {
FREE_AND_SET_NULL(sUnknown_0203CF10[i].buffer); FREE_AND_SET_NULL(sUnknown_0203CF10[i].buffer);
gTasks[taskId].data[2]++; gTasks[taskId].data[2]++;
@ -296,7 +296,7 @@ static void sub_81BED50(u8 taskId)
} }
} }
LoadBgTiles(0, sUnknown_0203CF04, MIRAGE_TOWER_GFX_LENGTH, 0); LoadBgTiles(0, sUnknown_0203CF04, MIRAGE_TOWER_GFX_LENGTH, 0);
if (sUnknown_0203CF10[OUTER_BUFFER_LENGTH - 1].curr_buffer_index > (INNER_BUFFER_LENGTH - 1)) if (sUnknown_0203CF10[OUTER_BUFFER_LENGTH - 1].currIndex > (INNER_BUFFER_LENGTH - 1))
break; break;
return; return;
case 4: case 4:
@ -338,9 +338,9 @@ static void sub_81BF028(u8 taskId)
switch (gTasks[taskId].data[0]) switch (gTasks[taskId].data[0])
{ {
case 1: case 1:
sUnknown_0203CF0C = AllocZeroed(sizeof(struct Struct203CF0C)); sUnknown_0203CF0C = AllocZeroed(sizeof(*sUnknown_0203CF0C));
sUnknown_0203CF0C->frameImageTiles = AllocZeroed(ROOT_FOSSIL_GFX_LENGTH); sUnknown_0203CF0C->frameImageTiles = AllocZeroed(ROOT_FOSSIL_GFX_LENGTH);
sUnknown_0203CF0C->frameImage = AllocZeroed(sizeof(struct DynamicSpriteFrameImage)); sUnknown_0203CF0C->frameImage = AllocZeroed(sizeof(*sUnknown_0203CF0C->frameImage));
sUnknown_0203CF0C->unkC = AllocZeroed(ROOT_FOSSIL_GFX_RANDOMIZER_LENGTH * sizeof(u16)); sUnknown_0203CF0C->unkC = AllocZeroed(ROOT_FOSSIL_GFX_RANDOMIZER_LENGTH * sizeof(u16));
sUnknown_0203CF0C->unk10 = 0; sUnknown_0203CF0C->unk10 = 0;
break; break;
@ -417,13 +417,15 @@ static void sub_81BF248(struct Sprite *sprite)
} }
} }
#ifdef NONMATCHING
static void sub_81BF2B8(u8* a, u16 b, u8 c, u8 d, u8 e) static void sub_81BF2B8(u8* a, u16 b, u8 c, u8 d, u8 e)
{ {
u8 r5, r4, r0, r2, r1; u8 r5, r4, r0, r2;
u16 var;
r5 = b / d; r5 = b / d;
r4 = r5; r4 = r5;
gUnknown_030012A8[0] = r5; gUnknown_030012A8[0] = r4;
r2 = b % d; r2 = b % d;
r0 = r2; r0 = r2;
@ -439,14 +441,123 @@ static void sub_81BF2B8(u8* a, u16 b, u8 c, u8 d, u8 e)
gUnknown_030012A8[4] = r0; gUnknown_030012A8[4] = r0;
gUnknown_030012A8[5] = r5; gUnknown_030012A8[5] = r5;
d /= 8; var = ((d / 8) * (r5 * 64)) + (r0 * 64);
d *= 64; gUnknown_030012A8[6] = var;
gUnknown_030012A8[6] = (d * r5) + (r0 * 64);
gUnknown_030012A8[7] = gUnknown_030012A8[6] + 9 * r4; var += (r4 * 8) + r2;
gUnknown_030012A8[7] = var;
r1 = (b & 1); // This part is non-matching. 99% sure it IS functionally equivalent, though.
r1 ^= 1; b = (b & 1) ^ 1;
c = (c << (r1 << 2)) | (15 << ((r1 ^ 1) << 2)); c = (c << ((b) << 2)) | (15 << ((b ^ 1) << 2));
a[(e << 5) + r4] &= c;
a[(var / 2) + (e * 32)] &= c;
} }
#else
NAKED
static void sub_81BF2B8(u8* a, u16 b, u8 c, u8 d, u8 e)
{
asm_unified("\n\
push {r4-r7,lr}\n\
mov r7, r10\n\
mov r6, r9\n\
mov r5, r8\n\
push {r5-r7}\n\
sub sp, 0x8\n\
str r0, [sp]\n\
mov r10, r1\n\
adds r6, r2, 0\n\
mov r8, r3\n\
ldr r0, [sp, 0x28]\n\
mov r9, r0\n\
lsls r1, 16\n\
lsrs r1, 16\n\
mov r10, r1\n\
lsls r6, 24\n\
lsrs r6, 24\n\
mov r0, r8\n\
lsls r0, 24\n\
mov r8, r0\n\
lsrs r7, r0, 24\n\
mov r1, r9\n\
lsls r1, 24\n\
lsrs r1, 24\n\
mov r9, r1\n\
mov r0, r10\n\
adds r1, r7, 0\n\
bl __divsi3\n\
adds r5, r0, 0\n\
lsls r5, 24\n\
lsrs r4, r5, 24\n\
ldr r3, =gUnknown_030012A8\n\
strh r4, [r3]\n\
mov r0, r10\n\
adds r1, r7, 0\n\
str r3, [sp, 0x4]\n\
bl __modsi3\n\
lsls r0, 24\n\
lsrs r2, r0, 24\n\
ldr r3, [sp, 0x4]\n\
strh r2, [r3, 0x2]\n\
movs r1, 0x7\n\
ands r4, r1\n\
ands r2, r1\n\
strh r4, [r3, 0x4]\n\
strh r2, [r3, 0x6]\n\
lsrs r0, 27\n\
lsrs r5, 27\n\
strh r0, [r3, 0x8]\n\
strh r5, [r3, 0xA]\n\
mov r1, r8\n\
lsrs r1, 27\n\
lsls r1, 6\n\
mov r8, r1\n\
mov r1, r8\n\
muls r1, r5\n\
lsls r0, 6\n\
adds r1, r0\n\
lsls r1, 16\n\
lsrs r1, 16\n\
strh r1, [r3, 0xC]\n\
lsls r4, 3\n\
adds r4, r2\n\
adds r1, r4\n\
lsls r4, r1, 16\n\
lsrs r4, 17\n\
strh r1, [r3, 0xE]\n\
movs r1, 0x1\n\
mov r0, r10\n\
ands r1, r0\n\
movs r2, 0x1\n\
eors r1, r2\n\
lsls r0, r1, 2\n\
lsls r6, r0\n\
eors r1, r2\n\
lsls r1, 2\n\
movs r0, 0xF\n\
lsls r0, r1\n\
orrs r6, r0\n\
lsls r6, 24\n\
lsrs r6, 24\n\
mov r1, r9\n\
lsls r1, 5\n\
mov r9, r1\n\
add r9, r4\n\
ldr r1, [sp]\n\
add r1, r9\n\
ldrb r0, [r1]\n\
ands r6, r0\n\
strb r6, [r1]\n\
add sp, 0x8\n\
pop {r3-r5}\n\
mov r8, r3\n\
mov r9, r4\n\
mov r10, r5\n\
pop {r4-r7}\n\
pop {r0}\n\
bx r0\n\
.pool\n\
");
}
#endif // NONMATCHING