From a72307040cfb534ac62e23e1f5649cb6501c2331 Mon Sep 17 00:00:00 2001 From: Mark Garlanger Date: Thu, 29 Jun 2023 10:56:30 -0500 Subject: heathkit/z37_fdc.cpp: Fixed some minor issues and cleaned up code. (#11374) * Updated port read values for the non-existent ports. * Clear interrupt block on reset. * Removed redundant member variables. * Added logging options. --- src/mame/heathkit/z37_fdc.cpp | 120 ++++++++++++++++++++++++------------------ src/mame/heathkit/z37_fdc.h | 31 +++++------ 2 files changed, 81 insertions(+), 70 deletions(-) diff --git a/src/mame/heathkit/z37_fdc.cpp b/src/mame/heathkit/z37_fdc.cpp index e47ac64ddbf..c21802958e5 100644 --- a/src/mame/heathkit/z37_fdc.cpp +++ b/src/mame/heathkit/z37_fdc.cpp @@ -12,31 +12,50 @@ #include "z37_fdc.h" +#define LOG_REG (1U << 1) // Shows register setup +#define LOG_LINES (1U << 2) // Show control lines +#define LOG_DRIVE (1U << 3) // Show drive select +#define LOG_FUNC (1U << 4) // Function calls + +#define VERBOSE (0) + #include "logmacro.h" +#define LOGREG(...) LOGMASKED(LOG_REG, __VA_ARGS__) +#define LOGLINES(...) LOGMASKED(LOG_LINES, __VA_ARGS__) +#define LOGDRIVE(...) LOGMASKED(LOG_DRIVE, __VA_ARGS__) +#define LOGFUNC(...) LOGMASKED(LOG_FUNC, __VA_ARGS__) + +#ifdef _MSC_VER +#define FUNCNAME __func__ +#else +#define FUNCNAME __PRETTY_FUNCTION__ +#endif + DEFINE_DEVICE_TYPE(HEATH_Z37_FDC, heath_z37_fdc_device, "heath_z37_fdc", "Heath H/Z-37 Soft-sectored Controller"); -heath_z37_fdc_device::heath_z37_fdc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) - : device_t(mconfig, HEATH_Z37_FDC, tag, owner, 0) - , m_fd_irq_cb(*this) - , m_drq_cb(*this) - , m_block_interrupt_cb(*this) - , m_fdc(*this, "z37_fdc") - , m_floppies(*this, "z37_fdc:%u", 0U) +heath_z37_fdc_device::heath_z37_fdc_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock): + device_t(mconfig, HEATH_Z37_FDC, tag, owner, 0), + m_fd_irq_cb(*this), + m_drq_cb(*this), + m_block_interrupt_cb(*this), + m_fdc(*this, "z37_fdc"), + m_floppies(*this, "z37_fdc:%u", 0U) { } -void heath_z37_fdc_device::ctrl_w(uint8_t val) +void heath_z37_fdc_device::ctrl_w(u8 val) { - m_control_reg = val; - bool motor_on = bool(BIT(val, ctrl_MotorsOn_c)); m_intrq_allowed = bool(BIT(val, ctrl_EnableIntReq_c)); m_drq_allowed = bool(BIT(val, ctrl_EnableDrqInt_c)); m_fdc->dden_w(BIT(val, ctrl_SetMFMRecording_c) ? CLEAR_LINE : ASSERT_LINE); + LOGREG("%s: motor on: %d, intrq allowed: %d, drq allowed: %d\n", + FUNCNAME, motor_on, m_intrq_allowed, m_drq_allowed); + if (m_drq_allowed) { m_block_interrupt_cb(ASSERT_LINE); @@ -47,30 +66,35 @@ void heath_z37_fdc_device::ctrl_w(uint8_t val) m_drq_cb(CLEAR_LINE); } - m_floppy = nullptr; if (BIT(val, ctrl_Drive_0_c)) { - m_floppy = m_floppies[0]->get_device(); + m_fdc->set_floppy(m_floppies[0]->get_device()); + LOGDRIVE("Drive selected: 0\n"); } else if (BIT(val, ctrl_Drive_1_c)) { - m_floppy = m_floppies[1]->get_device(); + m_fdc->set_floppy(m_floppies[1]->get_device()); + LOGDRIVE("Drive selected: 1\n"); } else if (BIT(val, ctrl_Drive_2_c)) { - m_floppy = m_floppies[2]->get_device(); + m_fdc->set_floppy(m_floppies[2]->get_device()); + LOGDRIVE("Drive selected: 2\n"); } else if (BIT(val, ctrl_Drive_3_c)) { - m_floppy = m_floppies[3]->get_device(); + m_fdc->set_floppy(m_floppies[3]->get_device()); + LOGDRIVE("Drive selected: 3\n"); + } + else + { + m_fdc->set_floppy(nullptr); + LOGDRIVE("Drive selected: none\n"); } - m_fdc->set_floppy(m_floppy); - - - for (uint8_t i = 0; i < 4; i++) + for (auto &elem : m_floppies) { - floppy_image_device *floppy = m_floppies[i]->get_device(); + floppy_image_device *floppy = elem->get_device(); if (floppy) { floppy->mon_w(!motor_on); @@ -78,43 +102,37 @@ void heath_z37_fdc_device::ctrl_w(uint8_t val) } } -uint8_t heath_z37_fdc_device::ctrl_r() -{ - return m_control_reg; -} - -void heath_z37_fdc_device::intf_w(uint8_t val) +void heath_z37_fdc_device::intf_w(u8 val) { m_access_track_sector = bool(BIT(val, if_SelectSectorTrack_c)); -} -uint8_t heath_z37_fdc_device::intf_r() -{ - return m_interface_reg; + LOGREG("access track/sector: %d\n", m_access_track_sector); } -void heath_z37_fdc_device::stat_w(uint8_t val) +void heath_z37_fdc_device::cmd_w(u8 val) { m_access_track_sector ? m_fdc->sector_w(val) : m_fdc->cmd_w(val); } -uint8_t heath_z37_fdc_device::stat_r() +u8 heath_z37_fdc_device::stat_r() { return m_access_track_sector ? m_fdc->sector_r() : m_fdc->status_r(); } -void heath_z37_fdc_device::data_w(uint8_t val) +void heath_z37_fdc_device::data_w(u8 val) { m_access_track_sector ? m_fdc->track_w(val) : m_fdc->data_w(val); } -uint8_t heath_z37_fdc_device::data_r() +u8 heath_z37_fdc_device::data_r() { return m_access_track_sector ? m_fdc->track_r() : m_fdc->data_r(); } -void heath_z37_fdc_device::write(offs_t reg, uint8_t val) +void heath_z37_fdc_device::write(offs_t reg, u8 val) { + LOGFUNC("%s: reg: %d val: %d\n", FUNCNAME, reg, val); + switch (reg) { case 0: @@ -124,7 +142,7 @@ void heath_z37_fdc_device::write(offs_t reg, uint8_t val) intf_w(val); break; case 2: - stat_w(val); + cmd_w(val); break; case 3: data_w(val); @@ -132,16 +150,16 @@ void heath_z37_fdc_device::write(offs_t reg, uint8_t val) } } -uint8_t heath_z37_fdc_device::read(offs_t reg) +u8 heath_z37_fdc_device::read(offs_t reg) { - uint8_t value = 0xff; + // default return for the h89 + u8 value = 0xff; + switch (reg) { case 0: - value = ctrl_r(); - break; case 1: - value = intf_r(); + // read not supported on these addresses break; case 2: value = stat_r(); @@ -151,20 +169,17 @@ uint8_t heath_z37_fdc_device::read(offs_t reg) break; } + LOGFUNC("%s: reg: %d val: %d\n", FUNCNAME, reg, value); + return value; } void heath_z37_fdc_device::device_start() { - save_item(NAME(m_control_reg)); - save_item(NAME(m_interface_reg)); save_item(NAME(m_intrq_allowed)); save_item(NAME(m_drq_allowed)); save_item(NAME(m_access_track_sector)); - m_control_reg = 0; - m_interface_reg = 0; - m_intrq_allowed = false; m_drq_allowed = false; m_access_track_sector = false; @@ -172,14 +187,13 @@ void heath_z37_fdc_device::device_start() void heath_z37_fdc_device::device_reset() { - m_control_reg = 0; - m_interface_reg = 0; - m_intrq_allowed = false; m_drq_allowed = false; m_access_track_sector = false; + m_fd_irq_cb(CLEAR_LINE); m_drq_cb(CLEAR_LINE); + m_block_interrupt_cb(CLEAR_LINE); } static void z37_floppies(device_slot_interface &device) @@ -210,12 +224,16 @@ void heath_z37_fdc_device::device_add_mconfig(machine_config &config) m_floppies[3]->enable_sound(true); } -void heath_z37_fdc_device::set_irq(uint8_t data) +void heath_z37_fdc_device::set_irq(u8 data) { + LOGLINES("set irq, allowed: %d data: %d\n", m_intrq_allowed, data); + m_fd_irq_cb(m_intrq_allowed ? data : CLEAR_LINE); } -void heath_z37_fdc_device::set_drq(uint8_t data) +void heath_z37_fdc_device::set_drq(u8 data) { + LOGLINES("set drq, allowed: %d data: %d\n", m_intrq_allowed, data); + m_drq_cb(m_drq_allowed ? data : CLEAR_LINE); } diff --git a/src/mame/heathkit/z37_fdc.h b/src/mame/heathkit/z37_fdc.h index 4ddfd64aa58..6b76aad036f 100644 --- a/src/mame/heathkit/z37_fdc.h +++ b/src/mame/heathkit/z37_fdc.h @@ -18,10 +18,10 @@ class heath_z37_fdc_device : public device_t { public: - heath_z37_fdc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock = 0); + heath_z37_fdc_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock = 0); - void write(offs_t reg, uint8_t val); - uint8_t read(offs_t reg); + void write(offs_t reg, u8 val); + u8 read(offs_t reg); auto irq_cb() { return m_fd_irq_cb.bind(); } auto drq_cb() { return m_drq_cb.bind(); } @@ -33,20 +33,18 @@ protected: virtual void device_reset() override; virtual void device_add_mconfig(machine_config &config) override; - void ctrl_w(uint8_t val); - uint8_t ctrl_r(); + void ctrl_w(u8 val); - void intf_w(uint8_t val); - uint8_t intf_r(); + void intf_w(u8 val); - void stat_w(uint8_t val); - uint8_t stat_r(); + void cmd_w(u8 val); + u8 stat_r(); - void data_w(uint8_t val); - uint8_t data_r(); + void data_w(u8 val); + u8 data_r(); - void set_irq(uint8_t data); - void set_drq(uint8_t data); + void set_irq(u8 data); + void set_drq(u8 data); private: devcb_write_line m_fd_irq_cb; @@ -56,14 +54,10 @@ private: required_device m_fdc; required_device_array m_floppies; - u8 m_control_reg; - u8 m_interface_reg; bool m_intrq_allowed; bool m_drq_allowed; bool m_access_track_sector; - floppy_image_device *m_floppy; - /// Bits set in cmd_ControlPort_c - DK.CON static constexpr u8 ctrl_EnableIntReq_c = 0; static constexpr u8 ctrl_EnableDrqInt_c = 1; @@ -75,8 +69,7 @@ private: static constexpr u8 ctrl_Drive_3_c = 7; /// Bits to set alternate registers on InterfaceControl_c - DK.INT - static constexpr uint8_t if_SelectSectorTrack_c = 0; - + static constexpr u8 if_SelectSectorTrack_c = 0; }; DECLARE_DEVICE_TYPE(HEATH_Z37_FDC, heath_z37_fdc_device) -- cgit v1.2.3