2012-10-30 2 views
2

Je fais un espace envahisseurs dans l'Assemblée 8086, pour tester que j'utilise DOSBox. Laissez-moi vous montrer mon code:Comment lire la clé sans attendre, assemblage 8086

;-------------------- 
;Update hero 
;-------------------- 
update: 
call vsync 
call update_hero ; method to read keyboard 
call set_video 
call clear_screen 
call draw_hero 
jmp update 

Maintenant, la procédure est 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 

Comme vous pouvez le voir, je suis en train de lire « un » ou « d » pour le mouvement, mais , ça ne marche pas, pouvez-vous m'aider à comprendre pourquoi? Ce que j'essaye de faire est de lire du clavier sans l'attendre, c'est pourquoi j'utilise la sous-fonction ah, 01h.

Cheers.

Modifier

J'ai vérifié pour les interruptions here, modifié le code, et maintenant ça fonctionne:

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 

Répondre

2

Vous êtes en train de vérifier s'il y a un caractère disponible, mais ne sont pas réellement en train de lire le caractère du tampon. Donc, la prochaine fois que vous vérifiez, il est toujours là.

A partir de cette page sur les fonctions du 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. 
+0

Merci, j'ai édité ma question et ajouté le code de travail. –

0

check_key:

mov  ah, 1 

int  16h 

jz  .ret 

mov  cx, 0 

xor  cl, ch 

mov  ah, 0 

int  16h 

.new.key: 

"al" est la nouvelle presh clé

.ret: 

ret 
0
update_hero proc 
mov ah, 01h 
int 16h 
cmp al, 97 
je left_pressed 
cmp al, 100 
jne none_pressed 
inc hero_x 

ret ; without the ret instruction "hero_x" will be decrease after increasing 

left_pressed: 
     dec hero_x 
none_pressed: 
ret 
update_hero endp 
Questions connexes