Shop OBEX P1 Docs P2 Docs Learn Events
Taqoz Reloaded v2.8 - Running commands from SD card — Parallax Forums

Taqoz Reloaded v2.8 - Running commands from SD card

bob_g4bbybob_g4bby Posts: 440
edited 2022-06-17 11:51 in Forth

Having compiled the following code, if you type a word that isn't found in the dictionary, then TAQOZ will search the SD card for a file of the same name, either with no extension, or .FTH, or .TXT extension. The file is then loaded as if it were being entered on the terminal. After loading, input is from the user terminal again. To enable this feature, type ON BATCH. To resume normal 'word not found' behaviour, type OFF BATCH. Don't forget to load some files containing Taqoz source code onto the SD card, before attempting to run them. Here's the code:-

--- Batch File ver 1 for Taqoz Reloaded v2.8 - Bob Edwards May 2022
TAQOZ

IFDEF *BATCHFILE*
    FORGET *BATCHFILE*
}

pub *BATCHFILE* ." Run Batch File of same name when word not found ver 1"
;

--- attempt to run SD card command, if word not found in dictionary
--- to turn feature on use ON BATCH , to turn off OFF BATCH
--- requires source code files on SD card with no extension, .TXT or .FTH

--- leftmost len chars of str - destructive, uses same string
pub LEFT$ ( str len -- str )
OVER+ C~
;

20 bytes SFILE                          --- source file on SD card

--- search for unknown word as file on SD card and execute
--- files ending with no extension, .FTH or .TXT are valid 
--- NB this word does not run directly from the terminal
pub SDEXEC  ( -- TRUE | FALSE )
    @WORD SFILE $!                      --- save unknown word
    SFILE FOPEN$                        --- attempt to open the file
    DUP 
    IF
        FLOADS TRUE                     --- load file with no extension if it exists
    ELSE
        DROP
        " .FTH" SFILE $+!
        SFILE FOPEN$
        DUP 
        IF
            FLOADS TRUE             --- else load file ending in .TXT
        ELSE
            DROP
            SFILE DUP LEN$ 3 - LEFT$    --- remove FTH from the filename
            " TXT" SWAP $+!             --- and add TXT
            SFILE FOPEN$
            DUP
            IF
                FLOADS TRUE             --- else loads file ending in .FTH
            ELSE
                DROP FALSE              --- no file found, signal failure
            THEN
        THEN
    THEN
;

--- enable / disable unknown word search on SD card
pub BATCH   ( ON | OFF -- ) 
    IF
        ' SDEXEC unum W!                --- if unknown word, attempt execute from SD card
    ELSE
        0 unum W!                       --- else return normal operation
    THEN
;
END

Could be useful for:-
1. Running a list of commands for test purposes - but you don't want it permanently in memory
2. Loading your favourite extensions
3. Turning TAQOZ into something similar to MSDOS

Here's a small program file - the filename can be anything, but I would choose COGRAM.FTH to match the name of the top level word. It just displays COG and LUT memory contents. Note that the program is compiled, run and then forgotten again - it leaves no permanent trace. Also note the use of NULL and CON to minimise unnecessary output to the console before and after the program runs:-

NULL

 pub COGRAM
        CON
        CRLF CRLF ." COG 0 COG memory" CRLF
        0 $200 COG DUMP
        CRLF CRLF ." COG 0 LUT memory" CRLF
        0 $200 LUT DUMP
        CRLF
        NULL
;

COGRAM
FORGET COGRAM
CON 

