Eremey Valetov 71ff44828d Add 16-bit real-mode DOS target -- 127KB standalone, no extender
New Makefile.dos16 builds with OpenWatcom wcc (16-bit, MEDIUM model)
producing a standard MZ executable that runs on any DOS without DOS/4GW.
All 24 source files compile clean; tested on FreeDOS 1.4 via QEMU.

Changes for 16-bit compatibility:
- hal_dos.c: INTX macro selects int86() vs int386() based on _M_I86
- sound.c: reduce stack buffer from 8192 to 512 samples on 16-bit
- tui.c: gracefully disable TUI if screen buffer allocation fails
  (near heap exhaustion common on 16-bit), batch mode still works
- .gitignore: add .obj/.exe/.err/.lib for OpenWatcom build artifacts

Size comparison:
- 32-bit DOS/4GW: 175KB + 265KB extender = 440KB total
- 16-bit real-mode: 127KB standalone

The 32-bit build (Makefile.dos) and Linux build are unaffected.
72/72 interpreter tests pass.
2026-04-10 06:32:47 -04:00

GW-BASIC 2026

A portable C reimplementation of Microsoft GW-BASIC, using the original 8088 assembly source (released by Microsoft in 2020) as the authoritative reference.

This is not a transpilation -- it reimplements the algorithms in clean C11 with modern data structures while targeting bug-compatible behavior.

Building

cmake -B build && cmake --build build

Requires a C11 compiler and CMake 3.10+. PulseAudio (libpulse-simple) is optional -- detected at build time for SOUND/BEEP/PLAY support.

Builds three targets:

  • gwbasic -- the interpreter
  • gwbasic-compile -- the ahead-of-time compiler
  • libgwrt.a -- runtime library for compiled programs

Usage

Interactive mode launches the authentic GW-BASIC full-screen editor:

$ ./gwbasic
GW-BASIC 2026 0.16.0
(C) Eremey Valetov 2026. MIT License.
Based on Microsoft GW-BASIC assembly source.
Ok
PRINT 2+2
 4
Ok

Run a program file (ASCII or binary tokenized):

./gwbasic tests/programs/prime_sieve.bas

Compile to a native executable:

./gwbasic-compile tests/programs/fibonacci.bas -c --runtime .

Ahead-of-Time Compiler

gwbasic-compile translates BASIC programs to C source, then invokes GCC to produce native executables linked against libgwrt.a.

Pipeline: .bas → tokenizer → analysis → C codegen → gcc → native binary.

69 of 69 eligible test programs compile and produce correct output (100%).

# Generate C source
./gwbasic-compile myprog.bas -o myprog.c

# Compile to executable (automatic)
./gwbasic-compile myprog.bas -c --runtime /path/to/gw-basic-2026

Jupyter Kernel

A Jupyter notebook kernel for GW-BASIC with inline Sixel graphics rendering, INPUT support, and Pygments syntax highlighting.

pip install -e .
gwbasickernel-install --user
jupyter notebook  # select "GW-BASIC 2026" kernel

What Works

100% token coverage -- all 144 GW-BASIC tokens are implemented.

Data types: INTEGER (%), SINGLE (!), DOUBLE (#), STRING ($)

Operators: + - * / ^ \ MOD AND OR XOR EQV IMP NOT < = > <= >= <>

Statements:

Category Statements
Output PRINT, LPRINT, LLIST, PRINT USING, WRITE, CLS
Variables LET, DIM, ERASE, SWAP, DEFINT/SNG/DBL/STR
Control flow GOTO, GOSUB/RETURN, FOR/NEXT, IF/THEN/ELSE, WHILE/WEND, ON...GOTO/GOSUB
Input INPUT, LINE INPUT, DATA/READ/RESTORE, INKEY$
Program RUN, CONT, STOP, END, NEW, LIST, CLEAR, AUTO, RENUM, DELETE, EDIT
Sequential I/O OPEN, CLOSE, PRINT#, WRITE#, INPUT#, LINE INPUT#
Random-access I/O FIELD, LSET, RSET, PUT, GET, CVI/CVS/CVD, MKI$/MKS$/MKD$
Program I/O SAVE (binary/ASCII), LOAD (auto-detects), MERGE, CHAIN, COMMON
Event trapping ON TIMER(n) GOSUB, TIMER ON/OFF/STOP, ON KEY(n) GOSUB
Error handling ON ERROR GOTO, RESUME, ERROR, ERR, ERL
User functions DEF FN, RANDOMIZE
File management KILL, NAME, FILES, MKDIR, RMDIR, CHDIR, SHELL, ENVIRON
Date/time DATE$, TIME$, TIMER
Screen LOCATE, COLOR, WIDTH, SCREEN, KEY ON/OFF/LIST
Graphics PSET, PRESET, LINE, CIRCLE, DRAW, PAINT, GET/PUT (sprites), VIEW, WINDOW, PALETTE, PMAP
Sound SOUND, BEEP, PLAY (MML)
Memory DEF SEG, PEEK, POKE, BSAVE, BLOAD
Hardware I/O OUT, INP, WAIT, MOTOR, STICK, STRIG

Tests

72 interpreter tests, 14 kernel tests, 69 compiler tests -- all passing.

bash tests/run_tests.sh              # interpreter
python -m gwbasickernel.test_kernel  # Jupyter kernel

Documentation

Full Sphinx documentation in docs/:

cd docs && pip install -r requirements.txt && make html

License

MIT License. See LICENSE.

Description
Portable C reimplementation of Microsoft GW-BASIC, with an ahead-of-time compiler. Mirror of github.com/evvaletov/gw-basic-2026.
Readme 446 KiB
Languages
C 83.3%
BASIC 6.5%
Python 5.4%
Shell 4.3%
CMake 0.4%