Annotation of hatari/src/rtc.c, revision 1.1.1.3

1.1       root        1: /*
                      2:   Hatari - rtc.c
                      3: 
                      4:   This file is distributed under the GNU Public License, version 2 or at
                      5:   your option any later version. Read the file gpl.txt for details.
                      6: 
                      7:   Mega-ST real time clock.
                      8:   There is probably a more efficient way to do it, such as using directly a
                      9:   timer in ram instead of calling localtime for each function. For now it will
                     10:   show that it works, at least...
                     11: 
                     12:   In fact these mappings seems to force the gem to ask the IKBD for the real
                     13:   time (seconds units). See ikbd.c for the time returned by the IKBD.
                     14: */
1.1.1.3 ! root       15: const char Rtc_rcsid[] = "Hatari $Id: rtc.c,v 1.5 2006/02/08 22:49:27 eerot Exp $";
1.1       root       16: 
                     17: #include <time.h>
                     18: 
                     19: #include "main.h"
1.1.1.2   root       20: #include "stMemory.h"
1.1       root       21: #include "rtc.h"
                     22: 
                     23: 
                     24: static BOOL rtc_bank;           /* RTC bank select (0=normal, 1=configuration(?)) */
                     25: static Sint8 fake_am, fake_amz;
                     26: 
                     27: 
                     28: /*-----------------------------------------------------------------------*/
                     29: /*
                     30:   Read seconds units.
                     31: */
                     32: void Rtc_SecondsUnits_ReadByte(void)
                     33: {
                     34:   struct tm *SystemTime;
                     35:   time_t nTimeTicks;
                     36: 
                     37:   /* Get system time */
                     38:   nTimeTicks = time(NULL);
                     39:   SystemTime = localtime(&nTimeTicks);
                     40:   STRam[0xfffc21] = SystemTime->tm_sec % 10;
                     41: }
                     42: 
                     43: 
                     44: /*-----------------------------------------------------------------------*/
                     45: /*
                     46:   Read seconds tens.
                     47: */
                     48: void Rtc_SecondsTens_ReadByte(void)
                     49: {
                     50:   struct tm *SystemTime;
                     51:   time_t nTimeTicks;
                     52: 
                     53:   /* Get system time */
                     54:   nTimeTicks = time(NULL);
                     55:   SystemTime = localtime(&nTimeTicks);
                     56:   STRam[0xfffc23] = SystemTime->tm_sec / 10;
                     57: }
                     58: 
                     59: 
                     60: /*-----------------------------------------------------------------------*/
                     61: /*
                     62:   Read minutes units.
                     63: */
                     64: void Rtc_MinutesUnits_ReadByte(void)
                     65: {
                     66:   if(rtc_bank)
                     67:   {
                     68:     STRam[0xfffc25] = fake_am;
                     69:   }
                     70:   else
                     71:   {
                     72:     struct tm *SystemTime;
                     73:     time_t nTimeTicks;
                     74: 
                     75:     /* Get system time */
                     76:     nTimeTicks = time(NULL);
                     77:     SystemTime = localtime(&nTimeTicks);
                     78:     STRam[0xfffc25] = SystemTime->tm_min % 10;
                     79:   }
                     80: }
                     81: 
                     82: 
                     83: /*-----------------------------------------------------------------------*/
                     84: /*
                     85:   Write minutes units.
                     86: */
                     87: void Rtc_MinutesUnits_WriteByte(void)
                     88: {
                     89:   /* TOS 1.0x uses this... */
                     90:   if(rtc_bank)
                     91:     fake_am = ((STRam[0xfffc25] & 0x0f) | 0xf0);
                     92:   /* else ignore */
                     93: }
                     94: 
                     95: 
                     96: /*-----------------------------------------------------------------------*/
                     97: /*
                     98:   Read minutes tens.
                     99: */
                    100: void Rtc_MinutesTens_ReadByte(void)
                    101: {
                    102:   if(rtc_bank)
                    103:   {
                    104:     STRam[0xfffc27] = fake_amz;
                    105:   }
                    106:   else
                    107:   {
                    108:     struct tm *SystemTime;
                    109:     time_t nTimeTicks;
                    110: 
                    111:     /* Get system time */
                    112:     nTimeTicks = time(NULL);
                    113:     SystemTime = localtime(&nTimeTicks);
                    114:     STRam[0xfffc27] = SystemTime->tm_min / 10;
                    115:   }
                    116: }
                    117: 
                    118: 
                    119: /*-----------------------------------------------------------------------*/
                    120: /*
                    121:   Write minutes tens.
                    122: */
                    123: void Rtc_MinutesTens_WriteByte(void)
                    124: {
                    125:   /* TOS 1.0x uses this... */
                    126:   if(rtc_bank)
                    127:     fake_amz = ((STRam[0xfffc27] & 0x0f) | 0xf0);
                    128:   /* else ignore */
                    129: }
                    130: 
                    131: 
                    132: /*-----------------------------------------------------------------------*/
                    133: /*
                    134:   Read hours units.
                    135: */
                    136: void Rtc_HoursUnits_ReadByte(void)
                    137: {
                    138:   struct tm *SystemTime;
                    139:   time_t nTimeTicks;
                    140: 
                    141:   /* Get system time */
                    142:   nTimeTicks = time(NULL);
                    143:   SystemTime = localtime(&nTimeTicks);
                    144:   STRam[0xfffc29] = SystemTime->tm_hour % 10;
                    145: }
                    146: 
                    147: 
                    148: /*-----------------------------------------------------------------------*/
                    149: /*
                    150:   Read hours tens.
                    151: */
                    152: void Rtc_HoursTens_ReadByte(void)
                    153: {
                    154:   struct tm *SystemTime;
                    155:   time_t nTimeTicks;
                    156: 
                    157:   /* Get system time */
                    158:   nTimeTicks = time(NULL);
                    159:   SystemTime = localtime(&nTimeTicks);
                    160:   STRam[0xfffc2b] = SystemTime->tm_hour / 10;
                    161: }
                    162: 
                    163: 
                    164: /*-----------------------------------------------------------------------*/
                    165: /*
                    166:   Read weekday.
                    167: */
                    168: void Rtc_Weekday_ReadByte(void)
                    169: {
                    170:   struct tm *SystemTime;
                    171:   time_t nTimeTicks;
                    172: 
                    173:   /* Get system time */
                    174:   nTimeTicks = time(NULL);
                    175:   SystemTime = localtime(&nTimeTicks);
                    176:   STRam[0xfffc2d] = SystemTime->tm_wday;
                    177: }
                    178: 
                    179: 
                    180: /*-----------------------------------------------------------------------*/
                    181: /*
                    182:   Read day units.
                    183: */
                    184: void Rtc_DayUnits_ReadByte(void)
                    185: {
                    186:   struct tm *SystemTime;
                    187:   time_t nTimeTicks;
                    188: 
                    189:   /* Get system time */
                    190:   nTimeTicks = time(NULL);
                    191:   SystemTime = localtime(&nTimeTicks);
                    192:   STRam[0xfffc2f] = SystemTime->tm_mday % 10;
                    193: }
                    194: 
                    195: 
                    196: /*-----------------------------------------------------------------------*/
                    197: /*
                    198:   Read day tens.
                    199: */
                    200: void Rtc_DayTens_ReadByte(void)
                    201: {
                    202:   struct tm *SystemTime;
                    203:   time_t nTimeTicks;
                    204: 
                    205:   /* Get system time */
                    206:   nTimeTicks = time(NULL);
                    207:   SystemTime = localtime(&nTimeTicks);
                    208:   STRam[0xfffc31] = SystemTime->tm_mday / 10;
                    209: }
                    210: 
                    211: 
                    212: /*-----------------------------------------------------------------------*/
                    213: /*
                    214:   Read month units.
                    215: */
                    216: void Rtc_MonthUnits_ReadByte(void)
                    217: {
                    218:   struct tm *SystemTime;
                    219:   time_t nTimeTicks;
                    220: 
                    221:   /* Get system time */
                    222:   nTimeTicks = time(NULL);
                    223:   SystemTime = localtime(&nTimeTicks);
                    224:   STRam[0xfffc33] = (SystemTime->tm_mon + 1) % 10;
                    225: }
                    226: 
                    227: 
                    228: /*-----------------------------------------------------------------------*/
                    229: /*
                    230:   Read month tens.
                    231: */
                    232: void Rtc_MonthTens_ReadByte(void)
                    233: {
                    234:   struct tm *SystemTime;
                    235:   time_t nTimeTicks;
                    236: 
                    237:   /* Get system time */
                    238:   nTimeTicks = time(NULL);
                    239:   SystemTime = localtime(&nTimeTicks);
                    240:   STRam[0xfffc35] = (SystemTime->tm_mon + 1) / 10;
                    241: }
                    242: 
                    243: 
                    244: /*-----------------------------------------------------------------------*/
                    245: /*
                    246:   Read year units.
                    247: */
                    248: void Rtc_YearUnits_ReadByte(void)
                    249: {
                    250:   struct tm *SystemTime;
                    251:   time_t nTimeTicks;
                    252: 
                    253:   /* Get system time */
                    254:   nTimeTicks = time(NULL);
                    255:   SystemTime = localtime(&nTimeTicks);
                    256:   STRam[0xfffc37] = SystemTime->tm_year % 10;
                    257: }
                    258: 
                    259: 
                    260: /*-----------------------------------------------------------------------*/
                    261: /*
                    262:   Read year tens.
                    263: */
                    264: void Rtc_YearTens_ReadByte(void)
                    265: {
                    266:   struct tm *SystemTime;
                    267:   time_t nTimeTicks;
                    268: 
                    269:   /* Get system time */
                    270:   nTimeTicks = time(NULL);
                    271:   SystemTime = localtime(&nTimeTicks);
                    272:   STRam[0xfffc39] = (SystemTime->tm_year - 80) / 10;
                    273: }
                    274: 
                    275: 
                    276: /*-----------------------------------------------------------------------*/
                    277: /*
                    278:   Read clock mod.
                    279: */
                    280: void Rtc_ClockMod_ReadByte(void)
                    281: {
                    282:   STRam[0xfffc3b] = ((STRam[0xfffc3b] & 0x0f) | 0xf0);
                    283: }
                    284: 
                    285: 
                    286: /*-----------------------------------------------------------------------*/
                    287: /*
                    288:   Write clock mod.
                    289: */
                    290: void Rtc_ClockMod_WriteByte(void)
                    291: {
                    292:   rtc_bank = STRam[0xfffc3b] & 1;
                    293: }
                    294: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.