Sie sind auf Seite 1von 1

code

SEGMENT
ASSUME
ORG
wwidth EQU
height EQU
ball
EQU
start:
mov
mov
xor
mov
mov

PARA PUBLIC 'Code'


cs:CODE, ds:CODE
100h
80
25
001

; width used; 2 bytes/character assumed


; height used
; character for the ball (happy face)

ah, 0b8h

; 2 - AL=0 if no command-line parameters?

es, ax
di, di
bl, 2*(wwidth+1)

; 2 - ES=screen segment
; 2 - start at origin of screen
; 2 - offset to next position (BX=0 for
;
.COM file?)
dx, (wwidth-1)*256+(height-1)
; 3 - # of columns (DH) & rows (DL) left
;
before change in direction

l0:
2 - load ball character
1+2 - get original character, and
store ball on screen
loop
$
2 - delay (CX=0 at start of .COM file)
stosb
1 - store original character back
lea
di, [di+bx-1]
3 - DI+BX-1=next screen position
dec
dh
2 - decrement column count
jnz
l1
2 - another column -- don't swap x yet
; for a bounce off of the left or right side of the screen, BX changes in
; magnitude from 162 to 158 (or vice versa) with no change of sign; this is
; accomplished by an exclusive or:
;
;
162 = 1010 0010
;
158 = 1001 1110
;
3Ch = 0011 1100
mov
dh, wwidth-1
; 2 - reset column count
xor
bl, 3Ch
; 3 - swap x-direction
l1:
dec
dl
; 2 - decrement row count
jnz
l2
; 2 - another row -- don't swap y yet
; for a bounce off of the bottom or top of the screen, BX changes in magnitude
; as before, but also changes in sign
mov
dl, height-1
; 2 - reset row count
neg
bx
; 2 - start to swap y-direction...
xor
bl, 3Ch
; 3 - done!
l2:
;
jump to here to check if key
;
has been pressed
mov
ah, 01h
; 2 - load fcn. # for Get Keyboard Status

code

mov
xchg

al, ball
es:[di], al

;
;
;
;
;
;
;
;

int
jz
ret
ENDS
END

16h
l0

; 2 - call keyboard interrupt


; 2 - if key not pressed, repeat
; 1 - otherwise exit

start

Das könnte Ihnen auch gefallen