Skip to content

Robert-van-Engelen/Forth500

PC-E500S

The PC-E500 is a powerful pocket computer introduced in 1989 that saw a PC-E500S successor in 1995.

Sébastien Furic's original (incomplete) ANS Forth compiler is available from the great retro web site Aldweb.

I've rewritten large parts of the code to optimize for speed, code size and compliance with the Forth Standard, see the changelog. The docol fetch-execute cycle is 40% more efficient. Words are now case-insensitive and can be typed in upper/lower/mixed case. All standard floating point words are now also included. Included in this repo are the binaries for unexpanded 32KB machines and expanded >96KB machines. Also included is the XASM assembler written by N. Kon for the SC62015 CPU. I translated the XASM documentation to English and I made a minor change to the XASM source code to be able to compile XASM with FreePascal (see XASM/PASCAL.txt). XASM is required to rebuild the Forth500 system from assembly. The Forth500.s source code is heavily documented and PC-E500 technical resources are included.

Discuss: HP Forum and reddit

Instruction manual

See the Forth500 User Guide with an introduction to Forth and a full description of the Forth500 system.

How fast is it?

The n-queens benchmark is solved in 3.47 seconds, faster than the compiled n-queens C program on a Sharp PC-G850VS that runs at 8.0MHz compared to the 2.3MHz PC-E500(S).

Load Forth500 via serial or cassette interface

To use Forth500, first load the binary, then CALL &B0000 (see expanded E500) or CALL &B9000 (see unexpanded E500). Forth500 starts immediately and can be exited with BYE. Call again to continue using Forth500 where you left off. Forth500 resides in protected memory and does not interfere with BASIC.

Forth programs can be loaded into Forth500 via the serial interface or cassette interface with PocketTools.

Editing Forth source files

TED is a small text editor for Forth500:

TED             edit the last file edited
TED FILE.FTH    edit FILE.FTH
TEDI            edit the last file edited, then read it into Forth500
TEDI FILE.FTH   edit FILE.FTH, then read it into Forth500

The TEDI command uses INCLUDE (or INCLUDED) to read the saved file.

See also TED.TXT.

Saving a Forth500 image to a file

SAVE saves the entire Forth500 image, including all user-defined definitions, to a binary file from Forth500:

SAVE F:MYFORTH.BIN

In BASIC execute (assuming memory for Forth500 is still allocated):

LOADM "F:MYFORTH.BIN"
CALL &B0000 (or CALL &B9000 on an unexpanded machine)

Batteries included...

