diff options
author | Revo <projectrevotpp@hotmail.com> | 2021-02-25 12:09:09 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-25 12:09:09 -0500 |
commit | 75dc81c75dc1dc86053303cdae9decdb2f05557d (patch) | |
tree | 002fb738596c50bb67a6dc5204340d2436f81041 | |
parent | ab4e396b1dac3f2a3a3379f9aa3de4de16fd26e9 (diff) | |
parent | 8fdf73a9f02bf896d4620341f47436160cc008ba (diff) |
Merge pull request #320 from red031000/master
partial CTRDG_flash_AT29LV512.o decomp
-rw-r--r-- | .github/workflows/build.yml | 2 | ||||
-rw-r--r-- | arm9/arm9.lsf | 1 | ||||
-rw-r--r-- | arm9/asm/CTRDG_flash_AT29LV512_asm.s (renamed from arm9/asm/CTRDG_flash_AT29LV512.s) | 192 | ||||
-rw-r--r-- | arm9/asm/CTRDG_flash_LE39FW512.s | 16 | ||||
-rw-r--r-- | arm9/asm/CTRDG_flash_MX29L010.s | 18 | ||||
-rw-r--r-- | arm9/asm/CTRDG_flash_common.s | 10 | ||||
-rw-r--r-- | arm9/lib/include/CTRDG_backup.h | 4 | ||||
-rw-r--r-- | arm9/lib/include/CTRDG_flash.h | 2 | ||||
-rw-r--r-- | arm9/lib/include/CTRDG_flash_AT29LV512.h | 10 | ||||
-rw-r--r-- | arm9/lib/include/OS_interrupt.h | 7 | ||||
-rw-r--r-- | arm9/lib/src/CTRDG_flash_AT29LV512.c | 143 | ||||
-rw-r--r-- | arm9/modules/21/include/mod21_02254854.h | 8 | ||||
-rw-r--r-- | arm9/modules/21/src/mod21_02254854.c | 22 |
13 files changed, 212 insertions, 223 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ba976726..22fd0531 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,7 @@ jobs: - name: Update and Install Software run: | sudo apt update - sudo apt -y upgrade + sudo apt -y --fix-missing upgrade sudo apt -y install g++-8-multilib linux-libc-dev binutils-arm-none-eabi sudo dpkg --add-architecture i386 wget -qO - https://dl.winehq.org/wine-builds/winehq.key | sudo apt-key add - diff --git a/arm9/arm9.lsf b/arm9/arm9.lsf index fac2074d..6bbff67c 100644 --- a/arm9/arm9.lsf +++ b/arm9/arm9.lsf @@ -456,6 +456,7 @@ Static arm9 Object CTRDG_proc.o Object CTRDG_backup.o Object CTRDG_flash_common.o + Object CTRDG_flash_AT29LV512_asm.o Object CTRDG_flash_AT29LV512.o Object CTRDG_flash_LE26FV10N1TS-10.o Object CTRDG_flash_LE39FW512.o diff --git a/arm9/asm/CTRDG_flash_AT29LV512.s b/arm9/asm/CTRDG_flash_AT29LV512_asm.s index 24b2e0f2..7cfa90af 100644 --- a/arm9/asm/CTRDG_flash_AT29LV512.s +++ b/arm9/asm/CTRDG_flash_AT29LV512_asm.s @@ -5,40 +5,11 @@ .extern AgbFlash .extern CTRDGi_PollingSR .extern ctrdgi_flash_lock_id - .extern UNK_021D6B38 .extern UNK_021D6B08 - - .section .rodata - - .global atMaxTime -atMaxTime: ; 0x02104004 - .short 10, 40, 0, 40 - - .global AT29LV512_lib -AT29LV512_lib: ; 0x0210400C - .word CTRDGi_WriteFlash4KBAT - .word CTRDGi_EraseFlashChipAT - .word CTRDGi_EraseFlash4KBAT - .word CTRDGi_WriteFlash4KBAsyncAT - .word CTRDGi_EraseFlashChipAsyncAT - .word CTRDGi_EraseFlash4KBAsyncAT - .word CTRDGi_PollingSR512kCOMMON - .word atMaxTime - .byte 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x0C, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x3D, 0x00 - - .global AT29LV512_org -AT29LV512_org: ; 0x02104048 - .word CTRDGi_WriteFlashSectorAT - .word CTRDGi_EraseFlashChipAT - .word CTRDGi_EraseFlashSectorAT - .word CTRDGi_WriteFlashSectorAsyncAT - .word CTRDGi_EraseFlashChipAsyncAT - .word CTRDGi_EraseFlashSectorAsyncAT - .word CTRDGi_PollingSR512kCOMMON - .word atMaxTime - .byte 0x00, 0x00, 0x01, 0x00, 0x80, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00 - .byte 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x3D, 0x00 + .extern CTRDGi_EraseFlashChipCoreAT + .extern CTRDGi_EraseFlashSectorCoreAT + .extern AT29LV512_org + .extern AT29LV512_lib .text @@ -385,158 +356,3 @@ _020DCA18: bx lr .balign 4 _020DCA54: .word 0x000080FF - - arm_func_start CTRDGi_EraseFlashSectorCoreAT -CTRDGi_EraseFlashSectorCoreAT: ; 0x020DCA58 - stmdb sp!, {r4-r5,lr} - sub sp, sp, #0x24 - mov r5, r0 - ldmia r5!, {r0-r3} - add r4, sp, #0x0 - stmia r4!, {r0-r3} - ldmia r5!, {r0-r3} - stmia r4!, {r0-r3} - ldr r0, [r5, #0x0] - ldr r1, _020DCB80 ; =AT29LV512_org - str r0, [r4, #0x0] - ldr r0, _020DCB84 ; =ctrdgi_flash_lock_id - ldrh r2, [sp, #0x20] - ldrh r1, [r1, #0x28] - ldrh r0, [r0, #0x0] - mov r1, r2, lsl r1 - add r5, r1, #0xa000000 - bl OS_LockCartridge - ldr r4, _020DCB88 ; =0x04000204 - ldr r1, _020DCB8C ; =AgbFlash - ldrh r0, [r4, #0x0] - ldr r2, [r1, #0x0] - ldrh r1, [r4, #0x0] - ldr r2, [r2, #0x10] - ldr r3, _020DCB90 ; =0x04000208 - bic r1, r1, #0x3 - orr r1, r1, r2 - strh r1, [r4, #0x0] - ldrh r2, [r3, #0x0] - mov r1, #0x0 - ldr r4, _020DCB94 ; =0x0A005555 - strh r1, [r3, #0x0] - mov r3, #0xaa - strb r3, [r4, #0x0] - ldr r1, _020DCB98 ; =0x0A002AAA - mov r3, #0x55 - strb r3, [r1, #0x0] - mov r3, #0xa0 - strb r3, [r4, #0x0] - ldr r1, _020DCB80 ; =AT29LV512_org - and r4, r0, #0x3 - ldr r1, [r1, #0x24] - cmp r1, #0x0 - beq _020DCB18 - mov r0, #0xff -_020DCB0C: - strb r0, [r5], #0x1 - subs r1, r1, #0x1 - bne _020DCB0C -_020DCB18: - ldr ip, _020DCB90 ; =0x04000208 - ldr r3, _020DCB9C ; =CTRDGi_PollingSR - ldrh r0, [r12, #0x0] - sub r1, r5, #0x1 - strh r2, [r12, #0x0] - ldr r3, [r3, #0x0] - mov r0, #0x1 - mov r2, #0xff - blx r3 - ldr r2, _020DCB88 ; =0x04000204 - movs r5, r0 - ldrh r1, [r2, #0x0] - andne r0, r5, #0xff00 - orrne r0, r0, #0x2 - movne r0, r0, lsl #0x10 - bic r1, r1, #0x3 - movne r5, r0, lsr #0x10 - orr r1, r1, r4 - ldr r0, _020DCB84 ; =ctrdgi_flash_lock_id - strh r1, [r2, #0x0] - ldrh r0, [r0, #0x0] - bl OS_UnlockCartridge - mov r0, r5 - add sp, sp, #0x24 - ldmia sp!, {r4-r5,lr} - bx lr - .balign 4 -_020DCB80: .word AT29LV512_org -_020DCB84: .word ctrdgi_flash_lock_id -_020DCB88: .word 0x04000204 -_020DCB8C: .word AgbFlash -_020DCB90: .word 0x04000208 -_020DCB94: .word 0x0A005555 -_020DCB98: .word 0x0A002AAA -_020DCB9C: .word CTRDGi_PollingSR - - arm_func_start CTRDGi_EraseFlashChipCoreAT -CTRDGi_EraseFlashChipCoreAT: ; 0x020DCBA0 - stmdb sp!, {r4-r5,lr} - sub sp, sp, #0x4 - ldr r0, _020DCC7C ; =ctrdgi_flash_lock_id - ldrh r0, [r0, #0x0] - bl OS_LockCartridge - ldr r4, _020DCC80 ; =0x04000204 - ldr r0, _020DCC84 ; =AgbFlash - ldrh r3, [r4, #0x0] - ldr r0, [r0, #0x0] - ldrh r1, [r4, #0x0] - ldr r2, [r0, #0x10] - ldr r0, _020DCC88 ; =0x04000208 - bic r1, r1, #0x3 - orr r1, r1, r2 - strh r1, [r4, #0x0] - ldrh r4, [r0, #0x0] - mov r2, #0x0 - ldr r1, _020DCC8C ; =UNK_021D6B38 - strh r2, [r0, #0x0] - ldr lr, _020DCC90 ; =0x0A005555 - str r4, [r1, #0x0] - mov r5, #0xaa - ldr r4, _020DCC94 ; =0x0A002AAA - strb r5, [lr, #0x0] - mov r12, #0x55 - strb r12, [r4, #0x0] - mov r2, #0x80 - strb r2, [lr, #0x0] - strb r5, [lr, #0x0] - strb r12, [r4, #0x0] - mov r2, #0x10 - strb r2, [lr, #0x0] - ldrh r2, [r0, #0x0] - ldr r2, [r1, #0x0] - ldr r1, _020DCC98 ; =CTRDGi_PollingSR - strh r2, [r0, #0x0] - ldr r4, [r1, #0x0] - mov r0, #0x3 - mov r1, #0xa000000 - mov r2, #0xff - and r5, r3, #0x3 - blx r4 - ldr r3, _020DCC80 ; =0x04000204 - ldr r1, _020DCC7C ; =ctrdgi_flash_lock_id - ldrh r2, [r3, #0x0] - mov r4, r0 - bic r0, r2, #0x3 - orr r0, r0, r5 - strh r0, [r3, #0x0] - ldrh r0, [r1, #0x0] - bl OS_UnlockCartridge - mov r0, r4 - add sp, sp, #0x4 - ldmia sp!, {r4-r5,lr} - bx lr - .balign 4 -_020DCC7C: .word ctrdgi_flash_lock_id -_020DCC80: .word 0x04000204 -_020DCC84: .word AgbFlash -_020DCC88: .word 0x04000208 -_020DCC8C: .word UNK_021D6B38 -_020DCC90: .word 0x0A005555 -_020DCC94: .word 0x0A002AAA -_020DCC98: .word CTRDGi_PollingSR diff --git a/arm9/asm/CTRDG_flash_LE39FW512.s b/arm9/asm/CTRDG_flash_LE39FW512.s index 3228818d..26e714c0 100644 --- a/arm9/asm/CTRDG_flash_LE39FW512.s +++ b/arm9/asm/CTRDG_flash_LE39FW512.s @@ -5,7 +5,7 @@ .extern AgbFlash .extern CTRDGi_PollingSR .extern ctrdgi_flash_lock_id - .extern UNK_021D6B38 + .extern ctrdgi_backup_irq .extern UNK_021D6B08 .section .rodata @@ -266,7 +266,7 @@ _020DCF38: mov r2, #0x0 strh r1, [r7, #0x0] ldrh r3, [r9, #0x0] - ldr r1, _020DD034 ; =UNK_021D6B38 + ldr r1, _020DD034 ; =ctrdgi_backup_irq and r5, r0, #0x3 strh r2, [r9, #0x0] ldrh r0, [r7, #0x0] @@ -289,7 +289,7 @@ _020DCFA0: bne _020DCFA0 _020DCFD4: ldr r3, _020DD030 ; =0x04000208 - ldr r0, _020DD034 ; =UNK_021D6B38 + ldr r0, _020DD034 ; =ctrdgi_backup_irq ldrh r1, [r3, #0x0] ldr r0, [r0, #0x0] ldr r2, _020DD028 ; =0x04000204 @@ -313,7 +313,7 @@ _020DD024: .word ctrdgi_flash_lock_id _020DD028: .word 0x04000204 _020DD02C: .word UNK_021D6B08 _020DD030: .word 0x04000208 -_020DD034: .word UNK_021D6B38 +_020DD034: .word ctrdgi_backup_irq arm_func_start CTRDGi_ProgramFlashByteLE CTRDGi_ProgramFlashByteLE: ; 0x020DD038 @@ -378,7 +378,7 @@ CTRDGi_EraseFlashSectorCoreLE: ; 0x020DD098 ldrh r5, [r0, #0x0] ldrh r12, [r1, #0x8] mov r1, #0x0 - ldr r2, _020DD1CC ; =UNK_021D6B38 + ldr r2, _020DD1CC ; =ctrdgi_backup_irq strh r1, [r0, #0x0] mov r6, r4, lsl r12 ldr lr, _020DD1D0 ; =0x0A005555 @@ -423,7 +423,7 @@ _020DD1BC: .word ctrdgi_flash_lock_id _020DD1C0: .word 0x04000204 _020DD1C4: .word AgbFlash _020DD1C8: .word 0x04000208 -_020DD1CC: .word UNK_021D6B38 +_020DD1CC: .word ctrdgi_backup_irq _020DD1D0: .word 0x0A005555 _020DD1D4: .word 0x0A002AAA _020DD1D8: .word CTRDGi_PollingSR @@ -447,7 +447,7 @@ CTRDGi_EraseFlashChipCoreLE: ; 0x020DD1DC strh r1, [r4, #0x0] ldrh r4, [r0, #0x0] mov r2, #0x0 - ldr r1, _020DD2C8 ; =UNK_021D6B38 + ldr r1, _020DD2C8 ; =ctrdgi_backup_irq strh r2, [r0, #0x0] ldr lr, _020DD2CC ; =0x0A005555 str r4, [r1, #0x0] @@ -490,7 +490,7 @@ _020DD2B8: .word ctrdgi_flash_lock_id _020DD2BC: .word 0x04000204 _020DD2C0: .word AgbFlash _020DD2C4: .word 0x04000208 -_020DD2C8: .word UNK_021D6B38 +_020DD2C8: .word ctrdgi_backup_irq _020DD2CC: .word 0x0A005555 _020DD2D0: .word 0x0A002AAA _020DD2D4: .word CTRDGi_PollingSR diff --git a/arm9/asm/CTRDG_flash_MX29L010.s b/arm9/asm/CTRDG_flash_MX29L010.s index 7b4e1dc3..13de7bd7 100644 --- a/arm9/asm/CTRDG_flash_MX29L010.s +++ b/arm9/asm/CTRDG_flash_MX29L010.s @@ -5,7 +5,7 @@ .extern AgbFlash .extern CTRDGi_PollingSR .extern ctrdgi_flash_lock_id - .extern UNK_021D6B38 + .extern ctrdgi_backup_irq .extern UNK_021D6B08 .section .rodata @@ -184,7 +184,7 @@ CTRDGi_WriteFlashSectorCoreMX: ; 0x020DD3D0 mov r3, r5, lsl r3 strh r0, [r1, #0x0] ldrh r1, [r8, #0x0] - ldr r0, _020DD558 ; =UNK_021D6B38 + ldr r0, _020DD558 ; =ctrdgi_backup_irq add r5, r3, #0xa000000 str r2, [r0, #0x0] cmp r1, #0x0 @@ -205,7 +205,7 @@ _020DD4C8: bne _020DD4C8 _020DD4FC: ldr r3, _020DD554 ; =0x04000208 - ldr r0, _020DD558 ; =UNK_021D6B38 + ldr r0, _020DD558 ; =ctrdgi_backup_irq ldrh r1, [r3, #0x0] ldr r0, [r0, #0x0] ldr r2, _020DD54C ; =0x04000204 @@ -228,7 +228,7 @@ _020DD548: .word ctrdgi_flash_lock_id _020DD54C: .word 0x04000204 _020DD550: .word UNK_021D6B08 _020DD554: .word 0x04000208 -_020DD558: .word UNK_021D6B38 +_020DD558: .word ctrdgi_backup_irq arm_func_start CTRDGi_ProgramFlashByteMX CTRDGi_ProgramFlashByteMX: ; 0x020DD55C @@ -314,7 +314,7 @@ _020DD684: ldr r0, _020DD748 ; =AgbFlash ldrh r12, [r8, #0x0] ldr r0, [r0, #0x0] - ldr r3, _020DD75C ; =UNK_021D6B38 + ldr r3, _020DD75C ; =ctrdgi_backup_irq ldrh r1, [r0, #0x8] ldr r0, [sp, #0x8] ldr r2, [sp, #0xc] @@ -333,7 +333,7 @@ _020DD684: strb r6, [r3, #0x0] strb r4, [r1, #0x0] ldrh r3, [r8, #0x0] - ldr r3, _020DD75C ; =UNK_021D6B38 + ldr r3, _020DD75C ; =ctrdgi_backup_irq ldr r3, [r3, #0x0] strh r3, [r8, #0x0] ldr r3, _020DD768 ; =CTRDGi_PollingSR @@ -367,7 +367,7 @@ _020DD74C: .word 0x000080FF _020DD750: .word ctrdgi_flash_lock_id _020DD754: .word 0x04000204 _020DD758: .word 0x04000208 -_020DD75C: .word UNK_021D6B38 +_020DD75C: .word ctrdgi_backup_irq _020DD760: .word 0x0A005555 _020DD764: .word 0x0A002AAA _020DD768: .word CTRDGi_PollingSR @@ -391,7 +391,7 @@ CTRDGi_EraseFlashChipCoreMX: ; 0x020DD76C strh r1, [r4, #0x0] ldrh r4, [r0, #0x0] mov r2, #0x0 - ldr r1, _020DD858 ; =UNK_021D6B38 + ldr r1, _020DD858 ; =ctrdgi_backup_irq strh r2, [r0, #0x0] ldr lr, _020DD85C ; =0x0A005555 str r4, [r1, #0x0] @@ -434,7 +434,7 @@ _020DD848: .word ctrdgi_flash_lock_id _020DD84C: .word 0x04000204 _020DD850: .word AgbFlash _020DD854: .word 0x04000208 -_020DD858: .word UNK_021D6B38 +_020DD858: .word ctrdgi_backup_irq _020DD85C: .word 0x0A005555 _020DD860: .word 0x0A002AAA _020DD864: .word CTRDGi_PollingSR diff --git a/arm9/asm/CTRDG_flash_common.s b/arm9/asm/CTRDG_flash_common.s index 4c51608a..ed1dd88e 100644 --- a/arm9/asm/CTRDG_flash_common.s +++ b/arm9/asm/CTRDG_flash_common.s @@ -51,8 +51,8 @@ CTRDGi_EraseAgbFlashSectorAsync: ; 0x021D6B30 CTRDGi_EraseAgbFlashChip: ; 0x021D6B34 .space 0x4 - .global UNK_021D6B38 -UNK_021D6B38: ; 0x021D6B38 + .global ctrdgi_backup_irq +ctrdgi_backup_irq: ; 0x021D6B38 .space 0x4 .global UNK_021D6B3C @@ -493,7 +493,7 @@ CTRDGi_ReadFlashID: ; 0x020DC48C ldr r5, _020DC590 ; =0x04000208 mov r0, #0x0 ldrh r2, [r5, #0x0] - ldr r1, _020DC594 ; =UNK_021D6B38 + ldr r1, _020DC594 ; =ctrdgi_backup_irq ldr r4, _020DC598 ; =0x0A005555 strh r0, [r5, #0x0] str r2, [r1, #0x0] @@ -527,7 +527,7 @@ _020DC4FC: orr r4, r0, r4, lsr #0x10 ldrh r2, [r12, #0x0] mov r0, #0x0 - ldr r1, _020DC594 ; =UNK_021D6B38 + ldr r1, _020DC594 ; =ctrdgi_backup_irq strh r0, [r12, #0x0] ldr r5, _020DC598 ; =0x0A005555 str r2, [r1, #0x0] @@ -559,7 +559,7 @@ _020DC580: bx lr .balign 4 _020DC590: .word 0x04000208 -_020DC594: .word UNK_021D6B38 +_020DC594: .word ctrdgi_backup_irq _020DC598: .word 0x0A005555 _020DC59C: .word 0x0A002AAA _020DC5A0: .word UNK_021D6B10 diff --git a/arm9/lib/include/CTRDG_backup.h b/arm9/lib/include/CTRDG_backup.h index d248b7a1..272744ad 100644 --- a/arm9/lib/include/CTRDG_backup.h +++ b/arm9/lib/include/CTRDG_backup.h @@ -5,6 +5,10 @@ #include "CTRDG_flash.h" #include "CTRDG_task.h" +#define CTRDG_BACKUP_PHASE_PROGRAM 0x0001 +#define CTRDG_BACKUP_PHASE_SECTOR_ERASE 0x0002 +#define CTRDG_BACKUP_PHASE_CHIP_ERASE 0x0003 + typedef struct CTRDGiFlashTypePlusTag { u16 (*CTRDGi_WriteAgbFlashSector)(u16 secNo, u8 *src); diff --git a/arm9/lib/include/CTRDG_flash.h b/arm9/lib/include/CTRDG_flash.h index 9a4aff41..aa02d951 100644 --- a/arm9/lib/include/CTRDG_flash.h +++ b/arm9/lib/include/CTRDG_flash.h @@ -4,6 +4,8 @@ #include "nitro/types.h" #include "MI_exMemory.h" +#define CTRDG_AGB_FLASH_ADR 0x0A000000 + typedef struct CTRDGiFlashSectorTag { u32 size; diff --git a/arm9/lib/include/CTRDG_flash_AT29LV512.h b/arm9/lib/include/CTRDG_flash_AT29LV512.h new file mode 100644 index 00000000..908dd6cf --- /dev/null +++ b/arm9/lib/include/CTRDG_flash_AT29LV512.h @@ -0,0 +1,10 @@ +#ifndef POKEDIAMOND_CTRDG_FLASH_AT29LV512_H +#define POKEDIAMOND_CTRDG_FLASH_AT29LV512_H + +#include "nitro/types.h" +#include "CTRDG_task.h" + +u32 CTRDGi_EraseFlashChipCoreAT(CTRDGTaskInfo *arg); +u32 CTRDGi_EraseFlashSectorCoreAT(CTRDGTaskInfo *arg); + +#endif //POKEDIAMOND_CTRDG_FLASH_AT29LV512_H diff --git a/arm9/lib/include/OS_interrupt.h b/arm9/lib/include/OS_interrupt.h index c3812128..d063b817 100644 --- a/arm9/lib/include/OS_interrupt.h +++ b/arm9/lib/include/OS_interrupt.h @@ -43,6 +43,13 @@ static inline BOOL OS_EnableIrq(void) return (BOOL)prep; } +static inline BOOL OS_RestoreIrq(BOOL enable) +{ + u16 prep = reg_OS_IME; + reg_OS_IME = (u16)enable; + return (BOOL)prep; +} + static inline OSIrqMask OS_GetIrqMask(void) { return reg_OS_IE; diff --git a/arm9/lib/src/CTRDG_flash_AT29LV512.c b/arm9/lib/src/CTRDG_flash_AT29LV512.c new file mode 100644 index 00000000..8cd90c31 --- /dev/null +++ b/arm9/lib/src/CTRDG_flash_AT29LV512.c @@ -0,0 +1,143 @@ +#include "CTRDG_flash_AT29LV512.h" +#include "function_target.h" +#include "CTRDG_backup.h" +#include "CTRDG_flash.h" +#include "MI_exMemory.h" +#include "OS_interrupt.h" +#include "OS_spinLock.h" + +#define CTRDG_BACKUP_COM_ADR1 (CTRDG_AGB_FLASH_ADR+0x00005555) +#define CTRDG_BACKUP_COM_ADR2 (CTRDG_AGB_FLASH_ADR+0x00002aaa) + +extern u16 ctrdgi_flash_lock_id; +extern BOOL ctrdgi_backup_irq; + +extern u16 CTRDGi_PollingSR512kCOMMON(u16 phase, u8 *adr, u16 lastData); + +extern u16 CTRDGi_EraseFlashChipAT(void); +extern u16 CTRDGi_EraseFlashSectorAT(u16 p_secNo); +extern u16 CTRDGi_EraseFlash4KBAT(u16 l_secNo); +extern u16 CTRDGi_WriteFlashSectorAT(u16 p_secNo, u8 *src); +extern u16 CTRDGi_WriteFlash4KBAT(u16 l_secNo, u8 *src); + +extern void CTRDGi_EraseFlashChipAsyncAT(CTRDG_TASK_FUNC callback); +extern void CTRDGi_EraseFlash4KBAsyncAT(u16 secNo, CTRDG_TASK_FUNC callback); +extern void CTRDGi_WriteFlash4KBAsyncAT(u16 secNo, u8 *src, CTRDG_TASK_FUNC callback); +extern void CTRDGi_EraseFlashSectorAsyncAT(u16 secNo, CTRDG_TASK_FUNC callback); +extern void CTRDGi_WriteFlashSectorAsyncAT(u16 secNo, u8 *src, CTRDG_TASK_FUNC callback); + +static const u16 atMaxTime[] = { + 10, 40, 0, 40 +}; + +const CTRDGiFlashTypePlus AT29LV512_lib = { + CTRDGi_WriteFlash4KBAT, + CTRDGi_EraseFlashChipAT, + CTRDGi_EraseFlash4KBAT, + CTRDGi_WriteFlash4KBAsyncAT, + CTRDGi_EraseFlashChipAsyncAT, + CTRDGi_EraseFlash4KBAsyncAT, + CTRDGi_PollingSR512kCOMMON, + atMaxTime, + { + 0x00010000, //ROM size + {0x00001000, 12, 16, 0}, //sector + {MI_CTRDG_RAMCYCLE_18, MI_CTRDG_RAMCYCLE_18}, //read cycle and write cycle + 0x1f, //maker ID + 0x3d, //device ID + } +}; + +const CTRDGiFlashTypePlus AT29LV512_org = { + CTRDGi_WriteFlashSectorAT, + CTRDGi_EraseFlashChipAT, + CTRDGi_EraseFlashSectorAT, + CTRDGi_WriteFlashSectorAsyncAT, + CTRDGi_EraseFlashChipAsyncAT, + CTRDGi_EraseFlashSectorAsyncAT, + CTRDGi_PollingSR512kCOMMON, + atMaxTime, + { + 0x00010000, //ROM size + {0x00000080, 7, 512, 0}, //sector + {MI_CTRDG_RAMCYCLE_18, MI_CTRDG_RAMCYCLE_18}, //read cycle and write cycle + 0x1f, //maker ID + 0x3d, //device ID + } +}; + +ARM_FUNC u32 CTRDGi_EraseFlashChipCoreAT(CTRDGTaskInfo *arg) +{ + MICartridgeRamCycle ram_cycle; + u32 result; + (void)arg; + + (void)OS_LockCartridge(ctrdgi_flash_lock_id); + + ram_cycle = MI_GetCartridgeRamCycle(); + MI_SetCartridgeRamCycle(AgbFlash->agbWait[0]); + + ctrdgi_backup_irq = OS_DisableIrq(); + + *(vu8 *)CTRDG_BACKUP_COM_ADR1 = 0xaa; + *(vu8 *)CTRDG_BACKUP_COM_ADR2 = 0x55; + *(vu8 *)CTRDG_BACKUP_COM_ADR1 = 0x80; + *(vu8 *)CTRDG_BACKUP_COM_ADR1 = 0xaa; + *(vu8 *)CTRDG_BACKUP_COM_ADR2 = 0x55; + *(vu8 *)CTRDG_BACKUP_COM_ADR1 = 0x10; + + (void)OS_RestoreIrq(ctrdgi_backup_irq); + + result = CTRDGi_PollingSR(CTRDG_BACKUP_PHASE_CHIP_ERASE, (u8 *)CTRDG_AGB_FLASH_ADR, 0xff); + + MI_SetCartridgeRamCycle(ram_cycle); + + (void)OS_UnlockCartridge(ctrdgi_flash_lock_id); + + return result; +} + +ARM_FUNC u32 CTRDGi_EraseFlashSectorCoreAT(CTRDGTaskInfo *arg) +{ + u32 i; + u8 *dst; + BOOL shlet_ime; + MICartridgeRamCycle ram_cycle; + u32 result; + CTRDGTaskInfo p = *arg; + u16 p_secNo = p.sec_num; + + dst = (u8 *)(CTRDG_AGB_FLASH_ADR + (p_secNo << AT29LV512_org.type.sector.shift)); + + (void)OS_LockCartridge(ctrdgi_flash_lock_id); + + ram_cycle = MI_GetCartridgeRamCycle(); + MI_SetCartridgeRamCycle(AgbFlash->agbWait[0]); + + shlet_ime = OS_DisableIrq(); + + *(vu8 *)CTRDG_BACKUP_COM_ADR1 = 0xaa; + *(vu8 *)CTRDG_BACKUP_COM_ADR2 = 0x55; + *(vu8 *)CTRDG_BACKUP_COM_ADR1 = 0xa0; + + for (i = AT29LV512_org.type.sector.size; i > 0; i--) + { + *dst++ = 0xff; + } + dst--; + + (void)OS_RestoreIrq(shlet_ime); + + result = CTRDGi_PollingSR(CTRDG_BACKUP_PHASE_PROGRAM, dst, 0xff); + + if (result) + { + result = (u16)((result & 0xff00) | CTRDG_BACKUP_PHASE_SECTOR_ERASE); + } + + MI_SetCartridgeRamCycle(ram_cycle); + + (void)OS_UnlockCartridge(ctrdgi_flash_lock_id); + + return result; +} diff --git a/arm9/modules/21/include/mod21_02254854.h b/arm9/modules/21/include/mod21_02254854.h index 26501f35..cc243568 100644 --- a/arm9/modules/21/include/mod21_02254854.h +++ b/arm9/modules/21/include/mod21_02254854.h @@ -4,12 +4,18 @@ #include "nitro/types.h" #include "mod21_02254A6C.h" +typedef struct Time +{ + u32 hour; + u32 minute; +} Time; + typedef struct UnkStruct02254854 { u8 bytearray[8]; u8 padding0[8]; BOOL Unk10; - u32 Unk14[2]; + Time time; u8 padding1[4]; u32 Unk20; void *Unk24; diff --git a/arm9/modules/21/src/mod21_02254854.c b/arm9/modules/21/src/mod21_02254854.c index fe285936..a9a7599d 100644 --- a/arm9/modules/21/src/mod21_02254854.c +++ b/arm9/modules/21/src/mod21_02254854.c @@ -3,7 +3,7 @@ #include "unk_0200CA44.h" #include "mod21_02254854.h" -extern void GF_RTC_CopyTime(u32 *param0); +extern void GF_RTC_CopyTime(Time *param0); u8 const MOD21_02254D80[] = { 0x10, 0xAF, 0x10, 0xCF }; extern BOOL MOD20_02254130(void *param0, BOOL param1, void *param2, UnkStruct02254854 *param3, u32 param4); @@ -42,7 +42,7 @@ THUMB_FUNC BOOL MOD21_02254854(UnkStruct02254854 **param0, u32 param1, u32 param THUMB_FUNC BOOL MOD21_0225489C(UnkStruct02254854 *param0, u32 param1, u32 param2, u32 param3) { #pragma unused (param2, param3) //not sure, please check - if (MOD21_02254A6C((UnkStruct02254A6C *)¶m0->Unk24, param0->Unk14)) //todo fix + if (MOD21_02254A6C((UnkStruct02254A6C *)¶m0->Unk24, ¶m0->time)) //todo fix { param0->bytearray[0] = 0; param0->bytearray[1] = 0; @@ -50,16 +50,16 @@ THUMB_FUNC BOOL MOD21_0225489C(UnkStruct02254854 *param0, u32 param1, u32 param2 param0->bytearray[3] = 1; param0->bytearray[6] = 0; param0->Unk20 = 0; - GF_RTC_CopyTime(param0->Unk14); - if (param0->Unk14[0] >= 0x18) + GF_RTC_CopyTime(¶m0->time); + if (param0->time.hour >= 0x18) { - param0->Unk14[0] = param0->Unk14[0] % 0x18; + param0->time.hour = param0->time.hour % 0x18; } - if (param0->Unk14[1] >= 0x3c) + if (param0->time.minute >= 0x3c) { - param0->Unk14[0] = param0->Unk14[0] % 0x3c; + param0->time.hour = param0->time.hour % 0x3c; } - param0->bytearray[5] = (u8)param0->Unk14[1]; + param0->bytearray[5] = (u8)param0->time.minute; param0->Unk10 = MOD20_02254130((void *)MOD21_02254D80, TRUE, MOD21_02254974, param0, 8); if (param0->Unk10 == FALSE) { @@ -168,9 +168,9 @@ THUMB_FUNC BOOL MOD21_022549E4(UnkStruct02254854 * param0) } if (MOD21_02254B34(param0->Unk24, 1)) { - param0->bytearray[5] = (u8)param0->Unk14[1]; - GF_RTC_CopyTime(param0->Unk14); - if (param0->bytearray[5] != param0->Unk14[1]) + param0->bytearray[5] = (u8)param0->time.minute; + GF_RTC_CopyTime(¶m0->time); + if (param0->bytearray[5] != param0->time.minute) { MOD21_02254B10(param0->Unk24, 1); } |