437420d750b8cba1b3ed60c2132808032a25834d
[AROS.git] / arch / m68k-amiga / battclock / readbattclock.c
blob437420d750b8cba1b3ed60c2132808032a25834d
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
4 Desc: ReadBattClock() function.
5 Lang: english
6 */
7 #define DEBUG 0
9 #include <aros/debug.h>
10 #include <aros/libcall.h>
11 #include <aros/symbolsets.h>
13 #include <utility/date.h>
14 #include <proto/utility.h>
16 #include "battclock_intern.h"
18 /*****************************************************************************
20 NAME */
21 #include <proto/battclock.h>
23 AROS_LH0(ULONG, ReadBattClock,
25 /* SYNOPSIS */
26 /* void */
28 /* LOCATION */
29 struct BattClockBase*, BattClockBase, 2, Battclock)
31 /* FUNCTION
32 Return the value stored in the battery back up clock. This value
33 is the number of seconds that have elapsed since midnight on the
34 1st of January 1978 (00:00:00 1.1.1978).
36 If the value of the battery clock is invalid, then the clock will
37 be reset.
39 INPUTS
41 RESULT
42 The number of seconds since 1.1.1978 00:00:00
44 NOTES
46 EXAMPLE
48 BUGS
50 SEE ALSO
51 WriteBattClock(), ResetBattClock()
53 INTERNALS
55 HISTORY
57 *****************************************************************************/
59 AROS_LIBFUNC_INIT
61 volatile UBYTE *p = BattClockBase->clockptr;
62 struct UtilityBase *UtilityBase = BattClockBase->UtilityBase;
63 struct ClockData cd;
64 UBYTE reg;
65 ULONG t;
67 D(bug("ReadBattClock\n"));
68 if (!p)
69 return 0;
70 reg = 0;
71 cd.sec = getbcd(p, reg);
72 cd.min = getbcd(p, reg + 2);
73 cd.hour = getbcd(p, reg + 4);
74 if (BattClockBase->clocktype == MSM6242B)
75 reg = 6;
76 else
77 reg = 7;
78 cd.mday = getbcd(p, reg);
79 cd.month = getbcd(p, reg + 2);
80 cd.year = getbcd(p, reg + 4) + 1900;
81 if (cd.year < 1978)
82 cd.year += 100;
83 cd.wday = 0;
84 t = Date2Amiga(&cd);
85 D(bug("%02d:%02d %02d.%02d.%d = %d\n", cd.hour, cd.min, cd.mday, cd.month, cd.year, t));
86 return t;
88 AROS_LIBFUNC_EXIT
90 } /* ReadBattClock */