Previous 15994 Revisions Next

r13551 Sunday 11th December, 2011 at 03:09:29 UTC by Tafoid
[COLECO][ADAM] Cleaned up inputs, fixing issue with Super Cobra (Bugzilla #2101) and made spinner irq behaviour more accurate. [hap, Kevtris, Tafoid]
[src/mess/drivers]adam.c coleco.c
[src/mess/includes]adam.h coleco.h
[src/mess/machine]coleco.c coleco.h

src/mess/machine/coleco.c
r13550r13551
88   UINT8 ctrl_sel = input_port_read_safe(machine, "CTRLSEL", 0);
99
1010   /* which controller shall we read? */
11   if ((ctrl_sel & 0x07) == 0x03)   // Driving controller
12      analog1 = input_port_read_safe(machine, "DRIV", 0);
11   if ((ctrl_sel & 0x07) == 0x02)   // Super Action Controller P1
12      analog1 = input_port_read_safe(machine, "SAC_SLIDE1", 0);
1313
14   else
15   {
16      if ((ctrl_sel & 0x07) == 0x02)   // Super Action Controller P1
17         analog1 = input_port_read_safe(machine, "SAC_SLIDE1", 0);
14   if ((ctrl_sel & 0x70) == 0x20)   // Super Action Controller P2
15      analog2 = input_port_read_safe(machine, "SAC_SLIDE2", 0);
1816
19      if ((ctrl_sel & 0x70) == 0x20)   // Super Action Controller P2
20         analog2 = input_port_read_safe(machine, "SAC_SLIDE2", 0);
21
22      /* In principle, even if not supported by any game, I guess we could have two Super
23        Action Controllers plugged into the Roller controller ports. Since I found no info
24        about the behavior of sliders in such a configuration, we overwrite SAC sliders with
25        the Roller trackball inputs and actually use the latter ones, when both are selected. */
26      if (ctrl_sel & 0x80)            // Roller controller
27      {
28         analog1 = input_port_read_safe(machine, "ROLLER_X", 0);
29         analog2 = input_port_read_safe(machine, "ROLLER_Y", 0);
30      }
17   /* In principle, even if not supported by any game, I guess we could have two Super
18       Action Controllers plugged into the Roller controller ports. Since I found no info
19       about the behavior of sliders in such a configuration, we overwrite SAC sliders with
20       the Roller trackball inputs and actually use the latter ones, when both are selected. */
21   if (ctrl_sel & 0x80)         // Roller controller
22   {
23      analog1 = input_port_read_safe(machine, "ROLLER_X", 0);
24      analog2 = input_port_read_safe(machine, "ROLLER_Y", 0);
3125   }
3226
3327    if (analog1 == 0)
3428      *joy_status0 = 0;
35    else if (analog1 & 0x08)
36      *joy_status0 = -1;
29    else if (analog1 & 8)
30      *joy_status0 = 0x8f;
3731    else
38      *joy_status0 = 1;
32      *joy_status0 = 0x81;
3933
4034    if (analog2 == 0)
4135      *joy_status1 = 0;
42    else if (analog2 & 0x08)
43      *joy_status1 = -1;
36    else if (analog2 & 8)
37      *joy_status1 = 0x8f;
4438    else
45      *joy_status1 = 1;
39      *joy_status1 = 0x81;
4640}
4741
4842
49UINT8 coleco_paddle1_read(running_machine &machine, int joy_mode, int joy_status)
43UINT8 coleco_paddle_read(running_machine &machine, int port, int joy_mode, int joy_status)
5044{
5145   UINT8 ctrl_sel = input_port_read_safe(machine, "CTRLSEL", 0);
46   UINT8 ctrl_extra = ctrl_sel & 0x80;
47   ctrl_sel = ctrl_sel >> (port*4) & 7;
5248
53   /* is there a controller connected to port1? */
54   if ((ctrl_sel & 0x07) != 0x01 )
49   /* Keypad and fire 1 (SAC Yellow Button) */
50   if (joy_mode == 0)
5551   {
56      /* Keypad and fire 1 (SAC Yellow Button) */
57      if (joy_mode == 0)
58      {
59         UINT8 data = 0x0f;   /* No key pressed by default */
60         UINT16 ipt1 = 0x00;
52      /* No key pressed by default */
53      UINT8 data = 0x0f;
54      UINT16 ipt = 0;
6155
62         if ((ctrl_sel & 0x07) == 0x00)         // colecovision controller
63            ipt1 = input_port_read(machine, "KEYPAD1");
64         else if ((ctrl_sel & 0x07) == 0x02)      // super action controller controller
65            ipt1 = input_port_read(machine, "SAC_KPD1");
56      if (ctrl_sel == 0)         // colecovision controller
57         ipt = input_port_read(machine, port ? "KEYPAD2" : "KEYPAD1");
58      else if (ctrl_sel == 2)      // super action controller
59         ipt = input_port_read(machine, port ? "SAC_KPD2" : "SAC_KPD1");
60      else                  // unconnected
61         ipt = 0xffff;
6662
67         /* Numeric pad buttons are not independent on a real ColecoVision, if you push more
68            than one, a real ColecoVision think that it is a third button, so we are going to emulate
69            the right behaviour */
70         /* Super Action Controller additional buttons are read in the same way */
71         if ((ctrl_sel & 0x07) != 0x03) /* If Driving Controller enabled -> no keypad 1*/
72         {
73            if (!(ipt1 & 0x0001)) data &= 0x0a; /* 0 */
74            if (!(ipt1 & 0x0002)) data &= 0x0d; /* 1 */
75            if (!(ipt1 & 0x0004)) data &= 0x07; /* 2 */
76            if (!(ipt1 & 0x0008)) data &= 0x0c; /* 3 */
77            if (!(ipt1 & 0x0010)) data &= 0x02; /* 4 */
78            if (!(ipt1 & 0x0020)) data &= 0x03; /* 5 */
79            if (!(ipt1 & 0x0040)) data &= 0x0e; /* 6 */
80            if (!(ipt1 & 0x0080)) data &= 0x05; /* 7 */
81            if (!(ipt1 & 0x0100)) data &= 0x01; /* 8 */
82            if (!(ipt1 & 0x0200)) data &= 0x0b; /* 9 */
83            if (!(ipt1 & 0x0400)) data &= 0x06; /* # */
84            if (!(ipt1 & 0x0800)) data &= 0x09; /* . */
85            if (!(ipt1 & 0x1000)) data &= 0x04; /* Blue Action Button */
86            if (!(ipt1 & 0x2000)) data &= 0x08; /* Purple Action Button */
87         }
63      /* Numeric pad buttons are not independent on a real ColecoVision, if you push more
64           than one, a real ColecoVision think that it is a third button, so we are going to emulate
65           the right behaviour */
66      /* Super Action Controller additional buttons are read in the same way */
67      if (!(ipt & 0x0001)) data &= 0x0a; /* 0 */
68      if (!(ipt & 0x0002)) data &= 0x0d; /* 1 */
69      if (!(ipt & 0x0004)) data &= 0x07; /* 2 */
70      if (!(ipt & 0x0008)) data &= 0x0c; /* 3 */
71      if (!(ipt & 0x0010)) data &= 0x02; /* 4 */
72      if (!(ipt & 0x0020)) data &= 0x03; /* 5 */
73      if (!(ipt & 0x0040)) data &= 0x0e; /* 6 */
74      if (!(ipt & 0x0080)) data &= 0x05; /* 7 */
75      if (!(ipt & 0x0100)) data &= 0x01; /* 8 */
76      if (!(ipt & 0x0200)) data &= 0x0b; /* 9 */
77      if (!(ipt & 0x0400)) data &= 0x06; /* # */
78      if (!(ipt & 0x0800)) data &= 0x09; /* . */
79      if (!(ipt & 0x1000)) data &= 0x04; /* Blue Action Button */
80      if (!(ipt & 0x2000)) data &= 0x08; /* Purple Action Button */
8881
89         return ((ipt1 & 0x4000) >> 8) | 0x30 | (data);
90      }
91      /* Joystick and fire 2 (SAC Red Button) */
92      else
93      {
94         UINT8 data = 0x0f;
95
96         if ((ctrl_sel & 0x07) == 0x00)         // colecovision controller
97            data = input_port_read(machine, "JOY1") & 0xcf;
98         else if ((ctrl_sel & 0x07) == 0x02)      // super action controller controller
99            data = input_port_read(machine, "SAC_JOY1") & 0xcf;
100
101          /* If any extra contoller enabled */
102         if ((ctrl_sel & 0x80) || ((ctrl_sel & 0x07) == 0x02) || ((ctrl_sel & 0x07) == 0x03))
103         {
104            if (joy_status == 0) data |= 0x30; /* Spinner Move Left*/
105            else if (joy_status == 1) data |= 0x20; /* Spinner Move Right */
106         }
107
108         return data | 0x80;
109      }
82      return (joy_status & 0x80) | ((ipt & 0x4000) >> 8) | 0x30 | data;
11083   }
111
112   return 0x0f;
113}
114
115
116UINT8 coleco_paddle2_read(running_machine &machine, int joy_mode, int joy_status)
117{
118   UINT8 ctrl_sel = input_port_read_safe(machine, "CTRLSEL", 0);
119
120   /* is there a controller connected to port2? */
121   if ((ctrl_sel & 0x70) != 0x10 )
84   /* Joystick and fire 2 (SAC Red Button) */
85   else
12286   {
123      /* Keypad and fire 1 */
124      if (joy_mode == 0)
125      {
126         UINT8 data = 0x0f;   /* No key pressed by default */
127         UINT16 ipt2 = 0x00;
87      UINT8 data = 0x7f;
12888
129         if ((ctrl_sel & 0x70) == 0x00)         // colecovision controller
130            ipt2 = input_port_read(machine, "KEYPAD2");
131         else if ((ctrl_sel & 0x70) == 0x20)      // super action controller controller
132            ipt2 = input_port_read(machine, "SAC_KPD2");
89      if (ctrl_sel == 0)         // colecovision controller
90         data = input_port_read(machine, port ? "JOY2" : "JOY1");
91      else if (ctrl_sel == 2)      // super action controller
92         data = input_port_read(machine, port ? "SAC_JOY2" : "SAC_JOY1");
13393
134         /* Numeric pad buttons are not independent on a real ColecoVision, if you push more
135            than one, a real ColecoVision think that it is a third button, so we are going to emulate
136            the right behaviour */
137         /* Super Action Controller additional buttons are read in the same way */
138         if (!(ipt2 & 0x0001)) data &= 0x0a; /* 0 */
139         if (!(ipt2 & 0x0002)) data &= 0x0d; /* 1 */
140         if (!(ipt2 & 0x0004)) data &= 0x07; /* 2 */
141         if (!(ipt2 & 0x0008)) data &= 0x0c; /* 3 */
142         if (!(ipt2 & 0x0010)) data &= 0x02; /* 4 */
143         if (!(ipt2 & 0x0020)) data &= 0x03; /* 5 */
144         if (!(ipt2 & 0x0040)) data &= 0x0e; /* 6 */
145         if (!(ipt2 & 0x0080)) data &= 0x05; /* 7 */
146         if (!(ipt2 & 0x0100)) data &= 0x01; /* 8 */
147         if (!(ipt2 & 0x0200)) data &= 0x0b; /* 9 */
148         if (!(ipt2 & 0x0400)) data &= 0x06; /* # */
149         if (!(ipt2 & 0x0800)) data &= 0x09; /* . */
150         if (!(ipt2 & 0x1000)) data &= 0x04; /* Blue Action Button */
151         if (!(ipt2 & 0x2000)) data &= 0x08; /* Purple Action Button */
152
153         return ((ipt2 & 0x4000) >> 8) | 0x30 | (data);
154      }
155      /* Joystick and fire 2*/
156      else
94      /* If any extra contoller enabled */
95      if (ctrl_extra || ctrl_sel == 2 || ctrl_sel == 3)
15796      {
158         UINT8 data = 0x0f;
159
160         if ((ctrl_sel & 0x70) == 0x00)         // colecovision controller
161            data = input_port_read(machine, "JOY2") & 0xcf;
162         else if ((ctrl_sel & 0x70) == 0x20)      // super action controller controller
163            data = input_port_read(machine, "SAC_JOY2") & 0xcf;
164
165         /* If Roller Controller or P2 Super Action Controller enabled */
166         if ((ctrl_sel & 0x80) || ((ctrl_sel & 0x70) == 0x20))
167         {
168            if (joy_status == 0) data |= 0x30;
169            else if (joy_status == 1) data |= 0x20;
170         }
171
172         return data | 0x80;
97         data &= 0xcf;
98         if (joy_status == 0) data |= 0x30; /* Spinner Move Left */
99         else if (joy_status == 0x81) data |= 0x20; /* Spinner Move Right */
173100      }
174   }
175101
176   return 0x0f;
102      return (joy_status & 0x80) | (data & 0x7f);
103   }
177104}
178105
179106
r13550r13551
296223INPUT_PORTS_END
297224
298225
299static INPUT_PORTS_START( driving )
300   PORT_START("DRIV")   // Driving Controller
301   PORT_BIT( 0x0f, 0x00, IPT_DIAL ) PORT_SENSITIVITY(20) PORT_KEYDELTA(10) PORT_CODE_DEC(KEYCODE_L) PORT_CODE_INC(KEYCODE_J) PORT_RESET PORT_CONDITION("CTRLSEL", 0x07, PORTCOND_EQUALS, 0x03)
302
303//  PORT_START("IN8")   //
304//  PORT_BIT( 0x0f, 0x00, IPT_TRACKBALL_Y ) PORT_SENSITIVITY(20) PORT_KEYDELTA(10) PORT_CODE_DEC(KEYCODE_I) PORT_CODE_INC(KEYCODE_K) PORT_PLAYER(2)
305INPUT_PORTS_END
306
307
308226static INPUT_PORTS_START( roller )
309227   PORT_START("ROLLER_X")   // Roller Controller X Axis
310   PORT_BIT( 0x0f, 0x00, IPT_TRACKBALL_X ) PORT_SENSITIVITY(20) PORT_KEYDELTA(10) PORT_CODE_DEC(KEYCODE_L) PORT_CODE_INC(KEYCODE_J) PORT_RESET PORT_CONDITION("CTRLSEL", 0x80, PORTCOND_EQUALS, 0x80)
228   PORT_BIT( 0x0f, 0x00, IPT_TRACKBALL_X ) PORT_SENSITIVITY(20) PORT_KEYDELTA(10) PORT_CODE_DEC(KEYCODE_L) PORT_CODE_INC(KEYCODE_J) PORT_REVERSE PORT_RESET PORT_CONDITION("CTRLSEL", 0x80, PORTCOND_EQUALS, 0x80)
311229
312230   PORT_START("ROLLER_Y")   // Roller Controller Y Axis
313231   PORT_BIT( 0x0f, 0x00, IPT_TRACKBALL_Y ) PORT_SENSITIVITY(20) PORT_KEYDELTA(10) PORT_CODE_DEC(KEYCODE_I) PORT_CODE_INC(KEYCODE_K) PORT_RESET PORT_CONDITION("CTRLSEL", 0x80, PORTCOND_EQUALS, 0x80)
r13550r13551
319237   PORT_CONFNAME( 0x07, 0x00, "Port 1 Controller" )
320238   PORT_CONFSETTING(  0x01, DEF_STR( None ) )
321239   PORT_CONFSETTING(  0x00, "ColecoVision Controller" )
322   PORT_CONFSETTING(  0x02, "Super Action Controller" )
323   PORT_CONFSETTING(  0x03, "Driving Controller" )
240   PORT_CONFSETTING(  0x02, "Super Action/Driving Controller" )
324241   PORT_CONFNAME( 0x70, 0x00, "Port 2 Controller" )
325242   PORT_CONFSETTING(  0x10, DEF_STR( None ) )
326243   PORT_CONFSETTING(  0x00, "ColecoVision Controller" )
r13550r13551
333250   PORT_INCLUDE( ctrl2 )
334251   PORT_INCLUDE( sac1 )
335252   PORT_INCLUDE( sac2 )
336   PORT_INCLUDE( driving )
337253   PORT_INCLUDE( roller )
338254INPUT_PORTS_END
src/mess/machine/coleco.h
r13550r13551
44#define __COLECO_CONTROLLERS__
55
66void coleco_scan_paddles(running_machine &machine, int *joy_status0, int *joy_status1);
7UINT8 coleco_paddle1_read(running_machine &machine, int joy_mode, int joy_status);
8UINT8 coleco_paddle2_read(running_machine &machine, int joy_mode, int joy_status);
7UINT8 coleco_paddle_read(running_machine &machine, int port, int joy_mode, int joy_status);
98
109INPUT_PORTS_EXTERN( coleco );
1110
src/mess/includes/adam.h
r13550r13551
115115   UINT16 m_key_y;
116116
117117   // paddle state
118   emu_timer *m_joy_irq_timer;
119   emu_timer *m_joy_d7_timer;
118120   int m_joy_mode;
119121   int m_joy_status0;
120122   int m_joy_status1;
src/mess/includes/coleco.h
r13550r13551
3232   DECLARE_WRITE8_MEMBER( paddle_off_w );
3333   DECLARE_WRITE8_MEMBER( paddle_on_w );
3434
35   emu_timer *m_joy_irq_timer;
36   emu_timer *m_joy_d7_timer;
3537   int m_joy_mode;
3638   int m_joy_status[2];
3739   int m_last_state;
src/mess/drivers/adam.c
r13550r13551
11551155//**************************************************************************
11561156
11571157//-------------------------------------------------
1158//  TIMER_CALLBACK( paddle_d7reset_callback )
1159//-------------------------------------------------
1160
1161static TIMER_CALLBACK( paddle_d7reset_callback )
1162{
1163   adam_state *state = machine.driver_data<adam_state>();
1164
1165   state->m_joy_status0 &= 0x7f;
1166   state->m_joy_status1 &= 0x7f;
1167}
1168
1169//-------------------------------------------------
1170//  TIMER_CALLBACK( paddle_irqreset_callback )
1171//-------------------------------------------------
1172
1173static TIMER_CALLBACK( paddle_irqreset_callback )
1174{
1175   adam_state *state = machine.driver_data<adam_state>();
1176
1177   state->m_maincpu->set_input_line(INPUT_LINE_IRQ0, CLEAR_LINE);
1178}
1179
1180
1181//-------------------------------------------------
11581182//  TIMER_DEVICE_CALLBACK( paddle_tick )
11591183//-------------------------------------------------
11601184
r13550r13551
11641188
11651189   coleco_scan_paddles(timer.machine(), &state->m_joy_status0, &state->m_joy_status1);
11661190
1191   // on change, controller port d7 is set for a short period and an irq is fired on d7 rising edge
11671192    if (state->m_joy_status0 || state->m_joy_status1)
11681193   {
1169      device_set_input_line(state->m_maincpu, INPUT_LINE_IRQ0, HOLD_LINE);
1194      state->m_joy_d7_timer->adjust(attotime::from_usec(500)); // TODO: measure duration
1195      // irq on rising edge, PULSE_LINE is not supported in this case, so clear it manually
1196
1197      state->m_maincpu->set_input_line(INPUT_LINE_IRQ0, ASSERT_LINE);
1198      state->m_joy_irq_timer->adjust(attotime::from_usec(11)); // TODO: measure duration
11701199   }
11711200}
11721201
r13550r13551
11971226
11981227READ8_MEMBER( adam_state::input1_r )
11991228{
1200   return coleco_paddle1_read(machine(), m_joy_mode, m_joy_status0);
1229   return coleco_paddle_read(machine(), 0, m_joy_mode, m_joy_status0);
12011230}
12021231
12031232
r13550r13551
12071236
12081237READ8_MEMBER( adam_state::input2_r )
12091238{
1210   return coleco_paddle1_read(machine(), m_joy_mode, m_joy_status1);
1239   return coleco_paddle_read(machine(), 1, m_joy_mode, m_joy_status1);
12111240}
12121241
12131242
r13550r13551
16171646
16181647void adam_state::machine_start()
16191648{
1649   m_joy_d7_timer = machine().scheduler().timer_alloc(FUNC(paddle_d7reset_callback));
1650   m_joy_irq_timer = machine().scheduler().timer_alloc(FUNC(paddle_irqreset_callback));
1651
16201652   // register for state saving
16211653   save_item(NAME(m_mioc));
16221654   save_item(NAME(m_game));
r13550r13551
16631695
16641696   m_adamnet = 0;
16651697
1698   m_joy_d7_timer->reset();
1699   m_joy_status0 &= 0x7f;
1700   m_joy_status1 &= 0x7f;
1701
1702   m_joy_irq_timer->reset();
1703   m_maincpu->set_input_line(INPUT_LINE_IRQ0, CLEAR_LINE);
1704
16661705   bankswitch();
16671706}
16681707
src/mess/drivers/coleco.c
r13550r13551
2727            E0-FF (R) = Read Controller data, A1=0 -> read controller 1, A1=1 -> read controller 2
2828
2929    - Modified paddle handler, now it is handled as on a real ColecoVision
30    - Added support for a Driving Controller (Expansion Module #2), enabled via category
3130    - Added support for a Roller Controller (Trackball), enabled via category
3231    - Added support for two Super Action Controller, enabled via category
3332
r13550r13551
6867
6968READ8_MEMBER( coleco_state::paddle_1_r )
7069{
71   return coleco_paddle1_read(machine(), m_joy_mode, m_joy_status[0]);
70   return coleco_paddle_read(machine(), 0, m_joy_mode, m_joy_status[0]);
7271}
7372
7473READ8_MEMBER( coleco_state::paddle_2_r )
7574{
76   return coleco_paddle2_read(machine(), m_joy_mode, m_joy_status[1]);
75   return coleco_paddle_read(machine(), 1, m_joy_mode, m_joy_status[1]);
7776}
7877
7978WRITE8_MEMBER( coleco_state::paddle_off_w )
r13550r13551
191190   drvstate->m_last_state = state;
192191}
193192
193static TIMER_CALLBACK( paddle_d7reset_callback )
194{
195   coleco_state *state = machine.driver_data<coleco_state>();
196
197   state->m_joy_status[0] &= 0x7f;
198   state->m_joy_status[1] &= 0x7f;
199}
200
201static TIMER_CALLBACK( paddle_irqreset_callback )
202{
203   coleco_state *state = machine.driver_data<coleco_state>();
204
205   state->m_maincpu->set_input_line(INPUT_LINE_IRQ0, CLEAR_LINE);
206}
207
194208static TIMER_DEVICE_CALLBACK( paddle_callback )
195209{
196210   coleco_state *state = timer.machine().driver_data<coleco_state>();
197211
198212   coleco_scan_paddles(timer.machine(), &state->m_joy_status[0], &state->m_joy_status[1]);
199213
214   // on change, controller port d7 is set for a short period and an irq is fired on d7 rising edge
200215    if (state->m_joy_status[0] || state->m_joy_status[1])
201      state->m_maincpu->set_input_line(INPUT_LINE_IRQ0, HOLD_LINE);
216    {
217       state->m_joy_d7_timer->adjust(attotime::from_usec(500)); // TODO: measure duration
218
219      // irq on rising edge, PULSE_LINE is not supported in this case, so clear it manually
220      state->m_maincpu->set_input_line(INPUT_LINE_IRQ0, ASSERT_LINE);
221      state->m_joy_irq_timer->adjust(attotime::from_usec(11)); // TODO: measure duration
222   }
202223}
203224
204225/* Machine Initialization */
r13550r13551
212233
213234void coleco_state::machine_start()
214235{
236   m_joy_d7_timer = machine().scheduler().timer_alloc(FUNC(paddle_d7reset_callback));
237   m_joy_irq_timer = machine().scheduler().timer_alloc(FUNC(paddle_irqreset_callback));
215238}
216239
217240void coleco_state::machine_reset()
218241{
219242   m_last_state = 0;
220243
244   m_joy_d7_timer->reset();
245   m_joy_status[0] &= 0x7f;
246   m_joy_status[1] &= 0x7f;
247
248   m_joy_irq_timer->reset();
249   m_maincpu->set_input_line(INPUT_LINE_IRQ0, CLEAR_LINE);
221250   m_maincpu->set_input_line_vector(INPUT_LINE_IRQ0, 0xff);
222251
223252   memset(&machine().region(Z80_TAG)->base()[0x6000], 0xff, 0x400);   // initialize RAM

Previous 15994 Revisions Next


© 1998-2018 The MESS Team