作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在组装 8086 中制作太空入侵者,用于测试我正在使用 DOSBox。让我向您展示我的代码:
;--------------------
;Update hero
;--------------------
update:
call vsync
call update_hero ; method to read keyboard
call set_video
call clear_screen
call draw_hero
jmp update
update_hero proc
mov ah, 01h
int 16h
cmp al, 97
je left_pressed
cmp al, 100
jne none_pressed
inc hero_x
left_pressed:
dec hero_x
none_pressed:
ret
update_hero endp
ah, 01h
的原因。 .
update_hero proc
mov ah, 01h ; checks if a key is pressed
int 16h
jz end_pressed ; zero = no pressed
mov ah, 00h ; get the keystroke
int 16h
begin_pressed:
cmp al, 65
je left_pressed
cmp al, 97
je left_pressed
cmp al, 68
je right_pressed
cmp al, 100
je right_pressed
cmp al, 81
je quit_pressed
cmp al, 113
je quit_pressed
jmp end_pressed
left_pressed:
sub hero_x, 2
jmp end_pressed
right_pressed:
add hero_x, 2
jmp end_pressed
quit_pressed:
jmp exit
end_pressed:
ret
update_hero endp
最佳答案
您只是在检查是否有可用的字符,但实际上并未从缓冲区读取字符。所以下次你检查时,它仍然存在。
从这个关于 BIOS 功能的页面 http://webpages.charter.net/danrollins/techhelp/0230.HTM
INT 16H,AH=1
Info: Checks to see if a key is available in the keyboard buffer, and
if so, returns its keycode in AX. It DOES NOT remove the
keystroke from the buffer.
关于assembly - 如何在不等待的情况下读取 key ,汇编 8086,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13143774/
我是一名优秀的程序员,十分优秀!