2023-02-10 23:20:40 +09:00
|
|
|
#include "card.h"
|
2022-11-27 06:38:23 +09:00
|
|
|
|
2023-02-10 23:20:40 +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
|
|
|
{
|
2023-02-10 23:20:40 +09:00
|
|
|
int rc;
|
|
|
|
|
2022-11-27 06:38:23 +09:00
|
|
|
// Mount the card
|
2023-02-10 23:20:40 +09:00
|
|
|
if (mount_(cm, 1))
|
|
|
|
return LOAD_ERR_MOUNT;
|
2022-11-27 06:38:23 +09:00
|
|
|
|
|
|
|
// Open the card
|
2023-02-10 23:20:40 +09:00
|
|
|
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
|
2023-02-10 23:20:40 +09:00
|
|
|
// 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
|
2023-02-10 23:20:40 +09:00
|
|
|
if (CARDRead(fileInfo, dst, fileSize, 0))
|
|
|
|
return LOAD_ERR_READ;
|
2022-11-27 06:38:23 +09:00
|
|
|
|
|
|
|
// Done
|
|
|
|
CARDClose(fileInfo);
|
|
|
|
return 0;
|
|
|
|
}
|