assemblygraphicsx86-16dosmouse-position

how to get the mouse position in assembly


here is a part of my code, this should draw a pixel on the mouse position:

mov ax,3h       ;set interruption to getting the mouse pos
int 33h         ;after the interruption: cx=x, dx=y

mov ah, 0Ch     ;draw a pixel
;the x and y should already be in the registers cx and dx after the last interruption
mov al, 5       ;set color (to some kind of purple)
int 10h         ;the drawing should happen here, but for some reason nothing is drawn

btw, im using video mode int 10h/ah=0h/al=12h, which has a 640x480 resolution and 16 colors.


Solution

  • You are geting the mouse cursor position correctly, it should work. I wrote a sample program

    plsHelp Program Format=COM
        MOV AX,0012h
        INT 10h      ; Set graphic videomode 640*480.
    Repeat:
        MOV AX,0003h
        INT 33h      ; Get mouse position and button status.
        TEST BX,2    ; Mouse right-button pressed?
        JNZ End
        MOV AX,0C05h
        INT 10h      ; Draw a pixel at CX*DX.
        JMP Repeat
    End:RET          ; Terminate program.
       EndProgram
    

    When assembled by euroasm.exe plsHelp.asm and run as plsHelp.com in DosBox on my Windows, moving the mouse leaves a magenta track as expected. Perhaps something is wrong with your environment.