From c26b5dadc48ad48d8a8cbbad082cb951dfca08e1 Mon Sep 17 00:00:00 2001 From: Robbbert Date: Sun, 24 May 2015 13:58:21 +1000 Subject: (MESS) camplynx: added TAP cassette format. --- scripts/src/lib.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'scripts/src/lib.lua') diff --git a/scripts/src/lib.lua b/scripts/src/lib.lua index d4738644375..54540f0f630 100644 --- a/scripts/src/lib.lua +++ b/scripts/src/lib.lua @@ -168,6 +168,8 @@ project "formats" MAME_DIR .. "src/lib/formats/c4040_dsk.h", MAME_DIR .. "src/lib/formats/c8280_dsk.c", MAME_DIR .. "src/lib/formats/c8280_dsk.h", + MAME_DIR .. "src/lib/formats/camplynx_cas.c", + MAME_DIR .. "src/lib/formats/camplynx_cas.h", MAME_DIR .. "src/lib/formats/cbm_crt.c", MAME_DIR .. "src/lib/formats/cbm_crt.h", MAME_DIR .. "src/lib/formats/cbm_tap.c", -- cgit v1.2.3 From d08d7c094d671562ec513c32e72d4fa462e639dc Mon Sep 17 00:00:00 2001 From: Dirk Best Date: Wed, 27 May 2015 16:44:18 +0200 Subject: bbc: Update to use the new wd_fdc. Until the 8271 floppy controller is updated, drive 0 and 1 = 8271 and drive 2 and 3 = wd_fdc. --- scripts/src/lib.lua | 2 + src/lib/formats/bbc_dsk.c | 53 +++++++++++++++++++++++++ src/lib/formats/bbc_dsk.h | 33 ++++++++++++++++ src/mess/drivers/bbc.c | 62 ++++++++++++++++++++--------- src/mess/includes/bbc.h | 4 +- src/mess/machine/bbc.c | 99 ++++++++++++++++++++++++++++------------------- 6 files changed, 194 insertions(+), 59 deletions(-) create mode 100644 src/lib/formats/bbc_dsk.c create mode 100644 src/lib/formats/bbc_dsk.h (limited to 'scripts/src/lib.lua') diff --git a/scripts/src/lib.lua b/scripts/src/lib.lua index 54540f0f630..a4bca8d6c50 100644 --- a/scripts/src/lib.lua +++ b/scripts/src/lib.lua @@ -158,6 +158,8 @@ project "formats" MAME_DIR .. "src/lib/formats/atarist_dsk.h", MAME_DIR .. "src/lib/formats/atom_tap.c", MAME_DIR .. "src/lib/formats/atom_tap.h", + MAME_DIR .. "src/lib/formats/bbc_dsk.c", + MAME_DIR .. "src/lib/formats/bbc_dsk.h", MAME_DIR .. "src/lib/formats/bw2_dsk.c", MAME_DIR .. "src/lib/formats/bw2_dsk.h", MAME_DIR .. "src/lib/formats/bw12_dsk.c", diff --git a/src/lib/formats/bbc_dsk.c b/src/lib/formats/bbc_dsk.c new file mode 100644 index 00000000000..dfa78c0bfd8 --- /dev/null +++ b/src/lib/formats/bbc_dsk.c @@ -0,0 +1,53 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + BBC Micro + + Disk image format + +***************************************************************************/ + +#include "bbc_dsk.h" + +bbc_format::bbc_format() : wd177x_format(formats) +{ +} + +const char *bbc_format::name() const +{ + return "bbc"; +} + +const char *bbc_format::description() const +{ + return "BBC Micro disk image"; +} + +const char *bbc_format::extensions() const +{ + return "bbc,img,ssd,dsd"; +} + +const bbc_format::format bbc_format::formats[] = +{ + { // 100k single sided single density + floppy_image::FF_525, floppy_image::SSSD, floppy_image::FM, + 4000, 10, 40, 1, 256, {}, 0, {}, 16, 11, 19 + }, + { // 200k double sided single density + floppy_image::FF_525, floppy_image::DSSD, floppy_image::FM, + 4000, 10, 40, 2, 256, {}, 0, {}, 16, 11, 19 + }, + { // 200k single sided double density + floppy_image::FF_525, floppy_image::SSQD, floppy_image::FM, + 4000, 10, 80, 1, 256, {}, 0, {}, 16, 11, 19 + }, + { // 400k double sided double density + floppy_image::FF_525, floppy_image::DSQD, floppy_image::FM, + 4000, 10, 80, 2, 256, {}, 0, {}, 16, 11, 19 + }, + {} +}; + +const floppy_format_type FLOPPY_BBC_FORMAT = &floppy_image_format_creator; diff --git a/src/lib/formats/bbc_dsk.h b/src/lib/formats/bbc_dsk.h new file mode 100644 index 00000000000..e2520781a15 --- /dev/null +++ b/src/lib/formats/bbc_dsk.h @@ -0,0 +1,33 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + BBC Micro + + Disk image format + +***************************************************************************/ + +#pragma once + +#ifndef __BBC_DSK_H__ +#define __BBC_DSK_H__ + +#include "wd177x_dsk.h" + +class bbc_format : public wd177x_format +{ +public: + bbc_format(); + + virtual const char *name() const; + virtual const char *description() const; + virtual const char *extensions() const; + +private: + static const format formats[]; +}; + +extern const floppy_format_type FLOPPY_BBC_FORMAT; + +#endif // __BBC_DSK_H__ diff --git a/src/mess/drivers/bbc.c b/src/mess/drivers/bbc.c index ca639730143..de7f17dee44 100644 --- a/src/mess/drivers/bbc.c +++ b/src/mess/drivers/bbc.c @@ -57,6 +57,7 @@ /* Devices */ #include "imagedev/flopdrv.h" +#include "formats/bbc_dsk.h" #include "formats/basicdsk.h" #include "imagedev/cassette.h" #include "formats/uef_cas.h" @@ -609,6 +610,19 @@ static const floppy_interface bbc_floppy_interface = "floppy_5_25" }; +FLOPPY_FORMATS_MEMBER( bbc_state::floppy_formats ) + FLOPPY_BBC_FORMAT +FLOPPY_FORMATS_END + +static SLOT_INTERFACE_START( bbc_floppies ) + SLOT_INTERFACE("sssd", FLOPPY_525_SSSD) + SLOT_INTERFACE("sd", FLOPPY_525_SD) + SLOT_INTERFACE("ssdd", FLOPPY_525_SSDD) + SLOT_INTERFACE("dd", FLOPPY_525_DD) + SLOT_INTERFACE("ssqd", FLOPPY_525_SSQD) + SLOT_INTERFACE("qd", FLOPPY_525_QD) +SLOT_INTERFACE_END + WRITE_LINE_MEMBER(bbc_state::econet_clk_w) { m_adlc->rxc_w(state); @@ -760,13 +774,15 @@ static MACHINE_CONFIG_DERIVED( bbcb, bbca ) MCFG_I8271_IRQ_CALLBACK(WRITELINE(bbc_state, bbc_i8271_interrupt)) MCFG_I8271_FLOPPIES(FLOPPY_0, FLOPPY_1) - MCFG_DEVICE_ADD("wd177x", WD1770, 0) - MCFG_WD17XX_DEFAULT_DRIVE2_TAGS - MCFG_WD17XX_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) - MCFG_WD17XX_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) - MCFG_LEGACY_FLOPPY_2_DRIVES_ADD(bbc_floppy_interface) + MCFG_WD1770x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) + MCFG_WD_FDC_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + + MCFG_FLOPPY_DRIVE_ADD("wd177x:0", bbc_floppies, "qd", bbc_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd177x:1", bbc_floppies, "qd", bbc_state::floppy_formats) + /* software lists */ MCFG_DEVICE_REMOVE("cass_ls_a") MCFG_SOFTWARE_LIST_ADD("cass_ls_b", "bbcb_cass") @@ -822,13 +838,15 @@ static MACHINE_CONFIG_DERIVED( bbcb_us, bbca ) MCFG_I8271_IRQ_CALLBACK(WRITELINE(bbc_state, bbc_i8271_interrupt)) MCFG_I8271_FLOPPIES(FLOPPY_0, FLOPPY_1) - MCFG_DEVICE_ADD("wd177x", WD1770, 0) - MCFG_WD17XX_DEFAULT_DRIVE2_TAGS - MCFG_WD17XX_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) - MCFG_WD17XX_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) - MCFG_LEGACY_FLOPPY_2_DRIVES_ADD(bbc_floppy_interface) + MCFG_WD1770x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) + MCFG_WD_FDC_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + + MCFG_FLOPPY_DRIVE_ADD("wd177x:0", bbc_floppies, "qd", bbc_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd177x:1", bbc_floppies, "qd", bbc_state::floppy_formats) + /* software lists */ MCFG_DEVICE_REMOVE("cass_ls_a") MCFG_SOFTWARE_LIST_ADD("cass_ls_b", "bbcb_cass") @@ -852,6 +870,8 @@ static MACHINE_CONFIG_DERIVED( bbcbp, bbcb ) /* fdc */ MCFG_DEVICE_REMOVE("i8271") + MCFG_DEVICE_REMOVE(FLOPPY_0) + MCFG_DEVICE_REMOVE(FLOPPY_1) MACHINE_CONFIG_END @@ -981,12 +1001,12 @@ static MACHINE_CONFIG_START( bbcm, bbc_state ) MCFG_VIA6522_IRQ_HANDLER(WRITELINE(bbc_state, bbcb_via_user_irq_w)) /* fdc */ - MCFG_DEVICE_ADD("wd177x", WD1770, 0) - MCFG_WD17XX_DEFAULT_DRIVE2_TAGS - MCFG_WD17XX_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) - MCFG_WD17XX_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + MCFG_WD1770x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) + MCFG_WD_FDC_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) - MCFG_LEGACY_FLOPPY_2_DRIVES_ADD(bbc_floppy_interface) + MCFG_FLOPPY_DRIVE_ADD("wd177x:0", bbc_floppies, "qd", bbc_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd177x:1", bbc_floppies, "qd", bbc_state::floppy_formats) /* econet */ MCFG_DEVICE_ADD("mc6854", MC6854, 0) @@ -1068,10 +1088,14 @@ static MACHINE_CONFIG_DERIVED( bbcmc, bbcm ) /* fdc */ MCFG_DEVICE_REMOVE("wd177x") - MCFG_DEVICE_ADD("wd177x", WD1772, 0) - MCFG_WD17XX_DEFAULT_DRIVE2_TAGS - MCFG_WD17XX_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) - MCFG_WD17XX_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + +// MCFG_WD1772x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD1770x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) + MCFG_WD_FDC_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + + MCFG_FLOPPY_DRIVE_ADD("wd177x:0", bbc_floppies, "qd", bbc_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd177x:1", bbc_floppies, "qd", bbc_state::floppy_formats) /* software lists */ MCFG_SOFTWARE_LIST_REMOVE("cart_ls_m") diff --git a/src/mess/includes/bbc.h b/src/mess/includes/bbc.h index 98e1c9b5a6c..11bd1c13eb1 100644 --- a/src/mess/includes/bbc.h +++ b/src/mess/includes/bbc.h @@ -20,7 +20,7 @@ #include "machine/mc6854.h" #include "machine/ram.h" #include "machine/i8271.h" -#include "machine/wd17xx.h" +#include "machine/wd_fdc.h" #include "machine/upd7002.h" #include "video/mc6845.h" #include "video/saa5050.h" @@ -80,6 +80,8 @@ public: m_palette(*this, "palette") { } + DECLARE_FLOPPY_FORMATS(floppy_formats); + DECLARE_WRITE8_MEMBER(bbc_page_selecta_w); DECLARE_WRITE8_MEMBER(bbc_memorya1_w); DECLARE_WRITE8_MEMBER(bbc_page_selectb_w); diff --git a/src/mess/machine/bbc.c b/src/mess/machine/bbc.c index efc9da1102e..d0a5572540e 100644 --- a/src/mess/machine/bbc.c +++ b/src/mess/machine/bbc.c @@ -17,7 +17,7 @@ #include "cpu/m6502/m6502.h" #include "sound/tms5220.h" #include "machine/6522via.h" -#include "machine/wd17xx.h" +#include "machine/wd_fdc.h" #include "imagedev/flopdrv.h" #include "includes/bbc.h" #include "machine/mc146818.h" @@ -1576,7 +1576,7 @@ void bbc_state::bbc_update_fdq_int(int state) /* do not trigger int */ bbc_state = 0; } - +//printf("bbc_state %d prev %d\n", bbc_state, m_previous_wd177x_int_state); /* nmi is edge triggered, and triggers when the state goes from clear->set. Here we are checking this transition before triggering the nmi */ if (bbc_state!=m_previous_wd177x_int_state) @@ -1594,6 +1594,7 @@ void bbc_state::bbc_update_fdq_int(int state) WRITE_LINE_MEMBER(bbc_state::bbc_wd177x_intrq_w) { +//printf("bbc_wd177x_intrq_w %d \n", state); m_wd177x_irq_state = state; bbc_update_fdq_int(state); } @@ -1606,20 +1607,28 @@ WRITE_LINE_MEMBER(bbc_state::bbc_wd177x_drq_w) WRITE8_MEMBER(bbc_state::bbc_wd177x_status_w) { - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); + floppy_image_device *floppy0 = machine().device("wd177x:0")->get_device(); + floppy_image_device *floppy1 = machine().device("wd177x:1")->get_device(); + floppy_image_device *floppy = NULL; + m_drive_control = data; - /* set drive */ - if ((data>>0) & 0x01) fdc->set_drive(0); - if ((data>>1) & 0x01) fdc->set_drive(1); + // bit 0, 1: drive select + if (BIT(data, 0)) floppy = floppy0; + if (BIT(data, 1)) floppy = floppy1; + + fdc->set_floppy(floppy); - /* set side */ - fdc->set_side((data>>2) & 0x01); + // bit 2: side select + if (floppy) + floppy->ss_w(BIT(data, 2)); - /* set density */ + // bit 3: density fdc->dden_w(BIT(data, 3)); - m_1770_IntEnabled=(((data>>4) & 0x01)==0); + // bit 4: interrupt enable + m_1770_IntEnabled = !BIT(data, 4); } @@ -1627,7 +1636,7 @@ WRITE8_MEMBER(bbc_state::bbc_wd177x_status_w) READ8_MEMBER(bbc_state::bbc_wd1770_read) { int retval=0xff; - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); switch (offset) { case 4: @@ -1645,22 +1654,22 @@ READ8_MEMBER(bbc_state::bbc_wd1770_read) default: break; } - logerror("wd177x read: $%02X $%02X\n", offset,retval); + //logerror("wd177x read: $%02X $%02X\n", offset,retval); return retval; } WRITE8_MEMBER(bbc_state::bbc_wd1770_write) { - wd1770_device *fdc = machine().device("wd177x"); - logerror("wd177x write: $%02X $%02X\n", offset,data); + wd1770_t *fdc = machine().device("wd177x"); + //logerror("wd177x write: $%02X $%02X\n", offset,data); switch (offset) { case 0: bbc_wd177x_status_w(space, 0, data); break; case 4: - fdc->command_w(space, 0, data); + fdc->cmd_w(space, 0, data); break; case 5: fdc->track_w(space, 0, data); @@ -1715,26 +1724,34 @@ AM_RANGE(0xfc00, 0xfdff) AM_READWRITE(bbc_opus_read , bbc_opus_write ) WRITE8_MEMBER(bbc_state::bbc_opus_status_w) { - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); + floppy_image_device *floppy0 = machine().device("wd177x:0")->get_device(); + floppy_image_device *floppy1 = machine().device("wd177x:1")->get_device(); + floppy_image_device *floppy = NULL; + m_drive_control = data; - /* set drive */ - if ((data>>1) & 0x01) fdc->set_drive(0); - if ((data>>2) & 0x01) fdc->set_drive(1); + // bit 1, 2: drive select + if (BIT(data, 1)) floppy = floppy0; + if (BIT(data, 2)) floppy = floppy1; - /* set side */ - fdc->set_side((data>>0) & 0x01); + fdc->set_floppy(floppy); - /* set density */ + // bit 0: side select + if (floppy) + floppy->ss_w(BIT(data, 0)); + + // bit 5: density fdc->dden_w(BIT(data, 5)); - m_1770_IntEnabled=(data>>4) & 0x01; + // bit 4: interrupt enable + m_1770_IntEnabled = BIT(data, 4); } READ8_MEMBER(bbc_state::bbc_opus_read) { - wd1770_device *fdc = machine().device("wd177x"); - logerror("wd177x read: $%02X\n", offset); + wd1770_t *fdc = machine().device("wd177x"); + //logerror("wd177x read: $%02X\n", offset); if (m_DFSType==6) { @@ -1762,8 +1779,8 @@ READ8_MEMBER(bbc_state::bbc_opus_read) WRITE8_MEMBER(bbc_state::bbc_opus_write) { - wd1770_device *fdc = machine().device("wd177x"); - logerror("wd177x write: $%02X $%02X\n", offset,data); + wd1770_t *fdc = machine().device("wd177x"); + //logerror("wd177x write: $%02X $%02X\n", offset,data); if (m_DFSType==6) { @@ -1772,7 +1789,7 @@ WRITE8_MEMBER(bbc_state::bbc_opus_write) switch (offset) { case 0xf8: - fdc->command_w(space, 0, data); + fdc->cmd_w(space, 0, data); break; case 0xf9: fdc->track_w(space, 0, data); @@ -1810,7 +1827,7 @@ BBC MASTER DISC SUPPORT READ8_MEMBER(bbc_state::bbcm_wd1770_read) { int retval=0xff; - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); switch (offset) { case 0: @@ -1834,12 +1851,12 @@ READ8_MEMBER(bbc_state::bbcm_wd1770_read) WRITE8_MEMBER(bbc_state::bbcm_wd1770_write) { - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); //logerror("wd177x write: $%02X $%02X\n", offset,data); switch (offset) { case 0: - fdc->command_w(space, 0, data); + fdc->cmd_w(space, 0, data); break; case 1: fdc->track_w(space, 0, data); @@ -1863,22 +1880,26 @@ READ8_MEMBER(bbc_state::bbcm_wd1770l_read) WRITE8_MEMBER(bbc_state::bbcm_wd1770l_write) { - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); + floppy_image_device *floppy0 = machine().device("wd177x:0")->get_device(); + floppy_image_device *floppy1 = machine().device("wd177x:1")->get_device(); + floppy_image_device *floppy = NULL; + m_drive_control = data; - /* set drive */ - if ((data>>0) & 0x01) fdc->set_drive(0); - if ((data>>1) & 0x01) fdc->set_drive(1); + // bit 0, 1: drive select + if (BIT(data, 0)) floppy = floppy0; + if (BIT(data, 1)) floppy = floppy1; - /* set side */ - fdc->set_side((data>>4) & 0x01); + // bit 4: side select + if (floppy) + floppy->ss_w(BIT(data, 4)); - /* set density */ + // bit 5: density fdc->dden_w(BIT(data, 5)); // m_1770_IntEnabled=(((data>>4) & 0x01)==0); m_1770_IntEnabled=1; - } -- cgit v1.2.3 From 05664c66570fb8df774708cc2c1b2cebda623ab5 Mon Sep 17 00:00:00 2001 From: Dirk Best Date: Thu, 28 May 2015 17:26:35 +0200 Subject: z80ne: updated to use the new wd fdc. remove custom dmk implementation --- scripts/src/lib.lua | 2 - src/lib/formats/z80ne_dsk.c | 807 -------------------------------------------- src/lib/formats/z80ne_dsk.h | 24 -- src/mess/drivers/z80ne.c | 24 +- src/mess/includes/z80ne.h | 14 +- src/mess/machine/z80ne.c | 49 ++- 6 files changed, 46 insertions(+), 874 deletions(-) delete mode 100644 src/lib/formats/z80ne_dsk.c delete mode 100644 src/lib/formats/z80ne_dsk.h (limited to 'scripts/src/lib.lua') diff --git a/scripts/src/lib.lua b/scripts/src/lib.lua index a4bca8d6c50..166ab4beddb 100644 --- a/scripts/src/lib.lua +++ b/scripts/src/lib.lua @@ -393,8 +393,6 @@ project "formats" MAME_DIR .. "src/lib/formats/x1_tap.h", MAME_DIR .. "src/lib/formats/xdf_dsk.c", MAME_DIR .. "src/lib/formats/xdf_dsk.h", - MAME_DIR .. "src/lib/formats/z80ne_dsk.c", - MAME_DIR .. "src/lib/formats/z80ne_dsk.h", MAME_DIR .. "src/lib/formats/zx81_p.c", MAME_DIR .. "src/lib/formats/zx81_p.h", MAME_DIR .. "src/lib/formats/hxcmfm_dsk.c", diff --git a/src/lib/formats/z80ne_dsk.c b/src/lib/formats/z80ne_dsk.c deleted file mode 100644 index 1f82d844c88..00000000000 --- a/src/lib/formats/z80ne_dsk.c +++ /dev/null @@ -1,807 +0,0 @@ -// license:??? -// copyright-holders:Roberto Lavarone -/********************************************************************* - - formats/z80ne_dsk.c - - Nuova Elettronica Z80NE disk images - -*********************************************************************/ - -#include - -#include "z80ne_dsk.h" -#include "basicdsk.h" -#include "imageutl.h" -#include "coretmpl.h" - -/* ----------------------------------------------------------------------- - * DMK file format - * - * David M. Keil's disk image format is aptly called an 'on disk' image - * format. This means that whatever written to the disk is encoded into - * the image file. IDAMS, sector headers, trailing CRCs, and intra-sector - * spacing. * - * - * HEADER DESCRIPTION: - * - * Offset Bytes Field Description - * ------ ----- ------------ ----------- - * 0 1 write_prot 0xff = Write Protected, 0x00 = R/W - * 1 1 tracks Number of tracks - * 2 2 track_length Bytes per track on DMK file (little endian) - * 4 1 disk_options Miscellaneous flags - * bit 0-3: Unused - * bit 4: Sides on DMK file - * 1=single, 0=double - * bit 5: Unused - * bit 6: Single Density DMK file - * 1=single (bytes written once - * on IDAMs) - * 0=double (bytes written - * two times for SD IDAMs) - * 5 7 reserved Reserved for future use - * 12 4 real_disk_code If this is 0x12345678 (little endian) - * then access a real disk drive - * (unsupported) - * - * Each track begins with a track TOC, consisting of 64 little endian 16-bit - * integers. Each integer has the following format: - * bit 0-13: Offset from beginning of track to 'FE' byte of IDAM - * Note these are always sorted from first to last. All empty - * entries are 0x00 - * bit 14: Undefined (reserved) - * bit 15: Sector double density (0=SD 1=DD) - * If not set and SD DMK flag is set then bytes are written - * once. - * ----------------------------------------------------------------------- */ - -struct dmk_tag -{ - int heads; - int tracks; - UINT32 track_size; -}; - -/* DMK file structure - * See WD1711 documentation - */ -/* DMK file header */ -#define DMK_HEADER_LEN 16 /* DMK header */ - /* For every track (40) */ - #define DMK_TOC_LEN 128 /* 64 16-bit relative offsets to IDAMs */ - #define DMK_GAP1_LEN 32 /* GAP1 (26 bytes 0xFF and 6 bytes 0x00) */ - - /* For every sector (10) 301 bytes */ - #define DMK_IDAM_LEN 7 /* IDAM (0xFE, Track, 0x00, Sector, 0x00, CRChi, CRClo) */ - #define DMK_ID_GAP_LEN 17 /* GAP2 (11 bytes 0xFF and 6 bytes 0x00) */ - #define DMK_DAM_LEN 1 /* Data Address Mark (0xFB) */ - #define DMK_DATA_LEN 256 /* Data */ - #define DMK_DATA_CRC_LEN 2 /* Data CRC (CRChi, CRClo) */ - #define DMK_DATA_GAP_LEN 18 /* GAP3 (12 bytes 0xFF and 6 bytes 0x00) (not for last sector) */ - - #define DMK_EXTRA_TRACK_LENGTH (176) /* GAP4 (192 bytes 0xFF) */ -/* End of DMK file structure */ - -#define dmk_idam_type(x) (x)[0] -#define dmk_idam_track(x) (x)[1] -#define dmk_idam_side(x) (x)[2] -#define dmk_idam_sector(x) (x)[3] -#define dmk_idam_sectorlength(x) (x)[4] -#define dmk_idam_crc(x) (((x)[5] << 8) + (x)[6]) -#define dmk_idam_set_crc(x, crc) (x)[5] = ((crc) >> 8); (x)[6] = ((crc) >> 0); - -static const char needle_data[] = "\x00\x00\x00\x00\x00\x00\x00\x00\xFB\xFB"; -static const char needle_deleted_data_fa[] = "\x00\x00\x00\x00\x00\x00\x00\x00\xFA\xFA"; -static const char needle_deleted_data_f8[] = "\x00\x00\x00\x00\x00\x00\x00\x00\xF8\xF8"; - - -static struct dmk_tag *get_dmk_tag(floppy_image_legacy *floppy) -{ - return (dmk_tag *)floppy_tag(floppy); -} - - -static floperr_t z80ne_dmk_get_track_offset(floppy_image_legacy *floppy, int head, int track, UINT64 *offset) -{ - struct dmk_tag *tag = get_dmk_tag(floppy); - - if ((head < 0) || (head >= tag->heads) || (track < 0) || (track >= tag->tracks)) - return FLOPPY_ERROR_SEEKERROR; - - *offset = track; - *offset *= tag->heads; - *offset += head; - *offset *= tag->track_size; - *offset += DMK_HEADER_LEN; - return FLOPPY_ERROR_SUCCESS; -} - - -static UINT32 z80ne_dmk_min_track_size(int sectors, int sector_length) -{ - int sector_physical_length; - sector_physical_length = (DMK_IDAM_LEN + DMK_ID_GAP_LEN + DMK_DAM_LEN + sector_length + DMK_DATA_CRC_LEN + DMK_DATA_GAP_LEN); - return DMK_TOC_LEN + 2 * (DMK_GAP1_LEN + (sectors * sector_physical_length) - DMK_DATA_GAP_LEN + DMK_EXTRA_TRACK_LENGTH); -} - - - -static floperr_t z80ne_dmk_read_track(floppy_image_legacy *floppy, int head, int track, UINT64 offset, void *buffer, size_t buflen) -{ - floperr_t err; - UINT64 track_offset; - - err = z80ne_dmk_get_track_offset(floppy, head, track, &track_offset); - if (err) - return err; - - floppy_image_read(floppy, buffer, offset + track_offset, buflen); - return FLOPPY_ERROR_SUCCESS; -} - - - -static floperr_t z80ne_dmk_write_track(floppy_image_legacy *floppy, int head, int track, UINT64 offset, const void *buffer, size_t buflen) -{ - floperr_t err; - UINT64 track_offset; - - err = z80ne_dmk_get_track_offset(floppy, head, track, &track_offset); - if (err) - return err; - - floppy_image_write(floppy, buffer, offset + track_offset, buflen); - return FLOPPY_ERROR_SUCCESS; -} - - - -static floperr_t z80ne_dmk_get_track_data_offset(floppy_image_legacy *floppy, int head, int track, UINT64 *offset) -{ - *offset = DMK_TOC_LEN + 1; - return FLOPPY_ERROR_SUCCESS; -} - - -static floperr_t z80ne_dmk_format_track(floppy_image_legacy *floppy, int head, int track, option_resolution *params) -{ - int sectors; - int sector_length; - int interleave; - int first_sector_id; - floperr_t err; - int physical_sector; - int logical_sector; - int track_position; - UINT16 idam_offset; - UINT16 crc; - UINT8 *track_data; - void *track_data_v; - UINT32 max_track_size; - std::vector sector_map; - dynamic_buffer local_sector; - int local_sector_size; - int sector_position; - int i; - - sectors = option_resolution_lookup_int(params, PARAM_SECTORS); - sector_length = option_resolution_lookup_int(params, PARAM_SECTOR_LENGTH); - interleave = option_resolution_lookup_int(params, PARAM_INTERLEAVE); - first_sector_id = option_resolution_lookup_int(params, PARAM_FIRST_SECTOR_ID); - - max_track_size = get_dmk_tag(floppy)->track_size; - - if (sectors > DMK_TOC_LEN/2) - { - err = FLOPPY_ERROR_INTERNAL; - goto done; - } - - if (max_track_size < z80ne_dmk_min_track_size(sectors, sector_length)) - { - err = FLOPPY_ERROR_NOSPACE; - goto done; - } - - err = floppy_load_track(floppy, head, track, TRUE, &track_data_v, NULL); - if (err) - goto done; - track_data = (UINT8 *) track_data_v; - - /* set up sector map */ - sector_map.resize(sectors); - memset(§or_map, 0xff, sectors); - - physical_sector = 0; - for (logical_sector = 0; logical_sector < sectors; logical_sector++) - { - while(sector_map[physical_sector] >= 0) - { - physical_sector++; - physical_sector %= sectors; - } - - sector_map[physical_sector] = logical_sector + first_sector_id; - physical_sector += interleave + 1; - physical_sector %= sectors; - } - - /* set up a local physical sector template */ - local_sector_size = (DMK_IDAM_LEN + - DMK_ID_GAP_LEN + - DMK_DAM_LEN + - sector_length + - DMK_DATA_CRC_LEN + - DMK_DATA_GAP_LEN); - local_sector.resize(local_sector_size); - memset(&local_sector, 0, local_sector_size); - - /* set up track table of contents */ - physical_sector = 0; - - /* write GAP1 (track lead in) */ - memset(&track_data[DMK_TOC_LEN], 0xFF, 52); - memset(&track_data[DMK_TOC_LEN+52], 0x00, 12); - track_position = DMK_TOC_LEN + DMK_GAP1_LEN * 2; - - /* - * prepare template in local sector - */ - - /* IDAM */ - sector_position = 0; - dmk_idam_type( &local_sector[sector_position]) = 0xFE; - dmk_idam_track( &local_sector[sector_position]) = track; - dmk_idam_side( &local_sector[sector_position]) = head; - dmk_idam_sector( &local_sector[sector_position]) = 0; /* replace in sector instances */ - dmk_idam_sectorlength( &local_sector[sector_position]) = compute_log2(sector_length / 128); - dmk_idam_set_crc( &local_sector[sector_position], 0); /* replace in sector instances */ - sector_position += 7; - - /* GAP2 (ID GAP) */ - memset(&local_sector[sector_position], 0xFF, 11); - sector_position += 11; - memset(&local_sector[sector_position], 0x00, 6); - sector_position += 6; - - /* sector body */ - local_sector[sector_position] = 0xFB; - memset(&local_sector[sector_position + 1], floppy_get_filler(floppy), sector_length); - crc = ccitt_crc16(0xffff, &local_sector[sector_position], sector_length + 1); - local_sector[sector_position + sector_length + 1] = (UINT8) (crc >> 8); - local_sector[sector_position + sector_length + 2] = (UINT8) (crc >> 0); - sector_position += sector_length + 3; - - /* GAP3 (Data GAP) */ - memset(&local_sector[sector_position], 0xFF, 12); - sector_position += 12; - memset(&local_sector[sector_position], 0x00, 6); - sector_position += 6; - - /* - * start of track data - */ - while(physical_sector < DMK_TOC_LEN/2) - { - if (physical_sector >= sectors) - { - /* no more sectors */ - idam_offset = 0; - } - else - { - /* this is a sector */ - idam_offset = track_position; - logical_sector = sector_map[physical_sector]; - - /* update IDAM in local sector template */ - dmk_idam_sector( &local_sector[0]) = logical_sector; /* update sector number in sector instance */ - crc = ccitt_crc16(0xffff, &local_sector[0], DMK_IDAM_LEN - 2); /* and recalculate crc */ - dmk_idam_set_crc( &local_sector[0], crc); - - /* write local sector in track doubling every byte (DMK double density mode) */ - for(i=0; i> 0); - track_data[physical_sector * 2 + 1] = (UINT8) (idam_offset >> 8); - - physical_sector++; - } - - /* write track footer GAP4 */ - assert(max_track_size >= (UINT32)track_position); - memset(&track_data[track_position], 0xFF, max_track_size - track_position); - -done: - return err; -} - - - -static int z80ne_dmk_get_heads_per_disk(floppy_image_legacy *floppy) -{ - return get_dmk_tag(floppy)->heads; -} - - - -static int z80ne_dmk_get_tracks_per_disk(floppy_image_legacy *floppy) -{ - return get_dmk_tag(floppy)->tracks; -} - - - -static UINT32 z80ne_dmk_get_track_size(floppy_image_legacy *floppy, int head, int track) -{ - return get_dmk_tag(floppy)->track_size; -} - -static UINT8 * my_memmem(UINT8 *haystack, size_t haystacklen, - UINT8 *needle, size_t needlelen) -{ - register UINT8 *h = haystack; - register UINT8 *n = needle; - register size_t hl = haystacklen; - register size_t nl = needlelen; - register size_t i; - - if (nl == 0) return haystack; /* The first occurrence of the empty string is deemed to occur at - the beginning of the string. */ - if (hl < nl) - return NULL; - - for( i = 0; (i < hl) && (i + nl <= hl ); i++ ) - if (h[i] == *n) /* first match */ - if ( !memcmp(&h[i]+1, n + 1, nl - 1) ) - return (haystack+i); /* returns a pointer to the substring */ - - return (UINT8 *)NULL; /* not found */ -} - - - -static floperr_t z80ne_dmk_seek_sector_in_track(floppy_image_legacy *floppy, int head, int track, int sector, int sector_is_index, int dirtify, UINT8 **sector_data, UINT32 *sector_length) -{ - struct dmk_tag *tag = get_dmk_tag(floppy); - floperr_t err; - size_t idam_offset = 0; - UINT16 calculated_crc; - size_t i, j; - size_t offs; - /*int state;*/ - UINT8 *track_data; - void *track_data_v; - size_t track_length; - size_t sec_len; - dynamic_buffer local_idam; - int local_idam_size; - UINT8 *sec_data; - - err = floppy_load_track(floppy, head, track, dirtify, &track_data_v, &track_length); - if (err) - goto done; - track_data = (UINT8 *) track_data_v; - - /* set up a local IDAM space */ - local_idam_size = (DMK_IDAM_LEN + - DMK_ID_GAP_LEN + - DMK_DAM_LEN + - DMK_DATA_GAP_LEN); - local_idam.resize(local_idam_size); - memset(&local_idam[0], 0, local_idam_size); - - /* search for matching IDAM */ - for (i = 0; i < DMK_TOC_LEN / 2; i++) - { - idam_offset = track_data[i * 2 + 1]; - idam_offset <<= 8; - idam_offset |= track_data[i * 2 + 0]; - idam_offset &= 0x3FFF; - - if (idam_offset == 0) - { - /* we've reached the end of the road */ - i = DMK_TOC_LEN; - break; - } - - if ((idam_offset + DMK_IDAM_LEN * 2) >= tag->track_size) - continue; - - /* overflowing the track? */ - if ((idam_offset + local_idam_size * 2) >= tag->track_size) - { - err = FLOPPY_ERROR_SEEKERROR; - goto done; - } - - /* create a local copy of sector of IDAM */ - for(j = 0; j < (DMK_IDAM_LEN + DMK_ID_GAP_LEN + DMK_DAM_LEN); j++) - local_idam[j] = track_data[idam_offset + j*2]; - - /* from now on all operations are done in local copy of IDAM */ - calculated_crc = ccitt_crc16(0xffff, &local_idam[0], DMK_IDAM_LEN - 2); - - /* check IDAM integrity and check for matching sector */ - if (calculated_crc == dmk_idam_crc(&local_idam[0])) - { - if (sector_is_index) - { - /* the sector is indexed; decrement the index and go */ - if (sector-- == 0) - break; - } - else - { - /* check for matching sector ID */ - if (sector == dmk_idam_sector(&local_idam[0])) - break; - } - } - } - - if (i >= DMK_TOC_LEN / 2) - { - err = FLOPPY_ERROR_SEEKERROR; - goto done; - } - - /* we found a matching sector ID */ - /*state = 0;*/ - offs = idam_offset + 2 * DMK_IDAM_LEN; - - /* find pattern 0x0000FB; this represents the start of a data sector */ - sec_data = my_memmem(&track_data[offs], 4 * (DMK_ID_GAP_LEN + DMK_DAM_LEN), (UINT8 *)needle_data, 10); - if(!sec_data) - { - /* find pattern 0x0000FA; this represents the start of a deleted data sector (used for system sectors) */ - sec_data = my_memmem(&track_data[offs], 4 * (DMK_ID_GAP_LEN + DMK_DAM_LEN), (UINT8 *)needle_deleted_data_fa, 10); - } - if(!sec_data) - { - /* find pattern 0x0000F8; this represents the start of a deleted data sector (used for system sectors) */ - sec_data = my_memmem(&track_data[offs], 4 * (DMK_ID_GAP_LEN + DMK_DAM_LEN), (UINT8 *)needle_deleted_data_f8, 10); - } - - if(sec_data) - sec_data += 10; - else - { - err = FLOPPY_ERROR_SEEKERROR; - goto done; - } - offs = sec_data - &track_data[offs]; - - sec_len = 128 << dmk_idam_sectorlength(&local_idam[0]); - - if ((offs + 2 * sec_len) > track_length) - { - err = FLOPPY_ERROR_INVALIDIMAGE; - goto done; - } - - if (sector_data) - *sector_data = sec_data; - if (sector_length) - *sector_length = sec_len; -done: - return err; -} - - - -static floperr_t z80ne_dmk_get_sector_length(floppy_image_legacy *floppy, int head, int track, int sector, UINT32 *sector_length) -{ - return z80ne_dmk_seek_sector_in_track(floppy, head, track, sector, FALSE, FALSE, NULL, sector_length); -} - - - -static floperr_t z80ne_dmk_get_indexed_sector_info(floppy_image_legacy *floppy, int head, int track, int sector_index, int *cylinder, int *side, int *sector, UINT32 *sector_length, unsigned long *flags) -{ - floperr_t err; - size_t idam_offset; - UINT8 *track_data; - void *track_data_v; - unsigned long dam; - - if (sector_index * 2 >= DMK_TOC_LEN) - return FLOPPY_ERROR_SEEKERROR; - - err = floppy_load_track(floppy, head, track, FALSE, &track_data_v, NULL); - if (err) - return err; - track_data = (UINT8 *) track_data_v; - - idam_offset = track_data[sector_index * 2 + 1]; - idam_offset <<= 8; - idam_offset |= track_data[sector_index * 2 + 0]; - idam_offset &= 0x3FFF; - - if (idam_offset == 0) - return FLOPPY_ERROR_SEEKERROR; - - /* determine type of data sector */ - /* find pattern 0x0000FB; this represents the start of a data sector */ - if ( my_memmem(&track_data[idam_offset+14], 4 * (DMK_ID_GAP_LEN + DMK_DAM_LEN), (UINT8 *)needle_data, 10) ) - dam = 0; - /* find pattern 0x0000FA; this represents the start of a deleted data sector (used for system sectors) */ - else if ( my_memmem(&track_data[idam_offset+14], 4 * (DMK_ID_GAP_LEN + DMK_DAM_LEN), (UINT8 *)needle_deleted_data_fa, 10) ) - dam = ID_FLAG_DELETED_DATA; - /* find pattern 0x0000F8; this represents the start of a deleted data sector (used for system sectors) */ - else if ( my_memmem(&track_data[idam_offset+14], 4 * (DMK_ID_GAP_LEN + DMK_DAM_LEN), (UINT8 *)needle_deleted_data_f8, 10) ) - dam = ID_FLAG_DELETED_DATA; - else - return FLOPPY_ERROR_SEEKERROR; - - if (cylinder) - *cylinder = (&track_data[idam_offset])[2]; - if (side) - *side = (&track_data[idam_offset])[4]; - if (sector) - *sector = (&track_data[idam_offset])[6]; - if (sector_length) - *sector_length = 128 << (&track_data[idam_offset])[8]; - if (flags) - *flags = dam; - return FLOPPY_ERROR_SUCCESS; -} - - - -static floperr_t internal_z80ne_dmk_read_sector(floppy_image_legacy *floppy, int head, int track, int sector, int sector_is_index, void *buffer, size_t buflen) -{ - floperr_t err; - UINT32 sector_length; - UINT16 crc_on_disk; - UINT16 calculated_crc; - UINT8 *sector_data = NULL; - dynamic_buffer local_sector; - int local_sector_size; - int i; - - /* get sector length and data pointer */ - err = z80ne_dmk_seek_sector_in_track(floppy, head, track, sector, sector_is_index, FALSE, §or_data, §or_length); - if (err) - goto done; - - /* set up a local physical sector space (DAM + data + crc + GAP) */ - local_sector_size = (DMK_DAM_LEN + sector_length + DMK_DATA_CRC_LEN + DMK_DATA_GAP_LEN); - local_sector.resize(local_sector_size); - memset(&local_sector, 0, local_sector_size); - - /* get sector data */ - /* create a local copy of sector data including DAM (for crc calculation) */ - for(i = 0; i < (DMK_DAM_LEN + sector_length + DMK_DATA_CRC_LEN); i++) - local_sector[i] = (sector_data - 2)[i*2]; - - crc_on_disk = local_sector[sector_length + 0 + 1]; - crc_on_disk <<= 8; - crc_on_disk += local_sector[sector_length + 1 + 1]; - - /* crc calculated including DAM */ - calculated_crc = ccitt_crc16(0xffff, &local_sector[0], sector_length+1); - if (calculated_crc != crc_on_disk) - { - err = FLOPPY_ERROR_INVALIDIMAGE; - goto done; - } - - /* copy local sector data excluding DAM */ - memcpy(buffer, &local_sector[1], MIN(sector_length, buflen)); - - done: - return err; -} - - - -static floperr_t internal_z80ne_dmk_write_sector(floppy_image_legacy *floppy, int head, int track, int sector, int sector_is_index, const void *buffer, size_t buflen, int ddam) -{ - floperr_t err; - UINT32 sector_length; - UINT8 *sector_data; - UINT16 crc; - dynamic_buffer local_sector; - int local_sector_size; - int i; - - /* get sector length */ - err = z80ne_dmk_seek_sector_in_track(floppy, head, track, sector, sector_is_index, TRUE, §or_data, §or_length); - if (err) - goto done; - - /* set up a local physical sector space */ - local_sector_size = (DMK_DAM_LEN + sector_length + DMK_DATA_CRC_LEN + DMK_DATA_GAP_LEN); - local_sector.resize(local_sector_size); - memset(&local_sector[0], 0, local_sector_size); - if(!ddam) - local_sector[0] = 0xFB; - else - local_sector[0] = 0xFA; - - if (buflen > sector_length) - { - err = FLOPPY_ERROR_INTERNAL; - goto done; - } - - memcpy(&local_sector[1], buffer, buflen); - - crc = ccitt_crc16(0xffff, &local_sector[0], DMK_DAM_LEN + sector_length); - local_sector[DMK_DAM_LEN + sector_length + 0] = crc >> 8; - local_sector[DMK_DAM_LEN + sector_length + 1] = crc >> 0; - - /* write local sector in track doubling every byte (DMK double density mode) */ - /* write DAM or DDAM too */ - sector_data -= 2; - for(i=0; i < (DMK_DAM_LEN + sector_length + DMK_DATA_CRC_LEN); i++) - sector_data[i*2] = sector_data[(i*2)+1] = local_sector[i]; - - done: - return err; -} - - - -static floperr_t z80ne_dmk_read_sector(floppy_image_legacy *floppy, int head, int track, int sector, void *buffer, size_t buflen) -{ - return internal_z80ne_dmk_read_sector(floppy, head, track, sector, FALSE, buffer, buflen); -} - -static floperr_t z80ne_dmk_write_sector(floppy_image_legacy *floppy, int head, int track, int sector, const void *buffer, size_t buflen, int ddam) -{ - return internal_z80ne_dmk_write_sector(floppy, head, track, sector, FALSE, buffer, buflen, ddam); -} - -static floperr_t z80ne_dmk_read_indexed_sector(floppy_image_legacy *floppy, int head, int track, int sector, void *buffer, size_t buflen) -{ - return internal_z80ne_dmk_read_sector(floppy, head, track, sector, TRUE, buffer, buflen); -} - -static floperr_t z80ne_dmk_write_indexed_sector(floppy_image_legacy *floppy, int head, int track, int sector, const void *buffer, size_t buflen, int ddam) -{ - return internal_z80ne_dmk_write_sector(floppy, head, track, sector, TRUE, buffer, buflen, ddam); -} - - - -static void z80ne_dmk_interpret_header(floppy_image_legacy *floppy, int *heads, int *tracks, int * sectors, int *track_size) -{ - UINT8 header[DMK_HEADER_LEN + DMK_TOC_LEN]; - int i; - int idam_offset; - int sects; - - floppy_image_read(floppy, header, 0, DMK_HEADER_LEN + DMK_TOC_LEN); - - if (tracks) - *tracks = header[1]; - if (heads) - *heads = (header[4] & 0x10) ? 1 : 2; - if (track_size) - *track_size = ((int) header[3]) * 0x100 + header[2]; - if(sectors) - { - /* count sectors on first track */ - sects = 0; - for (i = 0; i < DMK_TOC_LEN / 2; i++) - { - idam_offset = header[DMK_HEADER_LEN + i * 2 + 1]; - idam_offset <<= 8; - idam_offset |= header[DMK_HEADER_LEN + i * 2 + 0]; - idam_offset &= 0x3FFF; - - if (idam_offset == 0) - break; - else - sects++; - } - *sectors = sects; - } - -} - - - -FLOPPY_CONSTRUCT(z80ne_dmk_construct) -{ - struct FloppyCallbacks *callbacks; - struct dmk_tag *tag; - UINT8 header[DMK_HEADER_LEN]; - int heads, tracks, track_size, sectors, sector_length; - - if (params) - { - heads = option_resolution_lookup_int(params, PARAM_HEADS); - tracks = option_resolution_lookup_int(params, PARAM_TRACKS); - sectors = option_resolution_lookup_int(params, PARAM_SECTORS); - sector_length = option_resolution_lookup_int(params, PARAM_SECTOR_LENGTH); - - track_size = z80ne_dmk_min_track_size(sectors, sector_length); - - memset(header, 0, sizeof(header)); - header[1] = tracks; - header[2] = track_size >> 0; - header[3] = track_size >> 8; - header[4] = (heads == 2) ? 0x00 : 0x10; - - floppy_image_write(floppy, header, 0, sizeof(header)); - } - else - { - z80ne_dmk_interpret_header(floppy, &heads, &tracks, §ors, &track_size); - } - - tag = (dmk_tag*)floppy_create_tag(floppy, sizeof(struct dmk_tag)); - if (!tag) - return FLOPPY_ERROR_OUTOFMEMORY; - tag->heads = heads; - tag->track_size = track_size; - tag->tracks = tracks; - - callbacks = floppy_callbacks(floppy); - callbacks->read_track = z80ne_dmk_read_track; - callbacks->write_track = z80ne_dmk_write_track; - callbacks->get_track_data_offset = z80ne_dmk_get_track_data_offset; - callbacks->format_track = z80ne_dmk_format_track; - callbacks->get_heads_per_disk = z80ne_dmk_get_heads_per_disk; - callbacks->get_tracks_per_disk = z80ne_dmk_get_tracks_per_disk; - callbacks->get_track_size = z80ne_dmk_get_track_size; - callbacks->get_sector_length = z80ne_dmk_get_sector_length; - callbacks->get_indexed_sector_info = z80ne_dmk_get_indexed_sector_info; - callbacks->read_sector = z80ne_dmk_read_sector; - callbacks->write_sector = z80ne_dmk_write_sector; - callbacks->read_indexed_sector = z80ne_dmk_read_indexed_sector; - callbacks->write_indexed_sector = z80ne_dmk_write_indexed_sector; - - return FLOPPY_ERROR_SUCCESS; -} - - - -FLOPPY_IDENTIFY(z80ne_dmk_identify) -{ - int heads, tracks, sectors, track_size; - UINT64 size, expected_size; - - size = floppy_image_size(floppy); - z80ne_dmk_interpret_header(floppy, &heads, &tracks, §ors, &track_size); - expected_size = DMK_HEADER_LEN + (heads * tracks * track_size); - *vote = (size == expected_size) ? 90 : 0; - *vote += (sectors == 10) ? 10 : 0; - return FLOPPY_ERROR_SUCCESS; -} - - - -/* ----------------------------------------------------------------------- */ - -LEGACY_FLOPPY_OPTIONS_START( z80ne ) - /* - * Single side - * Single density - * FM, 125 kbit/s, - * 40 tracks, track ID: 0..39 - * 10 sectors/track, sector ID: 0..9 - * 256 bytes/sector - * Interleave 1 (sector ID sequence on track: 0 5 1 6 2 7 3 8 4 9) - * 3125 byte/track unformatted - * Rotation speed 300 rpm (5 rps) - */ - LEGACY_FLOPPY_OPTION( z80ne_dmk, "zmk", "Z80NE DMK disk image", z80ne_dmk_identify, z80ne_dmk_construct, NULL, - HEADS([1]) - TRACKS([40]) - SECTORS([10]) - SECTOR_LENGTH([256]) - INTERLEAVE([1]) - FIRST_SECTOR_ID([0])) -LEGACY_FLOPPY_OPTIONS_END diff --git a/src/lib/formats/z80ne_dsk.h b/src/lib/formats/z80ne_dsk.h deleted file mode 100644 index 8740008e821..00000000000 --- a/src/lib/formats/z80ne_dsk.h +++ /dev/null @@ -1,24 +0,0 @@ -// license:??? -// copyright-holders:Roberto Lavarone -/********************************************************************* - - formats/z80ne_dsk.h - - Nuova Elettronica Z80NE disk images - -*********************************************************************/ - -#ifndef Z80NE_DSK_H -#define Z80NE_DSK_H - -#include "flopimg.h" - - -/**************************************************************************/ - -LEGACY_FLOPPY_OPTIONS_EXTERN(z80ne); - -FLOPPY_IDENTIFY(z80ne_dmk_identify); -FLOPPY_CONSTRUCT(z80ne_dmk_construct); - -#endif /* Z80NE_DSK_H */ diff --git a/src/mess/drivers/z80ne.c b/src/mess/drivers/z80ne.c index a8031bf9397..c7e52a248f3 100644 --- a/src/mess/drivers/z80ne.c +++ b/src/mess/drivers/z80ne.c @@ -95,7 +95,7 @@ #include "cpu/z80/z80.h" #include "includes/z80ne.h" #include "imagedev/flopdrv.h" -#include "formats/z80ne_dsk.h" +#include "formats/dmk_dsk.h" #include "machine/ram.h" /* Layout */ @@ -400,12 +400,13 @@ static const UINT32 lx388palette[] = rgb_t(0xff, 0xc4, 0x18) /* ALPHANUMERIC BRIGHT ORANGE */ }; -static const floppy_interface z80netf_floppy_interface = -{ - FLOPPY_STANDARD_5_25_DSHD, - LEGACY_FLOPPY_OPTIONS_NAME(z80ne), - NULL -}; +FLOPPY_FORMATS_MEMBER( z80ne_state::floppy_formats ) + FLOPPY_DMK_FORMAT +FLOPPY_FORMATS_END + +static SLOT_INTERFACE_START( z80ne_floppies ) + SLOT_INTERFACE("sssd", FLOPPY_525_SSSD) +SLOT_INTERFACE_END static MACHINE_CONFIG_START( z80ne, z80ne_state ) /* basic machine hardware */ @@ -526,10 +527,11 @@ static MACHINE_CONFIG_START( z80netf, z80ne_state ) // AG = GND, GM2 = GND, GM1 = GND, GM0 = GND, CSS = GND // other lines not connected - MCFG_DEVICE_ADD("wd1771", FD1771, 0) - MCFG_WD17XX_DEFAULT_DRIVE4_TAGS - - MCFG_LEGACY_FLOPPY_4_DRIVES_ADD(z80netf_floppy_interface) + MCFG_FD1771x_ADD("wd1771", XTAL_2MHz / 2) + MCFG_FLOPPY_DRIVE_ADD("wd1771:0", z80ne_floppies, "sssd", z80ne_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd1771:1", z80ne_floppies, "sssd", z80ne_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd1771:2", z80ne_floppies, NULL, z80ne_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd1771:3", z80ne_floppies, NULL, z80ne_state::floppy_formats) MCFG_DEFAULT_LAYOUT(layout_z80netf) diff --git a/src/mess/includes/z80ne.h b/src/mess/includes/z80ne.h index 734dc6a57e6..6ba7c12831e 100644 --- a/src/mess/includes/z80ne.h +++ b/src/mess/includes/z80ne.h @@ -17,7 +17,7 @@ #include "imagedev/cassette.h" #include "machine/ay31015.h" #include "machine/kr2376.h" -#include "machine/wd17xx.h" +#include "machine/wd_fdc.h" /*************************************************************************** CONSTANTS @@ -74,6 +74,10 @@ public: m_ay31015(*this, "ay_3_1015"), m_lx388_kr2376(*this, "lx388_kr2376"), m_maincpu(*this, "z80ne"), + m_floppy0(*this, "wd1771:0"), + m_floppy1(*this, "wd1771:1"), + m_floppy2(*this, "wd1771:2"), + m_floppy3(*this, "wd1771:3"), m_cassette1(*this, "cassette"), m_cassette2(*this, "cassette2"), m_wd1771(*this, "wd1771"), @@ -99,6 +103,8 @@ public: m_io_modifiers(*this, "MODIFIERS"), m_io_config(*this, "CONFIG") { } + DECLARE_FLOPPY_FORMATS(floppy_formats) + optional_device m_vdg; optional_shared_ptr m_videoram; required_device m_ay31015; @@ -148,9 +154,13 @@ public: protected: required_device m_maincpu; + optional_device m_floppy0; + optional_device m_floppy1; + optional_device m_floppy2; + optional_device m_floppy3; required_device m_cassette1; required_device m_cassette2; - optional_device m_wd1771; + optional_device m_wd1771; required_memory_region m_region_z80ne; optional_memory_bank m_bank1; optional_memory_bank m_bank2; diff --git a/src/mess/machine/z80ne.c b/src/mess/machine/z80ne.c index 6e476fbe57d..7ae31e9afac 100644 --- a/src/mess/machine/z80ne.c +++ b/src/mess/machine/z80ne.c @@ -652,37 +652,30 @@ WRITE8_MEMBER(z80ne_state::lx390_motor_w) d1 1=select drive 1 d0 1=select drive 0 */ - UINT8 drive = 255; + floppy_image_device *floppy = NULL; - if (data & 1) - drive = 0; - else - if (data & 2) - drive = 1; - else - if (data & 4) - drive = 2; - else - if (data & 8) - drive = 3; + if (BIT(data, 0)) floppy = m_floppy0->get_device(); + if (BIT(data, 1)) floppy = m_floppy1->get_device(); + if (BIT(data, 2)) floppy = m_floppy2->get_device(); + if (BIT(data, 3)) floppy = m_floppy3->get_device(); - m_wd17xx_state.head = (data & 32) ? 1 : 0; - m_wd17xx_state.drive = data & 0x0F; + m_wd1771->set_floppy(floppy); - /* no drive selected, turn off all leds */ - if (!m_wd17xx_state.drive) - { - output_set_value("drv0", 0); - output_set_value("drv1", 0); - } + if (floppy) + { + floppy->ss_w(BIT(data, 5)); + floppy->mon_w(0); + } - if (drive < 4) - { - LOG(("lx390_motor_w, set drive %1d\n", drive)); - m_wd1771->set_drive(drive); - LOG(("lx390_motor_w, set side %1d\n", m_wd17xx_state.head)); - m_wd1771->set_side(m_wd17xx_state.head); - } + m_wd17xx_state.head = (data & 32) ? 1 : 0; + m_wd17xx_state.drive = data & 0x0F; + + /* no drive selected, turn off all leds */ + if (!m_wd17xx_state.drive) + { + output_set_value("drv0", 0); + output_set_value("drv1", 0); + } } READ8_MEMBER(z80ne_state::lx390_reset_bank) @@ -748,7 +741,7 @@ WRITE8_MEMBER(z80ne_state::lx390_fdc_w) { case 0: LOG(("lx390_fdc_w, WD17xx command: %02x\n", d)); - m_wd1771->command_w(space, offset, d ^ 0xff); + m_wd1771->cmd_w(space, offset, d ^ 0xff); if (m_wd17xx_state.drive & 1) output_set_value("drv0", 2); else if (m_wd17xx_state.drive & 2) -- cgit v1.2.3 From 0624b6efd0665097ef84e8816298aaffeda31d9e Mon Sep 17 00:00:00 2001 From: Dirk Best Date: Fri, 29 May 2015 23:46:56 +0200 Subject: restore my bbc changes (wtf did happen to them?) --- scripts/src/lib.lua | 2 + src/lib/formats/bbc_dsk.c | 53 +++++++++++++++++++++++++ src/lib/formats/bbc_dsk.h | 33 ++++++++++++++++ src/mess/drivers/bbc.c | 62 +++++++++++++++++++++--------- src/mess/includes/bbc.h | 4 +- src/mess/machine/bbc.c | 98 +++++++++++++++++++++++++++++------------------ 6 files changed, 194 insertions(+), 58 deletions(-) create mode 100644 src/lib/formats/bbc_dsk.c create mode 100644 src/lib/formats/bbc_dsk.h (limited to 'scripts/src/lib.lua') diff --git a/scripts/src/lib.lua b/scripts/src/lib.lua index ef809dd5b46..166ab4beddb 100644 --- a/scripts/src/lib.lua +++ b/scripts/src/lib.lua @@ -158,6 +158,8 @@ project "formats" MAME_DIR .. "src/lib/formats/atarist_dsk.h", MAME_DIR .. "src/lib/formats/atom_tap.c", MAME_DIR .. "src/lib/formats/atom_tap.h", + MAME_DIR .. "src/lib/formats/bbc_dsk.c", + MAME_DIR .. "src/lib/formats/bbc_dsk.h", MAME_DIR .. "src/lib/formats/bw2_dsk.c", MAME_DIR .. "src/lib/formats/bw2_dsk.h", MAME_DIR .. "src/lib/formats/bw12_dsk.c", diff --git a/src/lib/formats/bbc_dsk.c b/src/lib/formats/bbc_dsk.c new file mode 100644 index 00000000000..dfa78c0bfd8 --- /dev/null +++ b/src/lib/formats/bbc_dsk.c @@ -0,0 +1,53 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + BBC Micro + + Disk image format + +***************************************************************************/ + +#include "bbc_dsk.h" + +bbc_format::bbc_format() : wd177x_format(formats) +{ +} + +const char *bbc_format::name() const +{ + return "bbc"; +} + +const char *bbc_format::description() const +{ + return "BBC Micro disk image"; +} + +const char *bbc_format::extensions() const +{ + return "bbc,img,ssd,dsd"; +} + +const bbc_format::format bbc_format::formats[] = +{ + { // 100k single sided single density + floppy_image::FF_525, floppy_image::SSSD, floppy_image::FM, + 4000, 10, 40, 1, 256, {}, 0, {}, 16, 11, 19 + }, + { // 200k double sided single density + floppy_image::FF_525, floppy_image::DSSD, floppy_image::FM, + 4000, 10, 40, 2, 256, {}, 0, {}, 16, 11, 19 + }, + { // 200k single sided double density + floppy_image::FF_525, floppy_image::SSQD, floppy_image::FM, + 4000, 10, 80, 1, 256, {}, 0, {}, 16, 11, 19 + }, + { // 400k double sided double density + floppy_image::FF_525, floppy_image::DSQD, floppy_image::FM, + 4000, 10, 80, 2, 256, {}, 0, {}, 16, 11, 19 + }, + {} +}; + +const floppy_format_type FLOPPY_BBC_FORMAT = &floppy_image_format_creator; diff --git a/src/lib/formats/bbc_dsk.h b/src/lib/formats/bbc_dsk.h new file mode 100644 index 00000000000..e2520781a15 --- /dev/null +++ b/src/lib/formats/bbc_dsk.h @@ -0,0 +1,33 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + BBC Micro + + Disk image format + +***************************************************************************/ + +#pragma once + +#ifndef __BBC_DSK_H__ +#define __BBC_DSK_H__ + +#include "wd177x_dsk.h" + +class bbc_format : public wd177x_format +{ +public: + bbc_format(); + + virtual const char *name() const; + virtual const char *description() const; + virtual const char *extensions() const; + +private: + static const format formats[]; +}; + +extern const floppy_format_type FLOPPY_BBC_FORMAT; + +#endif // __BBC_DSK_H__ diff --git a/src/mess/drivers/bbc.c b/src/mess/drivers/bbc.c index aa1ae726ac3..5a4df8785ac 100644 --- a/src/mess/drivers/bbc.c +++ b/src/mess/drivers/bbc.c @@ -57,6 +57,7 @@ /* Devices */ #include "imagedev/flopdrv.h" +#include "formats/bbc_dsk.h" #include "formats/basicdsk.h" #include "imagedev/cassette.h" #include "formats/uef_cas.h" @@ -609,6 +610,19 @@ static const floppy_interface bbc_floppy_interface = "floppy_5_25" }; +FLOPPY_FORMATS_MEMBER( bbc_state::floppy_formats ) + FLOPPY_BBC_FORMAT +FLOPPY_FORMATS_END + +static SLOT_INTERFACE_START( bbc_floppies ) + SLOT_INTERFACE("sssd", FLOPPY_525_SSSD) + SLOT_INTERFACE("sd", FLOPPY_525_SD) + SLOT_INTERFACE("ssdd", FLOPPY_525_SSDD) + SLOT_INTERFACE("dd", FLOPPY_525_DD) + SLOT_INTERFACE("ssqd", FLOPPY_525_SSQD) + SLOT_INTERFACE("qd", FLOPPY_525_QD) +SLOT_INTERFACE_END + WRITE_LINE_MEMBER(bbc_state::econet_clk_w) { m_adlc->rxc_w(state); @@ -760,13 +774,15 @@ static MACHINE_CONFIG_DERIVED( bbcb, bbca ) MCFG_I8271_IRQ_CALLBACK(WRITELINE(bbc_state, bbc_i8271_interrupt)) MCFG_I8271_FLOPPIES(FLOPPY_0, FLOPPY_1) - MCFG_DEVICE_ADD("wd177x", WD1770, 0) - MCFG_WD17XX_DEFAULT_DRIVE2_TAGS - MCFG_WD17XX_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) - MCFG_WD17XX_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) - MCFG_LEGACY_FLOPPY_2_DRIVES_ADD(bbc_floppy_interface) + MCFG_WD1770x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) + MCFG_WD_FDC_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + + MCFG_FLOPPY_DRIVE_ADD("wd177x:0", bbc_floppies, "qd", bbc_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd177x:1", bbc_floppies, "qd", bbc_state::floppy_formats) + /* software lists */ MCFG_DEVICE_REMOVE("cass_ls_a") MCFG_SOFTWARE_LIST_ADD("cass_ls_b", "bbcb_cass") @@ -822,13 +838,15 @@ static MACHINE_CONFIG_DERIVED( bbcb_us, bbca ) MCFG_I8271_IRQ_CALLBACK(WRITELINE(bbc_state, bbc_i8271_interrupt)) MCFG_I8271_FLOPPIES(FLOPPY_0, FLOPPY_1) - MCFG_DEVICE_ADD("wd177x", WD1770, 0) - MCFG_WD17XX_DEFAULT_DRIVE2_TAGS - MCFG_WD17XX_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) - MCFG_WD17XX_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) - MCFG_LEGACY_FLOPPY_2_DRIVES_ADD(bbc_floppy_interface) + MCFG_WD1770x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) + MCFG_WD_FDC_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + + MCFG_FLOPPY_DRIVE_ADD("wd177x:0", bbc_floppies, "qd", bbc_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd177x:1", bbc_floppies, "qd", bbc_state::floppy_formats) + /* software lists */ MCFG_DEVICE_REMOVE("cass_ls_a") MCFG_SOFTWARE_LIST_ADD("cass_ls_b", "bbcb_cass") @@ -852,6 +870,8 @@ static MACHINE_CONFIG_DERIVED( bbcbp, bbcb ) /* fdc */ MCFG_DEVICE_REMOVE("i8271") + MCFG_DEVICE_REMOVE(FLOPPY_0) + MCFG_DEVICE_REMOVE(FLOPPY_1) MACHINE_CONFIG_END @@ -981,12 +1001,12 @@ static MACHINE_CONFIG_START( bbcm, bbc_state ) MCFG_VIA6522_IRQ_HANDLER(WRITELINE(bbc_state, bbcb_via_user_irq_w)) /* fdc */ - MCFG_DEVICE_ADD("wd177x", WD1770, 0) - MCFG_WD17XX_DEFAULT_DRIVE2_TAGS - MCFG_WD17XX_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) - MCFG_WD17XX_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + MCFG_WD1770x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) + MCFG_WD_FDC_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) - MCFG_LEGACY_FLOPPY_2_DRIVES_ADD(bbc_floppy_interface) + MCFG_FLOPPY_DRIVE_ADD("wd177x:0", bbc_floppies, "qd", bbc_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd177x:1", bbc_floppies, "qd", bbc_state::floppy_formats) /* econet */ MCFG_DEVICE_ADD("mc6854", MC6854, 0) @@ -1068,10 +1088,14 @@ static MACHINE_CONFIG_DERIVED( bbcmc, bbcm ) /* fdc */ MCFG_DEVICE_REMOVE("wd177x") - MCFG_DEVICE_ADD("wd177x", WD1772, 0) - MCFG_WD17XX_DEFAULT_DRIVE2_TAGS - MCFG_WD17XX_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) - MCFG_WD17XX_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + +// MCFG_WD1772x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD1770x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) + MCFG_WD_FDC_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + + MCFG_FLOPPY_DRIVE_ADD("wd177x:0", bbc_floppies, "qd", bbc_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd177x:1", bbc_floppies, "qd", bbc_state::floppy_formats) /* software lists */ MCFG_SOFTWARE_LIST_REMOVE("cart_ls_m") diff --git a/src/mess/includes/bbc.h b/src/mess/includes/bbc.h index d86172860b9..499283e8ec3 100644 --- a/src/mess/includes/bbc.h +++ b/src/mess/includes/bbc.h @@ -20,7 +20,7 @@ #include "machine/mc6854.h" #include "machine/ram.h" #include "machine/i8271.h" -#include "machine/wd17xx.h" +#include "machine/wd_fdc.h" #include "machine/upd7002.h" #include "video/mc6845.h" #include "video/saa5050.h" @@ -80,6 +80,8 @@ public: m_palette(*this, "palette") { } + DECLARE_FLOPPY_FORMATS(floppy_formats); + DECLARE_WRITE8_MEMBER(bbc_page_selecta_w); DECLARE_WRITE8_MEMBER(bbc_memorya1_w); DECLARE_WRITE8_MEMBER(bbc_page_selectb_w); diff --git a/src/mess/machine/bbc.c b/src/mess/machine/bbc.c index 4e3a0a35561..1fc4d5c22da 100644 --- a/src/mess/machine/bbc.c +++ b/src/mess/machine/bbc.c @@ -17,6 +17,7 @@ #include "cpu/m6502/m6502.h" #include "sound/tms5220.h" #include "machine/6522via.h" +#include "machine/wd_fdc.h" #include "imagedev/flopdrv.h" #include "includes/bbc.h" #include "machine/mc146818.h" @@ -1575,7 +1576,7 @@ void bbc_state::bbc_update_fdq_int(int state) /* do not trigger int */ bbc_state = 0; } - +//printf("bbc_state %d prev %d\n", bbc_state, m_previous_wd177x_int_state); /* nmi is edge triggered, and triggers when the state goes from clear->set. Here we are checking this transition before triggering the nmi */ if (bbc_state!=m_previous_wd177x_int_state) @@ -1593,6 +1594,7 @@ void bbc_state::bbc_update_fdq_int(int state) WRITE_LINE_MEMBER(bbc_state::bbc_wd177x_intrq_w) { +//printf("bbc_wd177x_intrq_w %d \n", state); m_wd177x_irq_state = state; bbc_update_fdq_int(state); } @@ -1605,20 +1607,28 @@ WRITE_LINE_MEMBER(bbc_state::bbc_wd177x_drq_w) WRITE8_MEMBER(bbc_state::bbc_wd177x_status_w) { - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); + floppy_image_device *floppy0 = machine().device("wd177x:0")->get_device(); + floppy_image_device *floppy1 = machine().device("wd177x:1")->get_device(); + floppy_image_device *floppy = NULL; + m_drive_control = data; - /* set drive */ - if ((data>>0) & 0x01) fdc->set_drive(0); - if ((data>>1) & 0x01) fdc->set_drive(1); + // bit 0, 1: drive select + if (BIT(data, 0)) floppy = floppy0; + if (BIT(data, 1)) floppy = floppy1; + + fdc->set_floppy(floppy); - /* set side */ - fdc->set_side((data>>2) & 0x01); + // bit 2: side select + if (floppy) + floppy->ss_w(BIT(data, 2)); - /* set density */ + // bit 3: density fdc->dden_w(BIT(data, 3)); - m_1770_IntEnabled=(((data>>4) & 0x01)==0); + // bit 4: interrupt enable + m_1770_IntEnabled = !BIT(data, 4); } @@ -1626,7 +1636,7 @@ WRITE8_MEMBER(bbc_state::bbc_wd177x_status_w) READ8_MEMBER(bbc_state::bbc_wd1770_read) { int retval=0xff; - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); switch (offset) { case 4: @@ -1644,22 +1654,22 @@ READ8_MEMBER(bbc_state::bbc_wd1770_read) default: break; } - logerror("wd177x read: $%02X $%02X\n", offset,retval); + //logerror("wd177x read: $%02X $%02X\n", offset,retval); return retval; } WRITE8_MEMBER(bbc_state::bbc_wd1770_write) { - wd1770_device *fdc = machine().device("wd177x"); - logerror("wd177x write: $%02X $%02X\n", offset,data); + wd1770_t *fdc = machine().device("wd177x"); + //logerror("wd177x write: $%02X $%02X\n", offset,data); switch (offset) { case 0: bbc_wd177x_status_w(space, 0, data); break; case 4: - fdc->command_w(space, 0, data); + fdc->cmd_w(space, 0, data); break; case 5: fdc->track_w(space, 0, data); @@ -1714,26 +1724,34 @@ AM_RANGE(0xfc00, 0xfdff) AM_READWRITE(bbc_opus_read , bbc_opus_write ) WRITE8_MEMBER(bbc_state::bbc_opus_status_w) { - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); + floppy_image_device *floppy0 = machine().device("wd177x:0")->get_device(); + floppy_image_device *floppy1 = machine().device("wd177x:1")->get_device(); + floppy_image_device *floppy = NULL; + m_drive_control = data; - /* set drive */ - if ((data>>1) & 0x01) fdc->set_drive(0); - if ((data>>2) & 0x01) fdc->set_drive(1); + // bit 1, 2: drive select + if (BIT(data, 1)) floppy = floppy0; + if (BIT(data, 2)) floppy = floppy1; - /* set side */ - fdc->set_side((data>>0) & 0x01); + fdc->set_floppy(floppy); - /* set density */ + // bit 0: side select + if (floppy) + floppy->ss_w(BIT(data, 0)); + + // bit 5: density fdc->dden_w(BIT(data, 5)); - m_1770_IntEnabled=(data>>4) & 0x01; + // bit 4: interrupt enable + m_1770_IntEnabled = BIT(data, 4); } READ8_MEMBER(bbc_state::bbc_opus_read) { - wd1770_device *fdc = machine().device("wd177x"); - logerror("wd177x read: $%02X\n", offset); + wd1770_t *fdc = machine().device("wd177x"); + //logerror("wd177x read: $%02X\n", offset); if (m_DFSType==6) { @@ -1761,8 +1779,8 @@ READ8_MEMBER(bbc_state::bbc_opus_read) WRITE8_MEMBER(bbc_state::bbc_opus_write) { - wd1770_device *fdc = machine().device("wd177x"); - logerror("wd177x write: $%02X $%02X\n", offset,data); + wd1770_t *fdc = machine().device("wd177x"); + //logerror("wd177x write: $%02X $%02X\n", offset,data); if (m_DFSType==6) { @@ -1771,7 +1789,7 @@ WRITE8_MEMBER(bbc_state::bbc_opus_write) switch (offset) { case 0xf8: - fdc->command_w(space, 0, data); + fdc->cmd_w(space, 0, data); break; case 0xf9: fdc->track_w(space, 0, data); @@ -1809,7 +1827,7 @@ BBC MASTER DISC SUPPORT READ8_MEMBER(bbc_state::bbcm_wd1770_read) { int retval=0xff; - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); switch (offset) { case 0: @@ -1833,12 +1851,12 @@ READ8_MEMBER(bbc_state::bbcm_wd1770_read) WRITE8_MEMBER(bbc_state::bbcm_wd1770_write) { - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); //logerror("wd177x write: $%02X $%02X\n", offset,data); switch (offset) { case 0: - fdc->command_w(space, 0, data); + fdc->cmd_w(space, 0, data); break; case 1: fdc->track_w(space, 0, data); @@ -1862,22 +1880,26 @@ READ8_MEMBER(bbc_state::bbcm_wd1770l_read) WRITE8_MEMBER(bbc_state::bbcm_wd1770l_write) { - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); + floppy_image_device *floppy0 = machine().device("wd177x:0")->get_device(); + floppy_image_device *floppy1 = machine().device("wd177x:1")->get_device(); + floppy_image_device *floppy = NULL; + m_drive_control = data; - /* set drive */ - if ((data>>0) & 0x01) fdc->set_drive(0); - if ((data>>1) & 0x01) fdc->set_drive(1); + // bit 0, 1: drive select + if (BIT(data, 0)) floppy = floppy0; + if (BIT(data, 1)) floppy = floppy1; - /* set side */ - fdc->set_side((data>>4) & 0x01); + // bit 4: side select + if (floppy) + floppy->ss_w(BIT(data, 4)); - /* set density */ + // bit 5: density fdc->dden_w(BIT(data, 5)); // m_1770_IntEnabled=(((data>>4) & 0x01)==0); m_1770_IntEnabled=1; - } -- cgit v1.2.3