start rom_8034C54 decomp

This commit is contained in:
DizzyEggg 2018-05-27 17:42:48 +02:00
parent 06186561f2
commit 357afd91b5
5 changed files with 199 additions and 505 deletions

View File

@ -1568,7 +1568,7 @@ sub_81C7E58: @ 81C7E58
ldr r2, [r6]
mov r8, r2
mov r0, r8
bl sub_8034974
bl GetDecompressedDataSize
adds r5, r0, 0
lsls r4, 5
ldr r0, =gPokenavLeftHeader_Pal
@ -1650,7 +1650,7 @@ sub_81C7F24: @ 81C7F24
adds r1, r2
ldr r6, [r1]
adds r0, r6, 0
bl sub_8034974
bl GetDecompressedDataSize
adds r5, r0, 0
lsls r4, 5
ldr r0, =gPokenavLeftHeader_Pal

View File

@ -5,505 +5,7 @@
.text
thumb_func_start sub_8034C54
sub_8034C54: @ 8034C54
push {r4-r7,lr}
adds r4, r0, 0
ldr r5, =gUnknown_02022E10
ldr r0, [r5]
cmp r0, 0
beq _08034C64
bl sub_8034CC8
_08034C64:
movs r0, 0x8
bl Alloc
str r0, [r5]
cmp r0, 0
bne _08034C78
movs r0, 0
b _08034CC0
.pool
_08034C78:
lsls r0, r4, 3
subs r0, r4
lsls r0, 2
bl Alloc
ldr r1, [r5]
str r0, [r1, 0x4]
cmp r0, 0
bne _08034C94
adds r0, r1, 0
bl Free
movs r0, 0
b _08034CC0
_08034C94:
str r4, [r1]
movs r3, 0
cmp r3, r4
bcs _08034CBE
movs r7, 0
movs r6, 0xFF
movs r2, 0
_08034CA2:
ldr r0, [r5]
ldr r0, [r0, 0x4]
adds r0, r2, r0
strb r7, [r0]
ldr r0, [r5]
ldr r1, [r0, 0x4]
adds r1, r2, r1
ldrb r0, [r1, 0x1]
orrs r0, r6
strb r0, [r1, 0x1]
adds r2, 0x1C
adds r3, 0x1
cmp r3, r4
bcc _08034CA2
_08034CBE:
movs r0, 0x1
_08034CC0:
pop {r4-r7}
pop {r1}
bx r1
thumb_func_end sub_8034C54
thumb_func_start sub_8034CC8
sub_8034CC8: @ 8034CC8
push {r4,r5,lr}
ldr r2, =gUnknown_02022E10
ldr r1, [r2]
cmp r1, 0
beq _08034D08
ldr r0, [r1, 0x4]
cmp r0, 0
beq _08034CFC
movs r4, 0
ldr r0, [r1]
cmp r4, r0
bcs _08034CF2
adds r5, r2, 0
_08034CE2:
adds r0, r4, 0
bl sub_80353DC
adds r4, 0x1
ldr r0, [r5]
ldr r0, [r0]
cmp r4, r0
bcc _08034CE2
_08034CF2:
ldr r0, =gUnknown_02022E10
ldr r0, [r0]
ldr r0, [r0, 0x4]
bl Free
_08034CFC:
ldr r4, =gUnknown_02022E10
ldr r0, [r4]
bl Free
movs r0, 0
str r0, [r4]
_08034D08:
pop {r4,r5}
pop {r0}
bx r0
.pool
thumb_func_end sub_8034CC8
thumb_func_start sub_8034D14
sub_8034D14: @ 8034D14
push {r4-r7,lr}
mov r7, r10
mov r6, r9
mov r5, r8
push {r5-r7}
sub sp, 0x8
mov r8, r0
mov r10, r1
adds r5, r2, 0
ldr r6, =gUnknown_02022E10
ldr r0, [r6]
cmp r0, 0
beq _08034DD4
ldr r1, [r0, 0x4]
mov r0, r8
lsls r2, r0, 3
subs r0, r2, r0
lsls r4, r0, 2
adds r1, r4, r1
ldrb r0, [r1]
mov r9, r2
cmp r0, 0
bne _08034DD4
ldrb r0, [r5, 0x1]
bl sub_8035518
ldr r1, [r6]
ldr r1, [r1, 0x4]
adds r1, r4, r1
strb r0, [r1, 0x1]
ldr r0, [r6]
ldr r0, [r0, 0x4]
adds r0, r4, r0
ldrb r0, [r0, 0x1]
cmp r0, 0xFF
beq _08034DD4
ldr r0, [r5, 0x8]
ldrh r0, [r0, 0x6]
bl GetSpriteTileStartByTag
ldr r2, [r6]
ldr r1, [r2, 0x4]
adds r1, r4, r1
strh r0, [r1, 0xA]
ldr r0, [r2, 0x4]
adds r0, r4, r0
ldrh r1, [r0, 0xA]
ldr r7, =0xffff0000
lsrs r0, r7, 16
cmp r1, r0
bne _08034DE0
ldr r2, [r5, 0x8]
ldrh r0, [r2, 0x4]
adds r1, r2, 0
cmp r0, 0
beq _08034D94
adds r0, r1, 0
bl LoadSpriteSheet
b _08034DB4
.pool
_08034D94:
ldr r0, [r2]
ldr r1, [r2, 0x4]
str r0, [sp]
str r1, [sp, 0x4]
ldr r0, [r2]
bl sub_8034974
lsls r0, 16
lsrs r0, 16
ldr r1, [sp, 0x4]
ands r1, r7
orrs r1, r0
str r1, [sp, 0x4]
mov r0, sp
bl LoadCompressedObjectPic
_08034DB4:
ldr r1, [r6]
ldr r1, [r1, 0x4]
adds r1, r4, r1
strh r0, [r1, 0xA]
ldr r0, =gUnknown_02022E10
ldr r0, [r0]
ldr r1, [r0, 0x4]
mov r2, r9
mov r3, r8
subs r0, r2, r3
lsls r0, 2
adds r0, r1
ldrh r1, [r0, 0xA]
ldr r0, =0x0000ffff
cmp r1, r0
bne _08034DE0
_08034DD4:
movs r0, 0
b _08034EE8
.pool
_08034DE0:
ldr r0, [r5, 0xC]
ldrh r0, [r0, 0x4]
bl IndexOfSpritePaletteTag
ldr r6, =gUnknown_02022E10
ldr r1, [r6]
ldr r1, [r1, 0x4]
mov r4, r9
mov r3, r8
subs r2, r4, r3
lsls r4, r2, 2
adds r1, r4, r1
strb r0, [r1, 0x4]
ldr r0, [r6]
ldr r0, [r0, 0x4]
adds r0, r4, r0
ldrb r0, [r0, 0x4]
cmp r0, 0xFF
bne _08034E14
ldr r0, [r5, 0xC]
bl LoadSpritePalette
ldr r1, [r6]
ldr r1, [r1, 0x4]
adds r1, r4, r1
strb r0, [r1, 0x4]
_08034E14:
ldr r0, [r6]
ldr r1, [r0, 0x4]
adds r1, r4, r1
ldrb r0, [r5]
lsls r0, 30
lsrs r0, 30
strb r0, [r1, 0x2]
ldr r0, [r6]
ldr r0, [r0, 0x4]
adds r0, r4, r0
ldrb r1, [r5, 0x1]
strb r1, [r0, 0x3]
ldr r2, [r6]
ldr r0, [r2, 0x4]
adds r0, r4, r0
ldrh r1, [r5, 0x4]
strh r1, [r0, 0xC]
ldr r0, [r2, 0x4]
adds r0, r4, r0
ldrh r1, [r5, 0x6]
strh r1, [r0, 0xE]
ldr r1, [r2, 0x4]
adds r1, r4, r1
ldrb r0, [r5]
lsls r0, 28
lsrs r0, 30
strb r0, [r1, 0x6]
ldr r0, [r6]
ldr r1, [r0, 0x4]
adds r1, r4, r1
ldrb r0, [r5]
lsls r0, 26
lsrs r0, 30
strb r0, [r1, 0x5]
ldr r0, [r6]
ldr r1, [r0, 0x4]
adds r1, r4, r1
ldrb r0, [r5]
lsrs r0, 6
strb r0, [r1, 0x7]
ldr r0, [r6]
ldr r0, [r0, 0x4]
adds r0, r4, r0
ldrb r1, [r5, 0x2]
strb r1, [r0, 0x8]
ldrb r1, [r5]
lsls r0, r1, 28
lsrs r0, 30
lsls r1, 26
lsrs r1, 30
bl sub_80355F8
ldr r1, [r6]
ldr r1, [r1, 0x4]
adds r1, r4, r1
strb r0, [r1, 0x9]
ldr r2, [r6]
ldr r0, [r2, 0x4]
adds r0, r4, r0
ldr r1, [r5, 0x8]
ldrh r1, [r1, 0x6]
strh r1, [r0, 0x10]
ldr r0, [r2, 0x4]
adds r0, r4, r0
ldr r1, [r5, 0xC]
ldrh r1, [r1, 0x4]
strh r1, [r0, 0x12]
ldr r0, [r2, 0x4]
adds r0, r4, r0
movs r1, 0x1
strb r1, [r0]
ldr r0, [r6]
ldr r0, [r0, 0x4]
adds r0, r4, r0
str r1, [r0, 0x14]
movs r3, 0x1
ldrb r0, [r5, 0x1]
cmp r3, r0
bcs _08034ECA
_08034EB2:
ldr r0, [r6]
ldr r2, [r0, 0x4]
adds r2, r4, r2
ldr r1, [r2, 0x14]
lsls r0, r1, 2
adds r0, r1
lsls r0, 1
str r0, [r2, 0x14]
adds r3, 0x1
ldrb r2, [r5, 0x1]
cmp r3, r2
bcc _08034EB2
_08034ECA:
ldr r0, =gUnknown_02022E10
ldr r0, [r0]
mov r3, r9
mov r4, r8
subs r1, r3, r4
lsls r1, 2
ldr r0, [r0, 0x4]
adds r0, r1
bl sub_8034EFC
mov r0, r8
mov r1, r10
bl sub_8035044
movs r0, 0x1
_08034EE8:
add sp, 0x8
pop {r3-r5}
mov r8, r3
mov r9, r4
mov r10, r5
pop {r4-r7}
pop {r1}
bx r1
.pool
thumb_func_end sub_8034D14
thumb_func_start sub_8034EFC
sub_8034EFC: @ 8034EFC
push {r4-r7,lr}
mov r7, r10
mov r6, r9
mov r5, r8
push {r5-r7}
sub sp, 0x4
adds r4, r0, 0
ldrb r5, [r4, 0x1]
movs r0, 0xC
ldrsh r7, [r4, r0]
ldrb r0, [r4, 0x3]
adds r0, 0x1
mov r8, r0
mov r1, sp
movs r0, 0
strh r0, [r1]
lsls r1, r5, 3
ldr r2, =gMain+0x38
mov r9, r2
add r1, r9
mov r0, r8
lsls r2, r0, 2
movs r0, 0x80
lsls r0, 17
orrs r2, r0
mov r0, sp
bl CpuSet
movs r6, 0
ldrb r5, [r4, 0x1]
cmp r6, r8
bcs _08034FCE
movs r1, 0x3F
mov r10, r1
movs r2, 0xD
negs r2, r2
mov r9, r2
_08034F46:
lsls r0, r5, 3
ldr r1, =gMain
adds r3, r0, r1
ldrh r1, [r4, 0xE]
adds r0, r3, 0
adds r0, 0x38
strb r1, [r0]
ldr r2, =0x000001ff
adds r0, r2, 0
adds r1, r7, 0
ands r1, r0
ldrh r2, [r3, 0x3A]
ldr r0, =0xfffffe00
ands r0, r2
orrs r0, r1
strh r0, [r3, 0x3A]
ldrb r1, [r4, 0x6]
movs r0, 0x39
adds r0, r3
mov r12, r0
lsls r1, 6
ldrb r2, [r0]
mov r0, r10
ands r0, r2
orrs r0, r1
mov r1, r12
strb r0, [r1]
ldrb r1, [r4, 0x5]
movs r2, 0x3B
adds r2, r3
mov r12, r2
lsls r1, 6
ldrb r2, [r2]
mov r0, r10
ands r0, r2
orrs r0, r1
mov r1, r12
strb r0, [r1]
ldrh r0, [r4, 0xA]
ldr r1, =0x000003ff
ands r1, r0
ldrh r2, [r3, 0x3C]
ldr r0, =0xfffffc00
ands r0, r2
orrs r0, r1
strh r0, [r3, 0x3C]
adds r3, 0x3D
movs r0, 0x3
ldrb r1, [r4, 0x7]
ands r1, r0
lsls r1, 2
ldrb r2, [r3]
mov r0, r9
ands r0, r2
orrs r0, r1
strb r0, [r3]
ldrb r2, [r4, 0x4]
lsls r2, 4
movs r1, 0xF
ands r0, r1
orrs r0, r2
strb r0, [r3]
ldrb r0, [r4, 0x8]
adds r7, r0
adds r6, 0x1
adds r5, 0x1
cmp r6, r8
bcc _08034F46
_08034FCE:
subs r5, 0x1
ldr r0, =gMain
lsls r3, r5, 3
adds r3, r0
movs r2, 0xC
ldrsh r1, [r4, r2]
ldrb r0, [r4, 0x8]
subs r1, r0
ldr r2, =0x000001ff
adds r0, r2, 0
ands r1, r0
ldrh r2, [r3, 0x3A]
ldr r0, =0xfffffe00
ands r0, r2
orrs r0, r1
strh r0, [r3, 0x3A]
adds r2, r3, 0
adds r2, 0x39
ldrb r1, [r2]
movs r0, 0x4
negs r0, r0
ands r0, r1
movs r1, 0x2
orrs r0, r1
strb r0, [r2]
ldrb r0, [r4, 0x9]
lsls r1, r0, 2
adds r1, r0
lsls r1, 1
ldrh r4, [r4, 0xA]
adds r1, r4
ldr r2, =0x000003ff
adds r0, r2, 0
ands r1, r0
ldrh r2, [r3, 0x3C]
ldr r0, =0xfffffc00
ands r0, r2
orrs r0, r1
strh r0, [r3, 0x3C]
add sp, 0x4
pop {r3-r5}
mov r8, r3
mov r9, r4
mov r10, r5
pop {r4-r7}
pop {r0}
bx r0
.pool
thumb_func_end sub_8034EFC
thumb_func_start sub_8035044
sub_8035044: @ 8035044

