FAST Forth Native-Language Embedded Computers
FAST Forth Native-Language Embedded Computers
FAST Forth Native-Language Embedded Computers
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Scr # 501<br />
0 \ begin line editor ( 16 5 91 CRC 8:25 )<br />
1 FORTH DEFINITIONS ( DEBUG ) FORGET TASK<br />
2 FORTH DEFINITIONS ( : TASK ; ) BASE F@ DECIMAL<br />
3 SEQ BELL 1 C, CTL G C,<br />
4<br />
5 ' (EXPECT) 'EXPECT F!<br />
6<br />
7 VOCABULARY EXPECTING IMMEDIATE EXPECTING DEFINITIONS<br />
8<br />
9 BLK F@ DUP 1+ SWAP 6 + THRU \ HERE FIRST OVER - ERASE<br />
10<br />
11 ' LNED ' EXPECT F !<br />
12 HERE FENCE F! BASE F! : TASK ; EDITOR FLUSH<br />
13<br />
14<br />
15<br />
Scr # 502<br />
0 \ line editor: variables, constants ( 25 11 91 CRC 13:44 )<br />
1 0 VARIABLE CURS \ line cursor<br />
2 0 VARIABLE BUF \ holding buffer<br />
3 0 VARIABLE SIZE \ size of line already in buffer<br />
4 1 VARIABLE PLACEF \ are we inserting or replacing?<br />
5 0 VARIABLE NXTLN \ pointer to next line to place<br />
6<br />
7 10 CONSTANT STRINGS \ number of back strings saved<br />
8<br />
9 CREATE STRARRAY STRINGS 4* ALLOT \ pointer array<br />
10<br />
11 ' QUERY 5 + C@ CONSTANT STRSIZE \ *very* implementation specific<br />
12<br />
Scr # 503<br />
0 \ line editor: makstrs, up dn history ( 25 11 91 CRC 13:47 )<br />
1 : MAKESTRS \ construct the string buffer at compile time.<br />
2 STRINGS 0 DO HERE DUP STRARRAY I 4* + F!<br />
3 STRSIZE 1+ DUP ALLOT ERASE LOOP ;<br />
4 MAKESTRS STRARRAY NXTLN F!<br />
5<br />
6 : UP 4 NXTLN +! NXTLN F@ STRARRAY - 4/<br />
7 STRINGS = IF STRARRAY NXTLN F! THEN ;<br />
8<br />
9 : DN NXTLN F@ STRARRAY \ down one in the string buffer<br />
10 = IF [ STRARRAY STRINGS 4* + ] LITERAL NXTLN F! THEN<br />
11 -4 NXTLN+! ;<br />
12<br />
13<br />
14<br />
15<br />
Scr # 504<br />
0 \ line editor: redraw, history access ( 25 11 91 CRC 13:47 )<br />
1 FORTH DEFINITIONS<br />
2 : HISTORY EXPECTING STRINGS 0 DO DN NXTLN F@ F@<br />
3 COUNT DUP IF CR I 4 .R SPACE THEN TYPE LOOP SPACE ;<br />
4 : HIST HISTORY ;<br />
5<br />
6 EXPECTING DEFINITIONS<br />
7 :REDRAW\ --- I re-display the line from cursor<br />
8 ERL BUFF@ CURS F@ + SIZE F@ CURSF@ -<br />
9 -DUP IF DUP >R TYPE SPACE<br />
10 R> 1+ 0 DO LEFT LOOP<br />
11 ELSE SPACE LEFT DROP THEN ;<br />
12<br />
13 : STORESTR \ --- I store string in array<br />
14 BUFF@ NXTLN F@ F@ 1+ SIZE F@ 2DUP SWAP 1- C! CMOVE;<br />
15<br />
<strong>Forth</strong> Dimensions 13<br />
playing each line in it. Since<br />
the word walks through the<br />
ring buffer exactly the number<br />
of times that there are<br />
entries, the pointer is left<br />
back in its starting position.<br />
This code depends on the<br />
word TYPE dropping its two<br />
arguments when presented<br />
with a count of zero.<br />
REDRAW uses the terminal-specific<br />
operator LEFT<br />
to move the cursor left one<br />
place on the screen. The<br />
Atari ST screen emulates<br />
the VT-52 terminal, and the<br />
present cursor position cannot<br />
be read by the application.<br />
Other implementations<br />
may be possible where the<br />
terminal code permits reading<br />
the cursor position.<br />
REDRAW redisplays the line<br />
from the current cursor position<br />
out to the right end of<br />
the line. An extra space is<br />
emitted in case the most<br />
recent keystroke deleted a<br />
character in the line.<br />
STORESTR (bottom of<br />
screen 504) and GETSTR<br />
move strings between the<br />
edit buffer and the string<br />
array. STORESTRstores the<br />
count (from SIZE) in the<br />
first byte of the array entry,<br />
and GETSTRuses the count<br />
to determine the length of<br />
the string to be moved into<br />
the edit buffer.<br />
LEFT and RIGHT, on<br />
screen 505, move the cursor<br />
one space to the left or<br />
right, if possible. If the cursor<br />
is already at the end of<br />
the line, a warning bell is<br />
emitted instead. These two<br />
words use their eponymous<br />
cursor control words to<br />
move the screen cursor appropriately.<br />
They are activated<br />
by the appropriate<br />
cursor-control arrow key.<br />
DEL, on line ten, deletes<br />
the character under<br />
the current cursor location.<br />
Line 11 does the actual<br />
deletion, culminating in the<br />
CMOVE at the end. Line 12<br />
March 1994 April