Previous 15994 Revisions Next

r12558 Wednesday 10th August, 2011 at 16:53:41 UTC by Angelo Salese
Added incremental RTC for Sega Saturn
[src/mame/drivers]saturn.c
[src/mame/includes]stv.h
[src/mame/machine]smpc.c

src/mame/machine/smpc.c
r12557r12558
268268static TIMER_CALLBACK( stv_smpc_intback )
269269{
270270   saturn_state *state = machine.driver_data<saturn_state>();
271   system_time systime;
272   machine.base_datetime(systime);
273271
274272   state->m_smpc_ram[0x21] = (0x80) | ((state->m_NMI_reset & 1) << 6);
275273
274   {
275      int i;
276
277      for(i=0;i<7;i++)
278         state->m_smpc_ram[0x23+i*2] = state->m_smpc.rtc_data[i];
279   }
280
276281   state->m_smpc_ram[0x31]=0x00;  //?
277282
278283   //state->m_smpc_ram[0x33]=input_port_read(space->machine(), "FAKE");
r12557r12558
364369static TIMER_CALLBACK( saturn_smpc_intback )
365370{
366371   saturn_state *state = machine.driver_data<saturn_state>();
367   system_time systime;
368   machine.base_datetime(systime);
369372
370373   if(state->m_smpc_ram[1] != 0)
371374   {
372375      {
373376         state->m_smpc_ram[0x21] = (0x80) | ((state->m_NMI_reset & 1) << 6);
374377
375         state->m_smpc_ram[0x23] = dec_2_bcd(systime.local_time.year / 100);
376            state->m_smpc_ram[0x25] = dec_2_bcd(systime.local_time.year % 100);
377         state->m_smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month + 1);
378            state->m_smpc_ram[0x29] = dec_2_bcd(systime.local_time.mday);
379            state->m_smpc_ram[0x2b] = dec_2_bcd(systime.local_time.hour);
380            state->m_smpc_ram[0x2d] = dec_2_bcd(systime.local_time.minute);
381            state->m_smpc_ram[0x2f] = dec_2_bcd(systime.local_time.second);
378         {
379            int i;
382380
381            for(i=0;i<7;i++)
382               state->m_smpc_ram[0x23+i*2] = state->m_smpc.rtc_data[i];
383         }
384
383385         state->m_smpc_ram[0x31]=0x00;  //?
384386
385387         //state->m_smpc_ram[0x33]=input_port_read(space->machine(), "FAKE");
r12557r12558
446448static void smpc_rtc_write(running_machine &machine)
447449{
448450   saturn_state *state = machine.driver_data<saturn_state>();
449   state->m_smpc_ram[0x2f] = state->m_smpc_ram[0x0d];
450   state->m_smpc_ram[0x2d] = state->m_smpc_ram[0x0b];
451   state->m_smpc_ram[0x2b] = state->m_smpc_ram[0x09];
452   state->m_smpc_ram[0x29] = state->m_smpc_ram[0x07];
453   state->m_smpc_ram[0x27] = state->m_smpc_ram[0x05];
454   state->m_smpc_ram[0x25] = state->m_smpc_ram[0x03];
455   state->m_smpc_ram[0x23] = state->m_smpc_ram[0x01];
451   int i;
452
453   for(i=0;i<7;i++)
454      state->m_smpc.rtc_data[i] = state->m_smpc_ram[0x01+i*2];
456455}
457456
458457static void smpc_memory_setting(running_machine &machine)
459458{
460459   saturn_state *state = machine.driver_data<saturn_state>();
461   state->m_smpc.SMEM[0] = state->m_smpc_ram[1];
462   state->m_smpc.SMEM[1] = state->m_smpc_ram[3];
463   state->m_smpc.SMEM[2] = state->m_smpc_ram[5];
464   state->m_smpc.SMEM[3] = state->m_smpc_ram[7];
460   int i;
461
462   for(i=0;i<4;i++)
463      state->m_smpc.SMEM[i] = state->m_smpc_ram[0x01+i*2];
465464}
466465
467466static void smpc_nmi_req(running_machine &machine)
src/mame/includes/stv.h
r12557r12558
8989        int   pmode;
9090        UINT8 SMEM[4];
9191        UINT8 intback;
92        UINT8 rtc_data[7];
9293   }m_smpc;
9394
9495   /* Saturn specific*/
src/mame/drivers/saturn.c
r12557r12558
15731573        state->m_smpc_ram[0x2f] = DectoBCD(systime.local_time.second);
15741574    */
15751575
1576   state->m_smpc_ram[0x2f]++;
1576   state->m_smpc.rtc_data[6]++;
15771577
15781578   /* seconds from 9 -> 10*/
1579   if((state->m_smpc_ram[0x2f] & 0x0f) >= 0x0a)         { state->m_smpc_ram[0x2f]+=0x10; state->m_smpc_ram[0x2f]&=0xf0; }
1579   if((state->m_smpc.rtc_data[6] & 0x0f) >= 0x0a)         { state->m_smpc.rtc_data[6]+=0x10; state->m_smpc.rtc_data[6]&=0xf0; }
15801580   /* seconds from 59 -> 0 */
1581   if((state->m_smpc_ram[0x2f] & 0xf0) >= 0x60)         { state->m_smpc_ram[0x2d]++;     state->m_smpc_ram[0x2f] = 0; }
1581   if((state->m_smpc.rtc_data[6] & 0xf0) >= 0x60)         { state->m_smpc.rtc_data[5]++;     state->m_smpc.rtc_data[6] = 0; }
15821582   /* minutes from 9 -> 10 */
1583   if((state->m_smpc_ram[0x2d] & 0x0f) >= 0x0a)         { state->m_smpc_ram[0x2d]+=0x10; state->m_smpc_ram[0x2d]&=0xf0; }
1583   if((state->m_smpc.rtc_data[5] & 0x0f) >= 0x0a)         { state->m_smpc.rtc_data[5]+=0x10; state->m_smpc.rtc_data[5]&=0xf0; }
15841584   /* minutes from 59 -> 0 */
1585   if((state->m_smpc_ram[0x2d] & 0xf0) >= 0x60)         { state->m_smpc_ram[0x2b]++;     state->m_smpc_ram[0x2d] = 0; }
1585   if((state->m_smpc.rtc_data[5] & 0xf0) >= 0x60)         { state->m_smpc.rtc_data[4]++;     state->m_smpc.rtc_data[5] = 0; }
15861586   /* hours from 9 -> 10 */
1587   if((state->m_smpc_ram[0x2b] & 0x0f) >= 0x0a)         { state->m_smpc_ram[0x2b]+=0x10; state->m_smpc_ram[0x2b]&=0xf0; }
1587   if((state->m_smpc.rtc_data[4] & 0x0f) >= 0x0a)         { state->m_smpc.rtc_data[4]+=0x10; state->m_smpc.rtc_data[4]&=0xf0; }
15881588   /* hours from 23 -> 0 */
1589   if((state->m_smpc_ram[0x2b] & 0xff) >= 0x24)            { state->m_smpc_ram[0x29]++; state->m_smpc_ram[0x27]+=0x10; state->m_smpc_ram[0x2b] = 0; }
1589   if((state->m_smpc.rtc_data[4] & 0xff) >= 0x24)            { state->m_smpc.rtc_data[3]++; state->m_smpc.rtc_data[2]+=0x10; state->m_smpc.rtc_data[4] = 0; }
15901590   /* week day name sunday -> monday */
1591   if((state->m_smpc_ram[0x27] & 0xf0) >= 0x70)            { state->m_smpc_ram[0x27]&=0x0f; }
1591   if((state->m_smpc.rtc_data[2] & 0xf0) >= 0x70)            { state->m_smpc.rtc_data[2]&=0x0f; }
15921592   /* day number 9 -> 10 */
1593   if((state->m_smpc_ram[0x29] & 0x0f) >= 0x0a)            { state->m_smpc_ram[0x29]+=0x10; state->m_smpc_ram[0x29]&=0xf0; }
1593   if((state->m_smpc.rtc_data[3] & 0x0f) >= 0x0a)            { state->m_smpc.rtc_data[3]+=0x10; state->m_smpc.rtc_data[3]&=0xf0; }
15941594
15951595   // year BCD to dec conversion (for the leap year stuff)
15961596   {
1597      year_num = (state->m_smpc_ram[0x25] & 0xf);
1597      year_num = (state->m_smpc.rtc_data[1] & 0xf);
15981598
1599      for(year_count = 0; year_count < (state->m_smpc_ram[0x25] & 0xf0); year_count += 0x10)
1599      for(year_count = 0; year_count < (state->m_smpc.rtc_data[1] & 0xf0); year_count += 0x10)
16001600         year_num += 0xa;
16011601
1602      year_num += (state->m_smpc_ram[0x23] & 0xf)*0x64;
1602      year_num += (state->m_smpc.rtc_data[0] & 0xf)*0x64;
16031603
1604      for(year_count = 0; year_count < (state->m_smpc_ram[0x23] & 0xf0); year_count += 0x10)
1604      for(year_count = 0; year_count < (state->m_smpc.rtc_data[0] & 0xf0); year_count += 0x10)
16051605         year_num += 0x3e8;
16061606   }
16071607
16081608   /* month +1 check */
16091609   /* the RTC have a range of 1980 - 2100, so we don't actually need to support the leap year special conditions */
1610   if(((year_num % 4) == 0) && (state->m_smpc_ram[0x27] & 0xf) == 2)
1610   if(((year_num % 4) == 0) && (state->m_smpc.rtc_data[2] & 0xf) == 2)
16111611   {
1612      if((state->m_smpc_ram[0x29] & 0xff) >= dpm[(state->m_smpc_ram[0x27] & 0xf)-1]+1+1)
1613         { state->m_smpc_ram[0x27]++; state->m_smpc_ram[0x29] = 0x01; }
1612      if((state->m_smpc.rtc_data[3] & 0xff) >= dpm[(state->m_smpc.rtc_data[2] & 0xf)-1]+1+1)
1613         { state->m_smpc.rtc_data[2]++; state->m_smpc.rtc_data[3] = 0x01; }
16141614   }
1615   else if((state->m_smpc_ram[0x29] & 0xff) >= dpm[(state->m_smpc_ram[0x27] & 0xf)-1]+1){ state->m_smpc_ram[0x27]++; state->m_smpc_ram[0x29] = 0x01; }
1615   else if((state->m_smpc.rtc_data[3] & 0xff) >= dpm[(state->m_smpc.rtc_data[2] & 0xf)-1]+1){ state->m_smpc.rtc_data[2]++; state->m_smpc.rtc_data[3] = 0x01; }
16161616   /* year +1 check */
1617   if((state->m_smpc_ram[0x27] & 0x0f) > 12)            { state->m_smpc_ram[0x25]++;  state->m_smpc_ram[0x27] = (state->m_smpc_ram[0x27] & 0xf0) | 0x01; }
1617   if((state->m_smpc.rtc_data[2] & 0x0f) > 12)            { state->m_smpc.rtc_data[1]++;  state->m_smpc.rtc_data[2] = (state->m_smpc.rtc_data[2] & 0xf0) | 0x01; }
16181618   /* year from 9 -> 10 */
1619   if((state->m_smpc_ram[0x25] & 0x0f) >= 0x0a)            { state->m_smpc_ram[0x25]+=0x10; state->m_smpc_ram[0x25]&=0xf0; }
1619   if((state->m_smpc.rtc_data[1] & 0x0f) >= 0x0a)            { state->m_smpc.rtc_data[1]+=0x10; state->m_smpc.rtc_data[1]&=0xf0; }
16201620   /* year from 99 -> 100 */
1621   if((state->m_smpc_ram[0x25] & 0xf0) >= 0xa0)            { state->m_smpc_ram[0x23]++; state->m_smpc_ram[0x25] = 0; }
1621   if((state->m_smpc.rtc_data[1] & 0xf0) >= 0xa0)            { state->m_smpc.rtc_data[0]++; state->m_smpc.rtc_data[1] = 0; }
16221622
16231623   // probably not SO precise, here just for reference ...
16241624   /* year from 999 -> 1000 */
1625   //if((state->m_smpc_ram[0x23] & 0x0f) >= 0x0a)               { state->m_smpc_ram[0x23]+=0x10; state->m_smpc_ram[0x23]&=0xf0; }
1625   //if((state->m_smpc.rtc_data[0] & 0x0f) >= 0x0a)               { state->m_smpc.rtc_data[0]+=0x10; state->m_smpc.rtc_data[0]&=0xf0; }
16261626   /* year from 9999 -> 0 */
1627   //if((state->m_smpc_ram[0x23] & 0xf0) >= 0xa0)               { state->m_smpc_ram[0x23] = 0; } //roll over
1627   //if((state->m_smpc.rtc_data[0] & 0xf0) >= 0xa0)               { state->m_smpc.rtc_data[0] = 0; } //roll over
16281628}
16291629
16301630static MACHINE_START( stv )
r12557r12558
16601660
16611661   machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(stvcd_exit), &machine));
16621662
1663   state->m_smpc_ram[0x23] = DectoBCD(systime.local_time.year /100);
1664    state->m_smpc_ram[0x25] = DectoBCD(systime.local_time.year %100);
1665    state->m_smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month+1);
1666    state->m_smpc_ram[0x29] = DectoBCD(systime.local_time.mday);
1667    state->m_smpc_ram[0x2b] = DectoBCD(systime.local_time.hour);
1668    state->m_smpc_ram[0x2d] = DectoBCD(systime.local_time.minute);
1669    state->m_smpc_ram[0x2f] = DectoBCD(systime.local_time.second);
1663   state->m_smpc.rtc_data[0] = DectoBCD(systime.local_time.year /100);
1664    state->m_smpc.rtc_data[1] = DectoBCD(systime.local_time.year %100);
1665    state->m_smpc.rtc_data[2] = (systime.local_time.weekday << 4) | (systime.local_time.month+1);
1666    state->m_smpc.rtc_data[3] = DectoBCD(systime.local_time.mday);
1667    state->m_smpc.rtc_data[4] = DectoBCD(systime.local_time.hour);
1668    state->m_smpc.rtc_data[5] = DectoBCD(systime.local_time.minute);
1669    state->m_smpc.rtc_data[6] = DectoBCD(systime.local_time.second);
16701670
16711671   state->m_stv_rtc_timer = machine.scheduler().timer_alloc(FUNC(stv_rtc_increment));
16721672}
r12557r12558
16751675static MACHINE_START( saturn )
16761676{
16771677   saturn_state *state = machine.driver_data<saturn_state>();
1678   system_time systime;
1679   machine.base_datetime(systime);
16781680
16791681   state->m_maincpu = downcast<legacy_cpu_device*>( machine.device("maincpu") );
16801682   state->m_slave = downcast<legacy_cpu_device*>( machine.device("slave") );
r12557r12558
17041706   state_save_register_global_pointer(machine, state->m_cart_dram, 0x400000/4);
17051707
17061708   machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(stvcd_exit), &machine));
1709
1710   state->m_smpc.rtc_data[0] = DectoBCD(systime.local_time.year /100);
1711    state->m_smpc.rtc_data[1] = DectoBCD(systime.local_time.year %100);
1712    state->m_smpc.rtc_data[2] = (systime.local_time.weekday << 4) | (systime.local_time.month+1);
1713    state->m_smpc.rtc_data[3] = DectoBCD(systime.local_time.mday);
1714    state->m_smpc.rtc_data[4] = DectoBCD(systime.local_time.hour);
1715    state->m_smpc.rtc_data[5] = DectoBCD(systime.local_time.minute);
1716    state->m_smpc.rtc_data[6] = DectoBCD(systime.local_time.second);
1717
1718   state->m_stv_rtc_timer = machine.scheduler().timer_alloc(FUNC(stv_rtc_increment));
17071719}
17081720
17091721
r12557r12558
19641976
19651977   state->m_vdp2.old_crmd = -1;
19661978   state->m_vdp2.old_tvmd = -1;
1979
1980   state->m_stv_rtc_timer->adjust(attotime::zero, 0, attotime::from_seconds(1));
19671981}
19681982
19691983

Previous 15994 Revisions Next


© 1998-2018 The MESS Team