From a3c17fad22523551b78ba60321688f1ed1e39b6a Mon Sep 17 00:00:00 2001 From: KDSKardabox Date: Thu, 22 Feb 2018 12:17:46 +0530 Subject: [PATCH] Decompile Fossil Special & Groundshake Data --- asm/fossil_specials.s | 633 -------------- data/fossil_special_fldeff_groundshake.s | 98 --- include/fldeff_groundshake.h | 36 - ld_script.txt | 3 +- src/fldeff_groundshake.c | 123 ++- src/fldeff_sweetscent.c | 3 +- src/fossil_specials.c | 1006 +++++++++++++++++++++- 7 files changed, 1104 insertions(+), 798 deletions(-) delete mode 100644 data/fossil_special_fldeff_groundshake.s delete mode 100644 include/fldeff_groundshake.h diff --git a/asm/fossil_specials.s b/asm/fossil_specials.s index 77a0281c1..eb7cb8ada 100644 --- a/asm/fossil_specials.s +++ b/asm/fossil_specials.s @@ -5,639 +5,6 @@ .text - thumb_func_start sub_81BED50 -sub_81BED50: @ 81BED50 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x10 - lsls r0, 24 - lsrs r0, 24 - mov r10, r0 - ldr r1, =gTasks - lsls r0, 2 - add r0, r10 - lsls r0, 3 - adds r0, r1 - ldrh r0, [r0, 0x8] - subs r0, 0x1 - lsls r0, 16 - asrs r0, 16 - adds r6, r1, 0 - cmp r0, 0x7 - bls _081BED7C - b _081BF002 -_081BED7C: - lsls r0, 2 - ldr r1, =_081BED90 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081BED90: - .4byte _081BEDB0 - .4byte _081BF002 - .4byte _081BEDC4 - .4byte _081BEF64 - .4byte _081BEF94 - .4byte _081BEFD0 - .4byte _081BEFF0 - .4byte _081BEFF8 -_081BEDB0: - ldr r4, =gUnknown_0203CF10 - movs r0, 0xC0 - lsls r0, 2 - bl AllocZeroed - str r0, [r4] - b _081BF002 - .pool -_081BEDC4: - mov r1, r10 - lsls r0, r1, 2 - adds r1, r0, r1 - lsls r1, 3 - adds r2, r1, r6 - ldrh r3, [r2, 0xE] - movs r4, 0xE - ldrsh r1, [r2, r4] - str r0, [sp, 0x8] - cmp r1, 0x5F - bgt _081BEE8A - movs r1, 0xA - ldrsh r0, [r2, r1] - cmp r0, 0x1 - ble _081BEE7C - lsls r0, r3, 24 - lsrs r4, r0, 24 - movs r0, 0x30 - bl Alloc - ldr r3, =gUnknown_0203CF10 - ldr r1, [r3] - lsls r2, r4, 3 - adds r1, r2, r1 - str r0, [r1] - movs r5, 0 - adds r4, r2, 0 -_081BEDFA: - ldr r0, [r3] - adds r0, r4, r0 - ldr r0, [r0] - adds r0, r5 - strb r5, [r0] - adds r0, r5, 0x1 - lsls r0, 16 - lsrs r5, r0, 16 - cmp r5, 0x2F - bls _081BEDFA - movs r5, 0 - ldr r7, =gUnknown_0203CF10 - adds r6, r2, 0 -_081BEE14: - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x30 - bl __umodsi3 - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x30 - bl __umodsi3 - lsls r0, 16 - lsrs r0, 16 - ldr r1, [r7] - adds r1, r6, r1 - ldr r1, [r1] - adds r0, r1, r0 - ldrb r2, [r0] - adds r1, r4 - ldrb r1, [r1] - strb r1, [r0] - ldr r0, [r7] - adds r0, r6, r0 - ldr r0, [r0] - adds r0, r4 - strb r2, [r0] - adds r0, r5, 0x1 - lsls r0, 16 - lsrs r5, r0, 16 - cmp r5, 0x2F - bls _081BEE14 - ldr r0, =gTasks - ldr r1, [sp, 0x8] - add r1, r10 - lsls r1, 3 - adds r2, r1, r0 - ldrh r3, [r2, 0xE] - movs r4, 0xE - ldrsh r1, [r2, r4] - adds r6, r0, 0 - cmp r1, 0x5F - bgt _081BEE78 - adds r0, r3, 0x1 - strh r0, [r2, 0xE] -_081BEE78: - movs r0, 0 - strh r0, [r2, 0xA] -_081BEE7C: - ldr r1, [sp, 0x8] - add r1, r10 - lsls r1, 3 - adds r1, r6 - ldrh r0, [r1, 0xA] - adds r0, 0x1 - strh r0, [r1, 0xA] -_081BEE8A: - ldr r0, [sp, 0x8] - add r0, r10 - lsls r0, 3 - adds r0, r6 - ldrb r4, [r0, 0xE] - ldrb r5, [r0, 0xC] - lsls r0, r4, 16 - cmp r5, r4 - bcs _081BEF32 - str r0, [sp, 0xC] -_081BEE9E: - movs r6, 0 - adds r0, r5, 0x1 - str r0, [sp, 0x4] - lsls r4, r5, 3 - movs r2, 0x5F - subs r1, r2, r5 - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 4 - mov r9, r0 -_081BEEB2: - ldr r0, =gUnknown_0203CF04 - ldr r0, [r0] - ldr r7, =gUnknown_0203CF10 - ldr r3, [r7] - adds r3, r4, r3 - ldrb r2, [r3, 0x4] - adds r1, r2, 0x1 - strb r1, [r3, 0x4] - lsls r2, 24 - lsrs r2, 24 - ldr r1, [r3] - adds r1, r2 - ldrb r1, [r1] - add r1, r9 - lsls r1, 16 - lsrs r1, 16 - movs r2, 0x1 - mov r8, r2 - str r2, [sp] - movs r2, 0 - movs r3, 0x30 - bl sub_81BF2B8 - adds r0, r6, 0x1 - lsls r0, 24 - lsrs r6, r0, 24 - cmp r6, 0 - beq _081BEEB2 - ldr r0, [r7] - adds r1, r4, r0 - ldrb r0, [r1, 0x4] - cmp r0, 0x2F - bls _081BEF24 - ldr r0, [r1] - bl Free - ldr r0, [r7] - adds r0, r4, r0 - movs r1, 0 - str r1, [r0] - ldr r1, [sp, 0x8] - add r1, r10 - lsls r1, 3 - ldr r4, =gTasks - adds r1, r4 - ldrh r0, [r1, 0xC] - adds r0, 0x1 - strh r0, [r1, 0xC] - mov r0, r8 - ands r5, r0 - cmp r5, 0x1 - bne _081BEF24 - ldr r0, =gUnknown_0203CF14 - ldr r1, [r0] - ldrh r0, [r1, 0x2] - subs r0, 0x1 - strh r0, [r1, 0x2] -_081BEF24: - ldr r1, [sp, 0x4] - lsls r0, r1, 16 - lsrs r5, r0, 16 - ldr r2, [sp, 0xC] - lsrs r0, r2, 16 - cmp r5, r0 - bcc _081BEE9E -_081BEF32: - ldr r0, =gUnknown_0203CF04 - ldr r1, [r0] - movs r2, 0x92 - lsls r2, 4 - movs r0, 0 - movs r3, 0 - bl LoadBgTiles - ldr r0, =gUnknown_0203CF10 - ldr r0, [r0] - movs r4, 0xBE - lsls r4, 2 - adds r0, r4 - ldrb r0, [r0, 0x4] - cmp r0, 0x2F - bhi _081BF002 - b _081BF014 - .pool -_081BEF64: - movs r0, 0 - bl UnsetBgTilemapBuffer - ldr r0, =sub_81BEBB4 - bl FindTaskIdByFunc - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0xFF - beq _081BEF7C - bl DestroyTask -_081BEF7C: - ldr r0, =gUnknown_0203CF14 - ldr r1, [r0] - movs r0, 0 - strh r0, [r1] - strh r0, [r1, 0x2] - bl sub_81BEB90 - b _081BF002 - .pool -_081BEF94: - ldr r4, =gUnknown_0203CF14 - ldr r0, [r4] - bl Free - movs r5, 0 - str r5, [r4] - ldr r4, =gUnknown_0203CF10 - ldr r0, [r4] - bl Free - str r5, [r4] - ldr r4, =gUnknown_0203CF04 - ldr r0, [r4] - bl Free - str r5, [r4] - ldr r4, =gUnknown_0203CF08 - ldr r0, [r4] - bl Free - str r5, [r4] - b _081BF002 - .pool -_081BEFD0: - movs r0, 0xC - movs r1, 0x2 - bl SetGpuRegBits - movs r0, 0x8 - movs r1, 0 - bl SetGpuRegBits - movs r0, 0 - movs r1, 0x7 - movs r2, 0 - bl SetBgAttribute - bl sub_81971D0 - b _081BF002 -_081BEFF0: - movs r0, 0 - bl ShowBg - b _081BF002 -_081BEFF8: - mov r0, r10 - bl DestroyTask - bl EnableBothScriptContexts -_081BF002: - ldr r0, =gTasks - mov r2, r10 - lsls r1, r2, 2 - add r1, r10 - lsls r1, 3 - adds r1, r0 - ldrh r0, [r1, 0x8] - adds r0, 0x1 - strh r0, [r1, 0x8] -_081BF014: - add sp, 0x10 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81BED50 - - thumb_func_start sub_81BF028 -sub_81BF028: @ 81BF028 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x18 - lsls r0, 24 - lsrs r7, r0, 24 - ldr r1, =gTasks - lsls r0, r7, 2 - adds r0, r7 - lsls r0, 3 - adds r0, r1 - ldrh r0, [r0, 0x8] - subs r0, 0x1 - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x7 - bls _081BF04C - b _081BF228 -_081BF04C: - lsls r0, 2 - ldr r1, =_081BF060 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081BF060: - .4byte _081BF080 - .4byte _081BF0B4 - .4byte _081BF0DC - .4byte _081BF0F0 - .4byte _081BF148 - .4byte _081BF170 - .4byte _081BF1CC - .4byte _081BF224 -_081BF080: - ldr r4, =gUnknown_0203CF0C - movs r0, 0x14 - bl AllocZeroed - str r0, [r4] - movs r0, 0x80 - bl AllocZeroed - ldr r1, [r4] - str r0, [r1] - movs r0, 0x8 - bl AllocZeroed - ldr r1, [r4] - str r0, [r1, 0x4] - movs r0, 0x80 - lsls r0, 2 - bl AllocZeroed - ldr r1, [r4] - str r0, [r1, 0xC] - movs r0, 0 - strh r0, [r1, 0x10] - b _081BF228 - .pool -_081BF0B4: - ldr r0, =gUnknown_0203CF0C - ldr r0, [r0] - ldr r1, [r0] - movs r5, 0 - ldr r2, =gRootFossil_Gfx -_081BF0BE: - adds r0, r5, r2 - ldrb r0, [r0] - strb r0, [r1] - adds r0, r5, 0x1 - lsls r0, 16 - lsrs r5, r0, 16 - adds r1, 0x1 - cmp r5, 0x7F - bls _081BF0BE - b _081BF228 - .pool -_081BF0DC: - ldr r0, =gUnknown_0203CF0C - ldr r0, [r0] - ldr r1, [r0, 0x4] - ldr r0, [r0] - str r0, [r1] - movs r0, 0x80 - strh r0, [r1, 0x4] - b _081BF228 - .pool -_081BF0F0: - mov r1, sp - ldr r0, =gUnknown_08617E00 - ldm r0!, {r2-r4} - stm r1!, {r2-r4} - ldm r0!, {r2-r4} - stm r1!, {r2-r4} - ldr r4, =gUnknown_0203CF0C - ldr r0, [r4] - ldr r0, [r0, 0x4] - str r0, [sp, 0xC] - movs r2, 0x10 - negs r2, r2 - mov r0, sp - movs r1, 0x80 - movs r3, 0x1 - bl CreateSprite - ldr r1, [r4] - movs r3, 0 - strb r0, [r1, 0x8] - ldr r2, =gSprites - ldr r0, [r4] - ldrb r1, [r0, 0x8] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r0, r2 - adds r0, 0x28 - strb r3, [r0] - ldr r3, [r4] - ldrb r1, [r3, 0x8] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r0, r2 - ldrh r1, [r0, 0x20] - strh r1, [r0, 0x2E] - ldrb r1, [r3, 0x8] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r0, r2 - movs r1, 0x1 - strh r1, [r0, 0x30] -_081BF148: - movs r5, 0 - ldr r2, =gUnknown_0203CF0C -_081BF14C: - ldr r0, [r2] - ldr r1, [r0, 0xC] - lsls r0, r5, 1 - adds r0, r1 - strh r5, [r0] - adds r0, r5, 0x1 - lsls r0, 16 - lsrs r5, r0, 16 - cmp r5, 0xFF - bls _081BF14C - b _081BF228 - .pool -_081BF170: - movs r5, 0 - movs r6, 0xFF - ldr r0, =0x000001ff - mov r8, r0 -_081BF178: - bl Random - adds r4, r6, 0 - ands r4, r0 - bl Random - adds r1, r6, 0 - ands r1, r0 - ldr r0, =gUnknown_0203CF0C - ldr r3, [r0] - ldr r0, [r3, 0xC] - lsls r1, 1 - adds r1, r0 - ldrh r2, [r1] - lsls r4, 1 - adds r4, r0 - ldrh r0, [r4] - strh r0, [r1] - strh r2, [r4] - adds r0, r5, 0x1 - lsls r0, 16 - lsrs r5, r0, 16 - cmp r5, r8 - bls _081BF178 - ldr r2, =gSprites - ldrb r1, [r3, 0x8] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r2, 0x1C - adds r0, r2 - ldr r1, =sub_81BF248 - str r1, [r0] - b _081BF228 - .pool -_081BF1CC: - ldr r3, =gSprites - ldr r5, =gUnknown_0203CF0C - ldr r0, [r5] - ldrb r1, [r0, 0x8] - lsls r0, r1, 4 - adds r0, r1 - lsls r2, r0, 2 - adds r0, r3, 0 - adds r0, 0x1C - adds r0, r2, r0 - ldr r1, [r0] - ldr r0, =SpriteCallbackDummy - cmp r1, r0 - bne _081BF238 - adds r0, r2, r3 - bl DestroySprite - ldr r0, [r5] - ldr r0, [r0, 0xC] - bl Free - ldr r0, [r5] - movs r4, 0 - str r4, [r0, 0xC] - ldr r0, [r0, 0x4] - bl Free - ldr r0, [r5] - str r4, [r0, 0x4] - ldr r0, [r0] - bl Free - ldr r0, [r5] - str r4, [r0] - bl Free - str r4, [r5] - b _081BF228 - .pool -_081BF224: - bl EnableBothScriptContexts -_081BF228: - ldr r0, =gTasks - lsls r1, r7, 2 - adds r1, r7 - lsls r1, 3 - adds r1, r0 - ldrh r0, [r1, 0x8] - adds r0, 0x1 - strh r0, [r1, 0x8] -_081BF238: - add sp, 0x18 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81BF028 - - thumb_func_start sub_81BF248 -sub_81BF248: @ 81BF248 - push {r4,r5,lr} - sub sp, 0x4 - adds r5, r0, 0 - ldr r0, =gUnknown_0203CF0C - ldr r0, [r0] - ldrh r0, [r0, 0x10] - cmp r0, 0xFF - bls _081BF268 - ldr r0, =SpriteCallbackDummy - str r0, [r5, 0x1C] - b _081BF2B0 - .pool -_081BF268: - ldrh r1, [r5, 0x22] - movs r2, 0x22 - ldrsh r0, [r5, r2] - cmp r0, 0x5F - ble _081BF2AC - movs r4, 0 -_081BF274: - ldr r0, =gUnknown_0203CF0C - ldr r3, [r0] - ldr r0, [r3] - ldrh r1, [r3, 0x10] - adds r2, r1, 0x1 - strh r2, [r3, 0x10] - lsls r1, 16 - ldr r2, [r3, 0xC] - lsrs r1, 15 - adds r1, r2 - ldrh r1, [r1] - movs r2, 0 - str r2, [sp] - movs r3, 0x10 - bl sub_81BF2B8 - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x1 - bls _081BF274 - adds r0, r5, 0 - movs r1, 0 - bl StartSpriteAnim - b _081BF2B0 - .pool -_081BF2AC: - adds r0, r1, 0x1 - strh r0, [r5, 0x22] -_081BF2B0: - add sp, 0x4 - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_81BF248 - thumb_func_start sub_81BF2B8 sub_81BF2B8: @ 81BF2B8 push {r4-r7,lr} diff --git a/data/fossil_special_fldeff_groundshake.s b/data/fossil_special_fldeff_groundshake.s deleted file mode 100644 index 8fa546ce8..000000000 --- a/data/fossil_special_fldeff_groundshake.s +++ /dev/null @@ -1,98 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - - .align 2 -gUnknown_08617274:: @ 8617274 - .space 0x20 - .incbin "graphics/misc/mirage_tower.4bpp" - - .align 2 -gUnknown_08617B94:: @ 8617B94 - .incbin "graphics/misc/mirage_tower.bin" - - .align 2 -gRootFossil_Pal:: @ 8617C24 - .incbin "graphics/misc/fossil.gbapal" - - .align 2 -gRootFossil_Gfx:: @ 8617C44 - .incbin "graphics/misc/fossil.4bpp" - - .align 2 -gMirageTowerCrumbles_Gfx:: @ 8617CC4 - .incbin "graphics/misc/mirage_tower_crumbles.4bpp" - - .align 2 -gMirageTowerCrumbles_Palette:: @ 8617D44 - .incbin "graphics/misc/mirage_tower_crumbles.gbapal" - - .align 1 -gUnknown_08617D64:: @ 8617D64 - .2byte 0x0000, 0x000a, 0x0041, 0x0011, 0x0003, 0x0032, 0xfff4, 0x0000, 0x004b, 0x000a, 0x000f, 0x005a, 0x0007, 0x0008, 0x0041, 0xffee - .2byte 0x0005, 0x004b, 0x0016, 0xfff6, 0x0037, 0xffe8, 0xfffc, 0x0041 - - .align 2 -gUnknown_08617D94:: @ 8617D94 - obj_tiles gMirageTowerCrumbles_Gfx, 0x0080, 0x0fa0 - null_obj_tiles - - .align 2 -gUnknown_08617DA4:: @ 8617DA4 - .byte 0x12, 0x35, 0x51, 0x02, 0x13, 0x35, 0x51, 0x02, 0x14, 0x35, 0x51, 0x02, 0x12, 0x36, 0x51, 0x02, 0x13, 0x36, 0x51, 0x02, 0x14, 0x36, 0x51, 0x02, 0x12, 0x37, 0x51, 0x02, 0x13, 0x37, 0x51, 0x02 - .byte 0x14, 0x37, 0x51, 0x02, 0x12, 0x38, 0x51, 0x02, 0x13, 0x38, 0x51, 0x02, 0x14, 0x38, 0x51, 0x02, 0x12, 0x39, 0x59, 0x02, 0x13, 0x39, 0x59, 0x02, 0x14, 0x39, 0x59, 0x02, 0x12, 0x3a, 0x21, 0x01 - .byte 0x13, 0x3a, 0x21, 0x01, 0x14, 0x3a, 0x21, 0x01 - - .align 2 -gSpriteAnim_8617DEC:: @ 8617DEC - .2byte 0x0000, 0x0001, 0xffff, 0x0000 - - .align 2 -gOamData_8617DF4:: @ 8617DF4 - .2byte 0x0000, 0x4000, 0x3000, 0x0000 - - .align 2 -gSpriteAnimTable_8617DFC:: @ 8617DFC - .4byte gSpriteAnim_8617DEC - - .align 2 -gUnknown_08617E00:: @ 8617E00 - spr_template 0xffff, 0xffff, gOamData_8617DF4, gSpriteAnimTable_8617DFC, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy - - .align 2 -gUnknown_08617E18:: @ 8617E18 - .byte 0x3b, 0x43, 0x61, 0x00, 0x0f, 0x05, 0xff, 0x9b - - .align 2 -gSpriteAnim_8617E20:: @ 8617E20 - .2byte 0x0000, 0x000c, 0xfffe, 0x0000 - - .align 2 -gSpriteAnimTable_8617E28:: @ 8617E28 - .4byte gSpriteAnim_8617E20 - - .align 2 -gUnknown_08617E2C:: @ 8617E2C - .2byte 0x0000, 0x0000, 0x0000, 0x0000 - - .align 2 -gUnknown_08617E34:: @ 8617E34 - spr_template 0x0fa0, 0xffff, gUnknown_08617E2C, gSpriteAnimTable_8617E28, NULL, gDummySpriteAffineAnimTable, sub_81BEAD8 - - .align 2 -gSpriteAnim_8617E4C:: @ 8617E4C - .2byte 0x0000, 0x000c, 0xfffe, 0x0000 - - .align 2 -gSpriteAnim_8617E54:: @ 8617E54 - .4byte gSpriteAnim_8617E4C - - .align 2 -gOamData_8617E58:: @ 8617E58 - .2byte 0x0000, 0x4000, 0x0000, 0x0000 - - .align 2 -gUnknown_08617E60:: @ 8617E60 - spr_template 0x0fa0, 0xffff, gOamData_8617E58, gSpriteAnim_8617E54, NULL, gDummySpriteAffineAnimTable, sub_81BEAD8 - diff --git a/include/fldeff_groundshake.h b/include/fldeff_groundshake.h deleted file mode 100644 index 07fdaf9c2..000000000 --- a/include/fldeff_groundshake.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef GUARD_FLDEFF_GROUNDSHAKE_H -#define GUARD_FLDEFF_GROUNDSHAKE_H - -struct InnerStruct203CF18 -{ - u8 filler[0xC4]; -}; - - -struct Struct203CF18 { - u8 taskId; - struct InnerStruct203CF18 unk4; -}; //size = 0xC8 - - -void sub_8151B68(struct InnerStruct203CF18 *, const u8*); -void sub_8151B3C(struct InnerStruct203CF18 *); -void sub_8151CA8(struct InnerStruct203CF18 *, u8, u8); -void sub_8151C50(struct InnerStruct203CF18 *, u8, u8); -void sub_8151D28(struct InnerStruct203CF18 *, u8, u8); -void sub_8151E50(struct InnerStruct203CF18 *); - -void sub_81BE6B8(void); -void sub_81BE72C(void); -void sub_81BE808(u8 taskId); -void sub_81BE900(u8 taskId); -void sub_81BE968(void); -void sub_81BE9C0(u8 taskId); -void sub_81BEA00(u8 taskId); -void sub_81BEA20(void); - -extern struct Struct203CF18 *gUnknown_0203CF18; -extern const s16 gUnknown_08617D64[][3]; -extern const u8 gUnknown_08617E18[]; - -#endif // GUARD_FLDEFF_GROUNDSHAKE_H diff --git a/ld_script.txt b/ld_script.txt index b48552348..9116a9c89 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -531,7 +531,8 @@ SECTIONS { src/unk_text_util_2.o(.rodata); src/unk_81BAD84.o(.rodata); src/battle_controller_player_partner.o(.rodata); - data/fossil_special_fldeff_groundshake.o(.rodata); + src/fossil_specials.o(.rodata); + src/fldeff_groundshake.o(.rodata); src/berry_fix_program.o(.rodata); data/pokemon_summary_screen.o(.rodata); data/pokenav.o(.rodata); diff --git a/src/fldeff_groundshake.c b/src/fldeff_groundshake.c index 34524ffd5..92aaf5238 100644 --- a/src/fldeff_groundshake.c +++ b/src/fldeff_groundshake.c @@ -5,7 +5,6 @@ #include "event_data.h" #include "field_camera.h" #include "field_map_obj.h" -#include "fldeff_groundshake.h" #include "malloc.h" #include "random.h" #include "script.h" @@ -13,9 +12,109 @@ #include "sprite.h" #include "task.h" -extern const struct SpriteTemplate gUnknown_08617E34; -extern const struct SpriteTemplate gUnknown_08617E60; +// structures +struct InnerStruct203CF18 +{ + u8 filler[0xC4]; +}; +struct Struct203CF18 { + u8 taskId; + struct InnerStruct203CF18 unk4; +}; //size = 0xC8 + +// extern data +extern const struct SpriteSheet gUnknown_08617D94[]; +extern const s16 gUnknown_08617D64[][3]; + +// extern functions +extern void sub_8151B68(struct InnerStruct203CF18 *, const u8*); +extern void sub_8151B3C(struct InnerStruct203CF18 *); +extern void sub_8151CA8(struct InnerStruct203CF18 *, u8, u8); +extern void sub_8151C50(struct InnerStruct203CF18 *, u8, u8); +extern void sub_8151D28(struct InnerStruct203CF18 *, u8, u8); +extern void sub_8151E50(struct InnerStruct203CF18 *); + +// static functions +static void sub_81BE808(u8 taskId); +static void sub_81BE900(u8 taskId); +static void sub_81BE968(void); +static void sub_81BE9C0(u8 taskId); +static void sub_81BEA00(u8 taskId); +static void sub_81BEA20(void); +static void sub_81BEAD8(struct Sprite* sprite); + +//.rodata +static const u8 gUnknown_08617E18[] = {0x3b, 0x43, 0x61, 0x00, 0x0f, 0x05, 0xff, 0x9b}; + +static const union AnimCmd gSpriteAnim_8617E20[] = +{ + ANIMCMD_FRAME(0, 12), + ANIMCMD_JUMP(0), +}; + +static const union AnimCmd *const gSpriteAnimTable_8617E28[] = +{ + gSpriteAnim_8617E20, +}; + +static const struct OamData gUnknown_08617E2C = +{ + .y = 0, + .affineMode = 0, + .objMode = 0, + .mosaic = 0, + .bpp = 0, + .shape = 0, + .x = 0, + .matrixNum = 0, + .size = 0, + .tileNum = 0, + .priority = 0, + .paletteNum = 0, + .affineParam = 0, +}; + +static const struct SpriteTemplate gUnknown_08617E34 = { + 0x0FA0, 0xFFFF, &gUnknown_08617E2C, gSpriteAnimTable_8617E28, NULL, gDummySpriteAffineAnimTable, sub_81BEAD8 +}; + +static const union AnimCmd gSpriteAnim_8617E4C[] = +{ + ANIMCMD_FRAME(0, 12), + ANIMCMD_JUMP(0), +}; + +static const union AnimCmd *const gSpriteAnim_8617E54[] = +{ + gSpriteAnim_8617E4C, +}; + +static const struct OamData gSpriteAnim_8617E58 = +{ + .y = 0, + .affineMode = 0, + .objMode = 0, + .mosaic = 0, + .bpp = 0, + .shape = 0, + .x = 0, + .matrixNum = 0, + .size = 1, + .tileNum = 0, + .priority = 0, + .paletteNum = 0, + .affineParam = 0, +}; + +static const struct SpriteTemplate gUnknown_08617E60 = { + 0x0FA0, 0xFFFF, &gSpriteAnim_8617E58, gSpriteAnim_8617E54, NULL, gDummySpriteAffineAnimTable, sub_81BEAD8 +}; + +// ewram +EWRAM_DATA struct Struct203CF18 *gUnknown_0203CF18 = NULL; + +//text bool8 sub_81BE66C(void) { if (!(gSaveBlock1Ptr->location.mapGroup == 0x0 && gSaveBlock1Ptr->location.mapNum == 0x1A)) @@ -90,7 +189,7 @@ void sub_81BE7F4(void) CreateTask(sub_81BE808, 0x8); } -void sub_81BE808(u8 taskId) +static void sub_81BE808(u8 taskId) { u8 mapObjectIdBuffer; struct MapObject *fieldMapObject; @@ -109,7 +208,7 @@ void sub_81BE808(u8 taskId) } } -void sp136_strengh_sound(u8 a, u8 b, u8 c, u8 d) +static void sp136_strengh_sound(u8 a, u8 b, u8 c, u8 d) { u8 taskId; @@ -123,7 +222,7 @@ void sp136_strengh_sound(u8 a, u8 b, u8 c, u8 d) PlaySE(SE_W070); } -void sub_81BE900(u8 taskId) +static void sub_81BE900(u8 taskId) { s16 *data; @@ -145,7 +244,7 @@ void sub_81BE900(u8 taskId) } } -void sub_81BE968(void) +static void sub_81BE968(void) { u8 taskId; @@ -154,8 +253,6 @@ void sub_81BE968(void) gTasks[taskId].data[0]++; } -extern const struct SpriteSheet gUnknown_08617D94[]; - void sub_81BE994(void) { LoadSpriteSheets(gUnknown_08617D94); @@ -164,7 +261,7 @@ void sub_81BE994(void) sp136_strengh_sound(2, 1, 16, 3); } -void sub_81BE9C0(u8 taskId) +static void sub_81BE9C0(u8 taskId) { u16 *data; @@ -174,14 +271,14 @@ void sub_81BE9C0(u8 taskId) gTasks[taskId].func = sub_81BEA00; } -void sub_81BEA00(u8 taskId) +static void sub_81BEA00(u8 taskId) { FreeSpriteTilesByTag(4000); DestroyTask(taskId); EnableBothScriptContexts(); } -void sub_81BEA20(void) +static void sub_81BEA20(void) { u8 count; u8 spriteId; @@ -202,7 +299,7 @@ void sub_81BEA20(void) } } -void sub_81BEAD8(struct Sprite* sprite) +static void sub_81BEAD8(struct Sprite* sprite) { sprite->data[1] += 2; sprite->pos2.y = (sprite->data[1] / 2); diff --git a/src/fldeff_sweetscent.c b/src/fldeff_sweetscent.c index 3dfcd640d..100e440a5 100644 --- a/src/fldeff_sweetscent.c +++ b/src/fldeff_sweetscent.c @@ -6,7 +6,6 @@ #include "field_effect.h" #include "field_player_avatar.h" #include "field_screen.h" -#include "fldeff_groundshake.h" #include "palette.h" #include "party_menu.h" #include "rom6.h" @@ -20,6 +19,8 @@ void hm2_sweet_scent(void); void sub_8159F5C(void); void sub_8159FEC(u8 taskId); void sub_815A090(u8 taskId); +void sub_81BE6B8(void); +void sub_81BE72C(void); bool8 SetUpFieldMove_SweetScent(void) { diff --git a/src/fossil_specials.c b/src/fossil_specials.c index c5539114d..749c37e4d 100644 --- a/src/fossil_specials.c +++ b/src/fossil_specials.c @@ -6,10 +6,10 @@ #include "field_camera.h" #include "field_map_obj.h" #include "fieldmap.h" -#include "fldeff_groundshake.h" #include "global.fieldmap.h" #include "gpu_regs.h" #include "malloc.h" +#include "menu.h" #include "random.h" #include "script.h" #include "sound.h" @@ -17,27 +17,129 @@ #include "task.h" #include "window.h" -//struct StructUnknown_0203CF14 +#define ROOT_FOSSIL_GFX_TILE_LENGTH 0x80 +#define ROOT_FOSSIL_GFX_PALETTE_LENGTH 0x100 +//struct struct Struct8617DA4 { u8 x; u8 y; u16 tileId; }; +struct Struct203CF10 { + u8 *buffer; + u8 curr_buffer_index; +}; -extern const struct Struct8617DA4 gUnknown_08617DA4[]; -extern const u8 gUnknown_08617274[]; //mirage tower -extern const u8 gUnknown_08617B94[]; //mirage tower tilemap +struct DynamicSpriteFrameImage{ + u8 *data; + u16 size; +}; -extern void * gUnknown_0203CF04; -extern void * gUnknown_0203CF08; -extern u16 (*gUnknown_0203CF14)[2]; +struct Struct203CF0C { + u8 *frameImageTiles; + struct DynamicSpriteFrameImage *frameImage; + u8 spriteId; + u16 *frameImagePalette; + u16 unk10; +}; +// static functions /*static*/ void sub_81BED50(u8 taskId); /*static*/ void sub_81BEBF4(u8 taskId); /*static*/ void sub_81BF028(u8 taskId); +/*static*/ void sub_81BF248(struct Sprite *); +// .rodata +static const u8 gUnknown_08617274[] = {00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}; +static const u8 gMirageTower_Gfx[] = INCBIN_U8("graphics/misc/mirage_tower.4bpp"); +static const u16 gUnknown_08617B94[] = INCBIN_U16("graphics/misc/mirage_tower.bin"); +static const u16 gRootFossil_Pal[] = INCBIN_U16("graphics/misc/fossil.gbapal"); +static const u8 gRootFossil_Gfx[] = INCBIN_U8("graphics/misc/fossil.4bpp"); +static const u8 gMirageTowerCrumbles_Gfx[] = INCBIN_U8("graphics/misc/mirage_tower_crumbles.4bpp"); +static const u16 gMirageTowerCrumbles_Palette[] = INCBIN_U16("graphics/misc/mirage_tower_crumbles.gbapal"); + +const s16 gUnknown_08617D64[][3] = + { + { 0, 10, 65}, + { 17, 3, 50}, + {-12, 0, 75}, + { 10, 15, 90}, + { 7, 8, 65}, + {-18, 5, 75}, + { 22, -10, 55}, + {-24, -4, 65}, + }; + +const struct SpriteSheet gUnknown_08617D94[] = +{ + {gMirageTowerCrumbles_Gfx, 0x0080, 0x0fa0}, + {NULL} +}; + +static const struct Struct8617DA4 gUnknown_08617DA4[] = + { + {0x12, 0x35, 0x251}, + {0x13, 0x35, 0x251}, + {0x14, 0x35, 0x251}, + {0x12, 0x36, 0x251}, + {0x13, 0x36, 0x251}, + {0x14, 0x36, 0x251}, + {0x12, 0x37, 0x251}, + {0x13, 0x37, 0x251}, + {0x14, 0x37, 0x251}, + {0x12, 0x38, 0x251}, + {0x13, 0x38, 0x251}, + {0x14, 0x38, 0x251}, + {0x12, 0x39, 0x259}, + {0x13, 0x39, 0x259}, + {0x14, 0x39, 0x259}, + {0x12, 0x3A, 0x121}, + {0x13, 0x3A, 0x121}, + {0x14, 0x3A, 0x121}, + }; + +static const union AnimCmd gSpriteAnim_8617DEC[] = +{ + ANIMCMD_FRAME(0, 1), + ANIMCMD_END, +}; + +static const struct OamData gOamData_8617DF4 = +{ + .y = 0, + .affineMode = 0, + .objMode = 0, + .mosaic = 0, + .bpp = 0, + .shape = 0, + .x = 0, + .matrixNum = 0, + .size = 1, + .tileNum = 0, + .priority = 0, + .paletteNum = 3, + .affineParam = 0, +}; + +static const union AnimCmd *const gSpriteAnimTable_8617DFC[] = +{ + gSpriteAnim_8617DEC, +}; + +static const struct SpriteTemplate gUnknown_08617E00 = { + 0xFFFF, 0xFFFF, &gOamData_8617DF4, gSpriteAnimTable_8617DFC, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy +}; + +// ewram +EWRAM_DATA u8* gUnknown_0203CF04 = NULL; +EWRAM_DATA u8* gUnknown_0203CF08 = NULL; +EWRAM_DATA struct Struct203CF0C *gUnknown_0203CF0C = NULL; +EWRAM_DATA struct Struct203CF10 *gUnknown_0203CF10 = NULL; +EWRAM_DATA u16 *gUnknown_0203CF14 = NULL; + +// text void sub_81BEB24(void) { u8 count; @@ -63,15 +165,15 @@ void sub_81BEB7C(void) void sub_81BEB90(void) { - SetGpuReg(REG_OFFSET_BG0HOFS, (*gUnknown_0203CF14)[0]); - SetGpuReg(REG_OFFSET_BG0VOFS, (*gUnknown_0203CF14)[1]); + SetGpuReg(REG_OFFSET_BG0HOFS, gUnknown_0203CF14[0]); + SetGpuReg(REG_OFFSET_BG0VOFS, gUnknown_0203CF14[1]); } void sub_81BEBB4(u8 taskId) { if(!(gTasks[taskId].data[0])) { - (*gUnknown_0203CF14)[0] = -(*gUnknown_0203CF14)[0]; + gUnknown_0203CF14[0] = -gUnknown_0203CF14[0]; gTasks[taskId].data[0] = 2; sub_81BEB90(); } @@ -79,6 +181,7 @@ void sub_81BEBB4(u8 taskId) gTasks[taskId].data[0]--; } + void sub_81BEBF4(u8 taskId) { u8 zero; @@ -91,8 +194,8 @@ void sub_81BEBF4(u8 taskId) gTasks[taskId].data[0]++; break; case 1: - gUnknown_0203CF04 = (u8 **) AllocZeroed(0x920); - gUnknown_0203CF08 = (u8 **) AllocZeroed(0x800); + gUnknown_0203CF04 = (u8 *)AllocZeroed(0x920); + gUnknown_0203CF08 = (u8 *)AllocZeroed(0x800); ChangeBgX(0, 0, 0); ChangeBgY(0, 0, 0); gTasks[taskId].data[0]++; @@ -117,13 +220,884 @@ void sub_81BEBF4(u8 taskId) gTasks[taskId].data[0]++; break; case 6: - gUnknown_0203CF14 = (u16(*)[2]) Alloc(4); + gUnknown_0203CF14 = (u16 *)Alloc(4); zero = 0; - (*gUnknown_0203CF14)[0] = 2; - (*gUnknown_0203CF14)[1] = zero; + gUnknown_0203CF14[0] = 2; + gUnknown_0203CF14[1] = zero; CreateTask(sub_81BEBB4, 0xA); DestroyTask(taskId); EnableBothScriptContexts(); break; } } + +#define OUTER_BUFFER_LENGTH 0x60 +#define INNER_BUFFER_LENGTH 0x30 + +//void sub_81BF2B8(u8 *buffer, u16 offset, u8 a, u8 buffer_size, u8 d); + +#ifdef NONMATCHING +void sub_81BED50(u8 taskId) +{ + u8 count, index, size, next_index, buffer_index, anotherTaskId, anotherCount; + u16 rand1, rand2, temp; + u8 left, right; + u16 left16, right16; + u8 *buffer; + struct Task *currTask; + + switch(gTasks[taskId].data[0]) + { + case 0: + gUnknown_0203CF10 = (struct Struct203CF10 *)AllocZeroed(OUTER_BUFFER_LENGTH << 3); + break; + case 2: + if(gTasks[taskId].data[3] <= (OUTER_BUFFER_LENGTH - 1)) + { + if(gTasks[taskId].data[1] > 1) + { + index = gTasks[taskId].data[3]; + gUnknown_0203CF10[index].buffer = (u8 *)Alloc(INNER_BUFFER_LENGTH); + for(count = 0; count <= (INNER_BUFFER_LENGTH - 1); count++) + gUnknown_0203CF10[index].buffer[count] = count; + for(count = 0; count <= (INNER_BUFFER_LENGTH - 1); count++) + { + rand1 = Random() % 0x30; + rand2 = Random() % 0x30; + temp = gUnknown_0203CF10[index].buffer[rand2]; + gUnknown_0203CF10[index].buffer[rand2] = gUnknown_0203CF10[index].buffer[rand1]; + gUnknown_0203CF10[index].buffer[rand1] = temp; + } + if(gTasks[taskId].data[3] <= (OUTER_BUFFER_LENGTH - 1)) + gTasks[taskId].data[3]++; + gTasks[taskId].data[1] = 0; + } + gTasks[taskId].data[1]++; + } + currTask = &(gTasks[taskId]); + right = currTask->data[3]; + left = currTask->data[2]; + while(left < right) + { + anotherCount = 0; + do + { + buffer = gUnknown_0203CF04; + buffer_index = gUnknown_0203CF10[left].curr_buffer_index; + gUnknown_0203CF10[left].curr_buffer_index = buffer_index + 1; + sub_81BF2B8(buffer, gUnknown_0203CF10[left].buffer[buffer_index] + (INNER_BUFFER_LENGTH * (OUTER_BUFFER_LENGTH - 1 - left)), 0, INNER_BUFFER_LENGTH, 1); + anotherCount++; + }while(!anotherCount); + + if(gUnknown_0203CF10[left].curr_buffer_index > (INNER_BUFFER_LENGTH - 1)) + { + Free(gUnknown_0203CF10[left].buffer); + gUnknown_0203CF10[left].buffer = NULL; + currTask->data[2]++; + if(left & 1) + gUnknown_0203CF04[1]--; + } + left++; + } + LoadBgTiles(0, gUnknown_0203CF04, 0x920, 0); + if(gUnknown_0203CF10[0x5F].curr_buffer_index > (INNER_BUFFER_LENGTH - 1)) + break; + return; + case 3: + UnsetBgTilemapBuffer(0); + anotherTaskId = FindTaskIdByFunc(sub_81BEBB4); + if(anotherTaskId != 0xFF) + DestroyTask(anotherTaskId); + gUnknown_0203CF14[1] = gUnknown_0203CF14[0] = 0; + + sub_81BEB90(); + + break; + case 4: + Free(gUnknown_0203CF14); + gUnknown_0203CF14 = NULL; + Free(gUnknown_0203CF10); + gUnknown_0203CF10 = NULL; + Free(gUnknown_0203CF04); + gUnknown_0203CF04 = NULL; + Free(gUnknown_0203CF08); + gUnknown_0203CF08 = NULL; + + break; + case 5: + SetGpuRegBits(0xC, 0x2); + SetGpuRegBits(0x8, 0x0); + SetBgAttribute(0, BG_CTRL_ATTR_MOSAIC, 0); + sub_81971D0(); + + break; + case 6: + ShowBg(0); + + break; + case 7: + DestroyTask(taskId); + EnableBothScriptContexts(); + break; + } + gTasks[taskId].data[0]++; +} +#else +ASM_DIRECT +void sub_81BED50(u8 taskId) +{ + asm("\n\ + .syntax 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, 0x10\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + mov r10, r0\n\ + ldr r1, =gTasks\n\ + lsls r0, 2\n\ + add r0, r10\n\ + lsls r0, 3\n\ + adds r0, r1\n\ + ldrh r0, [r0, 0x8]\n\ + subs r0, 0x1\n\ + lsls r0, 16\n\ + asrs r0, 16\n\ + adds r6, r1, 0\n\ + cmp r0, 0x7\n\ + bls _081BED7C\n\ + b _081BF002\n\ + _081BED7C:\n\ + lsls r0, 2\n\ + ldr r1, =_081BED90\n\ + adds r0, r1\n\ + ldr r0, [r0]\n\ + mov pc, r0\n\ + .pool\n\ + .align 2, 0\n\ + _081BED90:\n\ + .4byte _081BEDB0\n\ + .4byte _081BF002\n\ + .4byte _081BEDC4\n\ + .4byte _081BEF64\n\ + .4byte _081BEF94\n\ + .4byte _081BEFD0\n\ + .4byte _081BEFF0\n\ + .4byte _081BEFF8\n\ + _081BEDB0:\n\ + ldr r4, =gUnknown_0203CF10\n\ + movs r0, 0xC0\n\ + lsls r0, 2\n\ + bl AllocZeroed\n\ + str r0, [r4]\n\ + b _081BF002\n\ + .pool\n\ + _081BEDC4:\n\ + mov r1, r10\n\ + lsls r0, r1, 2\n\ + adds r1, r0, r1\n\ + lsls r1, 3\n\ + adds r2, r1, r6\n\ + ldrh r3, [r2, 0xE]\n\ + movs r4, 0xE\n\ + ldrsh r1, [r2, r4]\n\ + str r0, [sp, 0x8]\n\ + cmp r1, 0x5F\n\ + bgt _081BEE8A\n\ + movs r1, 0xA\n\ + ldrsh r0, [r2, r1]\n\ + cmp r0, 0x1\n\ + ble _081BEE7C\n\ + lsls r0, r3, 24\n\ + lsrs r4, r0, 24\n\ + movs r0, 0x30\n\ + bl Alloc\n\ + ldr r3, =gUnknown_0203CF10\n\ + ldr r1, [r3]\n\ + lsls r2, r4, 3\n\ + adds r1, r2, r1\n\ + str r0, [r1]\n\ + movs r5, 0\n\ + adds r4, r2, 0\n\ + _081BEDFA:\n\ + ldr r0, [r3]\n\ + adds r0, r4, r0\n\ + ldr r0, [r0]\n\ + adds r0, r5\n\ + strb r5, [r0]\n\ + adds r0, r5, 0x1\n\ + lsls r0, 16\n\ + lsrs r5, r0, 16\n\ + cmp r5, 0x2F\n\ + bls _081BEDFA\n\ + movs r5, 0\n\ + ldr r7, =gUnknown_0203CF10\n\ + adds r6, r2, 0\n\ + _081BEE14:\n\ + bl Random\n\ + lsls r0, 16\n\ + lsrs r0, 16\n\ + movs r1, 0x30\n\ + bl __umodsi3\n\ + adds r4, r0, 0\n\ + lsls r4, 16\n\ + lsrs r4, 16\n\ + bl Random\n\ + lsls r0, 16\n\ + lsrs r0, 16\n\ + movs r1, 0x30\n\ + bl __umodsi3\n\ + lsls r0, 16\n\ + lsrs r0, 16\n\ + ldr r1, [r7]\n\ + adds r1, r6, r1\n\ + ldr r1, [r1]\n\ + adds r0, r1, r0\n\ + ldrb r2, [r0]\n\ + adds r1, r4 \n\ + ldrb r1, [r1]\n\ + strb r1, [r0]\n\ + ldr r0, [r7]\n\ + adds r0, r6, r0\n\ + ldr r0, [r0]\n\ + adds r0, r4\n\ + strb r2, [r0]\n\ + adds r0, r5, 0x1\n\ + lsls r0, 16\n\ + lsrs r5, r0, 16\n\ + cmp r5, 0x2F\n\ + bls _081BEE14\n\ + ldr r0, =gTasks\n\ + ldr r1, [sp, 0x8]\n\ + add r1, r10\n\ + lsls r1, 3\n\ + adds r2, r1, r0\n\ + ldrh r3, [r2, 0xE]\n\ + movs r4, 0xE\n\ + ldrsh r1, [r2, r4]\n\ + adds r6, r0, 0\n\ + cmp r1, 0x5F\n\ + bgt _081BEE78\n\ + adds r0, r3, 0x1\n\ + strh r0, [r2, 0xE]\n\ + _081BEE78:\n\ + movs r0, 0\n\ + strh r0, [r2, 0xA]\n\ + _081BEE7C:\n\ + ldr r1, [sp, 0x8]\n\ + add r1, r10\n\ + lsls r1, 3\n\ + adds r1, r6\n\ + ldrh r0, [r1, 0xA]\n\ + adds r0, 0x1\n\ + strh r0, [r1, 0xA]\n\ + _081BEE8A:\n\ + ldr r0, [sp, 0x8]\n\ + add r0, r10\n\ + lsls r0, 3\n\ + adds r0, r6\n\ + ldrb r4, [r0, 0xE]\n\ + ldrb r5, [r0, 0xC]\n\ + lsls r0, r4, 16\n\ + cmp r5, r4\n\ + bcs _081BEF32\n\ + str r0, [sp, 0xC]\n\ + _081BEE9E:\n\ + movs r6, 0\n\ + adds r0, r5, 0x1\n\ + str r0, [sp, 0x4]\n\ + lsls r4, r5, 3\n\ + movs r2, 0x5F\n\ + subs r1, r2, r5\n\ + lsls r0, r1, 1\n\ + adds r0, r1\n\ + lsls r0, 4\n\ + mov r9, r0\n\ + _081BEEB2:\n\ + ldr r0, =gUnknown_0203CF04\n\ + ldr r0, [r0]\n\ + ldr r7, =gUnknown_0203CF10\n\ + ldr r3, [r7]\n\ + adds r3, r4, r3\n\ + ldrb r2, [r3, 0x4]\n\ + adds r1, r2, 0x1\n\ + strb r1, [r3, 0x4]\n\ + lsls r2, 24\n\ + lsrs r2, 24\n\ + ldr r1, [r3]\n\ + adds r1, r2\n\ + ldrb r1, [r1]\n\ + add r1, r9\n\ + lsls r1, 16\n\ + lsrs r1, 16\n\ + movs r2, 0x1\n\ + mov r8, r2\n\ + str r2, [sp]\n\ + movs r2, 0\n\ + movs r3, 0x30\n\ + bl sub_81BF2B8\n\ + adds r0, r6, 0x1\n\ + lsls r0, 24\n\ + lsrs r6, r0, 24\n\ + cmp r6, 0\n\ + beq _081BEEB2\n\ + ldr r0, [r7]\n\ + adds r1, r4, r0\n\ + ldrb r0, [r1, 0x4]\n\ + cmp r0, 0x2F\n\ + bls _081BEF24\n\ + ldr r0, [r1]\n\ + bl Free\n\ + ldr r0, [r7]\n\ + adds r0, r4, r0\n\ + movs r1, 0\n\ + str r1, [r0]\n\ + ldr r1, [sp, 0x8]\n\ + add r1, r10\n\ + lsls r1, 3\n\ + ldr r4, =gTasks\n\ + adds r1, r4\n\ + ldrh r0, [r1, 0xC]\n\ + adds r0, 0x1\n\ + strh r0, [r1, 0xC]\n\ + mov r0, r8\n\ + ands r5, r0\n\ + cmp r5, 0x1\n\ + bne _081BEF24\n\ + ldr r0, =gUnknown_0203CF14\n\ + ldr r1, [r0]\n\ + ldrh r0, [r1, 0x2]\n\ + subs r0, 0x1\n\ + strh r0, [r1, 0x2]\n\ + _081BEF24:\n\ + ldr r1, [sp, 0x4]\n\ + lsls r0, r1, 16\n\ + lsrs r5, r0, 16\n\ + ldr r2, [sp, 0xC]\n\ + lsrs r0, r2, 16\n\ + cmp r5, r0\n\ + bcc _081BEE9E\n\ + _081BEF32:\n\ + ldr r0, =gUnknown_0203CF04\n\ + ldr r1, [r0]\n\ + movs r2, 0x92\n\ + lsls r2, 4\n\ + movs r0, 0\n\ + movs r3, 0\n\ + bl LoadBgTiles\n\ + ldr r0, =gUnknown_0203CF10\n\ + ldr r0, [r0]\n\ + movs r4, 0xBE\n\ + lsls r4, 2\n\ + adds r0, r4\n\ + ldrb r0, [r0, 0x4]\n\ + cmp r0, 0x2F\n\ + bhi _081BF002\n\ + b _081BF014\n\ + .pool\n\ + _081BEF64:\n\ + movs r0, 0\n\ + bl UnsetBgTilemapBuffer\n\ + ldr r0, =sub_81BEBB4\n\ + bl FindTaskIdByFunc\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + cmp r0, 0xFF\n\ + beq _081BEF7C\n\ + bl DestroyTask\n\ + _081BEF7C:\n\ + ldr r0, =gUnknown_0203CF14\n\ + ldr r1, [r0]\n\ + movs r0, 0\n\ + strh r0, [r1]\n\ + strh r0, [r1, 0x2]\n\ + bl sub_81BEB90\n\ + b _081BF002\n\ + .pool\n\ + _081BEF94:\n\ + ldr r4, =gUnknown_0203CF14\n\ + ldr r0, [r4]\n\ + bl Free\n\ + movs r5, 0\n\ + str r5, [r4]\n\ + ldr r4, =gUnknown_0203CF10\n\ + ldr r0, [r4]\n\ + bl Free\n\ + str r5, [r4]\n\ + ldr r4, =gUnknown_0203CF04\n\ + ldr r0, [r4]\n\ + bl Free\n\ + str r5, [r4]\n\ + ldr r4, =gUnknown_0203CF08\n\ + ldr r0, [r4]\n\ + bl Free\n\ + str r5, [r4]\n\ + b _081BF002\n\ + .pool\n\ + _081BEFD0:\n\ + movs r0, 0xC\n\ + movs r1, 0x2\n\ + bl SetGpuRegBits\n\ + movs r0, 0x8\n\ + movs r1, 0\n\ + bl SetGpuRegBits\n\ + movs r0, 0\n\ + movs r1, 0x7\n\ + movs r2, 0\n\ + bl SetBgAttribute\n\ + bl sub_81971D0\n\ + b _081BF002\n\ + _081BEFF0:\n\ + movs r0, 0\n\ + bl ShowBg\n\ + b _081BF002\n\ + _081BEFF8:\n\ + mov r0, r10\n\ + bl DestroyTask\n\ + bl EnableBothScriptContexts\n\ + _081BF002:\n\ + ldr r0, =gTasks\n\ + mov r2, r10\n\ + lsls r1, r2, 2\n\ + add r1, r10\n\ + lsls r1, 3\n\ + adds r1, r0\n\ + ldrh r0, [r1, 0x8]\n\ + adds r0, 0x1\n\ + strh r0, [r1, 0x8]\n\ + _081BF014:\n\ + add sp, 0x10\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\ + .syntax divided"); +} +#endif // NONMATCHING + +#ifdef NONMATCHING +void sub_81BF028(u8 taskId) +{ + u8 spriteId, zero; + u16 count, rand1, rand2, temp, switch_val; + u16 count2; + u32 count3; + + u8 *buffer; + struct SpriteTemplate fossilTemplate; +; + switch_val = gTasks[taskId].data[0] - 1; + switch(switch_val) + { + case 0: + gUnknown_0203CF0C = (struct Struct203CF0C *)AllocZeroed(0x14); + gUnknown_0203CF0C->frameImageTiles = (u8 *)AllocZeroed(ROOT_FOSSIL_GFX_TILE_LENGTH); + gUnknown_0203CF0C->frameImage = (struct InMemorySpriteFrameImage *)AllocZeroed(0x8); + gUnknown_0203CF0C->frameImagePalette = (u16 *)AllocZeroed(ROOT_FOSSIL_GFX_PALETTE_LENGTH << 1); + gUnknown_0203CF0C->unk10 = 0; + break; + case 1: + buffer = gUnknown_0203CF0C->frameImageTiles; + for(count = 0; count <= (ROOT_FOSSIL_GFX_TILE_LENGTH - 1); count++, buffer++) + *buffer = gRootFossil_Gfx[count]; + break; + case 2: + gUnknown_0203CF0C->frameImage->data = gUnknown_0203CF0C->frameImageTiles; + gUnknown_0203CF0C->frameImage->size = ROOT_FOSSIL_GFX_TILE_LENGTH; + break; + case 3: + fossilTemplate = gUnknown_08617E00; + fossilTemplate.images = (struct SpriteFrameImage *)(gUnknown_0203CF0C->frameImage); + + spriteId = CreateSprite(&fossilTemplate, 128, -10, 1); + gUnknown_0203CF0C->spriteId = spriteId; + zero = 0; + gSprites[gUnknown_0203CF0C->spriteId].centerToCornerVecX = zero; + gSprites[gUnknown_0203CF0C->spriteId].data[0] = gSprites[gUnknown_0203CF0C->spriteId].pos1.x; + gSprites[gUnknown_0203CF0C->spriteId].data[1] = 1; + case 4: + for(count = 0; count <= (ROOT_FOSSIL_GFX_PALETTE_LENGTH -1); count++) + gUnknown_0203CF0C->frameImagePalette[count] = count; + break; + case 5: + for(count = 0; count <= ((ROOT_FOSSIL_GFX_PALETTE_LENGTH <<1) -1); count++) + { + rand1 = Random() & 0xFF; + rand2 = Random() & 0xFF; + temp = gUnknown_0203CF0C->frameImagePalette[rand2]; + gUnknown_0203CF0C->frameImagePalette[rand2] = gUnknown_0203CF0C->frameImagePalette[rand1]; + gUnknown_0203CF0C->frameImagePalette[rand1] = temp; + } + gSprites[gUnknown_0203CF0C->spriteId].callback = sub_81BF248; + break; + case 6: + if(gSprites[gUnknown_0203CF0C->spriteId].callback != SpriteCallbackDummy) + return; + DestroySprite(&gSprites[gUnknown_0203CF0C->spriteId]); + Free(gUnknown_0203CF0C->frameImagePalette); + gUnknown_0203CF0C->frameImagePalette = NULL; + Free(gUnknown_0203CF0C->frameImage); + gUnknown_0203CF0C->frameImage = NULL; + Free(gUnknown_0203CF0C->frameImageTiles); + gUnknown_0203CF0C->frameImageTiles = NULL; + Free(gUnknown_0203CF0C); + gUnknown_0203CF0C = NULL; + break; + case 7: + EnableBothScriptContexts(); + } + gTasks[taskId].data[0]++; +} + +#else +ASM_DIRECT +void sub_81BF028(u8 taskId) +{ + asm("\n\ + .syntax unified\n\ + sub_81BF028: @ 81BF028\n\ + push {r4-r7,lr}\n\ + mov r7, r8\n\ + push {r7}\n\ + sub sp, 0x18\n\ + lsls r0, 24\n\ + lsrs r7, r0, 24\n\ + ldr r1, =gTasks\n\ + lsls r0, r7, 2\n\ + adds r0, r7\n\ + lsls r0, 3\n\ + adds r0, r1\n\ + ldrh r0, [r0, 0x8]\n\ + subs r0, 0x1\n\ + lsls r0, 16\n\ + asrs r0, 16\n\ + cmp r0, 0x7\n\ + bls _081BF04C\n\ + b _081BF228\n\ + _081BF04C:\n\ + lsls r0, 2\n\ + ldr r1, =_081BF060\n\ + adds r0, r1\n\ + ldr r0, [r0]\n\ + mov pc, r0\n\ + .pool\n\ + .align 2, 0\n\ + _081BF060:\n\ + .4byte _081BF080\n\ + .4byte _081BF0B4\n\ + .4byte _081BF0DC\n\ + .4byte _081BF0F0\n\ + .4byte _081BF148\n\ + .4byte _081BF170\n\ + .4byte _081BF1CC\n\ + .4byte _081BF224\n\ + _081BF080:\n\ + ldr r4, =gUnknown_0203CF0C\n\ + movs r0, 0x14\n\ + bl AllocZeroed\n\ + str r0, [r4]\n\ + movs r0, 0x80\n\ + bl AllocZeroed\n\ + ldr r1, [r4]\n\ + str r0, [r1]\n\ + movs r0, 0x8\n\ + bl AllocZeroed\n\ + ldr r1, [r4]\n\ + str r0, [r1, 0x4]\n\ + movs r0, 0x80\n\ + lsls r0, 2\n\ + bl AllocZeroed\n\ + ldr r1, [r4]\n\ + str r0, [r1, 0xC]\n\ + movs r0, 0\n\ + strh r0, [r1, 0x10]\n\ + b _081BF228\n\ + .pool\n\ + _081BF0B4:\n\ + ldr r0, =gUnknown_0203CF0C\n\ + ldr r0, [r0]\n\ + ldr r1, [r0]\n\ + movs r5, 0\n\ + ldr r2, =gRootFossil_Gfx\n\ + _081BF0BE:\n\ + adds r0, r5, r2\n\ + ldrb r0, [r0]\n\ + strb r0, [r1]\n\ + adds r0, r5, 0x1\n\ + lsls r0, 16\n\ + lsrs r5, r0, 16\n\ + adds r1, 0x1\n\ + cmp r5, 0x7F\n\ + bls _081BF0BE\n\ + b _081BF228\n\ + .pool\n\ + _081BF0DC:\n\ + ldr r0, =gUnknown_0203CF0C\n\ + ldr r0, [r0]\n\ + ldr r1, [r0, 0x4]\n\ + ldr r0, [r0]\n\ + str r0, [r1]\n\ + movs r0, 0x80\n\ + strh r0, [r1, 0x4]\n\ + b _081BF228\n\ + .pool\n\ + _081BF0F0:\n\ + mov r1, sp\n\ + ldr r0, =gUnknown_08617E00\n\ + ldm r0!, {r2-r4}\n\ + stm r1!, {r2-r4}\n\ + ldm r0!, {r2-r4}\n\ + stm r1!, {r2-r4}\n\ + ldr r4, =gUnknown_0203CF0C\n\ + ldr r0, [r4]\n\ + ldr r0, [r0, 0x4]\n\ + str r0, [sp, 0xC]\n\ + movs r2, 0x10\n\ + negs r2, r2\n\ + mov r0, sp\n\ + movs r1, 0x80\n\ + movs r3, 0x1\n\ + bl CreateSprite\n\ + ldr r1, [r4]\n\ + movs r3, 0\n\ + strb r0, [r1, 0x8]\n\ + ldr r2, =gSprites\n\ + ldr r0, [r4]\n\ + ldrb r1, [r0, 0x8]\n\ + lsls r0, r1, 4\n\ + adds r0, r1\n\ + lsls r0, 2\n\ + adds r0, r2\n\ + adds r0, 0x28\n\ + strb r3, [r0]\n\ + ldr r3, [r4]\n\ + ldrb r1, [r3, 0x8]\n\ + lsls r0, r1, 4\n\ + adds r0, r1\n\ + lsls r0, 2\n\ + adds r0, r2\n\ + ldrh r1, [r0, 0x20]\n\ + strh r1, [r0, 0x2E]\n\ + ldrb r1, [r3, 0x8]\n\ + lsls r0, r1, 4\n\ + adds r0, r1\n\ + lsls r0, 2\n\ + adds r0, r2\n\ + movs r1, 0x1\n\ + strh r1, [r0, 0x30]\n\ + _081BF148:\n\ + movs r5, 0\n\ + ldr r2, =gUnknown_0203CF0C\n\ + _081BF14C:\n\ + ldr r0, [r2]\n\ + ldr r1, [r0, 0xC]\n\ + lsls r0, r5, 1\n\ + adds r0, r1\n\ + strh r5, [r0]\n\ + adds r0, r5, 0x1\n\ + lsls r0, 16\n\ + lsrs r5, r0, 16\n\ + cmp r5, 0xFF\n\ + bls _081BF14C\n\ + b _081BF228\n\ + .pool\n\ + _081BF170:\n\ + movs r5, 0\n\ + movs r6, 0xFF\n\ + ldr r0, =0x000001ff\n\ + mov r8, r0\n\ + _081BF178:\n\ + bl Random\n\ + adds r4, r6, 0\n\ + ands r4, r0\n\ + bl Random\n\ + adds r1, r6, 0\n\ + ands r1, r0\n\ + ldr r0, =gUnknown_0203CF0C\n\ + ldr r3, [r0]\n\ + ldr r0, [r3, 0xC]\n\ + lsls r1, 1\n\ + adds r1, r0\n\ + ldrh r2, [r1]\n\ + lsls r4, 1\n\ + adds r4, r0\n\ + ldrh r0, [r4]\n\ + strh r0, [r1]\n\ + strh r2, [r4]\n\ + adds r0, r5, 0x1\n\ + lsls r0, 16\n\ + lsrs r5, r0, 16\n\ + cmp r5, r8\n\ + bls _081BF178\n\ + ldr r2, =gSprites\n\ + ldrb r1, [r3, 0x8]\n\ + lsls r0, r1, 4\n\ + adds r0, r1\n\ + lsls r0, 2\n\ + adds r2, 0x1C\n\ + adds r0, r2\n\ + ldr r1, =sub_81BF248\n\ + str r1, [r0]\n\ + b _081BF228\n\ + .pool\n\ + _081BF1CC:\n\ + ldr r3, =gSprites\n\ + ldr r5, =gUnknown_0203CF0C\n\ + ldr r0, [r5]\n\ + ldrb r1, [r0, 0x8]\n\ + lsls r0, r1, 4\n\ + adds r0, r1\n\ + lsls r2, r0, 2\n\ + adds r0, r3, 0\n\ + adds r0, 0x1C\n\ + adds r0, r2, r0\n\ + ldr r1, [r0]\n\ + ldr r0, =SpriteCallbackDummy\n\ + cmp r1, r0\n\ + bne _081BF238\n\ + adds r0, r2, r3\n\ + bl DestroySprite\n\ + ldr r0, [r5]\n\ + ldr r0, [r0, 0xC]\n\ + bl Free\n\ + ldr r0, [r5]\n\ + movs r4, 0\n\ + str r4, [r0, 0xC]\n\ + ldr r0, [r0, 0x4]\n\ + bl Free\n\ + ldr r0, [r5]\n\ + str r4, [r0, 0x4]\n\ + ldr r0, [r0]\n\ + bl Free\n\ + ldr r0, [r5]\n\ + str r4, [r0]\n\ + bl Free\n\ + str r4, [r5]\n\ + b _081BF228\n\ + .pool\n\ + _081BF224:\n\ + bl EnableBothScriptContexts\n\ + _081BF228:\n\ + ldr r0, =gTasks\n\ + lsls r1, r7, 2\n\ + adds r1, r7\n\ + lsls r1, 3\n\ + adds r1, r0\n\ + ldrh r0, [r1, 0x8]\n\ + adds r0, 0x1\n\ + strh r0, [r1, 0x8]\n\ + _081BF238:\n\ + add sp, 0x18\n\ + pop {r3}\n\ + mov r8, r3\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0\n\ + .pool\n\ + .syntax divided"); +} +#endif // NONMATCHING + +#ifdef NONMATCHING +void sub_81BF248(struct Sprite *sprite) +{ + u8 count; + u16 x; + u16 y; + u8 *buffer; + + if(gUnknown_0203CF0C->unk10 > 0xFF) + { + sprite->callback = SpriteCallbackDummy; + return; + } + if(sprite->pos2.y > 0x5F) + { + for(count = 0; count <= 1; count++) + { + buffer = gUnknown_0203CF0C->frameImageTiles; + x = gUnknown_0203CF0C->unk10; + gUnknown_0203CF0C->unk10 = x+1; + sub_81BF2B8(buffer,gUnknown_0203CF0C->frameImagePalette[x] , 0, 0x10, 0); + } + StartSpriteAnim(sprite, 0x0); + } + else + sprite->pos2.y++; +} + +#else +ASM_DIRECT +void sub_81BF248(struct Sprite *sprite) +{ + asm("\n\ + .syntax unified\n\ + push {r4,r5,lr}\n\ + sub sp, 0x4\n\ + adds r5, r0, 0\n\ + ldr r0, =gUnknown_0203CF0C\n\ + ldr r0, [r0]\n\ + ldrh r0, [r0, 0x10]\n\ + cmp r0, 0xFF\n\ + bls _081BF268\n\ + ldr r0, =SpriteCallbackDummy\n\ + str r0, [r5, 0x1C]\n\ + b _081BF2B0\n\ + .pool\n\ + _081BF268:\n\ + ldrh r1, [r5, 0x22]\n\ + movs r2, 0x22\n\ + ldrsh r0, [r5, r2]\n\ + cmp r0, 0x5F\n\ + ble _081BF2AC\n\ + movs r4, 0\n\ + _081BF274:\n\ + ldr r0, =gUnknown_0203CF0C\n\ + ldr r3, [r0]\n\ + ldr r0, [r3]\n\ + ldrh r1, [r3, 0x10]\n\ + adds r2, r1, 0x1\n\ + strh r2, [r3, 0x10]\n\ + lsls r1, 16\n\ + ldr r2, [r3, 0xC]\n\ + lsrs r1, 15\n\ + adds r1, r2\n\ + ldrh r1, [r1]\n\ + movs r2, 0\n\ + str r2, [sp]\n\ + movs r3, 0x10\n\ + bl sub_81BF2B8\n\ + adds r0, r4, 0x1\n\ + lsls r0, 24\n\ + lsrs r4, r0, 24\n\ + cmp r4, 0x1\n\ + bls _081BF274\n\ + adds r0, r5, 0\n\ + movs r1, 0\n\ + bl StartSpriteAnim\n\ + b _081BF2B0\n\ + .pool\n\ + _081BF2AC:\n\ + adds r0, r1, 0x1\n\ + strh r0, [r5, 0x22]\n\ + _081BF2B0:\n\ + add sp, 0x4\n\ + pop {r4,r5}\n\ + pop {r0}\n\ + bx r0\n\ + .pool\n\ + .syntax divided"); +} +#endif // NONMATCHING + +extern u16 gUnknown_030012A8[8]; + + +