FORTH on the PicoCalc

This is kind of buried in Modules in zeptoforth · tabemann/zeptoforth Wiki · GitHub. Yah, foo::bar is specifically a zeptoforth feature, where foo is a word that pushes the ID of a wordlist/module, and bar is a word in that wordlist/module. This can be chained, e.g. one can write foo::bar::baz where bar is a word that pushes a wordlist/module ID in the wordlist/module whose ID is pushed by foo, and baz is a word in the wordlist/module whose ID is pushed by foo::bar.

I have made some changes to make colors brighter (I had previously set the low bits of each component to 0 when converting from 8-bit to 16-bit colors rather than extending the lowest bit of each of 8-bit colors’ components) and to optimize the text-only display driver a bit.

so :: is a separate word that NOT whitespace delimited? Does :: have a unique parsing mechanism? thanks

:: is not a word, and is specifically not whitespace-delimited – rather, it is a feature in the word lookup logic, which checks words being looked up for it, and if it is present, it first resolves what precedes the :: and uses that to obtain a wordlist/module ID which it applies to resolve what comes after it.

:: seems similar to classic forth “vocabulary”, but looks “object oriented”. Am i on the right track?

:: is not about object-orientation even though zeptoforth does have optional object-orientation. Rather, it is about namespacing. It is an alternative to explicitly importing a wordlist/module into the current namespace with import ( wid – ) which does modify the current search order.

For instance the following are equivalent:

begin-module hello
  : hello-world ( -- )
    cr ." Hello, world!"
  ;
end-module

hello::hello-world

and

begin-module hello
  : hello-world ( -- )
    cr ." Hello, world!"
  ;
end-module

hello import

hello-world

These are also equivalent to:

begin-module hello
  : hello-world ( -- )
    cr ." Hello, world!"
  ;
end-module> import

hello-world
1 Like

Where do I find source for the word “words”? I wish to display two columns on the picocalc screen (so it fits); and try 6 columns on my terminal emulator (teraterm). Thanks

Not on-topic for the PicoCalc, but I found several issues of the old MMSForth Newsletter. You can download about a dozen issues here: \home\nathanael\DiskStation\web\cpm\trs80\Library\

It seems that each of the issues was scanned in twice, the scans in the left column seem to be duplicates of the scans in the right column.

Not sure how much this might help with Forth on the PicoCalc, but it should, at least, be interesting.

It’s in src/common/forth/basic.fs. You might also want to look at more-words, which is in src/common/forth/more_words.fs

I added a screenshot tool picocalc-screenshot::take-screenshot ( dir-path-addr dir-path-bytes fs – ) for the graphical terminal emulator in extra/rp_common/picocalc_screenshot.fs.

It takes the path of a directory (which it will create if it does not already exist) to place a screenshot file with the name SCRxxxxx.BMP in in 8-bit RLE BMP format along with a filesystem (e.g. fat32-tools::sd-fs@ for the SD card filesystem).

It will automatically assign filenames for screenshots in ascending numerical order starting at SCR00000.BMP.

Here is a screenshot of my emulated setup (note that my display is 320x240 rather than 320x320):

Edit: I have now also added a similar screenshot tool for the text-only terminal emulator in extra/rp_common/picocalc_screenshot_text.fs. Note that if you are to use it you will need to update the text-only terminal emulator because implementing it required making modifications to the text-only terminal emulator.

Is it part of EVALUATE / WORD / equivalents as well? If I were to write a REPL, what would I need to do, to ensure I parse and lookup words the same way? For that matter, where does it “live” (both in word terms – it isnt a word does it live inside another word?, and src terms)?

Thanks!

It lives in internal::do-find-with-module which the hook find-hook is set to in src/common/forth/module.fs, and anything that uses find (note that this is not the same as the ANS Forth word of the same name) to look up a word, whether directly or indirectly. E.g. anything that uses token-word to look up a word from a parsed token ultimately uses find. The same goes with compat::find, which functions the same as ANS Forth find.

