QA findings from a multi-round review of the FreeDOS submission prep work:
- TUI rendering refactor: src/tui.c emitted ANSI escape sequences via
printf, which displays as raw text on bare FreeDOS (no ANSI.SYS).
Add four HAL ops (tui_enter, tui_leave, render_run, set_cursor_shape)
and route per-cell rendering through them. POSIX backend keeps the
ANSI path; DOS backend drives BIOS INT 10h via the existing
bios_set_cursor / bios_write_char helpers. The TUI's logical cursor
goes through the saved orig_locate to avoid recursing through the
swapped-in gw_hal->locate.
- DOS extended-key mapping: dos_getch returns 0x100 | scancode for
arrows / F-keys; tui_read_key wasn't translating those to its TK_*
constants, so the editor never saw arrow keys or F1-F10 on DOS.
Add a __MSDOS__-conditional translation table in tui_read_key.
- Version banner: GW_VERSION was still 0.16.0 even though the v0.17.0
release prep was already in CHANGES.TXT. Bump.
- Compiler PulseAudio link: gwbasic-compile -c hardcoded
'-lgwrt -lm -lpthread' on the gcc command line. When libgwrt was
built against libpulse-simple (the default on any host with the
PulseAudio dev headers installed), the compile workflow failed with
'undefined reference to pa_simple_drain'. CMake now passes
GWRT_HAS_PULSEAUDIO to gwbasic-compile when libpulse is present, and
the compiler appends -lpulse-simple to the link line.
- FRE("") garbage collection: the interpreter skipped strpool_gc with a
comment 'unsafe during expression eval', but that's exactly what real
GW-BASIC's FRE("") does (and the AOT compiler path already did). Add
the GC call; strpool_pin/unpin is the existing escape hatch if a
caller has live pool pointers on the C stack. Fixes the string_gc
compat test.
- Test harness normalization: run_tests.sh stripped trailing whitespace
on the actual output but not the expected file, causing spurious
mismatches against golden files captured from real GWBASIC.EXE.
Normalize both sides identically. Fixes the peek_gfx mismatch.
- Print_using: snprintf into mantissa[32] with %.*f and an unbounded
dec triggered a -Wformat-truncation warning. Clamp dec to 20 (IEEE
double has at most ~17 significant decimal digits).
- Doc/version consistency: 16-bit binary size reported as 127KB in one
place and 128KB in three; standardize on 128KB. HAL backend count
said '1 file' but is now 2. CI test count said 'all 66 test
programs' but is 72. Add a v0.17.0 row to the development.md table.
Update getting-started.md DOS section to match the BIOS-rendering
reality and add a manual TUI verification checklist.
- dos_init now writes back BIOS-reported cols/rows to dos_hal struct
fields (forward-declared so dos_init can reference it).
After these changes: 72/72 interpreter tests pass, compat 68/68
matched, no warnings on the Linux build.
4.1 KiB
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 interpretergwbasic-compile-- the ahead-of-time compilerlibgwrt.a-- runtime library for compiled programs
Usage
Interactive mode launches the authentic GW-BASIC full-screen editor:
$ ./gwbasic
GW-BASIC 2026 0.17.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.
56 of 56 eligible test programs compile via gwbasic-compile and produce
output matching the interpreter's golden files. Run bash tests/run_compiler_tests.sh to verify.
# 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, 56 compiler tests -- all passing.
bash tests/run_tests.sh # interpreter
python -m gwbasickernel.test_kernel # Jupyter kernel
DOS / FreeDOS
Cross-compiles to DOS with OpenWatcom V2:
wmake -f Makefile.dos16 # 16-bit real-mode (128KB standalone, no extender)
wmake -f Makefile.dos # 32-bit DOS/4GW (175KB, requires DOS4GW.EXE)
The 16-bit build runs on FreeDOS, MS-DOS, and compatible systems without a DOS extender. See Getting Started for details.
Documentation
Full Sphinx documentation in docs/:
cd docs && pip install -r requirements.txt && make html
License
MIT License. See LICENSE.