decompile rom_8034C54

This commit is contained in:
DizzyEggg 2018-05-27 23:26:01 +02:00
parent 357afd91b5
commit ff0c615870
6 changed files with 367 additions and 911 deletions

View File

@ -1,814 +0,0 @@
.include "asm/macros.inc"
.include "constants/constants.inc"
.syntax unified
.text
thumb_func_start sub_8035044
sub_8035044: @ 8035044
push {r4-r6,lr}
adds r3, r0, 0
adds r4, r1, 0
ldr r0, =gUnknown_02022E10
ldr r1, [r0]
adds r6, r0, 0
cmp r1, 0
beq _080350A8
ldr r2, [r1, 0x4]
lsls r1, r3, 3
subs r0, r1, r3
lsls r0, 2
adds r2, r0, r2
ldrb r0, [r2]
adds r5, r1, 0
cmp r0, 0
beq _080350A8
str r4, [r2, 0x18]
cmp r4, 0
bge _08035078
movs r2, 0x1
negs r4, r4
b _0803507A
.pool
_08035078:
movs r2, 0
_0803507A:
ldr r0, [r6]
ldr r1, [r0, 0x4]
subs r0, r5, r3
lsls r0, 2
adds r0, r1
ldrb r3, [r0, 0x2]
cmp r3, 0x1
beq _0803509A
cmp r3, 0x1
ble _08035092
cmp r3, 0x2
beq _080350A2
_08035092:
adds r1, r4, 0
bl sub_80350B0
b _080350A8
_0803509A:
adds r1, r4, 0
bl sub_8035164
b _080350A8
_080350A2:
adds r1, r4, 0
bl sub_80352C0
_080350A8:
pop {r4-r6}
pop {r0}
bx r0
thumb_func_end sub_8035044
thumb_func_start sub_80350B0
sub_80350B0: @ 80350B0
push {r4-r7,lr}
mov r7, r10
mov r6, r9
mov r5, r8
push {r5-r7}
sub sp, 0x4
mov r8, r0
mov r9, r1
str r2, [sp]
ldr r5, [r0, 0x14]
ldrb r7, [r0, 0x1]
ldr r0, =gMain
mov r10, r0
cmp r5, 0
beq _0803511A
lsls r0, r7, 3
adds r0, 0x3C
mov r1, r10
adds r6, r0, r1
_080350D6:
mov r0, r9
adds r1, r5, 0
bl __udivsi3
adds r4, r0, 0
adds r0, r4, 0
muls r0, r5
mov r2, r9
subs r2, r0
mov r9, r2
adds r0, r5, 0
movs r1, 0xA
bl __udivsi3
adds r5, r0, 0
mov r1, r8
ldrb r0, [r1, 0x9]
adds r1, r4, 0
muls r1, r0
mov r2, r8
ldrh r2, [r2, 0xA]
adds r1, r2
ldr r2, =0x000003ff
adds r0, r2, 0
ands r1, r0
ldrh r0, [r6]
ldr r2, =0xfffffc00
ands r0, r2
orrs r0, r1
strh r0, [r6]
adds r6, 0x8
adds r7, 0x1
cmp r5, 0
bne _080350D6
_0803511A:
ldr r0, [sp]
cmp r0, 0
beq _08035140
lsls r0, r7, 3
add r0, r10
adds r0, 0x39
ldrb r2, [r0]
movs r1, 0x4
negs r1, r1
ands r1, r2
strb r1, [r0]
b _08035154
.pool
_08035140:
lsls r2, r7, 3
add r2, r10
adds r2, 0x39
ldrb r1, [r2]
movs r0, 0x4
negs r0, r0
ands r0, r1
movs r1, 0x2
orrs r0, r1
strb r0, [r2]
_08035154:
add sp, 0x4
pop {r3-r5}
mov r8, r3
mov r9, r4
mov r10, r5
pop {r4-r7}
pop {r0}
bx r0
thumb_func_end sub_80350B0
thumb_func_start sub_8035164
sub_8035164: @ 8035164
push {r4-r7,lr}
mov r7, r10
mov r6, r9
mov r5, r8
push {r5-r7}
sub sp, 0x4
adds r6, r0, 0
mov r8, r1
str r2, [sp]
ldr r5, [r6, 0x14]
ldr r3, =gUnknown_03000DD4
ldrb r0, [r6, 0x1]
str r0, [r3]
ldr r2, =gUnknown_03000DD8
movs r0, 0
str r0, [r2]
ldr r1, =gUnknown_03000DDC
subs r0, 0x1
str r0, [r1]
adds r7, r3, 0
mov r10, r1
ldr r0, =gMain
mov r9, r0
cmp r5, 0
beq _0803524C
_08035196:
mov r0, r8
adds r1, r5, 0
bl __udivsi3
adds r4, r0, 0
adds r0, r4, 0
muls r0, r5
mov r1, r8
subs r1, r0
mov r8, r1
adds r0, r5, 0
movs r1, 0xA
bl __udivsi3
adds r5, r0, 0
cmp r4, 0
bne _080351C8
mov r2, r10
ldr r1, [r2]
movs r0, 0x1
negs r0, r0
cmp r1, r0
bne _080351C8
cmp r5, 0
bne _08035224
_080351C8:
ldr r2, [r7]
lsls r2, 3
add r2, r9
ldrb r0, [r6, 0x9]
adds r3, r4, 0
muls r3, r0
ldrh r4, [r6, 0xA]
adds r3, r4
ldr r1, =0x000003ff
adds r0, r1, 0
ands r3, r0
ldrh r0, [r2, 0x3C]
ldr r4, =0xfffffc00
adds r1, r4, 0
ands r0, r1
orrs r0, r3
strh r0, [r2, 0x3C]
adds r2, 0x39
ldrb r0, [r2]
movs r1, 0x4
negs r1, r1
ands r0, r1
strb r0, [r2]
mov r2, r10
ldr r1, [r2]
movs r0, 0x1
negs r0, r0
cmp r1, r0
bne _0803523A
ldr r4, =gUnknown_03000DD8
ldr r0, [r4]
str r0, [r2]
b _0803523A
.pool
_08035224:
ldr r0, [r7]
lsls r0, 3
add r0, r9
adds r0, 0x39
ldrb r1, [r0]
movs r2, 0x4
negs r2, r2
ands r1, r2
movs r2, 0x2
orrs r1, r2
strb r1, [r0]
_0803523A:
ldr r0, [r7]
adds r0, 0x1
str r0, [r7]
ldr r4, =gUnknown_03000DD8
ldr r0, [r4]
adds r0, 0x1
str r0, [r4]
cmp r5, 0
bne _08035196
_0803524C:
ldr r0, [sp]
cmp r0, 0
beq _08035298
ldr r1, [r7]
lsls r1, 3
add r1, r9
adds r1, 0x39
ldrb r2, [r1]
movs r0, 0x4
negs r0, r0
ands r0, r2
strb r0, [r1]
ldr r3, [r7]
lsls r3, 3
add r3, r9
movs r1, 0xC
ldrsh r2, [r6, r1]
mov r4, r10
ldr r0, [r4]
subs r0, 0x1
ldrb r1, [r6, 0x8]
muls r0, r1
adds r2, r0
ldr r1, =0x000001ff
adds r0, r1, 0
ands r2, r0
ldrh r1, [r3, 0x3A]
ldr r0, =0xfffffe00
ands r0, r1
orrs r0, r2
strh r0, [r3, 0x3A]
b _080352AE
.pool
_08035298:
ldr r0, [r7]
lsls r0, 3
add r0, r9
adds r0, 0x39
ldrb r2, [r0]
movs r1, 0x4
negs r1, r1
ands r1, r2
movs r2, 0x2
orrs r1, r2
strb r1, [r0]
_080352AE:
add sp, 0x4
pop {r3-r5}
mov r8, r3
mov r9, r4
mov r10, r5
pop {r4-r7}
pop {r0}
bx r0
thumb_func_end sub_8035164
thumb_func_start sub_80352C0
sub_80352C0: @ 80352C0
push {r4-r7,lr}
mov r7, r10
mov r6, r9
mov r5, r8
push {r5-r7}
sub sp, 0xC
mov r8, r0
mov r10, r1
str r2, [sp]
ldr r5, [r0, 0x14]
ldrb r3, [r0, 0x1]
movs r0, 0
str r0, [sp, 0x4]
mov r9, r0
cmp r5, 0
beq _0803535A
_080352E0:
lsls r0, r3, 3
adds r1, r0, 0
adds r1, 0x39
ldr r2, =gMain
adds r7, r1, r2
adds r0, 0x3C
adds r6, r0, r2
_080352EE:
mov r0, r10
adds r1, r5, 0
str r3, [sp, 0x8]
bl __udivsi3
adds r4, r0, 0
adds r0, r4, 0
muls r0, r5
mov r1, r10
subs r1, r0
mov r10, r1
adds r0, r5, 0
movs r1, 0xA
bl __udivsi3
adds r5, r0, 0
ldr r3, [sp, 0x8]
cmp r4, 0
bne _0803531E
ldr r2, [sp, 0x4]
cmp r2, 0
bne _0803531E
cmp r5, 0
bne _080352E0
_0803531E:
movs r0, 0x1
str r0, [sp, 0x4]
mov r1, r8
ldrb r0, [r1, 0x9]
adds r2, r4, 0
muls r2, r0
ldrh r4, [r1, 0xA]
adds r2, r4
ldr r1, =0x000003ff
adds r0, r1, 0
ands r2, r0
ldrh r0, [r6]
ldr r4, =0xfffffc00
adds r1, r4, 0
ands r0, r1
orrs r0, r2
strh r0, [r6]
ldrb r0, [r7]
movs r2, 0x4
negs r2, r2
adds r1, r2, 0
ands r0, r1
strb r0, [r7]
adds r7, 0x8
adds r6, 0x8
adds r3, 0x1
movs r4, 0x1
add r9, r4
cmp r5, 0
bne _080352EE
_0803535A:
mov r0, r8
ldrb r0, [r0, 0x3]
cmp r9, r0
bge _0803538A
ldr r1, =gMain
movs r5, 0x4
negs r5, r5
movs r4, 0x2
lsls r0, r3, 3
adds r0, 0x39
adds r2, r0, r1
_08035370:
ldrb r1, [r2]
adds r0, r5, 0
ands r0, r1
orrs r0, r4
strb r0, [r2]
adds r2, 0x8
adds r3, 0x1
movs r1, 0x1
add r9, r1
mov r0, r8
ldrb r0, [r0, 0x3]
cmp r9, r0
blt _08035370
_0803538A:
ldr r1, [sp]
cmp r1, 0
beq _080353B0
lsls r0, r3, 3
ldr r2, =gMain
adds r0, r2
adds r0, 0x39
ldrb r2, [r0]
movs r1, 0x4
negs r1, r1
ands r1, r2
strb r1, [r0]
b _080353C6
.pool
_080353B0:
lsls r2, r3, 3
ldr r4, =gMain
adds r2, r4
adds r2, 0x39
ldrb r1, [r2]
movs r0, 0x4
negs r0, r0
ands r0, r1
movs r1, 0x2
orrs r0, r1
strb r0, [r2]
_080353C6:
add sp, 0xC
pop {r3-r5}
mov r8, r3
mov r9, r4
mov r10, r5
pop {r4-r7}
pop {r0}
bx r0
.pool
thumb_func_end sub_80352C0
thumb_func_start sub_80353DC
sub_80353DC: @ 80353DC
push {r4-r7,lr}
adds r4, r0, 0
ldr r0, =gUnknown_02022E10
ldr r0, [r0]
cmp r0, 0
beq _0803546E
ldr r2, [r0, 0x4]
lsls r1, r4, 3
subs r0, r1, r4
lsls r0, 2
adds r2, r0, r2
ldrb r0, [r2]
adds r5, r1, 0
cmp r0, 0
beq _0803546E
ldrb r3, [r2, 0x3]
adds r0, r3, 0x1
ldrb r2, [r2, 0x1]
cmp r0, 0
beq _08035426
ldr r1, =gMain
movs r7, 0x4
negs r7, r7
movs r6, 0x2
adds r3, r0, 0
lsls r0, r2, 3
adds r0, 0x39
adds r2, r0, r1
_08035414:
ldrb r1, [r2]
adds r0, r7, 0
ands r0, r1
orrs r0, r6
strb r0, [r2]
subs r3, 0x1
adds r2, 0x8
cmp r3, 0
bne _08035414
_08035426:
adds r0, r4, 0
bl sub_8035570
cmp r0, 0
bne _08035442
ldr r0, =gUnknown_02022E10
ldr r0, [r0]
ldr r1, [r0, 0x4]
subs r0, r5, r4
lsls r0, 2
adds r0, r1
ldrh r0, [r0, 0x10]
bl FreeSpriteTilesByTag
_08035442:
adds r0, r4, 0
bl sub_80355B4
cmp r0, 0
bne _0803545E
ldr r0, =gUnknown_02022E10
ldr r0, [r0]
ldr r1, [r0, 0x4]
subs r0, r5, r4
lsls r0, 2
adds r0, r1
ldrh r0, [r0, 0x12]
bl FreeSpritePaletteByTag
_0803545E:
ldr r0, =gUnknown_02022E10
ldr r0, [r0]
ldr r1, [r0, 0x4]
subs r0, r5, r4
lsls r0, 2
adds r0, r1
movs r1, 0
strb r1, [r0]
_0803546E:
pop {r4-r7}
pop {r0}
bx r0
.pool
thumb_func_end sub_80353DC
thumb_func_start sub_803547C
sub_803547C: @ 803547C
push {r4-r7,lr}
adds r4, r0, 0
adds r5, r1, 0
ldr r0, =gUnknown_02022E10
ldr r1, [r0]
adds r7, r0, 0
cmp r1, 0
beq _0803550C
ldr r2, [r1, 0x4]
lsls r1, r4, 3
subs r0, r1, r4
lsls r0, 2
adds r2, r0, r2
ldrb r0, [r2]
adds r6, r1, 0
cmp r0, 0
beq _0803550C
ldrb r3, [r2, 0x3]
adds r1, r3, 0x1
ldrb r0, [r2, 0x1]
cmp r5, 0
beq _080354D8
cmp r1, 0
beq _0803550C
ldr r1, =gMain
movs r5, 0x4
negs r5, r5
movs r4, 0x2
adds r3, 0x1
lsls r0, 3
adds r0, 0x39
adds r2, r0, r1
_080354BC:
ldrb r1, [r2]
adds r0, r5, 0
ands r0, r1
orrs r0, r4
strb r0, [r2]
subs r3, 0x1
adds r2, 0x8
cmp r3, 0
bne _080354BC
b _0803550C
.pool
_080354D8:
cmp r1, 0
beq _080354FA
ldr r1, =gMain
movs r5, 0x4
negs r5, r5
adds r3, 0x1
lsls r0, 3
adds r0, 0x39
adds r2, r0, r1
_080354EA:
ldrb r1, [r2]
adds r0, r5, 0
ands r0, r1
strb r0, [r2]
subs r3, 0x1
adds r2, 0x8
cmp r3, 0
bne _080354EA
_080354FA:
ldr r0, [r7]
ldr r1, [r0, 0x4]
subs r0, r6, r4
lsls r0, 2
adds r0, r1
ldr r1, [r0, 0x18]
adds r0, r4, 0
bl sub_8035044
_0803550C:
pop {r4-r7}
pop {r0}
bx r0
.pool
thumb_func_end sub_803547C
thumb_func_start sub_8035518
sub_8035518: @ 8035518
push {r4,r5,lr}
lsls r0, 24
lsrs r4, r0, 24
movs r5, 0x40
movs r3, 0
ldr r0, =gUnknown_02022E10
ldr r0, [r0]
ldr r2, [r0]
cmp r3, r2
bcs _0803555A
ldr r1, [r0, 0x4]
_0803552E:
ldrb r0, [r1]
cmp r0, 0
bne _08035548
ldrb r0, [r1, 0x1]
cmp r0, 0xFF
beq _08035552
ldrb r0, [r1, 0x3]
cmp r0, r4
bhi _08035552
ldrb r0, [r1, 0x1]
b _0803556A
.pool
_08035548:
adds r0, r5, 0x1
ldrb r5, [r1, 0x3]
adds r0, r5
lsls r0, 16
lsrs r5, r0, 16
_08035552:
adds r1, 0x1C
adds r3, 0x1
cmp r3, r2
bcc _0803552E
_0803555A:
adds r0, r5, r4
adds r0, 0x1
cmp r0, 0x80
bgt _08035568
lsls r0, r5, 24
lsrs r0, 24
b _0803556A
_08035568:
movs r0, 0xFF
_0803556A:
pop {r4,r5}
pop {r1}
bx r1
thumb_func_end sub_8035518
thumb_func_start sub_8035570
sub_8035570: @ 8035570
push {r4-r6,lr}
adds r3, r0, 0
movs r2, 0
ldr r0, =gUnknown_02022E10
ldr r0, [r0]
ldr r4, [r0]
cmp r2, r4
bcs _080355AC
ldr r1, [r0, 0x4]
lsls r0, r3, 3
subs r0, r3
lsls r0, 2
adds r5, r0, r1
_0803558A:
ldrb r0, [r1]
cmp r0, 0
beq _080355A4
cmp r2, r3
beq _080355A4
ldrh r0, [r1, 0x10]
ldrh r6, [r5, 0x10]
cmp r0, r6
bne _080355A4
movs r0, 0x1
b _080355AE
.pool
_080355A4:
adds r1, 0x1C
adds r2, 0x1
cmp r2, r4
bcc _0803558A
_080355AC:
movs r0, 0
_080355AE:
pop {r4-r6}
pop {r1}
bx r1
thumb_func_end sub_8035570
thumb_func_start sub_80355B4
sub_80355B4: @ 80355B4
push {r4-r6,lr}
adds r3, r0, 0
movs r2, 0
ldr r0, =gUnknown_02022E10
ldr r0, [r0]
ldr r4, [r0]
cmp r2, r4
bcs _080355F0
ldr r1, [r0, 0x4]
lsls r0, r3, 3
subs r0, r3
lsls r0, 2
adds r5, r0, r1
_080355CE:
ldrb r0, [r1]
cmp r0, 0
beq _080355E8
cmp r2, r3
beq _080355E8
ldrh r0, [r1, 0x12]
ldrh r6, [r5, 0x12]
cmp r0, r6
bne _080355E8
movs r0, 0x1
b _080355F2
.pool
_080355E8:
adds r1, 0x1C
adds r2, 0x1
cmp r2, r4
bcc _080355CE
_080355F0:
movs r0, 0
_080355F2:
pop {r4-r6}
pop {r1}
bx r1
thumb_func_end sub_80355B4
thumb_func_start sub_80355F8
sub_80355F8: @ 80355F8
ldr r2, =gUnknown_082FF1C8
lsls r0, 2
adds r1, r0
adds r1, r2
ldrb r0, [r1]
bx lr
.pool
thumb_func_end sub_80355F8
thumb_func_start sub_8035608
sub_8035608: @ 8035608
push {lr}
bl ResetSpriteData
ldr r0, =gUnknown_0831AC88
movs r1, 0
movs r2, 0
movs r3, 0
bl CreateSprite
lsls r0, 24
lsrs r0, 24
ldr r2, =gSprites
lsls r1, r0, 4
adds r1, r0
lsls r1, 2
adds r1, r2
adds r1, 0x3E
ldrb r0, [r1]
movs r2, 0x4
orrs r0, r2
strb r0, [r1]
ldr r0, =sub_8035648
bl SetMainCallback2
pop {r0}
bx r0
.pool
thumb_func_end sub_8035608
thumb_func_start sub_8035648
sub_8035648: @ 8035648
push {lr}
bl AnimateSprites
bl BuildOamBuffer
pop {r0}
bx r0
thumb_func_end sub_8035648
.align 2, 0 @ Don't pad with nop.

