Here is the algorithm in pseudo-code:
// # initMouse initializes variables and centers the mouse pointer on screen function def initMouse() {: maxX = 639; maxY = 399; // # centering the mouse pointer on the screen virtualX = maxX >> 1; // # virtualX = maxX/2 virtualY = maxY >> 1; // # virtualY = maxY/2 // # store raw mouse values oldX = inp(&FBEE); oldY = inp(&FBEF); // # get mouse pointer position refreshMouse(); }
// # refreshMouse has to be called before you redraw the mouse pointer (and ideally on every frame) function def refreshMouse() {: // # get raw mouse values rawX = inp(&FBEE); rawY = inp(&FBEF); // # get the relative mouse displacement since last call deltaX = rawX - oldX; deltaY = rawY - oldY; // # store raw mouse values oldX = rawX; oldY = rawY; // # calculate new unclipped virtual position virtualX = virtualX + deltaX; virtualY = virtualY - deltaY; // # Kempston mouse Y-axis is inverted compared to screen coordinates! // # perform clipping if (virtualX < 0) then : virtualX = 0; else if ( elif virtualX > maxX) then : virtualX = maxX; if (virtualY < 0) then : virtualY = 0; else if ( elif virtualY > maxY) then : virtualY = maxY; // # now we translate position from the virtual screen to the current CPC screen mode mouseY = virtualY >> 1; // # mouseY = virtualY/2 if (mode2) then graphicsMode == 2: mouseX = virtualX; else if (mode1) then elif graphicsMode == 1: mouseX = virtualX >> 1; // # mouseX = virtualX/2 else if (mode0) then elif graphicsMode == 0: mouseX = virtualX >> 2; // # mouseX = virtualX/4 }
== Manual ==