Please consider a donation to the Higher Intellect project. See https://preterhuman.net/donate.php or the Donate to Higher Intellect page for more info. |
GFXMOUSE.ASM
Jump to navigation
Jump to search
;Function prototypes: ; ; int init_mouse(void) returns 0 if mouse driver not installed ; void exit_mouse(void); ; void show_mouse(void); ; void hide_mouse(void); ; void set_mouse_sens(int xsens, int ysens); ; int get_mouse_event(void); returns bits for mouse events ; int get_button_status(void); checks if buttons currently pressed down ;MOUSEMOVE = 1 ;LEFTBPRESS = 2 ;LEFTBRELEASE = 4 ;RIGHTBPRESS = 8 ;RIGHTBRELEASE = 16 DOSSEG .MODEL SMALL .386 .DATA cursor dw 0011111111111111b dw 0001111111111111b dw 0000111111111111b dw 0000011111111111b dw 0000001111111111b dw 0000000111111111b dw 0000000011111111b dw 0000000001111111b dw 0000000000111111b dw 0000000001111111b dw 0000000111111111b dw 0001000011111111b dw 1011000011111111b dw 1111100001111111b dw 1111100001111111b dw 1111110011111111b dw 0000000000000000b dw 0100000000000000b dw 0110000000000000b dw 0111000000000000b dw 0111100000000000b dw 0111110000000000b dw 0111111000000000b dw 0111111100000000b dw 0111111110000000b dw 0111111100000000b dw 0111110000000000b dw 0100011000000000b dw 0000011000000000b dw 0000001100000000b dw 0000001100000000b dw 0000000000000000b PUBLIC _mousex PUBLIC _mousey _mousex dw ? _mousey dw ? event_flags dw ? mousefreeze db ? .CODE PUBLIC _init_mouse PUBLIC _exit_mouse PUBLIC _get_mouse_event PUBLIC _get_button_status PUBLIC _set_mouse_sens PUBLIC _show_mouse PUBLIC _hide_mouse mousehandler PROC FAR push ax push cx push dx push ds push @data pop ds cmp byte ptr mousefreeze, 1 jz exit_handler mov _mousex, cx ;update mouse coordinates mov _mousey, dx mov cx, 0 test ax, 1 jz not_moved or cx, 1 not_moved: test ax, 2 ;Check LeftButton pressed jz not_leftbpress or cx, 2 not_leftbpress: test ax, 4 ;Check Left button released jz not_leftbrel or cx, 4 not_leftbrel: test ax, 8 ;Check right button pressed jz not_rightbpress or cx, 8 not_rightbpress: test ax, 16 ;Check right button released jz exit_handler or cx, 16 exit_handler: mov event_flags, cx pop ds pop dx pop cx pop ax retf mousehandler ENDP _init_mouse PROC mov ax,0 ;Mouse driver function 0 -- reset and detect int 33h cmp ax, 0 jz no_driver_installed mov mousefreeze,1 ; Freeze handler until installation completed mov dx, 639 ;Pixels horizontally mov ax, 7 ;mouse driver function 7 -- set max x range mov cx, 0 ;Minimum range int 33h mov dx, 479 ;Pixels vertically mov ax, 8 ;mouse driver function 8 -- set max y range mov cx, 0 ;Minimum range int 33h ; Now install user routine mov ax, _TEXT mov es, ax mov dx, OFFSET mousehandler mov cx, 31 ;bits for calling routine mov ax, 12 ;Function 12 -- set user routine int 33h mov cx, 0 ;xcoord mov dx, 0 ;ycoord mov ax, 4 ;mouse driver function 4 -- set mouse position int 33h mov ax, 9 ;Define cursor shape mov bx, 0 mov cx, 0 push @data pop es mov dx, OFFSET cursor int 33h mov mousefreeze, 0 ;Now the handler can start its work mov ax, 1 no_driver_installed: ret _init_mouse ENDP _exit_mouse PROC mov ax, 0 int 33h ret _exit_mouse ENDP _show_mouse PROC mov ax, 1 int 33h ret _show_mouse ENDP _hide_mouse PROC mov ax, 2 int 33h ret _hide_mouse ENDP _set_mouse_sens PROC push bp mov bp, sp mov ax, 0fh mov cx, [bp+4] mov dx, [bp+6] int 33h mov ax, 13h mov dx, [bp+8] int 33h pop bp ret _set_mouse_sens ENDP _get_mouse_event PROC mov ax,event_flags mov event_flags,0 ret _get_mouse_event ENDP _get_button_status PROC mov ax, 3 int 33h mov ax, bx ret _get_button_status ENDP END