Here is the algorithm in pseudo-code:
// initMouse initializes variables and centers the mouse pointer on screen
function initMouse() {
maxX = 639;
maxY = 399;
// refreshMouse has to be called before you redraw the mouse pointer (ideally every frame)
function refreshMouse() {
// get raw mouse values
rawX = inp(&FBEE);