APPLE1 REPLICA1 OR CFFA1 AND FORTH +

 

BACk AND Forth...

Originally, the Apple I didn’t have any storage option and only 8K of RAM.  Woz eventually built a very clever cassette interface for saving and loading programs, but the Apple I was soon abandoned for the development of the groundbreaking Apple II.  30 years later, the Apple I has become a bit of a cult computer, and replicas and clones have cropped up over the years.  Vince Briel’s Replica 1 simplified the design using some modern micro-controllers and extended it’s I/O somewhat.  Rich Dreher brought his successful Apple II Compact Flash interface to the Apple I, enhancing the Apple I’s RAM memory with an additional 32K and providing a rudimentary ProDOS compatible filesystem.  This set the foundation for a full port of Forth to the Apple I and CFFA1.


Forth is to BASIC what HP calculators are to TI calculators.  Forth uses postfix notation to represent it’s order of operations (go back and review this page’s title).  Using two stacks, one for parameters and one for return and loop values, it can represent complex algorithms quite efficiently.  Its terse and obscure syntax has also given it the moniker “a write-only language.”  However, Forth provides a powerful programming environment including runtime, compiler, editor, assembler, and disk I/O all in less than 10K of memory.  It also executes as a fairly fast indirect threaded interpreter.  Some parts of the Forth package are not required to be resident at all times.  The editor and assembler can be loaded only when needed, saving precious bytes.


Since Forth was meant to be portable, getting it running on the Apple I was rather easy.  The biggest challenge was mapping the Forth style block I/O to the file handling API of the CFFA1.  I decided to map every Forth 1K disk block to a separate ProDOS filename: BLOCK0001 would be block #1 to Forth.  Trust me, there were reasons to do so.  Forth was now running on the Apple I/CFFA1 and reading and writing disk blocks.  Unfortunately, the editor and assembler source had been lost over the years.  Luckily, the Forth Interest Group (FIG) that wrote the original figForth has all of their Forth Dimension journals scanned and online on their website: http://www.forth.org/fd/contents.html.  I typed in the editor (actually a polyForth compatible editor - more on that in just a sec) and the FORTH-65 assembler from the listings.  All of the pieces were now in place to return to yesteryear and learn Forth, just like it was 1976.


Probably the best know primer for Forth is “Starting Forth”, by Leo Brodie.  Although out of print, it lives on in the internetz: http://www.forth.com/starting-forth/.  This would be the recommended place to begin learning about Forth.  “Starting Forth” uses a version of Forth called polyForth which is slightly different than the figForth version running on the Apple I.  To understand the differences, review the figForth glossary available in the FIG Installation Manual and Glossary.  The editor included clones the editor included in polyForth.  It is described in Forth Dimension: Volume 3, Number 3 , page 80.  The FORTH-65 assembler is described in Forth Dimension: Volume 3, Number 5, page 143.


To get started, enter the CFFA1 menu with a 9000R.  Change the prefix to FORTH, and load the binary file F1 at it’s default address of $0270.  Quit the menu and start Forth with a 270R.  $0270 was a compromise load address that leaves plenty of room for the keyboard input buffer and satisfies certain alignment constraints required by the 6502.


Forth leaves many details of system usage up to the programmer.  Data types are whatever the program wants.  Likewise, data stored in disk blocks are free-form and has no file system, per se.  Loading programs requires knowing what disk block, or screen as it is known in Forth parlance.  The editor code resides at block 200 so load it by typing:


200 LOAD


You will see the following message during loading:


I ERROR 4: THIS IS AN EXISTING DICTIONAR

Y ENTRY. R ERROR 4: THIS IS AN EXISTING

DICTIONARY ENTRY. OK


The messages are just warnings and don’t affect the functionality of the editor.  The Apple I screen is only 40 characters wide, which is why it looks funny above.


The assembler is loaded from block 80.


80 LOAD


INDEX ERROR 4: THIS IS AN EXISTING DICTI

ONARY ENTRY. # ERROR 4: THIS IS AN EXIST

ING DICTIONARY ENTRY. 0= ERROR 4: THIS I

S AN EXISTING DICTIONARY ENTRY. 0< ERROR

4: THIS IS AN EXISTING DICTIONARY ENTRY

. OK


Again, these are warnings.  I haven’t tried assembling anything as the assembler is quite different than anything you’ve used before.  Remember, this is Forth, so the opcodes and operands are in postfix.  It is fully documented in the Forth Dimension issue Volume 3, Number 5, page 143.


Blocks 0-3 are used as a directory of programs.


0 LIST


will provide a list of programs and their blocks.  Use the editor to extend the listing.  Anyone remember using the tape counter when loading and saving programs to/from cassette?  Yeah, it’s just like that.


The Apple I doesn’t really have a monitor routine that you can easily call into and return from.  So, as a replacement for MON, I added a command called MENU which sends you to the CFFA1 menu.  Quit the menu to return back to Forth.


The only other enhancement I made was the line input routine.  The Apple I doesn’t have any character positioning control, not even backspace.  In order to know where you are in a line when backspacing, I print a ‘\’ and the character just backspaced over.  You can follow along and figure out where the internal cursor is.  The ESCAPE key cancels the entire line.  Many Apple I/Replica1 owners use a serial or USB interface that transparently hooks into the 6821 and intercepts the keyboard and screen I/O.  The backspace key will actually backspace over the character - just be sure to enable “destructive backspace” in your terminal emulation program.


The last thing you need is the archive to install on the CF card.  Here is the ShrinkIt archive (you will probably need to right click and ‘Save linked file as...’).  Enjoy the return to yesteryear and relish the simplicity and elegance that is Forth.


Version 1.1

I fixed the error when loading a screen that doesn’t yet have a corresponding block file.  It now clears out the screen and continues on.  The block file will be created if the screen is altered.


Version 1.2

Removed some of the opening text to save some bytes and clean it up.  Load address is now $0240 making more bytes available.  Also, moved the directory screen to block 1 from block 0.  figForth initializes the block number to 0, so if the first thing you do is type ‘0 LOAD’ you would get nothing.  Block 0 is now reserved and shouldn’t be used.


Forth links:

Apple I/Replica1 Forth ShrinkIt archive: FORTH1-1.2.shk

What is Forth? http://www.angelfire.com/in/zydenbos/WhatisForth.html

Starting Forth: http://www.forth.com/starting-forth/

Thinking Forth: http://thinking-forth.sourceforge.net/

Forth Interest Group (FIG): http://www.forth.org

Forth Inc.: http://www.forth.com/

Forth Dimension scans: http://www.forth.org/fd/contents.html

FIG Installation Manual and Glossary: http://www.forth.org/fig-forth/figdoc.zip

Green Arrays, Inc.: http://GreenArrayChips.com

John B. Matthews ProForth pages: https://sites.google.com/site/drjohnbmatthews/apple2/proforth