From 1c3935d040d00ce55fa565603ade7b011b0cd88e Mon Sep 17 00:00:00 2001 From: sup39 Date: Wed, 9 Nov 2022 21:51:50 +0900 Subject: [PATCH] init --- LICENSE | 24 +++++++++++++++++++++++ README.md | 7 +++++++ ReadFile.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ ReadFile.ld | 4 ++++ 4 files changed, 91 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 ReadFile.c create mode 100644 ReadFile.ld diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ae591eb --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +MIT License + +Copyright (c) 2022 sup39 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a2b987c --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Read File +Read file from memory card in SMS without allocating memory or modifying game id + +## TODO +- [ ] Add error message +- [ ] Handle inserting/removing memory card +- [ ] Make sure there is no side effect diff --git a/ReadFile.c b/ReadFile.c new file mode 100644 index 0000000..92c756a --- /dev/null +++ b/ReadFile.c @@ -0,0 +1,56 @@ +typedef struct { + char pad[20]; +} CARDFileInfo; +typedef struct { + int slot; +} TCardManager; + +/** For NTSC-J 1.0: + * + * mount_ 80107b50 + * open_ 801072f4 + * CARDOpen 800a3cac + * CARDRead 800a4640 + * CARDClose 800a3e24 + * + * onReadOptionBlock 801069f4 + */ + +typedef int bool; +int mount_(TCardManager *this, bool); +int open_(TCardManager *this, CARDFileInfo*); +int CARDOpen(int slot, const char *fileName, CARDFileInfo*); +int CARDRead(CARDFileInfo *fileInfo, void *buf, unsigned long size, unsigned long offset); +int CARDClose(CARDFileInfo *fileInfo); + +#define fileName "gct" +#define dst ((void*)0x817F0000) +#define size 0xE000 // 7 blocks +int onReadOptionBlock(TCardManager *this, CARDFileInfo *fileInfo) { + int rc; + // mount + if ((rc = mount_(this, 1))) goto orig; + + // open file + if ((rc = CARDOpen(this->slot, fileName, fileInfo))) { + // TODO error handling + // if (rc == -4) // file not exists + goto orig; + } + + // read file to memory + if ((rc = CARDRead(fileInfo, dst, size, 0))) { + // should not fail if (dst, size) is properly set + } else { + // everything is good + // TODO apply gecko code + *(char*)0x817effff = 1; // ready (temporary solution) + } + + // close file + CARDClose(fileInfo); + +orig: + // original function call + return open_(this, fileInfo); +} diff --git a/ReadFile.ld b/ReadFile.ld new file mode 100644 index 0000000..198acd1 --- /dev/null +++ b/ReadFile.ld @@ -0,0 +1,4 @@ +$$ = 0x817eff00; + +/* TCardManager::cmdLoop() */ +$bl$onReadOptionBlock = 0x801069f4;