; ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
; ³ (c) Lord Julus - 2000                Vxtasy #1 - Magazine source code ³
; ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

;=========( Procedure to init the mouse )====================================

init_mouse proc near
        pusha
        xor ax, ax
        int 33h
        cmp ax, 0
        je no_mouse_found
        mov mouse, 1

        mov ax, 0ah
        mov bx, 0
        mov cx, 87ffh
        mov dx, 4d00h
        int 33h


        push es
        push cs
        pop es
        mov dx, offset mouse_handler
        mov ax, 0ch
        mov cx, 007fh
        int 33h

;        call show_mouse

        pop es
        jmp exit_mouse

no_mouse_found:
        mov mouse, 0

exit_mouse:
        popa
        ret
init_mouse endp

;=========( Procedure to hide the mouse )====================================

hide_mouse proc near
        mov ax, 02h
        int 33h
        ret
hide_mouse endp

;=========( Procedure to show the mouse )====================================

show_mouse proc near
        mov ax, 01h
        int 33h
        ret
show_mouse endp

;=========( The mouse handler )==============================================

mouse_handler proc near
        cmp in_gfc, 1
        je handle_gfc

        cmp disable, 1
        je exit_for_all

        cmp ax, 1
        jne buttons

        shr cx, 3
        shr dx, 3

        mov mouse_oriz, cx
        mov mouse_vert, dx

        mov pressed_like_enter, 0

        cmp dl, menu_bar_row
        jne no_col_found

        mov dx, cx

        mov cx, max_menu_item
        mov bx, 1
        lea si, menu_bar_xcoord

repeat_compare_xcoord:
        lodsw
        mov left_coord, ax
        lodsw
        mov right_coord, ax

        cmp dx, left_coord
        ja maybe_this_col
        jmp no_this_one

maybe_this_col:
        cmp dx, right_coord
        jb sure_this_col

no_this_one:
        inc bx
        loop repeat_compare_xcoord
        jmp no_col_found

sure_this_col:
        cmp current_popup, bx
        je no_movement

        mov current_popup, bx
        mov actualizate, 1
        mov onlyactualize, 0

     pusha
     lea di, pop_pos                    ;
     mov cx, current_popup              ;
     shl cx, 1                          ;
     add di, cx                         ;
     dec di                             ;
     dec di                             ;
     mov ax, word ptr [di]              ;
     mov current_popit, ax              ;
     popa

     mov ax, true
     mov showpopup, ax
        jmp no_movement

no_col_found:

; try for popup:
        mov actualizate, 0

        mov cx, mouse_oriz
        mov dx, mouse_vert

        lea si, popup_coords
        mov cx, popup_height
        mov bx, 1

repeat_compare_xcoord2:
        push cx
        lodsw
        cmp ax, dx
        jne no_rite_row

        lodsw
        mov left_coord, ax
        lodsw
        mov right_coord, ax

        mov cx, mouse_oriz

        cmp cx, left_coord
        jae maybe_this_col2
        jmp no_this_one2

maybe_this_col2:
        cmp cx, right_coord
        jbe sure_this_col2


no_rite_row:
        lodsw
        lodsw
        inc bx

no_this_one2:
        pop cx
        loop repeat_compare_xcoord2
        jmp no_movement

sure_this_col2:
        pop cx
        mov ax, current_popit
        cmp ax, bx
        je no_movement
        mov current_popit, bx
        mov actualizate, 1
        mov onlyactualize, 1

no_movement:
;        call show_mouse
        retf

buttons:
        or ax, 02h
        cmp ax, 02h
        jne exit_for_all

        mov pressed_like_enter, 0
        mov actualizate, 0

        cmp no_popup, 1
        je already_correct

        mov cx, mouse_oriz
        mov dx, mouse_vert

        lea si, popup_coords
        mov cx, popup_height
        mov bx, 1

repeat_compare_xcoord3:
        push cx
        lodsw
        cmp ax, dx
        jne no_rite_row3

        lodsw
        mov left_coord, ax
        lodsw
        mov right_coord, ax

        mov cx, mouse_oriz

        cmp cx, left_coord
        jae maybe_this_col3
        jmp no_this_one3

maybe_this_col3:
        cmp cx, right_coord
        jbe sure_this_col3


no_rite_row3:
        lodsw
        lodsw
        inc bx

no_this_one3:
        pop cx
        loop repeat_compare_xcoord3
        jmp no_movement

sure_this_col3:
        pop cx

already_correct:
        mov pressed_like_enter, 1

exit_for_all:
        retf

handle_gfc:
        or ax, 2
        cmp ax, 2
        jne no_push

        shr cx, 3
        shr dx, 3

        mov mouse_oriz, cx
        mov mouse_vert, dx
        mov button_pressed, 1

no_push:
        mov button_pressed, 0
        retf

mouse_handler endp
