#include "typedefs.h"

//Global variables, storing the coordinates and the button press information
WORD MouseX, MouseY, MouseB, ActX, ActY;

char IfMouse();
void ShowMouse();
void HideMouse();
void ReadMouse();
void SetMousePos(WORD X, WORD Y);
void SetMinMaxX(WORD Min, WORD Max);
void SetMinMaxY(WORD Min, WORD Max);

//This procedure checks if a mouse is available
char IfMouse() {

    WORD Result;
    asm {
        xor ax, ax
        int 0x33
        mov Result, ax
    }
    return Result;
}

//This procedure makes the mouse cursor visible
void ShowMouse() {
    asm {
        mov ax, 0x1
        int 0x33
    }
}

//This procedure makes the mouse cursor invisible
void HideMouse() {
    asm {
        mov ax, 0x2
        int 0x33
    }
}

//This procedure reads the location of the mouse cursor and the button press
//information
void ReadMouse() {

    asm {
        mov ax, 0x3
        int 0x33
        mov MouseB, bx
        mov MouseX, cx
        mov MouseY, dx
        shr cx, 3
        shr dx, 3
        mov ActX, cx
        mov ActY, dx
    }
}

//This procedure sets the mouse cursor to another location
void SetMousePos(WORD X, WORD Y) {

    asm {
        mov ax, 0x4
        mov cx, X
        mov dx, Y
        int 0x33
    }
}

//This procedure sets the minimum and maximum values that the mouse cursor
//may reach in horizontal range
void SetMinMaxX (WORD Min, WORD Max) {

    asm {
        mov ax, 0x7
        mov cx, Min
        mov dx, Max
        int 0x33
    }
}


//This procedure sets the minimum and maximum values that the mouse cursor
//may reach in vertical range
void SetMinMaxY (WORD Min, WORD Max) {

    asm {
        mov ax, 0x8
        mov cx, Min
        mov dx, Max
        int 0x33
    }
}