summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arm9/asm/CTRDG_backup.s189
-rw-r--r--arm9/asm/CTRDG_flash_AT29LV512.s48
-rw-r--r--arm9/asm/CTRDG_flash_LE39FW512.s64
-rw-r--r--arm9/asm/CTRDG_flash_MX29L010.s56
-rw-r--r--arm9/asm/CTRDG_flash_MX29L512.s16
-rw-r--r--arm9/asm/CTRDG_flash_common.s80
-rw-r--r--arm9/lib/include/CTRDG_backup.h41
-rw-r--r--arm9/lib/include/CTRDG_flash.h25
-rw-r--r--arm9/lib/include/CTRDG_task.h25
-rw-r--r--arm9/lib/include/MI_exMemory.h18
-rw-r--r--arm9/lib/src/CTRDG_backup.c94
11 files changed, 335 insertions, 321 deletions
diff --git a/arm9/asm/CTRDG_backup.s b/arm9/asm/CTRDG_backup.s
deleted file mode 100644
index e4c4baa4..00000000
--- a/arm9/asm/CTRDG_backup.s
+++ /dev/null
@@ -1,189 +0,0 @@
- .include "asm/macros.inc"
- .include "global.inc"
-
- .extern AT29LV512_lib
- .extern CTRDGi_EraseFlash4KBAT
- .extern CTRDGi_EraseFlash4KBAsyncAT
- .extern CTRDGi_EraseFlashChipAT
- .extern CTRDGi_EraseFlashChipAsyncAT
- .extern CTRDGi_EraseFlashChipAsyncLE
- .extern CTRDGi_EraseFlashChipAsyncMX
- .extern CTRDGi_EraseFlashChipLE
- .extern CTRDGi_EraseFlashChipMX
- .extern CTRDGi_EraseFlashSectorAT
- .extern CTRDGi_EraseFlashSectorAsyncAT
- .extern CTRDGi_EraseFlashSectorAsyncLE
- .extern CTRDGi_EraseFlashSectorAsyncMX
- .extern CTRDGi_EraseFlashSectorMX
- .extern CTRDGi_PollingSR1MCOMMON
- .extern CTRDGi_PollingSR512kCOMMON
- .extern CTRDGi_WriteFlash4KBAT
- .extern CTRDGi_WriteFlash4KBAsyncAT
- .extern CTRDGi_WriteFlashSectorAT
- .extern CTRDGi_WriteFlashSectorAsyncAT
- .extern CTRDGi_WriteFlashSectorAsyncLE
- .extern CTRDGi_WriteFlashSectorAsyncMX
- .extern CTRDGi_WriteFlashSectorLE
- .extern CTRDGi_WriteFlashSectorMX
- .extern CTRDGi_WriteFlashSectorAsyncMX5
- .extern CTRDGi_WriteFlashSectorMX5
- .extern defaultFlash1M
- .extern defaultFlash512
- .extern LE26FV10N1TS_10
- .extern LE39FW512
- .extern MN63F805MNP
- .extern MX29L010
- .extern UNK_021D6B14
- .extern UNK_021D6B30
- .extern UNK_021D6B28
- .extern UNK_021D6B1C
- .extern UNK_021D6B24
- .extern UNK_021D6B20
- .extern UNK_021D6B0C
- .extern UNK_021D6B34
- .extern UNK_021D6B2C
- .extern UNK_021D6B4C
- .extern UNK_021D6B18
-
- .section .rodata
-
- .global UNK_02103FE4
-UNK_02103FE4: ; 0x02103FE4
- .byte 0x14, 0x00, 0x00, 0x00
-
- .global UNK_02103FE8
-UNK_02103FE8: ; 0x02103FE8
- .word MX29L010
- .word LE26FV10N1TS_10
- .word defaultFlash1M
-
- .global UNK_02103FF4
-UNK_02103FF4: ; 0x02103FF4
- .word LE39FW512
- .word AT29LV512_lib
- .word MN63F805MNP
- .word defaultFlash512
-
- .section .bss
-
- .text
-
- arm_func_start CTRDG_IdentifyAgbBackup
-CTRDG_IdentifyAgbBackup: ; 0x020DBD50
- stmdb sp!, {r4-r7,lr}
- sub sp, sp, #0x4
- mov r7, r0
- cmp r7, #0x1
- mov r0, #0x1
- bhi _020DBEAC
- bl OS_GetLockID
- ldr r1, _020DBED8 ; =UNK_021D6B0C
- strh r0, [r1, #0x0]
- ldrh r0, [r1, #0x0]
- bl OS_LockCartridge
- ldr r6, _020DBEDC ; =0x04000204
- ldr r1, _020DBEE0 ; =UNK_02103FE4
- ldrh r3, [r6, #0x0]
- ldrh r2, [r6, #0x0]
- ldr r0, _020DBEE4 ; =UNK_021D6B28
- and r4, r3, #0x3
- bic r2, r2, #0x3
- orr r2, r2, #0x3
- strh r2, [r6, #0x0]
- str r1, [r0, #0x0]
- bl CTRDGi_ReadFlashID
- ldr r2, _020DBEDC ; =0x04000204
- mov r6, r0
- ldrh r1, [r2, #0x0]
- cmp r7, #0x0
- ldreq r5, _020DBEE8 ; =UNK_02103FF4
- bic r1, r1, #0x3
- orr r1, r1, r4
- cmp r7, #0x1
- ldr r0, _020DBED8 ; =UNK_021D6B0C
- strh r1, [r2, #0x0]
- ldrh r0, [r0, #0x0]
- ldreq r5, _020DBEEC ; =UNK_02103FE8
- bl OS_UnlockCartridge
- ldr r2, [r5, #0x0]
- mov r0, #0x1
- ldrh r1, [r2, #0x38]
- cmp r1, #0x0
- beq _020DBE14
- and r3, r6, #0xff
-_020DBDF4:
- ldrh r1, [r2, #0x38]
- cmp r3, r1
- moveq r0, #0x0
- beq _020DBE14
- ldr r2, [r5, #0x4]!
- ldrh r1, [r2, #0x38]
- cmp r1, #0x0
- bne _020DBDF4
-_020DBE14:
- ldr r2, [r2, #0x0]
- ldr r1, _020DBEF0 ; =UNK_021D6B14
- ldr r3, _020DBEF4 ; =UNK_021D6B34
- str r2, [r1, #0x0]
- ldr r1, [r5, #0x0]
- ldr r2, _020DBEF8 ; =UNK_021D6B2C
- ldr r4, [r1, #0x4]
- ldr r1, _020DBEFC ; =UNK_021D6B18
- str r4, [r3, #0x0]
- ldr r3, [r5, #0x0]
- ldr r6, _020DBF00 ; =UNK_021D6B1C
- ldr r3, [r3, #0x8]
- ldr r4, _020DBF04 ; =UNK_021D6B30
- str r3, [r2, #0x0]
- ldr r2, [r5, #0x0]
- ldr r3, _020DBF08 ; =UNK_021D6B24
- ldr r7, [r2, #0xc]
- ldr r2, _020DBEE4 ; =UNK_021D6B28
- str r7, [r1, #0x0]
- ldr r7, [r5, #0x0]
- ldr r1, _020DBF0C ; =UNK_021D6B20
- ldr r7, [r7, #0x10]
- add sp, sp, #0x4
- str r7, [r6, #0x0]
- ldr r6, [r5, #0x0]
- ldr r6, [r6, #0x14]
- str r6, [r4, #0x0]
- ldr r4, [r5, #0x0]
- ldr r4, [r4, #0x18]
- str r4, [r3, #0x0]
- ldr r3, [r5, #0x0]
- ldr r3, [r3, #0x1c]
- str r3, [r2, #0x0]
- ldr r2, [r5, #0x0]
- add r2, r2, #0x20
- str r2, [r1, #0x0]
- ldmia sp!, {r4-r7,lr}
- bx lr
-_020DBEAC:
- cmp r7, #0x2
- addne sp, sp, #0x4
- ldmneia sp!, {r4-r7,lr}
- bxne lr
- bl OS_GetLockID
- ldr r1, _020DBF10 ; =UNK_021D6B4C
- strh r0, [r1, #0x0]
- mov r0, #0x0
- add sp, sp, #0x4
- ldmia sp!, {r4-r7,lr}
- bx lr
- .balign 4
-_020DBED8: .word UNK_021D6B0C
-_020DBEDC: .word 0x04000204
-_020DBEE0: .word UNK_02103FE4
-_020DBEE4: .word UNK_021D6B28
-_020DBEE8: .word UNK_02103FF4
-_020DBEEC: .word UNK_02103FE8
-_020DBEF0: .word UNK_021D6B14
-_020DBEF4: .word UNK_021D6B34
-_020DBEF8: .word UNK_021D6B2C
-_020DBEFC: .word UNK_021D6B18
-_020DBF00: .word UNK_021D6B1C
-_020DBF04: .word UNK_021D6B30
-_020DBF08: .word UNK_021D6B24
-_020DBF0C: .word UNK_021D6B20
-_020DBF10: .word UNK_021D6B4C
diff --git a/arm9/asm/CTRDG_flash_AT29LV512.s b/arm9/asm/CTRDG_flash_AT29LV512.s
index ff80e947..24b2e0f2 100644
--- a/arm9/asm/CTRDG_flash_AT29LV512.s
+++ b/arm9/asm/CTRDG_flash_AT29LV512.s
@@ -2,9 +2,9 @@
.include "global.inc"
.extern CTRDGi_PollingSR512kCOMMON
- .extern UNK_021D6B20
- .extern UNK_021D6B24
- .extern UNK_021D6B0C
+ .extern AgbFlash
+ .extern CTRDGi_PollingSR
+ .extern ctrdgi_flash_lock_id
.extern UNK_021D6B38
.extern UNK_021D6B08
@@ -259,14 +259,14 @@ CTRDGi_WriteFlashSectorCoreAT: ; 0x020DC86C
stmia r4!, {r0-r3}
ldmia r5!, {r0-r3}
stmia r4!, {r0-r3}
- ldr r0, _020DC984 ; =UNK_021D6B0C
+ ldr r0, _020DC984 ; =ctrdgi_flash_lock_id
ldr r1, [r5, #0x0]
ldrh r0, [r0, #0x0]
str r1, [r4, #0x0]
ldr r4, [sp, #0xc]
bl OS_LockCartridge
ldr r5, _020DC988 ; =0x04000204
- ldr r1, _020DC98C ; =UNK_021D6B20
+ ldr r1, _020DC98C ; =AgbFlash
ldrh r0, [r5, #0x0]
ldr r1, [r1, #0x0]
ldrh r2, [r5, #0x0]
@@ -302,7 +302,7 @@ _020DC91C:
bne _020DC91C
_020DC92C:
ldr ip, _020DC994 ; =0x04000208
- ldr r3, _020DC9A0 ; =UNK_021D6B24
+ ldr r3, _020DC9A0 ; =CTRDGi_PollingSR
ldrh r0, [r12, #0x0]
sub r1, r1, #0x1
mov r0, #0x1
@@ -311,7 +311,7 @@ _020DC92C:
ldr r3, [r3, #0x0]
blx r3
ldr r3, _020DC988 ; =0x04000204
- ldr r1, _020DC984 ; =UNK_021D6B0C
+ ldr r1, _020DC984 ; =ctrdgi_flash_lock_id
ldrh r2, [r3, #0x0]
mov r4, r0
bic r0, r2, #0x3
@@ -324,14 +324,14 @@ _020DC92C:
ldmia sp!, {r4-r5,lr}
bx lr
.balign 4
-_020DC984: .word UNK_021D6B0C
+_020DC984: .word ctrdgi_flash_lock_id
_020DC988: .word 0x04000204
-_020DC98C: .word UNK_021D6B20
+_020DC98C: .word AgbFlash
_020DC990: .word AT29LV512_org
_020DC994: .word 0x04000208
_020DC998: .word 0x0A005555
_020DC99C: .word 0x0A002AAA
-_020DC9A0: .word UNK_021D6B24
+_020DC9A0: .word CTRDGi_PollingSR
arm_func_start CTRDGi_EraseFlash4KBCoreAT
CTRDGi_EraseFlash4KBCoreAT: ; 0x020DC9A4
@@ -399,7 +399,7 @@ CTRDGi_EraseFlashSectorCoreAT: ; 0x020DCA58
ldr r0, [r5, #0x0]
ldr r1, _020DCB80 ; =AT29LV512_org
str r0, [r4, #0x0]
- ldr r0, _020DCB84 ; =UNK_021D6B0C
+ ldr r0, _020DCB84 ; =ctrdgi_flash_lock_id
ldrh r2, [sp, #0x20]
ldrh r1, [r1, #0x28]
ldrh r0, [r0, #0x0]
@@ -407,7 +407,7 @@ CTRDGi_EraseFlashSectorCoreAT: ; 0x020DCA58
add r5, r1, #0xa000000
bl OS_LockCartridge
ldr r4, _020DCB88 ; =0x04000204
- ldr r1, _020DCB8C ; =UNK_021D6B20
+ ldr r1, _020DCB8C ; =AgbFlash
ldrh r0, [r4, #0x0]
ldr r2, [r1, #0x0]
ldrh r1, [r4, #0x0]
@@ -439,7 +439,7 @@ _020DCB0C:
bne _020DCB0C
_020DCB18:
ldr ip, _020DCB90 ; =0x04000208
- ldr r3, _020DCB9C ; =UNK_021D6B24
+ ldr r3, _020DCB9C ; =CTRDGi_PollingSR
ldrh r0, [r12, #0x0]
sub r1, r5, #0x1
strh r2, [r12, #0x0]
@@ -456,7 +456,7 @@ _020DCB18:
bic r1, r1, #0x3
movne r5, r0, lsr #0x10
orr r1, r1, r4
- ldr r0, _020DCB84 ; =UNK_021D6B0C
+ ldr r0, _020DCB84 ; =ctrdgi_flash_lock_id
strh r1, [r2, #0x0]
ldrh r0, [r0, #0x0]
bl OS_UnlockCartridge
@@ -466,23 +466,23 @@ _020DCB18:
bx lr
.balign 4
_020DCB80: .word AT29LV512_org
-_020DCB84: .word UNK_021D6B0C
+_020DCB84: .word ctrdgi_flash_lock_id
_020DCB88: .word 0x04000204
-_020DCB8C: .word UNK_021D6B20
+_020DCB8C: .word AgbFlash
_020DCB90: .word 0x04000208
_020DCB94: .word 0x0A005555
_020DCB98: .word 0x0A002AAA
-_020DCB9C: .word UNK_021D6B24
+_020DCB9C: .word CTRDGi_PollingSR
arm_func_start CTRDGi_EraseFlashChipCoreAT
CTRDGi_EraseFlashChipCoreAT: ; 0x020DCBA0
stmdb sp!, {r4-r5,lr}
sub sp, sp, #0x4
- ldr r0, _020DCC7C ; =UNK_021D6B0C
+ ldr r0, _020DCC7C ; =ctrdgi_flash_lock_id
ldrh r0, [r0, #0x0]
bl OS_LockCartridge
ldr r4, _020DCC80 ; =0x04000204
- ldr r0, _020DCC84 ; =UNK_021D6B20
+ ldr r0, _020DCC84 ; =AgbFlash
ldrh r3, [r4, #0x0]
ldr r0, [r0, #0x0]
ldrh r1, [r4, #0x0]
@@ -510,7 +510,7 @@ CTRDGi_EraseFlashChipCoreAT: ; 0x020DCBA0
strb r2, [lr, #0x0]
ldrh r2, [r0, #0x0]
ldr r2, [r1, #0x0]
- ldr r1, _020DCC98 ; =UNK_021D6B24
+ ldr r1, _020DCC98 ; =CTRDGi_PollingSR
strh r2, [r0, #0x0]
ldr r4, [r1, #0x0]
mov r0, #0x3
@@ -519,7 +519,7 @@ CTRDGi_EraseFlashChipCoreAT: ; 0x020DCBA0
and r5, r3, #0x3
blx r4
ldr r3, _020DCC80 ; =0x04000204
- ldr r1, _020DCC7C ; =UNK_021D6B0C
+ ldr r1, _020DCC7C ; =ctrdgi_flash_lock_id
ldrh r2, [r3, #0x0]
mov r4, r0
bic r0, r2, #0x3
@@ -532,11 +532,11 @@ CTRDGi_EraseFlashChipCoreAT: ; 0x020DCBA0
ldmia sp!, {r4-r5,lr}
bx lr
.balign 4
-_020DCC7C: .word UNK_021D6B0C
+_020DCC7C: .word ctrdgi_flash_lock_id
_020DCC80: .word 0x04000204
-_020DCC84: .word UNK_021D6B20
+_020DCC84: .word AgbFlash
_020DCC88: .word 0x04000208
_020DCC8C: .word UNK_021D6B38
_020DCC90: .word 0x0A005555
_020DCC94: .word 0x0A002AAA
-_020DCC98: .word UNK_021D6B24
+_020DCC98: .word CTRDGi_PollingSR
diff --git a/arm9/asm/CTRDG_flash_LE39FW512.s b/arm9/asm/CTRDG_flash_LE39FW512.s
index b3f4b8a3..3228818d 100644
--- a/arm9/asm/CTRDG_flash_LE39FW512.s
+++ b/arm9/asm/CTRDG_flash_LE39FW512.s
@@ -2,9 +2,9 @@
.include "global.inc"
.extern CTRDGi_PollingSR512kCOMMON
- .extern UNK_021D6B20
- .extern UNK_021D6B24
- .extern UNK_021D6B0C
+ .extern AgbFlash
+ .extern CTRDGi_PollingSR
+ .extern ctrdgi_flash_lock_id
.extern UNK_021D6B38
.extern UNK_021D6B08
@@ -128,13 +128,13 @@ CTRDGi_EraseFlashChipLE: ; 0x020DCD70
arm_func_start CTRDGi_VerifyFlashErase
CTRDGi_VerifyFlashErase: ; 0x020DCD94
stmdb sp!, {r4-r6,lr}
- ldr r2, _020DCE14 ; =UNK_021D6B0C
+ ldr r2, _020DCE14 ; =ctrdgi_flash_lock_id
mov r4, r0
ldrh r0, [r2, #0x0]
mov r5, r1
bl OS_LockCartridge
ldr ip, _020DCE18 ; =0x04000204
- ldr r0, _020DCE1C ; =UNK_021D6B20
+ ldr r0, _020DCE1C ; =AgbFlash
ldrh r3, [r12, #0x0]
ldr r0, [r0, #0x0]
ldrh r1, [r12, #0x0]
@@ -148,7 +148,7 @@ CTRDGi_VerifyFlashErase: ; 0x020DCD94
blx r5
cmp r0, #0x0
ldr r2, _020DCE18 ; =0x04000204
- ldr r0, _020DCE14 ; =UNK_021D6B0C
+ ldr r0, _020DCE14 ; =ctrdgi_flash_lock_id
ldrh r1, [r2, #0x0]
ldrne r4, _020DCE20 ; =0x00008004
bic r1, r1, #0x3
@@ -160,14 +160,14 @@ CTRDGi_VerifyFlashErase: ; 0x020DCD94
ldmia sp!, {r4-r6,lr}
bx lr
.balign 4
-_020DCE14: .word UNK_021D6B0C
+_020DCE14: .word ctrdgi_flash_lock_id
_020DCE18: .word 0x04000204
-_020DCE1C: .word UNK_021D6B20
+_020DCE1C: .word AgbFlash
_020DCE20: .word 0x00008004
arm_func_start CTRDGi_VerifyFlashCoreFF
CTRDGi_VerifyFlashCoreFF: ; 0x020DCE24
- ldr r1, _020DCE54 ; =UNK_021D6B20
+ ldr r1, _020DCE54 ; =AgbFlash
ldr r1, [r1, #0x0]
ldr r2, [r1, #0x4]
cmp r2, #0x0
@@ -182,7 +182,7 @@ _020DCE4C:
mov r0, r2
bx lr
.balign 4
-_020DCE54: .word UNK_021D6B20
+_020DCE54: .word AgbFlash
arm_func_start CTRDGi_WriteFlashSectorCoreLE
CTRDGi_WriteFlashSectorCoreLE: ; 0x020DCE58
@@ -203,7 +203,7 @@ CTRDGi_WriteFlashSectorCoreLE: ; 0x020DCE58
ldrhs r0, _020DD018 ; =0x000080FF
ldmcsia sp!, {r4-r9,lr}
bxcs lr
- ldr r0, _020DD01C ; =UNK_021D6B20
+ ldr r0, _020DD01C ; =AgbFlash
mov r9, #0x0
ldr r0, [r0, #0x0]
ldrh r0, [r0, #0x8]
@@ -247,11 +247,11 @@ _020DCF1C:
cmp r9, r5
bls _020DCF1C
_020DCF38:
- ldr r0, _020DD024 ; =UNK_021D6B0C
+ ldr r0, _020DD024 ; =ctrdgi_flash_lock_id
ldrh r0, [r0, #0x0]
bl OS_LockCartridge
ldr r5, _020DD028 ; =0x04000204
- ldr r1, _020DD01C ; =UNK_021D6B20
+ ldr r1, _020DD01C ; =AgbFlash
ldrh r0, [r5, #0x0]
ldr r3, [r1, #0x0]
ldrh r2, [r5, #0x0]
@@ -295,7 +295,7 @@ _020DCFD4:
ldr r2, _020DD028 ; =0x04000204
strh r0, [r3, #0x0]
ldrh r1, [r2, #0x0]
- ldr r0, _020DD024 ; =UNK_021D6B0C
+ ldr r0, _020DD024 ; =ctrdgi_flash_lock_id
bic r1, r1, #0x3
orr r1, r1, r5
strh r1, [r2, #0x0]
@@ -307,9 +307,9 @@ _020DCFD4:
bx lr
.balign 4
_020DD018: .word 0x000080FF
-_020DD01C: .word UNK_021D6B20
+_020DD01C: .word AgbFlash
_020DD020: .word CTRDGi_VerifyFlashCoreFF
-_020DD024: .word UNK_021D6B0C
+_020DD024: .word ctrdgi_flash_lock_id
_020DD028: .word 0x04000204
_020DD02C: .word UNK_021D6B08
_020DD030: .word 0x04000208
@@ -329,7 +329,7 @@ CTRDGi_ProgramFlashByteLE: ; 0x020DD038
mov r0, #0xa0
strb r0, [r12, #0x0]
ldrb r2, [lr, #0x0]
- ldr r3, _020DD094 ; =UNK_021D6B24
+ ldr r3, _020DD094 ; =CTRDGi_PollingSR
mov r0, #0x1
strb r2, [r1, #0x0]
ldrb r2, [lr, #0x0]
@@ -341,7 +341,7 @@ CTRDGi_ProgramFlashByteLE: ; 0x020DD038
.balign 4
_020DD08C: .word 0x0A005555
_020DD090: .word 0x0A002AAA
-_020DD094: .word UNK_021D6B24
+_020DD094: .word CTRDGi_PollingSR
arm_func_start CTRDGi_EraseFlashSectorCoreLE
CTRDGi_EraseFlashSectorCoreLE: ; 0x020DD098
@@ -361,11 +361,11 @@ CTRDGi_EraseFlashSectorCoreLE: ; 0x020DD098
ldrhs r0, _020DD1B8 ; =0x000080FF
ldmcsia sp!, {r4-r6,lr}
bxcs lr
- ldr r0, _020DD1BC ; =UNK_021D6B0C
+ ldr r0, _020DD1BC ; =ctrdgi_flash_lock_id
ldrh r0, [r0, #0x0]
bl OS_LockCartridge
ldr r6, _020DD1C0 ; =0x04000204
- ldr r1, _020DD1C4 ; =UNK_021D6B20
+ ldr r1, _020DD1C4 ; =AgbFlash
ldrh r3, [r6, #0x0]
ldr r0, [r1, #0x0]
ldrh r2, [r6, #0x0]
@@ -397,7 +397,7 @@ CTRDGi_EraseFlashSectorCoreLE: ; 0x020DD098
strb r4, [r1, #0x0]
ldrh r4, [r0, #0x0]
ldr r4, [r2, #0x0]
- ldr r2, _020DD1D8 ; =UNK_021D6B24
+ ldr r2, _020DD1D8 ; =CTRDGi_PollingSR
strh r4, [r0, #0x0]
ldr r4, [r2, #0x0]
mov r0, #0x2
@@ -405,7 +405,7 @@ CTRDGi_EraseFlashSectorCoreLE: ; 0x020DD098
and r5, r3, #0x3
blx r4
ldr r3, _020DD1C0 ; =0x04000204
- ldr r1, _020DD1BC ; =UNK_021D6B0C
+ ldr r1, _020DD1BC ; =ctrdgi_flash_lock_id
ldrh r2, [r3, #0x0]
mov r4, r0
bic r0, r2, #0x3
@@ -419,24 +419,24 @@ CTRDGi_EraseFlashSectorCoreLE: ; 0x020DD098
bx lr
.balign 4
_020DD1B8: .word 0x000080FF
-_020DD1BC: .word UNK_021D6B0C
+_020DD1BC: .word ctrdgi_flash_lock_id
_020DD1C0: .word 0x04000204
-_020DD1C4: .word UNK_021D6B20
+_020DD1C4: .word AgbFlash
_020DD1C8: .word 0x04000208
_020DD1CC: .word UNK_021D6B38
_020DD1D0: .word 0x0A005555
_020DD1D4: .word 0x0A002AAA
-_020DD1D8: .word UNK_021D6B24
+_020DD1D8: .word CTRDGi_PollingSR
arm_func_start CTRDGi_EraseFlashChipCoreLE
CTRDGi_EraseFlashChipCoreLE: ; 0x020DD1DC
stmdb sp!, {r4-r5,lr}
sub sp, sp, #0x4
- ldr r0, _020DD2B8 ; =UNK_021D6B0C
+ ldr r0, _020DD2B8 ; =ctrdgi_flash_lock_id
ldrh r0, [r0, #0x0]
bl OS_LockCartridge
ldr r4, _020DD2BC ; =0x04000204
- ldr r0, _020DD2C0 ; =UNK_021D6B20
+ ldr r0, _020DD2C0 ; =AgbFlash
ldrh r3, [r4, #0x0]
ldr r0, [r0, #0x0]
ldrh r1, [r4, #0x0]
@@ -464,7 +464,7 @@ CTRDGi_EraseFlashChipCoreLE: ; 0x020DD1DC
strb r2, [lr, #0x0]
ldrh r2, [r0, #0x0]
ldr r2, [r1, #0x0]
- ldr r1, _020DD2D4 ; =UNK_021D6B24
+ ldr r1, _020DD2D4 ; =CTRDGi_PollingSR
strh r2, [r0, #0x0]
ldr r4, [r1, #0x0]
mov r0, #0x3
@@ -473,7 +473,7 @@ CTRDGi_EraseFlashChipCoreLE: ; 0x020DD1DC
and r5, r3, #0x3
blx r4
ldr r3, _020DD2BC ; =0x04000204
- ldr r1, _020DD2B8 ; =UNK_021D6B0C
+ ldr r1, _020DD2B8 ; =ctrdgi_flash_lock_id
ldrh r2, [r3, #0x0]
mov r4, r0
bic r0, r2, #0x3
@@ -486,11 +486,11 @@ CTRDGi_EraseFlashChipCoreLE: ; 0x020DD1DC
ldmia sp!, {r4-r5,lr}
bx lr
.balign 4
-_020DD2B8: .word UNK_021D6B0C
+_020DD2B8: .word ctrdgi_flash_lock_id
_020DD2BC: .word 0x04000204
-_020DD2C0: .word UNK_021D6B20
+_020DD2C0: .word AgbFlash
_020DD2C4: .word 0x04000208
_020DD2C8: .word UNK_021D6B38
_020DD2CC: .word 0x0A005555
_020DD2D0: .word 0x0A002AAA
-_020DD2D4: .word UNK_021D6B24
+_020DD2D4: .word CTRDGi_PollingSR
diff --git a/arm9/asm/CTRDG_flash_MX29L010.s b/arm9/asm/CTRDG_flash_MX29L010.s
index 5ac28935..7b4e1dc3 100644
--- a/arm9/asm/CTRDG_flash_MX29L010.s
+++ b/arm9/asm/CTRDG_flash_MX29L010.s
@@ -2,9 +2,9 @@
.include "global.inc"
.extern CTRDGi_PollingSR1MCOMMON
- .extern UNK_021D6B20
- .extern UNK_021D6B24
- .extern UNK_021D6B0C
+ .extern AgbFlash
+ .extern CTRDGi_PollingSR
+ .extern ctrdgi_flash_lock_id
.extern UNK_021D6B38
.extern UNK_021D6B08
@@ -135,7 +135,7 @@ CTRDGi_WriteFlashSectorCoreMX: ; 0x020DD3D0
stmia r4!, {r0-r3}
ldmia r5!, {r0-r3}
stmia r4!, {r0-r3}
- ldr r0, _020DD540 ; =UNK_021D6B20
+ ldr r0, _020DD540 ; =AgbFlash
ldr r1, [r5, #0x0]
ldr r0, [r0, #0x0]
str r1, [r4, #0x0]
@@ -153,11 +153,11 @@ CTRDGi_WriteFlashSectorCoreMX: ; 0x020DD3D0
addne sp, sp, #0x28
ldmneia sp!, {r4-r8,lr}
bxne lr
- ldr r0, _020DD548 ; =UNK_021D6B0C
+ ldr r0, _020DD548 ; =ctrdgi_flash_lock_id
ldrh r0, [r0, #0x0]
bl OS_LockCartridge
ldr r7, _020DD54C ; =0x04000204
- ldr r0, _020DD540 ; =UNK_021D6B20
+ ldr r0, _020DD540 ; =AgbFlash
ldrh r3, [r7, #0x0]
ldr r2, [r0, #0x0]
ldrh r1, [r7, #0x0]
@@ -169,7 +169,7 @@ CTRDGi_WriteFlashSectorCoreMX: ; 0x020DD3D0
strh r1, [r7, #0x0]
and r7, r3, #0x3
bl CTRDGi_SetFlashBankMx
- ldr r0, _020DD540 ; =UNK_021D6B20
+ ldr r0, _020DD540 ; =AgbFlash
and r1, r5, #0xf
ldr r3, [r0, #0x0]
mov r0, r1, lsl #0x10
@@ -211,7 +211,7 @@ _020DD4FC:
ldr r2, _020DD54C ; =0x04000204
strh r0, [r3, #0x0]
ldrh r1, [r2, #0x0]
- ldr r0, _020DD548 ; =UNK_021D6B0C
+ ldr r0, _020DD548 ; =ctrdgi_flash_lock_id
bic r1, r1, #0x3
orr r1, r1, r7
strh r1, [r2, #0x0]
@@ -222,9 +222,9 @@ _020DD4FC:
ldmia sp!, {r4-r8,lr}
bx lr
.balign 4
-_020DD540: .word UNK_021D6B20
+_020DD540: .word AgbFlash
_020DD544: .word 0x000080FF
-_020DD548: .word UNK_021D6B0C
+_020DD548: .word ctrdgi_flash_lock_id
_020DD54C: .word 0x04000204
_020DD550: .word UNK_021D6B08
_020DD554: .word 0x04000208
@@ -244,7 +244,7 @@ CTRDGi_ProgramFlashByteMX: ; 0x020DD55C
mov r0, #0xa0
strb r0, [r12, #0x0]
ldrb r2, [lr, #0x0]
- ldr r3, _020DD5B8 ; =UNK_021D6B24
+ ldr r3, _020DD5B8 ; =CTRDGi_PollingSR
mov r0, #0x1
strb r2, [r1, #0x0]
ldrb r2, [lr, #0x0]
@@ -256,7 +256,7 @@ CTRDGi_ProgramFlashByteMX: ; 0x020DD55C
.balign 4
_020DD5B0: .word 0x0A005555
_020DD5B4: .word 0x0A002AAA
-_020DD5B8: .word UNK_021D6B24
+_020DD5B8: .word CTRDGi_PollingSR
arm_func_start CTRDGi_EraseFlashSectorCoreMX
CTRDGi_EraseFlashSectorCoreMX: ; 0x020DD5BC
@@ -268,7 +268,7 @@ CTRDGi_EraseFlashSectorCoreMX: ; 0x020DD5BC
stmia r4!, {r0-r3}
ldmia r5!, {r0-r3}
stmia r4!, {r0-r3}
- ldr r0, _020DD748 ; =UNK_021D6B20
+ ldr r0, _020DD748 ; =AgbFlash
ldr r1, [r5, #0x0]
ldr r0, [r0, #0x0]
str r1, [r4, #0x0]
@@ -279,11 +279,11 @@ CTRDGi_EraseFlashSectorCoreMX: ; 0x020DD5BC
ldrhs r0, _020DD74C ; =0x000080FF
ldmcsia sp!, {r4-r11,lr}
bxcs lr
- ldr r0, _020DD750 ; =UNK_021D6B0C
+ ldr r0, _020DD750 ; =ctrdgi_flash_lock_id
ldrh r0, [r0, #0x0]
bl OS_LockCartridge
ldr r5, _020DD754 ; =0x04000204
- ldr r0, _020DD748 ; =UNK_021D6B20
+ ldr r0, _020DD748 ; =AgbFlash
ldrh r3, [r5, #0x0]
ldr r2, [r0, #0x0]
ldrh r1, [r5, #0x0]
@@ -311,7 +311,7 @@ CTRDGi_EraseFlashSectorCoreMX: ; 0x020DD5BC
mov r4, #0x30
str r0, [sp, #0xc]
_020DD684:
- ldr r0, _020DD748 ; =UNK_021D6B20
+ ldr r0, _020DD748 ; =AgbFlash
ldrh r12, [r8, #0x0]
ldr r0, [r0, #0x0]
ldr r3, _020DD75C ; =UNK_021D6B38
@@ -336,7 +336,7 @@ _020DD684:
ldr r3, _020DD75C ; =UNK_021D6B38
ldr r3, [r3, #0x0]
strh r3, [r8, #0x0]
- ldr r3, _020DD768 ; =UNK_021D6B24
+ ldr r3, _020DD768 ; =CTRDGi_PollingSR
ldr r3, [r3, #0x0]
blx r3
str r0, [sp, #0x4]
@@ -349,7 +349,7 @@ _020DD684:
beq _020DD684
_020DD714:
ldr r2, _020DD754 ; =0x04000204
- ldr r1, _020DD750 ; =UNK_021D6B0C
+ ldr r1, _020DD750 ; =ctrdgi_flash_lock_id
ldrh r0, [r2, #0x0]
bic r3, r0, #0x3
ldr r0, [sp, #0x0]
@@ -362,25 +362,25 @@ _020DD714:
ldmia sp!, {r4-r11,lr}
bx lr
.balign 4
-_020DD748: .word UNK_021D6B20
+_020DD748: .word AgbFlash
_020DD74C: .word 0x000080FF
-_020DD750: .word UNK_021D6B0C
+_020DD750: .word ctrdgi_flash_lock_id
_020DD754: .word 0x04000204
_020DD758: .word 0x04000208
_020DD75C: .word UNK_021D6B38
_020DD760: .word 0x0A005555
_020DD764: .word 0x0A002AAA
-_020DD768: .word UNK_021D6B24
+_020DD768: .word CTRDGi_PollingSR
arm_func_start CTRDGi_EraseFlashChipCoreMX
CTRDGi_EraseFlashChipCoreMX: ; 0x020DD76C
stmdb sp!, {r4-r5,lr}
sub sp, sp, #0x4
- ldr r0, _020DD848 ; =UNK_021D6B0C
+ ldr r0, _020DD848 ; =ctrdgi_flash_lock_id
ldrh r0, [r0, #0x0]
bl OS_LockCartridge
ldr r4, _020DD84C ; =0x04000204
- ldr r0, _020DD850 ; =UNK_021D6B20
+ ldr r0, _020DD850 ; =AgbFlash
ldrh r3, [r4, #0x0]
ldr r0, [r0, #0x0]
ldrh r1, [r4, #0x0]
@@ -408,7 +408,7 @@ CTRDGi_EraseFlashChipCoreMX: ; 0x020DD76C
strb r2, [lr, #0x0]
ldrh r2, [r0, #0x0]
ldr r2, [r1, #0x0]
- ldr r1, _020DD864 ; =UNK_021D6B24
+ ldr r1, _020DD864 ; =CTRDGi_PollingSR
strh r2, [r0, #0x0]
ldr r4, [r1, #0x0]
mov r0, #0x3
@@ -417,7 +417,7 @@ CTRDGi_EraseFlashChipCoreMX: ; 0x020DD76C
and r5, r3, #0x3
blx r4
ldr r3, _020DD84C ; =0x04000204
- ldr r1, _020DD848 ; =UNK_021D6B0C
+ ldr r1, _020DD848 ; =ctrdgi_flash_lock_id
ldrh r2, [r3, #0x0]
mov r4, r0
bic r0, r2, #0x3
@@ -430,11 +430,11 @@ CTRDGi_EraseFlashChipCoreMX: ; 0x020DD76C
ldmia sp!, {r4-r5,lr}
bx lr
.balign 4
-_020DD848: .word UNK_021D6B0C
+_020DD848: .word ctrdgi_flash_lock_id
_020DD84C: .word 0x04000204
-_020DD850: .word UNK_021D6B20
+_020DD850: .word AgbFlash
_020DD854: .word 0x04000208
_020DD858: .word UNK_021D6B38
_020DD85C: .word 0x0A005555
_020DD860: .word 0x0A002AAA
-_020DD864: .word UNK_021D6B24
+_020DD864: .word CTRDGi_PollingSR
diff --git a/arm9/asm/CTRDG_flash_MX29L512.s b/arm9/asm/CTRDG_flash_MX29L512.s
index 17b50125..eac57f63 100644
--- a/arm9/asm/CTRDG_flash_MX29L512.s
+++ b/arm9/asm/CTRDG_flash_MX29L512.s
@@ -6,8 +6,8 @@
.extern CTRDGi_EraseFlashSectorAsyncLE
.extern CTRDGi_PollingSR512kCOMMON
.extern UNK_021D6B08
- .extern UNK_021D6B20
- .extern UNK_021D6B0C
+ .extern AgbFlash
+ .extern ctrdgi_flash_lock_id
.section .rodata
@@ -69,7 +69,7 @@ CTRDGi_WriteFlashSectorCoreMX5: ; 0x020DD8C0
stmia r4!, {r0-r3}
ldmia r5!, {r0-r3}
stmia r4!, {r0-r3}
- ldr r0, _020DD9E8 ; =UNK_021D6B20
+ ldr r0, _020DD9E8 ; =AgbFlash
ldr r1, [r5, #0x0]
ldr r0, [r0, #0x0]
str r1, [r4, #0x0]
@@ -87,11 +87,11 @@ CTRDGi_WriteFlashSectorCoreMX5: ; 0x020DD8C0
addne sp, sp, #0x28
ldmneia sp!, {r4-r8,lr}
bxne lr
- ldr r0, _020DD9F0 ; =UNK_021D6B0C
+ ldr r0, _020DD9F0 ; =ctrdgi_flash_lock_id
ldrh r0, [r0, #0x0]
bl OS_LockCartridge
ldr r7, _020DD9F4 ; =0x04000204
- ldr r0, _020DD9E8 ; =UNK_021D6B20
+ ldr r0, _020DD9E8 ; =AgbFlash
ldrh r3, [r7, #0x0]
ldr r2, [r0, #0x0]
ldrh r1, [r7, #0x0]
@@ -126,7 +126,7 @@ _020DD984:
bne _020DD984
_020DD9B8:
ldr r2, _020DD9F4 ; =0x04000204
- ldr r0, _020DD9F0 ; =UNK_021D6B0C
+ ldr r0, _020DD9F0 ; =ctrdgi_flash_lock_id
ldrh r1, [r2, #0x0]
bic r1, r1, #0x3
orr r1, r1, r7
@@ -138,8 +138,8 @@ _020DD9B8:
ldmia sp!, {r4-r8,lr}
bx lr
.balign 4
-_020DD9E8: .word UNK_021D6B20
+_020DD9E8: .word AgbFlash
_020DD9EC: .word 0x000080FF
-_020DD9F0: .word UNK_021D6B0C
+_020DD9F0: .word ctrdgi_flash_lock_id
_020DD9F4: .word 0x04000204
_020DD9F8: .word UNK_021D6B08
diff --git a/arm9/asm/CTRDG_flash_common.s b/arm9/asm/CTRDG_flash_common.s
index aaef15fb..4c51608a 100644
--- a/arm9/asm/CTRDG_flash_common.s
+++ b/arm9/asm/CTRDG_flash_common.s
@@ -7,48 +7,48 @@
UNK_021D6B08: ; 0x021D6B08
.space 0x4
- .global UNK_021D6B0C
-UNK_021D6B0C: ; 0x021D6B0C
+ .global ctrdgi_flash_lock_id
+ctrdgi_flash_lock_id: ; 0x021D6B0C
.space 0x4
.global UNK_021D6B10
UNK_021D6B10: ; 0x021D6B10
.space 0x4
- .global UNK_021D6B14
-UNK_021D6B14: ; 0x021D6B14
+ .global CTRDGi_WriteAgbFlashSector
+CTRDGi_WriteAgbFlashSector: ; 0x021D6B14
.space 0x4
- .global UNK_021D6B18
-UNK_021D6B18: ; 0x021D6B18
+ .global CTRDGi_WriteAgbFlashSectorAsync
+CTRDGi_WriteAgbFlashSectorAsync: ; 0x021D6B18
.space 0x4
- .global UNK_021D6B1C
-UNK_021D6B1C: ; 0x021D6B1C
+ .global CTRDGi_EraseAgbFlashChipAsync
+CTRDGi_EraseAgbFlashChipAsync: ; 0x021D6B1C
.space 0x4
- .global UNK_021D6B20
-UNK_021D6B20: ; 0x021D6B20
+ .global AgbFlash
+AgbFlash: ; 0x021D6B20
.space 0x4
- .global UNK_021D6B24
-UNK_021D6B24: ; 0x021D6B24
+ .global CTRDGi_PollingSR
+CTRDGi_PollingSR: ; 0x021D6B24
.space 0x4
- .global UNK_021D6B28
-UNK_021D6B28: ; 0x021D6B28
+ .global ctrdgi_fl_maxtime
+ctrdgi_fl_maxtime: ; 0x021D6B28
.space 0x4
- .global UNK_021D6B2C
-UNK_021D6B2C: ; 0x021D6B2C
+ .global CTRDGi_EraseAgbFlashSector
+CTRDGi_EraseAgbFlashSector: ; 0x021D6B2C
.space 0x4
- .global UNK_021D6B30
-UNK_021D6B30: ; 0x021D6B30
+ .global CTRDGi_EraseAgbFlashSectorAsync
+CTRDGi_EraseAgbFlashSectorAsync: ; 0x021D6B30
.space 0x4
- .global UNK_021D6B34
-UNK_021D6B34: ; 0x021D6B34
+ .global CTRDGi_EraseAgbFlashChip
+CTRDGi_EraseAgbFlashChip: ; 0x021D6B34
.space 0x4
.global UNK_021D6B38
@@ -63,8 +63,8 @@ UNK_021D6B3C: ; 0x021D6B3C
UNK_021D6B44: ; 0x021D6B44
.space 0x8
- .global UNK_021D6B4C
-UNK_021D6B4C: ; 0x021D6B4C
+ .global ctrdgi_sram_lock_id
+ctrdgi_sram_lock_id: ; 0x021D6B4C
.space 0x4
.text
@@ -103,14 +103,14 @@ CTRDG_VerifyAgbFlash:
CTRDG_WriteAgbFlashSector:
stmdb sp!, {lr}
sub sp, sp, #0x4
- ldr r2, _020DBF90 ; =UNK_021D6B14
+ ldr r2, _020DBF90 ; =CTRDGi_WriteAgbFlashSector
ldr r2, [r2, #0x0]
blx r2
add sp, sp, #0x4
ldmia sp!, {lr}
bx lr
.balign 4
-_020DBF90: .word UNK_021D6B14
+_020DBF90: .word CTRDGi_WriteAgbFlashSector
arm_func_start CTRDG_ReadAgbFlash
CTRDG_ReadAgbFlash: ; 0x020DBF94
@@ -178,7 +178,7 @@ CTRDGi_VerifyAgbFlashCore: ; 0x020DC04C
stmia r4!, {r0-r3}
ldmia r5!, {r0-r3}
stmia r4!, {r0-r3}
- ldr r0, _020DC128 ; =UNK_021D6B0C
+ ldr r0, _020DC128 ; =ctrdgi_flash_lock_id
ldr r1, [r5, #0x0]
ldrh r0, [r0, #0x0]
str r1, [r4, #0x0]
@@ -187,7 +187,7 @@ CTRDGi_VerifyAgbFlashCore: ; 0x020DC04C
ldr r4, [sp, #0x18]
bl OS_LockCartridge
ldr r3, _020DC12C ; =0x04000204
- ldr r0, _020DC130 ; =UNK_021D6B20
+ ldr r0, _020DC130 ; =AgbFlash
ldrh r2, [r3, #0x0]
ldrh r1, [r3, #0x0]
and r7, r2, #0x3
@@ -205,7 +205,7 @@ CTRDGi_VerifyAgbFlashCore: ; 0x020DC04C
mov r0, r0, lsl #0x10
mov r6, r0, lsr #0x10
_020DC0D4:
- ldr r1, _020DC130 ; =UNK_021D6B20
+ ldr r1, _020DC130 ; =AgbFlash
mov r0, r5
ldr r1, [r1, #0x0]
mov r2, r4
@@ -214,7 +214,7 @@ _020DC0D4:
add r1, r1, #0xa000000
bl CTRDGi_VerifyFlashSectorCore
ldr r3, _020DC12C ; =0x04000204
- ldr r1, _020DC128 ; =UNK_021D6B0C
+ ldr r1, _020DC128 ; =ctrdgi_flash_lock_id
ldrh r2, [r3, #0x0]
mov r4, r0
bic r0, r2, #0x3
@@ -227,9 +227,9 @@ _020DC0D4:
ldmia sp!, {r4-r7,lr}
bx lr
.balign 4
-_020DC128: .word UNK_021D6B0C
+_020DC128: .word ctrdgi_flash_lock_id
_020DC12C: .word 0x04000204
-_020DC130: .word UNK_021D6B20
+_020DC130: .word AgbFlash
arm_func_start CTRDGi_VerifyFlashSectorCore
CTRDGi_VerifyFlashSectorCore: ; 0x020DC134
@@ -259,7 +259,7 @@ CTRDGi_ReadAgbFlashCore: ; 0x020DC168
stmia r4!, {r0-r3}
ldmia r5!, {r0-r3}
stmia r4!, {r0-r3}
- ldr r0, _020DC25C ; =UNK_021D6B0C
+ ldr r0, _020DC25C ; =ctrdgi_flash_lock_id
ldr r1, [r5, #0x0]
ldrh r0, [r0, #0x0]
str r1, [r4, #0x0]
@@ -269,7 +269,7 @@ CTRDGi_ReadAgbFlashCore: ; 0x020DC168
ldr r4, [sp, #0x18]
bl OS_LockCartridge
ldr r3, _020DC260 ; =0x04000204
- ldr r0, _020DC264 ; =UNK_021D6B20
+ ldr r0, _020DC264 ; =AgbFlash
ldrh r2, [r3, #0x0]
ldrh r1, [r3, #0x0]
and r8, r2, #0x3
@@ -287,7 +287,7 @@ CTRDGi_ReadAgbFlashCore: ; 0x020DC168
mov r0, r0, lsl #0x10
mov r7, r0, lsr #0x10
_020DC1F4:
- ldr r0, _020DC264 ; =UNK_021D6B20
+ ldr r0, _020DC264 ; =AgbFlash
cmp r4, #0x0
ldr r0, [r0, #0x0]
sub r4, r4, #0x1
@@ -304,7 +304,7 @@ _020DC218:
bne _020DC218
_020DC22C:
ldr r2, _020DC260 ; =0x04000204
- ldr r0, _020DC25C ; =UNK_021D6B0C
+ ldr r0, _020DC25C ; =ctrdgi_flash_lock_id
ldrh r1, [r2, #0x0]
bic r1, r1, #0x3
orr r1, r1, r8
@@ -316,9 +316,9 @@ _020DC22C:
ldmia sp!, {r4-r8,lr}
bx lr
.balign 4
-_020DC25C: .word UNK_021D6B0C
+_020DC25C: .word ctrdgi_flash_lock_id
_020DC260: .word 0x04000204
-_020DC264: .word UNK_021D6B20
+_020DC264: .word AgbFlash
arm_func_start CTRDGi_PollingSR1MCOMMON
CTRDGi_PollingSR1MCOMMON: ; 0x020DC268
@@ -398,7 +398,7 @@ _020DC33C:
_020DC360: ; 0x020DC360
cmp r7, r0
beq _020DC390
- ldr r0, _020DC3AC ; =UNK_021D6B20
+ ldr r0, _020DC3AC ; =AgbFlash
ldr r0, [r0, #0x0]
ldrh r0, [r0, #0x18]
cmp r0, #0xc2
@@ -418,7 +418,7 @@ _020DC394: ; 0x020DC394
bx lr
.balign 4
_020DC3A8: .word UNK_021D6B10
-_020DC3AC: .word UNK_021D6B20
+_020DC3AC: .word AgbFlash
_020DC3B0: .word 0x0A005555
arm_func_start CTRDGi_ReadSrFunc
@@ -463,7 +463,7 @@ _020DC42C: .word UNK_021D6B10
StartFlashTimer: ; 0x020DC430
stmdb sp!, {lr}
sub sp, sp, #0x4
- ldr r1, _020DC47C ; =UNK_021D6B28
+ ldr r1, _020DC47C ; =ctrdgi_fl_maxtime
ldr r2, _020DC480 ; =UNK_021D6B10
mov r3, #0x0
ldr r1, [r1, #0x0]
@@ -481,7 +481,7 @@ StartFlashTimer: ; 0x020DC430
ldmia sp!, {lr}
bx lr
.balign 4
-_020DC47C: .word UNK_021D6B28
+_020DC47C: .word ctrdgi_fl_maxtime
_020DC480: .word UNK_021D6B10
_020DC484: .word UNK_021D6B3C
_020DC488: .word UNK_021D6B44
diff --git a/arm9/lib/include/CTRDG_backup.h b/arm9/lib/include/CTRDG_backup.h
new file mode 100644
index 00000000..d248b7a1
--- /dev/null
+++ b/arm9/lib/include/CTRDG_backup.h
@@ -0,0 +1,41 @@
+#ifndef POKEDIAMOND_CTRDG_BACKUP_H
+#define POKEDIAMOND_CTRDG_BACKUP_H
+
+#include "nitro/types.h"
+#include "CTRDG_flash.h"
+#include "CTRDG_task.h"
+
+typedef struct CTRDGiFlashTypePlusTag
+{
+ u16 (*CTRDGi_WriteAgbFlashSector)(u16 secNo, u8 *src);
+ u16 (*CTRDGi_EraseAgbFlashChip)(void);
+ u16 (*CTRDGi_EraseAgbFlashSector)(u16 secNo);
+ void (*CTRDGi_WriteAgbFlashSectorAsync)(u16 secNo, u8 *src, CTRDG_TASK_FUNC callback);
+ void (*CTRDGi_EraseAgbFlashChipAsync)(CTRDG_TASK_FUNC callback);
+ void (*CTRDGi_EraseAgbFlashSectorAsync)(u16 secNo, CTRDG_TASK_FUNC callback);
+ u16 (*CTRDGi_PollingSR)(u16 phase, u8 *adr, u16 lastData);
+ const u16 (*maxtime);
+ CTRDGFlashType type;
+} CTRDGiFlashTypePlus;
+
+typedef enum
+{
+ CTRDG_BACKUP_TYPE_FLASH_512K,
+ CTRDG_BACKUP_TYPE_FLASH_1M,
+ CTRDG_BACKUP_TYPE_SRAM
+} CTRDGBackupType;
+
+extern const u16 (*ctrdgi_fl_maxtime);
+
+extern u16 (*CTRDGi_PollingSR)(u16 phase, u8 *adr, u16 lastData);
+extern const CTRDGFlashType *AgbFlash;
+extern u16 (*CTRDGi_WriteAgbFlashSector)(u16 secNo, u8 *src);
+extern u16 (*CTRDGi_EraseAgbFlashChip)(void);
+extern u16 (*CTRDGi_EraseAgbFlashSector)(u16 secNo);
+extern void (*CTRDGi_WriteAgbFlashSectorAsync)(u16 secNo, u8 *src, CTRDG_TASK_FUNC callback);
+extern void (*CTRDGi_EraseAgbFlashChipAsync)(CTRDG_TASK_FUNC callback);
+extern void (*CTRDGi_EraseAgbFlashSectorAsync)(u16 secNo, CTRDG_TASK_FUNC callback);
+
+u16 CTRDG_IdentifyAgbBackup(CTRDGBackupType type);
+
+#endif //POKEDIAMOND_CTRDG_BACKUP_H
diff --git a/arm9/lib/include/CTRDG_flash.h b/arm9/lib/include/CTRDG_flash.h
new file mode 100644
index 00000000..9a4aff41
--- /dev/null
+++ b/arm9/lib/include/CTRDG_flash.h
@@ -0,0 +1,25 @@
+#ifndef POKEDIAMOND_CTRDG_FLASH_H
+#define POKEDIAMOND_CTRDG_FLASH_H
+
+#include "nitro/types.h"
+#include "MI_exMemory.h"
+
+typedef struct CTRDGiFlashSectorTag
+{
+ u32 size;
+ u16 shift;
+ u16 count;
+ u16 top;
+ u8 reserved[2];
+} CTRDGiFlashSector;
+
+typedef struct CTRDGFlashTypeTag
+{
+ u32 romSize;
+ CTRDGiFlashSector sector;
+ MICartridgeRamCycle agbWait[2];
+ u16 makerID;
+ u16 deviceID;
+} CTRDGFlashType;
+
+#endif //POKEDIAMOND_CTRDG_FLASH_H
diff --git a/arm9/lib/include/CTRDG_task.h b/arm9/lib/include/CTRDG_task.h
new file mode 100644
index 00000000..2cf7a233
--- /dev/null
+++ b/arm9/lib/include/CTRDG_task.h
@@ -0,0 +1,25 @@
+#ifndef POKEDIAMOND_CTRDG_TASK_H
+#define POKEDIAMOND_CTRDG_TASK_H
+
+#include "nitro/types.h"
+
+struct CTRDGTaskInfo_tag;
+
+typedef u32 (*CTRDG_TASK_FUNC) (struct CTRDGTaskInfo_tag *);
+
+typedef struct CTRDGTaskInfo_tag
+{
+ CTRDG_TASK_FUNC task;
+ CTRDG_TASK_FUNC callback;
+ u32 result;
+ u8 *data;
+ u8 *adr;
+ u32 offset;
+ u32 size;
+ u8 *dst;
+ u16 sec_num;
+ u8 busy;
+ u8 param[1];
+} CTRDGTaskInfo;
+
+#endif //POKEDIAMOND_CTRDG_TASK_H
diff --git a/arm9/lib/include/MI_exMemory.h b/arm9/lib/include/MI_exMemory.h
index df46b008..aa90a73c 100644
--- a/arm9/lib/include/MI_exMemory.h
+++ b/arm9/lib/include/MI_exMemory.h
@@ -22,6 +22,14 @@ typedef enum
MI_CTRDG_ROMCYCLE2_4 = 1
} MICartridgeRomCycle2nd;
+typedef enum
+{
+ MI_CTRDG_RAMCYCLE_10 = 0,
+ MI_CTRDG_RAMCYCLE_8 = 1,
+ MI_CTRDG_RAMCYCLE_6 = 2,
+ MI_CTRDG_RAMCYCLE_18 = 3
+} MICartridgeRamCycle;
+
static inline void MIi_SetCardProcessor(MIProcessor proc)
{
reg_MI_EXMEMCNT =
@@ -54,4 +62,14 @@ static inline void MI_SetCartridgeRomCycle2nd(MICartridgeRomCycle2nd c2)
reg_MI_EXMEMCNT = (u16)((reg_MI_EXMEMCNT & ~0x10) | (c2 << 4));
}
+static inline void MI_SetCartridgeRamCycle(MICartridgeRamCycle c)
+{
+ reg_MI_EXMEMCNT = (u16)((reg_MI_EXMEMCNT & ~3) | (c << 0));
+}
+
+static inline MICartridgeRamCycle MI_GetCartridgeRamCycle(void)
+{
+ return (MICartridgeRamCycle)((reg_MI_EXMEMCNT & 3) >> 0);
+}
+
#endif //POKEDIAMOND_MI_EXMEMORY_H
diff --git a/arm9/lib/src/CTRDG_backup.c b/arm9/lib/src/CTRDG_backup.c
new file mode 100644
index 00000000..dc1a3f4b
--- /dev/null
+++ b/arm9/lib/src/CTRDG_backup.c
@@ -0,0 +1,94 @@
+#include "CTRDG_backup.h"
+#include "function_target.h"
+#include "OS_spinLock.h"
+
+extern u16 ctrdgi_flash_lock_id;
+extern u16 ctrdgi_sram_lock_id;
+
+extern u16 CTRDGi_ReadFlashID(void);
+
+extern const CTRDGiFlashTypePlus defaultFlash1M;
+extern const CTRDGiFlashTypePlus MX29L010;
+extern const CTRDGiFlashTypePlus LE26FV10N1TS_10;
+
+extern const CTRDGiFlashTypePlus defaultFlash512;
+extern const CTRDGiFlashTypePlus LE39FW512;
+extern const CTRDGiFlashTypePlus AT29LV512_lib;
+extern const CTRDGiFlashTypePlus MN63F805MNP;
+
+static const CTRDGiFlashTypePlus *const flash1M_list[] = {
+ &MX29L010,
+ &LE26FV10N1TS_10,
+ &defaultFlash1M
+};
+
+static const CTRDGiFlashTypePlus *const flash512_list[] = {
+ &LE39FW512,
+ &AT29LV512_lib,
+ &MN63F805MNP,
+ &defaultFlash512
+};
+
+static const u16 readidtime[] = {
+ 20
+};
+
+ARM_FUNC u16 CTRDG_IdentifyAgbBackup(CTRDGBackupType type)
+{
+ u16 result = 1;
+ u16 flashID;
+ const CTRDGiFlashTypePlus *const *flp;
+ MICartridgeRamCycle ram_cycle;
+
+ if (type == CTRDG_BACKUP_TYPE_FLASH_512K || type == CTRDG_BACKUP_TYPE_FLASH_1M)
+ {
+ ctrdgi_flash_lock_id = (u16)OS_GetLockID();
+
+ (void)OS_LockCartridge(ctrdgi_flash_lock_id);
+
+ ram_cycle = MI_GetCartridgeRamCycle();
+ MI_SetCartridgeRamCycle(MI_CTRDG_RAMCYCLE_18);
+
+ ctrdgi_fl_maxtime = readidtime;
+ flashID = CTRDGi_ReadFlashID();
+
+ if (type == CTRDG_BACKUP_TYPE_FLASH_512K)
+ {
+ flp = flash512_list;
+ }
+
+ if (type == CTRDG_BACKUP_TYPE_FLASH_1M)
+ {
+ flp = flash1M_list;
+ }
+
+ MI_SetCartridgeRamCycle(ram_cycle);
+ (void)OS_UnlockCartridge(ctrdgi_flash_lock_id);
+
+ result = 1;
+ while ((*flp)->type.makerID != 0)
+ {
+ if ((flashID & 0xff) == *(u16 *)&((*flp)->type.makerID))
+ {
+ result = 0;
+ break;
+ }
+ flp++;
+ }
+ CTRDGi_WriteAgbFlashSector = (*flp)->CTRDGi_WriteAgbFlashSector;
+ CTRDGi_EraseAgbFlashChip = (*flp)->CTRDGi_EraseAgbFlashChip;
+ CTRDGi_EraseAgbFlashSector = (*flp)->CTRDGi_EraseAgbFlashSector;
+ CTRDGi_WriteAgbFlashSectorAsync = (*flp)->CTRDGi_WriteAgbFlashSectorAsync;
+ CTRDGi_EraseAgbFlashChipAsync = (*flp)->CTRDGi_EraseAgbFlashChipAsync;
+ CTRDGi_EraseAgbFlashSectorAsync = (*flp)->CTRDGi_EraseAgbFlashSectorAsync;
+ CTRDGi_PollingSR = (*flp)->CTRDGi_PollingSR;
+ ctrdgi_fl_maxtime = (*flp)->maxtime;
+ AgbFlash = &(*flp)->type;
+ }
+ else if (type == CTRDG_BACKUP_TYPE_SRAM)
+ {
+ ctrdgi_sram_lock_id = (u16)OS_GetLockID();
+ result = 0;
+ }
+ return result;
+}