I fixed my program, but now the loop seems to be stuck. Whenever I press u or d, it is stuck, but the mouse part works :)
; 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
Any tips on fixing this? I tried a lot of things but it doesn't seem to work. I will try more things, but any advice is appreciated.
Thanks for your advice knm241. The above program now works fine thanks to you. The only problem that occurred was that the keyboard buffer was not clearing and thus the program would get stuck in a loop. I fixed that by clearing the buffer and now everything works.
I used this macro to clear the buffer.
and added it to FASTER and SLOWER jumps before it jumped back into the loop.