Skip to content

Commit

Permalink
added cx16.mouse_present() routine to check for presence of mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Sep 6, 2024
1 parent 2396f70 commit f7feaf1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
8 changes: 8 additions & 0 deletions compiler/res/prog8lib/cx16/syslib.p8
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,14 @@ asmsub mouse_pos() -> ubyte @A, uword @R0, uword @R1, byte @X {
}}
}

sub mouse_present() -> bool {
; -- check if a mouse is connected to the machine
cx16.r0L, void = cx16.i2c_read_byte($42, $22) ; $22 = I2C_GET_MOUSE_DEVICE_ID
if_cs
return false
return cx16.r0L != $fc ; $fc = BAT_FAIL
}

; shims for the kernal routines called via the extapi call:

asmsub mouse_set_pos(uword xpos @R0, uword ypos @R1) clobbers(X) {
Expand Down
3 changes: 3 additions & 0 deletions docs/source/todo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ in overwriting registers that already got their value, which requires a lot of s
Maybe this routine can be made more intelligent. See usesOtherRegistersWhileEvaluating() and argumentsViaRegisters().


Regenerate skeletons in doc.


Future Things and Ideas
^^^^^^^^^^^^^^^^^^^^^^^
Compiler:
Expand Down
19 changes: 1 addition & 18 deletions examples/test.p8
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,6 @@

main {
sub start() {
uword active_world = memory("world", 80*50, 0)
uword @shared cell_off = 500
uword @shared cell_off_1 = cell_off+1
const uword STRIDE = 40
sys.memset(active_world, 80*50, 1)

txt.print_ub(active_world[500] + active_world[501]) ; 2
txt.nl()
txt.print_ub(active_world[cell_off] + active_world[cell_off_1]) ; 2
txt.nl()
txt.print_ub(count()) ; 8
txt.nl()

sub count() -> ubyte {
return active_world[cell_off-STRIDE-1] + active_world[cell_off-STRIDE] + active_world[cell_off-STRIDE+1] +
active_world[cell_off-1] + active_world[cell_off+1] +
active_world[cell_off+STRIDE-1] + active_world[cell_off+STRIDE] + active_world[cell_off+STRIDE+1]
}
txt.print_bool(cx16.mouse_present())
}
}

0 comments on commit f7feaf1

Please sign in to comment.