mirror of
https://github.com/Polprzewodnikowy/N64FlashcartMenu.git
synced 2024-11-25 03:56:54 +01:00
Added file offset to flashcart_load_file
This commit is contained in:
parent
bbc4901403
commit
3db859b0f7
@ -112,12 +112,16 @@ flashcart_error_t flashcart_load_rom (char *rom_path, bool byte_swap, flashcart_
|
||||
return error;
|
||||
}
|
||||
|
||||
flashcart_error_t flashcart_load_file (char *file_path, uint32_t start_offset_address) {
|
||||
flashcart_error_t flashcart_load_file (char *file_path, uint32_t rom_offset, uint32_t file_offset) {
|
||||
if ((file_path == NULL) || (!file_exists(file_path))) {
|
||||
return FLASHCART_ERROR_ARGS;
|
||||
}
|
||||
|
||||
return flashcart->load_file(file_path, start_offset_address);
|
||||
if ((file_offset % FS_SECTOR_SIZE) != 0) {
|
||||
return FLASHCART_ERROR_ARGS;
|
||||
}
|
||||
|
||||
return flashcart->load_file(file_path, rom_offset, file_offset);
|
||||
}
|
||||
|
||||
flashcart_error_t flashcart_load_save (char *save_path, flashcart_save_type_t save_type) {
|
||||
|
@ -42,7 +42,7 @@ typedef struct {
|
||||
flashcart_error_t (*init) (void);
|
||||
flashcart_error_t (*deinit) (void);
|
||||
flashcart_error_t (*load_rom) (char *rom_path, flashcart_progress_callback_t *progress);
|
||||
flashcart_error_t (*load_file) (char *file_path, uint32_t start_offset_address);
|
||||
flashcart_error_t (*load_file) (char *file_path, uint32_t rom_offset, uint32_t file_offset);
|
||||
flashcart_error_t (*load_save) (char *save_path);
|
||||
flashcart_error_t (*set_save_type) (flashcart_save_type_t save_type);
|
||||
flashcart_error_t (*set_save_writeback) (uint32_t *sectors);
|
||||
@ -52,7 +52,7 @@ typedef struct {
|
||||
flashcart_error_t flashcart_init (void);
|
||||
flashcart_error_t flashcart_deinit (void);
|
||||
flashcart_error_t flashcart_load_rom (char *rom_path, bool byte_swap, flashcart_progress_callback_t *progress);
|
||||
flashcart_error_t flashcart_load_file (char *file_path, uint32_t start_offset_address);
|
||||
flashcart_error_t flashcart_load_file (char *file_path, uint32_t rom_offset, uint32_t file_offset);
|
||||
flashcart_error_t flashcart_load_save (char *save_path, flashcart_save_type_t save_type);
|
||||
|
||||
|
||||
|
@ -196,7 +196,7 @@ static flashcart_error_t sc64_load_rom (char *rom_path, flashcart_progress_callb
|
||||
return FLASHCART_OK;
|
||||
}
|
||||
|
||||
static flashcart_error_t sc64_load_file (char *file_path, uint32_t start_offset_address) {
|
||||
static flashcart_error_t sc64_load_file (char *file_path, uint32_t rom_offset, uint32_t file_offset) {
|
||||
FIL fil;
|
||||
UINT br;
|
||||
|
||||
@ -206,14 +206,19 @@ static flashcart_error_t sc64_load_file (char *file_path, uint32_t start_offset_
|
||||
|
||||
fix_file_size(&fil);
|
||||
|
||||
size_t file_size = f_size(&fil);
|
||||
size_t file_size = f_size(&fil) - file_offset;
|
||||
|
||||
if (file_size > (MiB(64) - start_offset_address)) {
|
||||
if (file_size > (MiB(64) - rom_offset)) {
|
||||
f_close(&fil);
|
||||
return FLASHCART_ERROR_ARGS;
|
||||
}
|
||||
|
||||
if (f_read(&fil, (void *) (ROM_ADDRESS + start_offset_address), file_size, &br) != FR_OK) {
|
||||
if (f_lseek(&fil, file_offset) != FR_OK) {
|
||||
f_close(&fil);
|
||||
return FLASHCART_ERROR_LOAD;
|
||||
}
|
||||
|
||||
if (f_read(&fil, (void *) (ROM_ADDRESS + rom_offset), file_size, &br) != FR_OK) {
|
||||
f_close(&fil);
|
||||
return FLASHCART_ERROR_LOAD;
|
||||
}
|
||||
|
@ -81,6 +81,7 @@ cart_load_err_t cart_load_emulator (menu_t *menu, cart_load_emu_type_t emu_type,
|
||||
path_t *path = path_init("sd:/", EMU_LOCATION);
|
||||
flashcart_save_type_t save_type = FLASHCART_SAVE_TYPE_NONE;
|
||||
uint32_t emulated_rom_offset = 0x200000;
|
||||
uint32_t emulated_file_offset = 0;
|
||||
|
||||
switch (emu_type) {
|
||||
case CART_LOAD_EMU_TYPE_NES:
|
||||
@ -112,7 +113,7 @@ cart_load_err_t cart_load_emulator (menu_t *menu, cart_load_emu_type_t emu_type,
|
||||
|
||||
path = path_clone_push(menu->browser.directory, menu->browser.entry->name);
|
||||
|
||||
menu->flashcart_error = flashcart_load_file(path_get(path), emulated_rom_offset);
|
||||
menu->flashcart_error = flashcart_load_file(path_get(path), emulated_rom_offset, emulated_file_offset);
|
||||
if (menu->flashcart_error != FLASHCART_OK) {
|
||||
path_free(path);
|
||||
return CART_LOAD_ERR_EMU_ROM;
|
||||
|
Loading…
Reference in New Issue
Block a user