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

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.7 ! root       15: const char Rtc_fileid[] = "Hatari rtc.c : " __DATE__ " " __TIME__;
1.1       root       16: 
                     17: #include <time.h>
                     18: 
                     19: #include "main.h"
1.1.1.4   root       20: #include "ioMem.h"
1.1       root       21: #include "rtc.h"
                     22: 
                     23: 
1.1.1.5   root       24: static bool rtc_bank;           /* RTC bank select (0=normal, 1=configuration(?)) */
1.1       root       25: static Sint8 fake_am, fake_amz;
                     26: 
                     27: 
                     28: /*-----------------------------------------------------------------------*/
1.1.1.4   root       29: /**
                     30:  * Read seconds units.
                     31:  */
1.1       root       32: void Rtc_SecondsUnits_ReadByte(void)
                     33: {
1.1.1.4   root       34:        struct tm *SystemTime;
                     35:        time_t nTimeTicks;
1.1       root       36: 
1.1.1.4   root       37:        /* Get system time */
                     38:        nTimeTicks = time(NULL);
                     39:        SystemTime = localtime(&nTimeTicks);
                     40:        IoMem[0xfffc21] = SystemTime->tm_sec % 10;
1.1       root       41: }
                     42: 
                     43: 
                     44: /*-----------------------------------------------------------------------*/
1.1.1.4   root       45: /**
                     46:  * Read seconds tens.
                     47:  */
1.1       root       48: void Rtc_SecondsTens_ReadByte(void)
                     49: {
1.1.1.4   root       50:        struct tm *SystemTime;
                     51:        time_t nTimeTicks;
1.1       root       52: 
1.1.1.4   root       53:        /* Get system time */
                     54:        nTimeTicks = time(NULL);
                     55:        SystemTime = localtime(&nTimeTicks);
                     56:        IoMem[0xfffc23] = SystemTime->tm_sec / 10;
1.1       root       57: }
                     58: 
                     59: 
                     60: /*-----------------------------------------------------------------------*/
1.1.1.4   root       61: /**
                     62:  * Read minutes units.
                     63:  */
