From 9719e2fa22d98a5f97c8d213b285a19ac4e25c57 Mon Sep 17 00:00:00 2001 From: KDSKardabox Date: Mon, 19 Feb 2018 15:37:02 +0530 Subject: [PATCH] Start decompile fossil_specials.s --- asm/fossil_specials.s | 254 ------------------------------------------ ld_script.txt | 1 + src/fossil_specials.c | 129 +++++++++++++++++++++ 3 files changed, 130 insertions(+), 254 deletions(-) create mode 100644 src/fossil_specials.c diff --git a/asm/fossil_specials.s b/asm/fossil_specials.s index 7956f814a4..77a0281c19 100644 --- a/asm/fossil_specials.s +++ b/asm/fossil_specials.s @@ -5,260 +5,6 @@ .text - thumb_func_start sub_81BEB24 -sub_81BEB24: @ 81BEB24 - push {r4,r5,lr} - movs r4, 0 - ldr r5, =gUnknown_08617DA4 -_081BEB2A: - lsls r2, r4, 2 - adds r2, r5 - ldrb r0, [r2] - adds r0, 0x7 - ldrb r1, [r2, 0x1] - adds r1, 0x7 - ldrh r2, [r2, 0x2] - bl MapGridSetMetatileIdAt - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x11 - bls _081BEB2A - bl DrawWholeMapView - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81BEB24 - - thumb_func_start sub_81BEB54 -sub_81BEB54: @ 81BEB54 - push {lr} - ldr r0, =sub_81BED50 - movs r1, 0x9 - bl CreateTask - pop {r0} - bx r0 - .pool - thumb_func_end sub_81BEB54 - - thumb_func_start sub_81BEB68 -sub_81BEB68: @ 81BEB68 - push {lr} - ldr r0, =sub_81BEBF4 - movs r1, 0x9 - bl CreateTask - pop {r0} - bx r0 - .pool - thumb_func_end sub_81BEB68 - - thumb_func_start sub_81BEB7C -sub_81BEB7C: @ 81BEB7C - push {lr} - ldr r0, =sub_81BF028 - movs r1, 0x9 - bl CreateTask - pop {r0} - bx r0 - .pool - thumb_func_end sub_81BEB7C - - thumb_func_start sub_81BEB90 -sub_81BEB90: @ 81BEB90 - push {r4,lr} - ldr r4, =gUnknown_0203CF14 - ldr r0, [r4] - ldrh r1, [r0] - movs r0, 0x10 - bl SetGpuReg - ldr r0, [r4] - ldrh r1, [r0, 0x2] - movs r0, 0x12 - bl SetGpuReg - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81BEB90 - - thumb_func_start sub_81BEBB4 -sub_81BEBB4: @ 81BEBB4 - push {lr} - lsls r0, 24 - lsrs r0, 24 - ldr r2, =gTasks - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - adds r2, r1, r2 - ldrh r1, [r2, 0x8] - movs r3, 0x8 - ldrsh r0, [r2, r3] - cmp r0, 0 - bne _081BEBEC - ldr r0, =gUnknown_0203CF14 - ldr r1, [r0] - ldrh r0, [r1] - negs r0, r0 - strh r0, [r1] - movs r0, 0x2 - strh r0, [r2, 0x8] - bl sub_81BEB90 - b _081BEBF0 - .pool -_081BEBEC: - subs r0, r1, 0x1 - strh r0, [r2, 0x8] -_081BEBF0: - pop {r0} - bx r0 - thumb_func_end sub_81BEBB4 - - thumb_func_start sub_81BEBF4 -sub_81BEBF4: @ 81BEBF4 - push {r4,r5,lr} - sub sp, 0xC - lsls r0, 24 - lsrs r5, r0, 24 - ldr r1, =gTasks - lsls r0, r5, 2 - adds r0, r5 - lsls r0, 3 - adds r0, r1 - movs r1, 0x8 - ldrsh r0, [r0, r1] - cmp r0, 0x6 - bls _081BEC10 - b _081BED40 -_081BEC10: - lsls r0, 2 - ldr r1, =_081BEC24 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081BEC24: - .4byte _081BEC40 - .4byte _081BEC50 - .4byte _081BEC88 - .4byte _081BECB0 - .4byte _081BECF8 - .4byte _081BED00 - .4byte _081BED1C -_081BEC40: - bl FreeAllWindowBuffers - movs r0, 0 - movs r1, 0x7 - movs r2, 0x2 - bl SetBgAttribute - b _081BED04 -_081BEC50: - ldr r4, =gUnknown_0203CF04 - movs r0, 0x92 - lsls r0, 4 - bl AllocZeroed - str r0, [r4] - ldr r4, =gUnknown_0203CF08 - movs r0, 0x80 - lsls r0, 4 - bl AllocZeroed - str r0, [r4] - movs r0, 0 - movs r1, 0 - movs r2, 0 - bl ChangeBgX - movs r0, 0 - movs r1, 0 - movs r2, 0 - bl ChangeBgY - b _081BECD8 - .pool -_081BEC88: - ldr r0, =gUnknown_08617274 - ldr r4, =gUnknown_0203CF04 - ldr r1, [r4] - movs r2, 0x92 - lsls r2, 3 - bl CpuSet - ldr r1, [r4] - movs r2, 0x92 - lsls r2, 4 - movs r0, 0 - movs r3, 0 - bl LoadBgTiles - b _081BECD8 - .pool -_081BECB0: - ldr r0, =gUnknown_0203CF08 - ldr r1, [r0] - movs r0, 0 - bl SetBgTilemapBuffer - ldr r1, =gUnknown_08617B94 - movs r0, 0x6 - str r0, [sp] - movs r0, 0xC - str r0, [sp, 0x4] - movs r0, 0x11 - str r0, [sp, 0x8] - movs r0, 0 - movs r2, 0xC - movs r3, 0x1D - bl CopyToBgTilemapBufferRect_ChangePalette - movs r0, 0 - bl CopyBgTilemapBufferToVram -_081BECD8: - ldr r1, =gTasks - lsls r0, r5, 2 - adds r0, r5 - lsls r0, 3 - adds r0, r1 - ldrh r1, [r0, 0x8] - adds r1, 0x1 - strh r1, [r0, 0x8] - b _081BED40 - .pool -_081BECF8: - movs r0, 0 - bl ShowBg - b _081BED04 -_081BED00: - bl sub_81BEB24 -_081BED04: - ldr r0, =gTasks - lsls r1, r5, 2 - adds r1, r5 - lsls r1, 3 - adds r1, r0 - ldrh r0, [r1, 0x8] - adds r0, 0x1 - strh r0, [r1, 0x8] - b _081BED40 - .pool -_081BED1C: - ldr r4, =gUnknown_0203CF14 - movs r0, 0x4 - bl Alloc - str r0, [r4] - movs r2, 0 - movs r1, 0x2 - strh r1, [r0] - strh r2, [r0, 0x2] - ldr r0, =sub_81BEBB4 - movs r1, 0xA - bl CreateTask - adds r0, r5, 0 - bl DestroyTask - bl EnableBothScriptContexts -_081BED40: - add sp, 0xC - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81BEBF4 - thumb_func_start sub_81BED50 sub_81BED50: @ 81BED50 push {r4-r7,lr} diff --git a/ld_script.txt b/ld_script.txt index 2adabb59ef..b48552348a 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -259,6 +259,7 @@ SECTIONS { src/unk_81BAD84.o(.text); src/battle_controller_player_partner.o(.text); src/fldeff_groundshake.o(.text); + src/fossil_specials.o(.text); asm/fossil_specials.o(.text); src/berry_fix_program.o(.text); src/pokemon_summary_screen.o(.text); diff --git a/src/fossil_specials.c b/src/fossil_specials.c new file mode 100644 index 0000000000..c5539114de --- /dev/null +++ b/src/fossil_specials.c @@ -0,0 +1,129 @@ +#include "global.h" +#include "constants/flags.h" +#include "constants/songs.h" +#include "bg.h" +#include "event_data.h" +#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 "random.h" +#include "script.h" +#include "sound.h" +#include "sprite.h" +#include "task.h" +#include "window.h" + +//struct StructUnknown_0203CF14 + +struct Struct8617DA4 { + u8 x; + u8 y; + u16 tileId; +}; + + +extern const struct Struct8617DA4 gUnknown_08617DA4[]; +extern const u8 gUnknown_08617274[]; //mirage tower +extern const u8 gUnknown_08617B94[]; //mirage tower tilemap + +extern void * gUnknown_0203CF04; +extern void * gUnknown_0203CF08; +extern u16 (*gUnknown_0203CF14)[2]; + +/*static*/ void sub_81BED50(u8 taskId); +/*static*/ void sub_81BEBF4(u8 taskId); +/*static*/ void sub_81BF028(u8 taskId); + +void sub_81BEB24(void) +{ + u8 count; + for(count = 0; count <= 0x11; count++) + MapGridSetMetatileIdAt(gUnknown_08617DA4[count].x + 7, gUnknown_08617DA4[count].y + 7, gUnknown_08617DA4[count].tileId); + DrawWholeMapView(); +} + +void sub_81BEB54(void) +{ + CreateTask(sub_81BED50, 0x9); +} + +void sub_81BEB68(void) +{ + CreateTask(sub_81BEBF4, 0x9); +} + +void sub_81BEB7C(void) +{ + CreateTask(sub_81BF028, 0x9); +} + +void sub_81BEB90(void) +{ + 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]; + gTasks[taskId].data[0] = 2; + sub_81BEB90(); + } + else + gTasks[taskId].data[0]--; +} + +void sub_81BEBF4(u8 taskId) +{ + u8 zero; + + switch(gTasks[taskId].data[0]) + { + case 0: + FreeAllWindowBuffers(); + SetBgAttribute(0, BG_CTRL_ATTR_MOSAIC, 2); + gTasks[taskId].data[0]++; + break; + case 1: + gUnknown_0203CF04 = (u8 **) AllocZeroed(0x920); + gUnknown_0203CF08 = (u8 **) AllocZeroed(0x800); + ChangeBgX(0, 0, 0); + ChangeBgY(0, 0, 0); + gTasks[taskId].data[0]++; + break; + case 2: + CpuSet(gUnknown_08617274, gUnknown_0203CF04, 0x490); + LoadBgTiles(0, gUnknown_0203CF04, 0x920, 0); + gTasks[taskId].data[0]++; + break; + case 3: + SetBgTilemapBuffer(0, gUnknown_0203CF08); + CopyToBgTilemapBufferRect_ChangePalette(0, &gUnknown_08617B94, 12, 29, 6, 12, 17); + CopyBgTilemapBufferToVram(0); + gTasks[taskId].data[0]++; + break; + case 4: + ShowBg(0); + gTasks[taskId].data[0]++; + break; + case 5: + sub_81BEB24(); + gTasks[taskId].data[0]++; + break; + case 6: + gUnknown_0203CF14 = (u16(*)[2]) Alloc(4); + zero = 0; + (*gUnknown_0203CF14)[0] = 2; + (*gUnknown_0203CF14)[1] = zero; + CreateTask(sub_81BEBB4, 0xA); + DestroyTask(taskId); + EnableBothScriptContexts(); + break; + } +}