diff options
author | 2012-02-02 07:42:20 +0000 | |
---|---|---|
committer | 2012-02-02 07:42:20 +0000 | |
commit | 791c1bd94a137e34fff007e4f585d43b20b6dfc2 (patch) | |
tree | 5083b3c2c7c9181776bce4a427dbf4ba5df40d0e /src/emu/machine/ctronics.c | |
parent | 1333b77c416dbbbddfd35203d5cdd3b8fdb3bbb8 (diff) |
did centronics implementation in c++ (no whatsnew)
Diffstat (limited to 'src/emu/machine/ctronics.c')
-rw-r--r-- | src/emu/machine/ctronics.c | 374 |
1 files changed, 103 insertions, 271 deletions
diff --git a/src/emu/machine/ctronics.c b/src/emu/machine/ctronics.c index a06cf944c8b..d2d3aa30bde 100644 --- a/src/emu/machine/ctronics.c +++ b/src/emu/machine/ctronics.c @@ -6,54 +6,79 @@ #include "emu.h" #include "ctronics.h" -#include "imagedev/printer.h" -/*************************************************************************** - FUNCTION PROTOTYPES -***************************************************************************/ +// device type definition +const device_type CENTRONICS = &device_creator<centronics_device>; -static WRITE_LINE_DEVICE_HANDLER( centronics_printer_online ); -static TIMER_CALLBACK( ack_callback ); -static TIMER_CALLBACK( busy_callback ); +//------------------------------------------------- +// centronics_device - constructor +//------------------------------------------------- +centronics_device::centronics_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, CENTRONICS, "Centronics", tag, owner, clock) +{ -/*************************************************************************** - TYPE DEFINITIONS -***************************************************************************/ +} -typedef struct _centronics_state centronics_state; -struct _centronics_state -{ - printer_image_device *printer; +//------------------------------------------------- +// centronics_device - destructor +//------------------------------------------------- - devcb_resolved_write_line out_ack_func; - devcb_resolved_write_line out_busy_func; - devcb_resolved_write_line out_not_busy_func; +centronics_device::~centronics_device() +{ +} - int strobe; - int busy; - int ack; - int auto_fd; - int pe; - int fault; +//------------------------------------------------- +// device_config_complete - perform any +// operations now that the configuration is +// complete +//------------------------------------------------- - UINT8 data; -}; +void centronics_device::device_config_complete() +{ + // inherit a copy of the static data + const centronics_interface *intf = reinterpret_cast<const centronics_interface *>(static_config()); + if (intf != NULL) + *static_cast<centronics_interface *>(this) = *intf; + // or initialize to defaults if none provided + else + { + memset(&m_out_ack_func, 0, sizeof(m_out_ack_func)); + memset(&m_out_busy_func, 0, sizeof(m_out_busy_func)); + memset(&m_out_not_busy_func, 0, sizeof(m_out_not_busy_func)); + } +} -/***************************************************************************** - INLINE FUNCTIONS -*****************************************************************************/ +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- -INLINE centronics_state *get_safe_token(device_t *device) +void centronics_device::device_start() { - assert(device != NULL); - assert(device->type() == CENTRONICS); + /* set some initial values */ + m_pe = FALSE; + m_fault = FALSE; + m_busy = TRUE; + m_strobe = TRUE; - return (centronics_state *)downcast<legacy_device_base *>(device)->token(); -} + /* get printer device */ + m_printer = subdevice<printer_image_device>("printer"); + /* resolve callbacks */ + m_out_ack_func.resolve(m_out_ack_cb, *this); + m_out_busy_func.resolve(m_out_busy_cb, *this); + m_out_not_busy_func.resolve(m_out_not_busy_cb, *this); + + /* register for state saving */ + save_item(NAME(m_auto_fd)); + save_item(NAME(m_strobe)); + save_item(NAME(m_busy)); + save_item(NAME(m_ack)); + save_item(NAME(m_data)); + +} /***************************************************************************** GLOBAL VARIABLES @@ -61,7 +86,6 @@ INLINE centronics_state *get_safe_token(device_t *device) const centronics_interface standard_centronics = { - FALSE, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL @@ -73,7 +97,7 @@ const centronics_interface standard_centronics = *****************************************************************************/ const struct printer_interface centronics_printer_config = { - DEVCB_LINE(centronics_printer_online) + DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, centronics_device, printer_online) }; static MACHINE_CONFIG_FRAGMENT( centronics ) @@ -82,199 +106,111 @@ static MACHINE_CONFIG_FRAGMENT( centronics ) MACHINE_CONFIG_END -/***************************************************************************** - DEVICE INTERFACE -*****************************************************************************/ - -static DEVICE_START( centronics ) -{ - centronics_state *centronics = get_safe_token(device); - const centronics_interface *intf = (const centronics_interface *)device->static_config(); - - /* validate some basic stuff */ - assert(device->static_config() != NULL); - - /* set some initial values */ - centronics->pe = FALSE; - centronics->fault = FALSE; - centronics->busy = TRUE; - centronics->strobe = TRUE; - - /* get printer device */ - centronics->printer = device->subdevice<printer_image_device>("printer"); - - /* resolve callbacks */ - centronics->out_ack_func.resolve(intf->out_ack_func, *device); - centronics->out_busy_func.resolve(intf->out_busy_func, *device); - centronics->out_not_busy_func.resolve(intf->out_not_busy_func, *device); - - /* register for state saving */ - device->save_item(NAME(centronics->auto_fd)); - device->save_item(NAME(centronics->strobe)); - device->save_item(NAME(centronics->busy)); - device->save_item(NAME(centronics->ack)); - device->save_item(NAME(centronics->data)); -} +/*************************************************************************** + IMPLEMENTATION +***************************************************************************/ -static DEVICE_RESET( centronics ) -{ -} +//------------------------------------------------- +// machine_config_additions - device-specific +// machine configurations +//------------------------------------------------- -DEVICE_GET_INFO( centronics ) +machine_config_constructor centronics_device::device_mconfig_additions() const { - switch (state) - { - /* --- the following bits of info are returned as 64-bit signed integers --- */ - case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(centronics_state); break; - case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; - - /* --- the following bits of info are returned as pointers --- */ - case DEVINFO_PTR_MACHINE_CONFIG: info->machine_config = MACHINE_CONFIG_NAME(centronics); break; - - /* --- the following bits of info are returned as pointers to data or functions --- */ - case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(centronics); break; - case DEVINFO_FCT_STOP: /* Nothing */ break; - case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(centronics); break; - - /* --- the following bits of info are returned as NULL-terminated strings --- */ - case DEVINFO_STR_NAME: strcpy(info->s, "Centronics"); break; - case DEVINFO_STR_FAMILY: strcpy(info->s, "Centronics"); break; - case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; - case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; - case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright MESS Team"); break; - } + return MACHINE_CONFIG_NAME( centronics ); } -/*************************************************************************** - IMPLEMENTATION -***************************************************************************/ - /*------------------------------------------------- - centronics_printer_online - callback that + printer_online - callback that sets us busy when the printer goes offline -------------------------------------------------*/ -WRITE_LINE_DEVICE_HANDLER(centronics_printer_online) +WRITE_LINE_MEMBER(centronics_device::printer_online) { - centronics_state *centronics = get_safe_token(device->owner()); - /* when going online, set PE and FAULT high and BUSY low */ - centronics->pe = state; - centronics->fault = state; - centronics->busy = !state; + m_pe = state; + m_fault = state; + m_busy = !state; } +static TIMER_CALLBACK( timer_ack_callback ) +{ + centronics_device *cent = reinterpret_cast<centronics_device *>(ptr); + cent->ack_callback(param); +} -static TIMER_CALLBACK( ack_callback ) +static TIMER_CALLBACK( timer_busy_callback ) { - centronics_state *centronics = (centronics_state *)ptr; + centronics_device *cent = reinterpret_cast<centronics_device *>(ptr); + cent->busy_callback(param); +} +void centronics_device::ack_callback(UINT8 param) +{ /* signal change */ - centronics->out_ack_func(param); - centronics->ack = param; + m_out_ack_func(param); + m_ack = param; if (param == FALSE) { /* data is now ready, output it */ - centronics->printer->output(centronics->data); + m_printer->output(m_data); /* ready to receive more data, return BUSY to low */ - machine.scheduler().timer_set(attotime::from_usec(7), FUNC(busy_callback), FALSE, ptr); + machine().scheduler().timer_set(attotime::from_usec(7), FUNC(timer_busy_callback), FALSE, this); } } -static TIMER_CALLBACK( busy_callback ) +void centronics_device::busy_callback(UINT8 param) { - centronics_state *centronics = (centronics_state *)ptr; - /* signal change */ - centronics->out_busy_func(param); - centronics->out_not_busy_func(!param); - centronics->busy = param; + m_out_busy_func(param); + m_out_not_busy_func(!param); + m_busy = param; if (param == TRUE) { /* timer to turn ACK low to receive data */ - machine.scheduler().timer_set(attotime::from_usec(10), FUNC(ack_callback), FALSE, ptr); + machine().scheduler().timer_set(attotime::from_usec(10), FUNC(timer_ack_callback), FALSE, this); } else { /* timer to return ACK to high state */ - machine.scheduler().timer_set(attotime::from_usec(5), FUNC(ack_callback), TRUE, ptr); + machine().scheduler().timer_set(attotime::from_usec(5), FUNC(timer_ack_callback), TRUE, this); } } /*------------------------------------------------- - centronics_data_w - write print data --------------------------------------------------*/ - -WRITE8_DEVICE_HANDLER( centronics_data_w ) -{ - centronics_state *centronics = get_safe_token(device); - centronics->data = data; -} - - -/*------------------------------------------------- - centronics_data_r - return current data --------------------------------------------------*/ - -READ8_DEVICE_HANDLER( centronics_data_r ) -{ - centronics_state *centronics = get_safe_token(device); - return centronics->data; -} - - -/*------------------------------------------------- set_line - helper to set individual bits -------------------------------------------------*/ -static void set_line(device_t *device, int line, int state) +void centronics_device::set_line(int line, int state) { - centronics_state *centronics = get_safe_token(device); - if (state) - centronics->data |= 1 << line; + m_data |= 1 << line; else - centronics->data &= ~(1 << line); + m_data &= ~(1 << line); } /*------------------------------------------------- - centronics_dx_w - write line dx print data --------------------------------------------------*/ - -WRITE_LINE_DEVICE_HANDLER( centronics_d0_w ) { set_line(device, 0, state); } -WRITE_LINE_DEVICE_HANDLER( centronics_d1_w ) { set_line(device, 1, state); } -WRITE_LINE_DEVICE_HANDLER( centronics_d2_w ) { set_line(device, 2, state); } -WRITE_LINE_DEVICE_HANDLER( centronics_d3_w ) { set_line(device, 3, state); } -WRITE_LINE_DEVICE_HANDLER( centronics_d4_w ) { set_line(device, 4, state); } -WRITE_LINE_DEVICE_HANDLER( centronics_d5_w ) { set_line(device, 5, state); } -WRITE_LINE_DEVICE_HANDLER( centronics_d6_w ) { set_line(device, 6, state); } -WRITE_LINE_DEVICE_HANDLER( centronics_d7_w ) { set_line(device, 7, state); } - - -/*------------------------------------------------- centronics_strobe_w - signal that data is ready -------------------------------------------------*/ -WRITE_LINE_DEVICE_HANDLER( centronics_strobe_w ) +WRITE_LINE_MEMBER( centronics_device::strobe_w ) { - centronics_state *centronics = get_safe_token(device); - /* look for a high -> low transition */ - if (centronics->strobe == TRUE && state == FALSE && centronics->busy == FALSE) + if (m_strobe == TRUE && state == FALSE && m_busy == FALSE) { /* STROBE has gone low, data is ready */ - device->machine().scheduler().timer_set(attotime::zero, FUNC(busy_callback), TRUE, centronics); + machine().scheduler().timer_set(attotime::zero, FUNC(timer_busy_callback), TRUE, this); } - centronics->strobe = state; + m_strobe = state; } @@ -283,113 +219,9 @@ WRITE_LINE_DEVICE_HANDLER( centronics_strobe_w ) printer (centronics mode) -------------------------------------------------*/ -WRITE_LINE_DEVICE_HANDLER( centronics_prime_w ) -{ - assert(((const centronics_interface *)device->static_config())->is_ibmpc == FALSE); - - /* reset printer if line is low */ - if (state == FALSE) - DEVICE_RESET_CALL( centronics ); -} - - -/*------------------------------------------------- - centronics_init_w - initialize and reset - printer (ibm mode) --------------------------------------------------*/ - -WRITE_LINE_DEVICE_HANDLER( centronics_init_w ) +WRITE_LINE_MEMBER( centronics_device::init_prime_w ) { - assert(((const centronics_interface *)device->static_config())->is_ibmpc == TRUE); - /* reset printer if line is low */ if (state == FALSE) - DEVICE_RESET_CALL( centronics ); + device_reset(); } - - -/*------------------------------------------------- - centronics_autofeed_w - auto line feed --------------------------------------------------*/ - -WRITE_LINE_DEVICE_HANDLER( centronics_autofeed_w ) -{ - centronics_state *centronics = get_safe_token(device); - assert(((const centronics_interface *)device->static_config())->is_ibmpc == TRUE); - - centronics->auto_fd = state; -} - - -/*------------------------------------------------- - centronics_ack_r - return the state of the - ack line --------------------------------------------------*/ - -READ_LINE_DEVICE_HANDLER( centronics_ack_r ) -{ - centronics_state *centronics = get_safe_token(device); - return centronics->ack; -} - - -/*------------------------------------------------- - centronics_busy_r - return the state of the - busy line --------------------------------------------------*/ - -READ_LINE_DEVICE_HANDLER( centronics_busy_r ) -{ - centronics_state *centronics = get_safe_token(device); - return centronics->busy; -} - - -/*------------------------------------------------- - centronics_pe_r - return the state of the - pe line --------------------------------------------------*/ - -READ_LINE_DEVICE_HANDLER( centronics_pe_r ) -{ - centronics_state *centronics = get_safe_token(device); - return centronics->pe; -} - - -/*------------------------------------------------- - centronics_not_busy_r - return the state of the - not busy line --------------------------------------------------*/ - -READ_LINE_DEVICE_HANDLER( centronics_not_busy_r ) -{ - centronics_state *centronics = get_safe_token(device); - return !centronics->busy; -} - - -/*------------------------------------------------- - centronics_vcc_r - return the state of the - vcc line --------------------------------------------------*/ - -READ_LINE_DEVICE_HANDLER( centronics_vcc_r ) -{ - /* always return high */ - return TRUE; -} - - -/*------------------------------------------------- - centronics_fault_r - return the state of the - fault line --------------------------------------------------*/ - -READ_LINE_DEVICE_HANDLER( centronics_fault_r ) -{ - centronics_state *centronics = get_safe_token(device); - return centronics->fault; -} - -DEFINE_LEGACY_DEVICE(CENTRONICS, centronics); |