r/Forth • u/DonHopkins • 1h ago
Forth Day Talks: Mitch Bradley, PDP-7 Forth, Don Hopkins, PDP-7 and Apple ][ Emulator
Mitch Bradley and I gave back-to-back talks at SVFIG's Forth Day on 21 November. Mitch wrote a Forth for the PDP-7, the machine Unix started on, with turtle graphics that draw on its Type 340 vector display. I'm writing the PDP-7 emulator it runs on, in JavaScript, in the browser. Everything below runs live, and the source is on GitHub.
Talks and videos
Mitch's talk and mine, with a transcript full of links:
https://www.youtube.com/watch?v=k2pwJ294r8o
https://github.com/SimHacker/WillWrightShowForFood/blob/main/packages/cabinet/FORTH-DAY-TALK.md
The demo, recorded before the talk:
A longer video (23 minutes), PIXIE and FORTH on the PDP-7 with the 340 display:
https://www.youtube.com/watch?v=lo8kdY-5i6c
Live demos
PDP-7 Forth, with the 340 display and light pen:
https://hyperties.org/cabinet/forth/
My ProDOS Forth for the Apple ][ (1985-88), booting to its 80-column Videx prompt:
https://hyperties.org/cabinet/languages/don-hopkins-prodos-forth/
Mitch's PDP-7 Forth
It's direct threaded. NEXT is a single instruction, XCT I 10, using one of the PDP-7's auto-increment registers as IP. A primitive's thread cell is a JMP to its code, a colon word's cell executes as a subroutine call, a constant's is a load, and a variable's is a load-address. Turtle graphics assemble Type 340 display instructions into core, and the display draws them by DMA.
The Forth coprocessor
The emulator has a Forth device that sits beside the CPU. When the CPU fetches NEXT, the device runs the thread cell itself: colon calls on the return stack, pushes for constants and variables, and 30 primitives (DUP, +, @, (LOOP), ?BRANCH, EXIT and so on) on the kernel's own stacks. Any other code word goes back to the CPU. It also answers FIND from a name table that follows LATEST.
The image in core is the same with or without it, and it hands control back to the CPU whenever something is unexpected, such as a patched NEXT or a pending interrupt. A menu switches between Forth in software and in "hardware", and the tests check that both print the same output and draw the same picture. It runs one thread cell per memory cycle, as the Novix did. A loop of 30,000 passes of I + takes 890,000 cycles in software and 107,000 with the device.
The emulator compiles PDP-7 code to JavaScript, which V8 compiles to machine code. Each instruction carries a small JavaScript template, and the compiler splices them together. The device's primitives have templates too, so the next step is to inline them, then compile whole colon definitions into single functions.
After that I want to emulate real Forth chips on the same framework: the Novix NC4016 running cmForth, and the GA144 with all 144 F18A cores and their ports visible at once. I've seen the recent posts here looking for arrayForth and GA144 boards. If you have arrayForth, or instruction set documents and software for the Novix, ShBoom, MuP21 or F21, I'd like to hear from you.
Design: https://github.com/SimHacker/WillWrightShowForFood/blob/main/packages/cabinet/FORTH-DEVICE.md
My Apple ][ Forth
I started from fig-FORTH for the 6502 and extended it toward Forth-83. It runs under ProDOS, with its own RPN 6502 assembler. On top of it I wrote an H19 terminal emulator with Videx 80-column output and an interrupt-driven serial driver, which is how I logged into MIT-MC and the other ITS machines over the ARPANET. The surviving disk is from May 1990, with 48 blocks of source. It now boots in the browser on an emulated Apple ][+ with a Videx card in slot 3.
The disk, the source and notes:
Source code
Mitch's PDP-7 Forth: https://github.com/MitchBradley/pdp7forth
The emulator: https://github.com/SimHacker/WillWrightShowForFood/tree/main/packages/cabinet

