aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoruser <user@clank>2026-09-24 23:08:46 +0200
committeruser <user@clank>2026-09-24 23:08:46 +0200
commit0ed3787ce6182a9198d67bb2b6ce556d21c7b1ad (patch)
treebd398978d05e52a2342f7b7a78428713683310db
parentfs: hard links - ln(1), and rm that removes a NAME (diff)
downloadgbos-0ed3787ce6182a9198d67bb2b6ce556d21c7b1ad.tar.gz
gbos-0ed3787ce6182a9198d67bb2b6ce556d21c7b1ad.tar.xz
gbos-0ed3787ce6182a9198d67bb2b6ce556d21c7b1ad.zip
term: ESC[2J, so clear(1) can actually clear
The terminal understood SGR and nothing else, so there was no way to erase the screen - printing 18 newlines only scrolls the history up out of sight. term_erase_all blanks the buffer, resets the colours, homes the cursor and repaints; the CSI parser routes 'J' to it, and clear(1) is four putc calls.
-rw-r--r--src/term.asm38
-rw-r--r--usr/clear.c10
2 files changed, 48 insertions, 0 deletions
diff --git a/src/term.asm b/src/term.asm
index 1ad120f..ea0cff7 100644
--- a/src/term.asm
+++ b/src/term.asm
@@ -877,6 +877,37 @@ update_tile_attr:
ret
; -----------------------------------------------------------------------------
+; term_erase_all - blank every cell, home the cursor and repaint. Backs ESC[2J,
+; which is what clear(1) emits; the terminal had no way to erase itself.
+; -----------------------------------------------------------------------------
+term_erase_all::
+ ld hl, TERM_BUF
+ ld de, TROWS * TSTRIDE
+.clr
+ ld a, $20 ; space
+ ld [hl+], a
+ dec de
+ ld a, d
+ or e
+ jr nz, .clr
+ ld hl, COL_BUF
+ ld de, TROWS * TSTRIDE
+.clrc
+ ld a, 7 ; default fg (white), default bg
+ ld [hl+], a
+ dec de
+ ld a, d
+ or e
+ jr nz, .clrc
+ xor a
+ ld [wCurRow], a
+ ld [wCurCol], a
+ ld [wViewTop], a
+ call term_redraw
+ call term_write_tilemap
+ ret
+
+; -----------------------------------------------------------------------------
; term_redraw - rebuild every tile from the buffer (init / full refresh).
; -----------------------------------------------------------------------------
term_redraw::
@@ -1239,6 +1270,8 @@ term_putc_body:
ld a, e
cp 109 ; 'm' : set graphics rendition
jr z, .csi_sgr
+ cp 74 ; 'J' : erase display (clear(1) sends ESC[2J)
+ jr z, .csi_ed
cp 59 ; ';' : parameter separator
jr z, .csi_sep
xor a ; unknown final byte: end the sequence
@@ -1254,6 +1287,11 @@ term_putc_body:
xor a
ld [wAnsiState], a
ret
+.csi_ed:
+ call term_erase_all
+ xor a
+ ld [wAnsiState], a
+ ret
; -----------------------------------------------------------------------------
; apply_sgr - act on the accumulated SGR parameter in wAnsiParam, updating the
diff --git a/usr/clear.c b/usr/clear.c
new file mode 100644
index 0000000..76ee4dc
--- /dev/null
+++ b/usr/clear.c
@@ -0,0 +1,10 @@
+#include "gbos.h"
+/* clear: erase the screen and home the cursor.
+ * Emits ESC[2J, which the terminal understands (see term.asm term_erase_all) -
+ * printing 18 newlines would only scroll the history up, not clear it. */
+void main(void) {
+ putc(27);
+ putc('[');
+ putc('2');
+ putc('J');
+}