]> 4ch.mooo.com Git - 16.git/blob - src/lib/doslib/hw/rtc/rtc.c
added a bunch of things~ and midi stuff~
[16.git] / src / lib / doslib / hw / rtc / rtc.c
1
2 #include <stdio.h>
3 #include <conio.h> /* this is where Open Watcom hides the outp() etc. functions */
4 #include <stdlib.h>
5 #include <stddef.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include <malloc.h>
9 #include <ctype.h>
10 #include <fcntl.h>
11 #include <dos.h>
12
13 #include <hw/rtc/rtc.h>
14 #include <hw/dos/dos.h>
15 #include <hw/8254/8254.h>               /* 8254 timer */
16 #include <hw/8259/8259.h>               /* 8259 PIC */
17
18 int probe_rtc() {
19         unsigned char idx,match=0;
20
21         _cli();
22         for (idx=0;idx < 10;idx += 2) {
23                 if (rtc_io_read(idx) != 0xFF) match++;
24         }
25         rtc_io_read(0xC);
26         rtc_io_read_unmasked(0xD);
27         _sti();
28         return (match >= 4);
29 }
30
31 int rtc_wait_for_update_complete() {
32         int r=0,v;
33         
34         do {
35                 v=rtc_io_read(0xA);
36                 if (v & 0x80) r = 1; /* caller also needs to know if update in progress was seen */
37         } while (v & 0x80);
38
39         return r; /* return whether or not the update cycle was seen */
40 }
41