2 Copyright © 2009-2011, The AROS Development Team. All rights reserved.
9 #include <proto/exec.h>
10 #include <proto/utility.h>
11 #include <utility/date.h>
13 #include "battclock_intern.h"
16 static inline UBYTE
MakeBCDByte(UBYTE n
)
18 return n
/ 10 << 4 | n
% 10;
21 AROS_LH1(void, WriteBattClock
,
22 AROS_LHA(ULONG
, time
, D0
),
23 struct BattClockBase
*, BattClockBase
, 3, Battclock
)
27 struct ClockData date
;
31 /* Convert time to the required format */
33 Amiga2Date(time
, &date
);
35 century
= date
.year
/ 100;
38 ObtainSemaphore(&BattClockBase
->sem
);
40 status_b
= ReadCMOSByte(STATUS_B
);
42 if ((status_b
& 0x04) == 0)
44 date
.sec
= MakeBCDByte(date
.sec
);
45 date
.min
= MakeBCDByte(date
.min
);
46 date
.hour
= MakeBCDByte(date
.hour
);
47 date
.mday
= MakeBCDByte(date
.mday
);
48 date
.month
= MakeBCDByte(date
.month
);
49 date
.year
= MakeBCDByte(date
.year
);
50 century
= MakeBCDByte(century
);
53 /* Write new time to the RTC */
54 WriteCMOSByte(SEC
, date
.sec
);
55 WriteCMOSByte(MIN
, date
.min
);
56 WriteCMOSByte(HOUR
, date
.hour
);
57 WriteCMOSByte(MDAY
, date
.mday
);
58 WriteCMOSByte(MONTH
, date
.month
);
59 WriteCMOSByte(YEAR
, date
.year
);
60 WriteCMOSByte(BattClockBase
->century
, century
);
62 ReleaseSemaphore(&BattClockBase
->sem
);