Previous 15994 Revisions Next

r12586 Saturday 13th August, 2011 at 00:39:47 UTC by Angelo Salese
Major reorganization and clean-up of SMPC
[src/mame/drivers]saturn.c
[src/mame/includes]stv.h
[src/mame/machine]smpc.c

src/mame/machine/smpc.c
r12585r12586
99
1010TODO:
1111- timings;
12- fix intback issue with inputs;
13- better arrangement of variables;
12- fix intback issue with inputs (according to the docs, it should fall in between
13  VBLANK-IN and OUT, for obvious reasons);
1414- clean-ups;
1515
1616*************************************************************************************/
r12585r12586
155155#define LOG_SMPC 0
156156#define LOG_PAD_CMD 0
157157
158READ8_HANDLER( stv_SMPC_r )
159{
160   saturn_state *state = space->machine().driver_data<saturn_state>();
161   int return_data;
162
163   return_data = state->m_smpc_ram[offset];
164
165   if (offset == 0x61) // ?? many games need this or the controls don't work
166      return_data = 0x20 ^ 0xff;
167
168   if (offset == 0x75)//PDR1 read
169      return_data = input_port_read(space->machine(), "DSW1");
170
171   if (offset == 0x77)//PDR2 read
172      return_data=  (0xfe | space->machine().device<eeprom_device>("eeprom")->read_bit());
173
174//  if (offset == 0x33) //country code
175//      return_data = input_port_read(machine, "FAKE");
176
177   //if(LOG_SMPC) printf ("cpu %s (PC=%08X) SMPC: Read from Byte Offset %02x Returns %02x\n", space->device().tag(), cpu_get_pc(&space->device()), offset, return_data);
178
179
180   return return_data;
181}
182
183158static TIMER_CALLBACK( stv_bankswitch_state )
184159{
185160   saturn_state *state = machine.driver_data<saturn_state>();
r12585r12586
216191   saturn_state *state = machine.driver_data<saturn_state>();
217192
218193   device_set_input_line(state->m_slave, INPUT_LINE_RESET, param ? ASSERT_LINE : CLEAR_LINE);
219   state->m_smpc_ram[0x5f] = param + 0x02; //read-back for last command issued
220   state->m_smpc_ram[0x63] = 0x00; //clear hand-shake flag
194   state->m_smpc.OREG[31] = param + 0x02; //read-back for last command issued
195   state->m_smpc.SF = 0x00; //clear hand-shake flag
221196}
222197
223198static TIMER_CALLBACK( smpc_sound_enable )
r12585r12586
226201
227202   device_set_input_line(state->m_audiocpu, INPUT_LINE_RESET, param ? ASSERT_LINE : CLEAR_LINE);
228203   state->m_en_68k = param ^ 1;
229   state->m_smpc_ram[0x5f] = param + 0x06; //read-back for last command issued
230   state->m_smpc_ram[0x63] = 0x00; //clear hand-shake flag
204   state->m_smpc.OREG[31] = param + 0x06; //read-back for last command issued
205   state->m_smpc.SF = 0x00; //clear hand-shake flag
231206}
232207
233208static void smpc_system_reset(running_machine &machine)
r12585r12586
270245static TIMER_CALLBACK( stv_smpc_intback )
271246{
272247   saturn_state *state = machine.driver_data<saturn_state>();
248   int i;
273249
274   state->m_smpc_ram[0x21] = (0x80) | ((state->m_NMI_reset & 1) << 6);
250   state->m_smpc.OREG[0] = (0x80) | ((state->m_NMI_reset & 1) << 6);
275251
276   {
277      int i;
252   for(i=0;i<7;i++)
253      state->m_smpc.OREG[1+i] = state->m_smpc.rtc_data[i];
278254
279      for(i=0;i<7;i++)
280         state->m_smpc_ram[0x23+i*2] = state->m_smpc.rtc_data[i];
281   }
255   state->m_smpc.OREG[8]=0x00;  // CTG0 / CTG1?
282256
283   state->m_smpc_ram[0x31]=0x00;  //?
257   state->m_smpc.OREG[9]=0x00;  // TODO: system region on Saturn
284258
285   //state->m_smpc_ram[0x33]=input_port_read(space->machine(), "FAKE");
286
287   state->m_smpc_ram[0x35]= 0 << 7 |
259   state->m_smpc.OREG[10]= 0 << 7 |
288260                            state->m_vdp2.dotsel << 6 |
289261                            1 << 5 |
290262                            1 << 4 |
r12585r12586
292264                            1 << 2 |
293265                            0 << 1 | //SYSRES
294266                            0 << 0;  //SOUNDRES
295   state->m_smpc_ram[0x37]= 0 << 6; //CDRES
267   state->m_smpc.OREG[11]= 0 << 6; //CDRES
296268
297   state->m_smpc_ram[0x39]=0xff;
298   state->m_smpc_ram[0x3b]=0xff;
299   state->m_smpc_ram[0x3d]=0xff;
300   state->m_smpc_ram[0x3f]=0xff;
269   for(i=0;i<4;i++)
270      state->m_smpc.OREG[12+i]=state->m_smpc.SMEM[i];
301271
302   state->m_smpc_ram[0x41]=0xff;
303   state->m_smpc_ram[0x43]=0xff;
304   state->m_smpc_ram[0x45]=0xff;
305   state->m_smpc_ram[0x47]=0xff;
306   state->m_smpc_ram[0x49]=0xff;
307   state->m_smpc_ram[0x4b]=0xff;
308   state->m_smpc_ram[0x4d]=0xff;
309   state->m_smpc_ram[0x4f]=0xff;
310   state->m_smpc_ram[0x51]=0xff;
311   state->m_smpc_ram[0x53]=0xff;
312   state->m_smpc_ram[0x55]=0xff;
313   state->m_smpc_ram[0x57]=0xff;
314   state->m_smpc_ram[0x59]=0xff;
315   state->m_smpc_ram[0x5b]=0xff;
316   state->m_smpc_ram[0x5d]=0xff;
272   for(i=0;i<15;i++)
273      state->m_smpc.OREG[16+i]=0xff; // undefined
317274
318275   //  /*This is for RTC,cartridge code and similar stuff...*/
319276   //if(LOG_SMPC) printf ("Interrupt: System Manager (SMPC) at scanline %04x, Vector 0x47 Level 0x08\n",scanline);
r12585r12586
322279   else
323280      state->m_scu.ist |= (IRQ_SMPC);
324281
282   /* put issued command in OREG31 */
283   state->m_smpc.OREG[31] = 0x10; // TODO: doc says 0?
325284   /* clear hand-shake flag */
326   state->m_smpc_ram[0x5f] = 0x10;
327   state->m_smpc_ram[0x63] = 0x00;
285   state->m_smpc.SF = 0x00;
328286}
329287
330288static TIMER_CALLBACK( intback_peripheral )
r12585r12586
342300   for(pad_num=0;pad_num<2;pad_num++)
343301   {
344302      pad = input_port_read(machine, padnames[pad_num]);
345      state->m_smpc_ram[0x21+pad_num*8] = 0xf1;   // no tap, direct connect
346      state->m_smpc_ram[0x23+pad_num*8] = 0x02;   // saturn pad
347      state->m_smpc_ram[0x25+pad_num*8] = pad>>8;
348      state->m_smpc_ram[0x27+pad_num*8] = pad & 0xff;
303      state->m_smpc.OREG[0+pad_num*4] = 0xf1;   // no tap, direct connect
304      state->m_smpc.OREG[1+pad_num*4] = 0x02;   // saturn pad
305      state->m_smpc.OREG[2+pad_num*4] = pad>>8;
306      state->m_smpc.OREG[3+pad_num*4] = pad & 0xff;
349307   }
350308
351309   if (state->m_smpc.intback_stage == 2)
352310   {
353      state->m_smpc.smpcSR = (0x80 | state->m_smpc.pmode);   // pad 2, no more data, echo back pad mode set by intback
311      state->m_smpc.SR = (0x80 | state->m_smpc.pmode);   // pad 2, no more data, echo back pad mode set by intback
354312      state->m_smpc.intback_stage = 0;
355313   }
356314   else
357315   {
358      state->m_smpc.smpcSR = (0xc0 | state->m_smpc.pmode);   // pad 1, more data, echo back pad mode set by intback
316      state->m_smpc.SR = (0xc0 | state->m_smpc.pmode);   // pad 1, more data, echo back pad mode set by intback
359317      state->m_smpc.intback_stage ++;
360318   }
361319
r12585r12586
364322   else
365323      state->m_scu.ist |= (IRQ_SMPC);
366324
367   state->m_smpc_ram[0x5f] = 0x10; /* callback for last command issued */
368   state->m_smpc_ram[0x63] = 0x00;   /* clear hand-shake flag */
325   state->m_smpc.OREG[31] = 0x10; /* callback for last command issued */
326   state->m_smpc.SF = 0x00;   /* clear hand-shake flag */
369327}
370328
371329static TIMER_CALLBACK( saturn_smpc_intback )
372330{
373331   saturn_state *state = machine.driver_data<saturn_state>();
374332
375   if(state->m_smpc_ram[1] != 0)
333   if(state->m_smpc.IREG[0] != 0)
376334   {
377335      {
378         state->m_smpc_ram[0x21] = (0x80) | ((state->m_NMI_reset & 1) << 6);
336         int i;
379337
380         {
381            int i;
338         state->m_smpc.OREG[0] = (0x80) | ((state->m_NMI_reset & 1) << 6); // bit 7: SETTIME (RTC isn't setted up properly)
382339
383            for(i=0;i<7;i++)
384               state->m_smpc_ram[0x23+i*2] = state->m_smpc.rtc_data[i];
385         }
340         for(i=0;i<7;i++)
341            state->m_smpc.OREG[1+i] = state->m_smpc.rtc_data[i];
386342
387         state->m_smpc_ram[0x31]=0x00;  //?
343         state->m_smpc.OREG[8]=0x00;  //Cartridge code?
388344
389         //state->m_smpc_ram[0x33]=input_port_read(space->machine(), "FAKE");
345         state->m_smpc.OREG[9] = state->m_saturn_region;
390346
391         state->m_smpc_ram[0x35]= 0 << 7 |
347         state->m_smpc.OREG[10]= 0 << 7 |
392348                                  state->m_vdp2.dotsel << 6 |
393349                                  1 << 5 |
394350                                  1 << 4 |
r12585r12586
396352                                  1 << 2 |
397353                                  0 << 1 | //SYSRES
398354                                  0 << 0;  //SOUNDRES
399         state->m_smpc_ram[0x37]= 0 << 6; //CDRES
355         state->m_smpc.OREG[11]= 0 << 6; //CDRES
400356
401         state->m_smpc_ram[0x39]=state->m_smpc.SMEM[0];
402         state->m_smpc_ram[0x3b]=state->m_smpc.SMEM[1];
403         state->m_smpc_ram[0x3d]=state->m_smpc.SMEM[2];
404         state->m_smpc_ram[0x3f]=state->m_smpc.SMEM[3];
357         for(i=0;i<4;i++)
358            state->m_smpc.OREG[12+i]=state->m_smpc.SMEM[i];
405359
406         state->m_smpc_ram[0x41]=0xff;
407         state->m_smpc_ram[0x43]=0xff;
408         state->m_smpc_ram[0x45]=0xff;
409         state->m_smpc_ram[0x47]=0xff;
410         state->m_smpc_ram[0x49]=0xff;
411         state->m_smpc_ram[0x4b]=0xff;
412         state->m_smpc_ram[0x4d]=0xff;
413         state->m_smpc_ram[0x4f]=0xff;
414         state->m_smpc_ram[0x51]=0xff;
415         state->m_smpc_ram[0x53]=0xff;
416         state->m_smpc_ram[0x55]=0xff;
417         state->m_smpc_ram[0x57]=0xff;
418         state->m_smpc_ram[0x59]=0xff;
419         state->m_smpc_ram[0x5b]=0xff;
420         state->m_smpc_ram[0x5d]=0xff;
360         for(i=0;i<15;i++)
361            state->m_smpc.OREG[16+i]=0xff; // undefined
421362      }
422363
423      state->m_smpc.intback_stage = (state->m_smpc_ram[3] & 8) >> 3; // first peripheral
424      state->m_smpc.smpcSR = 0x40 | state->m_smpc.intback_stage << 5;
425      state->m_smpc.pmode = state->m_smpc_ram[1]>>4;
426      state->m_smpc_ram[0x5f] = 0x10;
364      state->m_smpc.intback_stage = (state->m_smpc.IREG[1] & 8) >> 3; // first peripheral
365      state->m_smpc.SR = 0x40 | state->m_smpc.intback_stage << 5;
366      state->m_smpc.pmode = state->m_smpc.IREG[0]>>4;
427367
428368      if(!(state->m_scu.ism & IRQ_SMPC))
429369         device_set_input_line_and_vector(state->m_maincpu, 8, HOLD_LINE, 0x47);
430370      else
431371         state->m_scu.ist |= (IRQ_SMPC);
432372
373      /* put issued command in OREG31 */
374      state->m_smpc.OREG[31] = 0x10;
433375      /* clear hand-shake flag */
434      state->m_smpc_ram[0x63] = 0x00;
376      state->m_smpc.SF = 0x00;
435377   }
436   else if(state->m_smpc_ram[3] & 8)
378   else if(state->m_smpc.IREG[1] & 8)
437379   {
438      state->m_smpc.intback_stage = (state->m_smpc_ram[3] & 8) >> 3; // first peripheral
439      state->m_smpc.smpcSR = 0x40;
440      state->m_smpc_ram[0x5f] = 0x10;
380      state->m_smpc.intback_stage = (state->m_smpc.IREG[1] & 8) >> 3; // first peripheral
381      state->m_smpc.SR = 0x40;
382      state->m_smpc.OREG[31] = 0x10;
441383      machine.scheduler().timer_set(attotime::from_usec(0), FUNC(intback_peripheral),0);
442384   }
443385   else
444386   {
445      printf("SMPC intback bogus behaviour called %02x %02x\n",state->m_smpc_ram[1],state->m_smpc_ram[3]);
387      printf("SMPC intback bogus behaviour called %02x %02x\n",state->m_smpc.IREG[0],state->m_smpc.IREG[1]);
446388   }
447389
448390}
r12585r12586
453395   int i;
454396
455397   for(i=0;i<7;i++)
456      state->m_smpc.rtc_data[i] = state->m_smpc_ram[0x01+i*2];
398      state->m_smpc.rtc_data[i] = state->m_smpc.IREG[i];
457399}
458400
459401static void smpc_memory_setting(running_machine &machine)
r12585r12586
462404   int i;
463405
464406   for(i=0;i<4;i++)
465      state->m_smpc.SMEM[i] = state->m_smpc_ram[0x01+i*2];
407      state->m_smpc.SMEM[i] = state->m_smpc.IREG[i];
466408}
467409
468410static void smpc_nmi_req(running_machine &machine)
r12585r12586
478420   saturn_state *state = machine.driver_data<saturn_state>();
479421
480422   state->m_NMI_reset = cmd ^ 1;
481   state->m_smpc_ram[0x21] = (0x80) | ((state->m_NMI_reset & 1) << 6);
423   state->m_smpc.OREG[0] = (0x80) | ((state->m_NMI_reset & 1) << 6);
482424}
483425
426/********************************************
427 *
428 * ST-V handlers
429 *
430 *******************************************/
431
432READ8_HANDLER( stv_SMPC_r )
433{
434   saturn_state *state = space->machine().driver_data<saturn_state>();
435   int return_data = 0;
436
437   if(!(offset & 1))
438      return 0;
439
440   if(offset >= 0x21 && offset <= 0x5f)
441      return_data = state->m_smpc.OREG[(offset-0x21) >> 1];
442
443   if (offset == 0x61) // TODO: SR
444      return_data = 0x20 ^ 0xff;
445
446   if (offset == 0x63)
447      return_data = state->m_smpc.SF;
448
449   if (offset == 0x75)//PDR1 read
450      return_data = input_port_read(space->machine(), "DSW1");
451
452   if (offset == 0x77)//PDR2 read
453      return_data = (0xfe | space->machine().device<eeprom_device>("eeprom")->read_bit());
454
455   return return_data;
456}
457
458static void stv_comreg_exec(address_space *space,UINT8 data)
459{
460   switch (data)
461   {
462      case 0x00:
463         if(LOG_SMPC) printf ("SMPC: Master ON\n");
464         smpc_master_on(space->machine());
465         break;
466      //in theory 0x01 is for Master OFF,but obviously is not used.
467      case 0x02:
468      case 0x03:
469         if(LOG_SMPC) printf ("SMPC: Slave %s\n",(data & 1) ? "off" : "on");
470         space->machine().scheduler().timer_set(attotime::from_usec(100), FUNC(smpc_slave_enable),data & 1);
471         break;
472      case 0x06:
473      case 0x07:
474         if(LOG_SMPC) printf ("SMPC: Sound %s, ignored\n",(data & 1) ? "off" : "on");
475         break;
476      /*CD (SH-1) ON/OFF,guess that this is needed for Sports Fishing games...*/
477      //case 0x08:
478      //case 0x09:
479      case 0x0d:
480         if(LOG_SMPC) printf ("SMPC: System Reset\n");
481         smpc_system_reset(space->machine());
482         break;
483      case 0x0e:
484      case 0x0f:
485         if(LOG_SMPC) printf ("SMPC: Change Clock to %s\n",data & 1 ? "320" : "352");
486         smpc_change_clock(space->machine(),data & 1);
487         break;
488      /*"Interrupt Back"*/
489      case 0x10:
490         if(LOG_SMPC) printf ("SMPC: Status Acquire\n");
491         space->machine().scheduler().timer_set(attotime::from_msec(16), FUNC(stv_smpc_intback),0); //TODO: variable time
492         break;
493      /* RTC write*/
494      case 0x16:
495         if(LOG_SMPC) printf("SMPC: RTC write\n");
496         smpc_rtc_write(space->machine());
497         break;
498      /* SMPC memory setting*/
499      case 0x17:
500         if(LOG_SMPC) printf ("SMPC: memory setting\n");
501         //smpc_memory_setting(space->machine());
502         break;
503      case 0x18:
504         if(LOG_SMPC) printf ("SMPC: NMI request\n");
505         smpc_nmi_req(space->machine());
506         break;
507      case 0x19:
508      case 0x1a:
509         if(LOG_SMPC) printf ("SMPC: NMI %sable\n",data & 1 ? "Dis" : "En");
510         smpc_nmi_set(space->machine(),data & 1);
511         break;
512      default:
513         printf ("cpu '%s' (PC=%08X) SMPC: undocumented Command %02x\n", space->device().tag(), cpu_get_pc(&space->device()), data);
514   }
515}
516
484517WRITE8_HANDLER( stv_SMPC_w )
485518{
486519   saturn_state *state = space->machine().driver_data<saturn_state>();
487   system_time systime;
488   space->machine().base_datetime(systime);
489520
521   if (!(offset & 1)) // avoid writing to even bytes
522      return;
523
490524//  if(LOG_SMPC) printf ("8-bit SMPC Write to Offset %02x with Data %02x\n", offset, data);
491   state->m_smpc_ram[offset] = data;
492525
526   if(offset >= 1 && offset <= 0xd)
527      state->m_smpc.IREG[offset >> 1] = data;
528
529   if (offset == 0x1f) // COMREG
530   {
531      stv_comreg_exec(space,data);
532
533      // we've processed the command, clear status flag
534      if(data != 0x10 && data != 0x02 && data != 0x03)
535      {
536         state->m_smpc.OREG[31] = data; //read-back command
537         state->m_smpc.SF = 0x00;
538      }
539      /*TODO:emulate the timing of each command...*/
540   }
541
542   if(offset == 0x63)
543      state->m_smpc.SF = data & 1;
544
493545   if(offset == 0x75)
494546   {
495547      /*
r12585r12586
518570        */
519571      //popmessage("PDR2 = %02x",state->m_smpc_ram[0x77]);
520572
521      if(LOG_SMPC) printf("SMPC: M68k %s\n",(state->m_smpc_ram[0x77] & 0x10) ? "off" : "on");
573      if(LOG_SMPC) printf("SMPC: M68k %s\n",(data & 0x10) ? "off" : "on");
522574      //space->machine().scheduler().timer_set(attotime::from_usec(100), FUNC(smpc_sound_enable),(state->m_smpc_ram[0x77] & 0x10) >> 4);
523      device_set_input_line(state->m_audiocpu, INPUT_LINE_RESET, (state->m_smpc_ram[0x77] & 0x10) ? ASSERT_LINE : CLEAR_LINE);
524      state->m_en_68k = ((state->m_smpc_ram[0x77] & 0x10) >> 4) ^ 1;
575      device_set_input_line(state->m_audiocpu, INPUT_LINE_RESET, (data & 0x10) ? ASSERT_LINE : CLEAR_LINE);
576      state->m_en_68k = ((data & 0x10) >> 4) ^ 1;
525577
526      //if(LOG_SMPC) printf("SMPC: ram [0x77] = %02x\n",state->m_smpc_ram[0x77]);
578      //if(LOG_SMPC) printf("SMPC: ram [0x77] = %02x\n",data);
527579      state->m_smpc.PDR2 = (data & 0x60);
528580   }
529581
r12585r12586
533585        ---- --x- IOSEL2 direct (1) / control mode (0) port select
534586        ---- ---x IOSEL1 direct (1) / control mode (0) port select
535587        */
536      state->m_smpc.IOSEL1 = (state->m_smpc_ram[0x7d] & 1) >> 0;
537      state->m_smpc.IOSEL2 = (state->m_smpc_ram[0x7d] & 2) >> 1;
588      state->m_smpc.IOSEL1 = (data & 1) >> 0;
589      state->m_smpc.IOSEL2 = (data & 2) >> 1;
538590   }
539591
540592   if(offset == 0x7f)
541593   {
542594      //enable PAD irq & VDP2 external latch for port 1/2
543      state->m_smpc.EXLE1 = (state->m_smpc_ram[0x7f] & 1) >> 0;
544      state->m_smpc.EXLE2 = (state->m_smpc_ram[0x7f] & 2) >> 1;
595      state->m_smpc.EXLE1 = (data & 1) >> 0;
596      state->m_smpc.EXLE2 = (data & 2) >> 1;
545597   }
546
547   if (offset == 0x1f) // COMREG
548   {
549      switch (data)
550      {
551         case 0x00:
552            if(LOG_SMPC) printf ("SMPC: Master ON\n");
553            smpc_master_on(space->machine());
554            break;
555         //in theory 0x01 is for Master OFF,but obviously is not used.
556         case 0x02:
557         case 0x03:
558            if(LOG_SMPC) printf ("SMPC: Slave %s\n",(data & 1) ? "off" : "on");
559            space->machine().scheduler().timer_set(attotime::from_usec(100), FUNC(smpc_slave_enable),data & 1);
560            break;
561         case 0x06:
562         case 0x07:
563            if(LOG_SMPC) printf ("SMPC: Sound %s, ignored\n",(data & 1) ? "off" : "on");
564            break;
565         /*CD (SH-1) ON/OFF,guess that this is needed for Sports Fishing games...*/
566         //case 0x08:
567         //case 0x09:
568         case 0x0d:
569            if(LOG_SMPC) printf ("SMPC: System Reset\n");
570            smpc_system_reset(space->machine());
571            break;
572         case 0x0e:
573         case 0x0f:
574            if(LOG_SMPC) printf ("SMPC: Change Clock to %s\n",data & 1 ? "320" : "352");
575            smpc_change_clock(space->machine(),data & 1);
576            break;
577         /*"Interrupt Back"*/
578         case 0x10:
579            if(LOG_SMPC) printf ("SMPC: Status Acquire\n");
580            space->machine().scheduler().timer_set(attotime::from_msec(16), FUNC(stv_smpc_intback),0); //TODO: variable time
581            break;
582         /* RTC write*/
583         case 0x16:
584            if(LOG_SMPC) printf("SMPC: RTC write\n");
585            smpc_rtc_write(space->machine());
586            break;
587         /* SMPC memory setting*/
588         case 0x17:
589            if(LOG_SMPC) printf ("SMPC: memory setting\n");
590            //smpc_memory_setting(space->machine());
591            break;
592         case 0x18:
593            if(LOG_SMPC) printf ("SMPC: NMI request\n");
594            smpc_nmi_req(space->machine());
595            break;
596         case 0x19:
597         case 0x1a:
598            if(LOG_SMPC) printf ("SMPC: NMI %sable\n",data & 1 ? "Dis" : "En");
599            smpc_nmi_set(space->machine(),data & 1);
600            break;
601         default:
602            printf ("cpu '%s' (PC=%08X) SMPC: undocumented Command %02x\n", space->device().tag(), cpu_get_pc(&space->device()), data);
603      }
604
605      // we've processed the command, clear status flag
606      if(data != 0x10 && data != 0x02 && data != 0x03)
607      {
608         state->m_smpc_ram[0x5f] = data; //read-back command
609         state->m_smpc_ram[0x63] = 0x00;
610      }
611      /*TODO:emulate the timing of each command...*/
612   }
613598}
614599
600/********************************************
601 *
602 * Saturn handlers
603 *
604 *******************************************/
605
615606READ8_HANDLER( saturn_SMPC_r )
616607{
617608   saturn_state *state = space->machine().driver_data<saturn_state>();
618   int return_data;
609   UINT8 return_data = 0;
619610
620   return_data = state->m_smpc_ram[offset];
611   if (!(offset & 1)) // avoid reading to even bytes (TODO: is it 0s or 1s?)
612      return 0x00;
621613
622   if ((offset == 0x61))
623      return_data = state->m_smpc.smpcSR;
614   if(offset >= 0x21 && offset <= 0x5f)
615      return_data = state->m_smpc.OREG[(offset-0x21) >> 1];
624616
617   if (offset == 0x61)
618      return_data = state->m_smpc.SR;
619
620   if (offset == 0x63)
621      return_data = state->m_smpc.SF;
622
625623   if (offset == 0x75 || offset == 0x77)//PDR1/2 read
626624   {
627/*
628    PORT_START("JOY1")
629    PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1)
630    PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1)
631    PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1)
632    PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1)
633    PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_START ) PORT_PLAYER(1) // START
634    PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P1 A") PORT_PLAYER(1) // A
635    PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P1 B") PORT_PLAYER(1) // B
636    PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("P1 C") PORT_PLAYER(1) // C
637    PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("P1 R") PORT_PLAYER(1) // R
638    PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("P1 X") PORT_PLAYER(1) // X
639    PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("P1 Y") PORT_PLAYER(1) // Y
640    PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("P1 Z") PORT_PLAYER(1) // Z
641    PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_NAME("P1 L") PORT_PLAYER(1) // L
642*/
643625      if ((state->m_smpc.IOSEL1 && offset == 0x75) || (state->m_smpc.IOSEL2 && offset == 0x77))
644626      {
645627         int hshake;
r12585r12586
657639      }
658640   }
659641
660   if (offset == 0x33) return_data = state->m_saturn_region;
661
662642   if (LOG_SMPC) logerror ("cpu %s (PC=%08X) SMPC: Read from Byte Offset %02x (%d) Returns %02x\n", space->device().tag(), cpu_get_pc(&space->device()), offset, offset>>1, return_data);
663643
664644
665645   return return_data;
666646}
667647
668WRITE8_HANDLER( saturn_SMPC_w )
648static void saturn_comreg_exec(address_space *space,UINT8 data)
669649{
670650   saturn_state *state = space->machine().driver_data<saturn_state>();
671   system_time systime;
672//   UINT8 last;
673   running_machine &machine = space->machine();
674651
675   /* get the current date/time from the core */
676   machine.current_datetime(systime);
652   switch (data)
653   {
654      case 0x00:
655         if(LOG_SMPC) printf ("SMPC: Master ON\n");
656         smpc_master_on(space->machine());
657         break;
658      //in theory 0x01 is for Master OFF
659      case 0x02:
660      case 0x03:
661         if(LOG_SMPC) printf ("SMPC: Slave %s\n",(data & 1) ? "off" : "on");
662         space->machine().scheduler().timer_set(attotime::from_usec(100), FUNC(smpc_slave_enable),data & 1);
663         break;
664      case 0x06:
665      case 0x07:
666         if(LOG_SMPC) printf ("SMPC: Sound %s\n",(data & 1) ? "off" : "on");
667         space->machine().scheduler().timer_set(attotime::from_usec(100), FUNC(smpc_sound_enable),data & 1);
668         break;
669      /*CD (SH-1) ON/OFF,guess that this is needed for Sports Fishing games...*/
670      //case 0x08:
671      //case 0x09:
672      case 0x0d:
673         if(LOG_SMPC) printf ("SMPC: System Reset\n");
674         smpc_system_reset(space->machine());
675         break;
676      case 0x0e:
677      case 0x0f:
678         if(LOG_SMPC) printf ("SMPC: Change Clock to %s\n",data & 1 ? "320" : "352");
679         smpc_change_clock(space->machine(),data & 1);
680         break;
681      /*"Interrupt Back"*/
682      case 0x10:
683         if(LOG_SMPC) printf ("SMPC: Status Acquire (IntBack)\n");
684         int timing;
677685
678  if (LOG_SMPC) logerror ("8-bit SMPC Write to Offset %02x (reg %d) with Data %02x (prev %02x)\n", offset, offset>>1, data, state->m_smpc_ram[offset]);
686         timing = 100;
679687
680//  if (offset == 0x7d) printf("IOSEL2 %d IOSEL1 %d\n", (data>>1)&1, data&1);
688         if(state->m_smpc.IREG[0] != 0) // non-peripheral data
689            timing = 200;
681690
682//   last = state->m_smpc_ram[offset];
691         if(state->m_smpc.IREG[1] & 8) // peripheral data
692            timing = 15000;
683693
684   if (offset == 1)
694         /* TODO: check if IREG[2] is setted to 0xf0 */
695
696         if(LOG_PAD_CMD) printf("INTBACK %02x %02x\n",state->m_smpc.IREG[0],state->m_smpc.IREG[1]);
697         space->machine().scheduler().timer_set(attotime::from_usec(timing), FUNC(saturn_smpc_intback),0); //TODO: is variable time correct?
698         break;
699      /* RTC write*/
700      case 0x16:
701         if(LOG_SMPC) printf("SMPC: RTC write\n");
702         smpc_rtc_write(space->machine());
703         break;
704      /* SMPC memory setting*/
705      case 0x17:
706         if(LOG_SMPC) printf ("SMPC: memory setting\n");
707         smpc_memory_setting(space->machine());
708         break;
709      case 0x18:
710         if(LOG_SMPC) printf ("SMPC: NMI request\n");
711         smpc_nmi_req(space->machine());
712         break;
713      case 0x19:
714      case 0x1a:
715         if(LOG_SMPC) printf ("SMPC: NMI %sable\n",data & 1 ? "Dis" : "En");
716         smpc_nmi_set(space->machine(),data & 1);
717         break;
718      default:
719         printf ("cpu %s (PC=%08X) SMPC: undocumented Command %02x\n", space->device().tag(), cpu_get_pc(&space->device()), data);
720   }
721}
722
723WRITE8_HANDLER( saturn_SMPC_w )
724{
725   saturn_state *state = space->machine().driver_data<saturn_state>();
726
727   if (LOG_SMPC) logerror ("8-bit SMPC Write to Offset %02x (reg %d) with Data %02x\n", offset, offset>>1, data);
728
729   if (!(offset & 1)) // avoid writing to even bytes
730      return;
731
732   if(offset >= 1 && offset <= 0xd)
733      state->m_smpc.IREG[offset >> 1] = data;
734
735   if(offset == 1) //IREG0, check if a BREAK / CONTINUE request for INTBACK command
685736   {
686737      if(state->m_smpc.intback_stage)
687738      {
688739         if(data & 0x40)
689740         {
690741            if(LOG_PAD_CMD) printf("SMPC: BREAK request\n");
691            state->m_smpc.smpcSR &= 0x0f;
742            state->m_smpc.SR &= 0x0f;
692743            state->m_smpc.intback_stage = 0;
693744         }
694745         else if(data & 0x80)
695746         {
696747            if(LOG_PAD_CMD) printf("SMPC: CONTINUE request\n");
697748            space->machine().scheduler().timer_set(attotime::from_usec(200), FUNC(intback_peripheral),0); /* TODO: is timing correct? */
698            state->m_smpc_ram[0x1f] = 0x10;
699            //state->m_smpc_ram[0x63] = 0x01; //TODO: set hand-shake flag?
749            state->m_smpc.OREG[31] = 0x10;
750            //state->m_smpc.SF = 0x01; //TODO: set hand-shake flag?
700751         }
701752      }
702753   }
703754
704   state->m_smpc_ram[offset] = data;
705
706   if (offset == 0x75)   // PDR1
755   if (offset == 0x1f)
707756   {
708      state->m_smpc.PDR1 = (data & state->m_smpc_ram[0x79]);
709   }
757      saturn_comreg_exec(space,data);
710758
711   if (offset == 0x77)   // PDR2
712   {
713      state->m_smpc.PDR2 = (data & state->m_smpc_ram[0x7b]);
759      // we've processed the command, clear status flag
760      if(data != 0x10 && data != 2 && data != 3 && data != 6 && data != 7)
761      {
762         state->m_smpc.OREG[31] = data; //read-back for last command issued
763         state->m_smpc.SF = 0x00; //clear hand-shake flag
764      }
765      /*TODO:emulate the timing of each command...*/
714766   }
715767
768   if (offset == 0x63)
769      state->m_smpc.SF = data & 1; // hand-shake flag
770
771   if(offset == 0x75)   // PDR1
772      state->m_smpc.PDR1 = (data & state->m_smpc.DDR1);
773
774   if(offset == 0x77)   // PDR2
775      state->m_smpc.PDR2 = (data & state->m_smpc.DDR2);
776
777   if(offset == 0x79)
778      state->m_smpc.DDR1 = data & 0x7f;
779
780   if(offset == 0x7b)
781      state->m_smpc.DDR2 = data & 0x7f;
782
716783   if(offset == 0x7d)
717784   {
718      state->m_smpc.IOSEL1 = state->m_smpc_ram[0x7d] & 1;
719      state->m_smpc.IOSEL2 = (state->m_smpc_ram[0x7d] & 2) >> 1;
785      state->m_smpc.IOSEL1 = data & 1;
786      state->m_smpc.IOSEL2 = (data & 2) >> 1;
720787   }
721788
722789   if(offset == 0x7f)
723790   {
724791      //enable PAD irq & VDP2 external latch for port 1/2
725      state->m_smpc.EXLE1 = (state->m_smpc_ram[0x7f] & 1) >> 0;
726      state->m_smpc.EXLE2 = (state->m_smpc_ram[0x7f] & 2) >> 1;
792      state->m_smpc.EXLE1 = (data & 1) >> 0;
793      state->m_smpc.EXLE2 = (data & 2) >> 1;
727794   }
728
729   if (offset == 0x1f)
730   {
731      switch (data)
732      {
733         case 0x00:
734            if(LOG_SMPC) printf ("SMPC: Master ON\n");
735            smpc_master_on(space->machine());
736            break;
737         //in theory 0x01 is for Master OFF
738         case 0x02:
739         case 0x03:
740            if(LOG_SMPC) printf ("SMPC: Slave %s\n",(data & 1) ? "off" : "on");
741            space->machine().scheduler().timer_set(attotime::from_usec(100), FUNC(smpc_slave_enable),data & 1);
742            break;
743         case 0x06:
744         case 0x07:
745            if(LOG_SMPC) printf ("SMPC: Sound %s\n",(data & 1) ? "off" : "on");
746            space->machine().scheduler().timer_set(attotime::from_usec(100), FUNC(smpc_sound_enable),data & 1);
747            break;
748         /*CD (SH-1) ON/OFF,guess that this is needed for Sports Fishing games...*/
749         //case 0x08:
750         //case 0x09:
751         case 0x0d:
752            if(LOG_SMPC) printf ("SMPC: System Reset\n");
753            smpc_system_reset(space->machine());
754            break;
755         case 0x0e:
756         case 0x0f:
757            if(LOG_SMPC) printf ("SMPC: Change Clock to %s\n",data & 1 ? "320" : "352");
758            smpc_change_clock(space->machine(),data & 1);
759            break;
760         /*"Interrupt Back"*/
761         case 0x10:
762                if(LOG_SMPC) printf ("SMPC: Status Acquire (IntBack)\n");
763            int timing;
764
765            timing = 100;
766
767            if(state->m_smpc_ram[1] != 0) // non-peripheral data
768               timing = 200;
769
770            if(state->m_smpc_ram[3] & 8) // peripheral data
771               timing = 15000;
772
773            if(LOG_PAD_CMD) printf("INTBACK %02x %02x\n",state->m_smpc_ram[1],state->m_smpc_ram[3]);
774
775            space->machine().scheduler().timer_set(attotime::from_usec(timing), FUNC(saturn_smpc_intback),0); //TODO: is variable time correct?
776            break;
777         /* RTC write*/
778         case 0x16:
779            if(LOG_SMPC) printf("SMPC: RTC write\n");
780            smpc_rtc_write(space->machine());
781            break;
782         /* SMPC memory setting*/
783         case 0x17:
784            if(LOG_SMPC) printf ("SMPC: memory setting\n");
785            smpc_memory_setting(space->machine());
786            break;
787         case 0x18:
788            if(LOG_SMPC) printf ("SMPC: NMI request\n");
789            smpc_nmi_req(space->machine());
790            break;
791         case 0x19:
792         case 0x1a:
793            if(LOG_SMPC) printf ("SMPC: NMI %sable\n",data & 1 ? "Dis" : "En");
794            smpc_nmi_set(space->machine(),data & 1);
795            break;
796         default:
797            printf ("cpu %s (PC=%08X) SMPC: undocumented Command %02x\n", space->device().tag(), cpu_get_pc(&space->device()), data);
798      }
799
800      // we've processed the command, clear status flag
801      if(data != 0x10 && data != 2 && data != 3 && data != 6 && data != 7)
802      {
803         state->m_smpc_ram[0x5f] = data; //read-back for last command issued
804         state->m_smpc_ram[0x63] = 0x00; //clear hand-shake flag
805      }
806      /*TODO:emulate the timing of each command...*/
807   }
808795}
src/mame/includes/stv.h
r12585r12586
88
99   UINT32    *m_workram_l;
1010   UINT32    *m_workram_h;
11   UINT8     *m_smpc_ram;
1211   UINT8     *m_backupram;
1312   UINT8     *m_cart_backupram;
1413   UINT32    *m_scu_regs;
r12585r12586
8483        UINT8 EXLE2;
8584        UINT8 PDR1;
8685        UINT8 PDR2;
86        UINT8 DDR1;
87        UINT8 DDR2;
88        UINT8 SF;
89        UINT8 SR;
90        UINT8 IREG[7];
91        UINT8 OREG[32];
8792        int   intback_stage;
88        int   smpcSR;
8993        int   pmode;
9094        UINT8 SMEM[4];
9195        UINT8 intback;
src/mame/drivers/saturn.c
r12585r12586
14161416   state->m_minit_boost_timeslice = attotime::zero;
14171417   state->m_sinit_boost_timeslice = attotime::zero;
14181418
1419   state->m_smpc_ram = auto_alloc_array(machine, UINT8, 0x80);
14201419   state->m_scu_regs = auto_alloc_array(machine, UINT32, 0x100/4);
14211420   state->m_scsp_regs  = auto_alloc_array(machine, UINT16, 0x1000/2);
14221421   state->m_backupram = auto_alloc_array(machine, UINT8, 0x10000);
r12585r12586
14351434   //machine.device("slave")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x60ffc44, 0x60ffc47, FUNC(w60ffc44_write) );
14361435   //machine.device("slave")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x60ffc48, 0x60ffc4b, FUNC(w60ffc48_write) );
14371436
1438    state->m_smpc_ram[0x31] = 0x00; //CTG1=0 CTG0=0 (correct??)
1439//  state->m_smpc_ram[0x33] = input_port_read(machine, "FAKE");
1440   state->m_smpc_ram[0x5f] = 0x10;
1441
14421437   state->m_vdp2.pal = 0;
14431438}
14441439
r12585r12586
15711566   static int year_num, year_count;
15721567
15731568   /*
1574        state->m_smpc_ram[0x23] = DectoBCD(systime.local_time.year /100);
1575        state->m_smpc_ram[0x25] = DectoBCD(systime.local_time.year %100);
1576        state->m_smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month+1);
1577        state->m_smpc_ram[0x29] = DectoBCD(systime.local_time.mday);
1578        state->m_smpc_ram[0x2b] = DectoBCD(systime.local_time.hour);
1579        state->m_smpc_ram[0x2d] = DectoBCD(systime.local_time.minute);
1580        state->m_smpc_ram[0x2f] = DectoBCD(systime.local_time.second);
1569        state->m_smpc.rtc_data[0] = DectoBCD(systime.local_time.year /100);
1570        state->m_smpc.rtc_data[1] = DectoBCD(systime.local_time.year %100);
1571        state->m_smpc.rtc_data[2] = (systime.local_time.weekday << 4) | (systime.local_time.month+1);
1572        state->m_smpc.rtc_data[3] = DectoBCD(systime.local_time.mday);
1573        state->m_smpc.rtc_data[4] = DectoBCD(systime.local_time.hour);
1574        state->m_smpc.rtc_data[5] = DectoBCD(systime.local_time.minute);
1575        state->m_smpc.rtc_data[6] = DectoBCD(systime.local_time.second);
15811576    */
15821577
15831578   state->m_smpc.rtc_data[6]++;
r12585r12586
16471642   scsp_set_ram_base(machine.device("scsp"), state->m_sound_ram);
16481643
16491644   // save states
1650   state_save_register_global_pointer(machine, state->m_smpc_ram, 0x80);
16511645   state_save_register_global_pointer(machine, state->m_scu_regs, 0x100/4);
16521646   state_save_register_global_pointer(machine, state->m_scsp_regs,  0x1000/2);
16531647   state_save_register_global(machine, state->m_NMI_reset);
r12585r12586
16921686   scsp_set_ram_base(machine.device("scsp"), state->m_sound_ram);
16931687
16941688   // save states
1695   state_save_register_global_pointer(machine, state->m_smpc_ram, 0x80);
16961689   state_save_register_global_pointer(machine, state->m_scu_regs, 0x100/4);
16971690   state_save_register_global_pointer(machine, state->m_scsp_regs,  0x1000/2);
16981691   state_save_register_global(machine, state->m_NMI_reset);
r12585r12586
17081701   state_save_register_global(machine, scsp_last_line);
17091702   state_save_register_global(machine, state->m_smpc.intback_stage);
17101703   state_save_register_global(machine, state->m_smpc.pmode);
1711   state_save_register_global(machine, state->m_smpc.smpcSR);
1704   state_save_register_global(machine, state->m_smpc.SR);
17121705   state_save_register_global_array(machine, state->m_smpc.SMEM);
17131706   state_save_register_global_pointer(machine, state->m_cart_dram, 0x400000/4);
17141707
r12585r12586
19311924   cputag_set_input_line(machine, "slave", INPUT_LINE_RESET, ASSERT_LINE);
19321925   cputag_set_input_line(machine, "audiocpu", INPUT_LINE_RESET, ASSERT_LINE);
19331926
1934   state->m_smpc.smpcSR = 0x40;   // this bit is always on according to docs
1927   state->m_smpc.SR = 0x40;   // this bit is always on according to docs
19351928
19361929   state->m_en_68k = 0;
19371930   state->m_NMI_reset = 1;
1938   state->m_smpc_ram[0x21] = (0x80) | ((state->m_NMI_reset & 1) << 6);
19391931
19401932   DMA_STATUS = 0;
19411933
r12585r12586
20152007
20162008   state->m_en_68k = 0;
20172009   state->m_NMI_reset = 1;
2018   state->m_smpc_ram[0x21] = (0x80) | ((state->m_NMI_reset & 1) << 6);
20192010
20202011   port_sel = mux_data = 0;
20212012   port_i = -1;
r12585r12586
22312222static void saturn_init_driver(running_machine &machine, int rgn)
22322223{
22332224   saturn_state *state = machine.driver_data<saturn_state>();
2234   system_time systime;
22352225
22362226   state->m_saturn_region = rgn;
22372227   state->m_vdp2.pal = (rgn == 12) ? 1 : 0;
r12585r12586
22402230   sh2drc_set_options(machine.device("maincpu"), SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
22412231   sh2drc_set_options(machine.device("slave"), SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
22422232
2243   /* get the current date/time from the core */
2244   machine.current_datetime(systime);
2245
22462233   /* amount of time to boost interleave for on MINIT / SINIT, needed for communication to work */
22472234   state->m_minit_boost = 400;
22482235   state->m_sinit_boost = 400;
22492236   state->m_minit_boost_timeslice = attotime::zero;
22502237   state->m_sinit_boost_timeslice = attotime::zero;
22512238
2252   state->m_smpc_ram = auto_alloc_array(machine, UINT8, 0x80);
22532239   state->m_scu_regs = auto_alloc_array(machine, UINT32, 0x100/4);
22542240   state->m_scsp_regs = auto_alloc_array(machine, UINT16, 0x1000/2);
22552241   state->m_cart_dram = auto_alloc_array(machine, UINT32, 0x400000/4);
22562242   state->m_backupram = auto_alloc_array(machine, UINT8, 0x10000);
22572243   state->m_cart_backupram = auto_alloc_array(machine, UINT8, 0x400000);
2258
2259   state->m_smpc_ram[0x23] = dec_2_bcd(systime.local_time.year / 100);
2260   state->m_smpc_ram[0x25] = dec_2_bcd(systime.local_time.year % 100);
2261   state->m_smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month + 1);
2262   state->m_smpc_ram[0x29] = dec_2_bcd(systime.local_time.mday);
2263   state->m_smpc_ram[0x2b] = dec_2_bcd(systime.local_time.hour);
2264   state->m_smpc_ram[0x2d] = dec_2_bcd(systime.local_time.minute);
2265   state->m_smpc_ram[0x2f] = dec_2_bcd(systime.local_time.second);
2266   state->m_smpc_ram[0x31] = 0x00; //CTG1=0 CTG0=0 (correct??)
2267//  state->m_smpc_ram[0x33] = input_port_read(machine, "???");
2268   state->m_smpc_ram[0x5f] = 0x10;
2269
2270
22712244}
22722245
22732246static DRIVER_INIT( saturnus )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team