Made bitmap view and path AppMessage targets. Picture files can now be
[AROS.git] / arch / all-pc / battclock / writebattclock.c
blobcc983e798404ce668327dd181be3301a2420f531
1 /*
2 Copyright © 2009-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: WriteBattClock()
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 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)
25 AROS_LIBFUNC_INIT
27 struct ClockData date;
28 UBYTE century;
29 UWORD status_b;
31 /* Convert time to the required format */
33 Amiga2Date(time, &date);
35 century = date.year / 100;
36 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);
64 AROS_LIBFUNC_EXIT