summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPikalaxALT <pikalaxalt@gmail.com>2020-08-31 14:25:20 -0400
committerPikalaxALT <pikalaxalt@gmail.com>2020-08-31 14:25:20 -0400
commit5787ba96ba2bcb0860422c3e66c179e63368acac (patch)
tree38ff48e4d286804b19f920af382351d4d11a13d0
parent00cbfe2e138c842d9c0bce4e1848d3eaa88a39b8 (diff)
parentbf25a361cd0d013beb86a936b516957b66cfa011 (diff)
Merge branch 'master' of github.com:pret/pokediamond into pikalax_work
-rw-r--r--arm9/asm/MI_init.s17
-rw-r--r--arm9/asm/MI_uncompress.s50
-rw-r--r--arm9/asm/MI_wram.s12
-rw-r--r--arm9/asm/error_handling.s17
-rw-r--r--arm9/lib/include/MI_init.h6
-rw-r--r--arm9/lib/include/MI_uncompress.h7
-rw-r--r--arm9/lib/include/MI_wram.h14
-rw-r--r--arm9/lib/src/MI_init.c10
-rw-r--r--arm9/lib/src/MI_uncompress.c59
-rw-r--r--arm9/lib/src/MI_wram.c8
-rw-r--r--arm9/lib/src/OS_init.c2
-rw-r--r--arm9/lib/src/OS_reset.c2
-rw-r--r--arm9/src/error_handling.c16
-rw-r--r--include/error_handling.h6
-rw-r--r--include/global.h3
15 files changed, 126 insertions, 103 deletions
diff --git a/arm9/asm/MI_init.s b/arm9/asm/MI_init.s
deleted file mode 100644
index 282dde3b..00000000
--- a/arm9/asm/MI_init.s
+++ /dev/null
@@ -1,17 +0,0 @@
- .include "asm/macros.inc"
- .include "global.inc"
-
- .text
-
- arm_func_start MI_Init
-MI_Init: ; 0x020CE648
- stmdb sp!, {lr}
- sub sp, sp, #0x4
- mov r0, #0x3
- bl MI_SetWramBank
- mov r0, #0x0
- bl MI_StopDma
- add sp, sp, #0x4
- ldmfd sp!, {lr}
- bx lr
-
diff --git a/arm9/asm/MI_uncompress.s b/arm9/asm/MI_uncompress.s
deleted file mode 100644
index 5f736e14..00000000
--- a/arm9/asm/MI_uncompress.s
+++ /dev/null
@@ -1,50 +0,0 @@
- .include "asm/macros.inc"
- .include "global.inc"
-
- .text
-
- arm_func_start MI_UncompressLZ8
-MI_UncompressLZ8: ; 0x020CE528
- stmdb sp!, {r4-r6,lr}
- ldr r5, [r0], #0x4
- mov r2, r5, lsr #0x8
-_020CE534:
- cmp r2, #0x0
- ble _020CE5B4
- ldrb lr, [r0], #0x1
- mov r4, #0x8
-_020CE544:
- subs r4, r4, #0x1
- blt _020CE534
- tst lr, #0x80
- bne _020CE568
- ldrb r6, [r0], #0x1
- .word 0xE1416096
- add r1, r1, #0x1
- sub r2, r2, #0x1
- b _020CE5A4
-_020CE568:
- ldrb r5, [r0, #0x0]
- mov r6, #0x3
- add r3, r6, r5, asr #0x4
- ldrb r6, [r0], #0x1
- and r5, r6, #0xf
- mov r12, r5, lsl #0x8
- ldrb r6, [r0], #0x1
- orr r5, r6, r12
- add r12, r5, #0x1
- sub r2, r2, r3
-_020CE590:
- ldrb r5, [r1, -r12]
- .word 0xE1415095
- add r1, r1, #0x1
- subs r3, r3, #0x1
- bgt _020CE590
-_020CE5A4:
- cmp r2, #0x0
- movgt lr, lr, lsl #0x1
- bgt _020CE544
- b _020CE534
-_020CE5B4:
- ldmia sp!, {r4-r6,lr}
- bx lr
diff --git a/arm9/asm/MI_wram.s b/arm9/asm/MI_wram.s
deleted file mode 100644
index 3f245464..00000000
--- a/arm9/asm/MI_wram.s
+++ /dev/null
@@ -1,12 +0,0 @@
- .include "asm/macros.inc"
- .include "global.inc"
-
- .text
-
- arm_func_start MI_SetWramBank
-MI_SetWramBank:
- ldr r1, _020CD870 ; =0x04000247
- strb r0, [r1, #0x0]
- bx lr
- .balign 4
-_020CD870: .word 0x04000247
diff --git a/arm9/asm/error_handling.s b/arm9/asm/error_handling.s
deleted file mode 100644
index d6330897..00000000
--- a/arm9/asm/error_handling.s
+++ /dev/null
@@ -1,17 +0,0 @@
- .include "asm/macros.inc"
- .include "global.inc"
-
- .text
-
- thumb_func_start ErrorHandling
-ErrorHandling: ; 0x02020C2C
- push {r3, lr}
- bl FUN_02031810
- cmp r0, #0x0
- beq _02020C42
- bl OS_GetProcMode
- cmp r0, #0x12
- beq _02020C42
- bl PrintErrorMessageAndReset
-_02020C42:
- pop {r3, pc}
diff --git a/arm9/lib/include/MI_init.h b/arm9/lib/include/MI_init.h
new file mode 100644
index 00000000..a338ab6b
--- /dev/null
+++ b/arm9/lib/include/MI_init.h
@@ -0,0 +1,6 @@
+#ifndef POKEDIAMOND_MI_INIT_H
+#define POKEDIAMOND_MI_INIT_H
+
+void MI_Init(void);
+
+#endif //POKEDIAMOND_MI_INIT_H
diff --git a/arm9/lib/include/MI_uncompress.h b/arm9/lib/include/MI_uncompress.h
index 55f28e27..defafa8c 100644
--- a/arm9/lib/include/MI_uncompress.h
+++ b/arm9/lib/include/MI_uncompress.h
@@ -1,6 +1,7 @@
-#ifndef NITRO_MI_UNCOMPRESS_H_
-#define NITRO_MI_UNCOMPRESS_H_
+#ifndef POKEDIAMOND_MI_UNCOMPRESS_H
+#define POKEDIAMOND_MI_UNCOMPRESS_H
void MIi_UncompressBackward(void * bottom);
+void MI_UncompressLZ8(register const void *srcp, register void *destp);
-#endif //NITRO_MI_UNCOMPRESS_H_
+#endif //POKEDIAMOND_MI_UNCOMPRESS_H
diff --git a/arm9/lib/include/MI_wram.h b/arm9/lib/include/MI_wram.h
new file mode 100644
index 00000000..fa445a8a
--- /dev/null
+++ b/arm9/lib/include/MI_wram.h
@@ -0,0 +1,14 @@
+#ifndef POKEDIAMOND_MI_WRAM_H
+#define POKEDIAMOND_MI_WRAM_H
+
+typedef enum
+{
+ MI_WRAM_ARM9_ALL = 0,
+ MI_WRAM_1616_1 = 1,
+ MI_WRAM_1616_2 = 2,
+ MI_WRAM_ARM7_ALL = 3
+} MIWram;
+
+void MI_SetWramBank(MIWram cnt);
+
+#endif //POKEDIAMOND_MI_WRAM_H
diff --git a/arm9/lib/src/MI_init.c b/arm9/lib/src/MI_init.c
new file mode 100644
index 00000000..4556e95a
--- /dev/null
+++ b/arm9/lib/src/MI_init.c
@@ -0,0 +1,10 @@
+#include "nitro/types.h"
+#include "function_target.h"
+#include "MI_dma.h"
+#include "MI_wram.h"
+
+ARM_FUNC void MI_Init(void)
+{
+ MI_SetWramBank(MI_WRAM_ARM7_ALL);
+ MI_StopDma(0);
+}
diff --git a/arm9/lib/src/MI_uncompress.c b/arm9/lib/src/MI_uncompress.c
new file mode 100644
index 00000000..c6ad7e4e
--- /dev/null
+++ b/arm9/lib/src/MI_uncompress.c
@@ -0,0 +1,59 @@
+#include "function_target.h"
+#include "MI_uncompress.h"
+
+ARM_FUNC asm void MI_UncompressLZ8(register const void *srcp, register void *destp)
+{
+ stmfd sp!, {r4-r6, lr}
+
+ ldr r5, [r0], #4
+ mov r2, r5, lsr #8
+
+_020CE534:
+ cmp r2, #0
+ ble _020CE5B4
+
+ ldrb lr, [r0], #1
+ mov r4, #8
+
+_020CE544:
+ subs r4, r4, #1
+ blt _020CE534
+
+ tst lr, #0x80
+ bne _020CE568
+
+ ldrb r6, [r0], #1
+ swpb r6, r6, [r1]
+ add r1, r1, #1
+ sub r2, r2, #1
+ b _020CE5A4
+
+_020CE568:
+ ldrb r5, [r0, #0]
+ mov r6, #3
+ add r3, r6, r5, asr #4
+ ldrb r6, [r0], #1
+ and r5, r6, #0xf
+ mov r12, r5, lsl #8
+ ldrb r6, [r0], #1
+ orr r5, r6, r12
+ add r12, r5, #1
+ sub r2, r2, r3
+
+_020CE590:
+ ldrb r5, [r1, -r12]
+ swpb r5, r5, [r1]
+ add r1, r1, #1
+ subs r3, r3, #1
+ bgt _020CE590
+
+_020CE5A4:
+ cmp r2, #0
+ movgt lr, lr, lsl #1
+ bgt _020CE544
+ b _020CE534
+
+_020CE5B4:
+ ldmfd sp!, {r4-r6, lr}
+ bx lr
+}
diff --git a/arm9/lib/src/MI_wram.c b/arm9/lib/src/MI_wram.c
new file mode 100644
index 00000000..a65bbb6f
--- /dev/null
+++ b/arm9/lib/src/MI_wram.c
@@ -0,0 +1,8 @@
+#include "function_target.h"
+#include "consts.h"
+#include "MI_wram.h"
+
+ARM_FUNC void MI_SetWramBank(MIWram cnt)
+{
+ reg_GX_VRAMCNT_WRAM = (u8)cnt;
+}
diff --git a/arm9/lib/src/OS_init.c b/arm9/lib/src/OS_init.c
index 5bd435e7..00355853 100644
--- a/arm9/lib/src/OS_init.c
+++ b/arm9/lib/src/OS_init.c
@@ -1,8 +1,8 @@
#include "function_target.h"
#include "OS_init.h"
+#include "MI_init.h"
extern void PXI_Init(void);
-extern void MI_Init(void);
extern void CTRDG_Init(void);
extern void CARD_Init(void);
extern void PM_Init(void);
diff --git a/arm9/lib/src/OS_reset.c b/arm9/lib/src/OS_reset.c
index a458a8fa..03781947 100644
--- a/arm9/lib/src/OS_reset.c
+++ b/arm9/lib/src/OS_reset.c
@@ -7,6 +7,7 @@
#include "OS_spinLock.h"
#include "OS_cache.h"
#include "sections.h"
+#include "MI_dma.h"
static u16 OSi_IsInitReset = 0;
vu16 OSi_IsResetOccurred = 0;
@@ -16,7 +17,6 @@ extern u32 PXI_IsCallbackReady(u32 param1, u32 param2);
extern void PXI_SetFifoRecvCallback(u32 param1, void* callback);
extern u32 PXI_SendWordByFifo(u32 param1, u32 data, u32 param2);
extern void CARD_LockRom(u16 lockId);
-extern void MI_StopDma(u32 dma);
static void OSi_CommonCallback(PXIFifoTag tag, u32 data, BOOL err);
static void OSi_SendToPxi(u16 data);
diff --git a/arm9/src/error_handling.c b/arm9/src/error_handling.c
new file mode 100644
index 00000000..9052773f
--- /dev/null
+++ b/arm9/src/error_handling.c
@@ -0,0 +1,16 @@
+#include "global.h"
+#include "error_handling.h"
+
+extern u32 FUN_02031810(void);
+extern void PrintErrorMessageAndReset(void);
+
+THUMB_FUNC void ErrorHandling(void)
+{
+ if (FUN_02031810())
+ {
+ if (OS_GetProcMode() != OS_PROCMODE_IRQ)
+ {
+ PrintErrorMessageAndReset();
+ }
+ }
+}
diff --git a/include/error_handling.h b/include/error_handling.h
new file mode 100644
index 00000000..1299fcba
--- /dev/null
+++ b/include/error_handling.h
@@ -0,0 +1,6 @@
+#ifndef POKEDIAMOND_ERROR_HANDLING_H
+#define POKEDIAMOND_ERROR_HANDLING_H
+
+void ErrorHandling(void);
+
+#endif //POKEDIAMOND_ERROR_HANDLING_H
diff --git a/include/global.h b/include/global.h
index 3b377e5e..e0e8cb22 100644
--- a/include/global.h
+++ b/include/global.h
@@ -8,11 +8,10 @@
#include "nitro.h"
#include "global.fieldmap.h"
#include "constants/global.h"
+#include "error_handling.h"
#define NELEMS(a) (sizeof(a) / sizeof(*(a)))
-extern void ErrorHandling(void);
-
#define GF_ASSERT(expr) do {if (!(expr)) ErrorHandling();} while (0)
#ifndef IN_MAIN_C