输入等待鼠标或键盘 - 汇编语言

时间:2015-06-18 02:49:08

标签: assembly input keyboard mouse simultaneous

我修复了我的程序,但现在循环似乎被卡住了。每当我按 u d 时,它就会卡住,但鼠标部分可以工作:)

; You may customize this and other start-up templates; 
; The location of this template is c:\emu8086\inc\0_com_template.txt

org 100h

CLEAR   MACRO
    MOV AX,0600H
    MOV BH,07
    MOV CX,0000
    MOV DX,184FH
    INT 10H
  ENDM  

CURSOR  MACRO Col, Row
    MOV AH,02
    MOV BH,00
    MOV DL,Col
    MOV DH,Row
    INT 10H
  ENDM

DISP   MACRO MES
    MOV AH,09
    MOV DX,OFFSET MES
    INT 21H
ENDM

CLEARLINE MACRO ROW
    CURSOR 00,ROW
    DISP SPACES

ENDM





.MODEL SMALL ; RUN THE PROGRAM IN DIMENSIONS 79x24 
.STACK 64H
.DATA

OPTION1         DB      '1. Press "U" to Speed up the motor','$'
OPTION2         DB      '2. Press "D" to Slow Down the motor','$'
OPTION3         DB      '1. Right click the mouse to turn motor direction to clockwise','$'
OPTION4         DB      '2. Left click the mouse to turn the motor direction to anti-clockwise','$'
SPEEDUP         DB      'DC motor is speeding up ','$'
SLOWDOWN        DB      'DC motor is slowing down','$'
RIGHT           DB      'DC motor will now rotate clockwise','$'
LEFT            DB      'DC motor will now rotate anti-clockwise','$'
SPACES          DB      '                                                                                    ','$'





.CODE
MAIN:   MOV AX,@DATA
        MOV DS, AX
        CLEAR
        CURSOR 24,9
        DISP OPTION1
        CURSOR 24,10
        DISP OPTION2
        CURSOR 14,13
        DISP OPTION3
        CURSOR 8,14
        DISP OPTION4
L0:     MOV AH, 01H
        INT 16h
        JZ MOUSETIME
        JNZ COMPARE

COMPARE: CMP AL,'U'
        JE FASTER
        CMP AL,'u'
        JE FASTER
        CMP AL,'D'
        JE SLOWER
        CMP AL,'d'
        JE SLOWER

MOUSETIME:  MOV AX,03
        INT 33H
        CMP BX,0
        JZ L0
        JNZ SKIP
SKIP:   CMP BX,1    ;MOUSE LEFT
        JE MRIGHT
        CMP BX,2    ;MOUSE RIGHT
        JE MLEFT

FASTER: CLEARLINE 19
        CURSOR 27,19
        DISP SPEEDUP
        JMP L0

SLOWER: CLEARLINE 19
        CURSOR 27,19
        DISP SLOWDOWN
        JMP L0

MRIGHT: CLEARLINE 19
        CURSOR 18,19
        DISP RIGHT
        JMP L0

MLEFT:  CLEARLINE 19
        CURSOR 18,19
        DISP LEFT
        JMP L0

        MOV AH, 4CH
        INT 21H
    END MAIN

ret

有关解决此问题的任何提示吗?我尝试了很多东西,但它似乎没有用。我会尝试更多的东西,但任何建议都表示赞赏。

2 个答案:

答案 0 :(得分:1)

您在寻找这种中断服务吗? INT16/AH=01h

你可以这样使用

mov ah, 01h
int 16h
jz _no_keyboard_input_present
jnz _keyboard_input_present

答案 1 :(得分:0)

感谢您的建议knm241。 上面的程序现在可以正常工作,谢谢你。发生的唯一问题是键盘缓冲区没有清除,因此程序会陷入循环。我通过清除缓冲区来修复它,现在一切正常。

我用这个宏来清除缓冲区。

Error: error:0906A068:PEM routines:PEM_do_header:bad password read
at Error (native)
at Object.createSecureContext (_tls_common.js:108:19)
at Object.exports.connect (_tls_wrap.js:852:21)
at apnSocket (/home/Slurp/node_modules/apn/lib/socket.js:56:19)
at Connection.<anonymous> (/home/Slurp/node_modules/apn/lib/connection.js:188:17)
at _fulfilled (/home/Slurp/node_modules/apn/node_modules/q/q.js:834:54)
at self.promiseDispatch.done (/home/Slurp/node_modules/apn/node_modules/q/q.js:863:30)
at Promise.promise.promiseDispatch (/home/Slurp/node_modules/apn/node_modules/q/q.js:796:13)

并将其添加到FASTER和SLOWER之前跳回到循环中。