aboutsummaryrefslogtreecommitdiffstats
path: root/src/osk.asm
diff options
context:
space:
mode:
authoruser <user@clank>2026-07-16 16:11:06 +0200
committeruser <user@clank>2026-07-16 16:11:06 +0200
commitb565577fd371ea0a8d6255e61017e0e4f8f5b9e1 (patch)
tree5a73d87840951b84a6427d45e19a400cfb1e16ae /src/osk.asm
parentosk: toggle-able on-screen keyboard on the window layer (diff)
downloadgbos-b565577fd371ea0a8d6255e61017e0e4f8f5b9e1.tar.gz
gbos-b565577fd371ea0a8d6255e61017e0e4f8f5b9e1.tar.xz
gbos-b565577fd371ea0a8d6255e61017e0e4f8f5b9e1.zip
osk: wrap the cursor around all four edges
Left at column 0 wraps to the last column (and vice-versa); up at the top row wraps to the bottom (and vice-versa). Makes reaching far keys quicker - e.g. the Enter/space area is one UP away from the top row.
Diffstat (limited to 'src/osk.asm')
-rw-r--r--src/osk.asm46
1 files changed, 27 insertions, 19 deletions
diff --git a/src/osk.asm b/src/osk.asm
index b8ee611..490a402 100644
--- a/src/osk.asm
+++ b/src/osk.asm
@@ -246,38 +246,46 @@ osk_toggle::
ld [rLCDC], a
ret
-; movement (with clamping); each moves the highlight
+; movement with wrap-around; each moves the highlight
osk_up:
+ call osk_unhighlight
ld a, [wOskRow]
or a
- ret z
- call osk_unhighlight
- ld hl, wOskRow
- dec [hl]
+ jr nz, .d
+ ld a, OSK_ROWS ; 0 -> ROWS, so dec wraps to ROWS-1
+.d
+ dec a
+ ld [wOskRow], a
jr osk_highlight
osk_down:
- ld a, [wOskRow]
- cp OSK_ROWS-1
- ret z
call osk_unhighlight
- ld hl, wOskRow
- inc [hl]
+ ld a, [wOskRow]
+ inc a
+ cp OSK_ROWS
+ jr c, .s
+ xor a ; past bottom -> wrap to 0
+.s
+ ld [wOskRow], a
jr osk_highlight
osk_left:
+ call osk_unhighlight
ld a, [wOskCol]
or a
- ret z
- call osk_unhighlight
- ld hl, wOskCol
- dec [hl]
+ jr nz, .d
+ ld a, OSK_COLS
+.d
+ dec a
+ ld [wOskCol], a
jr osk_highlight
osk_right:
- ld a, [wOskCol]
- cp OSK_COLS-1
- ret z
call osk_unhighlight
- ld hl, wOskCol
- inc [hl]
+ ld a, [wOskCol]
+ inc a
+ cp OSK_COLS
+ jr c, .s
+ xor a
+.s
+ ld [wOskCol], a
jr osk_highlight
; -> A = type value of the selected key