?? brick.asm
字號:
.model small
.stack 1024
.data
FILE db 'map.txt', 00h
hfile dw ?
dummy dw ?
bricks db 120 dup(7) ; 10x12(each 32x12)
ball2 db 15, 15,
15, 15
ball6 db 0 , 0 , 15, 15, 0 , 0 ,
0 , 15, 15, 15, 15, 0 ,
15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15,
0 , 15, 15, 15, 15, 0 ,
0 , 0 , 15, 15, 0 , 0
ball10 db 0 , 0 , 0 , 0 , 15, 15, 0 , 0 , 0 , 0
db 0 , 0 , 15, 15, 15, 15, 15, 15, 0 , 0
db 0 , 15, 15, 15, 15, 15, 15, 15, 15, 0
db 0 , 15, 15, 15, 15, 15, 15, 15, 15, 0
db 15, 15, 15, 15, 15, 15, 15, 15, 15, 15
db 15, 15, 15, 15, 15, 15, 15, 15, 15, 15
db 0 , 15, 15, 15, 15, 15, 15, 15, 15, 0
db 0 , 15, 15, 15, 15, 15, 15, 15, 15, 0
db 0 , 0 , 15, 15, 15, 15, 15, 15, 0 , 0
db 0 , 0 , 0 , 0 , 15, 15, 0 , 0 , 0 , 0
balls dw ball2, ball6, ball10
sizes dw 2, 6, 10
ball_x dw 160
ball_y dw 190
ball_r dw 2
step_x dw 1
step_y dw -1
buffle dw 150
buf_len dw 32
delay_t dw 40
counter dw ?
.code
; Draw the ball
; input:
; ax: color
; modified: ax, cx
blit proc near
push bx
push si
push di
push ax ; count position in screen memory
mov ax, ball_y
mov bx, 320
imul bx
add ax, ball_x
mov di, ax
pop ax
mov bx, ball_r
mov bx, sizes[bx]
mov cx, bx ; cx = bx = counter
test ax, ax
jz do_clear
mov si, offset balls
add si, ball_r
mov si, [si]
loop6:
push cx
mov cx, bx
rep movsb
add di, 320
sub di, bx
pop cx
loop loop6
jmp exit1
do_clear:
xor ax, ax
loop7:
push cx
mov cx, bx
rep stosb
add di, 320
sub di, bx
pop cx
loop loop7
exit1:
pop di
pop si
pop bx
ret
blit endp
; Draw the buffle
; ax: color
;
paint proc near
mov di, 320 * 198
add di, buffle
mov ah, al
mov cx, buf_len
shr cx, 1
rep stosw
add di, 320
sub di, buf_len
mov cx, buf_len
shr cx, 1
rep stosw
ret
paint endp
; Draw a brick
; input:
; al: color
; di: position
; modified: ax, bx, cx
brick proc near
push di
mov ah, al
mov bx, 11
loop1:
dec bx
mov cx, 15
rep stosw
stosb
add di, 320 - 31
test bx, bx
jnz loop1
pop di
ret
brick endp
bground proc near
mov si, offset bricks
xor di, di
xor dx, dx
loop2:
mov al, [si]
call brick
add di, 32
inc si
inc dx
cmp dx, 10
jb skip1
add di, 320 * 11
xor dx, dx
skip1:
cmp si, offset bricks + 120
jb loop2
ret
bground endp
; Delay for a while
; cx: time
;
delay proc near
loop8:
push cx
mov cx, 0
loop9:
loop loop9
pop cx
loop loop8
ret
delay endp
; Test if the ball come to edge
;
;
hitedge proc near
mov ax, ball_x
mov bx, ball_y
mov si, ball_r
mov si, sizes[si]
mov cx, 318
sub cx, si
cmp ax, cx
jg x_edge
cmp ax, 1
jl x_edge
mov cx, 200
sub cx, si
cmp bx, cx
jg y_out
cmp bx, 1
jl y_edge
jmp skip4
x_edge:
neg step_x
jmp hit_edge
y_edge:
neg step_y
jmp hit_edge
y_out:
mov ax, 2
ret
hit_edge:
mov ax, 1
ret
skip4:
xor ax, ax
ret
hitedge endp
;
; deal with special color brick
;
; dl: current color
;
spec proc near
push ax
cmp dl, 7 ; color 7 and 1 has exchanged
jz spec1
cmp dl, 2
jz spec2
cmp dl, 3
jz spec3
cmp dl, 4
jz spec4
cmp dl, 5
jz spec5
cmp dl, 6
jz spec6
cmp dl, 1
jz spec7
jmp skip12
spec1:
; nothing to do
jmp skip12
spec2:
mov ax, delay_t
cmp ax, 20
jle skip13
sub ax, 10
mov delay_t, ax
skip13:
jmp skip12
spec3:
mov ax, delay_t
cmp ax, 60
jge skip14
add ax, 10
mov delay_t, ax
skip14:
jmp skip12
spec4:
xor ax, ax
call blit
mov ax, ball_r
cmp ax, 4
jge skip15
inc ax
inc ax
mov ball_r, ax
mov ax, 1
call blit
skip15:
jmp skip12
spec5:
xor ax, ax
call blit
mov ax, ball_r
cmp ax, 0
jle skip16
dec ax
dec ax
mov ball_r, ax
mov ax, 1
call blit
skip16:
jmp skip12
spec6:
xor ax, ax
call paint
mov ax, buf_len
cmp ax, 56
jge skip17
add ax, 8
mov buf_len, ax
mov ax, 15
call paint
skip17:
jmp skip12
spec7:
xor ax, ax
call paint
mov ax, buf_len
cmp ax, 16
jle skip12
sub ax, 8
mov buf_len, ax
mov ax, 15
call paint
skip12:
pop ax
ret
spec endp
; Get the color of the position
; ax: y
; bx: x
; return dl
;
getcl proc near
push ax
push cx
push si
mov cx, 320
mul cx
add ax, bx
mov si, ax
mov dl, byte ptr es:[si]
pop si
pop cx
pop ax
ret
getcl endp
; Test if the ball hit a brick
;
;
hbrick proc near
mov si, ball_r
mov si, sizes[si]
shr si, 1
mov bx, ball_x ; UP
add bx, si
mov ax, ball_y
dec ax
call getcl
mov dh, dl
inc bx
call getcl
or dl, dh
test dl, dl
jnz up_down
mov bx, ball_x ; DOWN
add bx, si
mov ax, ball_y
add ax, si
add ax, si
call getcl
mov dh, dl
inc bx
call getcl
or dl, dh
test dl, dl
jnz up_down
mov bx, ball_x ; LEFT
dec bx
mov ax, ball_y
add ax, si
call getcl
mov dh, dl
inc ax
call getcl
or dl, dh
test dl, dl
jnz left_right
mov bx, ball_x ; RIGHT
add bx, si
add bx, si
mov ax, ball_y
add ax, si
call getcl
mov dh, dl
inc ax
call getcl
or dl, dh
test dl, dl
jnz left_right
jmp skip7
up_down:
neg step_y
jmp hit_brick
left_right:
neg step_x
hit_brick:
cmp dl, 7
ja skip7
call spec
dec counter
push ax ; y = y - (y mod 12)
mov cx, 12
xor dx, dx
div cx
pop ax
sub ax, dx
xchg ax, bx ; bx = new y, ax = x
push ax ; x = x - (x mod 32)
mov cx, 32
xor dx, dx
div cx
pop ax
sub ax, dx
xchg ax, bx ; ax = new y, bx = new x
mov cx, 320
mul cx
add ax, bx
mov di, ax
xor ax, ax
call brick
skip7:
ret
hbrick endp
; Move the ball
;
;
move proc near
xor ax, ax
call blit
mov ax, ball_x
mov bx, ball_y
add ax, step_x
add bx, step_y
mov ball_x, ax
mov ball_y, bx
mov ax, 1
call blit
ret
move endp
; play while
;
;
play proc near
call bground
play_loop:
mov cx, delay_t
call delay
call hitedge
cmp ax, 2
jz quit
cmp ax, 1
jz skip18
call hbrick
skip18:
call move
mov ax, counter ; finished all
test ax, ax
jz quit
mov ah, 11h
int 16h
jz play_loop
mov ah, 07h ; get keyboard input
int 21h
cmp al, 00
jnz skip5
int 21h
skip5:
cmp al, 'K'
jz left
cmp al, 'M'
jz right
cmp al, 'q'
jz quit
cmp al, 27
jz quit
jmp skip6
left:
xor ax, ax
call paint
mov ax, buffle
cmp ax, 16
jle left_edge
sub ax, 16
jmp skip11
left_edge:
mov ax, 0
skip11:
mov buffle, ax
mov ax, 15
call paint
jmp skip6
right:
xor ax, ax
call paint
mov ax, buffle
mov cx, 320
sub cx, buf_len
cmp ax, cx
jge right_edge
add ax, 16
jmp skip12
right_edge:
mov ax, 320
sub ax, buf_len
skip12:
mov buffle, ax
mov ax, 15
call paint
skip6:
jmp play_loop
quit:
ret
play endp
read proc near
mov ah, 3dh
mov al, 00
mov dx, offset FILE
int 21h
jc error1
mov hfile, ax
mov si, offset bricks
mov cx, 12
loop10:
push cx
mov ah, 3fh
mov bx, hfile
mov cx, 10
mov dx, si
int 21h
jc error1
mov ah, 3fh
mov bx, hfile
mov cx, 2
mov dx, offset dummy
int 21h
jc error1
add si, 10
pop cx
loop loop10
mov cx, 120
mov si, offset bricks
loop11:
mov al, [si]
sub al, '0'
cmp al, 1
jz to7
cmp al, 7
jz to1
jmp skip10
to7:
mov al, 7
jmp skip10
to1:
mov al, 1
skip10:
mov [si], al
test al, al
jz skip19
inc counter
skip19:
inc si
loop loop11
success:
xor ax, ax
ret
error1:
mov ax, -1
ret
read endp
main proc near
mov ax, @data
mov ds, ax
mov ax, 0a000h
mov es, ax
mov ax, 0013h
int 10h
cld
call read
call play
mov ax, 0003h
int 10h
mov ax, 4c00h ;call dos to exit
int 21h
main endp
end main
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -