From b6c039589fadbf22316ea5b3f81628bdd2aceff2 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Fri, 15 May 2020 20:51:09 -0400 Subject: [PATCH] Don't emit BS when at beginning of input buffer --- blk/427 | 4 ++-- blk/428 | 12 ++++++------ emul/forth.bin | Bin 5919 -> 5921 bytes 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/blk/427 b/blk/427 index f3eb716..a53ca85 100644 --- a/blk/427 +++ b/blk/427 @@ -1,10 +1,10 @@ ( handle backspace: go back one char in IN>, if possible, then - emit SPC + BS ) + emit BS + SPC + BS ) : (inbs) ( already at IN( ? ) IN> @ IN( = IF EXIT THEN IN> @ 1- IN> ! - SPC BS + BS SPC BS ; : KEY diff --git a/blk/428 b/blk/428 index 2412b93..f915b88 100644 --- a/blk/428 +++ b/blk/428 @@ -1,16 +1,16 @@ -: (rdlnc) ( -- f ) +: (rdlnc) ( -- c ) ( buffer overflow? same as if we typed a newline ) - IN> @ IN) = IF 0x0a ELSE KEY THEN ( c ) + IN> @ IN) = IF 0x0a ELSE KEY THEN ( c ) DUP 0x7f = IF DROP 0x8 THEN ( del? same as backspace ) DUP 0x0a = IF DROP 0xd THEN ( lf? same as cr ) - ( echo back ) - DUP EMIT ( c ) ( bacspace? handle and exit ) DUP 0x8 = IF (inbs) EXIT THEN + ( echo back ) + DUP EMIT ( c ) ( write and advance ) - DUP ( keep as result ) ( c c ) + DUP ( keep as result ) ( c c ) ( We take advantage of the fact that c's MSB is always zero and thus ! automatically null-terminates our string ) - IN> @ ! 1 IN> +! ( c ) + IN> @ ! 1 IN> +! ( c ) ( if newline, replace with zero to indicate EOL ) DUP 0xd = IF DROP 0 THEN ; diff --git a/emul/forth.bin b/emul/forth.bin index 04694fd0121bbb02b39ddcc4ff7fe8011da0c04c..7b72c2f880a03ec2a47de6a905d23fc253aa9e77 100644 GIT binary patch delta 239 zcmbQQw@{DsFgN324MqlrHyb&R3i9yqyYln!J27~>MygD{A!x&RXR@e}x{v|`2LmHp zIs+TSRzW8Q7N&!Ill_Erm>7j7*9aLiR!-g^WWqRW@>8K`Wkz9Fegy^xhKJ0i%uT$a z%q&bGo+z^-(@vn+S|DF~awI(u~(8hly4)c1*q?I+d|!a+;Vc PvLbQ^xZSp12sf=BdGsIjOCr@4{W(FjmirD}F8ALjM