Comments

  • Nice!
    Thanks for sharing!

  • bob_g4bbybob_g4bby Posts: 440
    edited 2022-06-28 09:27

    Version 2 of this utility adds the feature that file loading is nestable. If an unknown word is encountered in the file being loaded, then a file of the same name will be searched for and loaded. Afterwards, the rest of the original file is loaded. This is useful so that library filenames may be included in the source and those libraries will be loaded automatically from SD card. File parameters are saved and restored on the L stack.
    N.B. Don't use the block load mode TAQOZ ... END if your file contains references to other files - nested loads only work with normal load mode.
    Here's the code:-

    --- Batch File ver 2 for Taqoz Reloaded v2.8 - Bob Edwards June 2022
    
    IFDEF *BATCHFILE*
        FORGET *BATCHFILE*
    }
    
    pub *BATCHFILE* ." If word not found, load file of same name from SD card ver 2"
    ;
    
    --- If word not found in dictionary, attempt to load SD card source code file of same name
    --- e.g. TEST would attempt to load TEST then TEST.FTH then TEST.TXT from SD card
    --- To turn feature on use ON BATCH , to turn off OFF BATCH
    --- Supports nested files, so an unknown word within a file will trigger the load of
    --- another file of the same name. When that is all loaded, the parent file continues
    --- to load. Useful to include libraries of files in source code
    
    --- leftmost len chars of str - destructive, uses same string
    pub LEFT$ ( str len -- str )
    OVER+ C~
    ;
    
    --- Push 3 params to L stack to remember input stream settings
    pri BFPUSH  ( -- )
        filesect @ >L
        _fread @ >L
        ukey W@ >L
    ;
    
    --- Pop 3 params from L stack to restore input stream settings
    pri BFPOP   ( -- )
        L> ukey W!
        L> _fread !
        L> filesect !
    ;
    
    --- load file as console input then restore on zero (0) char that marks file end to previous input setting
    pub FLOADSS ( sector -- )               
        OPEN-SECTOR                         --- set the starting sector for file access
        KEY:                                --- redirect (using ukey) all character input to the code that follows
    pub FGETS ( -- ch )                     --- Read the next byte from the file
        _fread @                            --- fetch the file read pointer
        SDC@                                --- fetch char from SD virtual memory in current file
        DUP
        IF                                  --- if the 0 end-of-file hasn't been reached
            _fread ++                       --- increment the file pointer
            EXIT                            --- Exit word now - pops return stack into IP
        THEN
        BFPOP                               --- Restore input stream settings
        ;
    
    13 bytes SFILE                          --- source file on SD card
    
    --- search for unknown word as file on SD card and load
    --- files ending with no extension, .FTH or .TXT 
    --- NB this word will not run directly from the terminal
    pub SDEXEC  ( -- TRUE | FALSE )
        @WORD SFILE $!                      --- save unknown word
        BFPUSH                              --- save current input stream settings
        SFILE FOPEN$                        --- attempt to open the file
        DUP 
        IF
            FLOADSS TRUE                    --- load file with no extension if it exists
        ELSE
            DROP
            " .FTH" SFILE $+!
            SFILE FOPEN$
            DUP 
            IF
                FLOADSS TRUE                --- else load file ending in .TXT
            ELSE
                DROP
                SFILE DUP LEN$ 3 - LEFT$    --- remove FTH from the filename
                " TXT" SWAP $+!             --- and add TXT
                SFILE FOPEN$
                DUP
                IF
                    FLOADSS TRUE            --- else loads file ending in .FTH
                ELSE
                    DROP FALSE              --- no file found, signal failure
                THEN
            THEN
        THEN
    ;
    
    --- enable / disable unknown word search on SD card
    pub BATCH   ( ON | OFF -- ) 
        IF
            ' SDEXEC unum W!                --- if unknown word, attempt execute from SD card
        ELSE
            0 unum W!                       --- else return normal operation
        THEN
    ;
    
    
    
  • Hi @bob_g4bby,

    I am not a FORTH fan at all, but played around a bit with it a while ago getting FORTH in lower RAM and Flexspin in higher RAM working together to present TAQOZ as a usable Object for Spin/Basic/C, whatever.

    Basically I got it running, but lost interest while Peter was changing the binary almost daily so I could not really send something to Eric.

    My plan was to present a TAQOZ object where you can send string commands to TAQOZ from any supported language and receiving the response and being able to use the power and speed from TAQOZ by letting TAQOZ doing the whole IO thing, just using it as coprocessor, somehow.

    I started with ROM TAQOZ but needed to change serial I/O from TAQOZ to a Mailbox, then switched to including a changed version with serial already redirected and lost somehow the drive to do it because defining words in Spin Source looks ugly and takes away a lot of memory.

    What you did here would eliminate the problem, I could use ONE TAQOZ binary and load the needed words from SD without compiling them into the Flexspin source (Spin Basic C whatever).

    This is great. Really.

    I hammered with real work right now, but you gave me some reason to look into that again, as soon I have more time.

    Here the link to the old thread, if you are interested... https://forums.parallax.com/discussion/169620/hijacking-the-p2-eval-rom-now-hijacking-current-taqoz#latest

    Enjoy!

    Mike

  • bob_g4bbybob_g4bby Posts: 440
    edited 2022-06-19 14:37

    Hi Mike (@msrobots), thanks for the nice comments.
    I remember your 'Taqoz as i/o coprocessor' conversation with Peter. Good to hear the sdcard utility has got you thinking about it again. Since Taqoz doesn't change much any more, it's been worthwhile writing forth libraries and documentation for it, which hopefully increases the number of users. A language needs to be stable for a community to grow around it. When you've more free time I hope you have another go and publish some code. A bridge to the other languages would also attract more users.
    Cheers, Bob

  • Hi Mike and Bob,
    interesting discussion!
    As there is a slowly growing amount of libraries, I have been thinking how to make them available to Forth. One way to achieve this would be to include a Forth written in C, like Atlast. https://www.fourmilab.ch/atlast/
    Christof

  • bob_g4bbybob_g4bby Posts: 440
    edited 2022-06-28 09:45

    Have you had a chance to try Atlast on the propeller, Christof ? It's certainly a unique add-on for any application written in C. It would be slower than Taqoz - but that isn't a big deal for the purpose it's been designed for.

  • No not yet.
    I have tried a version for arduino (on Teensy4, I think) and a version for raspi Pico, where I was able to enable the usage of its 2 cores. So I am quiet confident, that it is possible.....

Sign In or Register to comment.