-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhwclock.c
89 lines (82 loc) · 3.74 KB
/
hwclock.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*****************************************************************************/
/* */
/* hwclock.c */
/* */
/* Hardware Clock of C64/C128 and CBM510/CBM610 */
/* */
/* */
/* */
/* (C) Copyright 2009, Stefan Haubenthal <[email protected]> */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* warranty. In no event will the authors be held liable for any damages */
/* arising from the use of this software. */
/* */
/* Permission is granted to anyone to use this software for any purpose, */
/* including commercial applications, and to alter it and redistribute it */
/* freely, subject to the following restrictions: */
/* */
/* 1. The origin of this software must not be misrepresented; you must not */
/* claim that you wrote the original software. If you use this software */
/* in a product, an acknowledgment in the product documentation would be */
/* appreciated but is not required. */
/* 2. Altered source versions must be plainly marked as such, and must not */
/* be misrepresented as being the original software. */
/* 3. This notice may not be removed or altered from any source */
/* distribution. */
/* */
/*****************************************************************************/
#include <stdio.h>
#include <cbm.h>
#if defined(__CBM510__) || defined(__CBM610__)
# define outb(addr,val) pokebsys ((unsigned)(addr), val)
# define outw(addr,val) pokewsys ((unsigned)(addr), val)
# define inb(addr) peekbsys ((unsigned)(addr))
# define inw(addr) peekwsys ((unsigned)(addr))
#else
# define outb(addr,val) (*(unsigned char*) (addr) = (val))
# define outw(addr,val) (*(unsigned*) (addr) = (val))
# define inb(addr) (*(unsigned char*) (addr))
# define inw(addr) (*(unsigned*) (addr))
#endif
#ifndef CIA1
#define CIA1 CIA
#endif
unsigned char atobcd(unsigned char x)
{
return x/10<<4 | x%10;
}
unsigned char addbcd(unsigned char x)
{
return x+(x==8 || x==9 ? 0x18 : 0x12);
}
unsigned char hour, min, sec;
int main (int argc, char *argv[])
{
#if !defined(__CBM610__)
if (argc==2)
if (sscanf(argv[1], "%d:%02d:%02d", &hour, &min, &sec)==3)
#else
printf("hh:mm:ss? ");
if (scanf("%d:%02d:%02d", &hour, &min, &sec)==3)
#endif
{
#if !defined(__CBM510__)
if (get_tv()==TV_PAL)
outb(&CIA1.cra, inb(&CIA1.cra) | 0x80);
#endif
outb(&CIA1.tod_hour, hour>11 ? atobcd(hour-12) | 0x80 : atobcd(hour));
outb(&CIA1.tod_min, atobcd(min));
outb(&CIA1.tod_sec, atobcd(sec));
outb(&CIA1.tod_10, 0);
}
#if !defined(__CBM610__)
else
printf("Usage: %s [hh:mm:ss]\n", argv[0]);
#else
printf("\n");
#endif
printf("%x:%02x:%02x.%d\n", inb(&CIA1.tod_hour)&0x80 ? addbcd(inb(&CIA1.tod_hour)&~0x80) :
inb(&CIA1.tod_hour), inb(&CIA1.tod_min), inb(&CIA1.tod_sec), inb(&CIA1.tod_10));
}