diff --git a/asm/rom_81700F8.s b/asm/rom_81700F8.s deleted file mode 100644 index 45c505cd9..000000000 --- a/asm/rom_81700F8.s +++ /dev/null @@ -1,64 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_81700F8 -sub_81700F8: @ 81700F8 - push {r4,r5,lr} - ldr r5, =0x04000208 - ldrh r4, [r5] - movs r0, 0 - strh r0, [r5] - movs r0, 0x1 - bl RegisterRamReset - movs r0, 0 - movs r1, 0x80 - bl ClearGpuRegBits - strh r4, [r5] - ldr r1, =gMain - ldr r0, =0x00000439 - adds r1, r0 - ldrb r2, [r1] - movs r0, 0x3 - negs r0, r0 - ands r0, r2 - strb r0, [r1] - bl sub_815355C - lsls r0, 16 - lsrs r0, 16 - bl SetSaveBlocksPointers - bl sub_808447C - bl ResetSaveCounters - movs r0, 0 - bl sub_81534D0 - ldr r0, =gSaveFileStatus - ldrh r0, [r0] - cmp r0, 0 - beq _08170148 - cmp r0, 0x2 - bne _0817014C -_08170148: - bl Sav2_ClearSetDefault -_0817014C: - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldrb r0, [r0, 0x15] - lsls r0, 31 - lsrs r0, 31 - bl SetPokemonCryStereo - ldr r0, =0x02000000 - movs r1, 0xE0 - lsls r1, 9 - bl InitHeap - ldr r0, =sub_8086230 - bl SetMainCallback2 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81700F8 - - .align 2, 0 @ Don't pad with nop. diff --git a/include/gpu_regs.h b/include/gpu_regs.h new file mode 100644 index 000000000..2d47d602c --- /dev/null +++ b/include/gpu_regs.h @@ -0,0 +1,15 @@ +// +// Created by scott on 9/15/2017. +// + +#ifndef POKEEMERALD_GPU_REGS_H +#define POKEEMERALD_GPU_REGS_H + +// Exported type declarations + +// Exported RAM declarations + +// Exported ROM declarations +void ClearGpuRegBits(u8 regOffset, u16 mask); + +#endif //POKEEMERALD_GPU_REGS_H diff --git a/include/load_save.h b/include/load_save.h index 0fedd720b..20848e1a7 100644 --- a/include/load_save.h +++ b/include/load_save.h @@ -18,5 +18,6 @@ void SaveSerializedGame(void); void LoadSerializedGame(void); void LoadPlayerBag(void); void SavePlayerBag(void); +void SetSaveBlocksPointers(u16); #endif // GUARD_LOAD_SAVE_H diff --git a/include/malloc.h b/include/malloc.h index bd870ede3..d26d19242 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -1,8 +1,11 @@ #ifndef GUARD_MALLOC_H #define GUARD_MALLOC_H +extern u8 gHeap[]; + void *Alloc(u32 size); void *AllocZeroed(u32 size); void Free(void *pointer); +void InitHeap(void *pointer, u32 size); #endif // GUARD_MALLOC_H diff --git a/include/new_game.h b/include/new_game.h index f9ad7fcb8..060279c25 100644 --- a/include/new_game.h +++ b/include/new_game.h @@ -9,5 +9,7 @@ void ClearPokedexFlags(void); void WarpToTruck(void); void NewGameInitData(void); void ResetMiniGamesResults(void); +void sub_808447C(void); +void Sav2_ClearSetDefault(void); #endif // GUARD_NEW_GAME_H diff --git a/include/rom4.h b/include/rom4.h new file mode 100644 index 000000000..1538f5dbc --- /dev/null +++ b/include/rom4.h @@ -0,0 +1,15 @@ +// +// Created by scott on 9/15/2017. +// + +#ifndef POKEEMERALD_ROM4_H +#define POKEEMERALD_ROM4_H + +// Exported type declarations + +// Exported RAM declarations + +// Exported ROM declarations +void sub_8086230(void); + +#endif //POKEEMERALD_ROM4_H diff --git a/include/save.h b/include/save.h index 1d7fdd6e3..e98233c67 100644 --- a/include/save.h +++ b/include/save.h @@ -1,6 +1,8 @@ #ifndef GUARD_SAVE_H #define GUARD_SAVE_H +extern u16 gSaveFileStatus; + struct SaveSectionLocation { void *data; @@ -88,5 +90,7 @@ u16 CalculateChecksum(void *, u16); //u8 unref_sub_8125FF0(u8 *data, u16 size); //u8 unref_sub_8126068(u8 sector, u8 *data, u32 size); //u8 unref_sub_8126080(u8 sector, u8 *data); +u16 sub_815355C(void); +u8 sub_81534D0(u8); #endif // GUARD_SAVE_H diff --git a/ld_script.txt b/ld_script.txt index 4a5bb643a..e8c8a43ce 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -206,7 +206,7 @@ SECTIONS { asm/battle_controller_wally.o(.text); asm/player_pc.o(.text); asm/intro.o(.text); - asm/rom_81700F8.o(.text); + src/rom_81700F8.o(.text); asm/field_region_map.o(.text); asm/battle_anim_8170478.o(.text); asm/hall_of_fame.o(.text); diff --git a/src/rom_81700F8.c b/src/rom_81700F8.c new file mode 100644 index 000000000..b786ff9f8 --- /dev/null +++ b/src/rom_81700F8.c @@ -0,0 +1,32 @@ +#include "global.h" +#include "main.h" +#include "gpu_regs.h" +#include "m4a.h" +#include "load_save.h" +#include "save.h" +#include "new_game.h" +#include "rom4.h" +#include "malloc.h" + +void sub_81700F8(void) +{ + u16 imeBackup; + + imeBackup = REG_IME; + REG_IME = 0; + RegisterRamReset(0x00000001); + ClearGpuRegBits(REG_OFFSET_DISPCNT, 0x80); + REG_IME = imeBackup; + gMain.inBattle = FALSE; + SetSaveBlocksPointers(sub_815355C()); + sub_808447C(); + ResetSaveCounters(); + sub_81534D0(0); + if (gSaveFileStatus == 0 || gSaveFileStatus == 2) + { + Sav2_ClearSetDefault(); + } + SetPokemonCryStereo(gSaveBlock2Ptr->optionsSound); + InitHeap(gHeap, 0x1c000); + SetMainCallback2(sub_8086230); +}