In the vast majority of cases :: just works; the main thing I have encountered that does not know know about :: is defined?, which does a global lookup in all wordlists/modules (I have been tripped up by this). And yes, it works just the same with, say, evaluate as everywhere else.

Okay, great, very much appreciate the info. I’m still “getting my sea legs” with zeptoforth, and figuring out specifically how I can do what I’m thinking, so please excuse my questions. I’ve got familiarity with Forth, but every “platform Forth” has a ton of low-level differences, so I’m just feeling out the ones here to get a sense of what’s possible. Thanks again!

As they say, “if you’ve seen one Forth, you’ve seen one Forth”. :: in particular is a highly non-standard feature of zeptoforth, one I use heavily because it is so useful.

1 Like

I have now implemented being able to take screenshots with Attention (on the PicoCalc terminal emulator Break (Shift-Escape), on the serial console Control-T) followed by s. To implement this both versions of the terminal emulator had to be modified, and the screenshot code has to be loaded.

To signify to the user that something has happened, the display will be flashed prior to taking the screenshot if the user uses Attention s to take it. There will be a momentary pause while the screenshot is written to file.

It is recommended that you load extra/rp_common/picocalc_screenshot.fs or extra/rp_common/picocalc_screenshot_text.fs after loading extra/rp_common/picocalc_fat32.fs. If you have done so it will automatically use, in the following order, first the SD card FAT32 filesystem, then the PSRAM FAT32 filesystem, then the on-board flash FAT32 filesystem, depending on what is configured.

Note that the filesystem to use can be set with picocalc-screenshot::screenshot-fs! ( fs – ).

The directory that it uses is by default /SCREEN, but this directory can be changed with picocalc-screenshot::screenshot-path! ( path-addr path-bytes – ). If the directory does not exist it will be created, but the parent directorie(s) will not be created automatically.

I found internal::do-find-with-module find-hook and src/common/forth/module.fs. But I don’t see any ‘::’

I just want to see the code that says “I parsed :: and now I do X”. This seems like a difference I want to full understand. Thanks.

I want to modify “words” such that the output fits on my (narrow) picocalc and my (very wide) terminal emulator. May I assume the I start with the minimal kernal and load specific script(s) that will include src/common/forth/basic.fs ? Where do we find the needed scripts to build a modified “full” build?
Thanks

internal::do-find-with-module and the words it calls implement a simple parser that parses identifiers containing a :: and resolves them.

I would suggest making a new source file incorporating the modified words (and I would also suggest modifying more-words) rather than modifying src/common/forth/basic.fs. That way you can just load it on top of an existing build rather than making a new build from scratch.

That said, as to how to make a new full build, flash your board with just the kernel desired (or if you are not changing kernels, just execute erase-all on an existing install), and then execute in a shell at the base of the zeptoforth source tree:

$ utils/codeload3.sh -B 115200 -p <your tty device> serial src/<your platform>/forth/setup_full.fs

I have added the following words to the picocalc-term module to interface with the PicoCalc’s BIOS:

read-battery ( – battery-level )
Read the PicoCalc’s battery level

set-backlight ( desired-backlight-level – actual-backlight-level )
Set the PicoCalc’s display’s backlight level.

read-backlight ( – backlight-level )
Read the PicoCalc’s display’s backlight level.

set-kbd-backlight ( desired-kbd-backlight-level – actual-kbd-backlight-level )
Set the PicoCalc’s keyboard’s backlight level.

read-kbd-backlight ( – kbd-backlight-level )
Read the PicoCalc’s keyboard’s backlight level.

Note that these have not been tested on an actual PicoCalc, so I cannot guarantee that they will work, and would really appreciate it if you guys tried them out.

More:

I created a ‘Matrix’ demo, which is at test/rp_common/picocalc_matrix.fs. A screenshot is below:

1 Like