diff options
| author | coco875 <59367621+coco875@users.noreply.github.com> | 2025-01-26 02:43:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-25 18:43:30 -0700 |
| commit | 995c60c85cac45d23dbcbfea45f29ec4ed7618b6 (patch) | |
| tree | 55aa7092635da91e65a6bc1ff9f02134773e5122 /src/stubs.c | |
| parent | a37bb5afbd280949411ac9061ce54e92166325d8 (diff) | |
fix ghost (#175)
* fix ghost
* remove a semi colon
Diffstat (limited to 'src/stubs.c')
| -rw-r--r-- | src/stubs.c | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/src/stubs.c b/src/stubs.c index 0f383ea6b..fad163043 100644 --- a/src/stubs.c +++ b/src/stubs.c @@ -1,7 +1,18 @@ #include <libultraship.h> #include <libultraship/libultra.h> #include <string.h> +#include <stdio.h> #include <stubs.h> +#include "save.h" + +struct state_pak { + OSPfsState state; + FILE* file; +}; + +struct state_pak openFile[16]; + +int fileIndex = 0; u32 osTvType = OS_TV_NTSC; u32 osResetType; @@ -54,13 +65,35 @@ OSYieldResult osSpTaskYielded(OSTask* task) { } s32 osPfsDeleteFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name, u8* ext_name) { + char filename[1024]; + sprintf(filename, "channel_%d_%hu_%hd_%s.sav", pfs->channel, company_code, game_code, game_name); + remove(filename); + return PFS_NO_ERROR; } s32 osPfsReadWriteFile(OSPfs* pfs, s32 file_no, u8 flag, int offset, int size_in_bytes, u8* data_buffer) { + if (flag == PFS_READ) { + fseek(openFile[file_no].file, offset, SEEK_SET); + fread(data_buffer, size_in_bytes, 1, openFile[file_no].file); + } else { + fseek(openFile[file_no].file, offset, SEEK_SET); + fwrite(data_buffer, size_in_bytes, 1, openFile[file_no].file); + } + return PFS_NO_ERROR; } s32 osPfsAllocateFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name, u8* ext_name, int file_size_in_bytes, s32* file_no) { + char filename[1024]; + sprintf(filename, "channel_%d_%hu_%hd_%s.sav", pfs->channel, company_code, game_code, game_name); + *file_no = fileIndex++; + openFile[*file_no].file = fopen(filename, "w+"); + fwrite("\0", 1, file_size_in_bytes, openFile[*file_no].file); + openFile[*file_no].state.company_code = company_code; + openFile[*file_no].state.game_code = game_code; + strcpy(openFile[*file_no].state.game_name, game_name); + strcpy(openFile[*file_no].state.ext_name, ext_name); + return PFS_NO_ERROR; } void osSetTime(OSTime time) { @@ -70,9 +103,16 @@ s32 osPfsIsPlug(OSMesgQueue* queue, u8* pattern) { } s32 osPfsInit(OSMesgQueue* queue, OSPfs* pfs, int channel) { + pfs->queue = queue; + pfs->channel = channel; + pfs->status = 0; + pfs->status |= PFS_INITIALIZED; + return PFS_NO_ERROR; } s32 osPfsNumFiles(OSPfs* pfs, s32* max_files, s32* files_used) { + *max_files = 16; + *files_used = fileIndex; return 0; } @@ -83,4 +123,23 @@ s32 osPfsFreeBlocks(OSPfs* pfs, s32* bytes_not_used) { } s32 osPfsFindFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name, u8* ext_name, s32* file_no) { -} + char filename[1024]; + sprintf(filename, "channel_%d_%hu_%hd_%s.sav", pfs->channel, company_code, game_code, game_name); + for (int i = 0; i < 16; i++) { + if (openFile[i].state.game_code == game_code && openFile[i].state.company_code == company_code && + strcmp(openFile[i].state.game_name, game_name) == 0 && strcmp(openFile[i].state.ext_name, ext_name) == 0) { + *file_no = i; + return PFS_NO_ERROR; + } + } + *file_no = fileIndex++; + openFile[*file_no].file = fopen(filename, "r+"); + if (openFile[*file_no].file == NULL) { + openFile[*file_no].file = fopen(filename, "w+"); + } + openFile[*file_no].state.company_code = company_code; + openFile[*file_no].state.game_code = game_code; + strcpy(openFile[*file_no].state.game_name, game_name); + strcpy(openFile[*file_no].state.ext_name, ext_name); + return PFS_NO_ERROR; +}
\ No newline at end of file |
