A modern, cross-platform rewrite of the classic GW-BASIC interpreter, implemented in C++20 with a real-time execution model and hardware-accelerated graphics.
This project aims to preserve the simplicity and spirit of GW-BASIC while providing a clean, extensible architecture suitable for modern systems.
-
Line-numbered BASIC programs
-
Immediate mode (REPL) + file execution
-
Control flow:
IF ... THEN ... ELSEGOTO,GOSUB,RETURNFOR/NEXTWHILE/WEND
-
Variables:
- Numeric + string
- Arrays (
DIM) - Default typing (
DEFINT,DEFSTR, etc.)
-
Expressions:
- Arithmetic
- Logical (
AND,OR,NOT)
-
Functions:
ABS,INT,LEN,VALSQR,SIN,COS,TAN,ATNRND- String functions (
LEFT$,RIGHT$,MID$, etc.)
- Frame-based execution model
- Non-blocking input (
INKEY$) - Engine tick integration
- Batch rendering for high-performance drawing
- Suitable for games and simulations
- Windows โ Direct3D 11
- Linux โ OpenGL (X11)
- Headless mode for testing / CI
SCREENCLSCOLORLOCATEPSET,LINE,CIRCLEPAINT,DRAWGET/PUT(graphics blocks)VIEW,WINDOW,PMAPPALETTE,PALETTE USING
- Pixel canvas abstraction
- Palette remapping
- Viewport and world-coordinate transforms
- Hardware-accelerated presentation
- Automatic batching for performance
Here is example of graphics
tan(x^2 + y^2) = 1 graph example:
snake game example:
easter card example:
y=sin(x), y=cos(x) graphs:
norton commaner inspired example:
OPEN,CLOSEINPUT#,PRINT#,WRITE#LINE INPUT#EOF,LOF,LOCKILL,NAME,MKDIR,RMDIR
-
INKEY$(non-blocking) -
Keyboard input from:
- Console
- Native graphics window (Win32 / X11)
- C++20 compiler
- CMake โฅ 3.16
mkdir build
cd build
cmake ..
cmake --build .mkdir build
cd build
cmake ..
cmake --build . --config Debuggwbasicgwbasic --file ./examples/snake.basgwbasic --headless --file ./examples/snake.basgwbasic --file ./examples/snake.basFeatures:
- real-time gameplay
- keyboard control via graphics window
- hardware-accelerated rendering
10 SCREEN 2
20 CLS
30 COLOR 15,0
40 CX = 320: CY = 100
50 SX = 0.03: SY = 0.03
60 FOR PY = 0 TO 199
70 FOR PX = 0 TO 639
80 X = (PX - CX) * SX
90 Y = (PY - CY) * SY
100 IF ABS(TAN(X*X+Y*Y)-1) < 0.05 THEN PSET (PX,PY), 10
110 NEXT PX
120 NEXT PY
130 END- Lexer โ Parser โ AST โ Execution
- Line-numbered program storage
- Immediate + stored execution modes
- Variable storage
- Array memory
- File handles
- Graphics state
- Engine tick integration
-
In-memory pixel canvas
-
Platform-specific presenter:
- D3D11 (Windows)
- OpenGL (Linux)
-
Batch rendering system
- Cooperative execution
- Frame pacing (~60 FPS)
- Event pumping
- Input polling
-
Rendering is batched, not per-pixel immediate
-
Large plots are now significantly faster than naive implementations
-
Still an interpreter โ heavy numeric loops can be slow
-
Prefer:
- coarse stepping
- analytical drawing (e.g., circles instead of brute-force)
- Not a 100% GW-BASIC clone
- Graphics are portable abstractions, not exact hardware emulation
- Some legacy quirks are not implemented
- Floating-point math is modernized (not 8087-compatible)
- Performance depends on interpreter speed
- Fixed-timestep VM scheduler
- More BASIC compatibility edge cases
- Improved parser tolerance
- Sound subsystem (
PLAY,SOUND) improvements - Better console emulation
- Optional SDL backend
- Debug / trace mode
Contributions are welcome.
Focus areas:
- language compatibility
- performance improvements
- platform backends
- test coverage
Under MIT license
This project is not just a clone.
Itโs a modern BASIC runtime:
- simple like the original
- powerful enough for real-time programs
- portable across platforms
- clean and extensible in design




