我正在組裝一個乒乓球游戲,對于球技工,我在最后一個球位置所在的地方畫了一個空白球,但是當我將它添加到我的游戲回圈時,球開始閃爍,看起來有問題,這是代碼我用于球,有什么方法可以使洗掉程序更好,這樣它就不會閃爍(包括與我使用的方法不同的方法)?
IDEAL
MODEL small
jumps
STACK 100h
p186
DATASEG
;-------------------------
temp_x dw 0
temp_y dw 0
color dw 4
lengthOfDrawings dw 9
pic_off dw 0
x_ball dw 150
y_ball dw 50
h_ball dw 9
w_ball dw 9
ballSpeed dw 03AFFh
y_direction_ball dw 'd'
x_direction_ball dw 'r'
temp_var dw 0
ball db 00h, 00h, 08h, 08h, 08h, 08h, 08h, 00h, 00h
db 00h, 08h, 08h, 07h, 07h, 07h, 08h, 08h, 00h
db 08h, 08h, 07h, 07h, 07h, 07h, 07h, 08h, 08h
db 08h, 07h, 07h, 07h, 07h, 07h, 07h, 07h, 08h
db 08h, 07h, 07h, 07h, 07h, 07h, 07h, 07h, 08h
db 08h, 07h, 07h, 07h, 07h, 07h, 07h, 07h, 08h
db 08h, 08h, 07h, 07h, 07h, 07h, 07h, 08h, 08h
db 00h, 08h, 08h, 07h, 07h, 07h, 08h, 08h, 00h
db 00h, 00h, 08h, 08h, 08h, 08h, 08h, 00h, 00h
;----------------------
CODESEG
proc draw_pixel
pusha
xor bh, bh
mov cx, [temp_x]
mov dx, [temp_y]
mov ax, [color]
mov ah, 0ch
int 10h
popa
ret
endp draw_pixel
proc draw_line_ball
pusha
mov cx, [lengthOfDrawings]
mov ax, [x_ball]
mov [temp_x], ax
drawpr:
call draw_pixel
inc [temp_x]
loop drawpr
popa
ret
endp draw_line_ball
proc draw_ball
pusha
mov cx, [x_ball]
mov dx,[y_ball]
mov ax, 0ch
int 10H ; AL = COLOR
cmp al, 4
je endDrawBall
cmp al, 9
je endDrawBall
; DI ????? ????? ??????? ?? ???? ????
mov di,[pic_off]
mov dx, [y_ball]
print_line:
mov cx, [x_ball] ; x pos
mov si, [w_ball] ; ball width
print_columns:
mov al, [di] copy color to AL
inc di ; next item in array
; painting a pixel
; cx = x coordinate , dx = y coordinate, al- color
mov bh,0
mov ah,0ch
int 10h
inc cx ; inc x
dec si ; decrease col counter
cmp si, 0
jne print_columns
inc dx ;inc Y
dec [h_ball] ; decreasing row counter
cmp [h_ball], 0
jne print_line
endDrawBall:
popa
ret
endp draw_ball
proc draw_blank_ball
pusha
mov cx, 9
mov ax, [y_ball]
mov [temp_y], ax
mov [color], 0
rectanl:
call draw_line_ball
inc [temp_y]
loop rectanl
mov [color], 4
popa
ret
endp draw_blank_ball
proc delay
pusha
mov cx, 00h ;Higher part of the number
mov dx, [ballSpeed] ;Lower part of the number
mov al, 0
mov ah, 86h
int 15h
popa
ret
endp delay
start:
mov ax, @data
mov ds, ax
;---------------------------
;Changing to graphic mode
mov ax, 13h
int 10h
gameLoop:
add [x_ball], 2h
inc [y_ball]
mov [pic_off], offset ball
mov [h_ball], 9
mov [w_ball], 9
call draw_ball
call delay
call draw_blank_ball
jmp gameLoop
endGame:
;Returns to text mode
mov ax, 2h
int 10h
;---------------------------
exit:
mov ax, 4c00h
int 21h
END start
uj5u.com熱心網友回復:
pusha這將是一項相當昂貴的手術。只有推送/彈出您修改的暫存器可能是一種節省。
也就是說,這樣的事情怎么樣?它擺脫了對 draw_pixel 的呼叫(因此是 pusha/popa),以及暫存器的不斷重新填充。
proc draw_line_ball
pusha
mov si, [lengthOfDrawings]
xor bh, bh
mov cx, [x_ball]
mov dx, [temp_y]
mov ax, [color]
mov ah, 0ch
drawpr:
int 10h
inc cx
dec si
jnz drawpr
popa
ret
endp draw_line_ball
(顯然)我沒有嘗試過這個,但那里可能有一些有用的想法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/424407.html
上一篇:#define陳述句中的單反斜杠和雙反斜杠,以及信號名稱的起始.L是什么?(arm64總成)
下一篇:為什么顯示數字總和不正確
