Previous 199869 Revisions Next

r29212 Thursday 3rd April, 2014 at 08:08:38 UTC by Miodrag Milanović
smpc moved to state, need to be device-fied in future (nw)
[src/emu/machine]smpc.c smpc.h
[src/emu/video]stvvdp1.c
[src/mame/drivers]stv.c
[src/mame/includes]stv.h

trunk/src/emu/video/stvvdp1.c
r29211r29212
429429}
430430
431431#ifdef UNUSED_FUNCTION
432WRITE32_HANDLER ( saturn_vdp1_framebuffer1_w )
432WRITE32_MEMBER ( saturn_state::saturn_vdp1_framebuffer1_w )
433433{
434434   //popmessage ("STV VDP1 Framebuffer 1 WRITE offset %08x data %08x",offset, data);
435435}
436436
437READ32_HANDLER ( saturn_vdp1_framebuffer1_r )
437READ32_MEMBER ( saturn_state::saturn_vdp1_framebuffer1_r )
438438{
439439   //popmessage ("STV VDP1 Framebuffer 1 READ offset %08x",offset);
440440   return 0xffff;
trunk/src/emu/machine/smpc.c
r29211r29212
164164 *
165165 *******************************************/
166166
167static TIMER_CALLBACK( stv_bankswitch_state )
167TIMER_CALLBACK_MEMBER( saturn_state::stv_bankswitch_state )
168168{
169   saturn_state *state = machine.driver_data<saturn_state>();
170169   static const char *const banknames[] = { "game0", "game1", "game2", "game3" };
171170   UINT8* game_region;
172171
173   if(state->m_prev_bankswitch != param)
172   if(m_prev_bankswitch != param)
174173   {
175      game_region = machine.root_device().memregion(banknames[param])->base();
174      game_region = memregion(banknames[param])->base();
176175
177176      if (game_region)
178         memcpy(machine.root_device().memregion("abus")->base(), game_region, 0x3000000);
177         memcpy(memregion("abus")->base(), game_region, 0x3000000);
179178      else
180         memset(machine.root_device().memregion("abus")->base(), 0x00, 0x3000000);
179         memset(memregion("abus")->base(), 0x00, 0x3000000);
181180
182      state->m_prev_bankswitch = param;
181      m_prev_bankswitch = param;
183182   }
184183}
185184
186static void stv_select_game(running_machine &machine, int gameno)
185void saturn_state::stv_select_game(int gameno)
187186{
188   machine.scheduler().timer_set(attotime::zero, FUNC(stv_bankswitch_state), gameno);
187   machine().scheduler().timer_set(attotime::zero, timer_expired_delegate(FUNC(saturn_state::stv_bankswitch_state),this), gameno);
189188}
190189
191190/********************************************
r29211r29212
194193 *
195194 *******************************************/
196195
197static void smpc_master_on(running_machine &machine)
196void saturn_state::smpc_master_on()
198197{
199   saturn_state *state = machine.driver_data<saturn_state>();
200
201   state->m_maincpu->set_input_line(INPUT_LINE_RESET, CLEAR_LINE);
198   m_maincpu->set_input_line(INPUT_LINE_RESET, CLEAR_LINE);
202199}
203200
204static TIMER_CALLBACK( smpc_slave_enable )
201TIMER_CALLBACK_MEMBER( saturn_state::smpc_slave_enable )
205202{
206   saturn_state *state = machine.driver_data<saturn_state>();
207
208   state->m_slave->set_input_line(INPUT_LINE_RESET, param ? ASSERT_LINE : CLEAR_LINE);
209   state->m_smpc.OREG[31] = param + 0x02; //read-back for last command issued
210   state->m_smpc.SF = 0x00; //clear hand-shake flag
211   state->m_smpc.slave_on = param;
212//  printf("%d %d\n",machine.first_screen()->hpos(),machine.first_screen()->vpos());
203   m_slave->set_input_line(INPUT_LINE_RESET, param ? ASSERT_LINE : CLEAR_LINE);
204   m_smpc.OREG[31] = param + 0x02; //read-back for last command issued
205   m_smpc.SF = 0x00; //clear hand-shake flag
206   m_smpc.slave_on = param;
207//  printf("%d %d\n",machine().first_screen()->hpos(),machine().first_screen()->vpos());
213208}
214209
215static TIMER_CALLBACK( smpc_sound_enable )
210TIMER_CALLBACK_MEMBER( saturn_state::smpc_sound_enable )
216211{
217   saturn_state *state = machine.driver_data<saturn_state>();
218
219   state->m_audiocpu->set_input_line(INPUT_LINE_RESET, param ? ASSERT_LINE : CLEAR_LINE);
220   state->m_en_68k = param ^ 1;
221   state->m_smpc.OREG[31] = param + 0x06; //read-back for last command issued
222   state->m_smpc.SF = 0x00; //clear hand-shake flag
212   m_audiocpu->set_input_line(INPUT_LINE_RESET, param ? ASSERT_LINE : CLEAR_LINE);
213   m_en_68k = param ^ 1;
214   m_smpc.OREG[31] = param + 0x06; //read-back for last command issued
215   m_smpc.SF = 0x00; //clear hand-shake flag
223216}
224217
225static TIMER_CALLBACK( smpc_cd_enable )
218TIMER_CALLBACK_MEMBER( saturn_state::smpc_cd_enable )
226219{
227   saturn_state *state = machine.driver_data<saturn_state>();
228
229   state->m_smpc.OREG[31] = param + 0x08; //read-back for last command issued
230   state->m_smpc.SF = 0x08; //clear hand-shake flag (TODO: diagnostic wants this to have bit 3 high)
220   m_smpc.OREG[31] = param + 0x08; //read-back for last command issued
221   m_smpc.SF = 0x08; //clear hand-shake flag (TODO: diagnostic wants this to have bit 3 high)
231222}
232223
233static void smpc_system_reset(running_machine &machine)
224void saturn_state::smpc_system_reset()
234225{
235   saturn_state *state = machine.driver_data<saturn_state>();
236
237226   /*Only backup ram and SMPC ram are retained after that this command is issued.*/
238   memset(state->m_scu_regs ,0x00,0x000100);
239   memset(state->m_scsp_regs,0x00,0x001000);
240   memset(state->m_sound_ram,0x00,0x080000);
241   memset(state->m_workram_h,0x00,0x100000);
242   memset(state->m_workram_l,0x00,0x100000);
243   memset(state->m_vdp2_regs,0x00,0x040000);
244   memset(state->m_vdp2_vram,0x00,0x100000);
245   memset(state->m_vdp2_cram,0x00,0x080000);
246   memset(state->m_vdp1_vram,0x00,0x100000);
227   memset(m_scu_regs ,0x00,0x000100);
228   memset(m_scsp_regs,0x00,0x001000);
229   memset(m_sound_ram,0x00,0x080000);
230   memset(m_workram_h,0x00,0x100000);
231   memset(m_workram_l,0x00,0x100000);
232   memset(m_vdp2_regs,0x00,0x040000);
233   memset(m_vdp2_vram,0x00,0x100000);
234   memset(m_vdp2_cram,0x00,0x080000);
235   memset(m_vdp1_vram,0x00,0x100000);
247236   //A-Bus
248237
249   state->m_maincpu->set_input_line(INPUT_LINE_RESET, PULSE_LINE);
238   m_maincpu->set_input_line(INPUT_LINE_RESET, PULSE_LINE);
250239}
251240
252static TIMER_CALLBACK( smpc_change_clock )
241TIMER_CALLBACK_MEMBER( saturn_state::smpc_change_clock )
253242{
254   saturn_state *state = machine.driver_data<saturn_state>();
255243   UINT32 xtal;
256244
257   if(LOG_SMPC) printf ("Clock change execute at (%d %d)\n",machine.first_screen()->hpos(),machine.first_screen()->vpos());
245   if(LOG_SMPC) printf ("Clock change execute at (%d %d)\n",machine().first_screen()->hpos(),machine().first_screen()->vpos());
258246
259247   xtal = param ? MASTER_CLOCK_320 : MASTER_CLOCK_352;
260248
261   machine.device("maincpu")->set_unscaled_clock(xtal/2);
262   machine.device("slave")->set_unscaled_clock(xtal/2);
249   machine().device("maincpu")->set_unscaled_clock(xtal/2);
250   machine().device("slave")->set_unscaled_clock(xtal/2);
263251
264   state->m_vdp2.dotsel = param ^ 1;
265   state->stv_vdp2_dynamic_res_change();
252   m_vdp2.dotsel = param ^ 1;
253   stv_vdp2_dynamic_res_change();
266254
267   state->m_maincpu->set_input_line(INPUT_LINE_HALT, CLEAR_LINE);
268   if(!state->m_NMI_reset)
269      state->m_maincpu->set_input_line(INPUT_LINE_NMI, PULSE_LINE);
270   state->m_slave->set_input_line(INPUT_LINE_HALT, CLEAR_LINE);
271   state->m_slave->set_input_line(INPUT_LINE_RESET, ASSERT_LINE);
272   state->m_audiocpu->set_input_line(INPUT_LINE_HALT, CLEAR_LINE);
255   m_maincpu->set_input_line(INPUT_LINE_HALT, CLEAR_LINE);
256   if(!m_NMI_reset)
257      m_maincpu->set_input_line(INPUT_LINE_NMI, PULSE_LINE);
258   m_slave->set_input_line(INPUT_LINE_HALT, CLEAR_LINE);
259   m_slave->set_input_line(INPUT_LINE_RESET, ASSERT_LINE);
260   m_audiocpu->set_input_line(INPUT_LINE_HALT, CLEAR_LINE);
273261
274262   /* put issued command in OREG31 */
275   state->m_smpc.OREG[31] = 0x0e + param;
263   m_smpc.OREG[31] = 0x0e + param;
276264   /* clear hand-shake flag */
277   state->m_smpc.SF = 0x00;
265   m_smpc.SF = 0x00;
278266
279267   /* TODO: VDP1 / VDP2 / SCU / SCSP default power ON values? */
280268}
281269
282static TIMER_CALLBACK( stv_intback_peripheral )
270TIMER_CALLBACK_MEMBER( saturn_state::stv_intback_peripheral )
283271{
284   saturn_state *state = machine.driver_data<saturn_state>();
285
286   if (state->m_smpc.intback_stage == 2)
272   if (m_smpc.intback_stage == 2)
287273   {
288      state->m_smpc.SR = (0x80 | state->m_smpc.pmode);    // pad 2, no more data, echo back pad mode set by intback
289      state->m_smpc.intback_stage = 0;
274      m_smpc.SR = (0x80 | m_smpc.pmode);    // pad 2, no more data, echo back pad mode set by intback
275      m_smpc.intback_stage = 0;
290276   }
291277   else
292278   {
293      state->m_smpc.SR = (0xc0 | state->m_smpc.pmode);    // pad 1, more data, echo back pad mode set by intback
294      state->m_smpc.intback_stage ++;
279      m_smpc.SR = (0xc0 | m_smpc.pmode);    // pad 1, more data, echo back pad mode set by intback
280      m_smpc.intback_stage ++;
295281   }
296282
297   if(!(state->m_scu.ism & IRQ_SMPC))
298      state->m_maincpu->set_input_line_and_vector(8, HOLD_LINE, 0x47);
283   if(!(m_scu.ism & IRQ_SMPC))
284      m_maincpu->set_input_line_and_vector(8, HOLD_LINE, 0x47);
299285   else
300      state->m_scu.ist |= (IRQ_SMPC);
286      m_scu.ist |= (IRQ_SMPC);
301287
302   state->m_smpc.OREG[31] = 0x10; /* callback for last command issued */
303   state->m_smpc.SF = 0x00;    /* clear hand-shake flag */
288   m_smpc.OREG[31] = 0x10; /* callback for last command issued */
289   m_smpc.SF = 0x00;    /* clear hand-shake flag */
304290}
305291
306292
307static TIMER_CALLBACK( stv_smpc_intback )
293TIMER_CALLBACK_MEMBER( saturn_state::stv_smpc_intback )
308294{
309   saturn_state *state = machine.driver_data<saturn_state>();
310295   int i;
311296
312//  printf("%02x %02x %02x\n",state->m_smpc.intback_buf[0],state->m_smpc.intback_buf[1],state->m_smpc.intback_buf[2]);
297//  printf("%02x %02x %02x\n",m_smpc.intback_buf[0],m_smpc.intback_buf[1],m_smpc.intback_buf[2]);
313298
314   if(state->m_smpc.intback_buf[0] != 0)
299   if(m_smpc.intback_buf[0] != 0)
315300   {
316      state->m_smpc.OREG[0] = (0x80) | ((state->m_NMI_reset & 1) << 6);
301      m_smpc.OREG[0] = (0x80) | ((m_NMI_reset & 1) << 6);
317302
318303      for(i=0;i<7;i++)
319         state->m_smpc.OREG[1+i] = state->m_smpc.rtc_data[i];
304         m_smpc.OREG[1+i] = m_smpc.rtc_data[i];
320305
321      state->m_smpc.OREG[8]=0x00;  // CTG0 / CTG1?
306      m_smpc.OREG[8]=0x00;  // CTG0 / CTG1?
322307
323      state->m_smpc.OREG[9]=0x00;  // TODO: system region on Saturn
308      m_smpc.OREG[9]=0x00;  // TODO: system region on Saturn
324309
325      state->m_smpc.OREG[10]= 0 << 7 |
326                        state->m_vdp2.dotsel << 6 |
310      m_smpc.OREG[10]= 0 << 7 |
311                        m_vdp2.dotsel << 6 |
327312                        1 << 5 |
328313                        1 << 4 |
329314                        0 << 3 | //MSHNMI
330315                        1 << 2 |
331316                        0 << 1 | //SYSRES
332317                        0 << 0;  //SOUNDRES
333      state->m_smpc.OREG[11]= 0 << 6; //CDRES
318      m_smpc.OREG[11]= 0 << 6; //CDRES
334319
335320      for(i=0;i<4;i++)
336         state->m_smpc.OREG[12+i]=state->m_smpc.SMEM[i];
321         m_smpc.OREG[12+i]=m_smpc.SMEM[i];
337322
338323      for(i=0;i<15;i++)
339         state->m_smpc.OREG[16+i]=0xff; // undefined
324         m_smpc.OREG[16+i]=0xff; // undefined
340325
341      state->m_smpc.intback_stage = (state->m_smpc.intback_buf[1] & 8) >> 3; // first peripheral
342      state->m_smpc.SR = 0x40 | state->m_smpc.intback_stage << 5;
343      state->m_smpc.pmode = state->m_smpc.intback_buf[0]>>4;
326      m_smpc.intback_stage = (m_smpc.intback_buf[1] & 8) >> 3; // first peripheral
327      m_smpc.SR = 0x40 | m_smpc.intback_stage << 5;
328      m_smpc.pmode = m_smpc.intback_buf[0]>>4;
344329
345330      //  /*This is for RTC,cartridge code and similar stuff...*/
346331      //if(LOG_SMPC) printf ("Interrupt: System Manager (SMPC) at scanline %04x, Vector 0x47 Level 0x08\n",scanline);
347      if(!(state->m_scu.ism & IRQ_SMPC))
348         state->m_maincpu->set_input_line_and_vector(8, HOLD_LINE, 0x47);
332      if(!(m_scu.ism & IRQ_SMPC))
333         m_maincpu->set_input_line_and_vector(8, HOLD_LINE, 0x47);
349334      else
350         state->m_scu.ist |= (IRQ_SMPC);
335         m_scu.ist |= (IRQ_SMPC);
351336
352337      /* put issued command in OREG31 */
353      state->m_smpc.OREG[31] = 0x10; // TODO: doc says 0?
338      m_smpc.OREG[31] = 0x10; // TODO: doc says 0?
354339      /* clear hand-shake flag */
355      state->m_smpc.SF = 0x00;
340      m_smpc.SF = 0x00;
356341   }
357   else if(state->m_smpc.intback_buf[1] & 8)
342   else if(m_smpc.intback_buf[1] & 8)
358343   {
359      state->m_smpc.intback_stage = (state->m_smpc.intback_buf[1] & 8) >> 3; // first peripheral
360      state->m_smpc.SR = 0x40;
361      state->m_smpc.OREG[31] = 0x10;
362      machine.scheduler().timer_set(attotime::from_usec(0), FUNC(stv_intback_peripheral),0);
344      m_smpc.intback_stage = (m_smpc.intback_buf[1] & 8) >> 3; // first peripheral
345      m_smpc.SR = 0x40;
346      m_smpc.OREG[31] = 0x10;
347      machine().scheduler().timer_set(attotime::from_usec(0), timer_expired_delegate(FUNC(saturn_state::stv_intback_peripheral),this),0);
363348   }
364349   else
365350   {
366351      /* Shienryu calls this, it would be plainly illegal on Saturn, I'll just return the command and clear the hs flag for now. */
367      state->m_smpc.OREG[31] = 0x10;
368      state->m_smpc.SF = 0x00;
352      m_smpc.OREG[31] = 0x10;
353      m_smpc.SF = 0x00;
369354   }
370355}
371356
r29211r29212
383368        0x34 keyboard
384369*/
385370
386static void smpc_digital_pad(running_machine &machine, UINT8 pad_num, UINT8 offset)
371void saturn_state::smpc_digital_pad(UINT8 pad_num, UINT8 offset)
387372{
388   saturn_state *state = machine.driver_data<saturn_state>();
389373   static const char *const padnames[] = { "JOY1", "JOY2" };
390374   UINT16 pad_data;
391375
392   pad_data = machine.root_device().ioport(padnames[pad_num])->read();
393   state->m_smpc.OREG[0+pad_num*offset] = 0xf1;
394   state->m_smpc.OREG[1+pad_num*offset] = 0x02;
395   state->m_smpc.OREG[2+pad_num*offset] = pad_data>>8;
396   state->m_smpc.OREG[3+pad_num*offset] = pad_data & 0xff;
376   pad_data = ioport(padnames[pad_num])->read();
377   m_smpc.OREG[0+pad_num*offset] = 0xf1;
378   m_smpc.OREG[1+pad_num*offset] = 0x02;
379   m_smpc.OREG[2+pad_num*offset] = pad_data>>8;
380   m_smpc.OREG[3+pad_num*offset] = pad_data & 0xff;
397381}
398382
399static void smpc_analog_pad(running_machine &machine, UINT8 pad_num, UINT8 offset, UINT8 id)
383void saturn_state::smpc_analog_pad( UINT8 pad_num, UINT8 offset, UINT8 id)
400384{
401   saturn_state *state = machine.driver_data<saturn_state>();
402385   static const char *const padnames[] = { "AN_JOY1", "AN_JOY2" };
403386   static const char *const annames[2][3] = { { "AN_X1", "AN_Y1", "AN_Z1" },
404387                                    { "AN_X2", "AN_Y2", "AN_Z2" }};
405388   UINT16 pad_data;
406389
407   pad_data = machine.root_device().ioport(padnames[pad_num])->read();
408   state->m_smpc.OREG[0+pad_num*offset] = 0xf1;
409   state->m_smpc.OREG[1+pad_num*offset] = id;
410   state->m_smpc.OREG[2+pad_num*offset] = pad_data>>8;
411   state->m_smpc.OREG[3+pad_num*offset] = pad_data & 0xff;
412   state->m_smpc.OREG[4+pad_num*offset] = machine.root_device().ioport(annames[pad_num][0])->read();
390   pad_data = ioport(padnames[pad_num])->read();
391   m_smpc.OREG[0+pad_num*offset] = 0xf1;
392   m_smpc.OREG[1+pad_num*offset] = id;
393   m_smpc.OREG[2+pad_num*offset] = pad_data>>8;
394   m_smpc.OREG[3+pad_num*offset] = pad_data & 0xff;
395   m_smpc.OREG[4+pad_num*offset] = ioport(annames[pad_num][0])->read();
413396   if(id == 0x15)
414397   {
415      state->m_smpc.OREG[5+pad_num*offset] = machine.root_device().ioport(annames[pad_num][1])->read();
416      state->m_smpc.OREG[6+pad_num*offset] = machine.root_device().ioport(annames[pad_num][2])->read();
398      m_smpc.OREG[5+pad_num*offset] = ioport(annames[pad_num][1])->read();
399      m_smpc.OREG[6+pad_num*offset] = ioport(annames[pad_num][2])->read();
417400   }
418401}
419402
420static void smpc_keyboard(running_machine &machine, UINT8 pad_num, UINT8 offset)
403void saturn_state::smpc_keyboard(UINT8 pad_num, UINT8 offset)
421404{
422   saturn_state *state = machine.driver_data<saturn_state>();
423405   UINT16 game_key;
424406
425407   game_key = 0xffff;
426408
427   game_key ^= ((state->ioport("KEYS_1")->read() & 0x80) << 8); // right
428   game_key ^= ((state->ioport("KEYS_1")->read() & 0x40) << 8); // left
429   game_key ^= ((state->ioport("KEYS_1")->read() & 0x20) << 8); // down
430   game_key ^= ((state->ioport("KEYS_1")->read() & 0x10) << 8); // up
431   game_key ^= ((state->ioport("KEYF")->read() & 0x80) << 4); // ESC -> START
432   game_key ^= ((state->ioport("KEY3")->read() & 0x04) << 8); // Z / A trigger
433   game_key ^= ((state->ioport("KEY4")->read() & 0x02) << 8); // C / C trigger
434   game_key ^= ((state->ioport("KEY6")->read() & 0x04) << 6); // X / B trigger
435   game_key ^= ((state->ioport("KEY2")->read() & 0x20) << 2); // Q / R trigger
436   game_key ^= ((state->ioport("KEY3")->read() & 0x10) << 2); // A / X trigger
437   game_key ^= ((state->ioport("KEY3")->read() & 0x08) << 2); // S / Y trigger
438   game_key ^= ((state->ioport("KEY4")->read() & 0x08) << 1); // D / Z trigger
439   game_key ^= ((state->ioport("KEY4")->read() & 0x10) >> 1); // E / L trigger
409   game_key ^= ((ioport("KEYS_1")->read() & 0x80) << 8); // right
410   game_key ^= ((ioport("KEYS_1")->read() & 0x40) << 8); // left
411   game_key ^= ((ioport("KEYS_1")->read() & 0x20) << 8); // down
412   game_key ^= ((ioport("KEYS_1")->read() & 0x10) << 8); // up
413   game_key ^= ((ioport("KEYF")->read() & 0x80) << 4); // ESC -> START
414   game_key ^= ((ioport("KEY3")->read() & 0x04) << 8); // Z / A trigger
415   game_key ^= ((ioport("KEY4")->read() & 0x02) << 8); // C / C trigger
416   game_key ^= ((ioport("KEY6")->read() & 0x04) << 6); // X / B trigger
417   game_key ^= ((ioport("KEY2")->read() & 0x20) << 2); // Q / R trigger
418   game_key ^= ((ioport("KEY3")->read() & 0x10) << 2); // A / X trigger
419   game_key ^= ((ioport("KEY3")->read() & 0x08) << 2); // S / Y trigger
420   game_key ^= ((ioport("KEY4")->read() & 0x08) << 1); // D / Z trigger
421   game_key ^= ((ioport("KEY4")->read() & 0x10) >> 1); // E / L trigger
440422
441   state->m_smpc.OREG[0+pad_num*offset] = 0xf1;
442   state->m_smpc.OREG[1+pad_num*offset] = 0x34;
443   state->m_smpc.OREG[2+pad_num*offset] = game_key>>8; // game buttons, TODO
444   state->m_smpc.OREG[3+pad_num*offset] = game_key & 0xff;
423   m_smpc.OREG[0+pad_num*offset] = 0xf1;
424   m_smpc.OREG[1+pad_num*offset] = 0x34;
425   m_smpc.OREG[2+pad_num*offset] = game_key>>8; // game buttons, TODO
426   m_smpc.OREG[3+pad_num*offset] = game_key & 0xff;
445427   /*
446428       x--- ---- 0
447429       -x-- ---- caps lock
r29211r29212
452434       ---- --x- 1
453435       ---- ---x Break key
454436   */
455   state->m_smpc.OREG[4+pad_num*offset] = state->m_keyb.status | 6;
456   state->m_smpc.OREG[5+pad_num*offset] = state->m_keyb.data;
437   m_smpc.OREG[4+pad_num*offset] = m_keyb.status | 6;
438   m_smpc.OREG[5+pad_num*offset] = m_keyb.data;
457439}
458440
459static void smpc_mouse(running_machine &machine, UINT8 pad_num, UINT8 offset, UINT8 id)
441void saturn_state::smpc_mouse(UINT8 pad_num, UINT8 offset, UINT8 id)
460442{
461   saturn_state *state = machine.driver_data<saturn_state>();
462443   static const char *const mousenames[2][3] = { { "MOUSEB1", "MOUSEX1", "MOUSEY1" },
463444                                       { "MOUSEB2", "MOUSEX2", "MOUSEY2" }};
464445   UINT8 mouse_ctrl;
465446   INT16 mouse_x, mouse_y;
466447
467   mouse_ctrl = machine.root_device().ioport(mousenames[pad_num][0])->read();
468   mouse_x = machine.root_device().ioport(mousenames[pad_num][1])->read();
469   mouse_y = machine.root_device().ioport(mousenames[pad_num][2])->read();
448   mouse_ctrl = ioport(mousenames[pad_num][0])->read();
449   mouse_x = ioport(mousenames[pad_num][1])->read();
450   mouse_y = ioport(mousenames[pad_num][2])->read();
470451
471452   if(mouse_x < 0)
472453      mouse_ctrl |= 0x10;
r29211r29212
480461   if((mouse_y & 0xff00) != 0xff00 && (mouse_y & 0xff00) != 0x0000)
481462      mouse_ctrl |= 0x80;
482463
483   state->m_smpc.OREG[0+pad_num*offset] = 0xf1;
484   state->m_smpc.OREG[1+pad_num*offset] = id; // 0x23 / 0xe3
485   state->m_smpc.OREG[2+pad_num*offset] = mouse_ctrl;
486   state->m_smpc.OREG[3+pad_num*offset] = mouse_x & 0xff;
487   state->m_smpc.OREG[4+pad_num*offset] = mouse_y & 0xff;
464   m_smpc.OREG[0+pad_num*offset] = 0xf1;
465   m_smpc.OREG[1+pad_num*offset] = id; // 0x23 / 0xe3
466   m_smpc.OREG[2+pad_num*offset] = mouse_ctrl;
467   m_smpc.OREG[3+pad_num*offset] = mouse_x & 0xff;
468   m_smpc.OREG[4+pad_num*offset] = mouse_y & 0xff;
488469}
489470
490471/* TODO: is there ANY game on which the MD pad works? */
491static void smpc_md_pad(running_machine &machine, UINT8 pad_num, UINT8 offset, UINT8 id)
472void saturn_state::smpc_md_pad(UINT8 pad_num, UINT8 offset, UINT8 id)
492473{
493   saturn_state *state = machine.driver_data<saturn_state>();
494474   static const char *const padnames[] = { "MD_JOY1", "MD_JOY2" };
495475   UINT16 pad_data;
496476
497   pad_data = machine.root_device().ioport(padnames[pad_num])->read();
498   state->m_smpc.OREG[0+pad_num*offset] = 0xf1;
499   state->m_smpc.OREG[1+pad_num*offset] = id;
500   state->m_smpc.OREG[2+pad_num*offset] = pad_data>>8;
477   pad_data = ioport(padnames[pad_num])->read();
478   m_smpc.OREG[0+pad_num*offset] = 0xf1;
479   m_smpc.OREG[1+pad_num*offset] = id;
480   m_smpc.OREG[2+pad_num*offset] = pad_data>>8;
501481   if(id == 0xe2) // MD 6 Button PAD
502      state->m_smpc.OREG[3+pad_num*offset] = pad_data & 0xff;
482      m_smpc.OREG[3+pad_num*offset] = pad_data & 0xff;
503483}
504484
505static void smpc_unconnected(running_machine &machine, UINT8 pad_num, UINT8 offset)
485void saturn_state::smpc_unconnected(UINT8 pad_num, UINT8 offset)
506486{
507   saturn_state *state = machine.driver_data<saturn_state>();
508
509   state->m_smpc.OREG[0+pad_num*offset] = 0xf0;
487   m_smpc.OREG[0+pad_num*offset] = 0xf0;
510488}
511489
512static TIMER_CALLBACK( intback_peripheral )
490TIMER_CALLBACK_MEMBER( saturn_state::intback_peripheral )
513491{
514   saturn_state *state = machine.driver_data<saturn_state>();
515492   int pad_num;
516493   static const UINT8 peri_id[10] = { 0x02, 0x13, 0x15, 0x23, 0x23, 0x34, 0xe1, 0xe2, 0xe3, 0xff };
517494   UINT8 read_id[2];
r29211r29212
519496
520497//  if (LOG_SMPC) logerror("SMPC: providing PAD data for intback, pad %d\n", intback_stage-2);
521498
522   read_id[0] = (machine.root_device().ioport("INPUT_TYPE")->read()) & 0x0f;
523   read_id[1] = (machine.root_device().ioport("INPUT_TYPE")->read()) >> 4;
499   read_id[0] = (ioport("INPUT_TYPE")->read()) & 0x0f;
500   read_id[1] = (ioport("INPUT_TYPE")->read()) >> 4;
524501
525502   /* doesn't work? */
526   //pad_num = state->m_smpc.intback_stage - 1;
503   //pad_num = m_smpc.intback_stage - 1;
527504
528   if(LOG_PAD_CMD) printf("%d %d %d\n",state->m_smpc.intback_stage - 1,machine.first_screen()->vpos(),(int)machine.first_screen()->frame_number());
505   if(LOG_PAD_CMD) printf("%d %d %d\n",m_smpc.intback_stage - 1,machine().first_screen()->vpos(),(int)machine().first_screen()->frame_number());
529506
530507   offset = 0;
531508
r29211r29212
533510   {
534511      switch(read_id[pad_num])
535512      {
536         case 0: smpc_digital_pad(machine,pad_num,offset); break;
537         case 1: smpc_analog_pad(machine,pad_num,offset,peri_id[read_id[pad_num]]); break; /* Steering Wheel */
538         case 2: smpc_analog_pad(machine,pad_num,offset,peri_id[read_id[pad_num]]); break; /* Analog Pad */
539         case 4: smpc_mouse(machine,pad_num,offset,peri_id[read_id[pad_num]]); break; /* Pointing Device */
540         case 5: smpc_keyboard(machine,pad_num,offset); break;
541         case 6: smpc_md_pad(machine,pad_num,offset,peri_id[read_id[pad_num]]); break; /* MD 3B PAD */
542         case 7: smpc_md_pad(machine,pad_num,offset,peri_id[read_id[pad_num]]); break; /* MD 6B PAD */
543         case 8: smpc_mouse(machine,pad_num,offset,peri_id[read_id[pad_num]]); break; /* Saturn Mouse */
544         case 9: smpc_unconnected(machine,pad_num,offset); break;
513         case 0: smpc_digital_pad(pad_num,offset); break;
514         case 1: smpc_analog_pad(pad_num,offset,peri_id[read_id[pad_num]]); break; /* Steering Wheel */
515         case 2: smpc_analog_pad(pad_num,offset,peri_id[read_id[pad_num]]); break; /* Analog Pad */
516         case 4: smpc_mouse(pad_num,offset,peri_id[read_id[pad_num]]); break; /* Pointing Device */
517         case 5: smpc_keyboard(pad_num,offset); break;
518         case 6: smpc_md_pad(pad_num,offset,peri_id[read_id[pad_num]]); break; /* MD 3B PAD */
519         case 7: smpc_md_pad(pad_num,offset,peri_id[read_id[pad_num]]); break; /* MD 6B PAD */
520         case 8: smpc_mouse(pad_num,offset,peri_id[read_id[pad_num]]); break; /* Saturn Mouse */
521         case 9: smpc_unconnected(pad_num,offset); break;
545522      }
546523
547524      offset += (peri_id[read_id[pad_num]] & 0xf) + 2; /* offset for port 2 */
548525   }
549526
550   if (state->m_smpc.intback_stage == 2)
527   if (m_smpc.intback_stage == 2)
551528   {
552      state->m_smpc.SR = (0x80 | state->m_smpc.pmode);    // pad 2, no more data, echo back pad mode set by intback
553      state->m_smpc.intback_stage = 0;
529      m_smpc.SR = (0x80 | m_smpc.pmode);    // pad 2, no more data, echo back pad mode set by intback
530      m_smpc.intback_stage = 0;
554531   }
555532   else
556533   {
557      state->m_smpc.SR = (0xc0 | state->m_smpc.pmode);    // pad 1, more data, echo back pad mode set by intback
558      state->m_smpc.intback_stage ++;
534      m_smpc.SR = (0xc0 | m_smpc.pmode);    // pad 1, more data, echo back pad mode set by intback
535      m_smpc.intback_stage ++;
559536   }
560537
561   if(!(state->m_scu.ism & IRQ_SMPC))
562      state->m_maincpu->set_input_line_and_vector(8, HOLD_LINE, 0x47);
538   if(!(m_scu.ism & IRQ_SMPC))
539      m_maincpu->set_input_line_and_vector(8, HOLD_LINE, 0x47);
563540   else
564      state->m_scu.ist |= (IRQ_SMPC);
541      m_scu.ist |= (IRQ_SMPC);
565542
566   state->m_smpc.OREG[31] = 0x10; /* callback for last command issued */
567   state->m_smpc.SF = 0x00;    /* clear hand-shake flag */
543   m_smpc.OREG[31] = 0x10; /* callback for last command issued */
544   m_smpc.SF = 0x00;    /* clear hand-shake flag */
568545}
569546
570static TIMER_CALLBACK( saturn_smpc_intback )
547TIMER_CALLBACK_MEMBER( saturn_state::saturn_smpc_intback )
571548{
572   saturn_state *state = machine.driver_data<saturn_state>();
573
574   if(state->m_smpc.intback_buf[0] != 0)
549   if(m_smpc.intback_buf[0] != 0)
575550   {
576551      {
577552         int i;
578553
579         state->m_smpc.OREG[0] = (0x80) | ((state->m_NMI_reset & 1) << 6); // bit 7: SETTIME (RTC isn't setted up properly)
554         m_smpc.OREG[0] = (0x80) | ((m_NMI_reset & 1) << 6); // bit 7: SETTIME (RTC isn't setted up properly)
580555
581556         for(i=0;i<7;i++)
582            state->m_smpc.OREG[1+i] = state->m_smpc.rtc_data[i];
557            m_smpc.OREG[1+i] = m_smpc.rtc_data[i];
583558
584         state->m_smpc.OREG[8]=0x00;  //Cartridge code?
559         m_smpc.OREG[8]=0x00;  //Cartridge code?
585560
586         state->m_smpc.OREG[9] = state->m_saturn_region;
561         m_smpc.OREG[9] = m_saturn_region;
587562
588         state->m_smpc.OREG[10]= 0 << 7 |
589                              state->m_vdp2.dotsel << 6 |
563         m_smpc.OREG[10]= 0 << 7 |
564                              m_vdp2.dotsel << 6 |
590565                              1 << 5 |
591566                              1 << 4 |
592567                              0 << 3 | //MSHNMI
593568                              1 << 2 |
594569                              0 << 1 | //SYSRES
595570                              0 << 0;  //SOUNDRES
596         state->m_smpc.OREG[11]= 0 << 6; //CDRES
571         m_smpc.OREG[11]= 0 << 6; //CDRES
597572
598573         for(i=0;i<4;i++)
599            state->m_smpc.OREG[12+i]=state->m_smpc.SMEM[i];
574            m_smpc.OREG[12+i]=m_smpc.SMEM[i];
600575
601576         for(i=0;i<15;i++)
602            state->m_smpc.OREG[16+i]=0xff; // undefined
577            m_smpc.OREG[16+i]=0xff; // undefined
603578      }
604579
605      state->m_smpc.intback_stage = (state->m_smpc.intback_buf[1] & 8) >> 3; // first peripheral
606      state->m_smpc.SR = 0x40 | state->m_smpc.intback_stage << 5;
607      state->m_smpc.pmode = state->m_smpc.intback_buf[0]>>4;
580      m_smpc.intback_stage = (m_smpc.intback_buf[1] & 8) >> 3; // first peripheral
581      m_smpc.SR = 0x40 | m_smpc.intback_stage << 5;
582      m_smpc.pmode = m_smpc.intback_buf[0]>>4;
608583
609      if(!(state->m_scu.ism & IRQ_SMPC))
610         state->m_maincpu->set_input_line_and_vector(8, HOLD_LINE, 0x47);
584      if(!(m_scu.ism & IRQ_SMPC))
585         m_maincpu->set_input_line_and_vector(8, HOLD_LINE, 0x47);
611586      else
612         state->m_scu.ist |= (IRQ_SMPC);
587         m_scu.ist |= (IRQ_SMPC);
613588
614589      /* put issued command in OREG31 */
615      state->m_smpc.OREG[31] = 0x10;
590      m_smpc.OREG[31] = 0x10;
616591      /* clear hand-shake flag */
617      state->m_smpc.SF = 0x00;
592      m_smpc.SF = 0x00;
618593   }
619   else if(state->m_smpc.intback_buf[1] & 8)
594   else if(m_smpc.intback_buf[1] & 8)
620595   {
621      state->m_smpc.intback_stage = (state->m_smpc.intback_buf[1] & 8) >> 3; // first peripheral
622      state->m_smpc.SR = 0x40;
623      state->m_smpc.OREG[31] = 0x10;
624      machine.scheduler().timer_set(attotime::from_usec(0), FUNC(intback_peripheral),0);
596      m_smpc.intback_stage = (m_smpc.intback_buf[1] & 8) >> 3; // first peripheral
597      m_smpc.SR = 0x40;
598      m_smpc.OREG[31] = 0x10;
599      machine().scheduler().timer_set(attotime::from_usec(0), timer_expired_delegate(FUNC(saturn_state::intback_peripheral),this),0);
625600   }
626601   else
627602   {
628      printf("SMPC intback bogus behaviour called %02x %02x\n",state->m_smpc.IREG[0],state->m_smpc.IREG[1]);
603      printf("SMPC intback bogus behaviour called %02x %02x\n",m_smpc.IREG[0],m_smpc.IREG[1]);
629604   }
630605
631606}
632607
633static void smpc_rtc_write(running_machine &machine)
608void saturn_state::smpc_rtc_write()
634609{
635   saturn_state *state = machine.driver_data<saturn_state>();
636610   int i;
637611
638612   for(i=0;i<7;i++)
639      state->m_smpc.rtc_data[i] = state->m_smpc.IREG[i];
613      m_smpc.rtc_data[i] = m_smpc.IREG[i];
640614}
641615
642static void smpc_memory_setting(running_machine &machine)
616void saturn_state::smpc_memory_setting()
643617{
644   saturn_state *state = machine.driver_data<saturn_state>();
645618   int i;
646619
647620   for(i=0;i<4;i++)
648      state->m_smpc.SMEM[i] = state->m_smpc.IREG[i];
621      m_smpc.SMEM[i] = m_smpc.IREG[i];
649622}
650623
651static void smpc_nmi_req(running_machine &machine)
624void saturn_state::smpc_nmi_req()
652625{
653   saturn_state *state = machine.driver_data<saturn_state>();
654
655626   /*NMI is unconditionally requested */
656   state->m_maincpu->set_input_line(INPUT_LINE_NMI, PULSE_LINE);
627   m_maincpu->set_input_line(INPUT_LINE_NMI, PULSE_LINE);
657628}
658629
659static TIMER_CALLBACK( smpc_nmi_set )
630TIMER_CALLBACK_MEMBER( saturn_state::smpc_nmi_set )
660631{
661   saturn_state *state = machine.driver_data<saturn_state>();
632//  printf("%d %d\n",machine().first_screen()->hpos(),machine().first_screen()->vpos());
662633
663//  printf("%d %d\n",machine.first_screen()->hpos(),machine.first_screen()->vpos());
664   state->m_NMI_reset = param;
634   m_NMI_reset = param;
665635   /* put issued command in OREG31 */
666   state->m_smpc.OREG[31] = 0x19 + param;
636   m_smpc.OREG[31] = 0x19 + param;
667637   /* clear hand-shake flag */
668   state->m_smpc.SF = 0x00;
638   m_smpc.SF = 0x00;
669639
670   //state->m_smpc.OREG[0] = (0x80) | ((state->m_NMI_reset & 1) << 6);
640   //m_smpc.OREG[0] = (0x80) | ((m_NMI_reset & 1) << 6);
671641}
672642
673643
r29211r29212
682652 *
683653 *******************************************/
684654
685static void smpc_comreg_exec(address_space &space, UINT8 data, UINT8 is_stv)
655void saturn_state::smpc_comreg_exec(address_space &space, UINT8 data, UINT8 is_stv)
686656{
687   saturn_state *state = space.machine().driver_data<saturn_state>();
688
689657   switch (data)
690658   {
691659      case 0x00:
692660         if(LOG_SMPC) printf ("SMPC: Master ON\n");
693         smpc_master_on(space.machine());
661         smpc_master_on();
694662         break;
695663      //case 0x01: Master OFF?
696664      case 0x02:
697665      case 0x03:
698         if(LOG_SMPC) printf ("SMPC: Slave %s %d %d\n",(data & 1) ? "off" : "on",space.machine().first_screen()->hpos(),space.machine().first_screen()->vpos());
699         space.machine().scheduler().timer_set(attotime::from_usec(15), FUNC(smpc_slave_enable),data & 1);
666         if(LOG_SMPC) printf ("SMPC: Slave %s %d %d\n",(data & 1) ? "off" : "on",machine().first_screen()->hpos(),machine().first_screen()->vpos());
667         machine().scheduler().timer_set(attotime::from_usec(15), timer_expired_delegate(FUNC(saturn_state::smpc_slave_enable),this),data & 1);
700668         break;
701669      case 0x06:
702670      case 0x07:
703671         if(LOG_SMPC) printf ("SMPC: Sound %s\n",(data & 1) ? "off" : "on");
704672
705673         if(!is_stv)
706            space.machine().scheduler().timer_set(attotime::from_usec(15), FUNC(smpc_sound_enable),data & 1);
674            machine().scheduler().timer_set(attotime::from_usec(15), timer_expired_delegate(FUNC(saturn_state::smpc_sound_enable),this),data & 1);
707675         break;
708676      /*CD (SH-1) ON/OFF */
709677      case 0x08:
710678      case 0x09:
711679         printf ("SMPC: CD %s\n",(data & 1) ? "off" : "on");
712         space.machine().scheduler().timer_set(attotime::from_usec(20), FUNC(smpc_cd_enable),data & 1);
680         machine().scheduler().timer_set(attotime::from_usec(20), timer_expired_delegate(FUNC(saturn_state::smpc_cd_enable),this),data & 1);
713681         break;
714682      case 0x0d:
715683         if(LOG_SMPC) printf ("SMPC: System Reset\n");
716         smpc_system_reset(space.machine());
684         smpc_system_reset();
717685         break;
718686      case 0x0e:
719687      case 0x0f:
720         if(LOG_SMPC) printf ("SMPC: Change Clock to %s (%d %d)\n",data & 1 ? "320" : "352",space.machine().first_screen()->hpos(),space.machine().first_screen()->vpos());
688         if(LOG_SMPC) printf ("SMPC: Change Clock to %s (%d %d)\n",data & 1 ? "320" : "352",machine().first_screen()->hpos(),machine().first_screen()->vpos());
721689
722690         /* on ST-V timing of this is pretty fussy, you get 2 credits at start-up otherwise
723691            My current theory is that SMPC first stops all CPUs until it executes the whole snippet for this,
r29211r29212
725693            can do an usable mid-frame clock switching anyway.
726694            */
727695
728         state->m_maincpu->set_input_line(INPUT_LINE_HALT, ASSERT_LINE);
729         state->m_slave->set_input_line(INPUT_LINE_HALT, ASSERT_LINE);
730         state->m_audiocpu->set_input_line(INPUT_LINE_HALT, ASSERT_LINE);
696         m_maincpu->set_input_line(INPUT_LINE_HALT, ASSERT_LINE);
697         m_slave->set_input_line(INPUT_LINE_HALT, ASSERT_LINE);
698         m_audiocpu->set_input_line(INPUT_LINE_HALT, ASSERT_LINE);
731699
732         space.machine().scheduler().timer_set(space.machine().first_screen()->time_until_pos(state->get_vblank_start_position()*state->get_ystep_count(), 0), FUNC(smpc_change_clock),data & 1);
700         machine().scheduler().timer_set(machine().first_screen()->time_until_pos(get_vblank_start_position()*get_ystep_count(), 0), timer_expired_delegate(FUNC(saturn_state::smpc_change_clock),this),data & 1);
733701         break;
734702      /*"Interrupt Back"*/
735703      case 0x10:
736704         if(0)
737705         {
738            saturn_state *state = space.machine().driver_data<saturn_state>();
739            printf ("SMPC: Status Acquire %02x %02x %02x %d\n",state->m_smpc.IREG[0],state->m_smpc.IREG[1],state->m_smpc.IREG[2],space.machine().first_screen()->vpos());
706            printf ("SMPC: Status Acquire %02x %02x %02x %d\n",m_smpc.IREG[0],m_smpc.IREG[1],m_smpc.IREG[2],machine().first_screen()->vpos());
740707         }
741708
742709         int timing;
743710
744711         timing = 8;
745712
746         if(state->m_smpc.IREG[0] != 0) // non-peripheral data
713         if(m_smpc.IREG[0] != 0) // non-peripheral data
747714            timing += 8;
748715
749716         /* TODO: At vblank-out actually ... */
750         if(state->m_smpc.IREG[1] & 8) // peripheral data
717         if(m_smpc.IREG[1] & 8) // peripheral data
751718            timing += 700;
752719
753720         /* TODO: check if IREG[2] is setted to 0xf0 */
r29211r29212
755722            int i;
756723
757724            for(i=0;i<3;i++)
758               state->m_smpc.intback_buf[i] = state->m_smpc.IREG[i];
725               m_smpc.intback_buf[i] = m_smpc.IREG[i];
759726         }
760727
761728         if(is_stv)
762729         {
763            space.machine().scheduler().timer_set(attotime::from_usec(timing), FUNC(stv_smpc_intback),0); //TODO: variable time
730            machine().scheduler().timer_set(attotime::from_usec(timing), timer_expired_delegate(FUNC(saturn_state::stv_smpc_intback),this),0); //TODO: variable time
764731         }
765732         else
766733         {
767            if(LOG_PAD_CMD) printf("INTBACK %02x %02x %d %d\n",state->m_smpc.IREG[0],state->m_smpc.IREG[1],space.machine().first_screen()->vpos(),(int)space.machine().first_screen()->frame_number());
768            space.machine().scheduler().timer_set(attotime::from_usec(timing), FUNC(saturn_smpc_intback),0); //TODO: is variable time correct?
734            if(LOG_PAD_CMD) printf("INTBACK %02x %02x %d %d\n",m_smpc.IREG[0],m_smpc.IREG[1],machine().first_screen()->vpos(),(int)machine().first_screen()->frame_number());
735            machine().scheduler().timer_set(attotime::from_usec(timing), timer_expired_delegate(FUNC(saturn_state::saturn_smpc_intback),this),0); //TODO: is variable time correct?
769736         }
770737         break;
771738      /* RTC write*/
772739      case 0x16:
773740         if(LOG_SMPC) printf("SMPC: RTC write\n");
774         smpc_rtc_write(space.machine());
741         smpc_rtc_write();
775742         break;
776743      /* SMPC memory setting*/
777744      case 0x17:
778745         if(LOG_SMPC) printf ("SMPC: memory setting\n");
779         smpc_memory_setting(space.machine());
746         smpc_memory_setting();
780747         break;
781748      case 0x18:
782749         if(LOG_SMPC) printf ("SMPC: NMI request\n");
783         smpc_nmi_req(space.machine());
750         smpc_nmi_req();
784751         break;
785752      case 0x19:
786753      case 0x1a:
787754         /* TODO: timing */
788         if(LOG_SMPC) printf ("SMPC: NMI %sable %d %d\n",data & 1 ? "Dis" : "En",space.machine().first_screen()->hpos(),space.machine().first_screen()->vpos());
789         space.machine().scheduler().timer_set(attotime::from_usec(100), FUNC(smpc_nmi_set),data & 1);
755         if(LOG_SMPC) printf ("SMPC: NMI %sable %d %d\n",data & 1 ? "Dis" : "En",machine().first_screen()->hpos(),machine().first_screen()->vpos());
756         machine().scheduler().timer_set(attotime::from_usec(100), timer_expired_delegate(FUNC(saturn_state::smpc_nmi_set),this),data & 1);
790757         break;
791758      default:
792759         printf ("cpu '%s' (PC=%08X) SMPC: undocumented Command %02x\n", space.device().tag(), space.device().safe_pc(), data);
r29211r29212
799766 *
800767 *******************************************/
801768
802READ8_HANDLER( stv_SMPC_r )
769READ8_MEMBER( saturn_state::stv_SMPC_r )
803770{
804   saturn_state *state = space.machine().driver_data<saturn_state>();
805771   int return_data = 0;
806772
807773   if(!(offset & 1))
808774      return 0;
809775
810776   if(offset >= 0x21 && offset <= 0x5f)
811      return_data = state->m_smpc.OREG[(offset-0x21) >> 1];
777      return_data = m_smpc.OREG[(offset-0x21) >> 1];
812778
813779   if (offset == 0x61) // TODO: SR
814      return_data = state->m_smpc.SR;
780      return_data = m_smpc.SR;
815781
816782   if (offset == 0x63)
817      return_data = state->m_smpc.SF;
783      return_data = m_smpc.SF;
818784
819785   if (offset == 0x75)//PDR1 read
820      return_data = state->ioport("DSW1")->read();
786      return_data = ioport("DSW1")->read();
821787
822788   if (offset == 0x77)//PDR2 read
823      return_data = (0xfe | state->m_eeprom->do_read());
789      return_data = (0xfe | m_eeprom->do_read());
824790
825791   return return_data;
826792}
827793
828WRITE8_HANDLER( stv_SMPC_w )
794WRITE8_MEMBER( saturn_state::stv_SMPC_w )
829795{
830   saturn_state *state = space.machine().driver_data<saturn_state>();
831
832796   if (!(offset & 1)) // avoid writing to even bytes
833797      return;
834798
835799//  if(LOG_SMPC) printf ("8-bit SMPC Write to Offset %02x with Data %02x\n", offset, data);
836800
837801   if(offset >= 1 && offset <= 0xd)
838      state->m_smpc.IREG[offset >> 1] = data;
802      m_smpc.IREG[offset >> 1] = data;
839803
840804   if(offset == 1) //IREG0, check if a BREAK / CONTINUE request for INTBACK command
841805   {
842      if(state->m_smpc.intback_stage)
806      if(m_smpc.intback_stage)
843807      {
844808         if(data & 0x40)
845809         {
846810            if(LOG_PAD_CMD) printf("SMPC: BREAK request\n");
847            state->m_smpc.SR &= 0x0f;
848            state->m_smpc.intback_stage = 0;
811            m_smpc.SR &= 0x0f;
812            m_smpc.intback_stage = 0;
849813         }
850814         else if(data & 0x80)
851815         {
852816            if(LOG_PAD_CMD) printf("SMPC: CONTINUE request\n");
853            space.machine().scheduler().timer_set(attotime::from_usec(700), FUNC(stv_intback_peripheral),0); /* TODO: is timing correct? */
854            state->m_smpc.OREG[31] = 0x10;
855            state->m_smpc.SF = 0x01; //TODO: set hand-shake flag?
817            machine().scheduler().timer_set(attotime::from_usec(700), timer_expired_delegate(FUNC(saturn_state::stv_intback_peripheral),this),0); /* TODO: is timing correct? */
818            m_smpc.OREG[31] = 0x10;
819            m_smpc.SF = 0x01; //TODO: set hand-shake flag?
856820         }
857821      }
858822   }
r29211r29212
864828      // we've processed the command, clear status flag
865829      if(data != 0x10 && data != 0x02 && data != 0x03 && data != 0x08 && data != 0x09 && data != 0xe && data != 0xf && data != 0x19 && data != 0x1a)
866830      {
867         state->m_smpc.OREG[31] = data; //read-back command
868         state->m_smpc.SF = 0x00;
831         m_smpc.OREG[31] = data; //read-back command
832         m_smpc.SF = 0x00;
869833      }
870834      /*TODO:emulate the timing of each command...*/
871835   }
872836
873837   if(offset == 0x63)
874      state->m_smpc.SF = data & 1;
838      m_smpc.SF = data & 1;
875839
876840   if(offset == 0x75)
877841   {
r29211r29212
882846      ---- -x-- EEPROM CS line
883847      ---- --xx A-Bus bank bits
884848      */
885      state->m_eeprom->clk_write((data & 0x08) ? ASSERT_LINE : CLEAR_LINE);
886      state->m_eeprom->di_write((data >> 4) & 1);
887      state->m_eeprom->cs_write((data & 0x04) ? ASSERT_LINE : CLEAR_LINE);
888      state->m_stv_multi_bank = data & 3;
849      m_eeprom->clk_write((data & 0x08) ? ASSERT_LINE : CLEAR_LINE);
850      m_eeprom->di_write((data >> 4) & 1);
851      m_eeprom->cs_write((data & 0x04) ? ASSERT_LINE : CLEAR_LINE);
852      m_stv_multi_bank = data & 3;
889853
890      stv_select_game(space.machine(), state->m_stv_multi_bank);
854      stv_select_game(m_stv_multi_bank);
891855
892      state->m_smpc.PDR1 = (data & 0x60);
856      m_smpc.PDR1 = (data & 0x60);
893857   }
894858
895859   if(offset == 0x77)
r29211r29212
898862          -xx- ---- PDR2
899863          ---x ---- Enable Sound System (ACTIVE LOW)
900864      */
901      //popmessage("PDR2 = %02x",state->m_smpc_ram[0x77]);
865      //popmessage("PDR2 = %02x",m_smpc_ram[0x77]);
902866
903867      if(LOG_SMPC) printf("SMPC: M68k %s\n",(data & 0x10) ? "off" : "on");
904      //space.machine().scheduler().timer_set(attotime::from_usec(100), FUNC(smpc_sound_enable),(state->m_smpc_ram[0x77] & 0x10) >> 4);
905      state->m_audiocpu->set_input_line(INPUT_LINE_RESET, (data & 0x10) ? ASSERT_LINE : CLEAR_LINE);
906      state->m_en_68k = ((data & 0x10) >> 4) ^ 1;
868      //machine().scheduler().timer_set(attotime::from_usec(100), timer_expired_delegate(FUNC(saturn_state::smpc_sound_enable),this),(m_smpc_ram[0x77] & 0x10) >> 4);
869      m_audiocpu->set_input_line(INPUT_LINE_RESET, (data & 0x10) ? ASSERT_LINE : CLEAR_LINE);
870      m_en_68k = ((data & 0x10) >> 4) ^ 1;
907871
908872      //if(LOG_SMPC) printf("SMPC: ram [0x77] = %02x\n",data);
909      state->m_smpc.PDR2 = (data & 0x60);
873      m_smpc.PDR2 = (data & 0x60);
910874   }
911875
912876   if(offset == 0x7d)
r29211r29212
915879      ---- --x- IOSEL2 direct (1) / control mode (0) port select
916880      ---- ---x IOSEL1 direct (1) / control mode (0) port select
917881      */
918      state->m_smpc.IOSEL1 = (data & 1) >> 0;
919      state->m_smpc.IOSEL2 = (data & 2) >> 1;
882      m_smpc.IOSEL1 = (data & 1) >> 0;
883      m_smpc.IOSEL2 = (data & 2) >> 1;
920884   }
921885
922886   if(offset == 0x7f)
923887   {
924888      //enable PAD irq & VDP2 external latch for port 1/2
925      state->m_smpc.EXLE1 = (data & 1) >> 0;
926      state->m_smpc.EXLE2 = (data & 2) >> 1;
889      m_smpc.EXLE1 = (data & 1) >> 0;
890      m_smpc.EXLE2 = (data & 2) >> 1;
927891   }
928892}
929893
r29211r29212
1001965
1002966   if (offset == 0x63)
1003967   {
1004      //printf("SF %d %d\n",space.machine().first_screen()->hpos(),space.machine().first_screen()->vpos());
968      //printf("SF %d %d\n",machine().first_screen()->hpos(),machine().first_screen()->vpos());
1005969      return_data = m_smpc.SF;
1006970   }
1007971
r29211r29212
10601024         else if(data & 0x80)
10611025         {
10621026            if(LOG_PAD_CMD) printf("SMPC: CONTINUE request\n");
1063            machine().scheduler().timer_set(attotime::from_usec(700), FUNC(intback_peripheral),0); /* TODO: is timing correct? */
1027            machine().scheduler().timer_set(attotime::from_usec(700), timer_expired_delegate(FUNC(saturn_state::intback_peripheral),this),0); /* TODO: is timing correct? */
10641028            m_smpc.OREG[31] = 0x10;
10651029            m_smpc.SF = 0x01; //TODO: set hand-shake flag?
10661030         }
trunk/src/emu/machine/smpc.h
r29211r29212
1DECLARE_WRITE8_HANDLER( stv_SMPC_w );
2DECLARE_READ8_HANDLER( stv_SMPC_r );
3DECLARE_WRITE8_HANDLER( saturn_SMPC_w );
4DECLARE_READ8_HANDLER( saturn_SMPC_r );
1// TODO: make separate device when code is decoupled better
2//DECLARE_WRITE8_MEMBER( stv_SMPC_w );
3//DECLARE_READ8_MEMBER( stv_SMPC_r );
4//DECLARE_WRITE8_MEMBER( saturn_SMPC_w );
5//DECLARE_READ8_MEMBER( saturn_SMPC_r );
trunk/src/mame/includes/stv.h
r29211r29212
645645   DECLARE_WRITE_LINE_MEMBER(scudsp_end_w);
646646   DECLARE_READ16_MEMBER(scudsp_dma_r);
647647   DECLARE_WRITE16_MEMBER(scudsp_dma_w);
648   
649   // FROM smpc.c
650   TIMER_CALLBACK_MEMBER( stv_bankswitch_state );
651   void stv_select_game(int gameno);
652   void smpc_master_on();
653   TIMER_CALLBACK_MEMBER( smpc_slave_enable );
654   TIMER_CALLBACK_MEMBER( smpc_sound_enable );
655   TIMER_CALLBACK_MEMBER( smpc_cd_enable );
656   void smpc_system_reset();
657   TIMER_CALLBACK_MEMBER( smpc_change_clock );
658   TIMER_CALLBACK_MEMBER( stv_intback_peripheral );
659   TIMER_CALLBACK_MEMBER( stv_smpc_intback );
660   void smpc_digital_pad(UINT8 pad_num, UINT8 offset);
661   void smpc_analog_pad(UINT8 pad_num, UINT8 offset, UINT8 id);
662   void smpc_keyboard(UINT8 pad_num, UINT8 offset);
663   void smpc_mouse(UINT8 pad_num, UINT8 offset, UINT8 id);
664   void smpc_md_pad(UINT8 pad_num, UINT8 offset, UINT8 id);
665   void smpc_unconnected(UINT8 pad_num, UINT8 offset);
666   TIMER_CALLBACK_MEMBER( intback_peripheral );
667   TIMER_CALLBACK_MEMBER( saturn_smpc_intback );
668   void smpc_rtc_write();
669   void smpc_memory_setting();
670   void smpc_nmi_req();
671   TIMER_CALLBACK_MEMBER( smpc_nmi_set );
672   void smpc_comreg_exec(address_space &space, UINT8 data, UINT8 is_stv);
673   DECLARE_READ8_MEMBER( stv_SMPC_r );
674   DECLARE_WRITE8_MEMBER( stv_SMPC_w );
675   
648676};
649677
650678class stv_state : public saturn_state
trunk/src/mame/drivers/stv.c
r29211r29212
927927
928928static ADDRESS_MAP_START( stv_mem, AS_PROGRAM, 32, stv_state )
929929   AM_RANGE(0x00000000, 0x0007ffff) AM_ROM AM_SHARE("share6")  // bios
930   AM_RANGE(0x00100000, 0x0010007f) AM_READWRITE8_LEGACY(stv_SMPC_r, stv_SMPC_w,0xffffffff)
930   AM_RANGE(0x00100000, 0x0010007f) AM_READWRITE8(stv_SMPC_r, stv_SMPC_w,0xffffffff)
931931   AM_RANGE(0x00180000, 0x0018ffff) AM_READWRITE8(saturn_backupram_r,saturn_backupram_w,0xffffffff) AM_SHARE("share1")
932932   AM_RANGE(0x00200000, 0x002fffff) AM_RAM AM_MIRROR(0x20100000) AM_SHARE("workram_l")
933933//  AM_RANGE(0x00400000, 0x0040001f) AM_READWRITE(stv_ioga_r32, stv_io_w32) AM_SHARE("ioga") AM_MIRROR(0x20) /* installed with per-game specific */

Previous 199869 Revisions Next


© 1997-2024 The MAME Team