SUMMARY.md 3.0 KB

TP3-comp — state summary

Recreating Turbo Pascal 3.0 (compiler / editor / shell) in GNU Modula-2 (-fiso), starting with the shell.

Milestone: shell (TP3.0 main-menu shell)

Build: cd shell && make (gm2 16.0.1, -fiso; output shell/tpshell)

Files

  • shell/Term.def / shell/Term.mod — raw termios keyboard + ANSI screen (ClrScr, GotoXY, Marked/Normal, blocking GetCh, Beep).
  • shell/Posix.def / shell/Posix.c — DEFINITION MODULE FOR "C" bridge to libc: read/write/open/close/unlink/rename/getcwd/chdir/opendir/ readdir/closedir/statvfs + termios (tcgetattr/tcsetattr/cfmakeraw).
  • shell/Shell.mod — TP3.0 main-menu shell, same keys and layout as the original disassembled source (TPSRC4 kmenu / kcmdtab).
  • shell/Makefile — builds via make. Note: gm2 only emits main when the program module source is on the link line (gm2 -fiso -o tpshell Shell.mod Term.o Posix.o).
  • RESUME-TP3.md — full book-derived reference on the 8086 code the TP3 compiler generates for each Pascal construct (source of the compiler phase design).
  • Resources/ — TCAT pdfs / OCR of "Au coeur de Turbo Pascal", TP3.0 reference manual, disassembled TPSRC1-10.

Shell features (verified)

  • 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 drawn bold (TP3 uses high-bit chars).
  • Keys: L A W M E C R S D O Q; any other key redraws the menu (TP3).
  • W — set work file, auto-.PAS, Loading/New File, append-on-save.
  • S — save with ^Z EOF; old file -> .BAK via unlink+rename (TP3 order).
  • D — directory listing, DOS-style *.* mask glob, No files, k bytes free (statvfs).
  • O — options submenu (M/C/H/O/D/I/A/P/F/Q) with on-screen state (compile target, Code/Data/Stack, command-line params).
  • Q — confirmed quit (prompts to save when text changed).
  • E / C / R — placeholders (editor, compiler, run to come).

Reflection notes / quirks

  • Model cannot view images (manual figures), so layout was reconstructed from the disassembled TPSRC source, which is authoritative for TP3.0.
  • Foreign modules reject Modula-2-only types (POINTER TO record) — use ADDRESS and cast at the call site.
  • gm2 ICEs on FOR ... EXIT loops (use WHILE+flag).
  • termios is used in "raw" mode; output-affected: every newline is explicit CR LF.
  • Directory glob implements DOS semantics: *.* matches everything, * matches runs, case-insensitive; skips ./...

Next steps

  1. Editor: WordStar-style keys (^A..^Z basic editing, arrows, insert/overtype), reusing the txt text buffer already in Shell.mod.
  2. Compiler: front-end + 8086 code generator per RESUME-TP3.md (program prologue with CS-prefixed typed constants, TU_STACK_CHECK parameter pushes, VAR parameter les/seg access, functions in AX / TU_RESU_FCT_ST strings, typed constants in code segment, absolute vars).
  3. Interpreter ("R") for TP3 .COM-compatible execution.