Changes

Jump to: navigation, search

Kempston Mouse

59 bytes removed, 07:57, 10 August 2023
Undo revision 111767 by [[Special:Contributions/Phi2x|Phi2x]] ([[User talk:Phi2x|talk]]) snake case is too ugly
Here is the algorithm in pseudo-code:
# init_mouse initMouse initializes variables and centers the mouse pointer on screen def init_mouseinitMouse(): max_x maxX = 639 max_y maxY = 399
# centering the mouse pointer on the screen
virtual_x virtualX = max_x maxX >> 1 # max_xmaxX/2 virtual_y virtualY = max_y maxY >> 1 # max_ymaxY/2
# store raw mouse values
old_x oldX = inp(&FBEE) old_y oldY = inp(&FBEF)
# get mouse pointer position
refresh_mouserefreshMouse()
# refresh_mouse refreshMouse has to be called before you redraw the mouse pointer (and ideally on every frame) def refresh_mouserefreshMouse():
# get raw mouse values
raw_x rawX = inp(&FBEE) raw_y rawY = inp(&FBEF)
# get the relative mouse displacement since last call
delta_x deltaX = raw_x rawX - old_xoldX delta_y deltaY = raw_y rawY - old_yoldY
# store raw mouse values
old_x oldX = raw_xrawX old_y oldY = raw_yrawY
# calculate new unclipped virtual position
virtual_x virtualX = virtual_x virtualX + delta_xdeltaX virtual_y virtualY = virtual_y virtualY - delta_y deltaY # Kempston mouse Y-axis is inverted compared to screen coordinates!
# perform clipping
if virtual_x virtualX < 0: virtual_x virtualX = 0 elif virtual_x virtualX > max_xmaxX: virtual_x virtualX = max_xmaxX if virtual_y virtualY < 0: virtual_y virtualY = 0 elif virtual_y virtualY > max_ymaxY: virtual_y virtualY = max_ymaxY
# now we translate position from the virtual screen to the current CPC screen mode
mouse_y mouseY = virtual_y virtualY >> 1 # virtual_yvirtualY/2 if graphics_mode graphicsMode == 2: mouse_x mouseX = virtual_xvirtualX elif graphics_mode graphicsMode == 1: mouse_x mouseX = virtual_x virtualX >> 1 # virtual_xvirtualX/2 elif graphics_mode graphicsMode == 0: mouse_x mouseX = virtual_x virtualX >> 2 # virtual_xvirtualX/4
== Manual ==
8,324
edits