src/mess/machine/serial.c
| r0 | r14422 | |
| 1 | #include "emu.h" |
| 2 | #include "serial.h" |
| 3 | |
| 4 | const device_type SERIAL_PORT = &device_creator<serial_port_device>; |
| 5 | |
| 6 | device_serial_port_interface::device_serial_port_interface(const machine_config &mconfig, device_t &device) |
| 7 | : device_slot_card_interface(mconfig, device) |
| 8 | { |
| 9 | m_rdata = 0; |
| 10 | m_tdata = 0; |
| 11 | m_rbit = FALSE; |
| 12 | m_tbit = FALSE; |
| 13 | } |
| 14 | |
| 15 | device_serial_port_interface::~device_serial_port_interface() |
| 16 | { |
| 17 | } |
| 18 | |
| 19 | serial_port_device::serial_port_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 20 | : device_t(mconfig, SERIAL_PORT, "Serial Port", tag, owner, clock), |
| 21 | device_slot_interface(mconfig, *this), |
| 22 | m_dev(NULL) |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | serial_port_device::~serial_port_device() |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | void serial_port_device::device_config_complete() |
| 31 | { |
| 32 | const serial_port_interface *intf = reinterpret_cast<const serial_port_interface *>(static_config()); |
| 33 | if (intf != NULL) |
| 34 | { |
| 35 | *static_cast<serial_port_interface *>(this) = *intf; |
| 36 | } |
| 37 | else |
| 38 | { |
| 39 | memset(&m_out_rx8_cb, 0, sizeof(m_out_rx8_cb)); |
| 40 | memset(&m_out_rx_cb, 0, sizeof(m_out_rx_cb)); |
| 41 | } |
| 42 | m_dev = dynamic_cast<device_serial_port_interface *>(get_card_device()); |
| 43 | } |
| 44 | |
| 45 | void serial_port_device::device_start() |
| 46 | { |
| 47 | m_out_rx8_func.resolve(m_out_rx8_cb, *this); |
| 48 | m_out_rx_func.resolve(m_out_rx_cb, *this); |
| 49 | } |
| 50 | |
| 51 | const device_type RS232_PORT = &device_creator<rs232_port_device>; |
| 52 | |
| 53 | device_rs232_port_interface::device_rs232_port_interface(const machine_config &mconfig, device_t &device) |
| 54 | : device_serial_port_interface(mconfig, device) |
| 55 | { |
| 56 | m_dtr = FALSE; |
| 57 | m_rts = FALSE; |
| 58 | m_dcd = FALSE; |
| 59 | m_dsr = FALSE; |
| 60 | m_ri = FALSE; |
| 61 | m_cts = FALSE; |
| 62 | } |
| 63 | |
| 64 | device_rs232_port_interface::~device_rs232_port_interface() |
| 65 | { |
| 66 | } |
| 67 | |
| 68 | rs232_port_device::rs232_port_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 69 | : serial_port_device(mconfig, tag, owner, clock) |
| 70 | { |
| 71 | } |
| 72 | |
| 73 | rs232_port_device::~rs232_port_device() |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | void rs232_port_device::device_config_complete() |
| 78 | { |
| 79 | const rs232_port_interface *intf = reinterpret_cast<const rs232_port_interface *>(static_config()); |
| 80 | if (intf != NULL) |
| 81 | { |
| 82 | *static_cast<rs232_port_interface *>(this) = *intf; |
| 83 | memcpy(&(serial_port_interface::m_out_rx8_cb), &(rs232_port_interface::m_out_rx8_cb), sizeof(rs232_port_interface::m_out_rx8_cb)); |
| 84 | memcpy(&(serial_port_interface::m_out_rx_cb), &(rs232_port_interface::m_out_rx_cb), sizeof(rs232_port_interface::m_out_rx_cb)); |
| 85 | } |
| 86 | else |
| 87 | { |
| 88 | memset(&(serial_port_interface::m_out_rx8_cb), 0, sizeof(serial_port_interface::m_out_rx8_cb)); |
| 89 | memset(&(serial_port_interface::m_out_rx_cb), 0, sizeof(serial_port_interface::m_out_rx_cb)); |
| 90 | memset(&m_out_dcd_cb, 0, sizeof(m_out_dcd_cb)); |
| 91 | memset(&m_out_dsr_cb, 0, sizeof(m_out_dsr_cb)); |
| 92 | memset(&m_out_ri_cb, 0, sizeof(m_out_ri_cb)); |
| 93 | memset(&m_out_cts_cb, 0, sizeof(m_out_cts_cb)); |
| 94 | } |
| 95 | m_dev = dynamic_cast<device_rs232_port_interface *>(get_card_device()); |
| 96 | } |
| 97 | |
| 98 | void rs232_port_device::device_start() |
| 99 | { |
| 100 | serial_port_device::device_start(); |
| 101 | m_out_dcd_func.resolve(m_out_dcd_cb, *this); |
| 102 | m_out_dsr_func.resolve(m_out_dsr_cb, *this); |
| 103 | m_out_ri_func.resolve(m_out_ri_cb, *this); |
| 104 | m_out_cts_func.resolve(m_out_cts_cb, *this); |
| 105 | } |
src/mess/machine/serial.h
| r0 | r14422 | |
| 1 | #ifndef __SERIAL_H__ |
| 2 | #define __SERIAL_H__ |
| 3 | |
| 4 | #include "emu.h" |
| 5 | |
| 6 | #define MCFG_SERIAL_PORT_ADD(_tag, _intf, _slot_intf, _def_slot, _def_inp) \ |
| 7 | MCFG_DEVICE_ADD(_tag, SERIAL_PORT, 0) \ |
| 8 | MCFG_DEVICE_CONFIG(_intf) \ |
| 9 | MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, _def_inp) |
| 10 | |
| 11 | #define MCFG_RS232_PORT_ADD(_tag, _intf, _slot_intf, _def_slot, _def_inp) \ |
| 12 | MCFG_DEVICE_ADD(_tag, RS232_PORT, 0) \ |
| 13 | MCFG_DEVICE_CONFIG(_intf) \ |
| 14 | MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, _def_inp) |
| 15 | |
| 16 | struct serial_port_interface |
| 17 | { |
| 18 | devcb_write8 m_out_rx8_cb; |
| 19 | devcb_write_line m_out_rx_cb; |
| 20 | }; |
| 21 | |
| 22 | class device_serial_port_interface : public device_slot_card_interface |
| 23 | { |
| 24 | public: |
| 25 | device_serial_port_interface(const machine_config &mconfig, device_t &device); |
| 26 | virtual ~device_serial_port_interface(); |
| 27 | |
| 28 | virtual void tx8(UINT8 data) { m_tdata = data; } |
| 29 | virtual UINT8 rx8() { return m_rdata; } |
| 30 | virtual void tx(UINT8 state) { m_tbit = state; } |
| 31 | virtual int rx() { return m_rbit; } |
| 32 | protected: |
| 33 | UINT8 m_rdata; |
| 34 | UINT8 m_rbit; |
| 35 | UINT8 m_tdata; |
| 36 | UINT8 m_tbit; |
| 37 | }; |
| 38 | |
| 39 | class serial_port_device : public device_t, |
| 40 | public serial_port_interface, |
| 41 | public device_slot_interface |
| 42 | { |
| 43 | public: |
| 44 | serial_port_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 45 | virtual ~serial_port_device(); |
| 46 | |
| 47 | DECLARE_WRITE8_MEMBER( tx8 ) { if(m_dev) m_dev->tx8(data); } |
| 48 | DECLARE_READ8_MEMBER( rx8 ) { return (m_dev) ? m_dev->rx8() : 0; } |
| 49 | |
| 50 | DECLARE_WRITE_LINE_MEMBER( tx ) { if(m_dev) m_dev->tx(state); } |
| 51 | DECLARE_READ_LINE_MEMBER( rx ) { return (m_dev) ? m_dev->rx() : 0; } |
| 52 | |
| 53 | void out_rx8(UINT8 data) { m_out_rx8_func(0, data); } |
| 54 | void out_rx(UINT8 param) { m_out_rx_func(param); } |
| 55 | protected: |
| 56 | virtual void device_start(); |
| 57 | virtual void device_config_complete(); |
| 58 | |
| 59 | private: |
| 60 | devcb_resolved_write8 m_out_rx8_func; |
| 61 | devcb_resolved_write_line m_out_rx_func; |
| 62 | |
| 63 | device_serial_port_interface *m_dev; |
| 64 | }; |
| 65 | |
| 66 | extern const device_type SERIAL_PORT; |
| 67 | |
| 68 | struct rs232_port_interface |
| 69 | { |
| 70 | devcb_write8 m_out_rx8_cb; |
| 71 | devcb_write_line m_out_rx_cb; |
| 72 | devcb_write_line m_out_dcd_cb; |
| 73 | devcb_write_line m_out_dsr_cb; |
| 74 | devcb_write_line m_out_ri_cb; |
| 75 | devcb_write_line m_out_cts_cb; |
| 76 | }; |
| 77 | |
| 78 | class device_rs232_port_interface : public device_serial_port_interface |
| 79 | { |
| 80 | public: |
| 81 | device_rs232_port_interface(const machine_config &mconfig, device_t &device); |
| 82 | virtual ~device_rs232_port_interface(); |
| 83 | |
| 84 | virtual void dtr_w(UINT8 state) { m_dtr = state; } |
| 85 | virtual void rts_w(UINT8 state) { m_rts = state; } |
| 86 | |
| 87 | virtual UINT8 dcd_r() { return m_dcd; } |
| 88 | virtual UINT8 dsr_r() { return m_dsr; } |
| 89 | virtual UINT8 ri_r() { return m_ri; } |
| 90 | virtual UINT8 cts_r() { return m_cts; } |
| 91 | protected: |
| 92 | UINT8 m_dtr; |
| 93 | UINT8 m_rts; |
| 94 | UINT8 m_dcd; |
| 95 | UINT8 m_dsr; |
| 96 | UINT8 m_ri; |
| 97 | UINT8 m_cts; |
| 98 | }; |
| 99 | |
| 100 | class rs232_port_device : public serial_port_device, |
| 101 | public rs232_port_interface |
| 102 | { |
| 103 | public: |
| 104 | rs232_port_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 105 | virtual ~rs232_port_device(); |
| 106 | |
| 107 | DECLARE_WRITE_LINE_MEMBER( dtr_w ) { if (m_dev) m_dev->dtr_w(state); } |
| 108 | DECLARE_WRITE_LINE_MEMBER( rts_w ) { if (m_dev) m_dev->rts_w(state); } |
| 109 | |
| 110 | DECLARE_READ_LINE_MEMBER( dcd_r ) { return (m_dev) ? m_dev->dcd_r() : 0; } |
| 111 | DECLARE_READ_LINE_MEMBER( dsr_r ) { return (m_dev) ? m_dev->dsr_r() : 0; } |
| 112 | DECLARE_READ_LINE_MEMBER( ri_r ) { return (m_dev) ? m_dev->ri_r() : 0; } |
| 113 | DECLARE_READ_LINE_MEMBER( cts_r ) { return (m_dev) ? m_dev->cts_r() : 0; } |
| 114 | |
| 115 | void out_dcd(UINT8 param) { m_out_dcd_func(param); } |
| 116 | void out_dsr(UINT8 param) { m_out_dsr_func(param); } |
| 117 | void out_ri(UINT8 param) { m_out_ri_func(param); } |
| 118 | void out_cts(UINT8 param) { m_out_cts_func(param); } |
| 119 | |
| 120 | protected: |
| 121 | virtual void device_start(); |
| 122 | virtual void device_config_complete(); |
| 123 | |
| 124 | private: |
| 125 | device_rs232_port_interface *m_dev; |
| 126 | |
| 127 | devcb_resolved_write_line m_out_dcd_func; |
| 128 | devcb_resolved_write_line m_out_dsr_func; |
| 129 | devcb_resolved_write_line m_out_ri_func; |
| 130 | devcb_resolved_write_line m_out_cts_func; |
| 131 | }; |
| 132 | |
| 133 | extern const device_type RS232_PORT; |
| 134 | |
| 135 | #endif |
src/mess/machine/isa_com.c
| r14421 | r14422 | |
| 7 | 7 | #include "emu.h" |
| 8 | 8 | #include "isa_com.h" |
| 9 | 9 | #include "machine/ins8250.h" |
| 10 | | #include "machine/pc_mouse.h" |
| 10 | #include "machine/ser_mouse.h" |
| 11 | 11 | |
| 12 | 12 | /* called when a interrupt is set/cleared from com hardware */ |
| 13 | 13 | static WRITE_LINE_DEVICE_HANDLER( pc_com_interrupt_1 ) |
| r14421 | r14422 | |
| 22 | 22 | com->m_isa->irq3_w(state); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | | /* called when com registers read/written - used to update peripherals that |
| 26 | | are connected */ |
| 27 | | static void pc_com_refresh_connected_common(device_t *device, int n, int data) |
| 25 | static void pc_com_refresh_connected_common(device_t *uart, int n, int data) |
| 28 | 26 | { |
| 29 | | /* mouse connected to this port? */ |
| 30 | | if (input_port_read(*device->owner(), "DSW") & (0x80>>n)) |
| 31 | | pc_mouse_handshake_in(device,data); |
| 27 | isa8_com_device *com = downcast<isa8_com_device *>(uart->owner()); |
| 28 | rs232_port_device *port = com->get_port(n); |
| 29 | |
| 30 | port->dtr_w(data & 1); |
| 31 | port->rts_w((data & 2) && 1); |
| 32 | ins8250_handshake_in(uart, (port->cts_r() << 4)|(port->dsr_r() << 5)|(port->ri_r() << 6)|(port->dcd_r() << 7)); |
| 32 | 33 | } |
| 33 | 34 | |
| 34 | 35 | static INS8250_HANDSHAKE_OUT( pc_com_handshake_out_0 ) { pc_com_refresh_connected_common( device, 0, data ); } |
| r14421 | r14422 | |
| 36 | 37 | static INS8250_HANDSHAKE_OUT( pc_com_handshake_out_2 ) { pc_com_refresh_connected_common( device, 2, data ); } |
| 37 | 38 | static INS8250_HANDSHAKE_OUT( pc_com_handshake_out_3 ) { pc_com_refresh_connected_common( device, 3, data ); } |
| 38 | 39 | |
| 40 | static void pc_com_tx(device_t *uart, UINT8 data, int n) |
| 41 | { |
| 42 | isa8_com_device *com = downcast<isa8_com_device *>(uart->owner()); |
| 43 | com->get_port(n)->tx8(*memory_nonspecific_space(uart->machine()), 0, data); |
| 44 | } |
| 45 | |
| 46 | static INS8250_TRANSMIT( pc_com_tx_0 ) { pc_com_tx(device, data, 0); } |
| 47 | static INS8250_TRANSMIT( pc_com_tx_1 ) { pc_com_tx(device, data, 1); } |
| 48 | static INS8250_TRANSMIT( pc_com_tx_2 ) { pc_com_tx(device, data, 2); } |
| 49 | static INS8250_TRANSMIT( pc_com_tx_3 ) { pc_com_tx(device, data, 3); } |
| 50 | |
| 51 | WRITE8_DEVICE_HANDLER( pc_com_rx_0 ) { ins8250_receive(downcast<isa8_com_device *>(device->owner())->get_uart(0), data); } |
| 52 | WRITE8_DEVICE_HANDLER( pc_com_rx_1 ) { ins8250_receive(downcast<isa8_com_device *>(device->owner())->get_uart(1), data); } |
| 53 | WRITE8_DEVICE_HANDLER( pc_com_rx_2 ) { ins8250_receive(downcast<isa8_com_device *>(device->owner())->get_uart(2), data); } |
| 54 | WRITE8_DEVICE_HANDLER( pc_com_rx_3 ) { ins8250_receive(downcast<isa8_com_device *>(device->owner())->get_uart(3), data); } |
| 55 | |
| 39 | 56 | static const ins8250_interface genpc_com_interface[4]= |
| 40 | 57 | { |
| 41 | 58 | { |
| 42 | 59 | 1843200, |
| 43 | 60 | DEVCB_LINE(pc_com_interrupt_1), |
| 44 | | NULL, |
| 61 | pc_com_tx_0, |
| 45 | 62 | pc_com_handshake_out_0, |
| 46 | 63 | NULL |
| 47 | 64 | }, |
| 48 | 65 | { |
| 49 | 66 | 1843200, |
| 50 | 67 | DEVCB_LINE(pc_com_interrupt_2), |
| 51 | | NULL, |
| 68 | pc_com_tx_1, |
| 52 | 69 | pc_com_handshake_out_1, |
| 53 | 70 | NULL |
| 54 | 71 | }, |
| 55 | 72 | { |
| 56 | 73 | 1843200, |
| 57 | 74 | DEVCB_LINE(pc_com_interrupt_1), |
| 58 | | NULL, |
| 75 | pc_com_tx_2, |
| 59 | 76 | pc_com_handshake_out_2, |
| 60 | 77 | NULL |
| 61 | 78 | }, |
| 62 | 79 | { |
| 63 | 80 | 1843200, |
| 64 | 81 | DEVCB_LINE(pc_com_interrupt_2), |
| 65 | | NULL, |
| 82 | pc_com_tx_3, |
| 66 | 83 | pc_com_handshake_out_3, |
| 67 | 84 | NULL |
| 68 | 85 | } |
| 69 | 86 | }; |
| 70 | 87 | |
| 88 | static const rs232_port_interface serport_config[4] = |
| 89 | { |
| 90 | { |
| 91 | DEVCB_HANDLER( pc_com_rx_0 ), |
| 92 | DEVCB_NULL, |
| 93 | DEVCB_NULL, |
| 94 | DEVCB_NULL, |
| 95 | DEVCB_NULL, |
| 96 | DEVCB_NULL |
| 97 | }, |
| 98 | { |
| 99 | DEVCB_HANDLER( pc_com_rx_1 ), |
| 100 | DEVCB_NULL, |
| 101 | DEVCB_NULL, |
| 102 | DEVCB_NULL, |
| 103 | DEVCB_NULL, |
| 104 | DEVCB_NULL |
| 105 | }, |
| 106 | { |
| 107 | DEVCB_HANDLER( pc_com_rx_2 ), |
| 108 | DEVCB_NULL, |
| 109 | DEVCB_NULL, |
| 110 | DEVCB_NULL, |
| 111 | DEVCB_NULL, |
| 112 | DEVCB_NULL |
| 113 | }, |
| 114 | { |
| 115 | DEVCB_HANDLER( pc_com_rx_3 ), |
| 116 | DEVCB_NULL, |
| 117 | DEVCB_NULL, |
| 118 | DEVCB_NULL, |
| 119 | DEVCB_NULL, |
| 120 | DEVCB_NULL |
| 121 | } |
| 122 | }; |
| 123 | |
| 124 | static SLOT_INTERFACE_START(isa_com) |
| 125 | SLOT_INTERFACE("mouse", SERIAL_MOUSE) |
| 126 | SLOT_INTERFACE_END |
| 127 | |
| 71 | 128 | static MACHINE_CONFIG_FRAGMENT( com_config ) |
| 72 | 129 | MCFG_INS8250_ADD( "uart_0", genpc_com_interface[0] ) |
| 73 | 130 | MCFG_INS8250_ADD( "uart_1", genpc_com_interface[1] ) |
| 74 | 131 | MCFG_INS8250_ADD( "uart_2", genpc_com_interface[2] ) |
| 75 | 132 | MCFG_INS8250_ADD( "uart_3", genpc_com_interface[3] ) |
| 133 | MCFG_RS232_PORT_ADD( "serport0", serport_config[0], isa_com, "mouse", NULL ) |
| 134 | MCFG_RS232_PORT_ADD( "serport1", serport_config[1], isa_com, NULL, NULL ) |
| 135 | MCFG_RS232_PORT_ADD( "serport2", serport_config[3], isa_com, NULL, NULL ) |
| 136 | MCFG_RS232_PORT_ADD( "serport3", serport_config[4], isa_com, NULL, NULL ) |
| 76 | 137 | MACHINE_CONFIG_END |
| 77 | 138 | |
| 78 | | static INPUT_PORTS_START( com ) |
| 79 | | PORT_START("DSW") |
| 80 | | PORT_DIPNAME( 0xf0, 0x80, "Serial mouse") |
| 81 | | PORT_DIPSETTING( 0x80, "COM1" ) |
| 82 | | PORT_DIPSETTING( 0x40, "COM2" ) |
| 83 | | PORT_DIPSETTING( 0x20, "COM3" ) |
| 84 | | PORT_DIPSETTING( 0x10, "COM4" ) |
| 85 | | PORT_DIPSETTING( 0x00, DEF_STR( None ) ) |
| 86 | | PORT_BIT( 0x0f, 0x0f, IPT_UNUSED ) |
| 87 | | INPUT_PORTS_END |
| 88 | | |
| 89 | 139 | //************************************************************************** |
| 90 | 140 | // GLOBAL VARIABLES |
| 91 | 141 | //************************************************************************** |
| r14421 | r14422 | |
| 102 | 152 | return MACHINE_CONFIG_NAME( com_config ); |
| 103 | 153 | } |
| 104 | 154 | |
| 105 | | //------------------------------------------------- |
| 106 | | // input_ports - device-specific input ports |
| 107 | | //------------------------------------------------- |
| 108 | | |
| 109 | | ioport_constructor isa8_com_device::device_input_ports() const |
| 110 | | { |
| 111 | | return INPUT_PORTS_NAME( com ); |
| 112 | | } |
| 113 | | |
| 114 | 155 | //************************************************************************** |
| 115 | 156 | // LIVE DEVICE |
| 116 | 157 | //************************************************************************** |
| r14421 | r14422 | |
| 139 | 180 | void isa8_com_device::device_start() |
| 140 | 181 | { |
| 141 | 182 | set_isa_device(); |
| 142 | | m_isa->install_device(subdevice("uart_0"), 0x03f8, 0x03ff, 0, 0, FUNC(ins8250_r), FUNC(ins8250_w) ); |
| 143 | | m_isa->install_device(subdevice("uart_1"), 0x02f8, 0x02ff, 0, 0, FUNC(ins8250_r), FUNC(ins8250_w) ); |
| 144 | | m_isa->install_device(subdevice("uart_2"), 0x03e8, 0x03ef, 0, 0, FUNC(ins8250_r), FUNC(ins8250_w) ); |
| 145 | | m_isa->install_device(subdevice("uart_3"), 0x02e8, 0x02ef, 0, 0, FUNC(ins8250_r), FUNC(ins8250_w) ); |
| 183 | m_uart[0] = subdevice("uart_0"); |
| 184 | m_uart[1] = subdevice("uart_1"); |
| 185 | m_uart[2] = subdevice("uart_2"); |
| 186 | m_uart[3] = subdevice("uart_3"); |
| 187 | m_isa->install_device(m_uart[0], 0x03f8, 0x03ff, 0, 0, FUNC(ins8250_r), FUNC(ins8250_w) ); |
| 188 | m_isa->install_device(m_uart[1], 0x02f8, 0x02ff, 0, 0, FUNC(ins8250_r), FUNC(ins8250_w) ); |
| 189 | m_isa->install_device(m_uart[2], 0x03e8, 0x03ef, 0, 0, FUNC(ins8250_r), FUNC(ins8250_w) ); |
| 190 | m_isa->install_device(m_uart[3], 0x02e8, 0x02ef, 0, 0, FUNC(ins8250_r), FUNC(ins8250_w) ); |
| 191 | |
| 192 | m_serport[0] = subdevice<rs232_port_device>("serport0"); |
| 193 | m_serport[1] = subdevice<rs232_port_device>("serport1"); |
| 194 | m_serport[2] = subdevice<rs232_port_device>("serport2"); |
| 195 | m_serport[3] = subdevice<rs232_port_device>("serport3"); |
| 146 | 196 | } |
| 147 | 197 | |
| 148 | 198 | //------------------------------------------------- |
| r14421 | r14422 | |
| 151 | 201 | |
| 152 | 202 | void isa8_com_device::device_reset() |
| 153 | 203 | { |
| 154 | | pc_mouse_initialise(machine()); |
| 155 | | pc_mouse_set_serial_port(subdevice("uart_0")); |
| 156 | 204 | } |
| 157 | 205 | |
| 158 | 206 | static MACHINE_CONFIG_FRAGMENT( com_at_config ) |
| r14421 | r14422 | |
| 160 | 208 | MCFG_NS16450_ADD( "uart_1", genpc_com_interface[1] ) |
| 161 | 209 | MCFG_NS16450_ADD( "uart_2", genpc_com_interface[2] ) |
| 162 | 210 | MCFG_NS16450_ADD( "uart_3", genpc_com_interface[3] ) |
| 211 | MCFG_RS232_PORT_ADD( "serport0", serport_config[0], isa_com, "mouse", NULL ) |
| 212 | MCFG_RS232_PORT_ADD( "serport1", serport_config[1], isa_com, NULL, NULL ) |
| 213 | MCFG_RS232_PORT_ADD( "serport2", serport_config[3], isa_com, NULL, NULL ) |
| 214 | MCFG_RS232_PORT_ADD( "serport3", serport_config[4], isa_com, NULL, NULL ) |
| 163 | 215 | MACHINE_CONFIG_END |
| 164 | 216 | |
| 165 | 217 | //************************************************************************** |
src/mess/machine/ser_mouse.c
| r0 | r14422 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | machine/ser_mouse.c |
| 4 | |
| 5 | Code for emulating PC-style serial mouses |
| 6 | |
| 7 | ***************************************************************************/ |
| 8 | |
| 9 | #include "machine/ser_mouse.h" |
| 10 | |
| 11 | |
| 12 | const device_type SERIAL_MOUSE = &device_creator<serial_mouse_device>; |
| 13 | |
| 14 | serial_mouse_device::serial_mouse_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 15 | : device_t(mconfig, SERIAL_MOUSE, "Serial Mouse", tag, owner, clock), |
| 16 | device_rs232_port_interface(mconfig, *this) |
| 17 | { |
| 18 | } |
| 19 | |
| 20 | void serial_mouse_device::device_start() |
| 21 | { |
| 22 | m_owner = dynamic_cast<rs232_port_device *>(owner()); |
| 23 | } |
| 24 | |
| 25 | void serial_mouse_device::device_reset() |
| 26 | { |
| 27 | m_head = m_tail = 0; |
| 28 | m_timer = timer_alloc(); |
| 29 | m_old_dtr = m_old_rts = 0; |
| 30 | } |
| 31 | |
| 32 | /* add data to queue */ |
| 33 | void serial_mouse_device::queue_data(int data) |
| 34 | { |
| 35 | m_queue[m_head] = data; |
| 36 | m_head++; |
| 37 | m_head %= 256; |
| 38 | } |
| 39 | |
| 40 | /************************************************************************** |
| 41 | * Check for mouse moves and buttons. Build delta x/y packets |
| 42 | **************************************************************************/ |
| 43 | void serial_mouse_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 44 | { |
| 45 | static int ox = 0, oy = 0; |
| 46 | int nx,ny; |
| 47 | int dx, dy, nb; |
| 48 | int mbc; |
| 49 | |
| 50 | /* Do not get deltas or send packets if queue is not empty (Prevents drifting) */ |
| 51 | if (m_head==m_tail) |
| 52 | { |
| 53 | nx = input_port_read(*this, "ser_mouse_x"); |
| 54 | |
| 55 | dx = nx - ox; |
| 56 | if (dx<=-0x800) dx = nx + 0x1000 - ox; /* Prevent jumping */ |
| 57 | if (dx>=0x800) dx = nx - 0x1000 - ox; |
| 58 | ox = nx; |
| 59 | |
| 60 | ny = input_port_read(*this, "ser_mouse_y"); |
| 61 | |
| 62 | dy = ny - oy; |
| 63 | if (dy<=-0x800) dy = ny + 0x1000 - oy; |
| 64 | if (dy>=0x800) dy = ny - 0x1000 - oy; |
| 65 | oy = ny; |
| 66 | |
| 67 | nb = input_port_read(*this, "ser_mouse_misc"); |
| 68 | if ((nb & 0x80) != 0) |
| 69 | { |
| 70 | m_protocol=TYPE_MOUSE_SYSTEMS; |
| 71 | } |
| 72 | else |
| 73 | { |
| 74 | m_protocol=TYPE_MICROSOFT_MOUSE; |
| 75 | } |
| 76 | mbc = nb^m_mb; |
| 77 | m_mb = nb; |
| 78 | |
| 79 | /* check if there is any delta or mouse buttons changed */ |
| 80 | if ( (dx!=0) || (dy!=0) || (mbc!=0) ) |
| 81 | { |
| 82 | switch (m_protocol) |
| 83 | { |
| 84 | |
| 85 | default: |
| 86 | case TYPE_MICROSOFT_MOUSE: |
| 87 | { |
| 88 | /* split deltas into packtes of -128..+127 max */ |
| 89 | do |
| 90 | { |
| 91 | UINT8 m0, m1, m2; |
| 92 | int ddx = (dx < -128) ? -128 : (dx > 127) ? 127 : dx; |
| 93 | int ddy = (dy < -128) ? -128 : (dy > 127) ? 127 : dy; |
| 94 | m0 = 0x40 | ((nb << 4) & 0x30) | ((ddx >> 6) & 0x03) | ((ddy >> 4) & 0x0c); |
| 95 | m1 = ddx & 0x3f; |
| 96 | m2 = ddy & 0x3f; |
| 97 | |
| 98 | /* KT - changed to use a function */ |
| 99 | queue_data(m0 | 0x40); |
| 100 | queue_data(m1 & 0x03f); |
| 101 | queue_data(m2 & 0x03f); |
| 102 | if ((mbc & 0x04) != 0) /* If button 3 changed send extra byte */ |
| 103 | queue_data( (nb & 0x04) << 3); |
| 104 | |
| 105 | dx -= ddx; |
| 106 | dy -= ddy; |
| 107 | } while( dx || dy ); |
| 108 | } |
| 109 | break; |
| 110 | |
| 111 | /* mouse systems mouse |
| 112 | from "PC Mouse information" by Tomi Engdahl */ |
| 113 | |
| 114 | /* |
| 115 | The data is sent in 5 byte packets in following format: |
| 116 | D7 D6 D5 D4 D3 D2 D1 D0 |
| 117 | |
| 118 | 1. 1 0 0 0 0 LB CB RB |
| 119 | 2. X7 X6 X5 X4 X3 X2 X1 X0 |
| 120 | 3. Y7 Y6 Y5 Y4 Y3 Y4 Y1 Y0 |
| 121 | 4. X7' X6' X5' X4' X3' X2' X1' X0' |
| 122 | 5. Y7' Y6' Y5' Y4' Y3' Y4' Y1' Y0' |
| 123 | |
| 124 | LB is left button state (0=pressed, 1=released) |
| 125 | CB is center button state (0=pressed, 1=released) |
| 126 | RB is right button state (0=pressed, 1=released) |
| 127 | X7-X0 movement in X direction since last packet in signed byte |
| 128 | format (-128..+127), positive direction right |
| 129 | Y7-Y0 movement in Y direction since last packet in signed byte |
| 130 | format (-128..+127), positive direction up |
| 131 | X7'-X0' movement in X direction since sending of X7-X0 packet in signed byte |
| 132 | format (-128..+127), positive direction right |
| 133 | Y7'-Y0' movement in Y direction since sending of Y7-Y0 in signed byte |
| 134 | format (-128..+127), positive direction up |
| 135 | |
| 136 | The last two bytes in the packet (bytes 4 and 5) contains information about movement data changes which have occurred after data butes 2 and 3 have been sent. */ |
| 137 | |
| 138 | case TYPE_MOUSE_SYSTEMS: |
| 139 | { |
| 140 | |
| 141 | dy =-dy; |
| 142 | |
| 143 | do |
| 144 | { |
| 145 | int ddx = (dx < -128) ? -128 : (dx > 127) ? 127 : dx; |
| 146 | int ddy = (dy < -128) ? -128 : (dy > 127) ? 127 : dy; |
| 147 | |
| 148 | /* KT - changed to use a function */ |
| 149 | queue_data(0x080 | ((((nb & 0x04) >> 1) + ((nb & 0x02) << 1) + (nb & 0x01)) ^ 0x07)); |
| 150 | queue_data(ddx); |
| 151 | queue_data(ddy); |
| 152 | /* for now... */ |
| 153 | queue_data(0); |
| 154 | queue_data(0); |
| 155 | dx -= ddx; |
| 156 | dy -= ddy; |
| 157 | } while( dx || dy ); |
| 158 | |
| 159 | } |
| 160 | break; |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | /* Send any data from this scan or any pending data from a previous scan */ |
| 166 | |
| 167 | if( m_tail != m_head ) |
| 168 | { |
| 169 | int data; |
| 170 | |
| 171 | data = m_queue[m_tail]; |
| 172 | m_rdata = data; |
| 173 | m_owner->out_rx8(data); |
| 174 | m_tail++; |
| 175 | m_tail &= 255; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | |
| 180 | |
| 181 | /************************************************************************** |
| 182 | * Check for mouse control line changes and (de-)install timer |
| 183 | **************************************************************************/ |
| 184 | |
| 185 | void serial_mouse_device::check_state() |
| 186 | { |
| 187 | if((m_dtr == m_old_dtr) && (m_rts == m_old_rts)) return; |
| 188 | |
| 189 | if (m_dtr && m_rts) |
| 190 | { |
| 191 | /* RTS toggled */ |
| 192 | if (!m_old_rts && m_rts) |
| 193 | { |
| 194 | /* reset mouse */ |
| 195 | m_head = m_tail = m_mb = 0; |
| 196 | |
| 197 | if ((input_port_read(*this, "ser_mouse_misc") & 0x80) == 0 ) |
| 198 | { |
| 199 | /* Identify as Microsoft 3 Button Mouse */ |
| 200 | m_queue[m_head] = 'M'; |
| 201 | m_head++; |
| 202 | m_head %= 256; |
| 203 | m_queue[m_head] = '3'; |
| 204 | m_head++; |
| 205 | m_head %= 256; |
| 206 | } |
| 207 | } |
| 208 | /* start a timer to scan the mouse input */ |
| 209 | m_timer->adjust(attotime::zero, 0, attotime::from_hz(240)); |
| 210 | } |
| 211 | else |
| 212 | { |
| 213 | m_timer->adjust(attotime::zero); |
| 214 | m_head = m_tail = 0; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | |
| 219 | |
| 220 | /************************************************************************** |
| 221 | * Mouse INPUT_PORT declarations |
| 222 | **************************************************************************/ |
| 223 | |
| 224 | static INPUT_PORTS_START( ser_mouse ) |
| 225 | PORT_START( "ser_mouse_misc" ) |
| 226 | PORT_CONFNAME( 0x80, 0x80, "Mouse Protocol" ) |
| 227 | PORT_CONFSETTING( 0x80, "Mouse Systems" ) |
| 228 | PORT_CONFSETTING( 0x00, "Microsoft" ) |
| 229 | PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Mouse Left Button") PORT_CODE(MOUSECODE_BUTTON1) |
| 230 | PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("Mouse Middle Button") PORT_CODE(MOUSECODE_BUTTON3) |
| 231 | PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("Mouse Right Button") PORT_CODE(MOUSECODE_BUTTON2) |
| 232 | |
| 233 | PORT_START( "ser_mouse_x" ) /* Mouse - X AXIS */ |
| 234 | PORT_BIT( 0xfff, 0x00, IPT_MOUSE_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1) |
| 235 | |
| 236 | PORT_START( "ser_mouse_y" ) /* Mouse - Y AXIS */ |
| 237 | PORT_BIT( 0xfff, 0x00, IPT_MOUSE_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1) |
| 238 | INPUT_PORTS_END |
| 239 | |
| 240 | ioport_constructor serial_mouse_device::device_input_ports() const |
| 241 | { |
| 242 | return INPUT_PORTS_NAME(ser_mouse); |
| 243 | } |