11 Commits

Author SHA1 Message Date
Eremey Valetov
99eb992ead Add DOS build script, compiler/DOS test harnesses, FreeDOS package, CI
- build_dos.sh: Linux-friendly cross-compile to DOS via OpenWatcom V2.
  OpenWatcom's wmake on Linux can't apply the .c.obj implicit rule for
  subdirectory paths, and Makefile.dos / Makefile.dos16 rely on DOS-
  only commands like 'del'.  Script invokes wcc / wcc386 directly,
  tracks 16-bit vs 32-bit mode via a stamp file (auto-cleans on
  switch), generates a wlink directive file (the brace-delimited file
  list wouldn't survive shell quoting), and supports clean.  The DOS
  Makefiles still work on Windows / DOS hosts.

- tests/run_compiler_tests.sh: AOT compiler harness.  For each .bas
  in tests/programs/, compiles via gwbasic-compile -c, runs the
  resulting executable, normalizes output and diffs against the
  golden file from tests/expected/.  Skip list covers chain/common
  multi-file flows, hardware/timing-dependent programs, unnumbered
  direct-mode programs (compiler requires line numbers), and
  misc_stmts/run_file (interpreter-vs-compiler ON ERROR divergence).
  Result: 56/56 pass.

- tests/run_dos_smoke.sh + dos_smoke.bas + expected: runs gwbasic16.exe
  under DOSBox-X (flatpak) with a program that exercises arithmetic,
  strings, control flow, GOSUB, FOR/NEXT, DATA/READ, DEF FN, OPEN/
  PRINT#/CLOSE, and diffs against the interpreter's golden output.
  Uses $HOME for the staging dir (DOSBox-X flatpak doesn't see /tmp).

- pkg/GWBASIC.LSM + pkg/build_pkg.sh: FreeDOS submission package.
  Produces dist/gwbasic-<VERSION>.zip with the standard FreeDOS
  layout (APPINFO/GWBASIC.LSM, BIN/GWBASIC.EXE, DOC/GWBASIC/{README,
  CHANGES,LICENSE} with CRLF, SOURCE/GWBASIC/<full source>).  Source
  tree is filtered through git ls-files to exclude build artifacts.

- docs/Makefile: standard Sphinx Makefile so 'cd docs && make html'
  works as documented in README.md.

- .github/workflows/ci.yml: split into two jobs.  build-and-test now
  also runs the compiler harness.  New dos-cross-compile job caches
  ~/openwatcom-v2, downloads the OpenWatcom V2 snapshot if not
  cached, builds both 16-bit and 32-bit DOS binaries, asserts size
  bounds, and uploads them as artifacts.

- .gitignore: ignore .dos_build_mode (script's stamp), .link_dir/
  (transient wlink directive dir), dist/ (package output).
2026-05-03 12:26:09 -04:00
Eremey Valetov
eb32021c19 Implement string space pool with compacting garbage collector
Replaces individual malloc/free string management with a contiguous pool
(default 32KB) and compacting GC, matching the original GW-BASIC's
GETSPA/GARBAG architecture. Allocation is a bump pointer; gw_str_free()
is a no-op (descriptors are nulled, data reclaimed by GC). Compaction
runs at statement boundaries when the pool drops below 4KB free, walking
the variable table and array storage to relocate live strings.

FRE() now returns actual free pool space. FRE("") triggers a GC pass
before reporting. CLEAR n sets the string space size.
2026-03-29 04:55:48 -04:00
Eremey Valetov
612d3972dc Implement remaining statement/function gaps: RESET, ENVIRON/ENVIRON$, ERDEV/ERDEV$, IOCTL/IOCTL$, LCOPY, DATE$/TIME$ assignment, CALL, COM
Closes the last unimplemented extended statement tokens. ENVIRON uses
putenv/getenv for real environment variable access. DATE$/TIME$
assignment is accepted but silently ignored (no system clock modification).
ERDEV/ERDEV$/IOCTL$/PEN return stub values (no real device hardware).
CALL/CALLS raise Illegal function call. COM event trapping silently
accepted.
2026-03-28 18:48:38 -04:00
Eremey Valetov
e100290dd3 Implement Hardware I/O Simulator (OUT/INP/WAIT/MOTOR, port emulation)
New portio.c module following the virmem.c dispatch-by-address pattern,
emulating 8253 PIT channel 2 (speaker frequency), PPI port B (speaker
on/off), CGA mode/color select registers, game port (joystick stub),
COM1 serial (transmitter-ready stub), and floating bus default (0xFF).

OUT/WAIT/MOTOR statements and INP()/STICK()/STRIG() functions now fully
functional. Continuous tone generation via PulseAudio pthread worker for
programs that drive the speaker through OUT &H43/&H42/&H61.
2026-03-28 18:27:19 -04:00
Eremey Valetov
0d9f29aa7a Fix DRAW M/S/A bugs, add TA rotation, =variable; substitution, X substring execution
Rewrites gfx_draw() as a recursive draw_engine() to support all DRAW
mini-language features:

Bug fixes:
- M command parsing: skip generic arg parser so M100,50 correctly
  parses both coordinates instead of consuming x as a generic arg
- S (scale) semantics: distance is now (arg ?: 1) * scale / 4, matching
  original GW-BASIC where S4 means 1 pixel per unit, not 4
- A (rotation): implements 90-degree rotation state with direction
  vector transform for all 8 direction commands

New features:
- TA n: arbitrary rotation angle (-360 to 360 degrees) via cos/sin
- =variable;: numeric variable substitution in DRAW strings
- X stringvar;: execute substring from string variable (recursive)
- Scale factor applied to relative M coordinates
2026-03-21 02:48:17 -04:00
Eremey Valetov
3f3104c385 Implement MBF binary file compatibility, fix binary loader null-byte truncation, update to v0.14.0
Binary tokenized SAVE/LOAD now stores float constants in Microsoft Binary
Format (MBF) on disk, matching original GWBASIC.EXE.  A token-walking function
(convert_floats) converts IEEE↔MBF at the save_binary()/load_binary() boundary.

Also fixes a latent bug where load_binary() scanned for 0x00 to find the end
of each token line — this fails when float bytes contain null (e.g. MBF for
100.5 is 00 00 49 87).  The loader now uses the next-line pointer to compute
token data length, matching the original's approach.
2026-03-21 01:38:53 -04:00
Eremey Valetov
000116b2a2 Fix POINT coordinate mapping, remove orphaned palette array, expand tests
Apply coordinate mapping (VIEW/WINDOW) to POINT(x,y) function so it
returns correct pixel values when WINDOW is active. Remove unused
palette[] array from graphics.c (Sixel encoder uses palette_map[]
directly). Expand view_window.bas test to cover WINDOW SCREEN mode,
VIEW+WINDOW combination, and PMAP inverse mapping. Fix CI test count
in docs.
2026-03-10 22:38:42 -04:00
Eremey Valetov
0bacfcef6c Implement VIEW/WINDOW/PALETTE, PMAP, fix MBF float format, update to v0.13.0
Graphics viewport and coordinate mapping:
- VIEW [[SCREEN] (x1,y1)-(x2,y2) [,[fill][,border]]] with clipping
- WINDOW [[SCREEN] (x1,y1)-(x2,y2)] with Cartesian/screen modes
- PALETTE [attribute, color] with CGA 16-color remapping
- PMAP(coord, func) for logical/physical coordinate conversion
- All graphics statements (PSET, LINE, CIRCLE, PAINT, GET/PUT) respect
  viewport clipping and WINDOW coordinate mapping

MBF (Microsoft Binary Format) float support:
- CVS/CVD now interpret bytes as MBF format (compatible with real GW-BASIC)
- MKS$/MKD$ now produce MBF-encoded bytes
- Fixed shift errors in MBF↔IEEE conversion routines (single: 1→0, double: 4→3)
- Random-access file I/O now byte-compatible with original GWBASIC.EXE

66 tests (2 new), 61 compat matches (up from 58).
2026-03-10 22:20:58 -04:00
Eremey Valetov
4551c88a50 Implement BSAVE/BLOAD, TUI color, extended PEEK/POKE, update to v0.12.0
BSAVE/BLOAD: save and load virtual memory blocks with 0xFD-header
binary format, operating on the current DEF SEG segment.

TUI color: tui_refresh emits ANSI SGR codes from cell attributes;
COLOR statement sets tui.current_attr when TUI is active.

Extended PEEK/POKE: CGA graphics framebuffer (interlaced layout) via
gfx_cga_peek/poke routed through virmem when gfx_active(); BIOS
keyboard shift flags (offset 0x17 bit 7 = insert mode).

Add bibliography to language reference. 64 tests, all passing.
2026-03-01 13:37:05 -05:00
Eremey Valetov
0743757029 Implement DEF SEG/PEEK/POKE, GET/PUT sprites, fix PRINT USING, update to v0.11.0 2026-03-01 13:07:28 -05:00
Eremey Valetov
e7f35c21ff Implement binary SAVE/LOAD, INKEY$ extended keys, golden tests, update to v0.10.0
Binary SAVE/LOAD: SAVE now writes tokenized binary by default (0xFF header
format), matching original GW-BASIC behavior. SAVE "file",A for ASCII.
LOAD auto-detects binary vs ASCII from the first byte. Command-line file
loading also auto-detects, so binary .BAS files just work.

INKEY$ extended keys: arrow keys, Home/End/PgUp/PgDn, Insert/Delete, and
F1-F10 now return the correct CHR$(0) + scan_code two-byte sequences per
the IBM PC convention. Refactored event trap key parsing to use tui_read_key()
instead of duplicating escape sequence parsing.

Golden-file regression tests: generated .expected output files for 55 of 58
test programs (3 timing-dependent tests excluded). The test runner now
reports compat match status alongside pass/fail.

Classic programs: added Hamurabi, Lunar Lander, Gunner, and Diamond from
David Ahl's BASIC Computer Games (1978) in tests/classic/ for manual
compatibility testing.

Docs updated with compiler roadmap item and hardware I/O simulator plan.
2026-03-01 12:25:47 -05:00