-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathVSYN_CNT.ASM
More file actions
212 lines (171 loc) · 4.32 KB
/
VSYN_CNT.ASM
File metadata and controls
212 lines (171 loc) · 4.32 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
;******************************************************************************
; VSYNC counter
;******************************************************************************
;
;[TAB=8]
;------------------------------------------------------------------------------
%ifdef TOWNS
%define VSYNC_MACHINE 'FM TOWNS'
%define VSYNC_INT_NUM 04Bh
%define ESC_CURSOL_ON '[0v$'
%define ESC_CURSOL_OFF '[1v$'
%endif
%ifdef PC98
%define VSYNC_MACHINE 'PC-98'
%define VSYNC_INT_NUM 0Ah
%define ESC_CURSOL_ON '[>5l'
%define ESC_CURSOL_OFF '[>5h'
%endif
;------------------------------------------------------------------------------
%macro PRINT 1
mov edx,%1
mov ah,09h
int 21h
%endmacro
;------------------------------------------------------------------------------
segment text align=4 class=CODE use32
;------------------------------------------------------------------------------
..start:
PRINT warning
mov ah,08h ;push any key
int 21h
PRINT msg
PRINT cursor_OFF
; save dos vector
mov ax, 2503h
mov cl, VSYNC_INT_NUM
int 21h
mov [dos_vec], ebx
; set int vector
push ds
mov ax, cs
mov ds, ax
mov edx,counter_handler ; ds:edx
mov ax, 2506h
mov cl, VSYNC_INT_NUM
int 21h
pop ds
mov [ds_selector], ds
call start_vsync
xor ebp, ebp ; loop counter
align 4
count_loop:
mov eax, [count]
mov edi, count_num
mov ecx, 8
call decimal_string
sti
inc ebp
mov eax, ebp
mov edi, loop_num
mov ecx, 8
call decimal_string
PRINT counter_msg
mov ah,06h ; check key input
mov dl,0ffh ;
int 21h
test al,al
jz count_loop
end:
call stop_vsync
; restore dos vector
mov ax, 2505h
mov cl, VSYNC_INT_NUM
mov ebx, [dos_vec]
int 21h
PRINT cursor_ON
mov ah,4ch
xor al,al
int 21h
align 4
;------------------------------------------------------------------------------
; counter handler for FM TOWNS
;------------------------------------------------------------------------------
%ifdef TOWNS
counter_handler:
push edx
push eax
mov dx,5cah ;VSYNC-割り込み要因クリアレジスタ
out dx,al ;クリアレジスタに適当な値を出力
mov al,20h ;bit-5 = 1(EOI bit)
out 10h,al ;スレーブ側へ
out 6ch,al ;PIC アクセス、1μ秒ウェイトレジスタへ書き込み
cmc ; ウエイトレジスタがない場合
cmc ; この3命令でウエイトとする
out 00h,al ;bit-5 = 1(EOI bit)
call counter_main
pop eax
pop edx
iret
%endif
;------------------------------------------------------------------------------
; counter handler for PC-98
;------------------------------------------------------------------------------
%ifdef PC98
counter_handler:
push eax
out 64h,al ;クリアレジスタに適当な値を出力
mov al,20h
out 00h,al ;bit-5 = 1(EOI bit)
call counter_main
pop eax
iret
%endif
;------------------------------------------------------------------------------
; counter main
;------------------------------------------------------------------------------
align 4
counter_main:
push ds
mov ds, cs:[ds_selector]
inc dword [count]
pop ds
ret
;------------------------------------------------------------------------------
; VSYNC
;------------------------------------------------------------------------------
align 4
start_vsync:
in al,12h
and al,11110111b
out 12h,al
ret
align 4
stop_vsync:
in al,12h
or al,00001000b
out 12h,al
ret
;------------------------------------------------------------------------------
; decimal string
;------------------------------------------------------------------------------
align 4
decimal_string:
push ebx
push edx
mov ebx, 10
align 4
.loop:
xor edx, edx
div ebx ; edx:eax / 10 = eax, remainder: edx
add dl, '0'
mov [edi+ecx-1], dl
loop .loop
pop edx
pop ebx
ret
;------------------------------------------------------------------------------
segment data align=4 class=DATA use32
;------------------------------------------------------------------------------
warning db 'This binary for ',VSYNC_MACHINE,'.',13,10
db 'push any key for continue.',13,10,'$'
msg db 13,10,'push any key for stop.',13,10,'$'
cursor_ON db 27,ESC_CURSOL_ON
cursor_OFF db 27,ESC_CURSOL_OFF
counter_msg db 'Counter: '
count_num db '12345678 / loop: ',
loop_num db '12345678',13,'$'
align 4
count dd 0
dos_vec dd 0
ds_selector dd 0