xref: /reactos/hal/halx86/pc98/clock.c (revision 1734f297)
1 /*
2  * PROJECT:     NEC PC-98 series HAL
3  * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE:     PIT rollover tables
5  * COPYRIGHT:   Copyright 2020 Dmitry Borisov (di.sean@protonmail.com)
6  */
7 
8 /* INCLUDES ******************************************************************/
9 
10 #include <hal.h>
11 
12 /* GLOBALS *******************************************************************/
13 
14 #define LPT_STATUS         0x42
15 #define SYSTEM_CLOCK_8_MHZ 0x20
16 
17 ULONG PIT_FREQUENCY;
18 HALP_ROLLOVER HalpRolloverTable[15];
19 
20 /* Accuracy is 97.5% */
21 static const HALP_ROLLOVER RolloverTable1[15] =
22 {
23     {1996, 9996}, /* 1 ms */
24     {3993, 19997},
25     {5990, 29998},
26     {7987, 39999},
27     {9984, 50000},
28     {11980, 59996},
29     {13977, 69997},
30     {15974, 79998},
31     {17971, 89999},
32     {19968, 100000},
33     {21964, 109996},
34     {23961, 119997},
35     {25958, 129998},
36     {27955, 139999},
37     {29951, 149995} /* 15 ms */
38 };
39 static const HALP_ROLLOVER RolloverTable2[15] =
40 {
41     {2463, 10022}, /* 1 ms */
42     {4912, 19987},
43     {7376, 30013},
44     {9825, 39978},
45     {12288, 50000},
46     {14751, 60022},
47     {17200, 69987},
48     {19664, 80013},
49     {22113, 89978},
50     {24576, 100000},
51     {27039, 110022},
52     {29488, 119987},
53     {31952, 130013},
54     {34401, 139978},
55     {36864, 150000} /* 15 ms */
56 };
57 
58 /* PRIVATE FUNCTIONS *********************************************************/
59 
60 VOID
61 NTAPI
62 HalpInitializeClockPc98(VOID)
63 {
64     /* Obtain system clock value from the parallel port */
65     if (__inbyte(LPT_STATUS) & SYSTEM_CLOCK_8_MHZ)
66     {
67         PIT_FREQUENCY = TIMER_FREQUENCY_1;
68         RtlCopyMemory(HalpRolloverTable, RolloverTable1, sizeof(HALP_ROLLOVER) * 15);
69     }
70     else
71     {
72         PIT_FREQUENCY = TIMER_FREQUENCY_2;
73         RtlCopyMemory(HalpRolloverTable, RolloverTable2, sizeof(HALP_ROLLOVER) * 15);
74     }
75 }
76