diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2020-05-07 19:55:15 -0400 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2020-05-07 19:55:15 -0400 |
commit | ab5676fcf0a728374d5495c1980f1e2459d0ba4e (patch) | |
tree | bf1eab8ad536cd34027d7c25145b362c35339516 /arm9 | |
parent | 994cfcbc9a1e42043b25ae3ab6471b8ecbd55ff1 (diff) |
FS_command.c
Diffstat (limited to 'arm9')
-rw-r--r-- | arm9/asm/FS_command.s | 140 | ||||
-rw-r--r-- | arm9/data/rom2_2.s | 6 | ||||
-rw-r--r-- | arm9/data/rom2_3.s | 3 | ||||
-rw-r--r-- | arm9/lib/include/FS_archive.h | 5 | ||||
-rw-r--r-- | arm9/lib/include/FS_command.h | 2 | ||||
-rw-r--r-- | arm9/lib/include/FSi_util.h | 7 | ||||
-rw-r--r-- | arm9/lib/src/FS_command.c | 75 |
7 files changed, 96 insertions, 142 deletions
diff --git a/arm9/asm/FS_command.s b/arm9/asm/FS_command.s deleted file mode 100644 index 0c2ec755..00000000 --- a/arm9/asm/FS_command.s +++ /dev/null @@ -1,140 +0,0 @@ - .include "asm/macros.inc" - .include "global.inc" - .section .text - - arm_func_start FSi_TranslateCommand -FSi_TranslateCommand: - stmdb sp!, {r4-r8,lr} - mov r8, r0 - ldr r0, [r8, #0xc] - mov r7, r1 - mov r1, #0x1 - ldr r5, [r8, #0x8] - mov r4, r1, lsl r7 - ands r0, r0, #0x4 - moveq r1, #0x0 - cmp r1, #0x0 - ldrne r0, [r5, #0x1c] - orrne r0, r0, #0x200 - strne r0, [r5, #0x1c] - ldreq r0, [r5, #0x1c] - orreq r0, r0, #0x100 - streq r0, [r5, #0x1c] - ldr r0, [r5, #0x58] - ands r0, r0, r4 - beq _020CFFE4 - ldr r2, [r5, #0x54] - mov r0, r8 - mov r1, r7 - blx r2 - mov r6, r0 - cmp r6, #0x8 - addls pc, pc, r6, lsl #0x2 - b _020CFFE8 -_020CFFA0: - b _020CFFC4 - b _020CFFC4 - b _020CFFE8 - b _020CFFE8 - b _020CFFC4 - b _020CFFE8 - b _020CFFE8 - b _020CFFE8 - b _020CFFCC -_020CFFC4: - str r6, [r8, #0x14] - b _020CFFE8 -_020CFFCC: - ldr r1, [r5, #0x58] - mvn r0, r4 - and r0, r1, r0 - str r0, [r5, #0x58] - mov r6, #0x7 - b _020CFFE8 -_020CFFE4: - mov r6, #0x7 -_020CFFE8: - cmp r6, #0x7 - bne _020D0004 - ldr r1, _020D00AC ; =0x02103F80 - mov r0, r8 - ldr r1, [r1, r7, lsl #0x2] - blx r1 - mov r6, r0 -_020D0004: - cmp r6, #0x6 - bne _020D0060 - ldr r0, [r8, #0xc] - ands r0, r0, #0x4 - movne r0, #0x1 - moveq r0, #0x0 - cmp r0, #0x0 - beq _020D00A0 - bl OS_DisableInterrupts - ldr r1, [r5, #0x1c] - mov r4, r0 - ands r0, r1, #0x200 - beq _020D0050 - add r6, r5, #0xc -_020D003C: - mov r0, r6 - bl OS_SleepThread - ldr r0, [r5, #0x1c] - ands r0, r0, #0x200 - bne _020D003C -_020D0050: - mov r0, r4 - ldr r6, [r8, #0x14] - bl OS_RestoreInterrupts - b _020D00A0 -_020D0060: - ldr r0, [r8, #0xc] - ands r0, r0, #0x4 - movne r0, #0x1 - moveq r0, #0x0 - cmp r0, #0x0 - ldrne r0, [r5, #0x1c] - bicne r0, r0, #0x200 - strne r0, [r5, #0x1c] - strne r6, [r8, #0x14] - bne _020D00A0 - ldr r1, [r5, #0x1c] - mov r0, r8 - bic r2, r1, #0x100 - mov r1, r6 - str r2, [r5, #0x1c] - bl FSi_ReleaseCommand -_020D00A0: - mov r0, r6 - ldmia sp!, {r4-r8,lr} - bx lr - .balign 4 -_020D00AC: .word 0x02103F80 - - arm_func_start FSi_ReleaseCommand -FSi_ReleaseCommand: - stmdb sp!, {r4-r6,lr} - mov r6, r0 - mov r5, r1 - bl OS_DisableInterrupts - ldr r1, [r6, #0x0] - mov r4, r0 - ldr r0, [r6, #0x4] - cmp r1, #0x0 - strne r0, [r1, #0x4] - cmp r0, #0x0 - strne r1, [r0, #0x0] - mov r0, #0x0 - str r0, [r6, #0x0] - ldr r1, [r6, #0x0] - add r0, r6, #0x18 - str r1, [r6, #0x4] - ldr r1, [r6, #0xc] - bic r1, r1, #0x4f - str r1, [r6, #0xc] - str r5, [r6, #0x14] - bl OS_WakeupThread - mov r0, r4 - bl OS_RestoreInterrupts - ldmia sp!, {r4-r6,lr} - bx lr diff --git a/arm9/data/rom2_2.s b/arm9/data/rom2_2.s index ee7cadd3..9881b0bd 100644 --- a/arm9/data/rom2_2.s +++ b/arm9/data/rom2_2.s @@ -731,4 +731,8 @@ gScriptCmdTable: ; 0x020F355C .word FUN_0203AF84 .word FUN_0203AFA4 -.incbin "baserom.nds", 0xF80A0, 0x12790 + .incbin "baserom.nds", 0xF80A0, 0xFEE0 + + .global fsi_default_command +fsi_default_command: ; 0x02103F80 + .incbin "baserom.nds", 0x107F80, 0x28b0 diff --git a/arm9/data/rom2_3.s b/arm9/data/rom2_3.s index 43bd3cf2..14ef2fce 100644 --- a/arm9/data/rom2_3.s +++ b/arm9/data/rom2_3.s @@ -5,4 +5,5 @@ .section .data - .incbin "baserom.nds", 0x10a834, 0x76c
\ No newline at end of file + /* 0x02106834 */ + .incbin "baserom.nds", 0x10a834, 0x76c
\ No newline at end of file diff --git a/arm9/lib/include/FS_archive.h b/arm9/lib/include/FS_archive.h index d7c2a785..3bbbbff7 100644 --- a/arm9/lib/include/FS_archive.h +++ b/arm9/lib/include/FS_archive.h @@ -175,6 +175,11 @@ static inline BOOL FSi_IsArchiveAsync(volatile const FSArchive * p_arc) return (p_arc->flag & FS_ARCHIVE_FLAG_IS_ASYNC) != 0; } +static inline BOOL FSi_IsArchiveSync(volatile const FSArchive * p_arc) +{ + return (p_arc->flag & FS_ARCHIVE_FLAG_IS_SYNC) != 0; +} + static inline BOOL FS_IsArchiveTableLoaded(volatile const FSArchive * p_arc) { return (p_arc->flag & FS_ARCHIVE_FLAG_TABLE_LOAD) ? TRUE : FALSE; diff --git a/arm9/lib/include/FS_command.h b/arm9/lib/include/FS_command.h index db878f3f..b5e73bcf 100644 --- a/arm9/lib/include/FS_command.h +++ b/arm9/lib/include/FS_command.h @@ -3,6 +3,8 @@ #include "FS_file.h" +extern FSResult (*const fsi_default_command[])(FSFile *); + void FSi_ReleaseCommand(FSFile * file, FSResult signal); FSResult FSi_TranslateCommand(FSFile * file, FSCommandType command); diff --git a/arm9/lib/include/FSi_util.h b/arm9/lib/include/FSi_util.h index 1012df13..1f6faf6f 100644 --- a/arm9/lib/include/FSi_util.h +++ b/arm9/lib/include/FSi_util.h @@ -20,6 +20,13 @@ static inline void FSi_CutFromListCore(FSFileLink *trg) nx->link.prev = pr; } +static inline void FSi_CutFromList(FSFile *elem) +{ + FSFileLink *const trg = &elem->link; + FSi_CutFromListCore(trg); + trg->next = trg->prev = NULL; +} + static inline void FSi_AppendToList(FSFile *elem, FSFile *list) { FSFileLink *const trg = &elem->link; diff --git a/arm9/lib/src/FS_command.c b/arm9/lib/src/FS_command.c new file mode 100644 index 00000000..bc7839d8 --- /dev/null +++ b/arm9/lib/src/FS_command.c @@ -0,0 +1,75 @@ +#include "FS_file.h" +#include "FS_archive.h" +#include "FSi_util.h" +#include "FS_command.h" + +void FSi_ReleaseCommand(FSFile * p_file, FSResult ret) +{ + OSIntrMode bak_psr = OS_DisableInterrupts(); + FSi_CutFromList(p_file); + p_file->stat &= ~(FS_FILE_STATUS_CANCEL | FS_FILE_STATUS_BUSY | FS_FILE_STATUS_SYNC | FS_FILE_STATUS_ASYNC | FS_FILE_STATUS_OPERATING); + p_file->error = ret; + OS_WakeupThread(p_file->queue); + OS_RestoreInterrupts(bak_psr); +} + +FSResult FSi_TranslateCommand(FSFile *p_file, FSCommandType command) +{ + FSResult ret; + + FSArchive *const p_arc = p_file->arc; + const int bit = (1 << command); + + if (FS_IsFileSyncMode(p_file)) + p_arc->flag |= FS_ARCHIVE_FLAG_IS_SYNC; + else + p_arc->flag |= FS_ARCHIVE_FLAG_IS_ASYNC; + + if ((p_arc->proc_flag & bit) != 0) + { + switch (ret = (*p_arc->proc) (p_file, command)) + { + case FS_RESULT_SUCCESS: + case FS_RESULT_FAILURE: + case FS_RESULT_UNSUPPORTED: + p_file->error = ret; + break; + case FS_RESULT_PROC_ASYNC: + break; + case FS_RESULT_PROC_UNKNOWN: + ret = FS_RESULT_PROC_DEFAULT; + p_arc->proc_flag &= ~bit; + break; + } + } + else + { + ret = FS_RESULT_PROC_DEFAULT; + } + if (ret == FS_RESULT_PROC_DEFAULT) + { + ret = (*fsi_default_command[command]) (p_file); + } + if (ret == FS_RESULT_PROC_ASYNC) + { + if (FS_IsFileSyncMode(p_file)) + { + OSIntrMode bak_psr = OS_DisableInterrupts(); + while (FSi_IsArchiveSync(p_arc)) + OS_SleepThread(&p_arc->sync_q); + ret = p_file->error; + OS_RestoreInterrupts(bak_psr); + } + } + else if (!FS_IsFileSyncMode(p_file)) + { + p_arc->flag &= ~FS_ARCHIVE_FLAG_IS_ASYNC; + FSi_ReleaseCommand(p_file, ret); + } + else + { + p_arc->flag &= ~FS_ARCHIVE_FLAG_IS_SYNC; + p_file->error = ret; + } + return ret; +} |