Skip to main content

Mouse

The Hybrix virtual computer supports a virtual mouse input device. Mouse input is provided by moving your real mouse pointer over the Hybrix emulator screen. If you click on the emulator screen, the real mouse will become "captured" so that you can more accurately control the virtual computer. To release the capture, press the ESC key on your keyboard.

The io::mouse location uses the same io_hand_controller class as gamepad devices. However, the io_hand_controller.x and io_hand_controller.y fields behave differently: For a gamepad, these return the absolute position of the analog stick or directional controller. For the mouse, they are motion counters. For example, x will increase when you move the mouse to the right, and decrease when you move to the left. The value of x does not correspond to an absolute position, and the counter will simply roll over if it reaches the pair limits of 32,767 or -32,768.

Reading the mouse

Suppose we want to show a mouse pointer on the screen, for example an arrow sprite. Its position will be sprite_x and sprite_y. The program below illustrates how to read the io::mouse counters, calculate their amount of change ("delta"), and then update the pointer location by adding the change.

module example
var sprite_x: int
var sprite_y: int

var _last_mouse_x: pair
var _last_mouse_y: pair

func update()
var mouse_x: pair
var mouse_y: pair

# raw values
mouse_x <- io::mouse.x
mouse_y <- io::mouse.y

var delta_x: pair
var delta_y: pair

# "delta" is the change since last update()
delta_x <- to_pair(mouse_x - example::_last_mouse_x)
delta_y <- to_pair(mouse_y - example::_last_mouse_y)

example::_last_mouse_x <- mouse_x
example::_last_mouse_y <- mouse_y

# Apply the change to our mouse pointer sprite
example::sprite_x <- example::sprite_x + delta_x
example::sprite_y <- example::sprite_y + delta_y

# Constrain the mouse pointer sprite to stay on the screen
if example::sprite_x < 0
do example::sprite_x <- 0
if example::sprite_x >= 320
do example::sprite_x <- 319

if example::sprite_y < 0
do example::sprite_y <- 0
if example::sprite_y >= 224
do example::sprite_y <- 223
end func
end module

I/O definitions

class io_hand_controller # size 8
# 0 = disabled
# 1 = gamepad
# 16 = mouse (x and y are rolling counters)
var kind: byte

# +1 = a / mouse main button
# +2 = b / mouse middle button
# +4 = c / mouse secondary button
# +8 = d
var buttons: byte

# Gamepad: (left) -1023 .. +1023 (right)
var x: pair

# Gamepad: (up) -1023 .. +1023 (down)
var y: pair

var reserved: pair
end class
module io
. . .
inset mouse: io_hand_controller located at $d0_0078
. . .
end module