6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Mar 29, 2024 9:54 am

All times are UTC




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Fig Forth line editor
PostPosted: Tue Nov 23, 2021 6:27 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 355
I have collected 8 different Forths for the Apple II.

1 is text based and an SBC Forth
1 text based one is an ITC Forth
1 screen based and is an SBC Forth
And the rest are screen based and are ITC Forths.

Not one of the screen based Forths have a screen editor in Forth and only one has one that have to exit Forth to use. The two text based Forths are disk based only and can't access to a hard drive.

The absence of a good editor alone may deter a lot of people to start programming in Forth.

I offer these simple words for editing a line and another for saving a screen, for anyone just starting out in Forth and just want something simple to start entering code.

57B CONSTANT HTAB
: EDLN ( ln -- ) DUP . ." [" SCR @ (LINE) OVER >R TYPE ." ]" 3 HTAB C! R> C/L EXPECT CR ;
: SAVE UPDATE FLUSH ;

Replace the HTAB values for your machine. 3 HTAB should return the cursor 3 positions from the left side of the screen and on the same line that was printed to screen. This should position the cursor just after the "[".

Now it is as simple as doing:

screen# LIST
0-15 EDLN
SAVE

Hopefully anyone seeing how simple editing a line can be will keep newbies from giving up so quick and draw more interest to programming in Forth.

Note: Experienced users can disregard this post :)

OR, if this does help anyone or any interest, I will post a lot of very simple and small screen editing words that have a lot of power from the command line, and may be quicker than a full blown editor. These editing words include: Cut, Copy, Paste, Insert, Delete, Blank, any line or range of lines. And Copy, one screen or range of screens, from one screen to another.

Due to these words, I have come to prefer editing screens over editing a text file.

Other notes: A Virtual Memory screen file on a hard drive can be as large as the OS allows. On an Apple II with Prodos, this is 16 Mb and offers 32768 screens. Everything from programs to games to a directory to help files can be stored in screens. Maybe this will entice some interest.

May the Forth be with you.


Last edited by IamRob on Thu Dec 16, 2021 4:01 am, edited 4 times in total.

Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 25, 2021 7:22 pm 
Offline

Joined: Wed Nov 11, 2020 10:42 pm
Posts: 95
Location: Kelowna Canada
As a forth newb I appreciate trying to make it simpler especially editing. However even though I have not made this work as I believe it should on my system, there is an error in edln where I believe it should be ' ." [" scr ' not ' ." [ scr ' .
Also I needed to change the first line to ' : htab 09 emit ; ' for my screen and terminal.
I'm still not there but for my fig-forth implementation it could be better than using 'p' to replace the whole line. Still not a screen editor but better.
I ,for one, would be happy to see more words to make editing simpler especially in a screen oriented environment.
As a beginner the more worked examples the better to get the hang of this powerful language. As someone said forth is akin to handing someone a pair of scissors and saying " Here go run and play with this new toy". No hand holding and with words that can do many powerful and dangerous things.


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 26, 2021 4:36 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 355
Thanks! Corrected the missing quote in the original listing.

Here is my almost complete set of editing words to get you started.

( Line utils: EDLN CLRLN MOVLN oaD oaI oaC oaV oaX )
HEX 57B constant htab
: EDLN ( ln -- ) dup . ." [" scr @ (line) over >R type ." ]" 3 htab C! R> C/L expect cr ;
: LINE ( ln -- adr ) F and scr @ (line) drop ;
: CLRLN ( ln -- ) line c/l blanks ;
: MOVLN ( fmln toln --- ) over line swap line c/l cmove clrln ;
: (count2) dup 2+ swap @ ;
: oaC ( fmln toln -- ) over - 1+ c/l * pad ! line pad (count2) cmove ; ( copy a line )
: oaV ( ln -- ) pad count2 rot line swap cmove ; ( DANGER: read notes below ) ( paste a line )
: oaD ( ln -- ) 1+ 10 swap do i i 1- movln loop f clrln ; ( delete a line - moves all lines after, up )
: oaI ( ln -- ) dup 1- e do i i 1+ movln -1 +loop clrln ; ( insert a line )
: oaX ( ln -- ) dup line c/l pad c! pad count cmove clrln save ; ( cut a line )

( Screen utils: EDSCRN CLRSCRN INDEX SAVE REFRESH )

: EDSCRN ( -- ) 10 0 do i edln key 1b = if leave then loop cr ; ( press ESC key to exit screen editing mode )
: CLRSCRN ( scrn --- ) 0 swap (line) drop 400 blanks ; ( clears screen to blanks and not zeroes )

