diff options
Diffstat (limited to 'arm9/src')
-rw-r--r-- | arm9/src/error_message_reset.c | 51 | ||||
-rw-r--r-- | arm9/src/game_init.c | 284 | ||||
-rw-r--r-- | arm9/src/heap.c | 363 | ||||
-rw-r--r-- | arm9/src/main.c | 10 | ||||
-rw-r--r-- | arm9/src/options.c | 6 | ||||
-rw-r--r-- | arm9/src/unk_0200BB14.c | 4 | ||||
-rw-r--r-- | arm9/src/unk_02016B94.c | 24 | ||||
-rw-r--r-- | arm9/src/unk_0202F150.c | 2 | ||||
-rw-r--r-- | arm9/src/unk_02031734.c | 46 |
9 files changed, 409 insertions, 381 deletions
diff --git a/arm9/src/error_message_reset.c b/arm9/src/error_message_reset.c index 28627d6b..07c285a4 100644 --- a/arm9/src/error_message_reset.c +++ b/arm9/src/error_message_reset.c @@ -1,16 +1,19 @@ #include "error_message_reset.h" #include "GX_layers.h" +#include "gx.h" #include "unk_02031734.h" #include "unk_0202F150.h" #include "unk_02016B94.h" - +#include "PAD_pad.h" const struct UnkStruct_02016B94_4 UNK_020FF49C = { 0, 3, 3, 0x1a, 0x12, 1, 0x23 }; -const u32 UNK_020FF4A4[2] = { 0x00020000, 0x00000000 }; +const struct HeapParam UNK_020FF4A4[] = { + {0x00020000, OS_ARENA_MAIN} +}; -const struct GraphicsModes UNK_020FF4AC = { mode1 : 1 }; +const struct GraphicsModes UNK_020FF4AC = { dispMode : GX_DISPMODE_GRAPHICS }; const struct UnkStruct_02016B94_1 UNK_020FF4BC = { 0, 0, 0x800, 0, 1, 0, 0, 6, 0, 1, 0, 0, 0 }; @@ -44,13 +47,13 @@ THUMB_FUNC void PrintErrorMessageAndReset() OS_SetArenaHi(OS_ARENA_MAIN, OS_GetInitArenaHi(OS_ARENA_MAIN)); OS_SetArenaLo(OS_ARENA_MAIN, OS_GetInitArenaLo(OS_ARENA_MAIN)); - FUN_020166C8((u32 *)UNK_020FF4A4, 1, 1, 0); + InitHeapSystem(UNK_020FF4A4, NELEMS(UNK_020FF4A4), 1, 0); FUN_0200E3A0(PM_LCD_TOP, 0); FUN_0200E3A0(PM_LCD_BOTTOM, 0); - OS_DisableIrqMask(1); - OS_SetIrqFunction(1, &VBlankHandler); - OS_EnableIrqMask(1); + OS_DisableIrqMask(OS_IE_V_BLANK); + OS_SetIrqFunction(OS_IE_V_BLANK, &VBlankHandler); + OS_EnableIrqMask(OS_IE_V_BLANK); Main_SetVBlankIntrCB(NULL, NULL); @@ -58,18 +61,18 @@ THUMB_FUNC void PrintErrorMessageAndReset() GX_DisableEngineALayers(); GX_DisableEngineBLayers(); - reg_GX_DISPCNT &= 0xFFFFE0FF; - reg_GXS_DB_DISPCNT &= 0xFFFFE0FF; + reg_GX_DISPCNT &= ~REG_GX_DISPCNT_DISPLAY_MASK; + reg_GXS_DB_DISPCNT &= ~REG_GXS_DB_DISPCNT_DISPLAY_MASK; - FUN_0201669C(4, 8); + SetKeyRepeatTimers(4, 8); gMain.unk65 = 0; GX_SwapDisplay(); reg_G2_BLDCNT = 0; reg_G2S_DB_BLDCNT = 0; - reg_GX_DISPCNT &= 0xFFFF1FFF; - reg_GXS_DB_DISPCNT &= 0xFFFF1FFF; + reg_GX_DISPCNT &= ~(REG_GX_DISPCNT_OW_MASK | REG_GX_DISPCNT_W1_MASK | REG_GX_DISPCNT_W0_MASK); + reg_GXS_DB_DISPCNT &= ~(REG_GXS_DB_DISPCNT_OW_MASK | REG_GXS_DB_DISPCNT_W1_MASK | REG_GXS_DB_DISPCNT_W0_MASK); GX_SetBanks(&UNK_020FF4D8); ptr = FUN_02016B94(0); @@ -104,24 +107,22 @@ THUMB_FUNC void PrintErrorMessageAndReset() FUN_0200A274(0, 0x3f, 3); FUN_02032DAC(); - lid: - HandleDSLidAction(); - FUN_0202FB80(); - if (!FUN_02033678()) + while (1) { - OS_WaitIrq(1, 1); - goto lid; + HandleDSLidAction(); + FUN_0202FB80(); + if (FUN_02033678()) + break; + OS_WaitIrq(TRUE, OS_IE_V_BLANK); } - - lid2: - HandleDSLidAction(); - if (!((u16)(((reg_PAD_KEYINPUT | *(vu16 *)HW_BUTTON_XY_BUF) ^ 0x2FFF) & 0x2FFF) & 1)) + while (1) { - OS_WaitIrq(1, 1); - goto lid2; + HandleDSLidAction(); + if ((PAD_Read() & PAD_BUTTON_A)) + break; + OS_WaitIrq(TRUE, OS_IE_V_BLANK); } - FUN_0200E3A0(PM_LCD_TOP, 0x7FFF); FUN_0200E3A0(PM_LCD_BOTTOM, 0x7FFF); diff --git a/arm9/src/game_init.c b/arm9/src/game_init.c index 64ea7a54..1c6098ea 100644 --- a/arm9/src/game_init.c +++ b/arm9/src/game_init.c @@ -10,6 +10,7 @@ #include "game_init.h" #include "registers.h" #include "heap.h" +#include "OS_interrupt.h" #pragma thumb on @@ -30,11 +31,11 @@ OS_DTCM; static struct { void * contents; u32 name_hash; -} UNK_021C4928[128]; +} sFileCache[128]; struct Main gMain; -void Main_HBlankIntr(BOOL); +void Main_ToggleHBlankInterrupt(BOOL enableFlag); void FUN_0201B5CC(void *); void FUN_02015EA0(void) @@ -66,7 +67,7 @@ void Main_SetVBlankIntrCB(void (*a0)(void *), void * a1) void FUN_02015F1C(void) { - Main_HBlankIntr(FALSE); + Main_ToggleHBlankInterrupt(FALSE); gMain.hBlankIntr = NULL; gMain.hBlankIntrArg = NULL; } @@ -75,7 +76,7 @@ BOOL FUN_02015F34(void (*a0)(void *), void * a1) { if (a0 == 0) { - Main_HBlankIntr(FALSE); + Main_ToggleHBlankInterrupt(FALSE); gMain.hBlankIntr = NULL; gMain.hBlankIntrArg = NULL; return TRUE; @@ -84,7 +85,7 @@ BOOL FUN_02015F34(void (*a0)(void *), void * a1) { gMain.hBlankIntrArg = a1; gMain.hBlankIntr = a0; - Main_HBlankIntr(TRUE); + Main_ToggleHBlankInterrupt(TRUE); return TRUE; } else @@ -93,36 +94,36 @@ BOOL FUN_02015F34(void (*a0)(void *), void * a1) } } -void FUN_02015F6C(void) +void Main_CallHBlankCallback(void) { if (gMain.hBlankIntr != NULL) gMain.hBlankIntr(gMain.hBlankIntrArg); } -void Main_HBlankIntr(BOOL a0) +void Main_ToggleHBlankInterrupt(BOOL enableFlag) { (void)OS_DisableIrq(); - if (!a0) + if (!enableFlag) { (void)OS_GetIrqMask(); - OS_DisableIrqMask(2); + OS_DisableIrqMask(OS_IE_H_BLANK); GX_HBlankIntr(FALSE); } else { (void)OS_GetIrqMask(); - OS_SetIrqFunction(2, FUN_02015F6C); - OS_EnableIrqMask(2); + OS_SetIrqFunction(OS_IE_H_BLANK, Main_CallHBlankCallback); + OS_EnableIrqMask(OS_IE_H_BLANK); GX_HBlankIntr(TRUE); } (void)OS_EnableIrq(); } -const u32 UNK_020EDB10[][2] = { - { 0x0000D000, 0x00000000 }, - { 0x00021000, 0x00000000 }, - { 0x00001000, 0x00000000 }, - { 0x0010D800, 0x00000000 } +const struct HeapParam UNK_020EDB10[] = { + { 0x00D000, OS_ARENA_MAIN }, + { 0x021000, OS_ARENA_MAIN }, + { 0x001000, OS_ARENA_MAIN }, + { 0x10D800, OS_ARENA_MAIN } }; void FUN_02015FC8(void) @@ -136,12 +137,12 @@ void FUN_02015FC8(void) { csum += digest[i]; } - csum = (csum << 24) >> 24; + csum %= 256; while (csum & 3) { csum++; } - FUN_020166C8((u32 *)UNK_020EDB10, 4, 92, csum); + InitHeapSystem(UNK_020EDB10, NELEMS(UNK_020EDB10), 92, csum); } void InitSystemForTheGame(void) @@ -189,7 +190,7 @@ void InitGraphicMemory(void) MI_CpuClearFast((void *)HW_DB_PLTT, HW_DB_PLTT_SIZE); } -void * FUN_020161A4(u32 heap_id, const char * path) +void * AllocAndReadFile(u32 heap_id, const char * path) { void * ret; @@ -214,7 +215,7 @@ void * FUN_020161A4(u32 heap_id, const char * path) return ret; } -void FUN_020161F8(const char * path, void ** ptr) +void OpenAndReadWholeFile(const char * path, void ** ptr) { FSFile file; FS_InitFile(&file); @@ -227,94 +228,94 @@ void FUN_020161F8(const char * path, void ** ptr) } } -u32 FUN_02016230(const s8 * str) +u32 GetFilenameHash(const s8 * str) { u16 len = (u16)strlen(str); - u16 sp4; + u16 numWords; if ((len % 4) != 0) - sp4 = (u16)((len / 4) + 1); + numWords = (u16)((len / 4) + 1); else - sp4 = (u16)(len / 4); - u32 r7 = 0; + numWords = (u16)(len / 4); + u32 hash = 0; s32 i, j; - for (i = 0; i < sp4; i++) + for (i = 0; i < numWords; i++) { - u32 r1 = 0; + u32 curWord = 0; for (j = 0; j < 4; j++) { - int r5 = str[4 * i + j]; - if (r5 == 0) + int curChar = str[4 * i + j]; + if (curChar == 0) break; - r1 |= r5 << (8 * j); + curWord |= curChar << (8 * j); } - r7 ^= r1; + hash ^= curWord; } - return r7; + return hash; } -int FUN_020162A0(u32 a0) +int GetFileCacheId(u32 hash) { for (int i = 0; i < 128; i++) { - if (UNK_021C4928[i].name_hash == a0 && UNK_021C4928[i].contents != NULL) + if (sFileCache[i].name_hash == hash && sFileCache[i].contents != NULL) return i; } return -1; } -int FUN_020162C8(void * a0, u32 a1) +int AddFileToCache(void * contents, u32 hash) { for (int i = 0; i < 128; i++) { - if (UNK_021C4928[i].contents == NULL) + if (sFileCache[i].contents == NULL) { - UNK_021C4928[i].contents = a0; - UNK_021C4928[i].name_hash = a1; + sFileCache[i].contents = contents; + sFileCache[i].name_hash = hash; return i; } } return -1; } -void FUN_020162FC(void) +void ClearFileCache(void) { for (int i = 127; i > -1; i--) { - if (UNK_021C4928[i].contents != NULL) + if (sFileCache[i].contents != NULL) { - FreeToHeap(UNK_021C4928[i].contents); - UNK_021C4928[i].contents = NULL; - UNK_021C4928[i].name_hash = 0; + FreeToHeap(sFileCache[i].contents); + sFileCache[i].contents = NULL; + sFileCache[i].name_hash = 0; } } } -void * FUN_02016324(const s8 * str, u32 heap_id) +void * OpenFileCached(const s8 * str, u32 heap_id) { - s8 sp0[32]; + s8 filenameBuf[32]; FSFile file; void * ret; - int r5 = 0; + int skipCache = 0; if (str[0] == '!') { - strcpy(sp0, str + 1); - r5 = 1; + strcpy(filenameBuf, str + 1); + skipCache = 1; } else { - strcpy(sp0, str); + strcpy(filenameBuf, str); } - u32 r7 = FUN_02016230(sp0); - s32 r0 = FUN_020162A0(r7); - if (r0 >= 0 && r5 == 0) + u32 hash = GetFilenameHash(filenameBuf); + s32 cacheId = GetFileCacheId(hash); + if (cacheId >= 0 && skipCache == 0) { - ret = UNK_021C4928[r0].contents; + ret = sFileCache[cacheId].contents; } else { FS_InitFile(&file); - if (FS_OpenFile(&file, (const char *)sp0)) + if (FS_OpenFile(&file, (const char *)filenameBuf)) { u32 size = file.prop.file.bottom - file.prop.file.top; ret = AllocFromHeap(heap_id, size); @@ -327,8 +328,8 @@ void * FUN_02016324(const s8 * str, u32 heap_id) } } FS_CloseFile(&file); - if (r5 == 0) - FUN_020162C8(ret, r7); + if (skipCache == 0) + AddFileToCache(ret, hash); } else ret = NULL; @@ -336,24 +337,24 @@ void * FUN_02016324(const s8 * str, u32 heap_id) return ret; } -void FUN_020163BC(void) +void InitKeypadAndTouchpad(void) { TPCalibrateParam tp; - gMain.unk34 = 0; - gMain.unk38 = 0; - gMain.unk3C = 0; - gMain.unk40 = 0; - gMain.unk44 = 0; + gMain.buttonMode = 0; + gMain.heldKeysRaw = 0; + gMain.newKeysRaw = 0; + gMain.newAndRepeatedKeysRaw = 0; + gMain.heldKeys = 0; gMain.newKeys = 0; gMain.newAndRepeatedKeys = 0; - gMain.unk50 = 0; - gMain.unk54 = 8; - gMain.unk58 = 15; - gMain.unk5C = 0; - gMain.unk5E = 0; - gMain.unk60 = 0; - gMain.unk62 = 0; - gMain.unk64 = 0; + gMain.keyRepeatCounter = 0; + gMain.keyRepeatContinueDelay = 8; + gMain.keyRepeatStartDelay = 15; + gMain.touchX = 0; + gMain.touchY = 0; + gMain.touchNew = 0; + gMain.touchHeld = 0; + gMain.touchpadReadAuto = 0; TP_Init(); if (TP_GetUserInfo(&tp) == TRUE) TP_SetCalibrateParam(&tp); @@ -382,38 +383,53 @@ void FUN_02016454(u8 a0) gMain.unk67 &= ~a0; } -void FUN_02016464(void) +void ReadKeypadAndTocuhpad(void) { TPData raw, calib; if (PAD_DetectFold()) { + // Can't press any buttons while the lid is closed. gMain.newKeys = 0; - gMain.unk44 = 0; + gMain.heldKeys = 0; gMain.newAndRepeatedKeys = 0; - gMain.unk60 = 0; - gMain.unk62 = 0; + gMain.touchNew = 0; + gMain.touchHeld = 0; return; } - u32 r0 = PAD_Read(); - gMain.unk40 = gMain.unk3C = (r0 ^ gMain.unk38) & r0; - if (r0 != 0 && gMain.unk38 == r0) + + u32 padRead = PAD_Read(); + + // newKeys is all keys that were pressed on this frame but + // not the last frame. + gMain.newAndRepeatedKeysRaw = gMain.newKeysRaw = (padRead ^ gMain.heldKeysRaw) & padRead; + + // If you are holding down buttons, indicate them "repeated" every few frames + // as defined by .keyRepeatStartDelay and .keyRepeatContinueDelay. + // Same logic as gen3, but fixes the bug where the + // remapped keys are incorrectly used here. + // See also: pokeemerald/src/main.c:ReadKeys + if (padRead != 0 && gMain.heldKeysRaw == padRead) { - if (--gMain.unk50 == 0) + if (--gMain.keyRepeatCounter == 0) { - gMain.unk40 = r0; - gMain.unk50 = gMain.unk54; + gMain.newAndRepeatedKeysRaw = padRead; + gMain.keyRepeatCounter = gMain.keyRepeatContinueDelay; } } else { - gMain.unk50 = gMain.unk58; + gMain.keyRepeatCounter = gMain.keyRepeatStartDelay; } - gMain.unk38 = r0; - gMain.newKeys = gMain.unk3C; - gMain.unk44 = r0; - gMain.newAndRepeatedKeys = gMain.unk40; - FUN_02016568(); - if (gMain.unk64 == 0) + gMain.heldKeysRaw = padRead; + + // Apply the button mode option to the read key input + gMain.newKeys = gMain.newKeysRaw; + gMain.heldKeys = padRead; + gMain.newAndRepeatedKeys = gMain.newAndRepeatedKeysRaw; + ApplyButtonModeToInput(); + + // Read the touchpad. New to gen 4. + if (gMain.touchpadReadAuto == 0) { while (TP_RequestRawSampling(&raw)) ; @@ -421,111 +437,117 @@ void FUN_02016464(void) else TP_GetLatestRawPointInAuto(&raw); TP_GetCalibratedPoint(&calib, &raw); - if (calib.validity == 0) + + // If the touchpad is valid, we gucci. + if (calib.validity == TP_VALIDITY_VALID) { - gMain.unk5C = calib.x; - gMain.unk5E = calib.y; + gMain.touchX = calib.x; + gMain.touchY = calib.y; } - else if (gMain.unk62) + + // If the touchpad was used last frame, salvage what we can. + else if (gMain.touchHeld) { switch (calib.validity) { - case 1: - gMain.unk5E = calib.y; + case TP_VALIDITY_INVALID_X: + gMain.touchY = calib.y; break; - case 2: - gMain.unk5C = calib.x; + case TP_VALIDITY_INVALID_Y: + gMain.touchX = calib.x; break; - case 3: + case TP_VALIDITY_INVALID_XY: break; } } + // What was read from the touchpad was not salvageable. + // Ignore touch input. else calib.touch = 0; - gMain.unk60 = (u16)((gMain.unk62 ^ calib.touch) & calib.touch); - gMain.unk62 = calib.touch; + gMain.touchNew = (u16)((gMain.touchHeld ^ calib.touch) & calib.touch); + gMain.touchHeld = calib.touch; } -void FUN_02016568(void) +void ApplyButtonModeToInput(void) { - switch (gMain.unk34) + switch (gMain.buttonMode) { case 0: // Normal break; case 1: // Start = X if (gMain.newKeys & PAD_BUTTON_START) gMain.newKeys |= PAD_BUTTON_X; - if (gMain.unk44 & PAD_BUTTON_START) - gMain.unk44 |= PAD_BUTTON_X; + if (gMain.heldKeys & PAD_BUTTON_START) + gMain.heldKeys |= PAD_BUTTON_X; if (gMain.newAndRepeatedKeys & PAD_BUTTON_START) gMain.newAndRepeatedKeys |= PAD_BUTTON_X; break; case 2: // Swap X and Y; unused in the retail game { - u32 r1 = 0; + u32 swapMask = 0; if (gMain.newKeys & PAD_BUTTON_X) { - r1 |= PAD_BUTTON_Y; + swapMask |= PAD_BUTTON_Y; } if (gMain.newKeys & PAD_BUTTON_Y) { - r1 |= PAD_BUTTON_X; + swapMask |= PAD_BUTTON_X; } - gMain.newKeys &= 0xF3FF; - gMain.newKeys |= r1; + gMain.newKeys &= ((PAD_BUTTON_X | PAD_BUTTON_Y) ^ 0xFFFF);; + gMain.newKeys |= swapMask; } { - u32 r1 = 0; - if (gMain.unk44 & PAD_BUTTON_X) + u32 swapMask = 0; + if (gMain.heldKeys & PAD_BUTTON_X) { - r1 |= PAD_BUTTON_Y; + swapMask |= PAD_BUTTON_Y; } - if (gMain.unk44 & PAD_BUTTON_Y) + if (gMain.heldKeys & PAD_BUTTON_Y) { - r1 |= PAD_BUTTON_X; + swapMask |= PAD_BUTTON_X; } - gMain.unk44 &= 0xF3FF; - gMain.unk44 |= r1; + gMain.heldKeys &= ((PAD_BUTTON_X | PAD_BUTTON_Y) ^ 0xFFFF); + gMain.heldKeys |= swapMask; } { - u32 r1 = 0; + u32 swapMask = 0; if (gMain.newAndRepeatedKeys & PAD_BUTTON_X) { - r1 |= PAD_BUTTON_Y; + swapMask |= PAD_BUTTON_Y; } if (gMain.newAndRepeatedKeys & PAD_BUTTON_Y) { - r1 |= PAD_BUTTON_X; + swapMask |= PAD_BUTTON_X; } - gMain.newAndRepeatedKeys &= 0xF3FF; - gMain.newAndRepeatedKeys |= r1; + gMain.newAndRepeatedKeys &= ((PAD_BUTTON_X | PAD_BUTTON_Y) ^ 0xFFFF); + gMain.newAndRepeatedKeys |= swapMask; } break; case 3: // L = A if (gMain.newKeys & PAD_BUTTON_L) gMain.newKeys |= PAD_BUTTON_A; - if (gMain.unk44 & PAD_BUTTON_L) - gMain.unk44 |= PAD_BUTTON_A; + if (gMain.heldKeys & PAD_BUTTON_L) + gMain.heldKeys |= PAD_BUTTON_A; if (gMain.newAndRepeatedKeys & PAD_BUTTON_L) gMain.newAndRepeatedKeys |= PAD_BUTTON_A; - gMain.newKeys &= 0xFCFF; - gMain.unk44 &= 0xFCFF; - gMain.newAndRepeatedKeys &= 0xFCFF; + gMain.newKeys &= ((PAD_BUTTON_L | PAD_BUTTON_R) ^ 0xFFFF); + gMain.heldKeys &= ((PAD_BUTTON_L | PAD_BUTTON_R) ^ 0xFFFF); + gMain.newAndRepeatedKeys &= ((PAD_BUTTON_L | PAD_BUTTON_R) ^ 0xFFFF); } } -void FUN_0201669C(int x, int y) +void SetKeyRepeatTimers(int continueDelay, int startDelay) { - gMain.unk54 = x; - gMain.unk58 = y; + gMain.keyRepeatContinueDelay = continueDelay; + gMain.keyRepeatStartDelay = startDelay; } -void FUN_020166A8(u8 a0) +void SetSoftResetDisableMask(u8 a0) { - gMain.unk68 |= a0; + gMain.softResetDisabled |= a0; } -void FUN_020166B8(u8 a0) +void ClearSoftResetDisableMask(u8 a0) { - gMain.unk68 &= ~a0; + gMain.softResetDisabled &= ~a0; } diff --git a/arm9/src/heap.c b/arm9/src/heap.c index 7f35fdcc..842fd33a 100644 --- a/arm9/src/heap.c +++ b/arm9/src/heap.c @@ -1,31 +1,45 @@ #include "heap.h" #include "error_message_reset.h" #include "unk_02031734.h" +#include "NNS_FND_expheap.h" +#include "NNS_FND_allocator.h" +struct HeapInfo +{ + NNSFndHeapHandle *heapHandles; + NNSFndHeapHandle *parentHeapHandles; + void **subHeapRawPtrs; + u16 *numMemBlocks; + u8 *heapIdxs; + u16 totalNumHeaps; + u16 nTemplates; + u16 maxHeaps; + u16 unallocatedHeapId; +}; + +typedef struct MemoryBlock +{ + u8 filler_00[12]; + u32 heapId:8; + u32 filler_0D:24; +} MemoryBlock; -extern void *NNS_FndCreateExpHeapEx(void *param0, u32 param1, u32 param2); -extern void *NNS_FndAllocFromExpHeapEx(void *param0, u32 param1, s32 param2); -extern void NNS_FndDestroyExpHeap(); -extern void NNS_FndFreeToExpHeap(void *ptr1, void *ptr2); -extern u32 NNS_FndGetTotalFreeSizeForExpHeap(void *param0); -extern void NNS_FndInitAllocatorForExpHeap(u32 param0, void *param1, u32 param2); -extern u32 NNS_FndGetSizeForMBlockExpHeap(void *param0); -extern void NNS_FndResizeForMBlockExpHeap(void *ptr1, void *ptr2, u32 param2); - - -struct UnkStruct_020166C8 UNK_021C4D28; - +struct HeapInfo sHeapInfo; -THUMB_FUNC void FUN_020166C8(u32 *param0, u32 param1, u32 param2, u32 pre_size) +THUMB_FUNC void InitHeapSystem(const struct HeapParam *templates, u32 nTemplates, u32 totalNumHeaps, u32 pre_size) { - u32 unk_size = param1 + 24; + void * ptr; + u32 unk_size, i; - if (param2 < unk_size) + unk_size = nTemplates + 24; + + if (totalNumHeaps < unk_size) { - param2 = unk_size; + totalNumHeaps = unk_size; } if (pre_size != 0) { + // force align while (pre_size % 4 != 0) { pre_size++; @@ -34,207 +48,196 @@ THUMB_FUNC void FUN_020166C8(u32 *param0, u32 param1, u32 param2, u32 pre_size) OS_AllocFromArenaLo(OS_ARENA_MAIN, pre_size, 4); } - u32 r7 = param2 * 2; - - void *ptr = OS_AllocFromArenaLo(OS_ARENA_MAIN, (unk_size * 3 + 1) * sizeof(u32) + r7 + param2, 4); - UNK_021C4D28.unk00 = ptr; - ptr += (unk_size + 1) * 4; - UNK_021C4D28.unk04 = ptr; - ptr += unk_size * 4; - UNK_021C4D28.unk08 = ptr; - ptr += unk_size * 4; - UNK_021C4D28.unk0c = ptr; - ptr += r7; - UNK_021C4D28.unk10 = ptr; - UNK_021C4D28.unk14 = (u16)param2; - UNK_021C4D28.unk16 = (u16)param1; - - r7 = 0; - UNK_021C4D28.unk1a = (u16)unk_size; - UNK_021C4D28.unk18 = (u16)unk_size; - - while (r7 < param1) + sHeapInfo.heapHandles = (NNSFndHeapHandle*) OS_AllocFromArenaLo( + OS_ARENA_MAIN, + (unk_size + 1) * sizeof(NNSFndHeapHandle) + + unk_size * sizeof(NNSFndHeapHandle) + + unk_size * sizeof(void *) + + totalNumHeaps * sizeof(u16) + + totalNumHeaps, + 4 + ); + sHeapInfo.parentHeapHandles = sHeapInfo.heapHandles + (unk_size + 1); + sHeapInfo.subHeapRawPtrs = (void **)(sHeapInfo.parentHeapHandles + unk_size); + sHeapInfo.numMemBlocks = (u16 *)(sHeapInfo.subHeapRawPtrs + unk_size); + sHeapInfo.heapIdxs = (u8 *)(sHeapInfo.numMemBlocks + totalNumHeaps); + sHeapInfo.totalNumHeaps = (u16)totalNumHeaps; + sHeapInfo.nTemplates = (u16)nTemplates; + + sHeapInfo.unallocatedHeapId = (u16)unk_size; + sHeapInfo.maxHeaps = (u16)unk_size; + + for (i = 0; i < nTemplates; i++) { - void *ptr; - if (param0[1] == 0 || param0[1] != 2) + switch (templates[i].arena) { - ptr = OS_AllocFromArenaLo(OS_ARENA_MAIN, param0[0], 4); - } - else - { - ptr = OS_AllocFromArenaHi(OS_ARENA_MAINEX, param0[0], 4); + case OS_ARENA_MAIN: + default: + ptr = OS_AllocFromArenaLo(OS_ARENA_MAIN, templates[i].size, 4); + break; + case OS_ARENA_MAINEX: + ptr = OS_AllocFromArenaHi(OS_ARENA_MAINEX, templates[i].size, 4); + break; } - if (ptr != 0) + if (ptr != NULL) { - UNK_021C4D28.unk00[r7] = NNS_FndCreateExpHeapEx(ptr, param0[0], 0); - UNK_021C4D28.unk10[r7] = (u8)r7; + sHeapInfo.heapHandles[i] = NNS_FndCreateExpHeap(ptr, templates[i].size); + sHeapInfo.heapIdxs[i] = (u8)i; } else { - GF_AssertFail(); + GF_ASSERT(0); } - - param0 += 2; - r7++; } - while (param1 < unk_size + 1) + for (i = nTemplates; i < unk_size + 1; i++) { - UNK_021C4D28.unk00[param1] = 0; - UNK_021C4D28.unk10[param1] = (u8)UNK_021C4D28.unk1a; - - param1++; + sHeapInfo.heapHandles[i] = NULL; + sHeapInfo.heapIdxs[i] = (u8)sHeapInfo.unallocatedHeapId; } - while (param1 < param2) + while (i < totalNumHeaps) { - UNK_021C4D28.unk10[param1] = (u8)UNK_021C4D28.unk1a; + sHeapInfo.heapIdxs[i] = (u8)sHeapInfo.unallocatedHeapId; - param1++; + i++; } - for (param1 = 0; param1 < param2; param1++) + for (i = 0; i < totalNumHeaps; i++) { - UNK_021C4D28.unk0c[param1] = 0; + sHeapInfo.numMemBlocks[i] = 0; } } -THUMB_FUNC s32 FUN_020167F4() +THUMB_FUNC s32 FindFirstAvailableHeapHandle() { - s32 i = UNK_021C4D28.unk16; - s32 j = UNK_021C4D28.unk18; + s32 i; - if (i < j) + for (i = sHeapInfo.nTemplates; i < sHeapInfo.maxHeaps; i++) { - void **ptr = UNK_021C4D28.unk00 + i; - do - { - if (*ptr == 0) - { - return i; - } - i++; - ptr++; - } while (i < j); + if (sHeapInfo.heapHandles[i] == NULL) + return i; } return -1; } -THUMB_FUNC u32 FUN_0201681C(u32 param0, u32 param1, u32 param2) +THUMB_FUNC BOOL CreateHeap(u32 parent, u32 child, u32 size) { - return FUN_02016834(param0, param1, param2, 4); + return CreateHeapInternal(parent, child, size, 4); } -THUMB_FUNC u32 FUN_02016828(u32 param0, u32 param1, u32 param2) +THUMB_FUNC BOOL CreateHeapAtEnd(u32 parent, u32 child, u32 size) { - return FUN_02016834(param0, param1, param2, -4); + return CreateHeapInternal(parent, child, size, -4); } -THUMB_FUNC u32 FUN_02016834(u32 param0, u32 param1, u32 param2, s32 param3) +THUMB_FUNC BOOL CreateHeapInternal(u32 parent, u32 child, u32 size, s32 alignment) { GF_ASSERT(OS_GetProcMode() != OS_PROCMODE_IRQ); - u8 *ptr = UNK_021C4D28.unk10; - if (UNK_021C4D28.unk1a == ptr[param1]) + u8 *ptr = sHeapInfo.heapIdxs; + if (sHeapInfo.unallocatedHeapId == ptr[child]) { - void *ptr2 = UNK_021C4D28.unk00[ptr[param0]]; - if (ptr2 != 0) + NNSFndHeapHandle parentHeap = sHeapInfo.heapHandles[ptr[parent]]; + if (parentHeap != NULL) { - void *ptr3 = NNS_FndAllocFromExpHeapEx(ptr2, param2, param3); - if (ptr3 != 0) + void *newHeapAddr = NNS_FndAllocFromExpHeapEx(parentHeap, size, alignment); + if (newHeapAddr != NULL) { - param3 = FUN_020167F4(); - if (param3 >= 0) + s32 i = FindFirstAvailableHeapHandle(); + if (i >= 0) { - UNK_021C4D28.unk00[param3] = NNS_FndCreateExpHeapEx(ptr3, param2, 0); + sHeapInfo.heapHandles[i] = NNS_FndCreateExpHeap(newHeapAddr, size); - if (UNK_021C4D28.unk00[param3] != 0) + if (sHeapInfo.heapHandles[i] != NULL) { - UNK_021C4D28.unk04[param3] = ptr2; - UNK_021C4D28.unk08[param3] = ptr3; - UNK_021C4D28.unk10[param1] = (u8)param3; + sHeapInfo.parentHeapHandles[i] = parentHeap; + sHeapInfo.subHeapRawPtrs[i] = newHeapAddr; + sHeapInfo.heapIdxs[child] = (u8)i; - return 1; + return TRUE; } else { - GF_AssertFail(); + GF_ASSERT(0); } } else { - GF_AssertFail(); + GF_ASSERT(0); } } else { - GF_AssertFail(); + GF_ASSERT(0); } } else { - GF_AssertFail(); + GF_ASSERT(0); } } else { - GF_AssertFail(); + GF_ASSERT(0); } - return 0; + return FALSE; } -THUMB_FUNC void FUN_020168D0(u32 heap_id) +THUMB_FUNC void DestroyHeap(u32 heap_id) { - GF_ASSERT (OS_GetProcMode() != OS_PROCMODE_IRQ); + GF_ASSERT(OS_GetProcMode() != OS_PROCMODE_IRQ); + + NNSFndHeapHandle handle = sHeapInfo.heapHandles[sHeapInfo.heapIdxs[heap_id]]; - if (UNK_021C4D28.unk00[UNK_021C4D28.unk10[heap_id]] != 0) + if (handle != NULL) { - NNS_FndDestroyExpHeap(); + NNS_FndDestroyExpHeap(handle); - u8 index = UNK_021C4D28.unk10[heap_id]; - void *ptr1 = UNK_021C4D28.unk04[index]; - void *ptr2 = UNK_021C4D28.unk08[index]; - if (ptr1 != 0 && ptr2 != 0) + u8 index = sHeapInfo.heapIdxs[heap_id]; + NNSFndHeapHandle parentHeap = sHeapInfo.parentHeapHandles[index]; + void *childRaw = sHeapInfo.subHeapRawPtrs[index]; + if (parentHeap != NULL && childRaw != NULL) { - NNS_FndFreeToExpHeap(ptr1, ptr2); + NNS_FndFreeToExpHeap(parentHeap, childRaw); } else { - GF_AssertFail(); + GF_ASSERT(0); } - UNK_021C4D28.unk00[UNK_021C4D28.unk10[heap_id]] = 0; - UNK_021C4D28.unk04[UNK_021C4D28.unk10[heap_id]] = 0; - UNK_021C4D28.unk08[UNK_021C4D28.unk10[heap_id]] = 0; + sHeapInfo.heapHandles[sHeapInfo.heapIdxs[heap_id]] = NULL; + sHeapInfo.parentHeapHandles[sHeapInfo.heapIdxs[heap_id]] = NULL; + sHeapInfo.subHeapRawPtrs[sHeapInfo.heapIdxs[heap_id]] = NULL; - UNK_021C4D28.unk10[heap_id] = (u8)UNK_021C4D28.unk1a; + sHeapInfo.heapIdxs[heap_id] = (u8)sHeapInfo.unallocatedHeapId; } } -THUMB_FUNC u32 *FUN_02016944(void *param0, u32 param1, s32 param2, u32 param3) +THUMB_FUNC void *AllocFromHeapInternal(NNSFndHeapHandle heap, u32 size, s32 alignment, u32 heap_id) { - GF_ASSERT(param0); + GF_ASSERT(heap); OSIntrMode intr_mode = OS_DisableInterrupts(); - param1 += 16; - u32 *ptr = (u32 *)NNS_FndAllocFromExpHeapEx(param0, param1, param2); + size += sizeof(MemoryBlock); + void *ptr = NNS_FndAllocFromExpHeapEx(heap, size, alignment); OS_RestoreInterrupts(intr_mode); - if (ptr != 0) + if (ptr != NULL) { - ptr[3] = (ptr[3] & ~0xff) | (param3 & 0xff); + ((MemoryBlock *)ptr)->heapId = heap_id; - ptr += 4; + ptr += sizeof(MemoryBlock); } return ptr; } -THUMB_FUNC void FUN_02016988() +THUMB_FUNC void AllocFail() { if (FUN_02031810() != 0) { @@ -244,19 +247,19 @@ THUMB_FUNC void FUN_02016988() void *AllocFromHeap(u32 heap_id, u32 size) { - void *ptr = 0; - if (heap_id < UNK_021C4D28.unk14) + void *ptr = NULL; + if (heap_id < sHeapInfo.totalNumHeaps) { - u8 index = UNK_021C4D28.unk10[heap_id]; - ptr = FUN_02016944(UNK_021C4D28.unk00[index], size, 4, heap_id); + u8 index = sHeapInfo.heapIdxs[heap_id]; + ptr = AllocFromHeapInternal(sHeapInfo.heapHandles[index], size, 4, heap_id); } - if (ptr != 0) + if (ptr != NULL) { - UNK_021C4D28.unk0c[heap_id]++; + sHeapInfo.numMemBlocks[heap_id]++; } else { - FUN_02016988(); + AllocFail(); } return ptr; @@ -264,20 +267,20 @@ void *AllocFromHeap(u32 heap_id, u32 size) void *AllocFromHeapAtEnd(u32 heap_id, u32 size) { - void *ptr = 0; - if (heap_id < UNK_021C4D28.unk14) + void *ptr = NULL; + if (heap_id < sHeapInfo.totalNumHeaps) { - u8 index = UNK_021C4D28.unk10[heap_id]; - ptr = FUN_02016944(UNK_021C4D28.unk00[index], size, -4, heap_id); + u8 index = sHeapInfo.heapIdxs[heap_id]; + ptr = AllocFromHeapInternal(sHeapInfo.heapHandles[index], size, -4, heap_id); } - if (ptr != 0) + if (ptr != NULL) { - UNK_021C4D28.unk0c[heap_id]++; + sHeapInfo.numMemBlocks[heap_id]++; } else { - FUN_02016988(); + AllocFail(); } return ptr; @@ -285,97 +288,99 @@ void *AllocFromHeapAtEnd(u32 heap_id, u32 size) void FreeToHeap(void *ptr) { - u8 heap_id = (u8)((u32 *)ptr)[-1]; + ptr -= sizeof(MemoryBlock); + u32 heap_id = ((MemoryBlock *)ptr)->heapId; - if ((u16)heap_id < UNK_021C4D28.unk14) + if (heap_id < sHeapInfo.totalNumHeaps) { - u8 index = UNK_021C4D28.unk10[heap_id]; - void *ptr2 = UNK_021C4D28.unk00[index]; - GF_ASSERT(ptr2); + u8 index = sHeapInfo.heapIdxs[heap_id]; + NNSFndHeapHandle heap = sHeapInfo.heapHandles[index]; + GF_ASSERT(heap != NULL); - if (UNK_021C4D28.unk0c[heap_id] == 0) + if (sHeapInfo.numMemBlocks[heap_id] == 0) { - FUN_02016B90(heap_id); + GF_heap_c_dummy_return_true(heap_id); } - GF_ASSERT(UNK_021C4D28.unk0c[heap_id]); + GF_ASSERT(sHeapInfo.numMemBlocks[heap_id] != 0); - UNK_021C4D28.unk0c[heap_id]--; + sHeapInfo.numMemBlocks[heap_id]--; OSIntrMode intr_mode = OS_DisableInterrupts(); - NNS_FndFreeToExpHeap(ptr2, ptr - 16); + NNS_FndFreeToExpHeap(heap, ptr); OS_RestoreInterrupts(intr_mode); return; } - GF_AssertFail(); + GF_ASSERT(0); } -void FreeToHeapExplicit(u32 param0, void *param1) +void FreeToHeapExplicit(u32 heap_id, void *ptr) { - GF_ASSERT (OS_GetProcMode() != OS_PROCMODE_IRQ); + GF_ASSERT(OS_GetProcMode() != OS_PROCMODE_IRQ); - if (param0 < UNK_021C4D28.unk14) + if (heap_id < sHeapInfo.totalNumHeaps) { - u8 index = UNK_021C4D28.unk10[param0]; - void *ptr = UNK_021C4D28.unk00[index]; - GF_ASSERT (ptr ); + u8 index = sHeapInfo.heapIdxs[heap_id]; + NNSFndHeapHandle heap = sHeapInfo.heapHandles[index]; + GF_ASSERT( heap != NULL ); - u8 heap_id = (u8)((u32 *)param1)[-1]; - GF_ASSERT (heap_id == param0); + ptr -= sizeof(MemoryBlock); + GF_ASSERT(((MemoryBlock *)ptr)->heapId == heap_id); - NNS_FndFreeToExpHeap(ptr, param1 - 16); - GF_ASSERT (UNK_021C4D28.unk0c[param0]); + NNS_FndFreeToExpHeap(heap, ptr); + GF_ASSERT(sHeapInfo.numMemBlocks[heap_id] != 0); - UNK_021C4D28.unk0c[param0]--; + sHeapInfo.numMemBlocks[heap_id]--; return; } - GF_AssertFail(); + GF_ASSERT(0); } -THUMB_FUNC u32 FUN_02016AF8(u32 param0) +THUMB_FUNC u32 GF_ExpHeap_FndGetTotalFreeSize(u32 heap_id) { - if (param0 < UNK_021C4D28.unk14) + if (heap_id < sHeapInfo.totalNumHeaps) { - u8 index = UNK_021C4D28.unk10[param0]; - return NNS_FndGetTotalFreeSizeForExpHeap(UNK_021C4D28.unk00[index]); + u8 index = sHeapInfo.heapIdxs[heap_id]; + return NNS_FndGetTotalFreeSizeForExpHeap(sHeapInfo.heapHandles[index]); } - GF_AssertFail(); + GF_ASSERT(0); return 0; } -THUMB_FUNC void FUN_02016B20(u32 param0, u32 param1, u32 param2) +THUMB_FUNC void GF_ExpHeap_FndInitAllocator(NNSFndAllocator * pAllocator, u32 heap_id, int alignment) { - if (param1 < UNK_021C4D28.unk14) + if (heap_id < sHeapInfo.totalNumHeaps) { - u8 index = UNK_021C4D28.unk10[param1]; - NNS_FndInitAllocatorForExpHeap(param0, UNK_021C4D28.unk00[index], param2); + u8 index = sHeapInfo.heapIdxs[heap_id]; + NNS_FndInitAllocatorForExpHeap(pAllocator, sHeapInfo.heapHandles[index], alignment); return; } - GF_AssertFail(); + GF_ASSERT(0); } -THUMB_FUNC void FUN_02016B44(void *ptr, u32 param1) +THUMB_FUNC void ReallocFromHeap(void *ptr, u32 newSize) { - GF_ASSERT (OS_GetProcMode() != OS_PROCMODE_IRQ); + GF_ASSERT(OS_GetProcMode() != OS_PROCMODE_IRQ); - param1 += 16; - if (NNS_FndGetSizeForMBlockExpHeap(ptr - 16) >= param1) + newSize += sizeof(MemoryBlock); + ptr -= sizeof(MemoryBlock); + if (NNS_FndGetSizeForMBlockExpHeap(ptr) >= newSize) { - u8 heap_id = (u8)((u32 *)ptr)[-1]; + u32 heap_id = ((MemoryBlock *)ptr)->heapId; - u8 index = UNK_021C4D28.unk10[heap_id]; + u8 index = sHeapInfo.heapIdxs[heap_id]; - NNS_FndResizeForMBlockExpHeap(UNK_021C4D28.unk00[index], ptr - 16, param1); + NNS_FndResizeForMBlockExpHeap(sHeapInfo.heapHandles[index], ptr, newSize); return; } - GF_AssertFail(); + GF_ASSERT(0); } -THUMB_FUNC u32 FUN_02016B90(u32 param0) +THUMB_FUNC BOOL GF_heap_c_dummy_return_true(u32 heap_id) { -#pragma unused(param0) - return 1; +#pragma unused(heap_id) + return TRUE; } diff --git a/arm9/src/main.c b/arm9/src/main.c index 749bec41..fa35c81c 100644 --- a/arm9/src/main.c +++ b/arm9/src/main.c @@ -53,10 +53,10 @@ THUMB_FUNC void NitroMain(void) { InitSystemForTheGame(); InitGraphicMemory(); - FUN_020163BC(); + InitKeypadAndTouchpad(); FUN_02016438(0); - PM_GetBackLight((PMBackLightSwitch *)SDK_STATIC_BSS_START, NULL); + PM_GetBackLight(&gBacklightTop, NULL); FUN_02022294(); GF_InitRTCWork(); @@ -104,8 +104,8 @@ THUMB_FUNC void NitroMain(void) { FUN_02000EE8(); HandleDSLidAction(); - FUN_02016464(); - if ((gMain.unk38 & SOFT_RESET_KEY) == SOFT_RESET_KEY && !gMain.unk68) // soft reset? + ReadKeypadAndTocuhpad(); + if ((gMain.heldKeysRaw & SOFT_RESET_KEY) == SOFT_RESET_KEY && !gMain.softResetDisabled) // soft reset? { DoSoftReset(0); // soft reset? } @@ -248,7 +248,7 @@ THUMB_FUNC void FUN_02000F4C(u32 arg0, u32 arg1) while (1) { HandleDSLidAction(); - FUN_02016464(); + ReadKeypadAndTocuhpad(); if (gMain.newKeys & 1) break; FUN_02000E9C(); diff --git a/arm9/src/options.c b/arm9/src/options.c index 296b398a..03b63864 100644 --- a/arm9/src/options.c +++ b/arm9/src/options.c @@ -35,14 +35,14 @@ void Options_SetButtonModeOnMain(struct SaveBlock2 * sav2, u32 buttonMode) { switch (buttonMode) { case 1: - gMain.unk34 = 1; + gMain.buttonMode = 1; break; case 2: - gMain.unk34 = 3; + gMain.buttonMode = 3; break; case 0: default: - gMain.unk34 = 0; + gMain.buttonMode = 0; break; } } diff --git a/arm9/src/unk_0200BB14.c b/arm9/src/unk_0200BB14.c index 45850885..358d21ea 100644 --- a/arm9/src/unk_0200BB14.c +++ b/arm9/src/unk_0200BB14.c @@ -323,7 +323,7 @@ THUMB_FUNC BOOL FUN_0200BD20( for (s32 i = 0; i < st14; i++) { u32 st18 = FUN_02009660(param1->unk08, i); - void *st1c = FUN_020161A4(param0->unk000, st10[i]); + void *st1c = AllocAndReadFile(param0->unk000, st10[i]); FUN_02009668(st1c, st18, param0->unk000); FreeToHeap(st1c); @@ -344,7 +344,7 @@ THUMB_FUNC BOOL FUN_0200BD20( FUN_02009A90(param1->unk24[0]); FUN_02009D34(param1->unk24[1]); - void *r6 = FUN_020161A4(param0->unk000, st10[6]); + void *r6 = AllocAndReadFile(param0->unk000, st10[6]); param1->unk04 = FUN_02008BE0(r6, param0->unk000, param1->unk0c[0], diff --git a/arm9/src/unk_02016B94.c b/arm9/src/unk_02016B94.c index 6a9dd194..c03fbd75 100644 --- a/arm9/src/unk_02016B94.c +++ b/arm9/src/unk_02016B94.c @@ -73,32 +73,32 @@ THUMB_FUNC u32 FUN_02016BB8(u32 *param0) THUMB_FUNC void FUN_02016BBC(const struct GraphicsModes *modes) { - GX_SetGraphicsMode(modes->mode1, modes->mode2, modes->mode4); - GXS_SetGraphicsMode(modes->mode3); - reg_GX_DISPCNT &= 0xC7FFFFFF; - reg_GX_DISPCNT &= 0xF8FFFFFF; + GX_SetGraphicsMode(modes->dispMode, modes->bgMode, modes->_2d3dMode); + GXS_SetGraphicsMode(modes->subMode); + reg_GX_DISPCNT &= ~REG_GX_DISPCNT_BGSCREENOFFSET_MASK; + reg_GX_DISPCNT &= ~REG_GX_DISPCNT_BGCHAROFFSET_MASK; GX_DisableEngineALayers(); GX_DisableEngineBLayers(); } -THUMB_FUNC void FUN_02016BF4(u32 *param0, u32 param1) +THUMB_FUNC void FUN_02016BF4(const struct GraphicsModes *param0, u32 param1) { if (param1 == 0) { - GX_SetGraphicsMode(param0[0], param0[1], param0[3]); + GX_SetGraphicsMode(param0->dispMode, param0->bgMode, param0->_2d3dMode); GX_DisableEngineALayers(); } else { - GXS_SetGraphicsMode(param0[2]); + GXS_SetGraphicsMode(param0->subMode); GX_DisableEngineBLayers(); } } #ifdef NONMATCHING THUMB_FUNC void FUN_02016C18( - struct UnkStruct_02016B94_2 *param0, u8 param1, struct UnkStruct_02016B94_1 *param2, u8 param3) + struct UnkStruct_02016B94_2 *param0, u8 param1, const struct UnkStruct_02016B94_1 *param2, u8 param3) { u8 res = FUN_020177DC(param2->unk10, param3); switch (param1) @@ -342,7 +342,7 @@ THUMB_FUNC void FUN_02016C18( } #else THUMB_FUNC asm void FUN_02016C18( - struct UnkStruct_02016B94_2 *param0, u8 param1, struct UnkStruct_02016B94_1 *param2, u8 param3) + struct UnkStruct_02016B94_2 *param0, u8 param1, const struct UnkStruct_02016B94_1 *param2, u8 param3) { // clang-format off push {r3-r7, lr} @@ -4603,7 +4603,7 @@ THUMB_FUNC void FUN_020190EC(struct UnkStruct_02016B94_2 *param0, } THUMB_FUNC void FUN_02019150( - struct UnkStruct_02016B94_2 *param0, struct Window *param1, struct UnkStruct_02016B94_4 *param2) + struct UnkStruct_02016B94_2 *param0, struct Window *param1, const struct UnkStruct_02016B94_4 *param2) { FUN_02019064(param0, @@ -7745,7 +7745,7 @@ THUMB_FUNC void FUN_0201AB24(struct Window *window, u8 param1) THUMB_FUNC u32 FUN_0201AB28(struct Window *window, u32 heap_id, const char *path) { - void *ptr = FUN_020161A4(heap_id, path); + void *ptr = AllocAndReadFile(heap_id, path); window->unk00 = ptr; u32 st0; NNS_G2dGetUnpackedBGCharacterData(ptr, &st0); @@ -7755,7 +7755,7 @@ THUMB_FUNC u32 FUN_0201AB28(struct Window *window, u32 heap_id, const char *path THUMB_FUNC u32 FUN_0201AB44(struct Window *window, u32 heap_id, const char *path) { - void *ptr = FUN_020161A4(heap_id, path); + void *ptr = AllocAndReadFile(heap_id, path); window->unk00 = ptr; u32 st0; NNS_G2dGetUnpackedPaletteData(ptr, &st0); diff --git a/arm9/src/unk_0202F150.c b/arm9/src/unk_0202F150.c index 09b5b56f..ef9a6193 100644 --- a/arm9/src/unk_0202F150.c +++ b/arm9/src/unk_0202F150.c @@ -535,7 +535,7 @@ THUMB_FUNC BOOL FUN_0202FB80() { UNK_021C59F4.unk00 = 0; FUN_0202F984(); - UNK_021C59F4.unk04->unk628 |= gMain.unk44 & 0x7FFF; + UNK_021C59F4.unk04->unk628 |= gMain.heldKeys & 0x7FFF; FUN_02030674(); FUN_0202FCCC(); diff --git a/arm9/src/unk_02031734.c b/arm9/src/unk_02031734.c index 57764b82..7d3b4c03 100644 --- a/arm9/src/unk_02031734.c +++ b/arm9/src/unk_02031734.c @@ -97,14 +97,14 @@ THUMB_FUNC void FUN_020317C0() if (UNK_021C5A00->unk3F >= 0x13) { - FUN_020168D0(0x31); + DestroyHeap(0x31); } FUN_02033ED0(); FUN_0202E4F0(); FreeToHeap(UNK_021C5A00); - FUN_020168D0(0xf); + DestroyHeap(0xf); UNK_021C5A00 = NULL; } @@ -123,7 +123,7 @@ THUMB_FUNC void FUN_02031824(struct SaveBlock2 *sav2) { if (UNK_021C5A00 == NULL) { - FUN_02016828(3, 0xf, 0xe000); + CreateHeapAtEnd(3, 0xf, 0xe000); FUN_02031734(sav2, 0xa); UNK_021C5A00->unk40 = 0; @@ -201,7 +201,7 @@ THUMB_FUNC void FUN_02031948(struct SaveBlock2 *sav2, u8 param1, u8 param2, u32 { if (FUN_02030F40() == 0) { - FUN_02016828(3, 0xf, 0x7080); + CreateHeapAtEnd(3, 0xf, 0x7080); FUN_02031734(sav2, param1); UNK_021C5A00->unk40 = param2; UNK_021C5A00->unk30 = param3; @@ -213,7 +213,7 @@ THUMB_FUNC void FUN_02031990(struct SaveBlock2 *sav2, u8 param1, u8 param2, u32 { if (FUN_02030F40() == 0) { - FUN_02016828(3, 0xf, 0x7080); + CreateHeapAtEnd(3, 0xf, 0x7080); FUN_02031734(sav2, param1); UNK_021C5A00->unk40 = param2; UNK_021C5A00->unk30 = param3; @@ -273,7 +273,7 @@ THUMB_FUNC void FUN_02031A7C(struct SaveBlock2 *sav2) { if (UNK_021C5A00 == NULL) { - if (FUN_02016828(3, 0xf, 0x7080) == 0) + if (CreateHeapAtEnd(3, 0xf, 0x7080) == 0) { FUN_020335E0(); } @@ -406,7 +406,7 @@ THUMB_FUNC void FUN_02031C74(struct SaveBlock2 *sav2, u8 param1) { if (FUN_02030F40() == 0) { - FUN_02016828(3, 0xf, 0x7080); + CreateHeapAtEnd(3, 0xf, 0x7080); FUN_02031734(sav2, param1); FUN_02031D20(FUN_02032E00, 0); } @@ -416,7 +416,7 @@ THUMB_FUNC void FUN_02031CA8(struct SaveBlock2 *sav2, u8 param1) { if (FUN_02030F40() == 0) { - FUN_02016828(3, 0xf, 0x7080); + CreateHeapAtEnd(3, 0xf, 0x7080); FUN_02031734(sav2, param1); FUN_02031D20(FUN_02032E48, 0); } @@ -1393,7 +1393,7 @@ THUMB_FUNC void FUN_02032BD0(struct SaveBlock2 *sav2) { if (FUN_02030F40() == 0) { - FUN_02016828(3, 0xf, 0x7000); + CreateHeapAtEnd(3, 0xf, 0x7000); FUN_02031734(sav2, 0xe); UNK_021C5A00->unk40 = 0; FUN_02031D20(FUN_02032B8C, 0); @@ -1479,7 +1479,7 @@ THUMB_FUNC void FUN_02032D44(struct SaveBlock2 *sav2) { if (FUN_02030F40() == 0) { - FUN_02016828(3, 0xf, 0x7000); + CreateHeapAtEnd(3, 0xf, 0x7000); FUN_02031734(sav2, 0x11); UNK_021C5A00->unk40 = 0; FUN_02031D20(FUN_02032CF4, 0); @@ -1807,7 +1807,7 @@ THUMB_FUNC void FUN_020331C4() { if (UNK_021C5A00 != NULL) { - FUN_020166B8(1); + ClearSoftResetDisableMask(1); FUN_02031D20(FUN_02032440, 5); } } @@ -1866,7 +1866,7 @@ THUMB_FUNC void FUN_02033288(struct SaveBlock2 *sav2) { if (UNK_021C5A00 == NULL) { - FUN_02016828(3, 0xf, 0x100); + CreateHeapAtEnd(3, 0xf, 0x100); UNK_021C5A00 = (struct UnkStruct_02031734 *)AllocFromHeap(0xf, sizeof(struct UnkStruct_02031734)); MI_CpuFill8(UNK_021C5A00, 0, sizeof(struct UnkStruct_02031734)); @@ -1875,7 +1875,7 @@ THUMB_FUNC void FUN_02033288(struct SaveBlock2 *sav2) UNK_021C5A00->unk46 = 1; UNK_021C5A00->unk28 = sav2; FUN_020334E8(0, 1); - FUN_020166A8(1); + SetSoftResetDisableMask(1); } } @@ -1883,11 +1883,11 @@ THUMB_FUNC void FUN_020332DC() { if (UNK_021C5A00 != 0) { - FUN_020166B8(1); + ClearSoftResetDisableMask(1); FUN_020334E8(0, 0); FreeToHeap(UNK_021C5A00); UNK_021C5A00 = NULL; - FUN_020168D0(0xf); + DestroyHeap(0xf); } } @@ -1895,7 +1895,7 @@ THUMB_FUNC void FUN_02033310(struct SaveBlock2 *sav2) { if (UNK_021C5A00 == NULL) { - FUN_02016828(3, 0xf, 0x100); + CreateHeapAtEnd(3, 0xf, 0x100); UNK_021C5A00 = (struct UnkStruct_02031734 *)AllocFromHeap(0xf, sizeof(struct UnkStruct_02031734)); MI_CpuFill8(UNK_021C5A00, 0, sizeof(struct UnkStruct_02031734)); @@ -1903,7 +1903,7 @@ THUMB_FUNC void FUN_02033310(struct SaveBlock2 *sav2) UNK_021C5A00->unk46 = 1; UNK_021C5A00->unk28 = sav2; FUN_020334E8(0, 1); - FUN_020166A8(1); + SetSoftResetDisableMask(1); } } @@ -1911,11 +1911,11 @@ THUMB_FUNC void FUN_02033364() { if (UNK_021C5A00 != 0) { - FUN_020166B8(1); + ClearSoftResetDisableMask(1); FUN_020334E8(0, 0); FreeToHeap(UNK_021C5A00); UNK_021C5A00 = NULL; - FUN_020168D0(0xf); + DestroyHeap(0xf); } } @@ -1966,7 +1966,7 @@ THUMB_FUNC void FUN_0203341C() { if (FUN_0202E4C8()) { - FUN_02016828(3, 0x31, 0x31000); + CreateHeapAtEnd(3, 0x31, 0x31000); if (FUN_0202F918(1, 1, 0x200, 1) != 0) { MOD05_021D74E0(UNK_021C5A00->unk28, 0x31); @@ -1985,8 +1985,8 @@ THUMB_FUNC void *FUN_0203346C(struct SaveBlock2 *sav2, u32 param1) return 0; } - FUN_020166A8(1); - FUN_02016828(3, 0xf, 0x7080); + SetSoftResetDisableMask(1); + CreateHeapAtEnd(3, 0xf, 0x7080); FUN_02031734(sav2, 0x17); UNK_021C5A00->unk00 = AllocFromHeap(0xf, param1); MI_CpuFill8(UNK_021C5A00->unk00, 0, param1); @@ -2127,7 +2127,7 @@ THUMB_FUNC void FUN_020335F4() FUN_0200541C(); FUN_0202287C(UNK_021C5A00->unk28); - gMain.unk64 = 1; + gMain.touchpadReadAuto = 1; if (UNK_021C5A00->unk4E == 3) { FUN_020335A4(3); |