]> git.sur5r.net Git - c128-kasse/blob - src/c128time.c
7bba5b86fca01602f6bcf2e9e66d4b0f0e20756d
[c128-kasse] / src / c128time.c
1 /* 
2  * RGB2R-C128-Kassenprogramm
3  * © 2007-2009 phil_fry, sECuRE, sur5r
4  * See LICENSE for license information
5  *
6  */
7 #include <peekpoke.h>
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include "general.h"
11 #include <stdint.h>
12
13 char *get_time(void) {
14         uint32_t h = PEEK(0x00A0) * 65536,
15                 m = PEEK(0x00A1) * 256,
16                 s = PEEK(0x00A2);
17         static char buffer[9];
18         BYTE hrs, min;
19
20         h = (h + m + s) / 60;
21         hrs = (h / 3600);
22         h -= ((uint32_t)hrs * (uint32_t)3600);
23         min = (h / 60);
24         h -= (min * 60);
25         
26         sprintf(buffer, "%02d:%02d:%02d", hrs, min, (BYTE)h);
27         return buffer;
28 }
29
30 void set_time(BYTE hrs, BYTE min, BYTE sec) {
31         uint32_t added = ((uint32_t)sec + ((uint32_t)min * (uint32_t)60) + ((uint32_t)hrs * (uint32_t)3600)) * (uint32_t)60;
32         uint32_t lowbit = (added & 0xFF);
33         uint32_t middlebit = (added >> 8) & 0xFF;
34         uint32_t highbit = (added >> 16) & 0xFF;
35
36         POKE(0x00A0, (BYTE)highbit);
37         POKE(0x00A1, (BYTE)middlebit);
38         POKE(0x00A2, (BYTE)lowbit);
39 }