| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- .model small
- .code
- jumps
- org 100h
- start:
- mov ax, 03h ; \
- ; | Clear Screen
- int 10h ; /
- mov ah, 02h ; \ Функция установки курсора
- mov bh, 0 ; | Активная страница
- mov dh, 24 ; |- Курсор к paddle (Y)
- mov dl, 10 ; | (X)
- int 10h ; /
- mov ah, 09h ;\ Вывод символа
- mov al, '▀' ;| Выводимый символ
- mov bh, 0h ;\ Страница
- mov bl, 04h ;/ Прорисовка paddle (Аттрибуты символа)
- mov cx, 05h ;| Количество символов
- int 10h ;/
-
- mov ah, 02h ; \ Функция установки курсора
- mov bh, 0 ; | Активная страница
- mov dh, 15 ; |- Курсор к шарику (Y)
- mov dl, 15 ; | (X)
- int 10h ; /
- mov ah, 09h ;\ Вывод символа
- mov al, '' ;| Выводимый символ
- mov bh, 0h ;\ Страница
- mov bl, 01h ;/ Прорисовка шарика (Аттрибуты символа)
- mov cx, 01h ;| Количество символов
- int 10h ;/
-
- mainloop:
-
- mov ah, 06h ;\
- mov dl, 0FFh ;| IF KeyPressed then Z on
- int 21h ;/
- jz TOFLY ; Если нет - проверяем, нужно ли двигать шар
-
- mov si,offset ifpad ;\ Смещение переменной изменения
- mov byte ptr [si], 1 ;/ - Изменение произошло
- cmp al, 0 ; -Проверяем, была ли расширеная клавиша
- jne GOODKEY ; Если нет - на начало работы
- mov ah, 08h ; \
- int 21h ; /Иначе - Снова вызываем считывания
- GOODKEY: ; AL - готова к работе
- cmp al, 27 ;\ IF
- je KONEZ ;/ ESC then END
- cmp al, 75 ;\ IF
- jne GORIGHT ;/ not Left - goto try RIGHT
- mov si, offset px ;\ in [si] - xpos of paddle
- cmp BYTE PTR [si],1 ;| compare with beg of screen
- jbe TOFLY ;| IF <= then goto TRY BAll
- dec BYTE PTR [si] ;| Else dec xpos of paddle: xpos--
- jmp TOFLY ;/ goto TRY BALL
- GORIGHT:
- cmp al, 77 ;\ IF
- jne TOFLY ;/ not LEFT goto TRY BALL
- mov si, offset px ;\ in [si] - xpos of paddle
- cmp BYTE PTR [si],74 ;| compare with end of screen
- jae TOFLY ;| IF >= then goto TRY BAll
- inc BYTE PTR [si] ;| Else inc xpos of paddle: xpos++
- jmp TOFLY ;/ goto TRY BALL
-
- loopend: ; Final stage of loop
-
- mov si, offset IFPAD ;\ in [si] - if i need to redraw
- cmp byte ptr [si],0 ;| if ![si]_
- je PREDDEL ;/ goto DELEAY
-
- mov si,offset ifpad ;\ IF needed then, on next turn_
- mov byte ptr [si], 0 ;/ it will be 0
- mov ah, 09h ;\
- mov al, ' ' ;| Выводимый символ
- mov bh, 0h ;\ Страница
- mov bl, 00h ;/ Прорисовка шарика (Аттрибуты символа)
- mov cx, 01h ;| Количество символов
- int 10h ;/
- mov ah, 02h ; \ GotoXY(0,24) to delete all line
- mov bh, 0 ; | Активная страница
- mov dh, 24 ; |- Курсор к paddle (Y)
- mov dl, 0 ; | (X)
- int 10h ; /
- mov ah, 09h ;\ Clear last line to redraw paddle
- mov al, ' ' ;| Выводимый символ (#20)
- mov bh, 0h ;\ Страница
- mov bl, 00h ;/ Прорисовка шарика (Аттрибуты символа)
- mov cx, 80 ;| Количество символов
- int 10h ;/
- mov si, offset px ; [si] = xpos of paddle
- mov ah, 02h ; \ GotoXY(xpos,24)
- mov bh, 0 ; | Активная страница
- mov dh, 24 ; |- Курсор к paddle (Y)
- mov dl, byte ptr [si] ; | (X) (From [si])
- int 10h ; /
- mov ah, 09h ;\ Draw the paddle
- mov al, '▀' ;| Выводимый символ
- mov bh, 0h ;| Страница
- mov bl, 04h ;| Прорисовка paddle (Аттрибуты символа)
- mov cx, 05h ;| Количество символов (Length of paddle)
- int 10h ;/
-
- mov si, offset x1 ; [si] = x pos of ball (x1)
- mov di, offset y1 ; [di] = y pos of ball (y1)
-
- mov ah, 02h ; \ GotoXY(x1,y1)
- mov bh, 0 ; | Активная страница
- mov dh, byte ptr [di] ; |- Cursor to draw ball (Y1) (From [di])
- mov dl, byte ptr [si] ; | (X1) (From [si])
- int 10h ; /
- mov ah, 09h ;\ Draw ball
- mov al, '' ;| Выводимый символ
- mov bh, 0h ;| Страница
- mov bl, 01h ;| Прорисовка шарика (Аттрибуты символа)
- mov cx, 01h ;| Количество символов
- int 10h ;/
- PREDDEL: ;\
- mov cx, 05F00h ;|
- delay: push cx ;|- Delay for some time
- pop cx ;|
- loop delay ;/
- jmp mainloop ; TOTAL END OF LOOP !!!!!!!
- ;-----------------------------------------------------
- ; END OF LOOP
- ;-----------------------------------------------------
- TOFLY: ; Ball flying ?
- mov si, offset ticks ; [si] = ticks(counter to syncronize ball with_
- ; paddle
- mov al, byte ptr [si] ; al = ticks
- inc al ; al++
- mov byte ptr [si], al ; ticks++
- mov ah, 0 ; ax = al
- mov bx, 0200h ; the period of ball move
- xor dx, dx ; dx = 0
- div bx ; dx = ax mod bx
- cmp dx, 0 ; if ticks кратно bx (0FFFFh)_
- je MOVE ; then goto MOVE bALL
- xor si, si ; si=0
- jmp loopend ; goto ENDOFLOOP
- MOVE:
- mov byte ptr [si], 1 ; [si]-ticks=1 (to not overflow)
- mov si,offset ifpad ;\ [si] = ifRedraw
- mov byte ptr [si], 1 ;/ redraw = true
- mov si, offset x1 ;\ [si] = x pos of ball (x1)
- mov di, offset y1 ;/ [di] = y pos of ball (y1)
- cmp byte ptr [si], 0 ; compare x1 with 0
- ja moveright ; if > then goto TEST RIGHT_
- mov byte ptr [XNEW+1], 0C6h ; Else in XNEW - change (dec dh)_
- ; to (inc dh)
- moveright: ; if ball can go right
- cmp byte ptr [si], 79 ; comp x1 with 79(end of screen)
- jb moveup ; if < goto TRY UP_
- mov byte ptr [XNEW+1], 0CEh ; Else in XNEW - change (inc dh)_
- ; to (dec dh)
- ; the inc/dec mnemonics
- ; inc dl - FEC2
- ; dec dl - FECA
- ; inc dh - FEC6
- ; dec dh - FECE
- moveup: ; if ball can go up
- cmp byte ptr [di], 0 ; comp y1 with 0(top of screen)
- ja movedown ; if > goto TRY DOWN_
- mov byte ptr [YNEW+1], 0C2h ; Else in YNEW - change (dec dl)_
- ; to (inc dl)
-
- movedown: ; if ball can go down
- cmp byte ptr [di], 23 ; comp y1 with 24(bottom of screen)
- jb allgood ; if < goto TRY UP_
- PUSH DI ; push DI in stack ([di]=y1)
- mov di, offset px ; Now in [DI] - paddle xpos
- mov bl, byte ptr [di] ; bl = xpos
- POP DI ; Now in [DI] = y1
- cmp byte ptr [si], bl ;\ compare x1 with xpos
- jb KONEZ ;| if < then goto GAMEOVER
- add bl,5 ;| bl=xpos+5(length if paddle)
- ;|-If paddle under ball
- cmp byte ptr [si], bl ;| compare x1 with xpos+5
- jae KONEZ ;| if > then gameover_
- mov byte ptr [YNEW+1], 0CAh ;/ Else in YNEW - change (inc dl)_
- ; to (dec dl)
- allgood: ; End of ball tests
- mov dh, byte ptr [si] ; dh = x pos of ball (x1)
- mov dl, byte ptr [di] ; dh = y pos of ball (y1)
- XNEW: inc dh ;\ HERE functions, that move ball_
- YNEW: dec dl ;/ they changed in ball tests
-
- mov byte ptr [si], dh ;\ x1 := new x pos of ball
- mov byte ptr [di], dl ;/ y1 := new y pos of ball
- xor si, si ;\ CLEAR SI,DI
- xor di, di ;/
- jmp loopend ; goto draw new pos of ball and paddle
- ;-------------------------------------------------------------------
- ;End OF GAME
- ;-------------------------------------------------------------------
- KONEZ: ; GAMEOVER !!!!!!!!
- int 20h ; Global End Proc
- x1 db 15 ;\ Coordinates of ball
- y1 db 15 ;/
- px db 10 ; - X coordinate of paddle
- ticks db 0 ; the number of game ticks
- IFPAD db 0 ; bool variable - if redraw
- end start ; LAST LINE
|