Post Reply 
FORTH for the SHARP PC-E500 (S)
04-03-2022, 12:53 AM
Post: #67
RE: FORTH for the SHARP PC-E500 (S)
I haven't had the time to work on a text file editor for Forth500 to edit Forth source code. I usually INCLUDE my programs from COM: or use CLOAD with the CE-126P. Editing text files on the RAM disk can be done with a separate BASIC program called edit500 available at: http://www.andrewwoods3d.com/pce500/

Or you could use my new Forth500 TLOAD command defined below that loads Forth from a TEXT file created in BASIC with the built-in BASIC editor:

Code:
\ TLOAD.FTH load TEXT file with line numbers as Forth source
\ Author: Robert van Engelen
\ TLOAD filename

.( Loading TLOAD...)

ANEW _TLOAD_

DECIMAL

: TLOADED       ( c-addr u -- )
  \ open file and save fileid to the return stack
  R/O OPEN-FILE THROW >R
  \ read header 16 bytes + 0 0 CR bytes
  FIB 19 R@ READ-FILE 0= SWAP 19 = AND
  \ and check if it is a TEXT file header
  FIB 5 S\" \xff\x00\x08\x00\x34" S= AND IF
    BEGIN
      \ while not EOF and line number high byte is not $FF
      R@ READ-CHAR 0= SWAP $FF <> AND WHILE
      \ read and nip line number low byte
      R@ READ-CHAR NIP 0= WHILE
      \ get line len byte
      R@ READ-CHAR 0= WHILE ( -- len1 )
      \ read the len number of bytes into the FIB
      FIB OVER R@ READ-FILE 0= WHILE ( -- len1 len2 )
      \ all bytes read?
      OVER = WHILE ( -- len1 )
      \ evaluate the line read
      FIB SWAP ['] EVALUATE CATCH ?DUP IF
        \ drop string that failed to evaluate, close file and rethrow
        2DROP R> CLOSE-FILE DROP THROW
      THEN
    AGAIN
    ELSE DROP THEN
    ELSE 2DROP THEN
    ELSE DROP THEN
    THEN
    THEN
  ELSE
    ." not TEXT"
  THEN
  \ pop fileid from the return stack and close file
  R> CLOSE-FILE DROP
;

: TLOAD         ( "name" -- ) PARSE-NAME TLOADED ;

This approach is similar to the PC-G850(V)(S) C programming with its built-in line-number-based text editor. It is a bit odd to use line numbers. But hey, this is a throwback to the 80s Smile

How to use TLOAD:

1. in BASIC key in TEXT, the prompt will change to < to indicate the TEXT mode
2. type in your Forth program line-by-line with line numbers
3. use RENUM in case you can't insert a line
4. then SAVE "name" to save your program to RAM disk as name.BAS (don't forget this step!)
5. go back to Forth500 with CALL&B0000 (or CALL&B9000 on a 32K machine)
6. key in TLOAD name.BAS
7. done!

- Rob

"I count on old friends" -- HP 71B,Prime|Ti VOY200,Nspire CXII CAS|Casio fx-CG50...|Sharp PC-G850,E500,2500,1500,14xx,13xx,12xx...
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
FORTH for the SHARP PC-E500 (S) - Helix - 09-06-2021, 11:41 PM
RE: FORTH for the SHARP PC-E500 (S) - dmh - 10-02-2022, 02:29 PM
RE: FORTH for the SHARP PC-E500 (S) - robve - 04-03-2022 12:53 AM



User(s) browsing this thread: 1 Guest(s)