INT 33h AX=0000h is the first mouse call a program makes. It answers whether a mouse is installed (AX = FFFFh yes, AX = 0000h no) and how many buttons it has (BX), and it puts the driver into a known state:
| After a reset | Value |
|---|---|
| pointer | hidden (counter −1), in the middle of the screen |
| range | the whole virtual screen of the current video mode |
| event handler | removed (mask 0) |
| mickey ratio | 8 per 8 pixels across, 16 per 8 down |
| button counts | zero |
| pointer shape | the default arrow or text block |
MOV AX, 0000h ; mouse: reset and detectINT 33h ; AX = FFFFh: yes, BX = buttonsCALL PHEX4 ; FFFFMOV DL, " "MOV AH, 02h ; DOS: print the character in DLINT 21hMOV AX, BXCALL PHEX4 ; 0003 hereMOV DL, " "MOV AH, 02h ; DOS: print the character in DLINT 21hMOV AX, 0003h ; where did the reset put the pointer?INT 33h ; CX = x, DX = yMOV BX, DX ; keep y: printing uses DLMOV AX, CXCALL PDEC ; 320: half of 640MOV DL, " "MOV AH, 02h ; DOS: print the character in DLINT 21hMOV AX, BXCALL PDEC ; 96: 100 rounded down to a text rowPHEX4 PROC NEAR ; print AX as four hex digits; keeps every registerPUSH AXMOV AL, AHCALL PHEX2 ; the high byte firstPOP AXCALL PHEX2 ; then the low byteRETPHEX4 ENDPPHEX2 PROC NEAR ; print AL as two hex digits; keeps every registerPUSH AXPUSH CXPUSH DXMOV DH, AL ; keep the byteMOV CL, 4SHR AL, CL ; the high nibbleCALL HEXN1MOV AL, DHAND AL, 0Fh ; the low nibbleCALL HEXN1POP DXPOP CXPOP AXRETHEXN1:ADD AL, "0"CMP AL, "9"JBE HEXN2ADD AL, 7 ; past "9": "A".."F"HEXN2:MOV DL, ALMOV AH, 02hINT 21hRETPHEX2 ENDPPDEC PROC NEAR ; print AX in decimal; keeps every registerPUSH AXPUSH BXPUSH CXPUSH DXMOV BX, 10XOR CX, CX ; digits on the stackDECD1:XOR DX, DXDIV BX ; AX = AX / 10, DX = the last digitPUSH DXINC CXTEST AX, AXJNZ DECD1DECD2:POP DX ; the digits come back first to lastADD DL, "0"MOV AH, 02hINT 21hLOOP DECD2POP DXPOP CXPOP BXPOP AXRETPDEC ENDP
The button count
BX = 2 is a two-button mouse, 3 a three-button one (Mouse Systems, Logitech), and some drivers return FFFFh for two buttons. DOSBox-X reports 3. Do not rely on the middle button existing just because BX = 3.
Pitfalls
The reset can be slow on real hardware, up to a second or two with a serial mouse, because the driver resets the mouse too. INT 33h AX=0021h is the software-only reset (the same defaults, no hardware) and returns AX = FFFFh if a driver is there; use it when a program resets often. Call the reset after setting the video mode: the default range follows the mode current at the time. And check the vector before the first call (see INT 33h), because with no driver at all this call may go nowhere good.