: INDEX ( scrn -- ) cr 7 spaces ." SCREEN HEADERS"
dup 10 + swap do cr i 3 .r space 0 i .line loop cr ;

: REFRESH 0 prev @ ! scr @ list ;
: SAVE update flush ;


Notes: COUNT2 is used in the OAC definition to allow more than 255 characters to be copied to PAD. The definition, "!" is correctly used (and not C!) to store the length of the string. More than one line can be copied and pasted at a time. See DANGER note below for pasting.

DANGER: When pasting, make sure you are aware of how many lines got copied. This command will over-write other lines, and may overwrite past the end of the screen, and into the next buffer or other protected memory. If you believe this has happened, a re-boot may be necessary. If you are uncomfortable with this use, then change "OAC" to copy a single line only to this:

: oaC ( ln -- ) c/l pad c! line pad count cmove ;

Inserting lines will scroll all lines below the given line, off the screen. Protected memory is not affected.

INDEX displays the headers for the next 16 screens starting at the screen number specified.

The "OA" in each of the above words stands for "Open-Apple" and relates to the key commands used in most word-processors on an Apple computer to do the operation. PC users can change these to "CTRL" for the control commands used on that platform, if preferred.

All values in these word definitions are entered in HEX, not decimal.

Changes are not saved permanently to the screens until you type "SAVE". To undo all the changes in memory, type "REFRESH" to return the screen to the last "SAVE" state.


Last edited by IamRob on Tue Nov 30, 2021 5:53 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Sun Nov 28, 2021 9:41 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 841
okwatts wrote:
As a forth newb I appreciate trying to make it simpler especially editing. However even though I have not made this work as I believe it should on my system, there is an error in edln where I believe it should be ' ." [" scr ' not ' ." [ scr ' .


Is your system software and hardware or is it software running on a simulator?
VICE, a simulator for the Commodore 64, allows a shortcut which can be used before an editor is available. VICE allows copied text, from a plain text file, to be pasted in the simulator window. The simulated C64 treats it as text being typed in. I don't know about Apple simulators.


Top
 Profile  
Reply with quote  
PostPosted: Sun Nov 28, 2021 10:47 pm 
Offline

Joined: Wed Nov 11, 2020 10:42 pm
Posts: 95
Location: Kelowna Canada
I am using actual silicon on 65c02 and using a CRC65 from plasmo via USB to a PC running linux and picoterm. I also have a SYM-1 using 6502 nmos and Rich Cini SBC2.7 65c02 connected similarly. I would also like to use the CRC65-VGA6448 combo for this. These are running Fig-Forth using block or screen based access to a dedicated area of the CF/SD storage for forth.
I also have fig-forth running on a version of Grant Searle's MultiComp set up as a 6502. ( I would really like to get a 65C02 VHDL for the Multicomp but my FPGA skills are lacking). Editing for these use the line editor described by W. Ragsdale but I haven't tried more sophisticated things as yet.
Ideally a screen editor would be what I would like as Paul Dourish has demonstrated for his MITE computer.
I am a forth novice really so I have been learning by inspecting others code even though I have the Brodie books and other resources.

I believe that IamRob is taking real advantage of the Apple environment for the onscreen editing, not sure how that will translate to ANSI or other terminals as yet.


Top
 Profile  
Reply with quote  
PostPosted: Sun Nov 28, 2021 10:58 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 841

Where can I find information on William Ragsdale's editor?
My editor is based on the one presented in Forth Dimensions volume 3 issue 3 "THE FORTH, INC. LINE EDITOR" by S. H. Daniel.


Top
 Profile  
Reply with quote  
PostPosted: Sun Nov 28, 2021 11:16 pm 
Offline

