use the override options if specified
[AROS.git] / arch / all-pc / battclock / readbattclock.c
blob48b9668ef97e84d76b0eaadfaf369705f4fd0b56
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: ReadBattClock() function.
6 Lang: english
7 */
9 #include <proto/exec.h>
10 #include <proto/utility.h>
11 #include <utility/date.h>
13 #include "battclock_intern.h"
14 #include "cmos.h"
16 static inline int bcd_to_dec(int x)
18 return ( (x >> 4) * 10 + (x & 0x0f) );
21 AROS_LH0(ULONG, ReadBattClock,
22 struct BattClockBase *, BattClockBase, 2, Battclock)
24 AROS_LIBFUNC_INIT
26 struct ClockData date;
27 UWORD century;
28 UWORD status_b;
29 ULONG secs;
31 ObtainSemaphore(&BattClockBase->sem);
33 /* Make sure time isn't currently being updated */
34 while ((ReadCMOSByte(STATUS_A) & 0x80) != 0);
36 date.sec = ReadCMOSByte(SEC);
37 date.min = ReadCMOSByte(MIN);
38 date.hour = ReadCMOSByte(HOUR);
39 date.mday = ReadCMOSByte(MDAY);
40 date.month = ReadCMOSByte(MONTH);
41 date.year = ReadCMOSByte(YEAR);
42 century = ReadCMOSByte(BattClockBase->century);
43 status_b = ReadCMOSByte(STATUS_B);
45 ReleaseSemaphore(&BattClockBase->sem);
47 if ((status_b & 0x04) == 0)
49 date.sec = bcd_to_dec(date.sec);
50 date.min = bcd_to_dec(date.min);
51 date.hour = bcd_to_dec(date.hour);
52 date.mday = bcd_to_dec(date.mday);
53 date.month = bcd_to_dec(date.month);
54 date.year = bcd_to_dec(date.year);
55 century = bcd_to_dec(century);
58 date.year = century * 100 + date.year;
60 secs=Date2Amiga(&date);
62 return secs;
64 AROS_LIBFUNC_EXIT
65 } /* ReadBattClock */