Changes

Jump to: navigation, search

Kempston Mouse

190 bytes removed, 14 January
/* Get mouse position on screen */
This mouse is supported by [[The OCP Art Studio]], [[The Advanced OCP Art Studio]] and [[Carrier Command]].
It is emulated in [[Arnold (Emulator)|Arnold]] and [http://ace.cpcscene.net/en:downloads ACE].
== Pictures ==
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 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 mouseX = virtual_y virtualX if graphicsMode == 2 else (virtualX >> 1 # virtual_y/2 if graphics_mode == 2: mouse_x = virtual_x elif graphics_mode graphicsMode == 1: mouse_x = virtual_x else virtualX >> 1 # virtual_x/2) elif graphics_mode mouseY == 0: mouse_x = virtual_x virtualY >> 2 1 # virtual_xvirtualY/42
== Manual ==
4,948
edits