使输入等待鼠标或键盘 - 汇编语言
Make the input wait for mouse or keyboard - Assembly Language
我修复了我的程序,但现在循环似乎卡住了。每当我按 u 或 d 时,它就会卡住,但鼠标部分可以工作:)
; You may customize this and other start-up templates;
; The location of this template is c:\emu8086\inc[=10=]_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
关于解决此问题的任何提示?我尝试了很多东西,但似乎没有用。我会尝试更多的东西,但任何建议表示赞赏。
您在寻找这个中断服务吗? INT16/AH=01h
你可以这样使用
mov ah, 01h
int 16h
jz _no_keyboard_input_present
jnz _keyboard_input_present
感谢您的建议 knm241。
多亏了你,上面的程序现在可以正常工作了。发生的唯一问题是键盘缓冲区没有清除,因此程序会陷入循环。我通过清除缓冲区解决了这个问题,现在一切正常。
我用这个宏来清除缓冲区。
BUFFER MACRO
MOV AH,0C
MOV AL,0
INT 21H
ENDM
并在它跳回循环之前将其添加到 FASTER 和 SLOWER 跳转中。
我修复了我的程序,但现在循环似乎卡住了。每当我按 u 或 d 时,它就会卡住,但鼠标部分可以工作:)
; You may customize this and other start-up templates;
; The location of this template is c:\emu8086\inc[=10=]_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
关于解决此问题的任何提示?我尝试了很多东西,但似乎没有用。我会尝试更多的东西,但任何建议表示赞赏。
您在寻找这个中断服务吗? INT16/AH=01h
你可以这样使用
mov ah, 01h
int 16h
jz _no_keyboard_input_present
jnz _keyboard_input_present
感谢您的建议 knm241。 多亏了你,上面的程序现在可以正常工作了。发生的唯一问题是键盘缓冲区没有清除,因此程序会陷入循环。我通过清除缓冲区解决了这个问题,现在一切正常。
我用这个宏来清除缓冲区。
BUFFER MACRO
MOV AH,0C
MOV AL,0
INT 21H
ENDM
并在它跳回循环之前将其添加到 FASTER 和 SLOWER 跳转中。