Skip to content

Commit

Permalink
Added the ability to load the image of another Floppy Disk on the fly…
Browse files Browse the repository at this point in the history
…, to support the "Kouhen" and "Zenpen" images.

The item is in the menu "NES" -> "Change Disk"
  • Loading branch information
punesemu committed Jan 1, 2024
1 parent 0f84dea commit 1bae89a
Show file tree
Hide file tree
Showing 19 changed files with 393 additions and 185 deletions.
18 changes: 15 additions & 3 deletions src/c++/l7zip/l7z.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,21 @@ BYTE l7z_examine_archive(_uncompress_archive *archive) {
for (b = 0; b < LENGTH(uncompress_exts); b++) {
if (ustrcasecmp(ext, (uTCHAR *)uncompress_exts[b].e) == 0) {
_uncompress_archive_items_list *list = &archive->list;
BYTE found = FALSE;

if (uncompress_exts[b].type == UNCOMPRESS_TYPE_ROM) {
if (uncompress_exts[b].type & UNCOMPRESS_TYPE_ROM) {
archive->rom.count++;
} else if (uncompress_exts[b].type == UNCOMPRESS_TYPE_PATCH) {
found = TRUE;
}
if (uncompress_exts[b].type & UNCOMPRESS_TYPE_FLOPPY_DISK) {
archive->floppy_disk.count++;
found = TRUE;
}
if (uncompress_exts[b].type & UNCOMPRESS_TYPE_PATCH) {
archive->patch.count++;
} else {
found = TRUE;
}
if (!found) {
continue;
}

Expand Down Expand Up @@ -359,6 +368,9 @@ BYTE l7z_extract_from_archive(_uncompress_archive *archive, uint32_t selected, B
case UNCOMPRESS_TYPE_ROM:
archive->rom.storage_index = storage_index;
break;
case UNCOMPRESS_TYPE_FLOPPY_DISK:
archive->floppy_disk.storage_index = storage_index;
break;
case UNCOMPRESS_TYPE_PATCH:
archive->patch.storage_index = storage_index;
break;
Expand Down
40 changes: 21 additions & 19 deletions src/core/emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ INLINE static void emu_frame_finished(void);
INLINE static void emu_frame_sleep(void);

static BYTE emu_ctrl_if_rom_exist(void);
static uTCHAR *emu_ctrl_rom_ext(uTCHAR *file);
static void emu_recent_roms_add(BYTE *add, uTCHAR *file);

void emu_quit(void) {
Expand Down Expand Up @@ -329,7 +328,7 @@ BYTE emu_load_rom(void) {

gui_egds_stop_unnecessary();

elaborate_rom_file:
elaborate_rom_file:
info.format = HEADER_UNKOWN;
info.no_rom = FALSE;
info.cpu_rw_extern = FALSE;
Expand Down Expand Up @@ -1554,6 +1553,23 @@ void emu_invert_bytes(BYTE *b0, BYTE *b1) {
double emu_ms_to_cpu_cycles(double ms) {
return ((machine.cpu_hz * 0.001f) * ms);
}
uTCHAR *emu_ctrl_rom_ext(uTCHAR *file) {
uTCHAR name_file[255], *last_dot = NULL;
static uTCHAR ext[10];

gui_utf_basename(file, name_file, usizeof(name_file));

last_dot = ustrrchr(name_file, uL('.'));

if (last_dot == NULL) {
ustrncpy((uTCHAR *)ext, uL(".nes"), usizeof(ext) - 1);
} else {
// salvo l'estensione del file
ustrncpy((uTCHAR *)ext, last_dot, usizeof(ext) - 1);
}

return (ext);
}

INLINE static void emu_frame_started(void) {
info.lag_frame.next = TRUE;
Expand Down Expand Up @@ -1617,6 +1633,8 @@ INLINE static void emu_frame_sleep(void) {
static BYTE emu_ctrl_if_rom_exist(void) {
BYTE found = FALSE;

umemset(info.rom.compress_file, 0x00, usizeof(info.rom.compress_file));

if (info.rom.from_load_menu) {
ustrncpy(info.rom.change_rom, info.rom.from_load_menu, usizeof(info.rom.change_rom));
info.rom.change_rom[usizeof(info.rom.change_rom) - 1] = 0x00;
Expand Down Expand Up @@ -1657,6 +1675,7 @@ static BYTE emu_ctrl_if_rom_exist(void) {
if (is_rom) {
switch ((rc = uncompress_archive_extract_file(archive, UNCOMPRESS_TYPE_ROM))) {
case UNCOMPRESS_EXIT_OK:
ustrncpy(info.rom.compress_file, archive->file, usizeof(info.rom.compress_file) - 1);
ustrncpy(info.rom.change_rom, uncompress_archive_extracted_file_name(archive, UNCOMPRESS_TYPE_ROM),
usizeof(info.rom.change_rom) - 1);
found = TRUE;
Expand Down Expand Up @@ -1716,23 +1735,6 @@ static BYTE emu_ctrl_if_rom_exist(void) {

return (EXIT_OK);
}
static uTCHAR *emu_ctrl_rom_ext(uTCHAR *file) {
static uTCHAR ext[10];
uTCHAR name_file[255], *last_dot = NULL;

gui_utf_basename(file, name_file, usizeof(name_file));

last_dot = ustrrchr(name_file, uL('.'));

if (last_dot == NULL) {
ustrncpy((uTCHAR *)ext, uL(".nes"), usizeof(ext) - 1);
} else {
// salvo l'estensione del file
ustrncpy((uTCHAR *)ext, last_dot, usizeof(ext) - 1);
}

return (ext);
}
static void emu_recent_roms_add(BYTE *add, uTCHAR *file) {
if ((*add)) {
(*add) = FALSE;
Expand Down
1 change: 1 addition & 0 deletions src/core/emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ EXTERNC void emu_save_header_info(void);
EXTERNC BYTE emu_active_nidx(void);
EXTERNC void emu_invert_bytes(BYTE *b0, BYTE *b1);
EXTERNC double emu_ms_to_cpu_cycles(double ms);
EXTERNC uTCHAR *emu_ctrl_rom_ext(uTCHAR *file);

#undef EXTERNC

Expand Down
Loading

0 comments on commit 1bae89a

Please sign in to comment.