1.1       root       64: void Rtc_MinutesUnits_ReadByte(void)
                     65: {
1.1.1.4   root       66:        if (rtc_bank)
                     67:        {
                     68:                IoMem[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:                IoMem[0xfffc25] = SystemTime->tm_min % 10;
                     79:        }
1.1       root       80: }
                     81: 
                     82: 
                     83: /*-----------------------------------------------------------------------*/
1.1.1.4   root       84: /**
                     85:  * Write minutes units.
                     86:  */
1.1       root       87: void Rtc_MinutesUnits_WriteByte(void)
                     88: {
1.1.1.4   root       89:        /* TOS 1.0x uses this... */
                     90:        if (rtc_bank)
                     91:                fake_am = ((IoMem[0xfffc25] & 0x0f) | 0xf0);
                     92:        /* else ignore */
1.1       root       93: }
                     94: 
                     95: 
                     96: /*-----------------------------------------------------------------------*/
1.1.1.4   root       97: /**
                     98:  * Read minutes tens.
                     99:  */
1.1       root      100: void Rtc_MinutesTens_ReadByte(void)
                    101: {
1.1.1.4   root      102:        if (rtc_bank)
                    103:        {
                    104:                IoMem[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:                IoMem[0xfffc27] = SystemTime->tm_min / 10;
                    115:        }
1.1       root      116: }
                    117: 
                    118: 
                    119: /*-----------------------------------------------------------------------*/
1.1.1.4   root      120: /**
                    121:  * Write minutes tens.
                    122:  */
1.1       root      123: void Rtc_MinutesTens_WriteByte(void)
                    124: {
1.1.1.4   root      125:        /* TOS 1.0x uses this... */
                    126:        if (rtc_bank)
                    127:                fake_amz = ((IoMem[0xfffc27] & 0x0f) | 0xf0);
                    128:        /* else ignore */
1.1       root      129: }
                    130: 
                    131: 
                    132: /*-----------------------------------------------------------------------*/
1.1.1.4   root      133: /**
                    134:  * Read hours units.
                    135:  */
1.1       root      136: void Rtc_HoursUnits_ReadByte(void)
                    137: {
1.1.1.4   root      138:        struct tm *SystemTime;
                    139:        time_t nTimeTicks;
1.1       root      140: 
1.1.1.4   root      141:        /* Get system time */
                    142:        nTimeTicks = time(NULL);
                    143:        SystemTime = localtime(&nTimeTicks);
                    144:        IoMem[0xfffc29] = SystemTime->tm_hour % 10;
1.1       root      145: }
                    146: 
                    147: 
                    148: /*-----------------------------------------------------------------------*/
1.1.1.4   root      149: /**
                    150:  * Read hours tens.
                    151:  */
1.1       root      152: void Rtc_HoursTens_ReadByte(void)
                    153: {
1.1.1.4   root      154:        struct tm *SystemTime;
                    155:        time_t nTimeTicks;
1.1       root      156: 
1.1.1.4   root      157:        /* Get system time */
                    158:        nTimeTicks = time(NULL);
                    159:        SystemTime = localtime(&nTimeTicks);
                    160:        IoMem[0xfffc2b] = SystemTime->tm_hour / 10;
1.1       root      161: }
                    162: 
                    163: 
                    164: /*-----------------------------------------------------------------------*/
1.1.1.4   root      165: /**
                    166:  * Read weekday.
                    167:  */
1.1       root      168: void Rtc_Weekday_ReadByte(void)
                    169: {
1.1.1.4   root      170:        struct tm *SystemTime;
                    171:        time_t nTimeTicks;
1.1       root      172: 
1.1.1.4   root      173:        /* Get system time */
                    174:        nTimeTicks = time(NULL);
                    175:        SystemTime = localtime(&nTimeTicks);
                    176:        IoMem[0xfffc2d] = SystemTime->tm_wday;
1.1       root      177: }
                    178: 
                    179: 
                    180: /*-----------------------------------------------------------------------*/
1.1.1.4   root      181: /**
                    182:  * Read day units.
                    183:  */
1.1       root      184: void Rtc_DayUnits_ReadByte(void)
                    185: {
1.1.1.4   root      186:        struct tm *SystemTime;
                    187:        time_t nTimeTicks;
1.1       root      188: 
1.1.1.4   root      189:        /* Get system time */
                    190:        nTimeTicks = time(NULL);
                    191:        SystemTime = localtime(&nTimeTicks);
                    192:        IoMem[0xfffc2f] = SystemTime->tm_mday % 10;
1.1       root      193: }
                    194: 
                    195: 
                    196: /*-----------------------------------------------------------------------*/
1.1.1.4   root      197: /**
                    198:  * Read day tens.
                    199:  */
1.1       root      200: void Rtc_DayTens_ReadByte(void)
                    201: {
1.1.1.4   root      202:        struct tm *SystemTime;
                    203:        time_t nTimeTicks;
1.1       root      204: 
1.1.1.4   root      205:        /* Get system time */
                    206:        nTimeTicks = time(NULL);
                    207:        SystemTime = localtime(&nTimeTicks);
                    208:        IoMem[0xfffc31] = SystemTime->tm_mday / 10;
1.1       root      209: }
                    210: 
                    211: 
                    212: /*-----------------------------------------------------------------------*/
1.1.1.4   root      213: /**
                    214:  * Read month units.
                    215:  */
1.1       root      216: void Rtc_MonthUnits_ReadByte(void)
                    217: {
1.1.1.4   root      218:        struct tm *SystemTime;
                    219:        time_t nTimeTicks;
1.1       root      220: 
1.1.1.4   root      221:        /* Get system time */
                    222:        nTimeTicks = time(NULL);
                    223:        SystemTime = localtime(&nTimeTicks);
                    224:        IoMem[0xfffc33] = (SystemTime->tm_mon + 1) % 10;
1.1       root      225: }
                    226: 
                    227: 
                    228: /*-----------------------------------------------------------------------*/
1.1.1.4   root      229: /**
                    230:  * Read month tens.
                    231:  */
1.1       root      232: void Rtc_MonthTens_ReadByte(void)
                    233: {
1.1.1.4   root      234:        struct tm *SystemTime;
                    235:        time_t nTimeTicks;
1.1       root      236: 
1.1.1.4   root      237:        /* Get system time */
                    238:        nTimeTicks = time(NULL);
                    239:        SystemTime = localtime(&nTimeTicks);
                    240:        IoMem[0xfffc35] = (SystemTime->tm_mon + 1) / 10;
1.1       root      241: }
                    242: 
                    243: 
                    244: /*-----------------------------------------------------------------------*/
1.1.1.4   root      245: /**
                    246:  * Read year units.
                    247:  */
1.1       root      248: void Rtc_YearUnits_ReadByte(void)
                    249: {
1.1.1.4   root      250:        struct tm *SystemTime;
                    251:        time_t nTimeTicks;
1.1       root      252: 
1.1.1.4   root      253:        /* Get system time */
                    254:        nTimeTicks = time(NULL);
                    255:        SystemTime = localtime(&nTimeTicks);
                    256:        IoMem[0xfffc37] = SystemTime->tm_year % 10;
1.1       root      257: }
                    258: 
                    259: 
                    260: /*-----------------------------------------------------------------------*/
1.1.1.4   root      261: /**
                    262:  * Read year tens.
                    263:  */
1.1       root      264: void Rtc_YearTens_ReadByte(void)
                    265: {
1.1.1.4   root      266:        struct tm *SystemTime;
                    267:        time_t nTimeTicks;
1.1       root      268: 
1.1.1.4   root      269:        /* Get system time */
                    270:        nTimeTicks = time(NULL);
                    271:        SystemTime = localtime(&nTimeTicks);
                    272:        IoMem[0xfffc39] = (SystemTime->tm_year - 80) / 10;
1.1       root      273: }
                    274: 
                    275: 
                    276: /*-----------------------------------------------------------------------*/
1.1.1.4   root      277: /**
                    278:  * Read clock mod.
                    279:  */
1.1       root      280: void Rtc_ClockMod_ReadByte(void)
                    281: {
1.1.1.4   root      282:        IoMem[0xfffc3b] = ((IoMem[0xfffc3b] & 0x0f) | 0xf0);
1.1       root      283: }
                    284: 
                    285: 
                    286: /*-----------------------------------------------------------------------*/
1.1.1.4   root      287: /**
                    288:  * Write clock mod.
                    289:  */
1.1       root      290: void Rtc_ClockMod_WriteByte(void)
                    291: {
1.1.1.4   root      292:        rtc_bank = IoMem[0xfffc3b] & 1;
1.1       root      293: }
                    294: 

unix.superglobalmegacorp.com

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