View File

@ -1,12 +0,0 @@
.include "asm/macros.inc"
.include "constants/constants.inc"
.section .rodata
.align 2
gUnknown_082FF1C8:: @ 82FF1C8
.byte 0x01, 0x04, 0x10, 0x40
.byte 0x02, 0x04, 0x08, 0x20
.byte 0x02, 0x04, 0x08, 0x20
.byte 0x00, 0x00, 0x00, 0x00

View File

@ -28,6 +28,6 @@ void LoadSpecialPokePic(const struct CompressedSpriteSheet *src, void *dest, s32
void LoadSpecialPokePic_2(const struct CompressedSpriteSheet *src, void *dest, s32 species, u32 personality, bool8 isFrontPic);
void LoadSpecialPokePic_DontHandleDeoxys(const struct CompressedSpriteSheet *src, void *dest, s32 species, u32 personality, bool8 isFrontPic);
u32 sub_8034974(const u8 *ptr);
u32 GetDecompressedDataSize(const u8 *ptr);
#endif // GUARD_DECOMPRESS_H

26
include/rom_8034C54.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef GUARD_ROM_8034C54_H
#define GUARD_ROM_8034C54_H
struct UnkStruct3
{
u8 field_0_0:2;
u8 shape:2;
u8 size:2;
u8 priority:2;
u8 field_1;
u8 xDelta;
s16 x;
s16 y;
const struct SpriteSheet *spriteSheet;
const struct SpritePalette *spritePal;
};
bool32 sub_8034C54(u32 count);
void sub_8034CC8(void);
bool32 sub_8034D14(u32 id, s32 arg1, const struct UnkStruct3 *arg2);
void sub_8035044(u32 id, s32 arg1);
void sub_80353DC(u32 id);
void sub_803547C(u32 id, bool32 arg1);
u8 sub_80355F8(u32 arg0, u32 arg1);
#endif // GUARD_ROM_8034C54_H

View File

@ -60,7 +60,7 @@ SECTIONS {
src/main_menu.o(.text);
src/battle_controllers.o(.text);
src/decompress.o(.text);
asm/rom_8034C54.o(.text);
src/rom_8034C54.o(.text);
src/battle_bg.o(.text);
src/battle_main.o(.text);
src/battle_util.o(.text);
@ -371,7 +371,7 @@ SECTIONS {
data/rom_8011DC0.o(.rodata);
src/rtc.o(.rodata);
src/main_menu.o(.rodata);
data/battle_1.o(.rodata);
src/rom_8034C54.o(.rodata);
data/data2b.o(.rodata);
src/battle_main.o(.rodata);
src/battle_util.o(.rodata);

View File

@ -1,29 +1,15 @@
#include "global.h"
#include "rom_8034C54.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;
bool8 isActive;
u8 firstOamId;
u8 field_2;
u8 field_3;
u8 oamCount;
u8 palTagIndex;
u8 size;
u8 shape;
@ -36,31 +22,42 @@ struct UnkStruct2
u16 tileTag;
u16 palTag;
u32 field_14;
u8 field_18;
u8 field_19;
u8 field_1A;
u8 field_1B;
s32 field_18;
};
struct UnkStruct1
{
u32 count;
struct UnkStruct2 *field_4;
struct UnkStruct2 *array;
};
IWRAM_DATA u32 gUnknown_03000DD4;
IWRAM_DATA u32 gUnknown_03000DD8;
IWRAM_DATA u32 gUnknown_03000DDC;
extern struct UnkStruct1 *gUnknown_02022E10;
extern const struct SpriteTemplate gUnknown_0831AC88;
// 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);
static u8 sub_8035518(u8 arg0);;
static void sub_8034EFC(struct UnkStruct2 *arg0);
static void sub_80350B0(struct UnkStruct2 *arg0, s32 arg1, bool32 arg2);
static void sub_8035164(struct UnkStruct2 *arg0, s32 arg1, bool32 arg2);
static void sub_80352C0(struct UnkStruct2 *arg0, s32 arg1, bool32 arg2);
static bool32 SharesTileWithAnyActive(u32 id);
static bool32 SharesPalWithAnyActive(u32 id);
static void sub_8035648(void);
// iwram
static IWRAM_DATA s32 gUnknown_03000DD4;
static IWRAM_DATA s32 gUnknown_03000DD8;
static IWRAM_DATA s32 gUnknown_03000DDC;
// const rom data
static const u8 gUnknown_082FF1C8[][4] =
{
{0x01, 0x04, 0x10, 0x40},
{0x02, 0x04, 0x08, 0x20},
{0x02, 0x04, 0x08, 0x20},
{0x00, 0x00, 0x00, 0x00}
};
// code
bool32 sub_8034C54(u32 count)
@ -74,8 +71,8 @@ bool32 sub_8034C54(u32 count)
if (gUnknown_02022E10 == NULL)
return FALSE;
gUnknown_02022E10->field_4 = Alloc(sizeof(struct UnkStruct2) * count);
if (gUnknown_02022E10->field_4 == NULL)
gUnknown_02022E10->array = Alloc(sizeof(struct UnkStruct2) * count);
if (gUnknown_02022E10->array == NULL)
{
Free(gUnknown_02022E10);
return FALSE;
@ -84,8 +81,8 @@ bool32 sub_8034C54(u32 count)
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;
gUnknown_02022E10->array[i].isActive = FALSE;
gUnknown_02022E10->array[i].firstOamId |= 0xFF;
}
return TRUE;
@ -95,39 +92,39 @@ void sub_8034CC8(void)
{
if (gUnknown_02022E10 != NULL)
{
if (gUnknown_02022E10->field_4 != NULL)
if (gUnknown_02022E10->array != NULL)
{
u32 i;
for (i = 0; i < gUnknown_02022E10->count; i++)
sub_80353DC(i);
Free(gUnknown_02022E10->field_4);
Free(gUnknown_02022E10->array);
}
FREE_AND_SET_NULL(gUnknown_02022E10);
}
}
bool32 sub_8034D14(u32 id, u32 arg1, const struct UnkStruct3 *arg2)
bool32 sub_8034D14(u32 id, s32 arg1, const struct UnkStruct3 *arg2)
{
u32 i;
if (gUnknown_02022E10 == NULL)
return FALSE;
if (gUnknown_02022E10->field_4[id].field_0 != 0)
if (gUnknown_02022E10->array[id].isActive)
return FALSE;
gUnknown_02022E10->field_4[id].field_1 = sub_8035518(arg2->field_1);
if (gUnknown_02022E10->field_4[id].field_1 == 0xFF)
gUnknown_02022E10->array[id].firstOamId = sub_8035518(arg2->field_1);
if (gUnknown_02022E10->array[id].firstOamId == 0xFF)
return FALSE;
gUnknown_02022E10->field_4[id].tileStart = GetSpriteTileStartByTag(arg2->spriteSheet->tag);
if (gUnknown_02022E10->field_4[id].tileStart == 0xFFFF)
gUnknown_02022E10->array[id].tileStart = GetSpriteTileStartByTag(arg2->spriteSheet->tag);
if (gUnknown_02022E10->array[id].tileStart == 0xFFFF)
{
if (arg2->spriteSheet->size != 0)
{
gUnknown_02022E10->field_4[id].tileStart = LoadSpriteSheet(arg2->spriteSheet);
gUnknown_02022E10->array[id].tileStart = LoadSpriteSheet(arg2->spriteSheet);
}
else
{
@ -135,63 +132,322 @@ bool32 sub_8034D14(u32 id, u32 arg1, const struct UnkStruct3 *arg2)
compSpriteSheet = *(struct CompressedSpriteSheet*)(arg2->spriteSheet);
compSpriteSheet.size = GetDecompressedDataSize(arg2->spriteSheet->data);
gUnknown_02022E10->field_4[id].tileStart = LoadCompressedObjectPic(&compSpriteSheet);
gUnknown_02022E10->array[id].tileStart = LoadCompressedObjectPic(&compSpriteSheet);
}
if (gUnknown_02022E10->field_4[id].tileStart == 0xFFFF)
if (gUnknown_02022E10->array[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->array[id].palTagIndex = IndexOfSpritePaletteTag(arg2->spritePal->tag);
if (gUnknown_02022E10->array[id].palTagIndex == 0xFF)
gUnknown_02022E10->array[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;
gUnknown_02022E10->array[id].field_2 = arg2->field_0_0;
gUnknown_02022E10->array[id].oamCount = arg2->field_1;
gUnknown_02022E10->array[id].x = arg2->x;
gUnknown_02022E10->array[id].y = arg2->y;
gUnknown_02022E10->array[id].shape = arg2->shape;
gUnknown_02022E10->array[id].size = arg2->size;
gUnknown_02022E10->array[id].priority = arg2->priority;
gUnknown_02022E10->array[id].xDelta = arg2->xDelta;
gUnknown_02022E10->array[id].field_9 = sub_80355F8(arg2->shape, arg2->size);
gUnknown_02022E10->array[id].tileTag = arg2->spriteSheet->tag;
gUnknown_02022E10->array[id].palTag = arg2->spritePal->tag;
gUnknown_02022E10->array[id].isActive = TRUE;
gUnknown_02022E10->array[id].field_14 = 1;
for (i = 1; i < arg2->field_1; i++)
gUnknown_02022E10->field_4[id].field_14 *= 10;
gUnknown_02022E10->array[id].field_14 *= 10;
sub_8034EFC(&gUnknown_02022E10->field_4[id]);
sub_8034EFC(&gUnknown_02022E10->array[id]);
sub_8035044(id, arg1);
return TRUE;
}
void sub_8034EFC(struct UnkStruct2 *arg0)
static void sub_8034EFC(struct UnkStruct2 *arg0)
{
u32 i;
u32 r5 = arg0->field_1;
u32 oamId = arg0->firstOamId;
u32 x = arg0->x;
u32 r8 = arg0->field_3 + 1;
u32 oamCount = arg0->oamCount + 1;
CpuFill16(0, &gMain.oamBuffer[r5], sizeof(struct OamData) * r8);
for (i = 0, r5 = arg0->field_1; i < r8; i++, r5++)
CpuFill16(0, &gMain.oamBuffer[oamId], sizeof(struct OamData) * oamCount);
for (i = 0, oamId = arg0->firstOamId; i < oamCount; i++, oamId++)
{
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;
gMain.oamBuffer[oamId].y = arg0->y;
gMain.oamBuffer[oamId].x = x;
gMain.oamBuffer[oamId].shape = arg0->shape;
gMain.oamBuffer[oamId].size = arg0->size;
gMain.oamBuffer[oamId].tileNum = arg0->tileStart;
gMain.oamBuffer[oamId].priority = arg0->priority;
gMain.oamBuffer[oamId].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);
oamId--;
gMain.oamBuffer[oamId].x = arg0->x - arg0->xDelta;
gMain.oamBuffer[oamId].affineMode = 2;
gMain.oamBuffer[oamId].tileNum = arg0->tileStart + (arg0->field_9 * 10);
}
void sub_8035044(u32 id, s32 arg1)
{
bool32 r2;
if (gUnknown_02022E10 == NULL)
return;
if (!gUnknown_02022E10->array[id].isActive)
return;
gUnknown_02022E10->array[id].field_18 = arg1;
if (arg1 < 0)
{
r2 = TRUE;
arg1 *= -1;
}
else
{
r2 = FALSE;
}
switch (gUnknown_02022E10->array[id].field_2)
{
case 0:
default:
sub_80350B0(&gUnknown_02022E10->array[id], arg1, r2);
break;
case 1:
sub_8035164(&gUnknown_02022E10->array[id], arg1, r2);
break;
case 2:
sub_80352C0(&gUnknown_02022E10->array[id], arg1, r2);
break;
}
}
static void sub_80350B0(struct UnkStruct2 *arg0, s32 arg1, bool32 arg2)
{
u32 r5 = arg0->field_14;
u32 oamId = arg0->firstOamId;
while (r5 != 0)
{
u32 r4 = arg1 / r5;
arg1 -= (r4 * r5);
r5 /= 10;
gMain.oamBuffer[oamId].tileNum = (r4 * arg0->field_9) + arg0->tileStart;
oamId++;
}
if (arg2)
gMain.oamBuffer[oamId].affineMode = 0;
else
gMain.oamBuffer[oamId].affineMode = 2;
}
static void sub_8035164(struct UnkStruct2 *arg0, s32 arg1, bool32 arg2)
{
u32 r5 = arg0->field_14;
gUnknown_03000DD4 = arg0->firstOamId;
gUnknown_03000DD8 = 0;
gUnknown_03000DDC = -1;
while (r5 != 0)
{
u32 r4 = arg1 / r5;
arg1 -= (r4 * r5);
r5 /= 10;
if (r4 != 0 || gUnknown_03000DDC != -1 || r5 == 0)
{
gMain.oamBuffer[gUnknown_03000DD4].tileNum = (r4 * arg0->field_9) + arg0->tileStart;
gMain.oamBuffer[gUnknown_03000DD4].affineMode = 0;
if (gUnknown_03000DDC == -1)
gUnknown_03000DDC = gUnknown_03000DD8;
}
else
{
gMain.oamBuffer[gUnknown_03000DD4].affineMode = 2;
}
gUnknown_03000DD4++;
gUnknown_03000DD8++;
}
if (arg2)
{
gMain.oamBuffer[gUnknown_03000DD4].affineMode = 0;
gMain.oamBuffer[gUnknown_03000DD4].x = arg0->x + ((gUnknown_03000DDC - 1) * arg0->xDelta);
}
else
{
gMain.oamBuffer[gUnknown_03000DD4].affineMode = 2;
}
}
static void sub_80352C0(struct UnkStruct2 *arg0, s32 arg1, bool32 arg2)
{
u32 r5 = arg0->field_14;
u32 oamId = arg0->firstOamId;
u32 var_28 = 0;
s32 r9 = 0;
while (r5 != 0)
{
u32 r4 = arg1 / r5;
arg1 -= (r4 * r5);
r5 /= 10;
if (r4 != 0 || var_28 != 0 || r5 == 0)
{
var_28 = 1;
gMain.oamBuffer[oamId].tileNum = (r4 * arg0->field_9) + arg0->tileStart;
gMain.oamBuffer[oamId].affineMode = 0;
oamId++;
r9++;
}
}
while (r9 < arg0->oamCount)
{
gMain.oamBuffer[oamId].affineMode = 2;
oamId++;
r9++;
}
if (arg2)
gMain.oamBuffer[oamId].affineMode = 0;
else
gMain.oamBuffer[oamId].affineMode = 2;
}
void sub_80353DC(u32 id)
{
s32 oamId, oamCount, i;
if (gUnknown_02022E10 == NULL)
return;
if (!gUnknown_02022E10->array[id].isActive)
return;
oamCount = gUnknown_02022E10->array[id].oamCount + 1;
oamId = gUnknown_02022E10->array[id].firstOamId;
for (i = 0; i < oamCount; i++, oamId++)
gMain.oamBuffer[oamId].affineMode = 2;
if (!SharesTileWithAnyActive(id))
FreeSpriteTilesByTag(gUnknown_02022E10->array[id].tileTag);
if (!SharesPalWithAnyActive(id))
FreeSpritePaletteByTag(gUnknown_02022E10->array[id].palTag);
gUnknown_02022E10->array[id].isActive = FALSE;
}
void sub_803547C(u32 id, bool32 arg1)
{
s32 oamId, oamCount, i;
if (gUnknown_02022E10 == NULL)
return;
if (!gUnknown_02022E10->array[id].isActive)
return;
oamCount = gUnknown_02022E10->array[id].oamCount + 1;
oamId = gUnknown_02022E10->array[id].firstOamId;
if (arg1)
{
for (i = 0; i < oamCount; i++, oamId++)
gMain.oamBuffer[oamId].affineMode = 2;
}
else
{
for (i = 0; i < oamCount; i++, oamId++)
gMain.oamBuffer[oamId].affineMode = 0;
sub_8035044(id, gUnknown_02022E10->array[id].field_18);
}
}
static u8 sub_8035518(u8 arg0)
{
u32 i;
u16 oamCount = 64;
for (i = 0; i < gUnknown_02022E10->count; i++)
{
if (!gUnknown_02022E10->array[i].isActive)
{
if (gUnknown_02022E10->array[i].firstOamId != 0xFF && gUnknown_02022E10->array[i].oamCount <= arg0)
return gUnknown_02022E10->array[i].firstOamId;
}
else
{
oamCount += 1 + gUnknown_02022E10->array[i].oamCount;
}
}
if (oamCount + arg0 + 1 > 128)
return 0xFF;
else
return oamCount;
}
static bool32 SharesTileWithAnyActive(u32 id)
{
u32 i;
for (i = 0; i < gUnknown_02022E10->count; i++)
{
if (gUnknown_02022E10->array[i].isActive && i != id
&& gUnknown_02022E10->array[i].tileTag == gUnknown_02022E10->array[id].tileTag)
{
return TRUE;
}
}
return FALSE;
}
static bool32 SharesPalWithAnyActive(u32 id)
{
u32 i;
for (i = 0; i < gUnknown_02022E10->count; i++)
{
if (gUnknown_02022E10->array[i].isActive && i != id
&& gUnknown_02022E10->array[i].palTag == gUnknown_02022E10->array[id].palTag)
{
return TRUE;
}
}
return FALSE;
}
u8 sub_80355F8(u32 arg0, u32 arg1)
{
return gUnknown_082FF1C8[arg0][arg1];
}
static void sub_8035608(void)
{
u8 spriteId;
ResetSpriteData();
spriteId = CreateSprite(&gUnknown_0831AC88, 0, 0, 0);
gSprites[spriteId].invisible = 1;
SetMainCallback2(sub_8035648);
}
static void sub_8035648(void)
{
AnimateSprites();
BuildOamBuffer();
}