Turbo-pascal 3 recreation, based on multiple disassembiles and Collibri Books.

Eric Streit 0049d1076a Execution: a boot sector, qemu, and 11 bugs only a CPU could find 1 viikko sitten
Resources 1adc41da2d TP3-comp: working TP3.0 shell in GNU Modula-2 (-fiso) 2 viikkoa sitten
shell 0049d1076a Execution: a boot sector, qemu, and 11 bugs only a CPU could find 1 viikko sitten
.gitignore 0049d1076a Execution: a boot sector, qemu, and 11 bugs only a CPU could find 1 viikko sitten
README.md 7753a7be2d Summary: milestone state doc, and two more bugs the byte dump exposed 2 viikkoa sitten
RESUME-TP3.md 1adc41da2d TP3-comp: working TP3.0 shell in GNU Modula-2 (-fiso) 2 viikkoa sitten
SUMMARY.md 0049d1076a Execution: a boot sector, qemu, and 11 bugs only a CPU could find 1 viikko sitten
TP3-COMPILER.md 0049d1076a Execution: a boot sector, qemu, and 11 bugs only a CPU could find 1 viikko sitten
TP3-EDITOR-PSEUDOCODE.md 9088d9ebf2 TP3-comp: shell + Compiler.mod build clean under gm2 -fiso -Wall 2 viikkoa sitten
TP3-EDITOR.md c342d7cae3 TP3-comp: document how the original TP3 editor works 2 viikkoa sitten

README.md

TP3-comp

Recreating Turbo Pascal 3.0 (shell, editor, compiler, interpreter) in GNU Modula-2 (-fiso). Faithful to the original: the screen layout, keys and behaviours are reconstructed from the disassembled TP3.0 source (Resources/) and the reference manual.

Status

Milestone Tag Status
Main-menu shell v0.1-shell done
WordStar-style editor v0.2-editor done
Shell/editor polish (Ctrl-K-D quit) v-TP3-SHELL-EDITOR-QUIT done
Compiler skeleton + two-phase build v-TP3-SHELL-COMPILES done
Parser Skip bug class (9 sites) v-TP3-PARSER-FIXES done
Standard procedures + rel16 fix v-TP3-STDPROCS done
Runtime blob, linker, CmdRun interpreter — not started

Current state: tpshell builds clean (120792 bytes); the compiler front end parses and emits 8086 for 17 of 23 fixtures, verified by hex-dumping the image. No compiled program has been executed yet — CmdRun is a stub and the runtime blob does not exist. See SUMMARY.md for the verified detail.

Build

Requires GNU Modula-2 (gm2, tested with 16.0.1) and a C compiler for the FOR "C" bridge.

cd shell
make
./tpshell

The shell runs in raw mode: it needs a real ANSI terminal, no wrappers.

Layout

  • shell/Term.def|mod — raw termios keyboard + ANSI screen primitives (blocking GetCh, non-blocking Avail/GetKey via poll, GotoXY, highlight Marked/Normal, Beep).
  • shell/Posix.def|Posix.c — DEFINITION MODULE FOR "C" bridge to libc: read/write/open/close/unlink/rename/getcwd/chdir/opendir/readdir/closedir/ statvfs/poll and termios (tcgetattr/tcsetattr/cfmakeraw).
  • shell/TextBuf.def|mod — the shared TP3-style text buffer: a 62903-char array, lines terminated by CR. Text is kept in memory so the editor and the shell's S (save) operate on the same buffer.
  • shell/Editor.def|mod — WordStar-style full-screen editor.
  • shell/Shell.mod — TP3.0 main-menu dispatcher (kmenu/kcmdtab), work-file load/save with .BAK rotation, directory listing, options menu.
  • shell/Makefile — see notes below.
  • SUMMARY.md — state summary and reflection notes per milestone.
  • RESUME-TP3.md — book-derived reference for the 8086 code the TP3 compiler generates (source of the compiler phase).
  • Resources/ — OCR of "Au coeur de Turbo Pascal", TP3.0 manual and the disassembled TPSRC1-10.

Shell (TP3.0 main menu)

Exact TP3.0 screen: Logged drive, Active directory, Work file, Main file, Edit Compile Run Save / Dir Quit compiler Options, Text: n bytes, Free: n bytes, > prompt. Command letters are drawn bold (TP3 uses high-bit characters).

Key Action
L new drive / directory
A new active directory
W set work file (auto-.PAS), Loading/New File
M set main file
E edit work file
C compile (wired: TP3 error report + editor jumps to the error)
R run — stub, prints "Interpreter pending"
S save with ^Z EOF; old version → .BAK
D directory listing, DOS *.* mask, k bytes free
O options submenu (compile target, Code/Data/Stack, params)
Q quit (prompts to save when text changed)

Any other key redraws the menu, like TP3.

Editor

WordStar-style full-screen editing over TextBuf. Status line: Line n Col n Insert/Overwrite Indent X:FILENAME. Text rows are screen rows 2–24; row 1 carries status/prompt/messages.

Highlights:

  • Movement — ^S/^D/^E/^X/^A/^F/^R/^C/^W/^Z and ^Q S/D/E/X/R/C/B/K/P, arrow keys / PgUp / PgDn / Home / End (ANSI escape sequences).
  • Editing — insert/overwrite (^V), ^G delete char, backspace joins lines, ^T word, ^Y line, ^Q-Y to end of line, ^N / CR line break, TAB auto-indent to word start on the line above.
  • Block — ^K B/K mark, ^K T word, ^K H show/hide, ^K C/V/Y copy/move/delete, ^K R/W read/write block to/from a file.
  • Search — ^Q-F find, ^Q-A replace, ^L repeat last; options B/G/n/U/W, and N (no-confirm) for replace; ^A matches any char, CR LF searches a line break.
  • ^P prefix inserts a literal control character; ^U / ESC abort prompts.
  • ^K-D returns to the shell; the text stays in memory, changed is reported and S (or the quit prompt) writes it to disk.

Disk format matches TP3: CRLF line endings and a trailing ^Z; load normalizes CRLF/LF, save re-expands.

Porting notes (gm2)

  • Foreign modules (DEFINITION MODULE FOR "C") must use ADDRESS, not Modula-2 record/pointer types — cast at the call site.
  • gm2 ICEs on FOR ... EXIT; use WHILE+flag (or LOOP+EXIT).
  • gm2 only emits main when the program module source is on the link line: gm2 -fiso -o tpshell Shell.mod Term.o Posix.o TextBuf.o Editor.o.
  • termios is used in raw mode, so every newline is explicit CR LF.
  • EXIT is only legal inside LOOP (ISO Modula-2), not WHILE.