Previous 15994 Revisions Next

r8155 Monday 24th May, 2010 at 19:05:52 UTC by Angelo Salese
[X1]: Added proper RTC support
[src/mess/drivers]x1.c

src/mess/drivers/x1.c
r8154r8155
233233   UINT8 txt_disp;
234234}turbo_reg;
235235
236static struct
237{
238   UINT8 sec, min, hour, day, wday, month, year;
239}x1_rtc;
240
241static emu_timer *x1_rtc_timer;
242
236243static UINT8 pcg_write_addr;
237244
238245static DEVICE_START(x1_daisy){}
r8154r8155
750757
751758static WRITE8_HANDLER( sub_io_w )
752759{
753   mame_system_time systime;
754   mame_get_base_datetime(space->machine, &systime);
755760   /* TODO: check sub-routine at $10e */
756761   /* $17a -> floppy? */
757762   /* $094 -> ROM */
r8154r8155
812817         logerror("CMT: Command 0xEB received, returning 0x%02x.\n",sub_val[0]);
813818         break;
814819      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;
818823         sub_cmd_length = 3;
819824         break;
820825      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;
824829         sub_cmd_length = 3;
825830         break;
826831      #if 0
r8154r8155
20642069   }
20652070}
20662071
2072static 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
20672099static MACHINE_RESET( x1 )
20682100{
20692101   UINT8 *ROM = memory_region(machine, "maincpu");
r8154r8155
21042136      palette_set_color_rgb(machine, i+0x000, pal1bit(i >> 1), pal1bit(i >> 2), pal1bit(i >> 0));
21052137      palette_set_color_rgb(machine, i+0x100, pal1bit(i >> 1), pal1bit(i >> 2), pal1bit(i >> 0));
21062138   }
2139
2140   timer_adjust_periodic(x1_rtc_timer, attotime_zero, 0, ATTOTIME_IN_SEC(1));
21072141}
21082142
21092143static MACHINE_START( x1 )
21102144{
21112145   timer_pulse(machine, ATTOTIME_IN_HZ(240), NULL, 0, keyboard_callback);
21122146   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   }
21132163}
21142164
21152165static PALETTE_INIT(x1)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team