From 7c692c11113f0ae63f76deb7ab3733ea942a7ecd Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sun, 26 Apr 2020 14:52:55 -0400 Subject: [PATCH] recipes/rc2014: include readln directly in stage 1 XPACK is more efficient than stripfc was, we can pack more stuff in 8K. We now have enough space to fit readln. --- forth/readln.fs | 87 ----------------------------------------- recipes/rc2014/README.md | 59 +++++----------------------- recipes/rc2014/eeprom/README.md | 48 ++++++++++++++++++++--- recipes/rc2014/xcomp.fs | 5 +-- 4 files changed, 54 insertions(+), 145 deletions(-) delete mode 100644 forth/readln.fs diff --git a/forth/readln.fs b/forth/readln.fs deleted file mode 100644 index a10a1ed..0000000 --- a/forth/readln.fs +++ /dev/null @@ -1,87 +0,0 @@ -( requires core, parse, print ) - -( Managing variables in a core module is tricky. Sure, we - have (sysv), but here we need to allocate a big buffer, and - that cannot be done through (sysv). What we do is that we - allocate that buffer at runtime and use (sysv) to point to - it, a pointer that is set during the initialization - routine. ) - -64 CONSTANT INBUFSZ -: RDLNMEM+ 0x53 RAM+ @ + ; -( current position in INBUF ) -: IN> 0 RDLNMEM+ ; -( points to INBUF ) -: IN( 2 RDLNMEM+ ; -( points to INBUF's end ) -: IN) INBUFSZ 2+ RDLNMEM+ ; - -( flush input buffer ) -( set IN> to IN( and set IN> @ to null ) -: (infl) 0 IN( DUP IN> ! ! ; - -( handle backspace: go back one char in IN>, if possible, then - emit SPC + BS ) -: (inbs) - ( already at IN( ? ) - IN> @ IN( = IF EXIT THEN - IN> @ 1- IN> ! - SPC BS -; - -( read one char into input buffer and returns whether we - should continue, that is, whether CR was not met. ) -: (rdlnc) ( -- f ) - ( buffer overflow? same as if we typed a newline ) - IN> @ IN) = IF 0x0a ELSE KEY THEN ( c ) - ( del? same as backspace ) - DUP 0x7f = IF DROP 0x8 THEN - ( lf? same as cr ) - DUP 0x0a = IF DROP 0xd THEN - ( echo back ) - DUP EMIT ( c ) - ( bacspace? handle and exit ) - DUP 0x8 = IF (inbs) EXIT THEN - ( write and advance ) - DUP ( keep as result ) ( c c ) - ( Here, we take advantage of the fact that c's MSB is - always zero and thus ! automatically null-terminates - our string ) - IN> @ ! 1 IN> +! ( c ) - ( if newline, replace with zero to indicate EOL ) - DUP 0xd = IF DROP 0 THEN -; - -( Read one line in input buffer and make IN> point to it ) -: (rdln) - (infl) - BEGIN (rdlnc) NOT UNTIL - LF IN( IN> ! -; - -( And finally, implement C<* ) -: RDLN< - IN> @ C@ - DUP IF - ( not EOL? good, inc and return ) - 1 IN> +! - ELSE - ( EOL ? readline. we still return null though ) - (rdln) - THEN - ( update C @ C@ 0 > 0x06 RAM+ ! ( 06 == C, plus 2 for extra bytes after buffer: 1 for - the last typed 0x0a and one for the following NULL. ) - INBUFSZ 4 + ALLOT - (infl) - ['] RDLN< 0x0c RAM+ ! - 1 0x06 RAM+ ! ( 06 == C