SMS-GCI-Loader/source/card.c

35 lines
796 B
C
Raw Permalink Normal View History

#include "card.h"
2022-11-27 06:38:23 +09:00
// TODO: we need to keep some space to store this loader code
// #define DST_END ArenaHi
#define DST_END 0x817FE800
int loadCard(TCardManager *cm, CARDFileInfo *fileInfo, char *fileName, u32 *dst)
2022-11-27 06:38:23 +09:00
{
int rc;
2022-11-27 06:38:23 +09:00
// Mount the card
if (mount_(cm, 1))
return LOAD_ERR_MOUNT;
2022-11-27 06:38:23 +09:00
// Open the card
if ((rc = CARDOpen(cm->slot, fileName, fileInfo))) {
return rc == -4 ? LOAD_ERR_FILE_NOT_EXIST : LOAD_ERR_OPEN;
}
2022-11-27 06:38:23 +09:00
// Too many codes
// TODO fileInfo->length seems to be 0?
// int fileSize = fileInfo->length;
int fileSize = 0x2000 * 6;
if (fileSize > (DST_END - (u32)dst))
return LOAD_ERR_SIZE;
2022-11-27 06:38:23 +09:00
// Read codes into destination address
if (CARDRead(fileInfo, dst, fileSize, 0))
return LOAD_ERR_READ;
2022-11-27 06:38:23 +09:00
// Done
CARDClose(fileInfo);
return 0;
}