This commit is contained in:
sup39 2022-11-09 21:51:50 +09:00
commit 1c3935d040
4 changed files with 91 additions and 0 deletions

24
LICENSE Normal file
View file

@ -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.

7
README.md Normal file
View file

@ -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

56
ReadFile.c Normal file
View file

@ -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);
}

4
ReadFile.ld Normal file
View file

@ -0,0 +1,4 @@
$$ = 0x817eff00;
/* TCardManager::cmdLoop() */
$bl$onReadOptionBlock = 0x801069f4;