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/devices/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/devices/machine')
-rw-r--r-- | src/devices/machine/appldriv.h | 5 | ||||
-rw-r--r-- | src/devices/machine/mc6843.cpp | 43 | ||||
-rw-r--r-- | src/devices/machine/mc6843.h | 12 | ||||
-rw-r--r-- | src/devices/machine/sonydriv.cpp | 42 | ||||
-rw-r--r-- | src/devices/machine/sonydriv.h | 5 |
5 files changed, 73 insertions, 34 deletions
diff --git a/src/devices/machine/appldriv.h b/src/devices/machine/appldriv.h index 6d23284f46a..86f7c1658bf 100644 --- a/src/devices/machine/appldriv.h +++ b/src/devices/machine/appldriv.h @@ -16,6 +16,11 @@ #include "imagedev/flopdrv.h" #include "formats/ap2_dsk.h" +#define FLOPPY_0 "floppy0" +#define FLOPPY_1 "floppy1" +#define FLOPPY_2 "floppy2" +#define FLOPPY_3 "floppy3" + void apple525_set_lines(device_t *device, uint8_t lines); void apple525_set_enable_lines(device_t *device, int enable_mask); diff --git a/src/devices/machine/mc6843.cpp b/src/devices/machine/mc6843.cpp index af3c6cb9f46..e41aeeaf9d3 100644 --- a/src/devices/machine/mc6843.cpp +++ b/src/devices/machine/mc6843.cpp @@ -72,6 +72,7 @@ DEFINE_DEVICE_TYPE(MC6843, mc6843_device, "mc5843", "Motorola MC6843 FDC") mc6843_device::mc6843_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, MC6843, tag, owner, clock), + m_floppy(*this, {finder_base::DUMMY_TAG, finder_base::DUMMY_TAG, finder_base::DUMMY_TAG, finder_base::DUMMY_TAG}), m_write_irq(*this), m_CTAR(0), m_CMR(0), @@ -131,16 +132,17 @@ void mc6843_device::device_start() void mc6843_device::device_reset() { - int i; LOG (( "mc6843 reset\n" )); /* setup/reset floppy drive */ - for ( i = 0; i < 4; i++ ) + for (auto &img : m_floppy) { - legacy_floppy_image_device * img = floppy_image( i ); - img->floppy_mon_w(CLEAR_LINE); - img->floppy_drive_set_ready_state(FLOPPY_DRIVE_READY, 0 ); - img->floppy_drive_set_rpm( 300. ); + if (img.found()) + { + img->floppy_mon_w(CLEAR_LINE); + img->floppy_drive_set_ready_state(FLOPPY_DRIVE_READY, 0 ); + img->floppy_drive_set_rpm( 300. ); + } } /* reset registers */ @@ -160,35 +162,10 @@ void mc6843_device::device_reset() -legacy_floppy_image_device* mc6843_device::floppy_image( uint8_t drive ) -{ - legacy_floppy_image_device *img = floppy_get_device( machine(), drive ); - if (!img && owner()) { - // For slot devices, drives are typically attached to the slot rather than the machine - const char *floppy_name = nullptr; - switch (drive) { - case 0: - floppy_name = FLOPPY_0; - break; - case 1: - floppy_name = FLOPPY_1; - break; - case 2: - floppy_name = FLOPPY_2; - break; - case 3: - floppy_name = FLOPPY_3; - break; - } - img = owner()->subdevice<legacy_floppy_image_device>(floppy_name); - } - return img; -} - - legacy_floppy_image_device* mc6843_device::floppy_image( ) { - return floppy_image( m_drive ); + assert(m_floppy[m_drive].found()); + return m_floppy[m_drive].target(); } diff --git a/src/devices/machine/mc6843.h b/src/devices/machine/mc6843.h index 63052970edb..c75ba561548 100644 --- a/src/devices/machine/mc6843.h +++ b/src/devices/machine/mc6843.h @@ -21,6 +21,15 @@ class mc6843_device : public device_t public: mc6843_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); + template<int Id, typename T> void set_floppy_drive(T &&tag) { m_floppy[Id].set_tag(std::forward<T>(tag)); } + template<typename T, typename U, typename V, typename W> void set_floppy_drives(T &&tag0, U &&tag1, V &&tag2, W &&tag3) + { + m_floppy[0].set_tag(std::forward<T>(tag0)); + m_floppy[1].set_tag(std::forward<U>(tag1)); + m_floppy[2].set_tag(std::forward<V>(tag2)); + m_floppy[3].set_tag(std::forward<W>(tag3)); + } + auto irq() { return m_write_irq.bind(); } DECLARE_READ8_MEMBER(read); @@ -42,6 +51,8 @@ private: TIMER_CONT }; + optional_device_array<legacy_floppy_image_device, 4> m_floppy; + devcb_write_line m_write_irq; /* registers */ @@ -68,7 +79,6 @@ private: /* trigger delayed actions (bottom halves) */ emu_timer* m_timer_cont; - legacy_floppy_image_device* floppy_image(uint8_t drive); legacy_floppy_image_device* floppy_image(); void status_update(); void cmd_end(); diff --git a/src/devices/machine/sonydriv.cpp b/src/devices/machine/sonydriv.cpp index f6f1a604648..8f23a832c36 100644 --- a/src/devices/machine/sonydriv.cpp +++ b/src/devices/machine/sonydriv.cpp @@ -103,6 +103,48 @@ static int sony_enable2(void) return (sony.lines & SONY_CA1) && (sony.lines & SONY_LSTRB); } +static legacy_floppy_image_device *floppy_get_device(running_machine &machine,int drive) +{ + switch(drive) { + case 0 : return machine.device<legacy_floppy_image_device>(FLOPPY_0); + case 1 : return machine.device<legacy_floppy_image_device>(FLOPPY_1); + case 2 : return machine.device<legacy_floppy_image_device>(FLOPPY_2); + case 3 : return machine.device<legacy_floppy_image_device>(FLOPPY_3); + } + return nullptr; +} + +static legacy_floppy_image_device *floppy_get_device_by_type(running_machine &machine,int ftype,int drive) +{ + int i; + int cnt = 0; + for (i=0;i<4;i++) { + legacy_floppy_image_device *disk = floppy_get_device(machine,i); + if (disk && disk->floppy_get_drive_type()==ftype) { + if (cnt==drive) { + return disk; + } + cnt++; + } + } + return nullptr; +} + +static int floppy_get_drive_by_type(legacy_floppy_image_device *image,int ftype) +{ + int i,drive =0; + for (i=0;i<4;i++) { + legacy_floppy_image_device *disk = floppy_get_device(image->machine(),i); + if (disk && disk->floppy_get_drive_type()==ftype) { + if (image==disk) { + return drive; + } + drive++; + } + } + return -1; +} + static void load_track_data(device_t *device,int floppy_select) { int track_size; diff --git a/src/devices/machine/sonydriv.h b/src/devices/machine/sonydriv.h index 322db3f3342..8e0e5a54e5d 100644 --- a/src/devices/machine/sonydriv.h +++ b/src/devices/machine/sonydriv.h @@ -15,6 +15,11 @@ #include "imagedev/flopdrv.h" +#define FLOPPY_0 "floppy0" +#define FLOPPY_1 "floppy1" +#define FLOPPY_2 "floppy2" +#define FLOPPY_3 "floppy3" + #if 0 enum { |