Previous 15994 Revisions Next

r14422 Saturday 11th February, 2012 at 13:25:35 UTC by Miodrag Milanović
Made generic serial port and RS232 port as slot devices, implemented pc mouse as example device [Carl]
[src/mess]mess.mak
[src/mess/drivers]at.c genpc.c ibmpc.c
[src/mess/includes]at.h
[src/mess/machine]isa_com.c isa_com.h ser_mouse.c* ser_mouse.h* serial.c* serial.h*

src/mess/machine/serial.c
r0r14422
1#include "emu.h"
2#include "serial.h"
3
4const device_type SERIAL_PORT = &device_creator<serial_port_device>;
5
6device_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
15device_serial_port_interface::~device_serial_port_interface()
16{
17}
18
19serial_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
26serial_port_device::~serial_port_device()
27{
28}
29
30void 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
45void 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
51const device_type RS232_PORT = &device_creator<rs232_port_device>;
52
53device_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
64device_rs232_port_interface::~device_rs232_port_interface()
65{
66}
67
68rs232_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
73rs232_port_device::~rs232_port_device()
74{
75}
76
77void 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
98void 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
r0r14422
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
16struct serial_port_interface
17{
18   devcb_write8      m_out_rx8_cb;
19   devcb_write_line   m_out_rx_cb;
20};
21
22class device_serial_port_interface : public device_slot_card_interface
23{
24public:
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; }
32protected:
33   UINT8 m_rdata;
34   UINT8 m_rbit;
35   UINT8 m_tdata;
36   UINT8 m_tbit;
37};
38
39class serial_port_device : public device_t,
40                     public serial_port_interface,
41                     public device_slot_interface
42{
43public:
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); }
55protected:
56   virtual void device_start();
57   virtual void device_config_complete();
58
59private:
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
66extern const device_type SERIAL_PORT;
67
68struct 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
78class device_rs232_port_interface : public device_serial_port_interface
79{
80public:
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; }
91protected:
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
100class rs232_port_device : public serial_port_device,
101                     public rs232_port_interface
102{
103public:
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
120protected:
121   virtual void device_start();
122   virtual void device_config_complete();
123
124private:
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
133extern const device_type RS232_PORT;
134
135#endif
src/mess/machine/isa_com.c
r14421r14422
77#include "emu.h"
88#include "isa_com.h"
99#include "machine/ins8250.h"
10#include "machine/pc_mouse.h"
10#include "machine/ser_mouse.h"
1111
1212/* called when a interrupt is set/cleared from com hardware */
1313static WRITE_LINE_DEVICE_HANDLER( pc_com_interrupt_1 )
r14421r14422
2222   com->m_isa->irq3_w(state);
2323}
2424
25/* called when com registers read/written - used to update peripherals that
26are connected */
27static void pc_com_refresh_connected_common(device_t *device, int n, int data)
25static void pc_com_refresh_connected_common(device_t *uart, int n, int data)
2826{
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));
3233}
3334
3435static INS8250_HANDSHAKE_OUT( pc_com_handshake_out_0 ) { pc_com_refresh_connected_common( device, 0, data ); }
r14421r14422
3637static INS8250_HANDSHAKE_OUT( pc_com_handshake_out_2 ) { pc_com_refresh_connected_common( device, 2, data ); }
3738static INS8250_HANDSHAKE_OUT( pc_com_handshake_out_3 ) { pc_com_refresh_connected_common( device, 3, data ); }
3839
40static 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
46static INS8250_TRANSMIT( pc_com_tx_0 ) { pc_com_tx(device, data, 0); }
47static INS8250_TRANSMIT( pc_com_tx_1 ) { pc_com_tx(device, data, 1); }
48static INS8250_TRANSMIT( pc_com_tx_2 ) { pc_com_tx(device, data, 2); }
49static INS8250_TRANSMIT( pc_com_tx_3 ) { pc_com_tx(device, data, 3); }
50
51WRITE8_DEVICE_HANDLER( pc_com_rx_0 ) { ins8250_receive(downcast<isa8_com_device *>(device->owner())->get_uart(0), data); }
52WRITE8_DEVICE_HANDLER( pc_com_rx_1 ) { ins8250_receive(downcast<isa8_com_device *>(device->owner())->get_uart(1), data); }
53WRITE8_DEVICE_HANDLER( pc_com_rx_2 ) { ins8250_receive(downcast<isa8_com_device *>(device->owner())->get_uart(2), data); }
54WRITE8_DEVICE_HANDLER( pc_com_rx_3 ) { ins8250_receive(downcast<isa8_com_device *>(device->owner())->get_uart(3), data); }
55
3956static const ins8250_interface genpc_com_interface[4]=
4057{
4158   {
4259      1843200,
4360      DEVCB_LINE(pc_com_interrupt_1),
44      NULL,
61      pc_com_tx_0,
4562      pc_com_handshake_out_0,
4663      NULL
4764   },
4865   {
4966      1843200,
5067      DEVCB_LINE(pc_com_interrupt_2),
51      NULL,
68      pc_com_tx_1,
5269      pc_com_handshake_out_1,
5370      NULL
5471   },
5572   {
5673      1843200,
5774      DEVCB_LINE(pc_com_interrupt_1),
58      NULL,
75      pc_com_tx_2,
5976      pc_com_handshake_out_2,
6077      NULL
6178   },
6279   {
6380      1843200,
6481      DEVCB_LINE(pc_com_interrupt_2),
65      NULL,
82      pc_com_tx_3,
6683      pc_com_handshake_out_3,
6784      NULL
6885   }
6986};
7087
88static 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
124static SLOT_INTERFACE_START(isa_com)
125   SLOT_INTERFACE("mouse", SERIAL_MOUSE)
126SLOT_INTERFACE_END
127
71128static MACHINE_CONFIG_FRAGMENT( com_config )
72129   MCFG_INS8250_ADD( "uart_0", genpc_com_interface[0] )
73130   MCFG_INS8250_ADD( "uart_1", genpc_com_interface[1] )
74131   MCFG_INS8250_ADD( "uart_2", genpc_com_interface[2] )
75132   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 )
76137MACHINE_CONFIG_END
77138
78static 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 )
87INPUT_PORTS_END
88
89139//**************************************************************************
90140//  GLOBAL VARIABLES
91141//**************************************************************************
r14421r14422
102152   return MACHINE_CONFIG_NAME( com_config );
103153}
104154
105//-------------------------------------------------
106//  input_ports - device-specific input ports
107//-------------------------------------------------
108
109ioport_constructor isa8_com_device::device_input_ports() const
110{
111   return INPUT_PORTS_NAME( com );
112}
113
114155//**************************************************************************
115156//  LIVE DEVICE
116157//**************************************************************************
r14421r14422
139180void isa8_com_device::device_start()
140181{
141182   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");
146196}
147197
148198//-------------------------------------------------
r14421r14422
151201
152202void isa8_com_device::device_reset()
153203{
154   pc_mouse_initialise(machine());
155   pc_mouse_set_serial_port(subdevice("uart_0"));
156204}
157205
158206static MACHINE_CONFIG_FRAGMENT( com_at_config )
r14421r14422
160208   MCFG_NS16450_ADD( "uart_1", genpc_com_interface[1] )
161209   MCFG_NS16450_ADD( "uart_2", genpc_com_interface[2] )
162210   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 )
163215MACHINE_CONFIG_END
164216
165217//**************************************************************************
src/mess/machine/isa_com.h
r14421r14422
55
66#include "emu.h"
77#include "machine/isa.h"
8#include "machine/serial.h"
89
910//**************************************************************************
1011//  TYPE DEFINITIONS
r14421r14422
2324
2425      // optional information overrides
2526      virtual machine_config_constructor device_mconfig_additions() const;
26      virtual ioport_constructor device_input_ports() const;
27
28      rs232_port_device *get_port(int port) { return m_serport[port]; }
29      device_t *get_uart(int dev) { return m_uart[dev]; }
2730protected:
2831        // device-level overrides
2932        virtual void device_start();
r14421r14422
3134
3235private:
3336        // internal state
37   device_t *m_uart[4];
38   rs232_port_device *m_serport[4];
3439};
3540
3641
src/mess/machine/ser_mouse.c
r0r14422
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
12const device_type SERIAL_MOUSE = &device_creator<serial_mouse_device>;
13
14serial_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
20void serial_mouse_device::device_start()
21{
22   m_owner = dynamic_cast<rs232_port_device *>(owner());
23}
24
25void 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 */
33void 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 **************************************************************************/
43void 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
185void 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
224static 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)
238INPUT_PORTS_END
239
240ioport_constructor serial_mouse_device::device_input_ports() const
241{
242   return INPUT_PORTS_NAME(ser_mouse);
243}
src/mess/machine/ser_mouse.h
r0r14422
1/*****************************************************************************
2 *
3 * machine/ser_mouse.h
4 *
5 ****************************************************************************/
6
7#ifndef SER_MOUSE_H_
8#define SER_MOUSE_H_
9
10#include "emu.h"
11#include "machine/serial.h"
12
13class serial_mouse_device :
14      public device_t,
15      public device_rs232_port_interface
16{
17public:
18   serial_mouse_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
19
20   virtual ioport_constructor device_input_ports() const;
21
22   virtual void dtr_w(UINT8 state) { m_dtr = state; check_state(); m_old_dtr = state; }
23   virtual void rts_w(UINT8 state) { m_rts = state; check_state(); m_old_rts = state; }
24
25protected:
26   virtual void device_start();
27   virtual void device_reset();
28   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
29private:
30   typedef enum
31   {
32      TYPE_MICROSOFT_MOUSE,
33      TYPE_MOUSE_SYSTEMS
34   } PC_MOUSE_PROTOCOL;
35
36   void queue_data(int data);
37   void check_state();
38
39   PC_MOUSE_PROTOCOL m_protocol;
40   UINT8 m_old_dtr, m_old_rts;
41
42   UINT8 m_queue[256];
43   UINT8 m_head, m_tail, m_mb;
44
45   emu_timer *m_timer;
46   rs232_port_device *m_owner;
47};
48
49extern const device_type SERIAL_MOUSE;
50
51#endif /* SER_MOUSE_H_ */
src/mess/includes/at.h
r14421r14422
6161
6262#include "machine/isa_ide.h"
6363
64#include "machine/pc_mouse.h"
6564#include "machine/pc_lpt.h"
6665
6766
src/mess/mess.mak
r14421r14422
510510   $(MESS_MACHINE)/mpc105.o   \
511511   $(MESS_MACHINE)/mos6530.o   \
512512   $(MESS_MACHINE)/s100.o      \
513   $(MESS_MACHINE)/serial.o   \
513514   $(MESS_MACHINE)/upd765.o   \
514515   $(MESS_MACHINE)/ncr5380.o   \
515516   $(MESS_MACHINE)/ncr5390.o   \
r14421r14422
13321333   $(MESS_MACHINE)/pc_joy.o   \
13331334   $(MESS_MACHINE)/kb_keytro.o   \
13341335   $(MESS_MACHINE)/isa_adlib.o   \
1336   $(MESS_MACHINE)/ser_mouse.o   \
13351337   $(MESS_MACHINE)/isa_com.o   \
13361338   $(MESS_MACHINE)/isa_fdc.o   \
13371339   $(MESS_MACHINE)/isa_finalchs.o   \
src/mess/drivers/genpc.c
r14421r14422
3838
3939#include "machine/kb_keytro.h"
4040
41#include "machine/pc_mouse.h"
42
4341class genpc_state : public driver_device
4442{
4543public:
r14421r14422
8078
8179static INPUT_PORTS_START( pcgen )
8280   PORT_INCLUDE( kb_keytronic_pc )
83   PORT_INCLUDE( pc_mouse_microsoft )
8481INPUT_PORTS_END
8582
8683static INPUT_PORTS_START( pccga )
8784   PORT_INCLUDE( kb_keytronic_pc )
8885   PORT_INCLUDE( pcvideo_cga )
89   PORT_INCLUDE( pc_mouse_microsoft )
9086INPUT_PORTS_END
9187
9288static const unsigned i86_address_mask = 0x000fffff;
src/mess/drivers/at.c
r14421r14422
247247
248248   PORT_INCLUDE( kb_keytronic_at )      /* IN4 - IN11 */
249249   PORT_INCLUDE( pcvideo_cga )
250   PORT_INCLUDE( pc_mouse_microsoft )
251250INPUT_PORTS_END
252251
253252static INPUT_PORTS_START( atvga )
r14421r14422
289288   PORT_DIPSETTING(   0x01, DEF_STR( Yes ) )
290289
291290   PORT_INCLUDE( kb_keytronic_at )
292   PORT_INCLUDE( pc_mouse_microsoft )
293291INPUT_PORTS_END
294292
295293static const unsigned i286_address_mask = 0x00ffffff;
src/mess/drivers/ibmpc.c
r14421r14422
301301
302302static INPUT_PORTS_START( ibm5150 )
303303   PORT_INCLUDE( kb_keytronic_pc )      /* IN4 - IN11 */
304//  PORT_INCLUDE( pc_mouse_microsoft )  /* IN12 - IN14 */
305304//  PORT_INCLUDE( pc_joystick )         /* IN15 - IN19 */
306305INPUT_PORTS_END
307306

Previous 15994 Revisions Next


© 1998-2018 The MESS Team