[NTVDM]
[reactos.git] / subsystems / ntvdm / hardware / timer.h
1 /*
2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
4 * FILE: timer.h
5 * PURPOSE: Programmable Interval Timer emulation -
6 * i82C54/8254 compatible
7 * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
8 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
9 */
10
11 #ifndef _TIMER_H_
12 #define _TIMER_H_
13
14 /* INCLUDES *******************************************************************/
15
16 #include "ntvdm.h"
17
18 /* DEFINES ********************************************************************/
19
20 #define PIT_CHANNELS 3
21 #define PIT_BASE_FREQUENCY 1193182LL
22 #define PIT_DATA_PORT(x) (0x40 + (x))
23 #define PIT_COMMAND_PORT 0x43
24
25 #define WRITE_PIT_VALUE(PitChannel, Value) \
26 (PitChannel).Bcd ? BCD_TO_BINARY(Value) : (Value)
27
28 #define READ_PIT_VALUE(PitChannel, Value) \
29 (PitChannel).Bcd ? BINARY_TO_BCD(Value) : (Value)
30
31 typedef enum _PIT_MODE
32 {
33 PIT_MODE_INT_ON_TERMINAL_COUNT,
34 PIT_MODE_HARDWARE_ONE_SHOT,
35 PIT_MODE_RATE_GENERATOR,
36 PIT_MODE_SQUARE_WAVE,
37 PIT_MODE_SOFTWARE_STROBE,
38 PIT_MODE_HARDWARE_STROBE
39 } PIT_MODE, *PPIT_MODE;
40
41 typedef struct _PIT_CHANNEL
42 {
43 BOOLEAN Pulsed;
44
45
46 /* PIT Status members */
47 PIT_MODE Mode;
48 BOOLEAN Bcd;
49 BYTE ReadWriteMode; // 0 --> Counter Latch ; 1 --> LSB R/W ; 2 --> MSB R/W ; 3 --> LSB then MSB R/W
50
51 /* Reading the PIT status byte */
52 BOOLEAN LatchStatusSet;
53 BYTE StatusLatch;
54
55 /* For interleaving reading and writing in 2-byte RW mode */
56 BYTE ReadStatus; // Same convention as ReadWriteMode
57 BYTE WriteStatus; // Same convention as ReadWriteMode
58
59 /**/WORD CountRegister;/**/ // Our ReloadValue ???
60 WORD OutputLatch;
61 /*******************************/
62
63 WORD ReloadValue; // Max value of the counter
64 WORD CurrentValue; // Real value of the counter
65
66 /* PIT Output */
67 BOOLEAN Out; // 0: Low ; 1: High
68
69 } PIT_CHANNEL, *PPIT_CHANNEL;
70
71 extern PPIT_CHANNEL PitChannel2; // Needed for PC Speaker
72
73 /* FUNCTIONS ******************************************************************/
74
75 VOID PitDecrementCount(DWORD Count);
76 DWORD PitGetResolution(VOID);
77
78 VOID PitInitialize(VOID);
79
80 #endif // _TIMER_H_
81
82 /* EOF */