src/mess/drivers/x1.c
| r8154 | r8155 | |
| 233 | 233 | UINT8 txt_disp; |
| 234 | 234 | }turbo_reg; |
| 235 | 235 | |
| 236 | static struct |
| 237 | { |
| 238 | UINT8 sec, min, hour, day, wday, month, year; |
| 239 | }x1_rtc; |
| 240 | |
| 241 | static emu_timer *x1_rtc_timer; |
| 242 | |
| 236 | 243 | static UINT8 pcg_write_addr; |
| 237 | 244 | |
| 238 | 245 | static DEVICE_START(x1_daisy){} |
| r8154 | r8155 | |
| 750 | 757 | |
| 751 | 758 | static WRITE8_HANDLER( sub_io_w ) |
| 752 | 759 | { |
| 753 | | mame_system_time systime; |
| 754 | | mame_get_base_datetime(space->machine, &systime); |
| 755 | 760 | /* TODO: check sub-routine at $10e */ |
| 756 | 761 | /* $17a -> floppy? */ |
| 757 | 762 | /* $094 -> ROM */ |
| r8154 | r8155 | |
| 812 | 817 | logerror("CMT: Command 0xEB received, returning 0x%02x.\n",sub_val[0]); |
| 813 | 818 | break; |
| 814 | 819 | case 0xed: //get date |
| 815 | | sub_val[0] = ((systime.local_time.mday / 10)<<4) | ((systime.local_time.mday % 10) & 0xf); |
| 816 | | sub_val[1] = ((systime.local_time.month+1)<<4) | ((systime.local_time.weekday % 10) & 0xf); |
| 817 | | sub_val[2] = (((systime.local_time.year % 100)/10)<<4) | ((systime.local_time.year % 10) & 0xf); |
| 820 | sub_val[0] = x1_rtc.day; |
| 821 | sub_val[1] = (x1_rtc.month<<4) | (x1_rtc.wday & 0xf); |
| 822 | sub_val[2] = x1_rtc.year; |
| 818 | 823 | sub_cmd_length = 3; |
| 819 | 824 | break; |
| 820 | 825 | case 0xef: //get time |
| 821 | | sub_val[0] = ((systime.local_time.hour / 10)<<4) | ((systime.local_time.hour % 10) & 0xf); |
| 822 | | sub_val[1] = ((systime.local_time.minute / 10)<<4) | ((systime.local_time.minute % 10) & 0xf); |
| 823 | | sub_val[2] = ((systime.local_time.second / 10)<<4) | ((systime.local_time.second % 10) & 0xf); |
| 826 | sub_val[0] = x1_rtc.hour; |
| 827 | sub_val[1] = x1_rtc.min; |
| 828 | sub_val[2] = x1_rtc.sec; |
| 824 | 829 | sub_cmd_length = 3; |
| 825 | 830 | break; |
| 826 | 831 | #if 0 |
| r8154 | r8155 | |
| 2064 | 2069 | } |
| 2065 | 2070 | } |
| 2066 | 2071 | |
| 2072 | static TIMER_CALLBACK(x1_rtc_increment) |
| 2073 | { |
| 2074 | static const UINT8 dpm[12] = { 0x31, 0x28, 0x31, 0x30, 0x31, 0x30, 0x31, 0x31, 0x30, 0x31, 0x30, 0x31 }; |
| 2075 | |
| 2076 | x1_rtc.sec++; |
| 2077 | |
| 2078 | if((x1_rtc.sec & 0x0f) >= 0x0a) { x1_rtc.sec+=0x10; x1_rtc.sec&=0xf0; } |
| 2079 | if((x1_rtc.sec & 0xf0) >= 0x60) { x1_rtc.min++; x1_rtc.sec = 0; } |
| 2080 | if((x1_rtc.min & 0x0f) >= 0x0a) { x1_rtc.min+=0x10; x1_rtc.min&=0xf0; } |
| 2081 | if((x1_rtc.min & 0xf0) >= 0x60) { x1_rtc.hour++; x1_rtc.min = 0; } |
| 2082 | if((x1_rtc.hour & 0x0f) >= 0x0a) { x1_rtc.hour+=0x10; x1_rtc.hour&=0xf0; } |
| 2083 | if((x1_rtc.hour & 0xff) >= 0x24) { x1_rtc.day++; x1_rtc.wday++; x1_rtc.hour = 0; } |
| 2084 | if((x1_rtc.wday & 0x0f) >= 0x07) { x1_rtc.wday = 0; } |
| 2085 | if((x1_rtc.day & 0x0f) >= 0x0a) { x1_rtc.day+=0x10; x1_rtc.day&=0xf0; } |
| 2086 | /* FIXME: very crude leap year support (i.e. it treats the RTC to be with a 2000-2099 timeline), dunno how the real x1 supports this, |
| 2087 | maybe it just have a 1980-1999 timeline since year 0x00 shows as a XX on display */ |
| 2088 | if(((x1_rtc.year % 4) == 0) && x1_rtc.month == 2) |
| 2089 | { |
| 2090 | if((x1_rtc.day & 0xff) >= dpm[x1_rtc.month-1]+1+1) |
| 2091 | { x1_rtc.month++; x1_rtc.day = 0x01; } |
| 2092 | } |
| 2093 | else if((x1_rtc.day & 0xff) >= dpm[x1_rtc.month-1]+1){ x1_rtc.month++; x1_rtc.day = 0x01; } |
| 2094 | if(x1_rtc.month > 12) { x1_rtc.year++; x1_rtc.month = 0x01; } |
| 2095 | if((x1_rtc.year & 0x0f) >= 0x0a) { x1_rtc.year+=0x10; x1_rtc.year&=0xf0; } |
| 2096 | if((x1_rtc.year & 0xf0) >= 0xa0) { x1_rtc.year = 0; } //roll over |
| 2097 | } |
| 2098 | |
| 2067 | 2099 | static MACHINE_RESET( x1 ) |
| 2068 | 2100 | { |
| 2069 | 2101 | UINT8 *ROM = memory_region(machine, "maincpu"); |
| r8154 | r8155 | |
| 2104 | 2136 | palette_set_color_rgb(machine, i+0x000, pal1bit(i >> 1), pal1bit(i >> 2), pal1bit(i >> 0)); |
| 2105 | 2137 | palette_set_color_rgb(machine, i+0x100, pal1bit(i >> 1), pal1bit(i >> 2), pal1bit(i >> 0)); |
| 2106 | 2138 | } |
| 2139 | |
| 2140 | timer_adjust_periodic(x1_rtc_timer, attotime_zero, 0, ATTOTIME_IN_SEC(1)); |
| 2107 | 2141 | } |
| 2108 | 2142 | |
| 2109 | 2143 | static MACHINE_START( x1 ) |
| 2110 | 2144 | { |
| 2111 | 2145 | timer_pulse(machine, ATTOTIME_IN_HZ(240), NULL, 0, keyboard_callback); |
| 2112 | 2146 | timer_pulse(machine, ATTOTIME_IN_HZ(16), NULL, 0, cmt_wind_timer); |
| 2147 | |
| 2148 | /* set up RTC */ |
| 2149 | { |
| 2150 | mame_system_time systime; |
| 2151 | mame_get_base_datetime(machine, &systime); |
| 2152 | |
| 2153 | x1_rtc.day = ((systime.local_time.mday / 10)<<4) | ((systime.local_time.mday % 10) & 0xf); |
| 2154 | x1_rtc.month = ((systime.local_time.month+1)); |
| 2155 | x1_rtc.wday = ((systime.local_time.weekday % 10) & 0xf); |
| 2156 | x1_rtc.year = (((systime.local_time.year % 100)/10)<<4) | ((systime.local_time.year % 10) & 0xf); |
| 2157 | x1_rtc.hour = ((systime.local_time.hour / 10)<<4) | ((systime.local_time.hour % 10) & 0xf); |
| 2158 | x1_rtc.min = ((systime.local_time.minute / 10)<<4) | ((systime.local_time.minute % 10) & 0xf); |
| 2159 | x1_rtc.sec = ((systime.local_time.second / 10)<<4) | ((systime.local_time.second % 10) & 0xf); |
| 2160 | |
| 2161 | x1_rtc_timer = timer_alloc(machine, x1_rtc_increment, 0); |
| 2162 | } |
| 2113 | 2163 | } |
| 2114 | 2164 | |
| 2115 | 2165 | static PALETTE_INIT(x1) |