diff options
Diffstat (limited to 'arm9')
-rw-r--r-- | arm9/arm9.lsf | 4 | ||||
-rw-r--r-- | arm9/asm/nonmatchings/GenerateFontHalfRowLookupTable.s | 1 | ||||
-rw-r--r-- | arm9/asm/unk_02015E30.s | 72 | ||||
-rw-r--r-- | arm9/asm/unk_02020AFC.s | 165 | ||||
-rw-r--r-- | arm9/asm/unk_0208A998.s | 294 | ||||
-rw-r--r-- | arm9/global.inc | 9 | ||||
-rw-r--r-- | arm9/modules/22/asm/module_22.s | 10 | ||||
-rw-r--r-- | arm9/modules/41/asm/module_41.s | 10 | ||||
-rw-r--r-- | arm9/src/error_handling.c | 2 | ||||
-rw-r--r-- | arm9/src/error_message_reset.c | 146 | ||||
-rw-r--r-- | arm9/src/heap.c | 2 | ||||
-rw-r--r-- | arm9/src/main.c | 4 | ||||
-rw-r--r-- | arm9/src/text.c | 88 | ||||
-rw-r--r-- | arm9/src/timer3.c | 66 | ||||
-rw-r--r-- | arm9/src/unk_02015E30.c | 35 |
15 files changed, 268 insertions, 640 deletions
diff --git a/arm9/arm9.lsf b/arm9/arm9.lsf index ba128605..9bd6cb07 100644 --- a/arm9/arm9.lsf +++ b/arm9/arm9.lsf @@ -69,7 +69,7 @@ Static arm9 Object unk_0201E7D8.o Object unk_0201F06C.o Object unk_020208B8.o - Object unk_02020AFC.o + Object timer3.o Object error_handling.o Object unk_02020C44.o Object unk_0202134C.o @@ -317,7 +317,7 @@ Static arm9 Object unk_0208A258.o Object unk_0208A300.o Object unk_0208A338.o - Object unk_0208A998.o + Object error_message_reset.o ### Third-party libraries ### Object unk_0208AC14.o Object custom_allocator.o diff --git a/arm9/asm/nonmatchings/GenerateFontHalfRowLookupTable.s b/arm9/asm/nonmatchings/GenerateFontHalfRowLookupTable.s index a083bf2e..a590ef02 100644 --- a/arm9/asm/nonmatchings/GenerateFontHalfRowLookupTable.s +++ b/arm9/asm/nonmatchings/GenerateFontHalfRowLookupTable.s @@ -1,4 +1,3 @@ - .section .text glabel GenerateFontHalfRowLookupTable diff --git a/arm9/asm/unk_02015E30.s b/arm9/asm/unk_02015E30.s deleted file mode 100644 index 9ca09399..00000000 --- a/arm9/asm/unk_02015E30.s +++ /dev/null @@ -1,72 +0,0 @@ - .include "asm/macros.inc" - .include "global.inc" - - .section .bss - - .global UNK_021C4898 -UNK_021C4898: ; 0x021C4898 - .space 0x20 - - .text - - thumb_func_start FUN_02015E30 -FUN_02015E30: ; 0x02015E30 - ldr r0, _02015E38 ; =UNK_021C4898 - mov r1, #0x0 - str r1, [r0, #0x0] - bx lr - .balign 4 -_02015E38: .word UNK_021C4898 - - thumb_func_start FUN_02015E3C -FUN_02015E3C: ; 0x02015E3C - push {r3, lr} - ldr r1, _02015E5C ; =UNK_021C4898 - mov r2, #0x1 - str r2, [r1, #0x0] - mov r2, #0x0 - str r2, [r1, #0x10] - str r2, [r1, #0x14] - str r2, [r1, #0x8] - str r2, [r1, #0xc] - str r0, [r1, #0x4] - bl FUN_02020BF4 - ldr r2, _02015E5C ; =UNK_021C4898 - str r0, [r2, #0x18] - str r1, [r2, #0x1c] - pop {r3, pc} - .balign 4 -_02015E5C: .word UNK_021C4898 - - thumb_func_start FUN_02015E60 -FUN_02015E60: ; 0x02015E60 - push {r3-r5, lr} - ldr r0, _02015E9C ; =UNK_021C4898 - ldr r0, [r0, #0x0] - cmp r0, #0x0 - beq _02015E9A - bl FUN_02020BF4 - ldr r2, _02015E9C ; =UNK_021C4898 - ldr r3, [r2, #0x18] - ldr r2, [r2, #0x1c] - sub r0, r0, r3 - sbc r1, r2 - bl FUN_02020C14 - add r5, r1, #0x0 - ldr r1, _02015E9C ; =UNK_021C4898 - add r4, r0, #0x0 - ldr r3, [r1, #0x8] - ldr r2, [r1, #0xc] - sub r0, r3, r4 - sbc r2, r5 - bhs _02015E9A - ldr r0, [r1, #0x4] - sub r1, r4, r3 - bl AddIGTSeconds - ldr r0, _02015E9C ; =UNK_021C4898 - str r4, [r0, #0x8] - str r5, [r0, #0xc] -_02015E9A: - pop {r3-r5, pc} - .balign 4 -_02015E9C: .word UNK_021C4898 diff --git a/arm9/asm/unk_02020AFC.s b/arm9/asm/unk_02020AFC.s deleted file mode 100644 index 3d43d259..00000000 --- a/arm9/asm/unk_02020AFC.s +++ /dev/null @@ -1,165 +0,0 @@ - .include "asm/macros.inc" - .include "global.inc" - - .section .bss - - .global UNK_021C59B0 -UNK_021C59B0: ; 0x021C59B0 - .space 0xc - - .text - - thumb_func_start FUN_02020AFC -FUN_02020AFC: ; 0x02020AFC - push {r3, lr} - ldr r0, _02020B24 ; =UNK_021C59B0 - mov r2, #0x0 - str r2, [r0, #0x4] - str r2, [r0, #0x8] - ldr r1, _02020B28 ; =0x0400010E - str r2, [r0, #0x0] - strh r2, [r1, #0x0] - sub r0, r1, #0x2 - strh r2, [r0, #0x0] - mov r0, #0xc1 - strh r0, [r1, #0x0] - ldr r1, _02020B2C ; =FUN_02020B30 - mov r0, #0x40 - bl OS_SetIrqFunction - mov r0, #0x40 - bl OS_EnableIrqMask - pop {r3, pc} - .balign 4 -_02020B24: .word UNK_021C59B0 -_02020B28: .word 0x0400010E -_02020B2C: .word FUN_02020B30 - - thumb_func_start FUN_02020B30 -FUN_02020B30: ; 0x02020B30 - ldr r0, _02020B68 ; =UNK_021C59B0 - mov r3, #0x0 - ldr r1, [r0, #0x4] - ldr r2, [r0, #0x8] - add r1, r1, #0x1 - adc r2, r3 - str r1, [r0, #0x4] - str r2, [r0, #0x8] - ldr r1, [r0, #0x0] - cmp r1, #0x0 - beq _02020B54 - ldr r2, _02020B6C ; =0x0400010E - strh r3, [r2, #0x0] - sub r1, r2, #0x2 - strh r3, [r1, #0x0] - mov r1, #0xc1 - strh r1, [r2, #0x0] - str r3, [r0, #0x0] -_02020B54: - ldr r3, _02020B70 ; =0x027E0000 - ldr r1, _02020B74 ; =0x00003FF8 - mov r0, #0x40 - ldr r2, [r3, r1] - orr r2, r0 - str r2, [r3, r1] - ldr r3, _02020B78 ; =OS_SetIrqFunction - ldr r1, _02020B7C ; =FUN_02020B30 - bx r3 - nop -_02020B68: .word UNK_021C59B0 -_02020B6C: .word 0x0400010E -_02020B70: .word 0x027E0000 -_02020B74: .word 0x00003FF8 -_02020B78: .word OS_SetIrqFunction -_02020B7C: .word FUN_02020B30 - - thumb_func_start FUN_02020B80 -FUN_02020B80: ; 0x02020B80 - push {r4-r5, lr} - sub sp, #0xc - bl OS_DisableInterrupts - ldr r1, _02020BE4 ; =0x0400010C - add r3, sp, #0x0 - ldrh r1, [r1, #0x0] - ldr r2, _02020BE8 ; =0x0000FFFF - strh r1, [r3, #0x0] - ldr r1, _02020BEC ; =UNK_021C59B0 - ldr r5, [r1, #0x4] - ldr r4, [r1, #0x8] - mov r1, #0x0 - mvn r1, r1 - and r1, r5 - str r1, [sp, #0x4] - and r2, r4 - ldr r1, _02020BF0 ; =0x04000214 - str r2, [sp, #0x8] - ldr r2, [r1, #0x0] - mov r1, #0x40 - tst r2, r1 - beq _02020BC4 - ldrh r2, [r3, #0x0] - lsl r1, r1, #0x9 - tst r1, r2 - bne _02020BC4 - ldr r2, [sp, #0x4] - mov r1, #0x0 - ldr r3, [sp, #0x8] - add r2, r2, #0x1 - adc r3, r1 - str r2, [sp, #0x4] - str r3, [sp, #0x8] -_02020BC4: - bl OS_RestoreInterrupts - ldr r2, [sp, #0x4] - ldr r1, [sp, #0x8] - lsr r0, r2, #0x10 - lsl r1, r1, #0x10 - orr r1, r0 - add r0, sp, #0x0 - lsl r3, r2, #0x10 - ldrh r2, [r0, #0x0] - asr r0, r2, #0x1f - orr r1, r0 - add r0, r3, #0x0 - orr r0, r2 - add sp, #0xc - pop {r4-r5, pc} - .balign 4 -_02020BE4: .word 0x0400010C -_02020BE8: .word 0x0000FFFF -_02020BEC: .word UNK_021C59B0 -_02020BF0: .word 0x04000214 - - thumb_func_start FUN_02020BF4 -FUN_02020BF4: ; 0x02020BF4 - ldr r3, _02020BF8 ; =FUN_02020B80 - bx r3 - .balign 4 -_02020BF8: .word FUN_02020B80 - - thumb_func_start FUN_02020BFC -FUN_02020BFC: ; 0x02020BFC - push {r3, lr} - lsr r2, r0, #0x1a - lsl r1, r1, #0x6 - orr r1, r2 - ldr r2, _02020C10 ; =0x000082EA - lsl r0, r0, #0x6 - mov r3, #0x0 - bl _ll_udiv - pop {r3, pc} - .balign 4 -_02020C10: .word 0x000082EA - - thumb_func_start FUN_02020C14 -FUN_02020C14: ; 0x02020C14 - push {r3, lr} - lsr r2, r0, #0x1a - lsl r1, r1, #0x6 - orr r1, r2 - ldr r2, _02020C28 ; =0x01FF6210 - lsl r0, r0, #0x6 - mov r3, #0x0 - bl _ll_udiv - pop {r3, pc} - .balign 4 -_02020C28: .word 0x01FF6210 diff --git a/arm9/asm/unk_0208A998.s b/arm9/asm/unk_0208A998.s deleted file mode 100644 index 14a02753..00000000 --- a/arm9/asm/unk_0208A998.s +++ /dev/null @@ -1,294 +0,0 @@ - .include "asm/macros.inc" - .include "global.inc" - - .extern gMain - - .section .rodata - - .global UNK_020FF49C -UNK_020FF49C: ; 0x020FF49C - .byte 0x00, 0x03, 0x03, 0x1A, 0x12, 0x01, 0x23, 0x00 - - .global UNK_020FF4A4 -UNK_020FF4A4: ; 0x020FF4A4 - .byte 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 - - .global UNK_020FF4AC -UNK_020FF4AC: ; 0x020FF4AC - .byte 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - - .global UNK_020FF4BC -UNK_020FF4BC: ; 0x020FF4BC - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x01, 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - - .global UNK_020FF4D8 -UNK_020FF4D8: ; 0x020FF4D8 - .byte 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - - .section .bss - - .global sErrorMessagePrinterLock -sErrorMessagePrinterLock: ; 0x021C8C58 - .space 0x4 - - .text - - thumb_func_start FUN_0208A998 -FUN_0208A998: ; 0x0208A998 - ldr r3, _0208A9AC ; =0x027E0000 - ldr r1, _0208A9B0 ; =0x00003FF8 - mov r0, #0x1 - ldr r2, [r3, r1] - orr r0, r2 - str r0, [r3, r1] - ldr r3, _0208A9B4 ; =MI_WaitDma - mov r0, #0x3 - bx r3 - nop -_0208A9AC: .word 0x027E0000 -_0208A9B0: .word 0x00003FF8 -_0208A9B4: .word MI_WaitDma - - thumb_func_start PrintErrorMessageAndReset -PrintErrorMessageAndReset: ; 0x0208A9B8 - push {r4-r7, lr} - sub sp, #0x24 - ldr r0, _0208ABC8 ; =sErrorMessagePrinterLock - ldr r1, [r0, #0x0] - cmp r1, #0x1 - bne _0208A9C6 - b _0208ABC4 -_0208A9C6: - mov r1, #0x1 - str r1, [r0, #0x0] - mov r0, #0x0 - bl OS_GetInitArenaHi - add r1, r0, #0x0 - mov r0, #0x0 - bl OS_SetArenaHi - mov r0, #0x0 - bl OS_GetInitArenaLo - add r1, r0, #0x0 - mov r0, #0x0 - bl OS_SetArenaLo - mov r1, #0x1 - ldr r0, _0208ABCC ; =UNK_020FF4A4 - add r2, r1, #0x0 - mov r3, #0x0 - bl FUN_020166C8 - mov r0, #0x0 - add r1, r0, #0x0 - bl FUN_0200E3A0 - mov r0, #0x1 - mov r1, #0x0 - bl FUN_0200E3A0 - mov r0, #0x1 - bl OS_DisableIrqMask - ldr r1, _0208ABD0 ; =FUN_0208A998 - mov r0, #0x1 - bl OS_SetIrqFunction - mov r0, #0x1 - bl OS_EnableIrqMask - mov r0, #0x0 - add r1, r0, #0x0 - bl Main_SetVBlankIntrCB - mov r0, #0x0 - add r1, r0, #0x0 - bl FUN_02015F34 - bl FUN_0201E6D8 - bl FUN_0201E740 - mov r2, #0x1 - lsl r2, r2, #0x1a - ldr r1, [r2, #0x0] - ldr r0, _0208ABD4 ; =0xFFFFE0FF - and r1, r0 - str r1, [r2, #0x0] - ldr r2, _0208ABD8 ; =0x04001000 - ldr r1, [r2, #0x0] - and r0, r1 - str r0, [r2, #0x0] - mov r0, #0x4 - mov r1, #0x8 - bl FUN_0201669C - ldr r0, _0208ABDC ; =gMain + 0x60 - mov r1, #0x0 - strb r1, [r0, #0x5] - bl FUN_0201E7A0 - ldr r3, _0208ABE0 ; =0x04000050 - mov r0, #0x0 - strh r0, [r3, #0x0] - ldr r2, _0208ABE4 ; =0x04001050 - sub r3, #0x50 - strh r0, [r2, #0x0] - ldr r1, [r3, #0x0] - ldr r0, _0208ABE8 ; =0xFFFF1FFF - sub r2, #0x50 - and r1, r0 - str r1, [r3, #0x0] - ldr r1, [r2, #0x0] - and r0, r1 - str r0, [r2, #0x0] - ldr r0, _0208ABEC ; =UNK_020FF4D8 - bl FUN_0201E66C - mov r0, #0x0 - bl FUN_02016B94 - str r0, [sp, #0x10] - ldr r0, _0208ABF0 ; =UNK_020FF4AC - bl FUN_02016BBC - mov r1, #0x0 - ldr r0, [sp, #0x10] - ldr r2, _0208ABF4 ; =UNK_020FF4BC - add r3, r1, #0x0 - bl FUN_02016C18 - ldr r0, [sp, #0x10] - mov r1, #0x0 - bl FUN_02018744 - mov r1, #0x0 - str r1, [sp, #0x0] - ldr r0, [sp, #0x10] - ldr r2, _0208ABF8 ; =0x000001F7 - mov r3, #0x2 - str r1, [sp, #0x4] - bl FUN_0200CB00 - mov r0, #0x0 - mov r1, #0x20 - add r2, r0, #0x0 - bl FUN_02002ED0 - mov r0, #0x0 - mov r1, #0x20 - add r2, r0, #0x0 - add r3, r0, #0x0 - bl FUN_02017F18 - ldr r1, _0208ABFC ; =0x00006C21 - mov r0, #0x0 - bl FUN_02017FE4 - ldr r1, _0208ABFC ; =0x00006C21 - mov r0, #0x4 - bl FUN_02017FE4 - mov r0, #0x1 - mov r1, #0x1a - mov r2, #0xc8 - mov r3, #0x0 - bl NewMsgDataFromNarc - str r0, [sp, #0xc] - mov r0, #0x6 - lsl r0, r0, #0x6 - mov r1, #0x0 - bl String_ctor - add r4, r0, #0x0 - bl FUN_0201BD5C - ldr r0, [sp, #0x10] - ldr r2, _0208AC00 ; =UNK_020FF49C - add r1, sp, #0x14 - bl FUN_02019150 - mov r0, #0xd0 - str r0, [sp, #0x0] - mov r0, #0x90 - mov r2, #0x0 - str r0, [sp, #0x4] - add r0, sp, #0x14 - mov r1, #0xf - add r3, r2, #0x0 - bl FUN_020196F4 - ldr r2, _0208ABF8 ; =0x000001F7 - add r0, sp, #0x14 - mov r1, #0x0 - mov r3, #0x2 - bl FUN_0200CCA4 - ldr r0, [sp, #0xc] - mov r1, #0x3 - add r2, r4, #0x0 - bl ReadMsgDataIntoString - mov r1, #0x0 - str r1, [sp, #0x0] - str r1, [sp, #0x4] - add r0, sp, #0x14 - add r2, r4, #0x0 - add r3, r1, #0x0 - str r1, [sp, #0x8] - bl AddTextPrinterParameterized - add r0, r4, #0x0 - bl String_dtor - bl FUN_0201E788 - mov r0, #0x0 - bl FUN_0200E394 - mov r0, #0x1 - bl FUN_0200E394 - mov r0, #0x0 - mov r1, #0x3f - mov r2, #0x3 - bl FUN_0200A274 - bl FUN_02032DAC - mov r4, #0x1 -_0208AB58: - bl HandleDSLidAction - bl FUN_0202FB80 - bl FUN_02033678 - cmp r0, #0x0 - bne _0208AB72 - add r0, r4, #0x0 - add r1, r4, #0x0 - bl OS_WaitIrq - b _0208AB58 -_0208AB72: - ldr r5, _0208AC04 ; =0x04000130 - ldr r4, _0208AC08 ; =0x027FFFA8 - ldr r7, _0208AC0C ; =0x00002FFF - mov r6, #0x1 -_0208AB7A: - bl HandleDSLidAction - ldrh r1, [r5, #0x0] - ldrh r0, [r4, #0x0] - orr r1, r0 - ldr r0, _0208AC0C ; =0x00002FFF - eor r0, r1 - and r0, r7 - lsl r0, r0, #0x10 - lsr r0, r0, #0x10 - tst r0, r6 - bne _0208AB9C - mov r0, #0x1 - add r1, r0, #0x0 - bl OS_WaitIrq - b _0208AB7A -_0208AB9C: - ldr r1, _0208AC10 ; =0x00007FFF - mov r0, #0x0 - bl FUN_0200E3A0 - ldr r1, _0208AC10 ; =0x00007FFF - mov r0, #0x1 - bl FUN_0200E3A0 - add r0, sp, #0x14 - bl FUN_02019178 - ldr r0, [sp, #0xc] - bl DestroyMsgData - ldr r0, [sp, #0x10] - bl FreeToHeap - mov r0, #0x0 - bl OS_ResetSystem -_0208ABC4: - add sp, #0x24 - pop {r4-r7, pc} - .balign 4 -_0208ABC8: .word sErrorMessagePrinterLock -_0208ABCC: .word UNK_020FF4A4 -_0208ABD0: .word FUN_0208A998 -_0208ABD4: .word 0xFFFFE0FF -_0208ABD8: .word 0x04001000 -_0208ABDC: .word gMain + 0x60 -_0208ABE0: .word 0x04000050 -_0208ABE4: .word 0x04001050 -_0208ABE8: .word 0xFFFF1FFF -_0208ABEC: .word UNK_020FF4D8 -_0208ABF0: .word UNK_020FF4AC -_0208ABF4: .word UNK_020FF4BC -_0208ABF8: .word 0x000001F7 -_0208ABFC: .word 0x00006C21 -_0208AC00: .word UNK_020FF49C -_0208AC04: .word 0x04000130 -_0208AC08: .word 0x027FFFA8 -_0208AC0C: .word 0x00002FFF -_0208AC10: .word 0x00007FFF diff --git a/arm9/global.inc b/arm9/global.inc index ab44d83e..c8834374 100644 --- a/arm9/global.inc +++ b/arm9/global.inc @@ -1353,10 +1353,9 @@ .extern FUN_02020AB0 .extern FUN_02020ACC .extern FUN_02020AE8 -.extern FUN_02020AFC -.extern FUN_02020BF4 -.extern FUN_02020BFC -.extern FUN_02020C14 +.extern GetTimer3Count +.extern Timer3CountToMilliSeconds +.extern Timer3CountToSeconds .extern FUN_02020C44 .extern FUN_02020C90 .extern FUN_02020CB0 @@ -5479,7 +5478,6 @@ .extern FUN_0208A330 .extern FUN_0208A334 .extern FUN_0208A338 -.extern PrintErrorMessageAndReset .extern FUN_0208AC14 .extern FUN_0208AC58 .extern FUN_0208ACEC @@ -8519,3 +8517,4 @@ .extern CARDi_InitCommon .extern MonNotFaintedOrEgg .extern CountAlivePokemon + diff --git a/arm9/modules/22/asm/module_22.s b/arm9/modules/22/asm/module_22.s index ef079cdb..e58e406b 100644 --- a/arm9/modules/22/asm/module_22.s +++ b/arm9/modules/22/asm/module_22.s @@ -657,7 +657,7 @@ MOD22_02254D00: ; 0x02254D00 eor r0, r3 orr r0, r1 beq _02254D32 - bl FUN_02020BF4 + bl GetTimer3Count add r5, r4, #0 add r5, #0xc ldr r7, [r4, #0x14] @@ -672,7 +672,7 @@ MOD22_02254D00: ; 0x02254D00 str r3, [r5, #4] b _02254D3A _02254D32: - bl FUN_02020BF4 + bl GetTimer3Count str r0, [r4, #0xc] str r1, [r4, #0x10] _02254D3A: @@ -687,7 +687,7 @@ _02254D3A: MOD22_02254D44: ; 0x02254D44 push {r4, lr} add r4, r0, #0 - bl FUN_02020BF4 + bl GetTimer3Count str r0, [r4, #0x14] str r1, [r4, #0x18] mov r0, #0 @@ -706,12 +706,12 @@ MOD22_02254D58: ; 0x02254D58 bne _02254D66 b _02254E7C _02254D66: - bl FUN_02020BF4 + bl GetTimer3Count ldr r3, [r5, #0xc] ldr r2, [r5, #0x10] sub r0, r0, r3 sbc r1, r2 - bl FUN_02020BFC + bl Timer3CountToMilliSeconds ldr r2, _02254E80 ; =0x04000280 mov r3, #1 strh r3, [r2] diff --git a/arm9/modules/41/asm/module_41.s b/arm9/modules/41/asm/module_41.s index a60736df..637c100f 100644 --- a/arm9/modules/41/asm/module_41.s +++ b/arm9/modules/41/asm/module_41.s @@ -1046,7 +1046,7 @@ MOD41_0225504C: ; 0x0225504C add r5, r0, #0 add r4, r5, #0 add r4, #0x48 - bl FUN_02020BF4 + bl GetTimer3Count str r0, [r5, #0x68] str r1, [r5, #0x6c] mov r2, #0 @@ -1105,7 +1105,7 @@ MOD41_022550BC: ; 0x022550BC mov r1, #0 add r0, #0x88 str r1, [r0] - bl FUN_02020BF4 + bl GetTimer3Count str r0, [r4, #0x70] str r1, [r4, #0x74] pop {r4, pc} @@ -1115,7 +1115,7 @@ MOD41_022550BC: ; 0x022550BC MOD41_022550D0: ; 0x022550D0 push {r3, r4, r5, r6, r7, lr} add r4, r0, #0 - bl FUN_02020BF4 + bl GetTimer3Count add r5, r4, #0 add r5, #0x68 ldr r7, [r4, #0x70] @@ -1155,12 +1155,12 @@ MOD41_02255108: ; 0x02255108 ldr r0, [r0] cmp r0, #0 beq _0225516A - bl FUN_02020BF4 + bl GetTimer3Count ldr r3, [r4, #0x68] ldr r2, [r4, #0x6c] sub r0, r0, r3 sbc r1, r2 - bl FUN_02020C14 + bl Timer3CountToSeconds add r5, r0, #0 add r0, r4, #0 add r0, #0x80 diff --git a/arm9/src/error_handling.c b/arm9/src/error_handling.c index 9052773f..a01894f6 100644 --- a/arm9/src/error_handling.c +++ b/arm9/src/error_handling.c @@ -1,8 +1,8 @@ #include "global.h" #include "error_handling.h" +#include "error_message_reset.h" extern u32 FUN_02031810(void); -extern void PrintErrorMessageAndReset(void); THUMB_FUNC void ErrorHandling(void) { diff --git a/arm9/src/error_message_reset.c b/arm9/src/error_message_reset.c new file mode 100644 index 00000000..7d1caccb --- /dev/null +++ b/arm9/src/error_message_reset.c @@ -0,0 +1,146 @@ +#include "error_message_reset.h" + +const u32 UNK_020FF49C[2] = { 0x1a030300, 0x00230112 }; + +const u32 UNK_020FF4A4[2] = { 0x00020000, 0x00000000 }; + +const struct GraphicsModes UNK_020FF4AC = { mode1 : 1 }; + +const u32 UNK_020FF4BC[7] = { 0x00, 0x00, 0x0800, 0x00, 0x06000001, 0x0100, 0x00 }; + +const struct GraphicsBanks UNK_020FF4D8 = { bg : 3 }; + +u32 sErrorMessagePrinterLock; + +extern void FUN_0200E3A0(PMLCDTarget, int); +extern void FUN_0201E6D8(); +extern void FUN_0201E7A0(); +extern void FUN_0201E66C(const struct GraphicsBanks *banks); +extern u32 *FUN_02016B94(u32 param0); +extern void FUN_02016BBC(const struct GraphicsModes *modes); +extern void FUN_02016C18(u32 *param0, u32 param1, void *param2, u32 param3); +extern void FUN_02018744(u32 *param0, u32 param1); +extern void FUN_0200CB00(u32 *param0, u32 param1, u32 param2, u32 param3, u8 param4, u32 param5); +extern void FUN_02002ED0(u32 param0, u32 param1, u32 param2); +extern void FUN_02017F18(u32 param0, u32 param1, u32 param2, u32 param3); +extern void FUN_02017FE4(u32 param0, u32 param1); +extern void FUN_02019150(u32 *param0, u32 *param1, const u32 *param2); +extern void FUN_020196F4(u32 *, u8, u16, u16, u16, u16); +extern void FUN_0200CCA4(u32 *param0, u32 param1, u32 param2, u32 param3); +extern void FUN_0201E788(); +extern void FUN_0200E394(u32 param0); +extern void FUN_0200A274(u32 param0, u32 param1, u32 param2); +extern BOOL FUN_02032DAC(void); +extern BOOL FUN_0202FB80(void); +extern BOOL FUN_02033678(void); +extern void FUN_02019178(u32 *param0); +extern void FUN_0201E740(); + +THUMB_FUNC void VBlankHandler() +{ + *(vu32 *)HW_INTR_CHECK_BUF |= 1; + + MI_WaitDma(3); +} + +THUMB_FUNC void PrintErrorMessageAndReset() +{ + + u32 *ptr; + u32 buf[4]; + + if (sErrorMessagePrinterLock != 1) + { + sErrorMessagePrinterLock = 1; + 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); + FUN_0200E3A0(PM_LCD_TOP, 0); + FUN_0200E3A0(PM_LCD_BOTTOM, 0); + + OS_DisableIrqMask(1); + OS_SetIrqFunction(1, &VBlankHandler); + OS_EnableIrqMask(1); + + Main_SetVBlankIntrCB(NULL, NULL); + + FUN_02015F34(NULL, NULL); + FUN_0201E6D8(); + FUN_0201E740(); + + reg_GX_DISPCNT &= 0xFFFFE0FF; + reg_GXS_DB_DISPCNT &= 0xFFFFE0FF; + + FUN_0201669C(4, 8); + + gMain.unk65 = 0; + FUN_0201E7A0(); + + reg_G2_BLDCNT = 0; + reg_G2S_DB_BLDCNT = 0; + reg_GX_DISPCNT &= 0xFFFF1FFF; + reg_GXS_DB_DISPCNT &= 0xFFFF1FFF; + + FUN_0201E66C(&UNK_020FF4D8); + ptr = FUN_02016B94(0); + FUN_02016BBC(&UNK_020FF4AC); + + FUN_02016C18(ptr, 0, UNK_020FF4BC, 0); + FUN_02018744(ptr, 0); + + FUN_0200CB00(ptr, 0, 503, 2, 0, 0); + + FUN_02002ED0(0, 0x20, 0); + FUN_02017F18(0, 0x20, 0, 0); + FUN_02017FE4(0, 0x6C21); + FUN_02017FE4(4, 0x6C21); + + struct MsgData *msg_data = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, 0xc8, 0); + struct String *str = String_ctor(6 << 6, 0); + + FUN_0201BD5C(); + FUN_02019150(ptr, buf, UNK_020FF49C); + FUN_020196F4(buf, 15, 0, 0, 0xd0, 0x90); + FUN_0200CCA4(buf, 0, 0x1f7, 2); + + ReadMsgDataIntoString(msg_data, 3, str); + + AddTextPrinterParameterized((u32)buf, 0, (const u16 *)str, 0, 0, 0, NULL); // wtf + + String_dtor(str); + FUN_0201E788(); + FUN_0200E394(0); + FUN_0200E394(1); + FUN_0200A274(0, 0x3f, 3); + FUN_02032DAC(); + + lid: + HandleDSLidAction(); + FUN_0202FB80(); + if (!FUN_02033678()) + { + OS_WaitIrq(1, 1); + goto lid; + } + + + lid2: + HandleDSLidAction(); + if (!((u16)(((reg_PAD_KEYINPUT | *(vu16 *)HW_BUTTON_XY_BUF) ^ 0x2FFF) & 0x2FFF) & 1)) + { + OS_WaitIrq(1, 1); + goto lid2; + } + + FUN_0200E3A0(PM_LCD_TOP, 0x7FFF); + FUN_0200E3A0(PM_LCD_BOTTOM, 0x7FFF); + + FUN_02019178(buf); + + DestroyMsgData(msg_data); + FreeToHeap(ptr); + + OS_ResetSystem(0); + } +} diff --git a/arm9/src/heap.c b/arm9/src/heap.c index c27a40c0..84abc834 100644 --- a/arm9/src/heap.c +++ b/arm9/src/heap.c @@ -1,11 +1,11 @@ #include "heap.h" +#include "error_message_reset.h" extern void *tempName_NNS_FndCreateExpHeapEx(void *param0, u32 param1, u32 param2); extern void *tempName_NNS_FndAllocFromExpHeapEx(void *param0, u32 param1, s32 param2); extern void thunk_FUN_020adc8c(); extern void FUN_020ADDF0(void *ptr1, void *ptr2); extern u32 FUN_02031810(void); -extern void PrintErrorMessageAndReset(void); extern u32 FUN_020ADDC8(void *param0); extern void FUN_020AE82C(u32 param0, void *param1, u32 param2); extern u32 FUN_020ADDC0(void *param0); diff --git a/arm9/src/main.c b/arm9/src/main.c index 86f0f6af..c50fbaff 100644 --- a/arm9/src/main.c +++ b/arm9/src/main.c @@ -11,6 +11,7 @@ #include "poke_overlay.h" #include "player_data.h" #include "sound.h" +#include "timer3.h" FS_EXTERN_OVERLAY(MODULE_52); FS_EXTERN_OVERLAY(MODULE_63); @@ -34,7 +35,6 @@ extern void FUN_02002C14(void); extern void FUN_02002C50(int, int); extern struct SaveBlock2 * SaveBlock2_new(void); extern void * FUN_02029EF8(struct SaveBlock2 *); -extern void FUN_02020AFC(void); extern int FUN_020337E8(int); extern void FUN_02034188(int, int); extern int FUN_020227FC(struct SaveBlock2 *); @@ -75,7 +75,7 @@ THUMB_FUNC void NitroMain(void) gBacklightTop.unk18 = -1; gBacklightTop.unk20 = SaveBlock2_new(); InitSoundData(FUN_02029EF8(gBacklightTop.unk20), Sav2_PlayerData_GetOptionsAddr(gBacklightTop.unk20)); - FUN_02020AFC(); + Init_Timer3(); if (FUN_020337E8(3) == 3) FUN_02034188(3, 0); if (FUN_020227FC(gBacklightTop.unk20) == 0) diff --git a/arm9/src/text.c b/arm9/src/text.c index 6207d913..aadb84c0 100644 --- a/arm9/src/text.c +++ b/arm9/src/text.c @@ -416,93 +416,7 @@ THUMB_FUNC void GenerateFontHalfRowLookupTable(u8 fgColor, u8 bgColor, u8 shadow *(current++) = (shadow12) | temp; } #else -THUMB_FUNC void GenerateFontHalfRowLookupTable(u8 fgColor, u8 bgColor, u8 shadowColor) //TODO use asm preprocessor -{ - asm { - // push {r3-r7, lr} - sub sp, #0x30 - ldr r3, =UNK_021C570C - mov r5, #0x0 - str r5, [sp, #0x20] - str r0, [sp, #0x24] - str r2, [sp, #0x28] - str r1, [sp, #0x2c] - strh r1, [r3, #0x6] - strh r0, [r3, #0x2] - add r0, sp, #0x20 - strh r2, [r3, #0x4] - str r5, [sp, #0x14] - str r0, [sp, #0x8] - mov r12, r0 - mov lr, r0 - str r0, [sp, #0x18] - _0201C07E: - mov r0, #0x0 - str r0, [sp, #0x10] - ldr r0, [sp, #0x18] - str r0, [sp, #0x4] - ldr r0, [sp, #0x8] - ldr r0, [r0, #0x0] - str r0, [sp, #0x1c] - _0201C08C: - mov r0, #0x0 - str r0, [sp, #0xc] - mov r0, lr - str r0, [sp, #0x0] - ldr r0, [sp, #0x4] - ldr r0, [r0, #0x0] - lsl r7, r0, #0x4 - _0201C09A: - ldr r0, [sp, #0x0] - mov r3, #0x0 - ldr r0, [r0, #0x0] - mov r4, r12 - lsl r6, r0, #0x8 - _0201C0A4: - ldr r0, [r4, #0x0] - add r1, r7, #0x0 - lsl r0, r0, #0xc - orr r0, r6 - orr r1, r0 - ldr r0, [sp, #0x1c] - add r3, r3, #0x1 - add r2, r0, #0x0 - orr r2, r1 - lsl r1, r5, #0x1 - ldr r0, =UNK_021C5734 - add r5, r5, #0x1 - add r4, r4, #0x4 - strh r2, [r0, r1] - cmp r3, #0x4 - blt _0201C0A4 - ldr r0, [sp, #0x0] - add r0, r0, #0x4 - str r0, [sp, #0x0] - ldr r0, [sp, #0xc] - add r0, r0, #0x1 - str r0, [sp, #0xc] - cmp r0, #0x4 - blt _0201C09A - ldr r0, [sp, #0x4] - add r0, r0, #0x4 - str r0, [sp, #0x4] - ldr r0, [sp, #0x10] - add r0, r0, #0x1 - str r0, [sp, #0x10] - cmp r0, #0x4 - blt _0201C08C - ldr r0, [sp, #0x8] - add r0, r0, #0x4 - str r0, [sp, #0x8] - ldr r0, [sp, #0x14] - add r0, r0, #0x1 - str r0, [sp, #0x14] - cmp r0, #0x4 - blt _0201C07E - add sp, #0x30 - // pop {r3-r7, pc} - } -} +GLOBAL_ASM("asm/nonmatchings/GenerateFontHalfRowLookupTable.s") #endif THUMB_FUNC void DecompressGlyphTile(const u16 *src, u16 *dst) diff --git a/arm9/src/timer3.c b/arm9/src/timer3.c new file mode 100644 index 00000000..1799fd24 --- /dev/null +++ b/arm9/src/timer3.c @@ -0,0 +1,66 @@ +#include "timer3.h" + +struct Timer3Data timer3_data; + + +THUMB_FUNC void Init_Timer3() +{ + timer3_data.Timer3Counter = 0; + timer3_data.NeedReset = FALSE; + + reg_OS_TM3CNT_H = 0; + reg_OS_TM3CNT_L = 0; + reg_OS_TM3CNT_H = 0xc1; // start timer3 with f/64 and irq enable + + OS_SetIrqFunction(0x40, &CountUpTimer3); + OS_EnableIrqMask(0x40); // irq on timer3 overflow +} + + +THUMB_FUNC void CountUpTimer3() +{ + timer3_data.Timer3Counter++; + + if (timer3_data.NeedReset) + { + reg_OS_TM3CNT_H = 0; + reg_OS_TM3CNT_L = 0; + reg_OS_TM3CNT_H = 0xc1; + timer3_data.NeedReset = FALSE; + } + + *(vu32 *)HW_INTR_CHECK_BUF |= 0x40; + + OS_SetIrqFunction(0x40, &CountUpTimer3); +} + +THUMB_FUNC u64 internal_GetTimer3Count() +{ + OSIntrMode intr_mode = OS_DisableInterrupts(); + + vu16 timer3 = reg_OS_TM3CNT_L; + vu64 timer3_counter = timer3_data.Timer3Counter & 0x0000ffffffffffff; + + if (reg_OS_IF & 0x40 && !(timer3 & 0x8000)) + { + timer3_counter++; + } + + OS_RestoreInterrupts(intr_mode); + return (timer3_counter << 16) | timer3; +} + +THUMB_FUNC u64 GetTimer3Count() +{ + return internal_GetTimer3Count(); +} + +THUMB_FUNC u64 Timer3CountToMilliSeconds(u64 count) +{ + return (count *64) / 33514; +} + +THUMB_FUNC u64 Timer3CountToSeconds(u64 count) +{ + return (count *64) / HW_SYSTEM_CLOCK; +} diff --git a/arm9/src/unk_02015E30.c b/arm9/src/unk_02015E30.c new file mode 100644 index 00000000..8be466fb --- /dev/null +++ b/arm9/src/unk_02015E30.c @@ -0,0 +1,35 @@ + +#include "unk_02015E30.h" + +struct UnkStruct_02015E30 UNK_021C4898; + +THUMB_FUNC void FUN_02015E30() +{ + UNK_021C4898.unk00 = 0; +} + +THUMB_FUNC void FUN_02015E3C(struct IGT *igt) +{ + struct UnkStruct_02015E30 *unk1 = &UNK_021C4898; + UNK_021C4898.unk00 = 1; + UNK_021C4898.unk10 = 0; + UNK_021C4898.unk14 = 0; + UNK_021C4898.unk08 = 0; + UNK_021C4898.unk04 = igt; + + UNK_021C4898.unk18 = GetTimer3Count(); +} + +THUMB_FUNC void FUN_02015E60() +{ + if (UNK_021C4898.unk00 != 0) + { + u64 res = Timer3CountToSeconds(GetTimer3Count() - UNK_021C4898.unk18); + + if (UNK_021C4898.unk08 < res) + { + AddIGTSeconds(UNK_021C4898.unk04, (u32)(res - UNK_021C4898.unk08)); + UNK_021C4898.unk08 = res; + } + } +} |