diff options
author | AJR <ajrhacker@users.noreply.github.com> | 2019-11-05 00:30:42 -0500 |
---|---|---|
committer | AJR <ajrhacker@users.noreply.github.com> | 2019-11-05 00:38:11 -0500 |
commit | addf59de2fab6f3855aaf83b9308ea2c58143391 (patch) | |
tree | 583afae67c4145cb4a078a1466680eb8741e51f2 /src/mame/machine | |
parent | 5675bdec9c0f4ec91cb6064000cceb5d034b1156 (diff) |
flopdrv: Even legacy devices need some code cleanup (nw)
- Get rid of the hardcoded FLOPPY_n tags as much as practical, mostly adding device finder arrays in their place
- Move remaining functions using FLOPPY_n down into appldriv and sonydriv (both of which may be eliminated once FDC emulation is modernized)
- Replace CLEAR_LINE and ASSERT_LINE with 0 and 1 (these were being inaccurately used to represent active-low control line states)
Diffstat (limited to 'src/mame/machine')
-rw-r--r-- | src/mame/machine/atarifdc.cpp | 48 | ||||
-rw-r--r-- | src/mame/machine/atarifdc.h | 2 | ||||
-rw-r--r-- | src/mame/machine/micropolis.cpp | 20 | ||||
-rw-r--r-- | src/mame/machine/micropolis.h | 15 | ||||
-rw-r--r-- | src/mame/machine/rx01.cpp | 6 | ||||
-rw-r--r-- | src/mame/machine/rx01.h | 2 |
6 files changed, 36 insertions, 57 deletions
diff --git a/src/mame/machine/atarifdc.cpp b/src/mame/machine/atarifdc.cpp index f8eb9c08829..ce6a5eb3e3b 100644 --- a/src/mame/machine/atarifdc.cpp +++ b/src/mame/machine/atarifdc.cpp @@ -106,20 +106,18 @@ static void _atari_load_proc(device_image_interface &image, bool is_created) atarifdc->atari_load_proc(image, is_created); } -static int atari_fdc_get_drive(device_t *image) -{ - int drive = -1; - if (strcmp(image->tag(), ":fdc:" FLOPPY_0) == 0) drive = 0; - if (strcmp(image->tag(), ":fdc:" FLOPPY_1) == 0) drive = 1; - if (strcmp(image->tag(), ":fdc:" FLOPPY_2) == 0) drive = 2; - if (strcmp(image->tag(), ":fdc:" FLOPPY_3) == 0) drive = 3; - return drive; -} - void atari_fdc_device::atari_load_proc(device_image_interface &image, bool is_created) { - int id = atari_fdc_get_drive(&image.device()); - int size, i; + int id = -1; + + for (int i = 0; i < 4; i++) + { + if (&image.device() == m_floppy[i].target()) + { + id = i; + break; + } + } if (id == -1) return; @@ -142,7 +140,7 @@ void atari_fdc_device::atari_load_proc(device_image_interface &image, bool is_cr image.fseek(0, SEEK_SET); } - size = image.fread(m_drv[id].image.get(), MAXSIZE); + int size = image.fread(m_drv[id].image.get(), MAXSIZE); if( size <= 0 ) { @@ -198,6 +196,7 @@ void atari_fdc_device::atari_load_proc(device_image_interface &image, bool is_cr } + int i; switch (m_drv[id].type) { /* XFD or unknown format: find a matching size from the table */ @@ -740,21 +739,11 @@ static const floppy_interface atari_floppy_interface = "floppy_5_25" }; -legacy_floppy_image_device *atari_fdc_device::atari_floppy_get_device_child(int drive) -{ - switch(drive) { - case 0 : return subdevice<legacy_floppy_image_device>(FLOPPY_0); - case 1 : return subdevice<legacy_floppy_image_device>(FLOPPY_1); - case 2 : return subdevice<legacy_floppy_image_device>(FLOPPY_2); - case 3 : return subdevice<legacy_floppy_image_device>(FLOPPY_3); - } - return nullptr; -} - DEFINE_DEVICE_TYPE(ATARI_FDC, atari_fdc_device, "atari_fdc", "Atari FDC") atari_fdc_device::atari_fdc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, ATARI_FDC, tag, owner, clock), + m_floppy(*this, "floppy%u", 0U), m_pokey(*this, "^pokey"), m_pia(*this, "^pia"), m_serout_count(0), @@ -774,16 +763,12 @@ atari_fdc_device::atari_fdc_device(const machine_config &mconfig, const char *ta void atari_fdc_device::device_start() { - int id; - memset(m_serout_buff, 0, sizeof(m_serout_buff)); memset(m_serin_buff, 0, sizeof(m_serin_buff)); memset(m_drv, 0, sizeof(m_drv)); - for(id=0;id<4;id++) - { - atari_floppy_get_device_child(id)->floppy_install_load_proc(_atari_load_proc); - } + for (auto &floppy : m_floppy) + floppy->floppy_install_load_proc(_atari_load_proc); } //------------------------------------------------- @@ -792,5 +777,6 @@ void atari_fdc_device::device_start() void atari_fdc_device::device_add_mconfig(machine_config &config) { - legacy_floppy_image_device::add_4drives(config, &atari_floppy_interface); + for (auto &floppy : m_floppy) + LEGACY_FLOPPY(config, floppy, 0, &atari_floppy_interface); } diff --git a/src/mame/machine/atarifdc.h b/src/mame/machine/atarifdc.h index 5fb245bc123..342ead3051f 100644 --- a/src/mame/machine/atarifdc.h +++ b/src/mame/machine/atarifdc.h @@ -34,7 +34,6 @@ private: void add_serin(uint8_t data, int with_checksum); void a800_serial_command(); void a800_serial_write(); - legacy_floppy_image_device *atari_floppy_get_device_child(int drive); struct atari_drive { @@ -51,6 +50,7 @@ private: int sectors; /* total sectors, ie. tracks x heads x spt */ }; + required_device_array<legacy_floppy_image_device, 4> m_floppy; required_device<pokey_device> m_pokey; required_device<pia6821_device> m_pia; diff --git a/src/mame/machine/micropolis.cpp b/src/mame/machine/micropolis.cpp index b79ee7b3177..68df581d422 100644 --- a/src/mame/machine/micropolis.cpp +++ b/src/mame/machine/micropolis.cpp @@ -70,6 +70,7 @@ micropolis_device::micropolis_device(const machine_config &mconfig, const char * m_read_dden(*this), m_write_intrq(*this), m_write_drq(*this), + m_floppy_drive(*this, {finder_base::DUMMY_TAG, finder_base::DUMMY_TAG, finder_base::DUMMY_TAG, finder_base::DUMMY_TAG}), m_data(0), m_drive_num(0), m_track(0), @@ -83,7 +84,6 @@ micropolis_device::micropolis_device(const machine_config &mconfig, const char * m_drive(nullptr) { std::fill(std::begin(m_buffer), std::end(m_buffer), 0); - std::fill(std::begin(m_floppy_drive_tags), std::end(m_floppy_drive_tags), nullptr); } //------------------------------------------------- @@ -115,18 +115,13 @@ void micropolis_device::device_start() void micropolis_device::device_reset() { - for (auto & elem : m_floppy_drive_tags) + for (auto &img : m_floppy_drive) { - if (elem) + if (img.found()) { - legacy_floppy_image_device *img = siblingdevice<legacy_floppy_image_device>(elem); - - if (img) - { - img->floppy_drive_set_controller(this); - //img->floppy_drive_set_index_pulse_callback(wd17xx_index_pulse_callback); - img->floppy_drive_set_rpm(300.); - } + img->floppy_drive_set_controller(this); + //img->floppy_drive_set_index_pulse_callback(wd17xx_index_pulse_callback); + img->floppy_drive_set_rpm(300.); } } @@ -185,8 +180,7 @@ void micropolis_device::set_drive(uint8_t drive) if (VERBOSE) logerror("micropolis_set_drive: $%02x\n", drive); - if (m_floppy_drive_tags[drive]) - m_drive = siblingdevice<legacy_floppy_image_device>(m_floppy_drive_tags[drive]); + m_drive = m_floppy_drive[drive].target(); } diff --git a/src/mame/machine/micropolis.h b/src/mame/machine/micropolis.h index 7012690c5d8..d7eb6616e18 100644 --- a/src/mame/machine/micropolis.h +++ b/src/mame/machine/micropolis.h @@ -30,16 +30,15 @@ public: auto intrq_wr_callback() { return m_write_intrq.bind(); } auto drq_wr_callback() { return m_write_drq.bind(); } - void set_drive_tags(const char *tag1, const char *tag2, const char *tag3, const char *tag4) + template<typename T, typename U, typename V, typename W> + void set_drive_tags(T &&tag1, U &&tag2, V &&tag3, W &&tag4) { - m_floppy_drive_tags[0] = tag1; - m_floppy_drive_tags[1] = tag2; - m_floppy_drive_tags[2] = tag3; - m_floppy_drive_tags[3] = tag4; + m_floppy_drive[0].set_tag(std::forward<T>(tag1)); + m_floppy_drive[1].set_tag(std::forward<U>(tag2)); + m_floppy_drive[2].set_tag(std::forward<V>(tag3)); + m_floppy_drive[3].set_tag(std::forward<W>(tag4)); } - void set_default_drive_tags() { set_drive_tags(FLOPPY_0, FLOPPY_1, FLOPPY_2, FLOPPY_3); } - void set_drive(uint8_t drive); // set current drive (0-3) DECLARE_READ8_MEMBER( status_r ); @@ -63,7 +62,7 @@ private: devcb_write_line m_write_intrq; devcb_write_line m_write_drq; - const char *m_floppy_drive_tags[4]; + optional_device_array<legacy_floppy_image_device, 4> m_floppy_drive; /* register */ uint8_t m_data; diff --git a/src/mame/machine/rx01.cpp b/src/mame/machine/rx01.cpp index b98bd78fd7c..ab91393d93b 100644 --- a/src/mame/machine/rx01.cpp +++ b/src/mame/machine/rx01.cpp @@ -46,6 +46,7 @@ DEFINE_DEVICE_TYPE(RX01, rx01_device, "rx01", "RX01") rx01_device::rx01_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, RX01, tag, owner, clock) + , m_image(*this, "floppy%u", 0U) { } @@ -55,7 +56,8 @@ rx01_device::rx01_device(const machine_config &mconfig, const char *tag, device_ void rx01_device::device_add_mconfig(machine_config &config) { - legacy_floppy_image_device::add_2drives(config, &rx01_floppy_interface); + for (auto &floppy : m_image) + LEGACY_FLOPPY(config, floppy, 0, &rx01_floppy_interface); } //------------------------------------------------- @@ -64,8 +66,6 @@ void rx01_device::device_add_mconfig(machine_config &config) void rx01_device::device_start() { - m_image[0] = subdevice<legacy_floppy_image_device>(FLOPPY_0); - m_image[1] = subdevice<legacy_floppy_image_device>(FLOPPY_1); } diff --git a/src/mame/machine/rx01.h b/src/mame/machine/rx01.h index 8e53d7efbe5..599d40c84cb 100644 --- a/src/mame/machine/rx01.h +++ b/src/mame/machine/rx01.h @@ -59,7 +59,7 @@ private: RX01_INIT }; - legacy_floppy_image_device *m_image[2]; + required_device_array<legacy_floppy_image_device, 2> m_image; uint8_t m_buffer[128]; int m_buf_pos; |