RedForth
Program the original 65EL02 computer in Forth, from the stack to saving a bootable disk.
RedForth is the Forth system of the original RedPower 2 computer. The original system disks are
bundled unchanged: the
RedForth System Disk has 196 base words, and the
RedForth Extended System Disk (Forth XP) has 222, adding block editing and
Sortron commands. Boot one as described in
The original 65EL02 computer.
Tip
Built-in words are uppercase and case-sensitive. Keep a space between every word.
The stack
Numbers go onto a stack; the last one is used first. . prints and removes the top number.
10 3 - .
prints 7.
5 DUP * .
prints 25. .S shows the stack without changing it, and DROP removes the top item.
Your first word
: SQUARE DUP * ;
7 SQUARE .
defines SQUARE and prints 49. Your words live in RAM until you save a bootable image.
Variables
VARIABLE COUNT
42 COUNT !
COUNT @ .
1 COUNT +!
COUNT @ .
prints 42, then 43. ! writes a cell, @ reads it.
Loops and conditions
Control words belong inside a colon definition.
: COUNT3 3 0 DO I . LOOP ;
COUNT3
prints 0 1 2. DO takes its limit first, then its starting index.
: SIGN DUP 0< IF ." NEG" ELSE ." POS" THEN DROP ;
5 SIGN
5 NEGATE SIGN
prints POS, then NEG. True flags are -1 and false flags are 0.
Bundled outputs
Install a
Redbus I/O Expander at address 3 and connect bundled cable to it.
3 IOXADDR !
1 IOXSET
20 TICKS
1 IOXRST
pulses the white channel for about one second (20 game ticks). Each colour is one bit:
| Bit | Colour | Bit | Colour |
|---|---|---|---|
| 1 | white | 256 | light gray |
| 2 | orange | 512 | cyan |
| 4 | magenta | 1024 | purple |
| 8 | light blue | 2048 | blue |
| 16 | yellow | 4096 | brown |
| 32 | lime | 8192 | green |
| 64 | pink | 16384 | red |
| 128 | gray | 32768 | black |
3 IOX! turns on white and orange and clears every other output. 0 IOX! turns all outputs off.
IOX@ U. prints the inputs as an unsigned mask.
Save a bootable program
Bundled system disks are read-only. To keep your words:
- Boot from a system disk and define your program.
- Eject the system disk and insert a
Blank Floppy Disk. - Type
SAVE" MYPROGRAM".
Boot from that floppy later to get your environment back.
Forth XP: the block editor
Boot the XP disk, then replace it with a writable floppy.
1 BLOCK DROP
WIPE
0 PP : HELLO ." HI" ;
FLUSH
1 LIST
1 LOAD
HELLO
This stores, lists and loads a one-line program. Blocks are numbered 1 to 256, each sixteen lines of
64 characters. PP replaces a line, FLUSH writes the block, REVERT discards unsaved edits.
Forth XP: the Sortron
With a powered
Sortron at address 4, an inventory at its working face and a tube
outlet:
4 SORTADDR !
SORTSLOTS .
0 SORTSLOT@ . . .
1 0 SORTPULL .
prints the slot count, inspects slot zero, and requests one item from it. See Manager and Sortron for the hardware.
Useful words
| Word | Does |
|---|---|
WORDS |
List every word, including yours. |
FREE . |
Free memory. |
FORGET NAME |
Remove a word and everything defined after it. |
HEX, DECIMAL |
Number base. |
TICKS |
Wait a number of game ticks. |
PAGE, CR, EMIT, TYPE |
Screen output. |
KEY, KEY? |
Keyboard input. |
DISKNAME" WORK" |
Label a writable floppy. |
DISKRS, DISKWS |
Read or write one 128-byte sector. |
RBP! |
Select a Redbus device for the mapped register window. |
The in-game recipe guide lists all 196 base and 222 XP words with examples.
When a program is stuck
Close the terminal and use the Front Panel: its reset button, or Halt, Reset and Start in the CPU controls.