src/mame/machine/smpc.c
| r12557 | r12558 | |
| 268 | 268 | static TIMER_CALLBACK( stv_smpc_intback ) |
| 269 | 269 | { |
| 270 | 270 | saturn_state *state = machine.driver_data<saturn_state>(); |
| 271 | | system_time systime; |
| 272 | | machine.base_datetime(systime); |
| 273 | 271 | |
| 274 | 272 | state->m_smpc_ram[0x21] = (0x80) | ((state->m_NMI_reset & 1) << 6); |
| 275 | 273 | |
| 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 | |
| 276 | 281 | state->m_smpc_ram[0x31]=0x00; //? |
| 277 | 282 | |
| 278 | 283 | //state->m_smpc_ram[0x33]=input_port_read(space->machine(), "FAKE"); |
| r12557 | r12558 | |
| 364 | 369 | static TIMER_CALLBACK( saturn_smpc_intback ) |
| 365 | 370 | { |
| 366 | 371 | saturn_state *state = machine.driver_data<saturn_state>(); |
| 367 | | system_time systime; |
| 368 | | machine.base_datetime(systime); |
| 369 | 372 | |
| 370 | 373 | if(state->m_smpc_ram[1] != 0) |
| 371 | 374 | { |
| 372 | 375 | { |
| 373 | 376 | state->m_smpc_ram[0x21] = (0x80) | ((state->m_NMI_reset & 1) << 6); |
| 374 | 377 | |
| 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; |
| 382 | 380 | |
| 381 | for(i=0;i<7;i++) |
| 382 | state->m_smpc_ram[0x23+i*2] = state->m_smpc.rtc_data[i]; |
| 383 | } |
| 384 | |
| 383 | 385 | state->m_smpc_ram[0x31]=0x00; //? |
| 384 | 386 | |
| 385 | 387 | //state->m_smpc_ram[0x33]=input_port_read(space->machine(), "FAKE"); |
| r12557 | r12558 | |
| 446 | 448 | static void smpc_rtc_write(running_machine &machine) |
| 447 | 449 | { |
| 448 | 450 | 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]; |
| 456 | 455 | } |
| 457 | 456 | |
| 458 | 457 | static void smpc_memory_setting(running_machine &machine) |
| 459 | 458 | { |
| 460 | 459 | 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]; |
| 465 | 464 | } |
| 466 | 465 | |
| 467 | 466 | static void smpc_nmi_req(running_machine &machine) |
src/mame/drivers/saturn.c
| r12557 | r12558 | |
| 1573 | 1573 | state->m_smpc_ram[0x2f] = DectoBCD(systime.local_time.second); |
| 1574 | 1574 | */ |
| 1575 | 1575 | |
| 1576 | | state->m_smpc_ram[0x2f]++; |
| 1576 | state->m_smpc.rtc_data[6]++; |
| 1577 | 1577 | |
| 1578 | 1578 | /* 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; } |
| 1580 | 1580 | /* 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; } |
| 1582 | 1582 | /* 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; } |
| 1584 | 1584 | /* 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; } |
| 1586 | 1586 | /* 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; } |
| 1588 | 1588 | /* 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; } |
| 1590 | 1590 | /* 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; } |
| 1592 | 1592 | /* 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; } |
| 1594 | 1594 | |
| 1595 | 1595 | // year BCD to dec conversion (for the leap year stuff) |
| 1596 | 1596 | { |
| 1597 | | year_num = (state->m_smpc_ram[0x25] & 0xf); |
| 1597 | year_num = (state->m_smpc.rtc_data[1] & 0xf); |
| 1598 | 1598 | |
| 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) |
| 1600 | 1600 | year_num += 0xa; |
| 1601 | 1601 | |
| 1602 | | year_num += (state->m_smpc_ram[0x23] & 0xf)*0x64; |
| 1602 | year_num += (state->m_smpc.rtc_data[0] & 0xf)*0x64; |
| 1603 | 1603 | |
| 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) |
| 1605 | 1605 | year_num += 0x3e8; |
| 1606 | 1606 | } |
| 1607 | 1607 | |
| 1608 | 1608 | /* month +1 check */ |
| 1609 | 1609 | /* 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) |
| 1611 | 1611 | { |
| 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; } |
| 1614 | 1614 | } |
| 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; } |
| 1616 | 1616 | /* 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; } |
| 1618 | 1618 | /* 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; } |
| 1620 | 1620 | /* 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; } |
| 1622 | 1622 | |
| 1623 | 1623 | // probably not SO precise, here just for reference ... |
| 1624 | 1624 | /* 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; } |
| 1626 | 1626 | /* 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 |
| 1628 | 1628 | } |
| 1629 | 1629 | |
| 1630 | 1630 | static MACHINE_START( stv ) |
| r12557 | r12558 | |
| 1660 | 1660 | |
| 1661 | 1661 | machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(stvcd_exit), &machine)); |
| 1662 | 1662 | |
| 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); |
| 1670 | 1670 | |
| 1671 | 1671 | state->m_stv_rtc_timer = machine.scheduler().timer_alloc(FUNC(stv_rtc_increment)); |
| 1672 | 1672 | } |
| r12557 | r12558 | |
| 1675 | 1675 | static MACHINE_START( saturn ) |
| 1676 | 1676 | { |
| 1677 | 1677 | saturn_state *state = machine.driver_data<saturn_state>(); |
| 1678 | system_time systime; |
| 1679 | machine.base_datetime(systime); |
| 1678 | 1680 | |
| 1679 | 1681 | state->m_maincpu = downcast<legacy_cpu_device*>( machine.device("maincpu") ); |
| 1680 | 1682 | state->m_slave = downcast<legacy_cpu_device*>( machine.device("slave") ); |
| r12557 | r12558 | |
| 1704 | 1706 | state_save_register_global_pointer(machine, state->m_cart_dram, 0x400000/4); |
| 1705 | 1707 | |
| 1706 | 1708 | 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)); |
| 1707 | 1719 | } |
| 1708 | 1720 | |
| 1709 | 1721 | |
| r12557 | r12558 | |
| 1964 | 1976 | |
| 1965 | 1977 | state->m_vdp2.old_crmd = -1; |
| 1966 | 1978 | state->m_vdp2.old_tvmd = -1; |
| 1979 | |
| 1980 | state->m_stv_rtc_timer->adjust(attotime::zero, 0, attotime::from_seconds(1)); |
| 1967 | 1981 | } |
| 1968 | 1982 | |
| 1969 | 1983 | |