diff options
| -rw-r--r-- | include/gbos.inc | 1 | ||||
| -rw-r--r-- | src/osk.asm | 12 | ||||
| -rw-r--r-- | src/term.asm | 38 |
3 files changed, 34 insertions, 17 deletions
diff --git a/include/gbos.inc b/include/gbos.inc index 6dcefce..9b44b33 100644 --- a/include/gbos.inc +++ b/include/gbos.inc @@ -12,6 +12,7 @@ DEF rIF EQU $FF0F ; interrupt flags DEF rIE EQU $FFFF ; interrupt enable DEF rSVBK EQU $FF70 ; CGB WRAM bank select ($D000-$DFFF): 1..7 DEF wCurMask EQU $D589 ; term/osk: cursor underline bits OR'd into a tile's last row +DEF OSK_DOCK EQU 3 ; on-screen keyboard height in rows (dock at the bottom) DEF rKEY1 EQU $FF4D ; CGB speed switch DEF rSB EQU $FF01 ; serial data DEF rSC EQU $FF02 ; serial control diff --git a/src/osk.asm b/src/osk.asm index 5e316e3..609f6be 100644 --- a/src/osk.asm +++ b/src/osk.asm @@ -16,7 +16,7 @@ DEF rBCPD EQU $FF69 DEF rWY EQU $FF4A DEF rWX EQU $FF4B -DEF OSK_ROWS EQU 3 +DEF OSK_ROWS EQU OSK_DOCK DEF OSK_COLS EQU 20 DEF OSK_KEYS EQU OSK_ROWS * OSK_COLS DEF OSK_TILE0 EQU 104 ; first OSK tile index (bank 1; terminal uses 0-103) @@ -236,20 +236,16 @@ osk_toggle:: ld [wOskVisible], a or a jr z, .hide - ; show: shift the view up so the cursor line clears the keyboard - ld a, OSK_ROWS - call term_set_view + ; show: enable window, then recompute the view so the cursor clears the keys ld a, [rLCDC] or %00100000 ld [rLCDC], a - ret + jp term_write_tilemap .hide ld a, [rLCDC] and %11011111 ld [rLCDC], a - xor a ; view unshifted -> full 18-row backlog - call term_set_view - ret + jp term_write_tilemap ; offset recomputes to 0 -> full backlog ; movement with wrap-around; each moves the highlight osk_up: diff --git a/src/term.asm b/src/term.asm index fb6e870..64e45aa 100644 --- a/src/term.asm +++ b/src/term.asm @@ -80,10 +80,10 @@ term_init:: xor a ld [wCurRow], a ld [wCurCol], a + ld [wViewTop], a ; view starts unshifted (all 18 rows) + ld [wOskVisible], a ; OSK hidden until toggled ld a, 1 ld [wCursorOn], a - xor a - ld [wViewTop], a ; view starts unshifted (all 18 rows) ; clear the buffer (all slots) to spaces ld hl, TERM_BUF @@ -108,6 +108,7 @@ term_init:: ; line-slot tiles. Pass 1 = indices (bank 0), pass 2 = attributes (bank 1). ; ----------------------------------------------------------------------------- term_write_tilemap:: + call compute_offset xor a ld [rVBK], a ld c, 0 ; screen row @@ -494,18 +495,37 @@ cursor_down: inc a cp TROWS jr c, .ok - call term_scroll + call term_scroll ; rewrites the tilemap (offset recomputed) ld a, TROWS-1 -.ok ld [wCurRow], a ret +.ok + ld [wCurRow], a + ; the cursor changed rows; if the OSK is up the view offset may need to move + ld a, [wOskVisible] + or a + ret z + jp term_write_tilemap -; term_set_view - A = view-top offset. screen row -> logical row + A. 0 shows all -; 18 rows; OSK_ROWS shifts the view up so the cursor line clears the keyboard. -; No content is scrolled/lost - just remapped. -term_set_view:: +; compute_offset - set wViewTop so the cursor line is always on screen: 0 when +; the OSK is hidden; otherwise max(0, wCurRow - 14) so the cursor sits at the +; bottom visible row (14) once the terminal has filled past it, but stays put +; while there is little content (no shifting the cursor off the top). +compute_offset:: + ld a, [wOskVisible] + or a + jr nz, .osk + xor a ld [wViewTop], a - jp term_write_tilemap + ret +.osk + ld a, [wCurRow] + sub TROWS - OSK_DOCK - 1 ; wCurRow - 14 + jr nc, .store + xor a ; cursor above row 14 -> no shift +.store + ld [wViewTop], a + ret ; ----------------------------------------------------------------------------- ; term_putc - A = character. Print at the cursor, advance, handle \n \r \b. |
