Skip to content

Commit

Permalink
Implementato estrazione e inserimento automatico del disco.
Browse files Browse the repository at this point in the history
Quando si cambia il disco o si fa la switch del lato (ALT+S) non sarà
più necessario prima estrarlo e poi inserirlo.
  • Loading branch information
punesemu committed Nov 13, 2017
1 parent d5d9519 commit 7006fd0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
15 changes: 0 additions & 15 deletions src/core/cpu_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,6 @@ static BYTE INLINE fds_rd_mem(WORD address, BYTE made_tick) {
} else if (!fds.drive.scan) {
cpu.openbus |= 0x02;
}
#if !defined (RELEASE)
//fprintf(stderr, "0x%04X 0x%02X\n", address, cpu.openbus);
#endif
return (TRUE);
}
if (address == 0x4033) {
Expand Down Expand Up @@ -2016,7 +2013,6 @@ static BYTE INLINE fds_wr_mem(WORD address, BYTE value) {
if (!fds.drive.enabled_dsk_reg) {
return (TRUE);
}

fds.drive.data_external_connector = value;
return (TRUE);
}
Expand All @@ -2028,51 +2024,43 @@ static BYTE INLINE fds_wr_mem(WORD address, BYTE value) {
if (fds.drive.enabled_snd_reg) {
if ((address >= 0x4040) && (address <= 0x407F)) {
fds.snd.wave.data[address & 0x003F] = value & 0x3F;

return (TRUE);
}
if (address == 0x4080) {
fds.snd.volume.speed = value & 0x3F;
fds.snd.volume.increase = value & 0x40;
fds.snd.volume.mode = value & 0x80;

return (TRUE);
}
if (address == 0x4082) {
fds.snd.main.frequency = (fds.snd.main.frequency & 0xFF00) | value;

return (TRUE);
}
if (address == 0x4083) {
fds.snd.main.frequency = ((value & 0x0F) << 8) | (fds.snd.main.frequency & 0x00FF);
fds.snd.envelope.disabled = value & 0x40;
fds.snd.main.silence = value & 0x80;

return (TRUE);
}
if (address == 0x4084) {
fds.snd.sweep.speed = value & 0x3F;
fds.snd.sweep.increase = value & 0x40;
fds.snd.sweep.mode = value & 0x80;

return (TRUE);
}
if (address == 0x4085) {
fds.snd.sweep.bias = ((SBYTE) (value << 1)) / 2;
fds.snd.modulation.index = 0;

return (TRUE);
}
if (address == 0x4086) {
fds.snd.modulation.frequency = (fds.snd.modulation.frequency & 0xFF00) | value;

return (TRUE);
}
if (address == 0x4087) {
fds.snd.modulation.frequency = ((value & 0x0F) << 8)
| (fds.snd.modulation.frequency & 0x00FF);
fds.snd.modulation.disabled = value & 0x80;

return (TRUE);
}
if (address == 0x4088) {
Expand All @@ -2090,18 +2078,15 @@ static BYTE INLINE fds_wr_mem(WORD address, BYTE value) {
}
fds.snd.modulation.data[a + 1] = fds.snd.modulation.data[a];
}

return (TRUE);
}
if (address == 0x4089) {
fds.snd.wave.writable = value & 0x80;
fds.snd.wave.volume = value & 0x03;

return (TRUE);
}
if (address == 0x408A) {
fds.snd.envelope.speed = value;

return (TRUE);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/core/fds.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ typedef struct _fds_diff_ele {
void fds_init(void) {
memset(&fds, 0x00, sizeof(fds));

fds.side.change.new_side = 0xFF;

fds.drive.disk_ejected = TRUE;
fds.drive.motor_on = TRUE;
fds.drive.enabled_dsk_reg = 0x01;
Expand Down Expand Up @@ -249,9 +251,7 @@ void fds_disk_op(WORD type, BYTE side_to_insert) {
#endif

fds.side.data = (WORD *) malloc(fds.info.sides_size[side_to_insert] * sizeof(WORD));

fds.side.counted_files = 0xFFFF;

break;
}

Expand Down Expand Up @@ -405,10 +405,12 @@ void fds_disk_op(WORD type, BYTE side_to_insert) {
break;
case FDS_DISK_SELECT_AND_INSERT:
type = FDS_DISK_INSERT;
fds.side.change.new_side = 0xFF;
fds.drive.side_inserted = side_to_insert;
fds_diff_op(FDS_OP_READ, 0, 0);
goto fds_disk_op_start;
case FDS_DISK_SELECT:
fds.side.change.new_side = 0xFF;
fds.drive.side_inserted = side_to_insert;
text_add_line_info(1, "Disk [cyan]%d [normal]side [cyan]%c [brown]selected",
(fds.drive.side_inserted / 2) + 1, (fds.drive.side_inserted & 0x01) + 'A');
Expand Down
4 changes: 4 additions & 0 deletions src/core/fds.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ EXTERNC struct _fds {
uint32_t position;
} block_4;
} file[0xFF];
struct _fds_side_change {
BYTE new_side;
uint32_t delay;
} change;
WORD *data;
uint32_t counted_files;
} side;
Expand Down
8 changes: 8 additions & 0 deletions src/core/mappers/mapper_FDS.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ void extcl_cpu_every_cycle_FDS(void) {
}
}

/* se c'e' un delay aspetto */
if (fds.side.change.delay > 0) {
if (!(--fds.side.change.delay)) {
fds_disk_op(FDS_DISK_SELECT_AND_INSERT, fds.side.change.new_side);
}
return;
}

/* no disco, no party */
if (fds.drive.disk_ejected) {
fds.drive.delay = 1000;
Expand Down
23 changes: 18 additions & 5 deletions src/gui/mainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,12 @@ void mainWindow::ctrl_disk_side(QAction *action) {
} else {
action->setEnabled(false);
}
if (side == fds.drive.side_inserted) {

if (fds.side.change.new_side == 0xFF) {
if (side == fds.drive.side_inserted) {
action->setChecked(true);
}
} else if (side == fds.side.change.new_side) {
action->setChecked(true);
}
}
Expand Down Expand Up @@ -1821,17 +1826,25 @@ void mainWindow::s_disk_side() {
int side = QVariant(((QObject *)sender())->property("myValue")).toInt();

if (side == 0xFFF) {
side = fds.drive.side_inserted;
if (++side >= fds.info.total_sides) {
side = 0;
side = fds.drive.side_inserted ^ 0x01;
if (side >= fds.info.total_sides) {
return;
}
}

if (fds.drive.side_inserted == side) {
return;
}

fds_disk_op(FDS_DISK_SELECT, side);
if (fds.drive.disk_ejected) {
fds.side.change.new_side = 0xFF;
fds.side.change.delay = 0;
fds_disk_op(FDS_DISK_SELECT, side);
} else {
fds.side.change.new_side = side;
fds.side.change.delay = 3000000;
fds_disk_op(FDS_DISK_EJECT, 0);
}

update_menu_nes();
}
Expand Down

0 comments on commit 7006fd0

Please sign in to comment.