2020-11-23 19:58:51 +01:00
|
|
|
# RETRO on Unix - Listener and Extensions
|
2017-10-20 05:05:43 +02:00
|
|
|
|
2019-02-05 21:22:17 +01:00
|
|
|
In this file I am implementing the interactive listener that
|
2020-11-23 19:58:51 +01:00
|
|
|
RETRO will run when started with `-i`, `-i,c`, or `-i,fs`.
|
2019-03-29 21:03:05 +01:00
|
|
|
|
|
|
|
The basic image has a space allocated for input at the end of
|
|
|
|
the kernel. This is at address 1024 (the kernel space is fixed
|
|
|
|
at addresses 0 to 1023).
|
|
|
|
|
|
|
|
~~~
|
|
|
|
#1024 'TIB const
|
|
|
|
~~~
|
|
|
|
|
2019-05-22 16:20:01 +02:00
|
|
|
~~~
|
2021-04-22 15:45:32 +02:00
|
|
|
:image:save (s-) #1000 io:scan-for io:invoke ;
|
2019-05-22 16:20:01 +02:00
|
|
|
~~~
|
2017-10-20 05:05:43 +02:00
|
|
|
|
2019-02-05 21:22:17 +01:00
|
|
|
## Console Input
|
2018-11-23 21:38:46 +01:00
|
|
|
|
2019-02-05 21:22:17 +01:00
|
|
|
The RRE interface provides a keyboard device. This exposes it
|
|
|
|
via `c:get`.
|
2017-10-20 05:05:43 +02:00
|
|
|
|
|
|
|
~~~
|
2021-01-24 03:42:45 +01:00
|
|
|
:c:get (-c) #1 io:scan-for io:invoke ;
|
2017-10-20 05:05:43 +02:00
|
|
|
~~~
|
|
|
|
|
2019-02-05 21:22:17 +01:00
|
|
|
Now that I can read characters, it's time to support reading
|
|
|
|
strings. I do this via two words. The first is `parse-until`.
|
|
|
|
This will setup a temporary string as an input buffer, then
|
|
|
|
read input, passing each character ot a provided quote. When
|
|
|
|
the quote returns `TRUE`, it ends and returns the string. When
|
|
|
|
not `TRUE` it will add the character to the buffer.
|
2017-10-20 05:05:43 +02:00
|
|
|
|
2019-02-05 21:22:17 +01:00
|
|
|
~~~
|
|
|
|
{{
|
2020-11-23 19:58:51 +01:00
|
|
|
(c-cf) :edit? dup [ ASCII:BS eq? ] [ ASCII:DEL eq? ] bi or ;
|
|
|
|
(c-) :gather edit? &drop &buffer:add choose ;
|
|
|
|
(q-qc) :cycle repeat c:get dup-pair swap call not 0; drop gather again ;
|
2019-02-05 21:22:17 +01:00
|
|
|
---reveal---
|
|
|
|
:parse-until (q-s)
|
|
|
|
[ s:empty buffer:set cycle drop-pair buffer:start ] buffer:preserve ;
|
|
|
|
}}
|
|
|
|
~~~
|
|
|
|
|
|
|
|
Using this, a simple `s:get` can be implemented very easily as
|
|
|
|
a quote which looks for an end of line character.
|
|
|
|
|
|
|
|
~~~
|
|
|
|
:s:get (-s) [ [ ASCII:LF eq? ] [ ASCII:CR eq? ] bi or ] parse-until ;
|
2019-12-09 20:37:26 +01:00
|
|
|
:s:get-word (-s) &c:whitespace? parse-until ;
|
2019-02-05 21:22:17 +01:00
|
|
|
~~~
|
|
|
|
|
2019-03-29 19:46:22 +01:00
|
|
|
~~~
|
2020-11-23 19:58:51 +01:00
|
|
|
:clear '\^[2J\^[0;0H s:format s:put ;
|
2019-03-29 19:46:22 +01:00
|
|
|
~~~
|
|
|
|
|
|
|
|
Hide the support words.
|
|
|
|
|
|
|
|
# Standard Interactive Listener
|
2019-02-05 21:22:17 +01:00
|
|
|
|
|
|
|
The main part of this file is the *listener*, an interactive
|
2021-04-30 17:09:01 +02:00
|
|
|
read-eval-print loop.
|
2019-02-05 21:22:17 +01:00
|
|
|
|
|
|
|
RRE's C part will access a couple parts of this, based on the
|
|
|
|
startup flags passed.
|
2017-11-15 20:57:17 +01:00
|
|
|
|
|
|
|
~~~
|
2018-11-14 14:52:30 +01:00
|
|
|
'NoEcho var
|
2017-11-15 20:57:17 +01:00
|
|
|
|
2019-05-22 16:20:01 +02:00
|
|
|
:bye #0 unix:exit ;
|
|
|
|
|
2017-11-15 20:57:17 +01:00
|
|
|
{{
|
2020-09-11 19:22:03 +02:00
|
|
|
'EOT var
|
|
|
|
FALSE 'Ignoring var-n
|
|
|
|
(-f) :ignoring? @Ignoring ;
|
2019-05-22 16:20:01 +02:00
|
|
|
(-nn) :version @Version #100 /mod ;
|
2020-09-11 19:22:03 +02:00
|
|
|
(c-f) :done? dup !EOT
|
|
|
|
[ ASCII:CR eq? ]
|
2019-05-22 16:20:01 +02:00
|
|
|
[ ASCII:LF eq? ]
|
|
|
|
[ ASCII:SPACE eq? ] tri or or ;
|
2020-09-11 19:22:03 +02:00
|
|
|
(c-f) :eol? @EOT [ ASCII:CR eq? ] [ ASCII:LF eq? ] bi or ;
|
2019-05-22 16:20:01 +02:00
|
|
|
(s-sf) :valid? dup s:length n:strictly-positive? ;
|
2021-04-30 17:09:01 +02:00
|
|
|
(c-c) :check-eof dup [ #-1 eq? ] [ ASCII:EOT eq? ] bi or if: bye ;
|
2019-05-22 16:20:01 +02:00
|
|
|
:bs buffer:get buffer:get drop-pair ;
|
2021-04-30 17:09:01 +02:00
|
|
|
(c-c) :check-bs dup [ ASCII:BS eq? ] [ ASCII:DEL eq? ] bi or if: bs ;
|
2019-05-22 16:20:01 +02:00
|
|
|
(c-c) :check check-eof check-bs ;
|
|
|
|
(-c) :character c:get dup buffer:add ;
|
|
|
|
(q-) :buffer [ TIB buffer:set call buffer:start ] buffer:preserve ;
|
|
|
|
(-s) :read-token [ [ character check done? ] until ] buffer s:chop ;
|
|
|
|
(-sf) :input read-token valid? ;
|
2020-09-11 19:22:03 +02:00
|
|
|
(sf-) :process ignoring? [ drop-pair eol? [ &Ignoring v:off ] if ] if;
|
|
|
|
&interpret &drop choose ;
|
2017-11-15 20:57:17 +01:00
|
|
|
---reveal---
|
2020-09-14 21:55:02 +02:00
|
|
|
:// script:ignore-to-eol &Ignoring v:on ; immediate
|
2019-05-22 16:20:01 +02:00
|
|
|
:banner version 'RETRO_12_(%n.%n)\n s:format s:put
|
|
|
|
EOM here - here EOM '%n_Max,_%n_Used,_%n_Free\n s:format s:put ;
|
2019-09-18 18:48:15 +02:00
|
|
|
:listen @NoEcho [ banner ] -if repeat input process again ;
|
2017-11-15 20:57:17 +01:00
|
|
|
}}
|
2019-01-13 00:30:52 +01:00
|
|
|
|
|
|
|
&listen #1 store
|
2017-11-15 20:57:17 +01:00
|
|
|
~~~
|