-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCREEN.ASM
More file actions
360 lines (313 loc) · 5.39 KB
/
SCREEN.ASM
File metadata and controls
360 lines (313 loc) · 5.39 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
.MODEL TINY
public Print
public TestSpace
public Bottom
public InitScreen
public PrintLong
public GameOverPrompt
public RemovePause
public PrintPause
extrn RandSeed:word
extrn Items:word
BORDER_CHAR equ 32
BORDER_COLOR equ 29
HISCORE_TEXT_POS equ 0
SCORE_TEXT_POS equ 240
LEVEL_TEXT_POS equ 400
LOGO_POS equ 800
BY_POS equ 970
TORE_POS equ 1128
BAST_POS equ 1202
PREVIEW_TEXT_POS equ 134
GAME_OVER_POS equ 934
PLAY_AGAIN_POS equ 1654
PAUSE_POS equ 934
.DATA
TetrisLogo label word
db 'S',1
db 'm',2
db 'a',3
db 'l',4
db 'l',5
db 'T',6
db 'e',7
db 't',8
db 'r',9
db 'i',10
db 's',11
dw 0
db 'b',7
db 'y',7
dw 0
db 'T',1
db 'o',2
db 'r',3
db 'e',4
dw 0
db 'B',6
db 'a',7
db 's',8
db 't',9
db 'i',10
db 'a',11
db 'n',12
db 's',13
db 'e',14
db 'n',15
dw 0
db 'HISCORE:',0
db 'SCORE:',0
db 'LEVEL:',0
db 'Preview:',0
GameOverText label word
db 'GAME OVER',0
db 'Play again?',0
RemovePauseText label byte
db 5 dup (' ')
db 0
PauseText db 'PAUSE',0
RowFill db 25 dup (?)
.CODE
InitScreen proc near
mov ax,0001h ; Screen mode 1
int 10h
xor di,di
mov ax,0b800h
mov es,ax
mov cx,1000
xor ax,ax
rep stosw ; Fill screen with 0
mov ax,BORDER_CHAR+256*BORDER_COLOR ; Horisontal lines
mov di,28
mov cx,12
rep stosw ; Upper
mov di,28+24*80
mov cx,12
rep stosw ; Lower
mov cx,23
mov ax,BORDER_CHAR+256*BORDER_COLOR ; Vertical lines
mov di,80+28
loop_s1:
mov es:[di],ax
add di,22
mov es:[di],ax
add di,58
loop loop_s1
push es
push ds
pop es
mov cx,25
mov di, offset RowFill
mov ax,0
rep stosb ; Clear buffer
pop es
; Print text
mov di,LOGO_POS
mov si,offset TetrisLogo
call PrintColorString
mov di,BY_POS
call PrintColorString
mov di,TORE_POS
call PrintColorString
mov di,BAST_POS
call PrintColorString
mov ah,1
mov di,HISCORE_TEXT_POS
call PrintMonoString
mov di,SCORE_TEXT_POS
call PrintMonoString
mov di,LEVEL_TEXT_POS
call PrintMonoString
mov di,PREVIEW_TEXT_POS
call PrintMonoString
ret
InitScreen endp
DeleteRow proc near ;bx=Row
mov dx,0b800h
mov es,dx
dec bx
mov cx,bx
mov ax,bx
mov dx,80
imul dx
add ax,30 ; ax=source offset
mov si,ax
loop_d1:
mov di,si
add di,80
push cx
mov cx,10
push ds
push es
pop ds
rep movsw
pop ds
sub si,100
mov cl,byte ptr RowFill[bx]
mov byte ptr RowFill[bx+1],cl
dec bx
pop cx
loop loop_d1
ret
DeleteRow endp
Bottom proc near ;ax=ItemNr di=scroffset
mov dx,0b800h
mov es,dx
mov dx,06
imul dx
add ax, offset Items ; ax=ax*6
xor cx,cx ; for cx=0 to 3
loop_b1:
mov bx,ax
add bx,cx
push ax
mov al,byte ptr [bx+2]
cbw
shl ax,1
add di,ax
mov ax,di
xor dx,dx
mov bx,80
div bx
mov bx,ax
inc byte ptr RowFill[bx]
pop ax
inc cx
cmp cx,4
jne loop_b1
xor bx,bx
loop_b2:
cmp byte ptr RowFill[bx],10
jne not_full
push bx
call DeleteRow
inc word ptr randseed
pop bx
not_full:
inc bx
cmp bx,24
jne loop_b2
ret
Bottom endp
TestSpace proc near ;ax= item_nr di=scroffs
mov dx,0b800h
mov es,dx
mov dx,06
imul dx
add ax, offset Items ; ax=ax*6
xor dx,dx ; for dx=0 to 3
loop1:
mov bx,ax
add bx,dx
push ax
mov al,byte ptr [bx+2]
cbw
shl ax,1
add di,ax
pop ax
cmp word ptr es:[di],0
jne bad
inc dx
cmp dx,4
jne loop1
mov ax,01
ret
bad:
xor ax,ax
ret
TestSpace endp
Print proc near ;ax= item_nr di=scroffs si=T/F
mov dx,0b800h
mov es,dx
mov dx,06
imul dx ; ax=ax*6
add ax, offset Items ; ax+=[_items]
xor dx,dx ; for dx=3 to 0
cmp si,0
je loop2
mov bx,ax
mov si,ds:[bx]
loop2:
mov bx,ax
add bx,dx
push ax
mov al,byte ptr [bx+2]
cbw
shl ax,1
add di,ax
pop ax
mov es:[di],si
inc dx
cmp dx,4
jne loop2
ret
Print endp
PrintLong proc near
mov bx,0b800h
mov es,bx
mov bx,10
more_digits:
div bx
add dx,'0'+256*7
mov es:[di],dx
sub di,2
mov dx,0
cmp ax,0
jne short more_digits
ret
PrintLong endp
PrintColorString proc near
mov bx,0b800h
mov es,bx
color_loop:
mov ax,ds:si
inc si
inc si
and ax,ax
jz color_done
mov es:di,ax
inc di
inc di
jmp color_loop
color_done:
ret
PrintColorString endp
PrintMonoString proc near
mov bx,0b800h
mov es,bx
mono_loop:
mov al,ds:si
inc si
and al,al
jz mono_done
mov es:di,ax
inc di
inc di
jmp mono_loop
mono_done:
ret
PrintMonoString endp
GameOverPrompt proc near
mov ah,1
mov di,GAME_OVER_POS
mov si,offset GameOverText
call near ptr PrintMonoString
mov di,PLAY_AGAIN_POS
call near ptr PrintMonoString
ret
GameOverPrompt endp
RemovePause proc near
xor ah,ah
mov di,PAUSE_POS
mov si,offset RemovePauseText
call PrintMonoString
ret
RemovePause endp
PrintPause proc near
mov ah,1
mov di,PAUSE_POS
mov si,offset PauseText
call PrintMonoString
ret
PrintPause endp
end