Joined: Wed Nov 11, 2020 10:42 pm
Posts: 95
Location: Kelowna Canada
Hi
I used the sample code from the fig-FORTH Installation manual (near the end) dated May 1979. (I have the PDF but it's large). I also looked at code for SYMforth mentioned in the thread here concerning SYMbiosys from 2012-2013 (viewtopic.php?f=2&t=1696).


Top
 Profile  
Reply with quote  
PostPosted: Sun Nov 28, 2021 11:41 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 841

Thanks, I just downloaded it. I'll take a look at it.


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 30, 2021 5:46 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 355
okwatts wrote:
not sure how that will translate to ANSI or other terminals as yet.

I don't believe there should be any difference as the ." should handle ANSI characters on screen for your computer. The rest of Forth words posted follow the FigForth Standard. Only horizontal tabbing would need to be figured out for your computer.

Hah! Just realized the cursor-up word is not needed if the CR is not used. Fixed in the post above.


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 15, 2021 8:51 pm 
Offline

Joined: Wed Nov 11, 2020 10:42 pm
Posts: 95
Location: Kelowna Canada
Hi Just noticed as I tried using this again that by inspection of the actual files saved, I get 3 nulls ($00) inserted after the end of my edits when using edln. I surmise these arise from the 3 Htabs (which seem to extend into the next line but that might be expected), but the effect is to stop loading of any code definitions after those lines from those screens. Not sure if your code generates the same issues and apart with experimenting with doing 3 drops I see no simple way to correct this.
Is it just my implementation or what am i missing?


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 16, 2021 4:07 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 355
I forgot to re-edit my first post after I made some corrections. This is the fixed code as well as an explanation what should happen.

57B CONSTANT HTAB
: EDLN ( ln -- ) DUP . ." [" SCR @ (LINE) OVER >R TYPE ." ]" 3 HTAB C! R> C/L EXPECT CR ;

Replace the HTAB values for your machine. 3 HTAB should return the cursor to 3 positions from the left side of the screen and on the same line that was just printed to screen. This should position the cursor just after the "[".

Compiling or Interpreting this word definition in your Forth should not result in 3 zeroes following the end of the line. Your version of Forth may put them there automatically since in some Forth's that is the LINK pointer plus word length of the next word definition in the Library.


Top
 Profile  
Reply with quote  
PostPosted: Sat Dec 18, 2021 4:41 pm 
Offline

Joined: Wed Nov 11, 2020 10:42 pm
Posts: 95
Location: Kelowna Canada
It appears that the 3 nulls that are introduced into the screen after the end of my edits using edln are the result of the "expect" in edlin. According to the fig-forth manual and glossary the definition of expect is " Transfer characters from the terminal to address, until a 'return' or the count of characters have been received. One or more nulls are added at the end of the text."
In my implementation there must be 3 nulls and since this goes into the screen that is being edited, it means when I load the screen the interpretation of the words that follow is stopped.
It looks like I will have to change the implementation of expect or change the way load parses the input to use this.
I guess this is what they meant when it is said that forth is not so much a standard but a way to create your own language to do what you want.


Top
 Profile  
Reply with quote  
PostPosted: Mon Dec 20, 2021 12:35 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 355
I think EXPECT may have done that on my Forth at one time as well.
The zeroes are put into the Input buffer before getting copied into TIB, so the interpreter can use them as an end-of-line terminator.

I changed my EXPECT to only store the zeroes in TIB and not in the original Input buffer, even though TIB may not always be the destination for the Input.

This way the zeroes at the end of the input line do not get copied, which allows EXPECT to put the input into the 1k Forth buffer.
This allows me to transfer my input to anywhere I choose as an address. I also reserved a zero-page byte for the input length and my definition of SPAN is just:

: SPAN ZPIL C@ ; \ replace ZPIL with the zero-page address set below

to save to PAD or to any variable with a preceding length byte would be:
PAD 1+ 50 EXPECT SPAN PAD C! ;

Here is my listing for EXPECT. Change the Input routine and zero-page addresses for your machine

Code:
: EXPECT ( addr req_count -- )

   DW *+2      \ point the CFA to the next line
   STX XSAVE

    LDA $0,X      \ expected count left on the stack
   STA $1      \ free zero-page memory

   LDA 2,X      \ addr that was left on the stack (can be TIB @$300 or
            \  PAD or memory for a string)
   STA N
   LDA 3,X
   STA N+1

   JSR $FD6F      \ applesoft INPUT routine returns count in X-reg
            \ and its buffer is at $200; change this to your Input handler

   CPX $1      \ requested count
   BCC EXPECT1
   LDX $1      \ input went over the max, so trim down to just the requested amount

EXPECT1   LDA #0
   STA TIB,X      \ store zero in TIB but not in other memory (the address here is found by doing "TIB @")
   STA TIB+1,X
   TXA
   TAY
   DEY
   BMI EXIT      \ in case of an empty input
   STY ZPIL      \ save actual input length in a free zero-page byte used by SPAN

]LP   LDA $200,Y   \ change address to your Input buffer
   AND #$7F
   STA (N),Y      \ N was loaded with an address above
   DEY
   BPL ]LP