View File

@ -818,7 +818,7 @@ static bool8 LoadBerryBlenderGfx(void)
switch (sBerryBlenderData->loadGfxState)
{
case 0:
sBerryBlenderData->tilesBuffer = AllocZeroed(sub_8034974(sBlenderCenterGfx) + 100);
sBerryBlenderData->tilesBuffer = AllocZeroed(GetDecompressedDataSize(sBlenderCenterGfx) + 100);
LZDecompressWram(sBlenderCenterGfx, sBerryBlenderData->tilesBuffer);
sBerryBlenderData->loadGfxState++;
break;
@ -829,7 +829,7 @@ static bool8 LoadBerryBlenderGfx(void)
sBerryBlenderData->loadGfxState++;
break;
case 2:
LoadBgTiles(2, sBerryBlenderData->tilesBuffer, sub_8034974(sBlenderCenterGfx), 0);
LoadBgTiles(2, sBerryBlenderData->tilesBuffer, GetDecompressedDataSize(sBlenderCenterGfx), 0);
sBerryBlenderData->loadGfxState++;
break;
case 3:
@ -837,7 +837,7 @@ static bool8 LoadBerryBlenderGfx(void)
sBerryBlenderData->loadGfxState++;
break;
case 4:
LoadBgTiles(1, sBerryBlenderData->tilesBuffer, sub_8034974(gUnknown_08D91DB8), 0);
LoadBgTiles(1, sBerryBlenderData->tilesBuffer, GetDecompressedDataSize(gUnknown_08D91DB8), 0);
sBerryBlenderData->loadGfxState++;
break;
case 5:
@ -845,7 +845,7 @@ static bool8 LoadBerryBlenderGfx(void)
sBerryBlenderData->loadGfxState++;
break;
case 6:
CopyToBgTilemapBuffer(1, sBerryBlenderData->tilesBuffer, sub_8034974(gUnknown_08D927EC), 0);
CopyToBgTilemapBuffer(1, sBerryBlenderData->tilesBuffer, GetDecompressedDataSize(gUnknown_08D927EC), 0);
CopyBgTilemapBufferToVram(1);
sBerryBlenderData->loadGfxState++;
break;

View File

@ -459,7 +459,7 @@ _08034964:\n\
.syntax divided");
}
u32 sub_8034974(const u8 *ptr)
u32 GetDecompressedDataSize(const u8 *ptr)
{
return (ptr[3] << 16) | (ptr[2] << 8) | (ptr[1]);
}

