From: sang@cm.deakin.OZ.AU (Shane Hyde)
Newsgroups: rec.games.programmer
Subject: Mouse in Mode X
Date: 5 Oct 1992 06:31:31 GMT
Organization: Deakin University, Geelong, Australia
Distribution: world
NNTP-Posting-Host: aragorn.cm.deakin.oz.au



As promised, here are some mouse routines for mode X.  they must be used in
conjuntion with Xlib02 posted recently and Tasm.  Doing it this way
means a 256 color mouse pointer (wow)

CAVEAT.
	They are hacks.  Demonstration only, to show how I did it.
	
The C interface is -

	void x_mouse_init() must be called AFTER initialising modex.
	void x_mouse_remove()
	void x_mouse_hide()
	void x_mouse_show()
and global variables
	int x_mouse_x
	int x_mouse_y
	int x_mouse_bstat
	int x_mouse_nbuts

Very primitive indeed, but it was whipped up in a few hours of reading and 
hacking.  It's really only meant as a demonstration.  The mouse pointer
is just a square block so far ( for testing) but its fairly easy to do a
set mouse image routine

Sorry it's not commented more, but what the hell!

Shane..(sang@cm.deakin.oz.au)

P.S.  If any one knows a better way, mail me.
P.P.S. No flames please.  I'm a shithouse assembly coder (I already know).
-----Cut here --------
COMMENT $
***** Xmouse.asm
***** Copyright (C)1992
***** Shane hyde
$

.286
.model large

include xlib.inc
include xpbitmap.inc

global  _x_mouse_init   :proc
global  _x_mouse_remove :proc
global  _x_mouse_show   :proc
global  _x_mouse_hide   :proc
global  _x_mouse_x       :word
global  _x_mouse_y       :word
global  _x_mouse_nbuts   :word
global  _x_mouse_bstat   :word

.data
        mo_exists       dw 0
        _x_mouse_nbuts   dw 0

        _x_mouse_bstat   dw 0
        _x_mouse_x       dw 0
        _x_mouse_y       dw 0
        _x_mouse_hidden  dw 0

        oldx            dw 0
        oldy            dw 0
        onlast          dw 0

        mouse_data_seg  dw 0
        olmask          dw 0
        olr_seg         dw 0
        olr_off         dw 0

mouseimage label dword
        db 4
        db 16
        db 256 dup (55)

backimage  label dword
        db 0
        db 0
        db 300 dup (0)
.code
        assume ds:@data

remove_old proc near
        mov ax,SEG backimage    ; restore background image
        push ax
        mov ax,OFFSET backimage
        push ax
        mov ax,_VisiblePageOffs
        push ax
        push oldy
        push oldx
        call _x_put_pbm
        add sp,0ah
        ret
remove_old endp


mo_handler proc far
        push bp
        mov bp,sp

        push ds
        mov ax,@data
        mov ds,ax

        mov _x_mouse_x,cx            ; Store the info in the globals
        mov _x_mouse_y,dx
        mov _x_mouse_bstat,bx

        cmp _x_mouse_hidden,1
        je @@MouseHidden

        mov ax,onlast           ; Should we restore the background
        cmp ax,1
        jne @@DontRestore

        call remove_old

@@DontRestore:
        mov ax,_x_mouse_x            ; remember x,y for next round
        mov oldx,ax

        mov ax,_x_mouse_y
        mov oldy,ax


        mov onlast,1

        mov ax,SEG backimage    ; save background
        push ax
        mov ax,OFFSET backimage
        push ax
        mov ax,_VisiblePageOffs
        push ax
        push 10h
        push 04h
        push _x_mouse_y
        push _x_mouse_x
        call _x_get_pbm
        add sp,0eh

        mov ax,SEG mouseimage           ; show mouse pointer
        push ax
        mov ax,OFFSET mouseimage
        push ax
        mov ax,_VisiblePageOffs
        push ax
        push _x_mouse_y
        push _x_mouse_x
        call _x_put_masked_pbm
        add sp,0ah

@@MouseHidden:
        pop ds
        pop bp
        ret
mo_handler endp

init_handler proc near
        mov ax,14h
        mov bx,SEG mo_handler
        mov es,bx
        mov dx,OFFSET mo_handler
        mov cx,0bh
        int 33h
        mov olmask,cx
        mov bx,es
        mov olr_seg,bx
        mov olr_off,dx
        ret
init_handler endp

;Routine to install the mouse for Mode X
;C-callable as x_mouse_init()
;
;
;
;
;
;
_x_mouse_init proc
        push bp         ; preserve stack frame
        mov bp,sp

        push ds         ; set local data segment
        mov ax,@data
        mov ds,ax

        mov ax,0000h    ; initialise mouse driver
        int 33h

        mov mo_exists,ax
        cmp ax,0
        je @@Finished   ; No mouse driver

        cmp bx,0ffffh    ; Find out how many buttons
        jne @@Jump3buts
        mov _x_mouse_nbuts,2
        jmp @@ButtonsDone
@@Jump3buts:
        mov _x_mouse_nbuts,bx
@@ButtonsDone:
        mov cx,ds
        mov mouse_data_seg,cx

        mov ax,02h      ; Hide the real pointer
        int 33h

        mov _x_mouse_hidden,0 ; show the logical

        mov ax,07h      ;set boundaries for the mouse
        mov cx,0
        mov dx,_ScrnPhysicalPixelWidth
        int 33h

        mov ax,08h
        mov cx,0
        mov dx,_ScrnPhysicalHeight
        int 33h

        call init_handler
@@Finished:
        pop ds          ; fix up segments
        pop bp
        ret
_x_mouse_init endp

; Remove the mouse
; C-callable as x_mouse_remove()
;
_x_mouse_remove proc
        push bp
        mov bp,sp

        push ds
        push si
        push di

        mov ax,@data
        mov ds,ax

        mov ax,14h              ; remove the handler
        mov bx,olr_seg
        mov es,bx
        mov dx,olr_off
        mov cx,olmask
        int 33h

        call remove_old

        mov onlast,0
        pop di
        pop si
        pop ds
        pop bp
        ret
_x_mouse_remove endp


_x_mouse_hide proc
        push bp
        mov bp,sp

        mov _x_mouse_hidden,1
        mov onlast,0
        call remove_old
        pop bp
        ret
_x_mouse_hide endp

_x_mouse_show proc
        push bp
        mov bp,sp

        mov _x_mouse_hidden,0
        pop bp
        ret
_x_mouse_show endp


end

--
Shane Hyde (sang@cm.deakin.oz.au)|'Tell me, who's the real patriots, the Archie
Dept. of Computing/Mathematics   |Bunker slobs waving flags, or the people with
Deakin University                |the guts to work for some real change?' -
Geelong Vic 3217                 |                 Jello Biafra.