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

Loading An Extension

Introduction

VLIST showed you a great many words, and still SuperForth cannot draw a line, play a tune or pick a random number. It can, though - just not yet. Those words are on the disc, written in Forth, in files like the one you made in S9, waiting to be loaded.

This is how the whole system is meant to be used. You load what a program needs and nothing else, and the room is left for your own work.

What Is On The Disc

FileHolds
UTILITYrandom numbers, arrays, typed-in numbers, the clock and more
GRAPHICSdrawing
SPRITESmoving shapes
SOUNDSthe sound chip
FLOATnumbers with decimal points
FUNKEYSthe function keys
GAMEa complete game, to read

DOSTOOLS and EDITOR40 are there too; they are already inside BIGFORTH.

Looking Inside A File

SuperForth works on one file at a time. NEWFILE changes which:

NEWFILE UTILITY

Now LIST, LOAD and the editor all mean UTILITY. Your own file has been closed, safely, first.

The author put a comment on the top line of every screen, so INDEX gives you a table of contents:

1 8 INDEX

Loading Part Of One

You load just the screen you want. Screen 1 is the random number generator:

1 LOAD

and now there is a new word. 100 CHOOSE leaves a number from 0 to 99.

Notice that LOAD counted only three blocks, not eight. The screen ends with the word ;S, which means "stop loading here", and the rest of it is blank.

The Code

At the 0: prompt:

BIGFORTH

Then:

NEWFILE UTILITY
1 8 INDEX
1 LOAD
100 CHOOSE .

Starting from

A fresh boot of the course disc, with BIGFORTH started and no file named.

What you should see

  1 ( RANDOM NUMBER GENERATOR )
  2 ( MACHINE CODE SUBROUTINE CALL )
  3 ( ARRAY DEFINING WORDS )
  4 ( NUMBER INPUT & ADC PORTS )
  5 ( DIRECT KEYSCAN )
  6 ( TIME WORDS )
  7 ( BAUD RATE SET AND SERIAL PORT )
  8 ( DOUBLE NUMBER EXTENSIONS )ok
1 LOAD

Loading Blocks: 1 2 3 ok
100 CHOOSE .
79 ok

UTILITY's index, screen 1 loaded, and a number chosen

Your number will be 79 too. S20 explains why, and what to do about it.

Getting Back

The words you loaded stay in memory when you change file, so the routine is: open the extension, load what you need, and go home.

NEWFILE UTILITY
1 LOAD
NEWFILE MYWORK

After that your own screens can use CHOOSE as if it had always been there.

Unloading

Most extension screens start by defining a word that does nothing, for exactly the reason you met in S8. Screen 1 of UTILITY starts with : RANDTASK ;, so

FORGET RANDTASK

takes the random number words out again, along with anything you defined after loading them.

Mind Your Spelling

NEWFILE will open anything. If the file does not exist, it says New File and makes one. So NEWFILE UTILTY gives you an empty file with a silly name, and a LOAD from it loads nothing. BIGFORTH has a word to clear up: DELETE-FILE removes whichever file is current. Make very sure which file that is - .FILE tells you - before you use it.

Change One Thing

  • Type NEWFILE GRAPHICS and 1 4 INDEX. What is on the fourth screen?
  • Load screen 1 of UTILITY twice. What does SuperForth say? Then FORGET RANDTASK once. Does CHOOSE still work? Why?
  • Type NEWFILE UTILTY, with the mistake. Then .FILE, then DELETE-FILE, then DIR. What is the current file afterwards?
  • Use 2 LIST to read screen 2 of UTILITY. You will not understand all of it yet. What is the last word on the screen, and what is it for?

Exercises

18.1 FLOAT is 22 screens long. Find out how many of them are in use, using INDEX.

18.2 Load CHOOSE, then go back to a file of your own, and on screen 1 of it define DICE ( -- n ) to leave a number from 1 to 6. Save and load it.

18.3 Restart BIGFORTH with your file. 1 LOAD fails. Why, and what do you have to do first, every time?

Worked solutions are in Appendix II.

When It Goes Wrong

SymptomCause
New File when you expected an extensionThe name is misspelt. You now have an empty file of that name; DELETE-FILE while it is still current.
CHOOSE? from your own screen after a restartExtensions live in memory. Load them again each session before your own screens.
Isn't Unique several times during a loadThat screen was already loaded.
Your own words have vanishedYou used FORGET on an extension's marker, which takes out everything defined after it, including yours.

Summary

NEWFILE name changes the current file; INDEX shows what its screens hold; LOAD brings one in, stopping at ;S. The loaded words stay when you switch back to your own file, until you FORGET the extension's marker word or leave SuperForth. Load what you need, each session, before your own screens.

Next

S19, Asking A Question - getting a number, not just a keypress, out of the person at the keyboard.

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.