Skip to content

10.Features

Matteo Vitturi edited this page Aug 15, 2024 · 5 revisions

Main Features

This is a partly standardised FIG-Forth ported to the new Sinclair ZX Spectrum Next based on my previous work available somewhere in The Internet. The main difference from previous non-Next versions is that v-Forth can INCLUDE any source file via NEEDS and in addition, it uses a single dedicated file on SD to provide a Block/Screen persistency (instead of on ZX Microdrive cartridges or DISCiPLE disks).

Though -- as per it core -- this is a well working piece of software, its library is still “work-in-progress”, as there are many things to do to cope with all the new Sinclair ZX Spectrum Next's functionalities.

The binary-core is now built using Visual Studio Code resulting in less than 7.5 KBytes (plus 3.5 K for name-space). In the past -- up to 2022 -- it was built by compiling a single Forth source-file.

For historical reasons, this Forth is greatly influenced by Oasis's White Lightning, but many parts come from many ideas I read in ad old book "Forth: An Application Approach - D.Toppen - 1985 - McGraw-Hill" (Italian translation "Il Forth in pratica - D.Toppen - 1985 - McGraw-Hill" ). Credits and thanks also must go to Marcos Cruz (programandala.net) the first person who appreciated my ZX-Microdrive version of this Forth. Also credits to Marcos Cruz's "Solo Forth" who gave me the idea of using IX register as NEXT address for instance.

Dot Command

Starting from version 1.7 build 20231004 a dot-command .vforth can be used along with a plain vForth installation. It accepts a single parameter that is taken as auto-start source file, for example

.vfroth demo/fedora.f

Screen / BLOCK facility

The BLOCK disk access is completely my own work. In this implementation the disk-access uses some NEXTZXOS API, namely DOS_SET_POSITION ($0136), DOS_READ ($0112) and DOS_WRITE ($0115). All read'n'write BLOCK operations involve the file via suitable F_OPEN NEXTZXOS API. It comes with a 16 MBytes file that is the straight concatenation of all Screens/BLOCKS. Despite of ZX-Microdrive version's legacy, each Screen is now 1,024 Bytes in length. In this implementation, a Screen is formed by two BLOCKs: A Screen can be LOADed by LOAD using a positive integer number to refer to the Screen and at any time, you can LOAD any part of that library and you can modify or improve it using the Line-Editor shown here below. Also, this implementation provides seven BUFFERs where Screen's BLOCKs can be edited using Line Editor Facility.

AUTOEXEC facility

At the very first COLD startup, the word AUTOEXEC is invoked and that in turn does a 11 LOAD execution. In this implementation, it eventually loads some useful utilities such as the Line-Editor , the Case-Of structure , the Debugger and Full Screen Editor. You are also allowed to modify the content of Screen# 11. Once the first AUTOEXEC is executed it won't be executed again in the subsequent COLD or WARM start. But, you can execute it giving directly AUTOEXEC.

LOAD from any source file

Any source-file can be included using INCLUDE definition that handles file of any size but line-length is limited to 511 bytes, but NEEDS <NNNN> is the correct way to import these definitions non included in the core binary to keep the smallest possible size of the core itself.

Output can be collected to file

A standard OPEN #13,"o>output.txt" performed from Basic before entering Forth environment allows redirection of any emitted output to "output.txt" file by selecting such a stream via 13 SELECT.

GRAPHICS Library

The ZX Spectrum Next's machine can handle several Graphic-Modes and v-Forth is able to use them via NEEDS GRAPHICS. In all the definitions of this library, the x-coordinate is the vertical distance from the top-left corner of the grid, the y-coordinate is the horizontal distance from the top-left corner of the grid. The core part of this library was written in Assembler to achieve an useful speed.

MOUSE Library

An interrupt-driven mouse facility is made available via NEEDS MOUSE which requires INTERRUPTS library. Sprite # 0 image is made a white arrow shape with shadow and its definition is given directly in Forth code, and this, by the way, shows how easily Forth language can perform such a task.

Raspberry Pi Zero

A few high-level definitions are available to allow interaction with RPi0's Bash-shell via internal UART. For example:

ASK echo $BASH_VERSION

The Unix command that follows ASK -- a whole line -- is sent to RPi0, and its reply is received in PAD, reply lenght is returned on stack, so that you can simply use:

PAD SWAP TYPE

to display the answer: "4.4.12(1)-release"

Full-Screen-Editor

Screens# 190-197 provide a nice full screen editor that works as a wrapper around the old Line Oriented Editor that can be used modify any Screen once you made it the Current Screen using the LIST word. For example, you can give 4 LIST to display the content of Screen # 4 and then EDIT to directly edit it. The Line-Editor itself is formed by a group of half-a-dozen definitions. See the dedicated Wiki-page for details.

Decompiler

Imported via NEEDS SEE, it allows the inspection a word: if the word is a colon definition SEE shows its peculiar addresses followed by the definitions used to define it. If the word is a primitive -- word defined directly in Assembler -- then the first few bytes are are DUMPed to video. See the dedicated Wiki-page for details.

Assembler vocabulary facility

Imported via NEEDS ASSEMBLER, it provides a quite complete Z80-Assembler with Z80 Next extensions. It uses a peculiar post-fix notation close enough to the real Z80 Assembly we are familiar with. For years, I used this ASSEMBLER vocabulary to rebuild this Forth system. See the dedicated Assembler Wiki-page for details.

MMU memory management unit

Among ZX Spectrum Next new features is the huge amount of RAM. Strings are dictionary expensive, so it would be useful storing them in HEAP as constant-strings and fetch them at need. These 8K pages are a good place to store an array of strings, or even numeric array and implement some matrices algebra. This implementation moves away the Dictionary Name-Space and provides an heap memory facility: This HEAP can be seen as a 64K “double-linked-list” area starting at 8K page $20 and it provides a easy way to fit any of 8K RAM bank at MMU7 slot (address E000-FFFF), for instance this is an easy addressing way to Layer 2 memory area.

Floating Point Option

There is a simple FLOATING Point Option Library that exploits the native standard ZX Spectrum Floating-Point capabilities (via RST $28 service routine), with a few differences. To load this Floating-point Option Library you have to use NEEDS FLOATING. This option can't work from dot-command.