FS_command_default through FSi_WriteFileCommand

This commit is contained in:
PikalaxALT
2020-05-07 21:02:08 -04:00
parent ab5676fcf0
commit eb410178e4
6 changed files with 130 additions and 139 deletions

View File

@@ -113,6 +113,7 @@ SECTIONS {
#include "undefined_syms.txt"
.arm9 : {
SDK_STATIC_START = .;
SDK_STATIC_TEXT_START = .;
secure.o (.text)
crt0.o (.text)
crt0.o (.version)
@@ -202,6 +203,7 @@ SECTIONS {
PXI_init.o (.text)
PXI_fifo.o (.text)
FS_command.o (.text)
FS_command_default.asm.o (.text)
FS_command_default.o (.text)
FS_archive.o (.text)
FS_file.o (.text)
@@ -221,13 +223,18 @@ SECTIONS {
libc.o (.text)
/* MWCC library */
libmwcc.o (.text)
SDK_STATIC_TEXT_END = .;
/* Static data */
SDK_STATIC_DATA_START = .;
rom2.o (.data)
string_util.o (.data)
rom2_2.o (.data)
FS_rom.o (.data)
FS_command_default.o (.rodata)
rom2_3.o (.data)
FS_rom.o (.data)
rom2_4.o (.data)
SDK_STATIC_DATA_END = .;
SDK_STATIC_END = .;
SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START;
} > arm9

View File

@@ -1,6 +1,9 @@
.include "asm/macros.inc"
.include "global.inc"
.section .text
.extern FSi_StrNICmp
.extern FSi_ReadTable
.extern FSi_SeekDirDirect
arm_func_start FSi_CloseFileCommand
FSi_CloseFileCommand: ; 0x020D0114
@@ -42,7 +45,6 @@ FSi_OpenFileFastCommand: ; 0x020D0144
mov r2, #0x8
str r3, [sp, #0xc]
bl FSi_ReadTable
_020D0194:
cmp r0, #0
addne sp, sp, #0x14
ldmneia sp!, {r4-r5,lr}
@@ -614,135 +616,3 @@ _020D0978:
bx lr
.balign 4
_020D0988: .word 0x00000FFF
arm_func_start FSi_WriteFileCommand
FSi_WriteFileCommand: ; 0x020D098C
stmdb sp!, {lr}
sub sp, sp, #0x4
ldr r2, [r0, #0x2c]
ldr r3, [r0, #0x38]
ldr lr, [r0, #0x8]
ldr r1, [r0, #0x30]
add r12, r2, r3
str r12, [r0, #0x2c]
ldr r12, [lr, #0x4c]
mov r0, lr
blx r12
add sp, sp, #0x4
ldmia sp!, {lr}
bx lr
arm_func_start FSi_ReadFileCommand
FSi_ReadFileCommand: ; 0x020D09C4
stmdb sp!, {lr}
sub sp, sp, #0x4
ldr r2, [r0, #0x2c]
ldr r3, [r0, #0x38]
ldr lr, [r0, #0x8]
ldr r1, [r0, #0x30]
add r12, r2, r3
str r12, [r0, #0x2c]
ldr r12, [lr, #0x48]
mov r0, lr
blx r12
add sp, sp, #0x4
ldmia sp!, {lr}
bx lr
arm_func_start FSi_SeekDirDirect
FSi_SeekDirDirect: ; 0x020D09FC
ldr r3, [r0, #0xc]
mov r2, #0x0
orr r3, r3, #0x4
str r3, [r0, #0xc]
ldr r3, [r0, #0x8]
ldr ip, _020D0A2C ; =FSi_TranslateCommand
str r3, [r0, #0x30]
str r2, [r0, #0x38]
strh r2, [r0, #0x36]
strh r1, [r0, #0x34]
mov r1, #0x2
bx r12
.balign 4
_020D0A2C: .word FSi_TranslateCommand
arm_func_start FSi_ReadTable
FSi_ReadTable:
stmdb sp!, {r4-r8,lr}
mov r7, r0
ldr r5, [r7, #0x0]
mov r6, r2
ldr r2, [r5, #0x1c]
mov r0, r5
orr r2, r2, #0x200
str r2, [r5, #0x1c]
ldr r2, [r7, #0x4]
ldr r4, [r5, #0x50]
mov r3, r6
blx r4
cmp r0, #0x0
beq _020D0A7C
cmp r0, #0x1
beq _020D0A7C
cmp r0, #0x6
beq _020D0A8C
b _020D0AC8
_020D0A7C:
ldr r1, [r5, #0x1c]
bic r1, r1, #0x200
str r1, [r5, #0x1c]
b _020D0AC8
_020D0A8C:
bl OS_DisableInterrupts
ldr r1, [r5, #0x1c]
mov r4, r0
ands r0, r1, #0x200
beq _020D0AB8
add r8, r5, #0xc
_020D0AA4:
mov r0, r8
bl OS_SleepThread
ldr r0, [r5, #0x1c]
ands r0, r0, #0x200
bne _020D0AA4
_020D0AB8:
mov r0, r4
bl OS_RestoreInterrupts
ldr r0, [r5, #0x24]
ldr r0, [r0, #0x14]
_020D0AC8:
ldr r1, [r7, #0x4]
add r1, r1, r6
str r1, [r7, #0x4]
ldmia sp!, {r4-r8,lr}
bx lr
arm_func_start FSi_StrNICmp
FSi_StrNICmp: ; 0x020D0ADC
stmdb sp!, {lr}
sub sp, sp, #0x4
cmp r2, #0x0
mov lr, #0x0
bls _020D0B30
_020D0AF0:
ldrb r12, [r0, lr]
ldrb r3, [r1, lr]
sub r12, r12, #0x41
cmp r12, #0x19
sub r3, r3, #0x41
addls r12, r12, #0x20
cmp r3, #0x19
addls r3, r3, #0x20
cmp r12, r3
addne sp, sp, #0x4
subne r0, r12, r3
ldmneia sp!, {lr}
bxne lr
add lr, lr, #0x1
cmp lr, r2
blo _020D0AF0
_020D0B30:
mov r0, #0x0
add sp, sp, #0x4
ldmia sp!, {lr}
bx lr

View File

@@ -733,6 +733,3 @@ gScriptCmdTable: ; 0x020F355C
.incbin "baserom.nds", 0xF80A0, 0xFEE0
.global fsi_default_command
fsi_default_command: ; 0x02103F80
.incbin "baserom.nds", 0x107F80, 0x28b0

View File

@@ -5,5 +5,5 @@
.section .data
/* 0x02106834 */
.incbin "baserom.nds", 0x10a834, 0x76c
/* 0x02103FA4 */
.incbin "baserom.nds", 0x107FA4, 0x288C

9
arm9/data/rom2_4.s Normal file
View File

@@ -0,0 +1,9 @@
.include "asm/macros.inc"
.include "global.inc"
/* rom2.s TODO: Disassemble */
.section .data
/* 0x02106834 */
.incbin "baserom.nds", 0x10a834, 0x76c

View File

@@ -0,0 +1,108 @@
#include "nitro.h"
#include "FS_file.h"
#include "FS_command.h"
#include "FS_archive.h"
#include "MI_byteAccess.h"
typedef struct
{
FSArchive *arc;
u32 pos;
}
FSiSyncReadParam;
FSResult FSi_ReadFileCommand(FSFile * p_file);
FSResult FSi_WriteFileCommand(FSFile * p_file);
FSResult FSi_SeekDirCommand(FSFile * p_file);
FSResult FSi_ReadDirCommand(FSFile * p_file);
FSResult FSi_FindPathCommand(FSFile * p_file);
FSResult FSi_GetPathCommand(FSFile * p_file);
FSResult FSi_OpenFileFastCommand(FSFile * p_file);
FSResult FSi_OpenFileDirectCommand(FSFile * p_file);
FSResult FSi_CloseFileCommand(FSFile * p_file);
FSResult (*const fsi_default_command[])(FSFile *) = {
[FS_COMMAND_READFILE] = FSi_ReadFileCommand,
[FS_COMMAND_WRITEFILE] = FSi_WriteFileCommand,
[FS_COMMAND_SEEKDIR] = FSi_SeekDirCommand,
[FS_COMMAND_READDIR] = FSi_ReadDirCommand,
[FS_COMMAND_FINDPATH] = FSi_FindPathCommand,
[FS_COMMAND_GETPATH] = FSi_GetPathCommand,
[FS_COMMAND_OPENFILEFAST] = FSi_OpenFileFastCommand,
[FS_COMMAND_OPENFILEDIRECT] = FSi_OpenFileDirectCommand,
[FS_COMMAND_CLOSEFILE] = FSi_CloseFileCommand,
};
// Case-insensitive string comparison
u32 FSi_StrNICmp(const char * str1, const char * str2, u32 len)
{
int i;
for (i = 0; i < len; i++)
{
u32 c = MI_ReadByte(str1 + i) - 'A';
u32 d = MI_ReadByte(str2 + i) - 'A';
if (c <= 'Z' - 'A')
c += 'a' - 'A';
if (d <= 'Z' - 'A')
d += 'a' - 'A';
if (c != d)
return c - d;
}
return 0;
}
FSResult FSi_ReadTable(FSiSyncReadParam * p, void * dst, u32 len)
{
FSResult ret;
FSArchive * const p_arc = p->arc;
p_arc->flag |= FS_ARCHIVE_FLAG_IS_SYNC;
switch (ret = (*p_arc->table_func)(p_arc, dst, p->pos, len))
{
case FS_RESULT_SUCCESS:
case FS_RESULT_FAILURE:
p_arc->flag &= ~FS_ARCHIVE_FLAG_IS_SYNC;
break;
case FS_RESULT_PROC_ASYNC:
{
OSIntrMode bak_psr = OS_DisableInterrupts();
while (FSi_IsArchiveSync(p_arc))
OS_SleepThread(&p_arc->sync_q);
OS_RestoreInterrupts(bak_psr);
ret = p_arc->list.next->error;
}
break;
}
p->pos += len;
return ret;
}
FSResult FSi_SeekDirDirect(FSFile * p_dir, u32 id)
{
p_dir->stat |= FS_FILE_STATUS_SYNC;
p_dir->arg.seekdir.pos.arc = p_dir->arc;
p_dir->arg.seekdir.pos.pos = 0;
p_dir->arg.seekdir.pos.index = 0;
p_dir->arg.seekdir.pos.own_id = (u16)id;
return FSi_TranslateCommand(p_dir, FS_COMMAND_SEEKDIR);
}
// The actual commands
FSResult FSi_ReadFileCommand(FSFile * p_file)
{
FSArchive *const p_arc = p_file->arc;
const u32 pos = p_file->prop.file.pos;
const u32 len = p_file->arg.readfile.len;
void *const dst = p_file->arg.readfile.dst;
p_file->prop.file.pos += len;
return (*p_arc->read_func)(p_arc, dst, pos, len);
}
FSResult FSi_WriteFileCommand(FSFile * p_file)
{
FSArchive *const p_arc = p_file->arc;
const u32 pos = p_file->prop.file.pos;
const u32 len = p_file->arg.writefile.len;
const void *const src = p_file->arg.writefile.src;
p_file->prop.file.pos += len;
return (*p_arc->write_func)(p_arc, src, pos, len);
}