DOSBoxを使用していることをテストするために、アセンブリ8086でスペースインベーダーを作成しています。私のコードをお見せしましょう:
;--------------------
;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は次のようになります。
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
ご覧のとおり、ムーブメントの「a」または「d」を読み込もうとしていますが、機能していません。理由を理解するのを手伝ってもらえますか?
私がやろうとしているのは、待たずにキーボードから読み取ることです。そのため、サブ機能を使用してい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