Previous 15994 Revisions Next

r14432 Sunday 12th February, 2012 at 07:37:18 UTC by Miodrag Milanović
Split pc mouse in two separate device by Carl (nw)
[src/mess/machine]isa_com.c ser_mouse.c ser_mouse.h

src/mess/machine/isa_com.c
r14431r14432
122122};
123123
124124static SLOT_INTERFACE_START(isa_com)
125   SLOT_INTERFACE("mouse", SERIAL_MOUSE)
125   SLOT_INTERFACE("microsoft_mouse", MSFT_SERIAL_MOUSE)
126   SLOT_INTERFACE("mouse_systems_mouse", MSYSTEM_SERIAL_MOUSE)
126127SLOT_INTERFACE_END
127128
128129static MACHINE_CONFIG_FRAGMENT( com_config )
r14431r14432
130131   MCFG_INS8250_ADD( "uart_1", genpc_com_interface[1] )
131132   MCFG_INS8250_ADD( "uart_2", genpc_com_interface[2] )
132133   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( "serport0", serport_config[0], isa_com, "microsoft_mouse", NULL )
134135   MCFG_RS232_PORT_ADD( "serport1", serport_config[1], isa_com, NULL, NULL )
135136   MCFG_RS232_PORT_ADD( "serport2", serport_config[3], isa_com, NULL, NULL )
136137   MCFG_RS232_PORT_ADD( "serport3", serport_config[4], isa_com, NULL, NULL )
r14431r14432
208209   MCFG_NS16450_ADD( "uart_1", genpc_com_interface[1] )
209210   MCFG_NS16450_ADD( "uart_2", genpc_com_interface[2] )
210211   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( "serport0", serport_config[0], isa_com, "microsoft_mouse", NULL )
212213   MCFG_RS232_PORT_ADD( "serport1", serport_config[1], isa_com, NULL, NULL )
213214   MCFG_RS232_PORT_ADD( "serport2", serport_config[3], isa_com, NULL, NULL )
214215   MCFG_RS232_PORT_ADD( "serport3", serport_config[4], isa_com, NULL, NULL )
src/mess/machine/ser_mouse.c
r14431r14432
99#include "machine/ser_mouse.h"
1010
1111
12const device_type SERIAL_MOUSE = &device_creator<serial_mouse_device>;
12const device_type MSFT_SERIAL_MOUSE = &device_creator<microsoft_mouse_device>;
13const device_type MSYSTEM_SERIAL_MOUSE = &device_creator<mouse_systems_mouse_device>;
1314
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),
15serial_mouse_device::serial_mouse_device(const machine_config &mconfig, device_type type, const char* name, const char *tag, device_t *owner, UINT32 clock)
16   : device_t(mconfig, type, name, tag, owner, clock),
1617      device_rs232_port_interface(mconfig, *this)
1718{
1819}
1920
21microsoft_mouse_device::microsoft_mouse_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
22   : serial_mouse_device(mconfig, MSFT_SERIAL_MOUSE, "Microsoft Serial Mouse", tag, owner, clock)
23{
24}
25
26mouse_systems_mouse_device::mouse_systems_mouse_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
27   : serial_mouse_device(mconfig, MSYSTEM_SERIAL_MOUSE, "Mouse Systems Serial Mouse", tag, owner, clock)
28{
29}
30
2031void serial_mouse_device::device_start()
2132{
2233   m_owner = dynamic_cast<rs232_port_device *>(owner());
34   m_timer = timer_alloc();
35   m_enabled = false;
2336}
2437
2538void serial_mouse_device::device_reset()
2639{
2740   m_head = m_tail = 0;
28   m_timer = timer_alloc();
29   m_old_dtr = m_old_rts = 0;
3041}
3142
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
4043/**************************************************************************
4144 *  Check for mouse moves and buttons. Build delta x/y packets
4245 **************************************************************************/
r14431r14432
6467      if (dy>=0x800) dy = ny - 0x1000 - oy;
6568      oy = ny;
6669
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      }
70      nb = input_port_read(*this, "ser_mouse_btn");
7671      mbc = nb^m_mb;
7772      m_mb = nb;
7873
7974      /* check if there is any delta or mouse buttons changed */
8075      if ( (dx!=0) || (dy!=0) || (mbc!=0) )
81      {
82         switch (m_protocol)
83         {
76         mouse_trans(dx, dy, nb, mbc);
77   }
8478
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;
79   if( m_tail != m_head )
80   {
81      UINT8 data = unqueue_data();
82      m_rdata = data;
83      m_owner->out_rx8(data);
84   }
85}
86   
87void microsoft_mouse_device::mouse_trans(int dx, int dy, int nb, int mbc)
88{
89   /* split deltas into packets of -128..+127 max */
90   do
91   {
92      UINT8 m0, m1, m2;
93      int ddx = (dx < -128) ? -128 : (dx > 127) ? 127 : dx;
94      int ddy = (dy < -128) ? -128 : (dy > 127) ? 127 : dy;
95      m0 = 0x40 | ((nb << 4) & 0x30) | ((ddx >> 6) & 0x03) | ((ddy >> 4) & 0x0c);
96      m1 = ddx & 0x3f;
97      m2 = ddy & 0x3f;
9798
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);
99      /* KT - changed to use a function */
100      queue_data(m0 | 0x40);
101      queue_data(m1 & 0x03f);
102      queue_data(m2 & 0x03f);
103      if ((mbc & 0x04) != 0)  /* If button 3 changed send extra byte */
104         queue_data( (nb & 0x04) << 3);
104105
105                  dx -= ddx;
106                  dy -= ddy;
107               } while( dx || dy );
108            }
109            break;
106      dx -= ddx;
107      dy -= ddy;
108   } while( dx || dy );
109}
110110
111            /* mouse systems mouse
112                from "PC Mouse information" by Tomi Engdahl */
111/* mouse systems mouse
112   from "PC Mouse information" by Tomi Engdahl */
113113
114            /*
115                The data is sent in 5 byte packets in following format:
116                        D7      D6      D5      D4      D3      D2      D1      D0
114/*
115   The data is sent in 5 byte packets in following format:
116   D7      D6      D5      D4      D3      D2      D1      D0
117117
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'
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'
123123
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
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
135135
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. */
136   The last two bytes in the packet (bytes 4 and 5) contains information
137   about movement data changes which have occurred after data bytes 2 and 3 have been sent. */
137138
138            case TYPE_MOUSE_SYSTEMS:
139            {
139void mouse_systems_mouse_device::mouse_trans(int dx, int dy, int nb, int mbc)
140{
141   dy =-dy;
140142
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 )
143   do
168144   {
169      int data;
145      int ddx = (dx < -128) ? -128 : (dx > 127) ? 127 : dx;
146      int ddy = (dy < -128) ? -128 : (dy > 127) ? 127 : dy;
170147
171      data = m_queue[m_tail];
172      m_rdata = data;
173      m_owner->out_rx8(data);
174      m_tail++;
175      m_tail &= 255;
176   }
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 );
177158}
178159
179
180
181160/**************************************************************************
182161 *  Check for mouse control line changes and (de-)install timer
183162 **************************************************************************/
184163
185void serial_mouse_device::check_state()
164void serial_mouse_device::set_mouse_enable(bool state)
186165{
187   if((m_dtr == m_old_dtr) && (m_rts == m_old_rts)) return;
166   if(state && !m_enabled)
167      m_timer->adjust(attotime::zero, 0, attotime::from_hz(240));
168   else if(!state && m_enabled)
169   {
170      m_timer->adjust(attotime::zero);
171      m_head = m_tail = 0;
172   }
173   m_enabled = state;
188174
175}
176
177void microsoft_mouse_device::check_state()
178{
189179   if (m_dtr && m_rts)
190180   {
191181      /* RTS toggled */
192182      if (!m_old_rts && m_rts)
193183      {
194184         /* 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         }
185         serial_mouse_device::device_reset();
186         /* Identify as Microsoft 3 Button Mouse */
187         queue_data('M');
188         queue_data('3');
207189      }
208190      /* start a timer to scan the mouse input */
209      m_timer->adjust(attotime::zero, 0, attotime::from_hz(240));
191      set_mouse_enable(true);
210192   }
211193   else
212   {
213      m_timer->adjust(attotime::zero);
214      m_head = m_tail = 0;
215   }
194      set_mouse_enable(false);
216195}
217196
218197
r14431r14432
222201 **************************************************************************/
223202
224203static 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" )
204   PORT_START( "ser_mouse_btn" )
229205   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Mouse Left Button") PORT_CODE(MOUSECODE_BUTTON1)
230206   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("Mouse Middle Button") PORT_CODE(MOUSECODE_BUTTON3)
231207   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("Mouse Right Button") PORT_CODE(MOUSECODE_BUTTON2)
src/mess/machine/ser_mouse.h
r14431r14432
1515      public device_rs232_port_interface
1616{
1717public:
18   serial_mouse_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
18   serial_mouse_device(const machine_config &mconfig, device_type type, const char* name, const char *tag, device_t *owner, UINT32 clock);
1919
2020   virtual ioport_constructor device_input_ports() const;
2121
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
2522protected:
2623   virtual void device_start();
2724   virtual void device_reset();
2825   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
26   virtual void mouse_trans(int dx, int dy, int nb, int mbc) = 0;
27   void set_mouse_enable(bool state);
28   void queue_data(UINT8 data) {m_queue[m_head] = data; ++m_head %= 256;}
29   UINT8 unqueue_data() {UINT8 ret = m_queue[m_tail]; ++m_tail %= 256; return ret;}
2930private:
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
4231   UINT8 m_queue[256];
4332   UINT8 m_head, m_tail, m_mb;
4433
4534   emu_timer *m_timer;
4635   rs232_port_device *m_owner;
36   bool m_enabled;
4737};
4838
49extern const device_type SERIAL_MOUSE;
39class microsoft_mouse_device : public serial_mouse_device
40{
41public:
42   microsoft_mouse_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
43   virtual void dtr_w(UINT8 state) { m_dtr = state; check_state(); }
44   virtual void rts_w(UINT8 state) { m_rts = state; check_state(); m_old_rts = state; }
45protected:
46   virtual void mouse_trans(int dx, int dy, int nb, int mbc);
47   virtual void device_reset() {m_old_rts = 0; serial_mouse_device::device_reset();}
48private:
49   void check_state();
50   UINT8 m_old_rts;
51};
52extern const device_type MSFT_SERIAL_MOUSE;
5053
54class mouse_systems_mouse_device : public serial_mouse_device
55{
56public:
57   mouse_systems_mouse_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
58   virtual void dtr_w(UINT8 state) { m_dtr = state; check_state(); }
59   virtual void rts_w(UINT8 state) { m_rts = state; check_state(); }
60protected:
61   virtual void mouse_trans(int dx, int dy, int nb, int mbc);
62private:
63   void check_state() { set_mouse_enable((m_dtr && m_rts)?true:false); }
64};
65
66extern const device_type MSYSTEM_SERIAL_MOUSE;
67
5168#endif /* SER_MOUSE_H_ */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team