SuperForth for the Tatung Einstein, showing a SuperForth 1.12 session defining a word
← Back to Courses
module
9

Keeping Your Work

Introduction

Everything you have defined so far has lived in the machine's memory and died with it. That was fine for SQUARE. It is not fine for anything you spent an evening on.

SuperForth keeps programs on the disc, as text, in files. You type your definitions into a file with an editor, and then tell SuperForth to read them. This section gets a program onto the disc and back again.

A Bigger Forth

The FORTH you have been using is the language and nothing else. It has no editor in it. SuperForth's editor is itself written in Forth, it takes up room, and a finished program does not need it.

The course disc carries a second version, BIGFORTH, which is FORTH with the editor and a few disc tools already loaded. It was made with SuperForth itself, following the instructions in its own manual, and nothing in it differs from what you have been using. It is simply further along.

On a real Einstein with your own SuperForth disc, BIGFORTH is not there until you make it. Do that now, on your backup disc: Appendix III has the seven lines, and DIR at the 0: prompt will tell you whether the disc has the 16K free that it needs.

From here on, use BIGFORTH.

Opening A File

You name your file when you start. At the 0: prompt:

BIGFORTH MYWORK

SuperForth adds .FIG to the name, looks for MYWORK.FIG on the disc, and because it is not there, tells you it is starting a fresh one:

New File

Z80A Einstein SuperFORTH 1.12
     (c) 1984 Peter Amey

Next time, when the file exists, it says nothing and just opens it. (That is the other half of the No File Open you have been seeing since S2.)

Screens

A SuperForth file is not one long scroll of text. It is a stack of screens, numbered from 1. Each screen is sixteen lines, numbered 0 to 15. You write on one screen at a time.

It is a small page, and that is the point. A screen holds a handful of short definitions - about as much as you can hold in your head.

The Editor

1 SELECT

opens screen 1 in the editor. The display changes completely:

The editor showing five definitions on lines 0 to 4 of screen 1

The top row tells you which screen you are on and which column the cursor is in. Down the left, in reverse, are the line numbers. Each line of your screen takes two rows of the display, because a screen's lines are wider than the Einstein's 40 columns, so a long line simply carries on underneath itself. The 40 character rule from S7 does not apply in here.

Now just type. ENTER takes you to the start of the next line. If you make a mistake, DEL rubs out backwards. S10 covers moving around and changing things; for now, type carefully.

When you have finished, press ESC. You are back at SuperForth, below the editor's display.

In MAME, ESC is your Esc key and DEL is Backspace.

Saving, And Loading

Leaving the editor does not put anything on the disc. Your screen is in memory. To write it:

FLUSH

And now the part that makes it all worthwhile:

1 LOAD

LOAD reads screen 1 exactly as if you were typing it, line by line, only much faster. Every definition on it is compiled. When it has finished, your words exist.

The Code

At the 0: prompt:

BIGFORTH MYWORK

Then:

1 SELECT

In the editor, type these five lines, pressing ENTER after each, and then press ESC:

: STAR ." *" ;
: STARS STAR STAR STAR STAR STAR ;
: EDGE STARS CR ;
: MIDDLE STAR 3 SPACES STAR CR ;
: BOX CR EDGE MIDDLE MIDDLE EDGE ;

Back at SuperForth:

FLUSH
1 LOAD
BOX

Starting from

A fresh boot of the course disc, at the 0: prompt, with no file called MYWORK on it yet.

What you should see

FLUSH
ok
1 LOAD

Loading Blocks: 1 2 3 4 5 6 7 8 ok
BOX

*****
*   *
*   *
*****
ok

Loading Blocks is SuperForth counting its way through the screen as it reads it.

Proving It

Now find out whether it really is on the disc. Type DOS, restart the Einstein - in MAME, close the window and run the command again - and at the 0: prompt:

BIGFORTH MYWORK

This time there is no New File. Try your word before loading anything:

BOX
BOX?

It has never heard of it - SuperForth has only just started. Then:

1 LOAD
BOX

After a restart: BOX is unknown, screen 1 is loaded, and BOX draws the box

That box came off the disc.

Looking Around

WordShows
1 LISTscreen 1, without opening the editor
.FILEthe name of the file you have open
DIReverything on the disc, and the current file's name

DIR is one of the disc tools in BIGFORTH. Your file is in the list as MYWORK .FIG. The files with a * beside them are SuperForth's own and are locked, so that you cannot overwrite them by accident.

Always Leave Through DOS

FLUSH writes your screens to the disc. So does DOS: it saves anything outstanding on its way out. Switching off does not, and nor does closing the MAME window. Make a habit of FLUSH after every spell in the editor and DOS before you stop the machine, and you will never lose more than a few minutes.

Change One Thing

  • After loading, type 1 LOAD a second time. What does SuperForth say about each word, and is anything actually wrong? (S7 has the answer.)
  • Type 1 LIST. Then 2 LIST. What is on a screen you have never written to?
  • Start BIGFORTH with no file name at all and try 1 LIST. What does it tell you, and what should you have typed?
  • Type DIR before and after you first FLUSH a brand new file. When does the file appear on the disc?

Exercises

9.1 Start BIGFORTH with a new file called SHAPES. Put TRIANGLE from S8 on screen 1, save it, load it and run it.

9.2 Leave with DOS, restart with BIGFORTH SHAPES, and get TRIANGLE running again. How many things did you have to type?

9.3 Open MYWORK again and look at screen 1 with 1 LIST. Without opening the editor, how can you tell which file you are in?

Worked solutions are in Appendix II.

When It Goes Wrong

SymptomCause
You pressed ESC and MAME itself closedMAME's own control keys have been switched on, by forward delete on a Mac (Fn and Backspace on a laptop) or Scroll Lock on Windows. Press the same key again to switch them off. Appendix IV explains. Anything not yet written to the disc went with it.
SELECT?You started FORTH, which has no editor. Type DOS and start BIGFORTH.
New File when you expected your old oneThe name is not the one you used before. DOS, then DIR at the 0: prompt to see what it is really called.
Your words come back with a ? after restartingOpening the file does not load it. 1 LOAD.
Bad Data, Drive 0:You are not using the course disc. SuperForth can only save to an .mfi disc image - S2 explains.
Every word gets Isn't Unique during a LOADYou have loaded the screen twice. Harmless; S10 shows how to avoid it.

Summary

BIGFORTH name starts a SuperForth with an editor and opens your file. 1 SELECT edits screen 1, ESC leaves the editor, FLUSH writes to the disc, and 1 LOAD compiles the screen as though you had typed it. Always leave through DOS. Your work now survives.

Next

S10, Changing Your Mind - moving around in the editor, fixing a word that is wrong, using more than one screen, and letting SuperForth show you where a mistake is.

Get the Newsletter

New guides, disk images and community finds, roughly once a quarter. No spam, we promise, this isn't Tatung's marketing department.
Your subscription could not be saved. Please try again.
Your subscription has been successful.

Newsletter

Subscribe to our newsletter and stay updated.