Skip to content

Commit

Permalink
[FDS] Fixed initialization of fds.info structure on disk change (#396).
Browse files Browse the repository at this point in the history
Thanks to TakuikaNinja for his help and support.
  • Loading branch information
punesemu committed May 11, 2024
1 parent 4bed752 commit 5448b15
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
14 changes: 9 additions & 5 deletions src/core/fds.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ BYTE fds_load_rom(BYTE format) {
fds.info.expcted_sides = fds.info.total_sides;
fds.info.write_protected = 0x00;
fds.info.cycles_8bit_delay = emu_ms_to_cpu_cycles(FDS_8BIT_MS_DELAY);
fds.info.cycles_insert_delay = emu_ms_to_cpu_cycles(FDS_INSERT_MS_DELAY);
fds.info.cycles_dummy_delay = emu_ms_to_cpu_cycles(FDS_OP_SIDE_MS_DELAY);

// converto nel mio formato immagine
Expand Down Expand Up @@ -367,6 +368,8 @@ BYTE fds_change_disk(uTCHAR *file) {
_fds_info finfo;
FILE *fp = NULL;

fds_free_fds_info();

memset(&finfo, 0x00, sizeof(_fds_info));
umemset(&path[0], 0x00, usizeof(path));
ustrncpy(path, file, usizeof(path) - 1);
Expand Down Expand Up @@ -444,10 +447,15 @@ BYTE fds_change_disk(uTCHAR *file) {
position = 0;
}

info.format = finfo.format;
ustrncpy(info.rom.file, path, usizeof(info.rom.file));

finfo.expcted_sides = finfo.total_sides;
finfo.write_protected = 0x00;
finfo.enabled = fds.info.enabled;
finfo.writings_occurred = FALSE;
finfo.cycles_8bit_delay = fds.info.cycles_8bit_delay;
finfo.cycles_insert_delay = fds.info.cycles_insert_delay;
finfo.cycles_dummy_delay = fds.info.cycles_dummy_delay;

// converto nel mio formato immagine
Expand All @@ -461,10 +469,6 @@ BYTE fds_change_disk(uTCHAR *file) {

finfo.frame_insert = nes[0].p.ppu.frames;

info.format = finfo.format;
ustrncpy(info.rom.file, path, usizeof(info.rom.file));

fds_free_fds_info();
memcpy(&fds.info, &finfo, sizeof(_fds_info));
fds_info();

Expand Down Expand Up @@ -588,7 +592,7 @@ void fds_disk_op(WORD type, BYTE side_to_insert, BYTE quiet) {
fds.drive.transfer_reset = 0x02;
fds.drive.motor_started = FALSE;
fds.drive.delay_8bit = 0;
fds.drive.delay_insert = FDS_DELAY_INSERT;
fds.drive.delay_insert = fds.info.cycles_insert_delay;
fds.auto_insert.r4032.frames = 0;
fds.auto_insert.r4032.checks = 0;
if (!quiet) {
Expand Down
4 changes: 3 additions & 1 deletion src/core/fds.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ enum fds_misc {
FDS_DISK_BLOCK_MARK = 0x80,
FDS_AUTOINSERT_R4032_MAX_CHECKS = 7,
FDS_MIN_LAG_FRAMES = 20,
FDS_DELAY_INSERT = 90000,
FDS_IMAGE_SIDE_SIZE = 75500,
DISK_FDS_SIDE_SIZE = 65500,
DISK_QD_SIDE_SIZE = 65536,
Expand All @@ -64,6 +63,8 @@ enum fds_misc {
// Aspic (1988)(Bothtec)(J) necessita di almeno 1500 ms
// Pulsar no Hikari - Space Wars Simulation (Japan) di almeno 1600 ms
#define FDS_OP_SIDE_MS_DELAY 1600.0f
// Kosodate Gokko (Japan) (Unl) ha un delay di 78 ms
#define FDS_INSERT_MS_DELAY 74.0f

#define fds_auto_insert_enabled() (cfg->fds_switch_side_automatically & !fds.auto_insert.disabled & !fds.bios.first_run)
#define fds_reset_envelope_counter(env) (fds.snd.envelope.speed << 3) * (fds.snd.env.speed + 1)
Expand Down Expand Up @@ -100,6 +101,7 @@ typedef struct _fds_info {
BYTE last_operation;
BYTE frame_insert;
uint32_t cycles_8bit_delay;
uint32_t cycles_insert_delay;
uint32_t cycles_dummy_delay;
_fds_info_protection protection;
_fds_info_side sides[20];
Expand Down
16 changes: 9 additions & 7 deletions src/core/mappers/mapper_FDS.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ void extcl_cpu_every_cycle_FDS(BYTE nidx) {

fds.drive.scan = FALSE;
fds.info.last_operation = FDS_OP_NONE;
fds.drive.data_available = FALSE;

if (fds.drive.motor_started) {
fds.drive.scan = !fds.drive.transfer_reset;
Expand Down Expand Up @@ -327,24 +326,27 @@ void extcl_cpu_every_cycle_FDS(BYTE nidx) {
fds.auto_insert.r4032.checks = 0;

if (transfer) {
fds.drive.data_available = 0x80;
fds.drive.transfer_flag = 0x02;

if (fds.drive.irq_disk_enabled) {
nes[nidx].c.irq.high |= FDS_DISK_IRQ;
}
if (fds.drive.io_mode) {
fds.drive.data_io = data;
fds.info.last_operation = FDS_OP_READ;
if (!fds.drive.data_available) {
fds.info.last_operation = FDS_OP_READ;
}
} else {
fds.side.info->data[fds.drive.disk_position] = data;
fds.info.writings_occurred = TRUE;
fds.info.last_operation = FDS_OP_WRITE;
if (!fds.drive.data_available) {
fds.info.last_operation = FDS_OP_WRITE;
}
}
fds.drive.data_available = 0x80;
fds.drive.transfer_flag = 0x02;
}
}
if (++fds.drive.disk_position >= fds.info.sides[fds.drive.side_inserted].size) {
fds.drive.delay_insert = FDS_DELAY_INSERT;
fds.drive.delay_insert = fds.info.cycles_insert_delay;
fds.drive.end_of_head = 0x40;
// Bishoujo Alien Battle (Japan) (Unl).fds non esegue la routine a 0xE188
fds.auto_insert.in_game = TRUE;
Expand Down

0 comments on commit 5448b15

Please sign in to comment.