mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-20 14:28:06 +11:00
bd38d80f9c
and renamed it "Core words". Also, reworded the presentation.
17 lines
622 B
Plaintext
17 lines
622 B
Plaintext
: (rdlnc) ( -- c )
|
|
( buffer overflow? same as if we typed a newline )
|
|
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 )
|
|
( bacspace? handle and exit )
|
|
DUP 0x8 = IF (inbs) EXIT THEN
|
|
( echo back )
|
|
DUP EMIT ( c )
|
|
( write and advance )
|
|
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 )
|
|
( if newline, replace with zero to indicate EOL )
|
|
DUP 0xd = IF DROP 0 THEN ;
|