From cada1f7375e323edb20d8145341ad99ceca24fb0 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Tue, 17 Oct 2017 23:56:46 +0100 Subject: [PATCH] refactored loadnesrom removes file fragmentation issue --- src/main.c | 54 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/src/main.c b/src/main.c index ca336a0..5eac146 100644 --- a/src/main.c +++ b/src/main.c @@ -1272,26 +1272,52 @@ void rom_load_y(void) void loadnesrom(display_context_t disp, u8 *rom_path) { - FatRecord rec_tmpf; + FRESULT result; + FIL emufile; + UINT emubytesread; + result = f_open(&emufile, "/ED64/neon64bu.rom", FA_READ); - if (fatFindRecord("/ED64/neon64bu.rom", &rec_tmpf, 0) == 0) //filename already exists? + if (result == FR_OK) { - u8 resp = 0; + int emufsize = f_size(&emufile); //load nes emulator - resp = fatOpenFileByName("/ED64/neon64bu.rom", 0); //err if not found ^^ - resp = sdRead(file.sector, (void *)0xb0000000, file.sec_available); + result = + f_read ( + &emufile, /* [IN] File object */ + (void *)0xb0000000, /* [OUT] Buffer to store read data */ + emufsize, /* [IN] Number of bytes to read */ + &emubytesread /* [OUT] Number of bytes read */ + ); + + result = f_close(&emufile); //load nes rom - resp = fatOpenFileByName(rom_path, 0); //err if not found ^^ - resp = sdRead(file.sector, (void *)0xb0200000, file.sec_available); + FIL romfile; + UINT rombytesread; + result = f_open(&romfile, rom_path, FA_READ); + + if (result == FR_OK) + { + int romfsize = f_size(&romfile); + + result = + f_read ( + &romfile, /* [IN] File object */ + (void *)0xb0200000, /* [OUT] Buffer to store read data */ + romfsize, /* [IN] Number of bytes to read */ + &rombytesread /* [OUT] Number of bytes read */ + ); + + result = f_close(&romfile); - boot_cic = CIC_6102; - boot_save = 0; //save off/cpak - force_tv = 0; //no force - cheats_on = 0; //cheats off - checksum_fix_on = 0; - - bootRom(disp, 1); + boot_cic = CIC_6102; + boot_save = 0; //save off/cpak + force_tv = 0; //no force + cheats_on = 0; //cheats off + checksum_fix_on = 0; + + bootRom(disp, 1); + } } }