Repolode
hra1129

hra1129/msx_basic_compiler

BACON, a compiler that translates MSX-BASIC programs into machine code for MSX computers, with PLAY (PSG music) support.

Stars
37
Forks
5
Open issues
9
Last commit
5 days ago

What is it?

msx_basic_compiler (BACON) compiles MSX-BASIC source files into assembly code, which is then assembled into a binary that runs on MSX computers. The generated program is loaded alongside a BACON loader binary and executed on the MSX, so the compiled code runs without the BASIC interpreter's usual per-line interpretation.

The compiler works by scanning the whole source to determine variable type defaults from DEFINT, DEFSNG, DEFDBL and DEFSTR statements, and it leaves out source-level commands such as LIST, RENUM, TRON and MERGE. Some runtime error checks are omitted to improve speed, and VARPTR on arrays can change after string operations, as described in the project's notes on differences from MSX-BASIC.

The project includes support for the standard MSX-BASIC PLAY statement and the PLAY(n) function, converting MML strings into BIOS sound queues. Output assembly is produced by the msx_bacon tool and assembled with the ZMA assembler.

Key features

  • 01Compiles MSX-BASIC source files into assembly code for MSX.
  • 02Supports the standard MSX-BASIC PLAY statement and PLAY(n) function for PSG music.
  • 03Determines default variable types across the whole source from DEFINT, DEFSNG, DEFDBL and DEFSTR.
  • 04Works with the ZMA assembler to produce a runnable binary.
  • 05Ships with an OpenMSX test disk for checking PLAY behavior.

Use cases

  • Speeding up an existing MSX-BASIC program by compiling it to machine code.
  • Experimenting with MSX sound by writing PLAY music in BASIC.
  • Studying how an MSX-BASIC compiler handles variables and strings.

Quick start

  1. 1

    Write the BASIC program hello.bas

  2. 2

    Compile hello.bas to assembly with msx_bacon

    msx_bacon hello.bas hello.asm
  3. 3

    Assemble hello.asm to hello.bin with ZMA (separate assembler)

    zma hello.asm hello.bin
  4. 4

    Copy hello.bin and BACONLDR.BIN to MSX and load them with BLOAD

Things to know

  • Requires the separate ZMA assembler to produce the final binary.
  • The macOS install path is hard-coded to /opt/homebrew/bin and the Makefile must be edited for other setups.
  • Some MSX-BASIC features are unsupported, such as LIST, RENUM, TRON, TROFF and MERGE, and runtime error checking is minimal.

In collections

Topics

FAQ

What is msx_basic_compiler?
BACON, a compiler that translates MSX-BASIC programs into machine code for MSX computers, with PLAY (PSG music) support. msx_basic_compiler (BACON) compiles MSX-BASIC source files into assembly code, which is then assembled into a binary that runs on MSX computers. The generated program is loaded alongside a BACON loader binary and executed on the MSX, so the compiled code runs without the BASIC interpreter's usual per-line interpretation.
Is msx_basic_compiler free to use? What license does it have?
msx_basic_compiler is open source under the MIT license. Check the license terms before using it in commercial products.
Is msx_basic_compiler still maintained?
Actively maintained. The last commit to msx_basic_compiler was on Nov 2, 2026.
What can I use msx_basic_compiler for?
Speeding up an existing MSX-BASIC program by compiling it to machine code. Experimenting with MSX sound by writing PLAY music in BASIC. Studying how an MSX-BASIC compiler handles variables and strings.
How do I install msx_basic_compiler?
Write the BASIC program hello.bas Compile hello.bas to assembly with msx_bacon: msx_bacon hello.bas hello.asm Assemble hello.asm to hello.bin with ZMA (separate assembler): zma hello.asm hello.bin Copy hello.bin and BACONLDR.BIN to MSX and load them with BLOAD
Where can I get msx_basic_compiler?
The source code and installation instructions are on GitHub: https://github.com/hra1129/msx_basic_compiler

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects