Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
TITLE PROGRAM 5-4: DISPLAYING MOUSE POSITION
;Performs the following tasks: (a) gets the current video mode and saves it, (b) sets the mode to a new video ;mode, (c) gets the mouse pointer position, converts it to character position and displays it continuously unless a ;key is pressed, (d) upon pressing any key, it restores the original video mode and exits to DOS.
ASM
PAGE    60,132
CURSOR  	MACRO ROW,COLUMN
        	MOV 	AH,02H
        	MOV 	BH,00
        	MOV 	DH,ROW
        	MOV 	DL,COLUMN
                INT     10H
        	ENDM
DISPLAY         MACRO STRING
        	MOV 	AH,09H
        	MOV 	DX,OFFSET STRING 	;load string address
                INT     21H
        	ENDM

                .MODEL SMALL
                .STACK
                .DATA
MESSAGE_1   	DB 'PRESS ANY KEY TO GET OUT','$'
MESSAGE_2   	DB 'THE MOUSE CURSOR IS LOCATED AT ','$'
POS_HO         	DB ?,?, ' AND $'
POS_VE          DB ?,?,'$'
OLDVIDEO        DB ?                    ;current video mode
NEWVIDEO    	DB 0EH         		;new video mode
                .CODE
MAIN            PROC   
       		MOV 	AX,@DATA
   		MOV 	DS,AX
        	MOV 	AH,0FH         		;get current video mode
                INT     10H
        	MOV 	OLDVIDEO,AL   		;save it
        	MOV 	AX,0600H     		;clear screen
        	MOV 	BH,07
        	MOV 	CX,0
        	MOV 	DX,184FH
                INT     10H
        	MOV 	AH,00H       		;set new video mode
        	MOV 	AL,NEWVIDEO
                INT     10H
                MOV     AX,0                    ;initialize mouse
                INT     33H
        	MOV 	AX,01      		;show mouse cursor
                INT     33H          
        	CURSOR 20,20
        	DISPLAY MESSAGE_1
AGAIN:  	MOV 	AX,03H       		;get mouse location
                INT     33H         
        	MOV 	AX,CX			;get the hor. pixel position
                CALL    CONVERT                 ;convert to displayable data
        	MOV 	POS_HO,AL		;save the LSD 
        	MOV 	POS_HO+1,AH		;save  the MSD
        	MOV 	AX,DX			;get the vert. pixel position
                CALL    CONVERT                 ;convert
        	MOV 	POS_VE,AL		;save
        	MOV 	POS_VE+1,AH		
        	CURSOR 5,20      		;
        	DISPLAY MESSAGE_2 ;
        	DISPLAY POS_HO
        	DISPLAY POS_VE
                MOV     AH,01                ;check for key press
                INT     16H
                JZ      AGAIN                ;if no key press, keep monitoring mouse position
                MOV     AH,02                ;hide mouse
                INT     33H           
                MOV     AH,0                 ;restore original video mode
                MOV     AL,OLDVIDEO          ;load original video mode
                MOV     AH,0                 ;restore original video mode
                MOV     AL,OLDVIDEO          ;load original video mode
                INT     10H
                MOV     AH,4CH               ;go back to DOS      
                INT     21H         
MAIN    	ENDP
;--------------------
;divide pixels position by 8 and convert to ASCII to make it displayable 
;ax=pixels position (it is in hex)
;on return ax= two ASCII digits
CONVERT 	PROC
                SHR     AX,1          ;divide
                SHR     AX,1          ;by 8
                SHR     AX,1          ;to get screen position by character
        	MOV 	BL,10         
        	SUB 	AH,AH
                DIV     BL     ;divide by ten to convert from hex. to decimal
                OR      AX,3030H      ;make it ASCII
                RET                   ;return with AX=two ASCII digits
CONVERT 	ENDP
	   	END     MAIN
Posted
Updated 10-Dec-14 23:40pm
v2
Comments
barneyman 11-Dec-14 20:46pm    
it's fairly obvious what it's doing - even if you can't read 8086 assembler, the comments are fairly explicit - have a look for a guide to 8086 assembler, to work out what MOV, SHR, et al do, and (golden oldie) Ralph Brown's Interrupt List (http://www.ctyme.com/rbrown.htm) will help with what the INT calls are doing

1 solution

No.

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900