Forth500 is Forth Standard compliant and includes the following words built in:

  • CORE and CORE-EXT complete: ABORT, ABORT", ABS, ACCEPT, ACTION-OF, AGAIN, ALIGN, ALIGNED, ALLOT, AND, BASE, BEGIN, BL, BUFFER:, [, [CHAR], [COMPILE], ['], CASE, C,, CELL+, CELLS, C@, CHAR, CHAR+, CHARS, COMPILE,, CONSTANT, COUNT, CR, CREATE, C!, :, :NONAME, ,, C", DECIMAL, DEFER, DEFER@, DEFER!, DEPTH, DO, DOES>, DROP, DUP, /, /MOD, .R, .(, .", ELSE, EMIT, ENDCASE, ENDOF, ENVIRONMENT?, ERASE, EVALUATE, EXECUTE, EXIT, =, FALSE, FILL, FIND, FM/MOD, @, HERE, HEX, HOLD, HOLDS, I, IF, IMMEDIATE, INVERT, IS, J, KEY, LEAVE, LITERAL, LOOP, LSHIFT, MARKER, MAX, MIN, MOD, MOVE, M*, -, NEGATE, NIP, OF, OR, OVER, 1-, 1+, PAD, PARSE-NAME, PARSE, PICK, POSTPONE, +, +LOOP, +!, QUIT, RECURSE, REFILL, REPEAT, RESTORE-INPUT, R@, ROLL, ROT, RSHIFT, R>, SAVE-INPUT, SIGN, SM/REM, SOURCE-ID, SOURCE, SPACE, SPACES, STATE, SWAP, ;, S\", S", S>D, !, THEN, TO, TRUE, TUCK, TYPE, ', *, */, */MOD, 2DROP, 2DUP, 2/, 2@, 2OVER, 2R@, 2R>, 2SWAP, 2!, 2*, 2>R, U.R, UM/MOD, UM*, UNLOOP, UNTIL, UNUSED, U., U<, U>, VALUE, VARIABLE, WHILE, WITHIN, WORD, XOR, 0=, 0<, 0>, 0<>, \, ., <, >, <>, #>, <#, #, #S, (, ?DO, ?DUP, >BODY, >IN, >NUMBER, >R
  • BLOCK removed to save space, not practical on the PC-E500
  • DOUBLE and DOUBLE-EXT complete: DABS, D.R, D=, DMAX, DMIN, D-, DNEGATE, D+, D2/, D2*, DU<, D0=, D0<, D., D<, D>S, M+, M*/, 2CONSTANT, 2LITERAL, 2ROT, 2VALUE, 2VARIABLE
  • EXCEPTION and EXCEPTION-EXT complete: ABORT, ABORT", CATCH, THROW
  • FACILITY complete: AT-XY, KEY?, PAGE
  • FACILITY-EXT mostly complete: BEGIN-STRUCTURE, CFIELD:, EKEY, EKEY?, EKEY>CHAR, END-STRUCTURE, FIELD:, 2FIELD:, +FIELD, MS
  • FILE and FILE-EXT complete: BIN, CLOSE-FILE, CREATE-FILE, DELETE-FILE, FILE-POSITION, FILE-SIZE, FILE-STATUS, FLUSH-FILE, INCLUDE-FILE, INCLUDE, INCLUDED, OPEN-FILE, R/O, R/W, READ-FILE, READ-LINE, REFILL, RENAME-FILE, REPOSITION-FILE, REQUIRE, REQUIRED, RESIZE-FILE, SOURCE-ID, S\", S", W/O, WRITE-FILE, WRITE-LINE, (
  • FLOATING and FLOATING-EXT complete: DFALIGN, DFALIGNED, DFFIELD:, DF@, DFLOAT+, DFLOATS, DF!, D>F, FABS, FACOS, FACOSH, FALIGN, FALIGNED, FALOG, FASIN, FASINH, FATAN, FATANH, FATAN2, FCONSTANT, FCOS, FCOSH, FDEPTH, FDROP, FDUP, F/, FEXP, FEXPM1, FE., FFIELD:, F@, FLITERAL, FLN, FLNP1, FLOAT+, FLOATS, FLOG, FLOOR, FMAX, FMIN, F-, FNEGATE, FOVER, F+, FROT, FROUND, FSIN, FSINCOS, FSINH, FSQRT, FSWAP, FS., F!, FTAN, FTANH, FTRUNC, F*, F**, FVALUE, FVARIABLE, F0=, F0<, F., F<, F~, F>D, F>S, PRECISION, REPRESENT, SET-PRECISION, SFALIGN, SFALIGNED, SFFIELD:, SF@, SFLOAT+, SFLOATS, SF!, S>F, >FLOAT, where the hyperbolics and FE. and F~ are defined in FLOATEXT.FTH to load separately to save memory
  • STRING complete: BLANK, CMOVE, CMOVE>, COMPARE, /STRING, -TRAILING, SEARCH, SLITERAL
  • STRING-EXT three words not implemented
  • TOOLS and TOOLS-EXT mostly complete: .S, ?, AHEAD, BYE, DUMP, FORGET, STATE, N>R, NR>, WORDS, [DEFINED], [ELSE], [IF], [THEN], [UNDEFINED]
  • SEARCH and SEARCH EXT partly complete: DEFINITIONS, FIND, FORTH

Additional built-in Forth500 words:

  • introspection: COLON?, DOES>?, MARKER?, DEFER?, VALUE?, 2VALUE?, FVALUE?
  • values: +TO (single and double cell, not float)
  • variables: D+!, ON, OFF
  • arithmetic: UMAX, UMIN, 2+, 2-, M-, D*, UMD*, D/MOD, D/, DMOD, FDEG, FDMS, FRAND, FSIGN
  • logic: D<>, D>, D0<>, D0>, F<>, F>, F0<>, F0>
  • stack: -ROT, 2NIP, 2TUCK, DUP>R, RDROP/R>DROP, CLEAR
  • loops: K, ?LEAVE
  • strings: NEXT-CHAR, S=, -CHARS, EDIT, >DOUBLE
  • display: REVERSE-TYPE, PAUSE, BASE., BIN., DEC., HEX., N.S, TTY
  • printing: STDL, PRINTER
  • tape: TAPE, CLOAD
  • LCD: SET-SYMBOLS, BUSY-ON, BUSY-OFF, CURSOR, SET-CURSOR, X@, X!, Y@, Y!, XMAX@, XMAX!, YMAX@, YMAX!
  • graphics: GMODE!, GPOINT, GPOINT?, GLINE, GBOX, GDOTS, GDOTS?, GDRAW, GBLIT!, GBLIT@
  • sound: BEEP
  • vocabulary: VOCABULARY, CURRENT, CONTEXT
  • dictionary: LAST-XT, HIDE, REVEAL, L>NAME, >NAME, NAME>, FIND-WORD, CREATE-NONAME
  • files: FILES, DSKF, DRIVE, STDO, STDI, STDL, STRING>FILE, FILE>STRING, FIND-FILE, FILE-INFO, FILE-END?, WRITE-CHAR, READ-CHAR, PEEK-CHAR, CHAR-READY?, SEEK-FILE (with SEEK-SET, SEEK-CUR, SEEK-END), >FILE
  • keyboard: >KEY-BUFFER, KEY-CLEAR, INKEY
  • parsing: \"-PARSE
  • marking: ANEW
  • power: POWER-OFF
  • misc: CELL, NOOP