View File

@ -1,5 +1,197 @@
#include "global.h"
#include "malloc.h"
#include "decompress.h"
#include "main.h"
struct UnkStruct3
{
u8 field_0_0:2;
u8 shape:2;
u8 size:2;
u8 priority:2;
u8 field_1;
u8 xDelta;
u8 field_3;
s16 x;
s16 y;
const struct SpriteSheet *spriteSheet;
const struct SpritePalette *spritePal;
};
struct UnkStruct2
{
u8 field_0;
u8 field_1;
u8 field_2;
u8 field_3;
u8 palTagIndex;
u8 size;
u8 shape;
u8 priority;
u8 xDelta;
u8 field_9;
u16 tileStart;
s16 x;
s16 y;
u16 tileTag;
u16 palTag;
u32 field_14;
u8 field_18;
u8 field_19;
u8 field_1A;
u8 field_1B;
};
struct UnkStruct1
{
u32 count;
struct UnkStruct2 *field_4;
};
IWRAM_DATA u32 gUnknown_03000DD4;
IWRAM_DATA u32 gUnknown_03000DD8;
IWRAM_DATA u32 gUnknown_03000DDC;
extern struct UnkStruct1 *gUnknown_02022E10;
// this file's functions
void sub_8034CC8(void);
void sub_80353DC(u32 id);
u8 sub_8035518(u8 arg0);
u8 sub_80355F8(u32 arg0, u32 arg1);
void sub_8034EFC(struct UnkStruct2 *arg0);
void sub_8035044(u32 id, u32 arg1);
// code
bool32 sub_8034C54(u32 count)
{
u32 i;
if (gUnknown_02022E10 != NULL)
sub_8034CC8();
gUnknown_02022E10 = Alloc(sizeof(*gUnknown_02022E10));
if (gUnknown_02022E10 == NULL)
return FALSE;
gUnknown_02022E10->field_4 = Alloc(sizeof(struct UnkStruct2) * count);
if (gUnknown_02022E10->field_4 == NULL)
{
Free(gUnknown_02022E10);
return FALSE;
}
gUnknown_02022E10->count = count;
for (i = 0; i < count; i++)
{
gUnknown_02022E10->field_4[i].field_0 = 0;
gUnknown_02022E10->field_4[i].field_1 |= 0xFF;
}
return TRUE;
}
void sub_8034CC8(void)
{
if (gUnknown_02022E10 != NULL)
{
if (gUnknown_02022E10->field_4 != NULL)
{
u32 i;
for (i = 0; i < gUnknown_02022E10->count; i++)
sub_80353DC(i);
Free(gUnknown_02022E10->field_4);
}
FREE_AND_SET_NULL(gUnknown_02022E10);
}
}
bool32 sub_8034D14(u32 id, u32 arg1, const struct UnkStruct3 *arg2)
{
u32 i;
if (gUnknown_02022E10 == NULL)
return FALSE;
if (gUnknown_02022E10->field_4[id].field_0 != 0)
return FALSE;
gUnknown_02022E10->field_4[id].field_1 = sub_8035518(arg2->field_1);
if (gUnknown_02022E10->field_4[id].field_1 == 0xFF)
return FALSE;
gUnknown_02022E10->field_4[id].tileStart = GetSpriteTileStartByTag(arg2->spriteSheet->tag);
if (gUnknown_02022E10->field_4[id].tileStart == 0xFFFF)
{
if (arg2->spriteSheet->size != 0)
{
gUnknown_02022E10->field_4[id].tileStart = LoadSpriteSheet(arg2->spriteSheet);
}
else
{
struct CompressedSpriteSheet compSpriteSheet;
compSpriteSheet = *(struct CompressedSpriteSheet*)(arg2->spriteSheet);
compSpriteSheet.size = GetDecompressedDataSize(arg2->spriteSheet->data);
gUnknown_02022E10->field_4[id].tileStart = LoadCompressedObjectPic(&compSpriteSheet);
}
if (gUnknown_02022E10->field_4[id].tileStart == 0xFFFF)
return FALSE;
}
gUnknown_02022E10->field_4[id].palTagIndex = IndexOfSpritePaletteTag(arg2->spritePal->tag);
if (gUnknown_02022E10->field_4[id].palTagIndex == 0xFF)
gUnknown_02022E10->field_4[id].palTagIndex = LoadSpritePalette(arg2->spritePal);
gUnknown_02022E10->field_4[id].field_2 = arg2->field_0_0;
gUnknown_02022E10->field_4[id].field_3 = arg2->field_1;
gUnknown_02022E10->field_4[id].x = arg2->x;
gUnknown_02022E10->field_4[id].y = arg2->y;
gUnknown_02022E10->field_4[id].shape = arg2->shape;
gUnknown_02022E10->field_4[id].size = arg2->size;
gUnknown_02022E10->field_4[id].priority = arg2->priority;
gUnknown_02022E10->field_4[id].xDelta = arg2->xDelta;
gUnknown_02022E10->field_4[id].field_9 = sub_80355F8(arg2->shape, arg2->size);
gUnknown_02022E10->field_4[id].tileTag = arg2->spriteSheet->tag;
gUnknown_02022E10->field_4[id].palTag = arg2->spritePal->tag;
gUnknown_02022E10->field_4[id].field_0 = 1;
gUnknown_02022E10->field_4[id].field_14 = 1;
for (i = 1; i < arg2->field_1; i++)
gUnknown_02022E10->field_4[id].field_14 *= 10;
sub_8034EFC(&gUnknown_02022E10->field_4[id]);
sub_8035044(id, arg1);
return TRUE;
}
void sub_8034EFC(struct UnkStruct2 *arg0)
{
u32 i;
u32 r5 = arg0->field_1;
u32 x = arg0->x;
u32 r8 = arg0->field_3 + 1;
CpuFill16(0, &gMain.oamBuffer[r5], sizeof(struct OamData) * r8);
for (i = 0, r5 = arg0->field_1; i < r8; i++, r5++)
{
gMain.oamBuffer[r5].y = arg0->y;
gMain.oamBuffer[r5].x = x;
gMain.oamBuffer[r5].shape = arg0->shape;
gMain.oamBuffer[r5].size = arg0->size;
gMain.oamBuffer[r5].tileNum = arg0->tileStart;
gMain.oamBuffer[r5].priority = arg0->priority;
gMain.oamBuffer[r5].paletteNum = arg0->palTagIndex;
x += arg0->xDelta;
}
r5--;
gMain.oamBuffer[r5].x = arg0->x - arg0->xDelta;
gMain.oamBuffer[r5].affineMode = 2;
gMain.oamBuffer[r5].tileNum = arg0->tileStart + (arg0->field_9 * 10);
}