-
Notifications
You must be signed in to change notification settings - Fork 0
/
zmei.asm
627 lines (599 loc) · 8.77 KB
/
zmei.asm
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
.model tiny
assume cs:progg
progg segment
org 100h
;----------------------------------------------------------------------------
startup proc
;jmp check_speed
mov word ptr [ds:1960h],0000h
jmp set_video
;jmp set_video
ret
startup endp
;----------------------------------------------------------------------------
defeat:
mov sp,00h
mov word ptr [ds:1960h],0000h
mov word ptr [ds:1970h],0000h
lea dx,filenamed
mov [ds:1802h],dx
jmp read_file
;----------------------------------------------------------------------------
set_video:
;mov ax,4F02h
;mov bx,100h
mov ah,00h
mov al,13h
int 10h
jmp intro
;----------------------------------------------------------------------------
apple_check:
mov si,[ds:1800h]
cmp si,00h
jz konec
jmp not_finished
konec:
jmp set_param
;mov cx,0000h
;mov dx,0000h
;chknext:
;mov sp,00h
;mov ah,0Dh
;int 10h
;cmp al,00h
;ja onemchk
;jmp gotov
;onemchk:
;cmp al,0Fh
;jnb gotov
;jmp not_finished
;gotov:
;add cx,02h
;cmp cx,0140h
;jnz more2
;mov cx,00h
;add dx,02h
;cmp dx,00C8h
;jz orev2
;more2:
;jmp chknext
;orev2:
;jmp set_param
;----------------------------------------------------------------------------
read_file:
mov dx,[ds:1802h]
mov ax,3D00h
xor cx,cx
int 21h
mov dx,1A20h
mov bx,ax
mov cx,42B6h
mov ah,3Fh
int 21h
mov ax,3E00h
int 21h
jmp draw_apples
;----------------------------------------------------------------------------
intro:
lea dx,filenamei
mov [ds:1802h],dx
jmp read_file
;Âõîäíûå äàííûå: x â AX, y â BX, öâåò â CX
;Âûõîäíûå äàííûå: ðåãèñòðû AX è BX íå ñîõðàíÿþòñÿ
draw_pix:
;push bx
mov di,cx
mov bx,dx
xchg BH,BL ;óìíîæàåì y íà 256, BL=0
add di,BX ;AX = x+256y
shr BX,1 ;äåëèì 256y íà äâà
shr BX,1 ;BX = 256y/4 = 64y
add BX,di ;BX = x+320y
mov di,ES ;ñîõðàíÿåì çíà÷åíèå ES
mov si,0A000h ;ñåãìåíò ïàìÿòè ýêðàíà VGA
mov es,si
mov ES:[BX],al ;âûâîäèì áàéò íà ýêðàí
mov ES,di ;âîññòàíàâëèâàåì çíà÷åíèå ðåãèñòðà ES
;pop bx
ret
;----------------------------------------------------------------------------
draw_apples:
mov cx,0000h
mov dx,0000h
mov bx,1E56h
drawnext:
;mov ah,0Ch
mov al,[bx]
cmp al,02h
jnz netoo
mov si,[ds:1800h]
inc si
mov [ds:1800h],si
netoo:
cmp al,03h
jnz netoo2
mov si,[ds:1800h]
inc si
mov [ds:1800h],si
netoo2:
cmp al,04h
jnz netoo3
mov si,[ds:1800h]
inc si
mov [ds:1800h],si
netoo3:
;mov ah,0Ch
mov al,[bx]
push bx
;int 10h
call draw_pix
inc cx
;mov ah,0Ch
;mov al,[ds:bx]
call draw_pix
;int 10h
inc dx
;mov ah,0Ch
;mov al,[ds:bx]
call draw_pix
;int 10h
dec cx
;mov ah,0Ch
;mov al,[ds:bx]
call draw_pix
;int 10h
pop bx
mov sp,00h
inc bx
dec dx
add cx,02h
cmp cx,0140h
jnz more
mov cx,00h
add dx,02h
cmp dx,00C8h
jz orev
more:
jmp drawnext
orev:
mov bx,[ds:1970h]
cmp bx,0F3h
jnz nodraws
mov ax,0000h
int 16h
jmp draw_snake
nodraws:
mov word ptr [ds:1970h],00F3h
jmp choice
;jmp set_param
;----------------------------------------------------------------------------
choice:
mov ah,00h
int 16h
cmp ah,01h
jnz drugkn1
jmp exit
drugkn1:
cmp ah,3Bh
jnz drugkn2
mov word ptr [ds:1900h],02h
jmp set_param
drugkn2:
cmp ah,3Ch
jnz drugkn3
mov word ptr [ds:1900h],01h
jmp set_param
drugkn3:
jmp choice
;----------------------------------------------------------------------------
kastorka:
mov dx,1000h
mov ax,0000h
mov al,[ds:1930h]
mov cl,02h
mul cl
add ax,dx
mov bx,ax
mov ax,[bx]
mov cx,0000h
mov dx,0000h
mov cl,al
mov dl,ah
;add cl,01h
mov ah,0Ch
mov al,02h
int 10h
inc cl
mov ah,0Ch
mov al,02h
int 10h
inc dl
mov ah,0Ch
mov al,02h
int 10h
dec cl
mov ah,0Ch
mov al,02h
int 10h
jmp return
;----------------------------------------------------------------------------
draw_snake:
mov bx,[ds:1928h]
mov ax,[bx]
mov cx,0000h
mov dx,0000h
mov cl,al
mov dl,ah
mov al,[ds:1939h]
cmp al,00h
jz skiper
mov al,0Fh
skiper:
call draw_pix
;mov ah,0Ch
;int 10h
inc cl
call draw_pix
;mov ah,0Ch
;int 10h
inc dl
call draw_pix
;mov ah,0Ch
;int 10h
dec cl
call draw_pix
;mov ah,0Ch
;int 10h
mov cx,[ds:1000h]
inc cx
mov [ds:1000h],cx
mov dx,[ds:1930h]
cmp cx,dx
jae skip
mov bx,[ds:1928h]
inc bx
inc bx
mov [ds:1928h],bx
jmp draw_snake
skip:
mov ax,[ds:1938h]
cmp ax,0000h
jz toend
mov bx,[ds:1928h]
inc bx
inc bx
mov [ds:1928h],bx
mov word ptr [ds:1938h],0000h
mov cx,[ds:1000h]
dec cx
mov [ds:1000h],cx
jmp draw_snake
toend:
mov word ptr [ds:1928h],1002h
mov word ptr [ds:1938h],0F00h
mov word ptr [ds:1000h],0000h
jmp Snake_moves
;----------------------------------------------------------------------------
exit:
mov sp,00h
int 20h
;----------------------------------------------------------------------------
set_param:
mov word ptr [ds:1000h],0000h
mov word ptr [ds:1002h],8080h
mov word ptr [ds:1004h],8082h
mov word ptr [ds:1006h],8084h
mov word ptr [ds:1008h],8086h
mov bx,1008h
yeshcho:
add bx,02h
mov [bx],0FFFFh
cmp bx,17FEh
jb yeshcho
mov word ptr [ds:1926h],0800h
mov word ptr [ds:1928h],1002h
mov word ptr [ds:1930h],0004h
mov word ptr [ds:1932h],0001h
mov word ptr [ds:1938h],0F00h
mov word ptr [ds:1800h],0000h
mov word ptr [ds:1940h],0000h
mov bx,[ds:1960h]
add bx,0Bh
cmp bx,037h
jbe nextlev
mov bx,0000h
nextlev:
mov [ds:1960h],bx
lea dx,filenamei+bx
mov [ds:1802h],dx
jmp read_file
;----------------------------------------------------------------------------
snake_moves:
push ax
push bx
push cx
mov ax,[ds:1002h]
mov cx,0000h
mov dx,0000h
mov cl,al
mov dl,ah
mov ax,[ds:1932h]
cmp ax,0001h
jnz drugoi
dec cl
dec cl
drugoi:
mov ax,[ds:1932h]
cmp ax,0002h
jnz drugoi2
dec dl
dec dl
drugoi2:
mov ax,[ds:1932h]
cmp ax,0003h
jnz drugoi3
inc cl
inc cl
drugoi3:
mov ax,[ds:1932h]
cmp ax,0004h
jnz drugoi4
inc dl
inc dl
drugoi4:
mov ah,0Dh
int 10h
cmp al,02h
jnz noapple
mov dx,[ds:1930h]
inc dx
mov si,[ds:1800h]
dec si
mov [ds:1800h],si
mov [ds:1930h],dx
noapple:
cmp al,04h
jnz noapple2
mov dx,[ds:1930h]
inc dx
inc dx
mov si,[ds:1800h]
dec si
mov [ds:1800h],si
mov [ds:1930h],dx
noapple2:
cmp al,03h
jnz noapple3
jmp kastorka
return:
mov dx,[ds:1930h]
dec dx
mov [ds:1930h],dx
noapple3:
cmp al,0Fh
jnz noapple4
jmp defeat
noapple4:
jmp apple_check
not_finished:
mov cx,[ds:1932h]
cmp cx,0001h
jnz another1
mov bx,[ds:1928h]
mov dx,[bx]
mov [ds:1940h],dx
dec dl
dec dl
mov [bx],dx
mov bx,[ds:1928h]
inc bx
inc bx
mov [ds:1928h],bx
again1:
mov bx,[ds:1928h]
mov dx,[bx]
mov ax,[ds:1940h]
mov [ds:1940h],dx
mov [bx],ax
mov cx,[ds:1000h]
inc cx
mov [ds:1000h],cx
mov dx,[ds:1930h]
cmp cx,dx
jz skip1
mov bx,[ds:1928h]
inc bx
inc bx
mov [ds:1928h],bx
jmp again1
skip1:
mov [ds:1928h],1002h
another1:
mov cx,[ds:1932h]
cmp cx,0002h
jnz another2
mov bx,[ds:1928h]
mov dx,[bx]
mov [ds:1940h],dx
dec dh
dec dh
mov [bx],dx
mov bx,[ds:1928h]
inc bx
inc bx
mov [ds:1928h],bx
again2:
mov bx,[ds:1928h]
mov dx,[bx]
mov ax,[ds:1940h]
mov [ds:1940h],dx
mov [bx],ax
mov cx,[ds:1000h]
inc cx
mov [ds:1000h],cx
mov dx,[ds:1930h]
cmp cx,dx
jz skip2
mov bx,[ds:1928h]
inc bx
inc bx
mov [ds:1928h],bx
jmp again2
skip2:
mov [ds:1928h],1002h
another2:
mov cx,[ds:1932h]
cmp cx,0003h
jnz another3
mov bx,[ds:1928h]
mov dx,[bx]
mov [ds:1940h],dx
inc dl
inc dl
mov [bx],dx
mov bx,[ds:1928h]
inc bx
inc bx
mov [ds:1928h],bx
again3:
mov bx,[ds:1928h]
mov dx,[bx]
mov ax,[ds:1940h]
mov [ds:1940h],dx
mov [bx],ax
mov cx,[ds:1000h]
inc cx
mov [ds:1000h],cx
mov dx,[ds:1930h]
cmp cx,dx
jz skip3
mov bx,[ds:1928h]
inc bx
inc bx
mov [ds:1928h],bx
jmp again3
skip3:
mov [ds:1928h],1002h
another3:
mov cx,[ds:1932h]
cmp cx,0004h
jnz another4
mov bx,[ds:1928h]
mov dx,[bx]
mov [ds:1940h],dx
inc dh
inc dh
mov [bx],dx
mov bx,[ds:1928h]
inc bx
inc bx
mov [ds:1928h],bx
again4:
mov bx,[ds:1928h]
mov dx,[bx]
mov ax,[ds:1940h]
mov [ds:1940h],dx
mov [bx],ax
mov cx,[ds:1000h]
inc cx
mov [ds:1000h],cx
mov dx,[ds:1930h]
cmp cx,dx
jz skip4
mov bx,[ds:1928h]
inc bx
inc bx
mov [ds:1928h],bx
jmp again4
skip4:
mov [ds:1928h],1002h
another4:
mov ah,01h
int 16h
jz getto3
mov al,ah
mov ah,00h
int 16h
;mov bx,ax
;mov ax,0000h
;LAHF
;mov al,[ds:1955h]
;cmp ah,46h
;jz getto3
cmp ah,44h
jnz proced
jmp exit
proced:
cmp ah,4Bh
jnz getto
mov bx,[ds:1932h]
cmp bx,0003h
jz getto
mov word ptr [ds:1932h],0001h
getto:
cmp ah,4Dh
jnz getto1
mov bx,[ds:1932h]
cmp bx,0001h
jz getto1
mov word ptr [ds:1932h],0003h
getto1:
cmp ah,50h
jnz getto2
mov bx,[ds:1932h]
cmp bx,0002h
jz getto2
mov word ptr [ds:1932h],0004h
getto2:
cmp ah,48h
jnz getto3
mov bx,[ds:1932h]
cmp bx,0004h
jz getto3
mov word ptr [ds:1932h],0002h
getto3:
pop cx
pop bx
pop ax
mov word ptr [ds:1000h],0000h
mov sp,00h
mov bx,0000h
mov cx,0000h
;jmp draw_snake
jmp slow_down
;jmp check_speed
;----------------------------------------------------------------------------
slow_down:
mov ah,00h
int 1Ah
mov bx,[ds:1900h]
add dx,bx
adc cx,00h
mov di,dx
mov si,cx
repet:
int 1Ah
;push ax
;mov ah,01h
;mov al,00h
;int 16h
;mov [ds:1955h],ah
;pop ax
cmp cx,si
jae onemoprov
jmp repet
onemoprov:
cmp dx,di
jb repet
jmp draw_snake
tick0 dw 0,0
tick2 dw 0,0
filenamed db 'losezz.bmp',0
filenamei db 'intro0.bmp',0
filename1 db 'level1.bmp',0
filename2 db 'level2.bmp',0
filename3 db 'level3.bmp',0
filename4 db 'level4.bmp',0
filename5 db 'victor.bmp',0
progg ends
end startup