4 #include <aros/debug.h>
5 #include <aros/libcall.h>
6 #include <aros/symbolsets.h>
8 #include <hardware/custom.h>
9 #include <proto/exec.h>
11 #include "battclock_intern.h"
13 static int BattClock_Init(struct BattClockBase
*BattClockBase
)
15 volatile UBYTE
*p
= (volatile UBYTE
*)0xdc0000;
16 volatile struct Custom
*cm
= (volatile struct Custom
*)0xdc0000;
17 volatile struct Custom
*c
= (volatile struct Custom
*)0xdff000;
18 BOOL found
= TRUE
, didreset
= FALSE
;
23 UWORD adkcon
= c
->adkconr
;
25 if (c
->adkconr
== cm
->adkconr
) {
27 if (c
->adkconr
== cm
->adkconr
) {
29 if (c
->adkconr
== cm
->adkconr
)
34 c
->adkcon
= 0x8000 | adkcon
;
36 D(bug("custom chipset detected in clock space\n"));
39 // ok, not custom, check if we have a clock
41 // 10 minutes or hours bit 3 set = not a clock
42 if ((getreg(p
, 0x01) & 0x8) || (getreg(p
, 0x03) & 8))
44 // this is not easy, most UAE versions emulate clock
45 // registers very badly (read-only registers are read-write etc..)
46 // so this needs to be quite stupid.
47 while (rounds
-- > 0) {
48 if (getreg(p
, 0x0d) == 0x8 && getreg(p
, 0x0f) == 0x0) {
50 BattClockBase
->clocktype
= RF5C01A
;
51 BattClockBase
->clockptr
= p
;
54 } else if (getreg(p
, 0x0f) == 0x4) {
56 BattClockBase
->clocktype
= MSM6242B
;
57 BattClockBase
->clockptr
= p
;
64 putreg(p
, 0xd, 4); // set irq flag
65 if (getreg(p
, 0xd) == 0) {
66 // was MSM, irq can't be set
67 putreg(p
, 0xf, 7); // reset
68 putreg(p
, 0xf, 4); // leave 24h on
69 } else { // was alarm en
71 putreg(p
, 0xf, 3); // reset
72 putreg(p
, 0xf, 0); // reset off
73 putreg(p
, 0xd, 8); // timer en
78 resetbattclock(BattClockBase
);
84 BattClockBase
->UtilityBase
= (struct UtilityBase
*)OpenLibrary("utility.library", 0);
85 D(bug("BattClockBase init=%d clock=%d\n", found
, BattClockBase
->clocktype
));
89 ADD2INITLIB(BattClock_Init
, 0)