EXIT   LDX XSAVE
   JMP POPTWO   \ remove original Dest address and count request


Top
 Profile  
Reply with quote  
PostPosted: Sun Jan 15, 2023 6:50 pm 
Offline

Joined: Wed Jan 01, 2003 6:32 pm
Posts: 31
Here is my FIG FORTH 1.1 screen editor. It is optimized for a very dumb, antique 1200 Baud DIY terminal (ELEKTERMINAL for the experts). Therefor be aware of the slightly unusual control codes

Code:
VED.BLK V2022

SCR # 3
  0 ( FULL SCREEN EDITOR      D. Lausberg 31.8.97      SCR #1 )
  1 VOCABULARY VED immediate VED DEFINITIONS
  2 decimal
  3 1 VARIABLE &MODE    1 VARIABLE &CUR
  4 1 variable &tag1    1 variable &tag2
  5 0 variable &BUF
  6 9 constant ht       8 constant bs
  7 28 constant home
  8 1023 constant cps  15 constant lps
  9 : nbs 0 do bs emit loop ;
 10
 11 : CLS 12 EMIT ;
 12 : nvt dup 0= if drop else 0 do 11 emit loop endif ;
 13 : xcr 13 emit lps < if 10 emit endif ;
 14 : .L (LINE) -trailing 1 max type ;
 15 -->

SCR # 4
  0 ( FULL SCREEN EDITOR                                SCR #2 )
  1 : curpos &cur @ ;
  2 : !cur &cur ! ;
  3 : >line# c/l / ;
  4 : line#> c/l * ;
  5 : line@ scr @ (line) ;
  6 : bufpos curpos >line# line@ drop curpos c/l mod +
  7     dup &BUF ! ;
  8 : +1BUF &BUF @ 1+ &BUF ! ;
  9 : +1cur curpos 1+ dup cps > if drop cps bs emit endif !cur ;
 10 : -1cur curpos 1 - dup 0 < if drop 0 ht emit endif !cur ;
 11 : #toeol c/l mod c/l swap - ;
 12
 13 -->
 14
 15

SCR # 5
  0 ( Full Screen Editor                                  SCR #3 )
  1 : ?prt dup bl < swap 126 > or 0= ;
  2 : nop ;
  3 : exec swap 2 * + @ execute ;
  4
  5
  6 : larrow -1cur bs emit ;
  7 : rarrow +1cur ht emit ;
  8 : uarrow curpos c/l - dup 0 < if drop curpos else
  9   11 emit endif !cur ;
 10 : darrow curpos c/l + dup cps > if drop curpos else
 11   10 emit endif !cur ;
 12
 13 : imode &mode  @ -1 xor &mode ! ; ( toggle insert mode )
 14
 15 -->

SCR # 6
  0 ( Full Screen Editor                               SCR #4 )
  1 : distoeos 13 emit dup line#> !cur lps 1+ over do i scr @
  2   .L i xcr loop 15 swap - nvt ;
  3 : updscr cls 0 distoeos ;
  4 : scr-ini updscr ;
  5 : nxtblk 1 scr +! scr-ini ;
  6 : lstblk scr @ 1 - dup 1 < if drop 1 endif
  7   scr ! scr-ini ;
  8 : quit-ed cls ." edit complete" flush forth quit ;
  9
 10 : clrline line@ blanks update ;
 11 : ?empty line@ -trailing swap drop 0= ;
 12 : -move line@ cmove update ;
 13 : exp dup 1 - 14 do i line@ drop i 1+ -move -1 +loop
 14   clrline ;
 15 -->

SCR # 7
  0 ( Full Screen Editor                                 SCR #5 )
  1 : shrink lps dup rot do i 1+ line@ drop i -move loop
  2   clrline ;
  3 : clear-page 16 0 do I clrline loop updscr ;
  4 : copy b/scr * offset @ + swap b/scr * b/scr over + swap
  5   do dup I block 2 - ! 1+ update loop drop flush ;
  6
  7 : insertline lps ?empty if dup exp distoeos
  8   endif ;
  9 : deleteline dup shrink distoeos ;
 10 : clp clear-page ;
 11 : iline curpos >line# insertline ;
 12 : dline curpos >line# deleteline ;
 13
 14 : tab 8 curpos 8 mod - 0 do +1cur ht emit loop ;
 15 -->

SCR # 8
  0 ( Full Screen Editor                              SCR #6 )
  1 : #in pad 10 expect 0 0 pad 1 - (number) drop drop ;
  2 : edits cls ."   Edit SCR #: " #in scr ! scr-ini ;
  3
  4 : settag scr @ key dup 49 = if swap &tag1 ! endif
  5                        50 = if &tag2 ! else drop endif ;
  6 : totag key dup 49 = if &tag1 @ scr ! scr-ini endif
  7                 50 = if &tag2 @ scr ! scr-ini endif ;
  8
  9 : REP pad 1+ swap -move ;
 10 : holdln curpos >line# line@ pad c! pad 1+ c/l cmove ;
 11 : putln curpos >line# dup &mode @ if
 12         lps ?empty if dup exp REP else drop endif
 13     else REP endif distoeos ;
 14
 15 -->

SCR # 9
  0 ( Full Screen Editor                                 SCR #7 )
  1 : ret &mode @ if iline else curpos >line# 1+ dup 15 <
  2   if 10 emit endif 15 min line#> !cur 29 emit endif ;
  3
  4 : delchar bufpos dup >R dup 1+ swap curpos #toeol 1 - dup
  5   >R cmove R> R> + bl swap c! update ;
  6 : distoeol bufpos swap #toeol -trailing 1+ swap
  7   over type nbs ;
  8 : dchar delchar curpos distoeol ;
  9 : inschar dup >R here over over curpos #toeol 1 -
 10   dup >R cmove swap 1+ R> cmove R> c! update ;
 11 : ins-page scr @ eom @ lo - 1024 / 4 +
 12   do i 1 - i copy -1 +loop clear-page ;
 13 : RUBOUT larrow dchar ;
 14 : .mode 18 spaces &mode @ if ." INSERT " else 7 spaces endif ;
 15 -->

SCR # 10
  0 ( Full Screen Editor                                 SCR #8 )
  1 : help cls 15 spaces ." Commands" .mode ."   SCR# " scr @ . cr
  2   ."  CTL-E  Cursor up           ESC    Help" cr
  3   ."  CTL-X  Cursor down         CTL-V  Insert on/off" cr
  4   ."  CTL-D  Cursor right        CTL-G  Delete chr" cr
  5   ."  CTL-S  Cursor left         CTL-Y  Delete line" cr
  6   ."  CTL-R  Page up             CTL-N  Insert new page" cr
  7   ."  CTL-A  Page down           CTL-B  Edit SCR #" cr
  8   ."  CTL-F  Tab                 CTL-Z  Clear page" cr
  9   ."  CTL-V  Set tag to SCR      CTL-O  Copy line to PAD" cr
 10   ."  CTL-T  Goto tagged SCR     CTL-P  Put PAD to line" cr
 11   cr
 12   ."                             CTL-Q  Quit editor" cr
 13   cr
 14   ." Press key to continue " key drop updscr ;
 15 -->

SCR # 11
  0 ( Full Screen Editor                                 SCR #9 )
  1 0 variable cmd -2 allot
  2   ] nop    nxtblk  edits  nop    rarrow uarrow tab      dchar
  3     larrow rarrow  darrow uarrow nop    ret    ins-page holdln
  4     putln  quit-ed lstblk larrow totag  settag imode    nop
  5     darrow dline   clp    help   updscr nop    nop      nop [
  6
  7 : command dup 127 = if RUBOUT else cmd exec endif ;
  8 : insertoff key dup ?prt if dup emit curpos 255 and
  9     if &BUF @ else bufpos endif C! +1BUF +1CUR update
 10    else command bufpos drop endif ;
 11 : inserton key dup ?prt if dup emit &buf @ inschar +1cur
 12   curpos distoeol update else command bufpos drop then ;
 13 : vedit decimal 0 &mode ! 3 scr ! scr-ini
 14   begin &mode @ if inserton else insertoff then again ;
 15 -->

SCR # 12
  0 ( Full Screen Editor                                 SCR #10 )
  1 FORTH Definitions
  2 : e ved vedit ;
  3 : new LO EOM ! 3 scr ! ved 16 0 do I clrline loop vedit ;
  4
  5
  6 latest    12 +origin !  ( top NFA )
  7 ( here      28 +origin !  ( Fence )
  8 here      30 +origin !  ( DP )
  9 ' VED      6 +origin !  ( Voc-Link )
 10 ( here      Fence ! )    ;S
 11
 12
 13
 14
 15


In my implementation, screen numbers start with #3. The word to start the editor is E

Have fun

Dietrich

_________________
My system: Elektor Junior Computer, GitHub https://github.com/Dietrich-L


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: