source: xtideuniversalbios/trunk/Assembly_Library/Inc/SystemTimer.inc@ 361

Last change on this file since 361 was 287, checked in by aitotat@…, 13 years ago

Changes to Assembly Library:

  • Hopefully fixed a problem of wrong sized MDA cursor.
  • Some minor improvements.
File size: 4.9 KB
Line 
1; Project name : Assembly Library
2; Description : System Timer (8254) relates equates and macros.
3%ifndef SYSTEMTIMER_INC
4%define SYSTEMTIMER_INC
5
6; Timer/Counter to program
7TIMER_0 EQU (0<<6)
8TIMER_1 EQU (1<<6)
9TIMER_2 EQU (2<<6)
10
11; Counter commands
12LATCH EQU (0<<4) ; Counter Latch Command (latches the count for reading)
13READ_OR_WRITE_LSB_ONLY EQU (1<<4) ; MSB is always zero
14READ_OR_WRITE_MSB_ONLY EQU (2<<4) ; LSB is always zero
15READ_OR_WRITE_LSB_THEN_MSB EQU (3<<4)
16
17; Timer modes
18MODE_0_SINGLE_TIMEOUT EQU (0<<1) ; Interrupt on Terminal Count
19MODE_1_ONE_SHOT EQU (1<<1) ; Hardware Retriggerable One-Shot
20MODE_2_RATE_GENERATOR EQU (2<<1)
21MODE_3_SQUARE_WAVE_MODE EQU (3<<1)
22MODE_4_SOFTWARE_TRIGGERED_STROBE EQU (4<<1)
23MODE_5_HARDWARE_RETRIGGERABLE_STROBE EQU (5<<1)
24
25; Binary / BCD Mode
26BINARY_COUNTER EQU 0
27BCD_COUNTER EQU 1
28
29
30; Ports
31COUNT_REGISTER_0 EQU 40h ; Timer 0 Count Register (System Timer Ticks)
32COUNT_REGISTER_1 EQU 41h ; Timer 1 Count Register (DRAM Refresh)
33COUNT_REGISTER_2 EQU 42h ; Timer 2 Count Register (General Use)
34CONTROL_WORD_REGISTER_out EQU 43h
35
36; Timer 2 is connected to PC Speaker that can be controller from port 61h.
37SPEAKER_CONTROL_REGISTER EQU 61h
38FLG_TIMER_2_OUTPUT_in EQU (1<<5) ; AT+ only
39FLG_SPEAKER_DATA_ENABLED EQU (1<<1)
40FLG_SPEAKER_GATE_TIMER_2_ON EQU (1<<0)
41
42
43; The duration of one tick
44TIMER_CYCLE_TIME EQU 838 ; nanosecs
45
46
47
48
49;--------------------------------------------------------------------
50; OUTPUT_COUNTER_COMMAND_TO
51; Parameters:
52; %1: TIMER_0, TIMER_1 or TIMER_2
53; %2: Command to counter
54; %3: Timer mode
55; %4: BINARY_COUNTER or BCD_COUNTER
56; Returns:
57; Nothing
58; Corrupts registers:
59; AL
60;--------------------------------------------------------------------
61%macro OUTPUT_COUNTER_COMMAND_TO 4
62 mov al, %1 | %2 | %3 | %4
63 out CONTROL_WORD_REGISTER_out, al
64%endmacro
65
66
67;--------------------------------------------------------------------
68; WRITE_COUNT_FROM_AL_TO
69; WRITE_COUNT_FROM_AX_TO
70; Parameters:
71; %1: TIMER_0, TIMER_1 or TIMER_2
72; AX: Count to write to timer
73; Returns:
74; Nothing
75; Corrupts registers:
76; AL (WRITE_COUNT_FROM_AX_TO only)
77;--------------------------------------------------------------------
78%macro WRITE_COUNT_FROM_AL_TO 1
79 %ifidni %1, TIMER_0
80 out COUNT_REGISTER_0, al
81 %elifidni %1, TIMER_1
82 out COUNT_REGISTER_1, al
83 %elifidni %1, TIMER_2
84 out COUNT_REGISTER_2, al
85 %else
86 %error "Invalid timer name passed to WRITE_COUNT_FROM_AL_TO"
87 %endif
88%endmacro
89
90%macro WRITE_COUNT_FROM_AX_TO 1
91 %ifidni %1, TIMER_0
92 out COUNT_REGISTER_0, al
93 mov al, ah
94 out COUNT_REGISTER_0, al
95 %elifidni %1, TIMER_1
96 out COUNT_REGISTER_1, al
97 mov al, ah
98 out COUNT_REGISTER_1, al
99 %elifidni %1, TIMER_2
100 out COUNT_REGISTER_2, al
101 mov al, ah
102 out COUNT_REGISTER_2, al
103 %else
104 %error "Invalid timer name passed to WRITE_COUNT_FROM_AX_TO"
105 %endif
106%endmacro
107
108
109;--------------------------------------------------------------------
110; READ_COUNT_TO_AL_FROM
111; READ_COUNT_TO_AX_FROM
112; Parameters:
113; %1: TIMER_0, TIMER_1 or TIMER_2
114; Returns:
115; AL/AX: Counter value
116; Corrupts registers:
117; Nothing
118;--------------------------------------------------------------------
119%macro READ_COUNT_TO_AL_FROM 1
120 %ifidni %1, TIMER_0
121 in al, COUNT_REGISTER_0
122 %elifidni %1, TIMER_1
123 in al, COUNT_REGISTER_1
124 %elifidni %1, TIMER_2
125 in al, COUNT_REGISTER_2
126 %else
127 %error "Invalid timer name passed to READ_COUNT_TO_AL_FROM"
128 %endif
129%endmacro
130
131%macro READ_COUNT_TO_AX_FROM 1
132 %ifidni %1, TIMER_0
133 in al, COUNT_REGISTER_0
134 mov ah, al
135 in al, COUNT_REGISTER_0
136 %elifidni %1, TIMER_1
137 in al, COUNT_REGISTER_1
138 mov ah, al
139 in al, COUNT_REGISTER_1
140 %elifidni %1, TIMER_2
141 in al, COUNT_REGISTER_2
142 mov ah, al
143 in al, COUNT_REGISTER_2
144 %else
145 %error "Invalid timer name passed to READ_COUNT_TO_AX_FROM"
146 %endif
147 xchg al, ah
148%endmacro
149
150
151;--------------------------------------------------------------------
152; START_PRECISE_EVENT_TIMER
153; Parameters:
154; Nothing
155; Returns:
156; Nothing
157; Corrupts registers:
158; AL
159;--------------------------------------------------------------------
160%macro START_PRECISE_EVENT_TIMER 0
161 in al, SPEAKER_CONTROL_REGISTER
162 or al, FLG_SPEAKER_GATE_TIMER_2_ON
163 out SPEAKER_CONTROL_REGISTER, al
164%endmacro
165
166
167;--------------------------------------------------------------------
168; STOP_PRECISE_EVENT_TIMER
169; Parameters:
170; Nothing
171; Returns:
172; Nothing
173; Corrupts registers:
174; AL
175;--------------------------------------------------------------------
176%macro STOP_PRECISE_EVENT_TIMER 0
177 in al, SPEAKER_CONTROL_REGISTER
178 and al, ~(FLG_SPEAKER_DATA_ENABLED | FLG_SPEAKER_GATE_TIMER_2_ON)
179 out SPEAKER_CONTROL_REGISTER, al
180%endmacro
181
182
183%endif ; SYSTEMTIMER_INC
Note: See TracBrowser for help on using the repository browser.