2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: ReadBattClock() function.
9 #include <proto/exec.h>
10 #include <proto/utility.h>
11 #include <utility/date.h>
13 #include "battclock_intern.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
)
26 struct ClockData date
;
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
);