diff --git a/ld/libfiles.ntsc-beta.inc b/ld/libfiles.ntsc-beta.inc index 39b991940..67e1f8bcd 100644 --- a/ld/libfiles.ntsc-beta.inc +++ b/ld/libfiles.ntsc-beta.inc @@ -24,7 +24,8 @@ build/ROMID/lib/lib_06100.o (section); \ build/ROMID/lib/ultra/io/gbpakpower.o (section); \ build/ROMID/lib/ultra/io/conteeplongwrite.o (section); \ - build/ROMID/lib/lib_06550.o (section); \ + build/ROMID/lib/ultra/io/pfsresizefile.o (section); \ + build/ROMID/lib/ultra/io/pfsinitpak.o (section); \ build/ROMID/lib/lib_070d0.o (section); \ build/ROMID/lib/lib_074f0.o (section); \ build/ROMID/lib/audiomgr.o (section); \ diff --git a/ld/libfiles.ntsc-final.inc b/ld/libfiles.ntsc-final.inc index 1ca189e9e..890e5703d 100644 --- a/ld/libfiles.ntsc-final.inc +++ b/ld/libfiles.ntsc-final.inc @@ -23,7 +23,8 @@ build/ROMID/lib/lib_06100.o (section); \ build/ROMID/lib/ultra/io/gbpakpower.o (section); \ build/ROMID/lib/ultra/io/conteeplongwrite.o (section); \ - build/ROMID/lib/lib_06550.o (section); \ + build/ROMID/lib/ultra/io/pfsresizefile.o (section); \ + build/ROMID/lib/ultra/io/pfsinitpak.o (section); \ build/ROMID/lib/lib_070d0.o (section); \ build/ROMID/lib/lib_074f0.o (section); \ build/ROMID/lib/audiomgr.o (section); \ diff --git a/ld/libfiles.pal-final.inc b/ld/libfiles.pal-final.inc index 972bf9a0c..5290187d1 100644 --- a/ld/libfiles.pal-final.inc +++ b/ld/libfiles.pal-final.inc @@ -23,7 +23,8 @@ build/ROMID/lib/lib_06100.o (section); \ build/ROMID/lib/ultra/io/gbpakpower.o (section); \ build/ROMID/lib/ultra/io/conteeplongwrite.o (section); \ - build/ROMID/lib/lib_06550.o (section); \ + build/ROMID/lib/ultra/io/pfsresizefile.o (section); \ + build/ROMID/lib/ultra/io/pfsinitpak.o (section); \ build/ROMID/lib/lib_070d0.o (section); \ build/ROMID/lib/lib_074f0.o (section); \ build/ROMID/lib/audiomgr.o (section); \ diff --git a/src/game/pak/pak.c b/src/game/pak/pak.c index b0d29c270..f6ad942c7 100644 --- a/src/game/pak/pak.c +++ b/src/game/pak/pak.c @@ -11,7 +11,6 @@ #include "lib/joy.h" #include "lib/lib_06100.h" #include "lib/lib_06440.h" -#include "lib/lib_06550.h" #include "lib/main.h" #include "lib/memory.h" #include "lib/rng.h" diff --git a/src/include/PR/os_pfs.h b/src/include/PR/os_pfs.h index 9ae5574af..309052e6f 100644 --- a/src/include/PR/os_pfs.h +++ b/src/include/PR/os_pfs.h @@ -184,6 +184,13 @@ s32 osPfsDeleteFile(OSPfs *pfs, u16 company_code, u32 game_code, char *game_name s32 osPfsFileState(OSPfs *pfs, s32 file_no, OSPfsState *state); s32 osPfsReadWriteFile(OSPfs* pfs, s32 fileNo, u8 flag, s32 offset, s32 size, u8* data); s32 osPfsFreeBlocks(OSPfs* pfs, s32 *bytes_not_used); +s32 osPfsReSizeFile(OSPfs *pfs, u16 company_code, u32 game_code, u8 *game_name, u8 *ext_name, u32 numbytes); + +#if VERSION >= VERSION_NTSC_1_0 +s32 osPfsInitPak(OSMesgQueue *mq, OSPfs *pfs, s32 channel, s32 *arg3); +#else +s32 osPfsInitPak(OSMesgQueue *mq, OSPfs *pfs, s32 channel); +#endif s32 osMotorAccess(OSPfs *pfs, u32 vibrate); void osSetUpMempakWrite(s32 channel, OSPifRam* buf); diff --git a/src/include/lib/lib_06550.h b/src/include/lib/lib_06550.h deleted file mode 100644 index c036f340c..000000000 --- a/src/include/lib/lib_06550.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _IN_LIB_LIB_06550_H -#define _IN_LIB_LIB_06550_H -#include -#include "data.h" -#include "types.h" - -s32 osPfsReSizeFile(OSPfs *pfs, u16 company_code, u32 game_code, u8 *game_name, u8 *ext_name, u32 numbytes); - -#if VERSION >= VERSION_NTSC_1_0 -s32 osPfsInitPak(OSMesgQueue *mq, OSPfs *pfs, s32 channel, s32 *arg3); -#else -s32 osPfsInitPak(OSMesgQueue *mq, OSPfs *pfs, s32 channel); -#endif - -s32 func00007084(OSPfs *pfs); - -#endif diff --git a/src/lib/ultra/io/pfsinitpak.c b/src/lib/ultra/io/pfsinitpak.c new file mode 100644 index 000000000..5b38d1157 --- /dev/null +++ b/src/lib/ultra/io/pfsinitpak.c @@ -0,0 +1,163 @@ +#include +#include "libultra_internal.h" +#include "constants.h" +#include "bss.h" +#include "lib/lib_4b170.h" +#include "lib/lib_4e090.h" +#include "data.h" +#include "types.h" + +s32 __osPfsCheckRamArea(OSPfs* pfs); +s32 func00007084(OSPfs *pfs); + +#if VERSION >= VERSION_NTSC_1_0 +s32 osPfsInitPak(OSMesgQueue *queue, OSPfs *pfs, s32 channel, s32 *arg3) +#else +s32 osPfsInitPak(OSMesgQueue *queue, OSPfs *pfs, s32 channel) +#endif +{ + s32 ret; + u16 sum; + u16 isum; + u8 temp[32]; + __OSPackId *id; + __OSPackId newid; + + ret = 0; + + __osSiGetAccess(); + ret = __osPfsGetStatus(queue, channel); + __osSiRelAccess(); + + if (ret != 0) { + return ret; + } + + pfs->queue = queue; + pfs->channel = channel; + pfs->status = 0; + + ERRCK(__osPfsCheckRamArea(pfs)); + ERRCK(__osPfsSelectBank(pfs, 0)); + ERRCK(__osContRamRead(pfs->queue, pfs->channel, 1, (u8*)temp)); + __osIdCheckSum((u16*)temp, &sum, &isum); + + id = (__OSPackId *)temp; + + if (id->checksum != sum || id->inverted_checksum != isum) { + ret = __osCheckPackId(pfs, id); + + if (ret != 0) { + pfs->status |= 4; + return ret; + } + } + + if ((id->deviceid & 1) == 0) { + ret = __osRepairPackId(pfs, id, &newid); + + if (ret != 0) { + if (ret == 10) { + pfs->status |= 4; + } + + return ret; + } + + id = &newid; + + if ((id->deviceid & 1) == 0) { + return PFS_ERR_DEVICE; + } + } + + bcopy(id, pfs->id, 0x20); + + pfs->version = id->version; + pfs->banks = id->banks; + pfs->inode_start_page = pfs->banks * 2 + 3; + pfs->dir_size = 0x10; + pfs->inode_table = 8; + pfs->minode_table = pfs->banks * PFS_ONE_PAGE + 8; + pfs->dir_table = pfs->minode_table + pfs->banks * PFS_ONE_PAGE; + +#if VERSION >= VERSION_NTSC_1_0 + ERRCK(__osContRamRead(pfs->queue, pfs->channel, 7, pfs->label)); + ret = osPfsChecker(pfs); + pfs->status |= PFS_INITIALIZED; + + if (arg3 != NULL) { + *arg3 = func00007084(pfs); + } +#else + + ret = __osContRamRead(pfs->queue, pfs->channel, 7, pfs->label); + + if (ret != 0) { + return ret; + } + + crashPrint("pfsinitpak.c -> ret = %d\n", ret); + ret = osPfsChecker(pfs); + pfs->status |= PFS_INITIALIZED; +#endif + + return ret; +} + +s32 __osPfsCheckRamArea(OSPfs* pfs) +{ + s32 i = 0; + s32 ret = 0; + u8 temp1[BLOCKSIZE]; + u8 temp2[BLOCKSIZE]; + u8 saveReg[BLOCKSIZE]; + + if ((ret = __osPfsSelectBank(pfs, 0)) != 0) { + return ret; + } + + if ((ret = __osContRamRead(pfs->queue, pfs->channel, 0, saveReg)) != 0) { + return ret; + } + + for (i = 0; i < BLOCKSIZE; i++) { + temp1[i] = i; + } + + if ((ret = __osContRamWrite(pfs->queue, pfs->channel, 0, temp1, 0)) != 0) { + return ret; + } + + if ((ret = __osContRamRead(pfs->queue, pfs->channel, 0, temp2)) != 0) { + return ret; + } + + if (bcmp(temp1, temp2, BLOCKSIZE) != 0) { + return PFS_ERR_DEVICE; + } + + return __osContRamWrite(pfs->queue, pfs->channel, 0, saveReg, 0); +} + +#if VERSION >= VERSION_NTSC_1_0 +s32 func00007084(OSPfs *pfs) +{ + s32 ret; + u32 buffer[7]; + + ret = __osContRamRead(pfs->queue, pfs->channel, 1, (u8 *) buffer); + + if (ret != 0) { + return 0; + } + + return buffer[1]; +} +#else +GLOBAL_ASM( +glabel func00007084 +/* 71a0: 03e00008 */ jr $ra +/* 71a4: 00000000 */ sll $zero,$zero,0x0 +); +#endif diff --git a/src/lib/lib_06550.c b/src/lib/ultra/io/pfsresizefile.c similarity index 89% rename from src/lib/lib_06550.c rename to src/lib/ultra/io/pfsresizefile.c index 0585fc7a9..8aa37bce7 100644 --- a/src/lib/lib_06550.c +++ b/src/lib/ultra/io/pfsresizefile.c @@ -2,7 +2,6 @@ #include "libultra_internal.h" #include "constants.h" #include "bss.h" -#include "lib/lib_06550.h" #include "lib/lib_4b170.h" #include "lib/lib_4e090.h" #include "data.h" @@ -593,157 +592,3 @@ glabel osPfsReSizeFile /* 6d58: 03e00008 */ jr $ra /* 6d5c: 27bd02d0 */ addiu $sp,$sp,0x2d0 ); - -s32 __osPfsCheckRamArea(OSPfs* pfs); - -#if VERSION >= VERSION_NTSC_1_0 -s32 osPfsInitPak(OSMesgQueue *queue, OSPfs *pfs, s32 channel, s32 *arg3) -#else -s32 osPfsInitPak(OSMesgQueue *queue, OSPfs *pfs, s32 channel) -#endif -{ - s32 ret; - u16 sum; - u16 isum; - u8 temp[32]; - __OSPackId *id; - __OSPackId newid; - - ret = 0; - - __osSiGetAccess(); - ret = __osPfsGetStatus(queue, channel); - __osSiRelAccess(); - - if (ret != 0) { - return ret; - } - - pfs->queue = queue; - pfs->channel = channel; - pfs->status = 0; - - ERRCK(__osPfsCheckRamArea(pfs)); - ERRCK(__osPfsSelectBank(pfs, 0)); - ERRCK(__osContRamRead(pfs->queue, pfs->channel, 1, (u8*)temp)); - __osIdCheckSum((u16*)temp, &sum, &isum); - - id = (__OSPackId *)temp; - - if (id->checksum != sum || id->inverted_checksum != isum) { - ret = __osCheckPackId(pfs, id); - - if (ret != 0) { - pfs->status |= 4; - return ret; - } - } - - if ((id->deviceid & 1) == 0) { - ret = __osRepairPackId(pfs, id, &newid); - - if (ret != 0) { - if (ret == 10) { - pfs->status |= 4; - } - - return ret; - } - - id = &newid; - - if ((id->deviceid & 1) == 0) { - return PFS_ERR_DEVICE; - } - } - - bcopy(id, pfs->id, 0x20); - - pfs->version = id->version; - pfs->banks = id->banks; - pfs->inode_start_page = pfs->banks * 2 + 3; - pfs->dir_size = 0x10; - pfs->inode_table = 8; - pfs->minode_table = pfs->banks * PFS_ONE_PAGE + 8; - pfs->dir_table = pfs->minode_table + pfs->banks * PFS_ONE_PAGE; - -#if VERSION >= VERSION_NTSC_1_0 - ERRCK(__osContRamRead(pfs->queue, pfs->channel, 7, pfs->label)); - ret = osPfsChecker(pfs); - pfs->status |= PFS_INITIALIZED; - - if (arg3 != NULL) { - *arg3 = func00007084(pfs); - } -#else - - ret = __osContRamRead(pfs->queue, pfs->channel, 7, pfs->label); - - if (ret != 0) { - return ret; - } - - crashPrint("pfsinitpak.c -> ret = %d\n", ret); - ret = osPfsChecker(pfs); - pfs->status |= PFS_INITIALIZED; -#endif - - return ret; -} - -s32 __osPfsCheckRamArea(OSPfs* pfs) -{ - s32 i = 0; - s32 ret = 0; - u8 temp1[BLOCKSIZE]; - u8 temp2[BLOCKSIZE]; - u8 saveReg[BLOCKSIZE]; - - if ((ret = __osPfsSelectBank(pfs, 0)) != 0) { - return ret; - } - - if ((ret = __osContRamRead(pfs->queue, pfs->channel, 0, saveReg)) != 0) { - return ret; - } - - for (i = 0; i < BLOCKSIZE; i++) { - temp1[i] = i; - } - - if ((ret = __osContRamWrite(pfs->queue, pfs->channel, 0, temp1, 0)) != 0) { - return ret; - } - - if ((ret = __osContRamRead(pfs->queue, pfs->channel, 0, temp2)) != 0) { - return ret; - } - - if (bcmp(temp1, temp2, BLOCKSIZE) != 0) { - return PFS_ERR_DEVICE; - } - - return __osContRamWrite(pfs->queue, pfs->channel, 0, saveReg, 0); -} - -#if VERSION >= VERSION_NTSC_1_0 -s32 func00007084(OSPfs *pfs) -{ - s32 ret; - u32 buffer[7]; - - ret = __osContRamRead(pfs->queue, pfs->channel, 1, (u8 *) buffer); - - if (ret != 0) { - return 0; - } - - return buffer[1]; -} -#else -GLOBAL_ASM( -glabel func00007084 -/* 71a0: 03e00008 */ jr $ra -/* 71a4: 00000000 */ sll $zero,$zero,0x0 -); -#endif