Made bitmap view and path AppMessage targets. Picture files can now be
[AROS.git] / arch / m68k-amiga / battclock / battclock_init.c
blob58fcce7de9b0afb78c9c9ccf059e318cd71d1f4f
2 #define DEBUG 0
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;
19 BYTE rounds = 2;
21 Disable();
22 for (;;) {
23 UWORD adkcon = c->adkconr;
24 c->adkcon = 0x7fff;
25 if (c->adkconr == cm->adkconr) {
26 c->adkcon = 0x8001;
27 if (c->adkconr == cm->adkconr) {
28 c->adkcon = 0x0001;
29 if (c->adkconr == cm->adkconr)
30 found = FALSE;
33 c->adkcon = 0x7fff;
34 c->adkcon = 0x8000 | adkcon;
35 if (!found) {
36 D(bug("custom chipset detected in clock space\n"));
37 break;
39 // ok, not custom, check if we have a clock
40 found = FALSE;
41 // 10 minutes or hours bit 3 set = not a clock
42 if ((getreg(p, 0x01) & 0x8) || (getreg(p, 0x03) & 8))
43 break;
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) {
49 // RF, maybe
50 BattClockBase->clocktype = RF5C01A;
51 BattClockBase->clockptr = p;
52 found = TRUE;
53 break;
54 } else if (getreg(p, 0x0f) == 0x4) {
55 // MSM
56 BattClockBase->clocktype = MSM6242B;
57 BattClockBase->clockptr = p;
58 found = TRUE;
59 break;
60 } else {
61 // reset clock
62 putreg(p, 0xe, 0);
63 putreg(p, 0xd, 0);
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
70 // RF
71 putreg(p, 0xf, 3); // reset
72 putreg(p, 0xf, 0); // reset off
73 putreg(p, 0xd, 8); // timer en
75 didreset = TRUE;
77 if (didreset)
78 resetbattclock(BattClockBase);
80 break;
82 Enable();
83 if (found)
84 BattClockBase->UtilityBase = (struct UtilityBase*)OpenLibrary("utility.library", 0);
85 D(bug("BattClockBase init=%d clock=%d\n", found, BattClockBase->clocktype));
86 return found;
89 ADD2INITLIB(BattClock_Init, 0)