-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimulation-code.asm
More file actions
212 lines (175 loc) · 3.01 KB
/
Simulation-code.asm
File metadata and controls
212 lines (175 loc) · 3.01 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
#make_bin#
#LOAD_SEGMENT=FFFFh#
#LOAD_OFFSET=0000h#
#CS=0000h#
#IP=0000h#
#DS=0000h#
#ES=0000h#
#SS=0000h#
#SP=FFFEh#
#AX=0000h#
#BX=0000h#
#CX=0000h#
#DX=0000h#
#SI=0000h#
#DI=0000h#
#BP=0000h#
db 1024 dup(0)
;init ds, es, ss, sp
st1:cli
mov ax,0200h
mov ds,ax
mov es,ax
mov ss,ax
mov sp,0f00H
; init 8259
mov al, 13h ;icw1
out 10h, al
mov al, 80h ;icw2
out 12h, al
mov al, 01h ;icw4
out 12h, al
mov al, 00h ;ocw1
out 12h, al
sti
;init 8255
mov al, 81h
out 06h, al
mov al, 00h
out 04h, al
mov al, 00h
out 02, al
;init 8253
;C0 - 50 ms, 1khz input, count = 50, mode 3
mov al, 00110111b
out 0eh, al
mov al, 50
out 08h, al
mov al, 00
out 08h, al
;C1 - Random time generator, 1khz input, count = 4k, mode 3
mov al, 01110111b
out 0eh, al
mov al, 00
out 0ah, al
mov al, 40
out 0ah, al
;check game start
gst:in al, 04h
and al, 01h
cmp al, 01h
jne gst
;init all displays and 50ms clock
mov al, 00h
out 00h, al
out 02h, al
out 04h, al
;generate random number
;
in al, 04h
and al, 02h
cmp al, 02h
je stp
in al, 04h
and al, 08h
mov ah, al
cmp al, 08h
je hi
lo: ;
in al, 04h
and al, 02h
cmp al, 02h
je stp
in al, 04h
and al, 08h
cmp al, ah
je lo
lo2:;
in al, 04h
and al, 02h
cmp al, 02h
je stp
in al, 04h
and al, 08h
cmp al, ah
jne lo2
jmp pc0
hi: ;
in al, 04h
and al, 02h
cmp al, 02h
je stp
in al, 04h
and al, 08h
cmp al, ah
je hi
hi2:;
in al, 04h
and al, 02h
cmp al, 02h
je stp
in al, 04h
and al, 08h
cmp al, ah
jne hi2
; start the first led and C0 (50ms)
pc0:mov al, 30h
out 04h, al
;store score in bl
mov bl, 10
;store if the user wins in bh
mov dx, 0
ml: in al, 04h
and al, 04h
mov ah, al
w51:;
in al, 04h
and al, 02h
cmp al, 02h
je go
in al, 04h
and al, 04h
cmp ah, al
je w51
stc
rcl dl, 1
mov al, dl
out 00, al
;debug score
cmp dl, 11111111b
je go
dec bl
jmp ml
;in case of cheating with stop button
stp:mov cx, 30h
lpt:in al, 04h
and al, 04h
mov ah, al
cmp ah,00h
jne glw
mov al,00
out 00h,al
mov al, 20h
out 04, al
jmp w52
glw:mov al,0ffh
out 00h,al
mov al, 30h
out 04, al
w52:in al, 04h
and al, 04h
cmp ah, al
je w52
dec cx
jnz lpt
;init all displays and 50ms clock
mov al, 00h
out 00h, al
out 02h, al
out 04h, al
jmp gst
;otherwise you display and restart
go: mov al, bl
ror al, 1
out 02h, al
jmp gst