From bc7c4e397fee3cc50f90b323f509cb358d5c35ba Mon Sep 17 00:00:00 2001 From: Michael Zapf Date: Thu, 28 Mar 2024 23:34:02 +0100 Subject: [PATCH] ti99: Replaced static_cast with dynamic_cast (mametesters 06824) --- src/devices/bus/ti99/gromport/cartridges.cpp | 3 ++- src/devices/bus/ti99/gromport/gromport.cpp | 10 ++++++++-- src/devices/bus/ti99/peb/cc_fdc.cpp | 19 +++++++++++-------- src/devices/bus/ti99/peb/myarcfdc.cpp | 3 ++- src/devices/bus/ti99/peb/scsicard.cpp | 3 ++- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/devices/bus/ti99/gromport/cartridges.cpp b/src/devices/bus/ti99/gromport/cartridges.cpp index 832d3ca2950..f60e90d5e7e 100644 --- a/src/devices/bus/ti99/gromport/cartridges.cpp +++ b/src/devices/bus/ti99/gromport/cartridges.cpp @@ -452,7 +452,8 @@ bool ti99_cartridge_device::is_grom_idle() void ti99_cartridge_device::device_config_complete() { - m_connector = static_cast(owner()); + m_connector = dynamic_cast(owner()); + // owner is the empty_state during -listxml, so this will be nullptr } /* diff --git a/src/devices/bus/ti99/gromport/gromport.cpp b/src/devices/bus/ti99/gromport/gromport.cpp index 518750d6402..77a9212d5b5 100644 --- a/src/devices/bus/ti99/gromport/gromport.cpp +++ b/src/devices/bus/ti99/gromport/gromport.cpp @@ -244,7 +244,12 @@ bool gromport_device::is_grom_idle() void gromport_device::device_config_complete() { - m_connector = downcast(subdevices().first()); + if (subdevices().first() != nullptr) + { + m_connector = dynamic_cast(subdevices().first()); + if (m_connector == nullptr) + throw emu_fatalerror("gromport_device: cartridge connector not found"); + } } INPUT_PORTS_START(gromport) @@ -283,7 +288,8 @@ void cartridge_connector_device::ready_line(int state) void cartridge_connector_device::device_config_complete() { - m_gromport = static_cast(owner()); + m_gromport = dynamic_cast(owner()); + // owner is the empty_state during -listxml, so this will be nullptr } } // end namespace bus::ti99::gromport diff --git a/src/devices/bus/ti99/peb/cc_fdc.cpp b/src/devices/bus/ti99/peb/cc_fdc.cpp index d215560e8b0..2fe2a74b3a0 100644 --- a/src/devices/bus/ti99/peb/cc_fdc.cpp +++ b/src/devices/bus/ti99/peb/cc_fdc.cpp @@ -567,9 +567,10 @@ ROM_END void corcomp_dcc_device::device_config_complete() { - m_decpal = static_cast(subdevice(CCDCC_PALU2_TAG)); - m_ctrlpal = static_cast(subdevice(CCDCC_PALU1_TAG)); - connect_drives(); + m_decpal = dynamic_cast(subdevice(CCDCC_PALU2_TAG)); + m_ctrlpal = dynamic_cast(subdevice(CCDCC_PALU1_TAG)); + if (m_decpal != nullptr) + connect_drives(); } ioport_constructor corcomp_fdc_device::device_input_ports() const @@ -605,7 +606,8 @@ ccfdc_sel_pal_device::ccfdc_sel_pal_device(const machine_config &mconfig, device void ccfdc_dec_pal_device::device_config_complete() { - m_board = static_cast(owner()); + m_board = dynamic_cast(owner()); + // owner is the empty_state during -listxml, so this will be nullptr } /* @@ -707,8 +709,9 @@ int ccdcc_palu1_device::ready_out() void ccdcc_palu1_device::device_config_complete() { - m_board = static_cast(owner()); - m_decpal = static_cast(owner()->subdevice(CCDCC_PALU2_TAG)); + m_board = dynamic_cast(owner()); + m_decpal = dynamic_cast(owner()->subdevice(CCDCC_PALU2_TAG)); + // owner is the empty_state during -listxml, so this will be nullptr } // ============================================================================ @@ -825,8 +828,8 @@ int ccfdc_palu6_device::ready_out() void ccfdc_palu6_device::device_config_complete() { - m_board = static_cast(owner()); - m_decpal = static_cast(owner()->subdevice(CCFDC_PALU12_TAG)); + m_board = dynamic_cast(owner()); + m_decpal = dynamic_cast(owner()->subdevice(CCFDC_PALU12_TAG)); } } // end namespace bus::ti99::peb diff --git a/src/devices/bus/ti99/peb/myarcfdc.cpp b/src/devices/bus/ti99/peb/myarcfdc.cpp index 5e345f5ecb6..bcaacf0222e 100644 --- a/src/devices/bus/ti99/peb/myarcfdc.cpp +++ b/src/devices/bus/ti99/peb/myarcfdc.cpp @@ -514,7 +514,8 @@ bool ddcc1_pal_device::cs259() void ddcc1_pal_device::device_config_complete() { - m_board = static_cast(owner()); + m_board = dynamic_cast(owner()); + // owner is the empty_state during -listxml, so this will be nullptr } } // end namespace bus::ti99::peb diff --git a/src/devices/bus/ti99/peb/scsicard.cpp b/src/devices/bus/ti99/peb/scsicard.cpp index 9dbb5fc156f..1299ccc45a9 100644 --- a/src/devices/bus/ti99/peb/scsicard.cpp +++ b/src/devices/bus/ti99/peb/scsicard.cpp @@ -697,7 +697,8 @@ void whtscsi_pld_device::update_line_states(int address, bool drq, bool irq) void whtscsi_pld_device::device_config_complete() { - m_board = static_cast(owner()); + m_board = dynamic_cast(owner()); + // owner is the empty_state during -listxml, so this will be nullptr } } // end namespace bus::ti99::peb