-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ztimer.h
88 lines (82 loc) · 1.55 KB
/
ztimer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Porting of The precision Zen timer by Michael Abrash
*
* See Michael Abrash's Graphics Programming Black Book, Chapter 3
*/
extern uint32_t ztimercount; // if > 2^16-1 then overflow happened (time elapsed > 53ms)
extern uint16_t ztimerref;
double zTimeToUs();
#define DELAY "db 0xeb,0,0xeb,0,0xeb,0" // 3 x jmp $+2
extern void ZTimerOn();
#pragma aux ZTimerOn = \
"sti" \
"mov al, 0x34" \
"out 0x43, al" \
DELAY \
"mov al, 0" \
"out 0x40, al" \
DELAY \
"out 0x40, al" \
DELAY \
DELAY \
DELAY \
"cli" \
"mov al, 0x34" \
"out 0x43, al" \
DELAY \
"mov al, 0" \
"out 0x40, al" \
DELAY \
"out 0x40, al" \
modify [ax]
extern void ZTimerOff();
#pragma aux ZTimerOff = \
"xor eax, eax" \
"out 0x43, al" \
"mov al, 0xA " \
"out 0x20, al" \
DELAY \
"in al, 0x20" \
"and al, 1" \
"shl eax, 16" \
\
"sti" \
"in al, 0x40" \
DELAY \
"mov ah, al" \
"in al, 0x40" \
"xchg ah, al" \
"neg ax" \
"mov ztimercount, eax" \
\
"mov bx, 0" \
"mov cx, 16" \
"cli" \
"RefLoop:" \
\
"mov al, 0x34" \
"out 0x43, al" \
DELAY \
"mov al, 0" \
"out 0x40, al" \
DELAY \
"out 0x40, al" \
\
"mov al, 0" \
"out 0x43, al" \
DELAY \
"in al, 0x40" \
DELAY \
"mov ah, al" \
"in al, 0x40" \
"xchg ah, al" \
"neg ax" \
\
"add bx, ax" \
"loop RefLoop" \
\
"sti" \
"add bx, 8" \
"shr bx, 4" \
"mov ztimerref, bx" \
modify [eax bx cx]