这是代码:
IDEAL
MODEL small
STACK 100h
DATASEG
; --------------------------
key db 0
locH dw 0 ;location horizontal
locV dw 0 ;location vertical
; --------------------------
CODESEG
UP_ON equ 48h
UP_OFF equ 0c8h
DOWN_ON equ 50h
DOWN_OFF equ 0d0h
LEFT_ON equ 4Bh
LEFT_OFF equ 0cBh
RIGHT_ON equ 4Dh
RIGHT_OFF equ 0cDh
ESCAPE equ 1
proc getKey
in al, 60h
mov [key],al
ret
endp getKey
start:
mov ax, @data
mov ds, ax
; --------------------------
;fullscreen
MOV AL, 13H
MOV AH, 0
INT 10H
;print red pixel
MOV AH,0Ch
MOV AL,4
MOV CX,160 ; 0 ≤ X ≤ 319
MOV DX,100 ; 0 ≤ Y ≤ 199
INT 10H
mov [locH],cx
mov [locV],dx
mainLoop:
call getKey
cmp [key],ESCAPE
jne next
jmp exit
next:
;checks if key is up
cmp [key],UP_ON
je up
;checks if key is down
cmp [key],DOWN_ON
je down
;checks if key is left
cmp [key],LEFT_ON
je left
;checks if key is right
cmp [key],RIGHT_ON
jne next2
jmp right
next2:
jmp mainLoop
; --------------------------
exit:
;exits full screen mode
MOV AL, 3H
MOV AH, 0
INT 10H
mov ax, 4c00h
int 21h
up:
;delete previous red pixel
MOV AH,0Ch
MOV AL,0
MOV CX,[locH] ; 0 ≤ X ≤ 319
MOV DX,[locV] ; 0 ≤ Y ≤ 199
INT 10H
inc [locV]
;print next red pixel
MOV AH,0Ch
MOV AL,4
MOV CX,[locH] ; 0 ≤ X ≤ 319
MOV DX,[locV] ; 0 ≤ Y ≤ 199
INT 10H
mov [locH],cx
mov [locV],dx
jmp mainLoop
down:
;delete previous red pixel
MOV AH,0Ch
MOV AL,0
MOV CX,[locH] ; 0 ≤ X ≤ 319
MOV DX,[locV] ; 0 ≤ Y ≤ 199
INT 10H
dec [locV]
;print next red pixel
MOV AH,0Ch
MOV AL,4
MOV CX,[locH] ; 0 ≤ X ≤ 319
MOV DX,[locV] ; 0 ≤ Y ≤ 199
INT 10H
mov [locH],cx
mov [locV],dx
left:
;delete previous red pixel
MOV AH,0Ch
MOV AL,0
MOV CX,[locH]; 0 ≤ X ≤ 319
MOV DX,[locV] ; 0 ≤ Y ≤ 199
INT 10H
dec [locH]
;print next red pixel
MOV AH,0Ch
MOV AL,4
MOV CX,[locH] ; 0 ≤ X ≤ 319
MOV DX,[locV] ; 0 ≤ Y ≤ 199
INT 10H
mov [locH],cx
mov [locV],dx
right:
;delete previous red pixel
MOV AH,0Ch
MOV AL,0
MOV CX,[locH]; 0 ≤ X ≤ 319
MOV DX,[locV] ; 0 ≤ Y ≤ 199
INT 10H
inc [locH]
;print next red pixel
MOV AH,0Ch
MOV AL,4
MOV CX,[locH] ; 0 ≤ X ≤ 319
MOV DX,[locV] ; 0 ≤ Y ≤ 199
INT 10H
mov [locH],cx
mov [locV],dx
jmp mainLoop
END start
似乎代码中存在两个问题:
相对超出范围000Eh字节.- 已解决
代码无法正常运行。当我按下箭头键时,像素就会变形并移动到屏幕上的不同位置。 我不知道为什么会出现问题,我尝试了所有可以想到的事情。
感谢您的帮助!
答案 0 :(得分:1)
由于您遇到了第二个问题,以下是对当前程序的一些观察:
您不应该通过直接读取某些键盘端口来了解按键。更好地使用适当的BIOS功能:
proc getKey
mov ah, 00h
int 10h
mov [key],al
ret
endp getKey
当用户按下 UP 键时,他会指望红点在屏幕上向上移动。由于屏幕的坐标系统与通常的数学XY坐标系统不同,您需要在向上例程中dec [locV]
和向下<{1>} / em>例程。
您的左和右例程正确无误。
BIOS调用失败的原因是没有提供所有参数!
BIOS调用绘制像素,期望inc [locV]
寄存器中的显示页面。你应该把它设置为零:
BH