/mcbasic

A cross-compiler for MICROCOLOR BASIC 1.0 that targets the TRS-80 MC-10.

Primary LanguageC++MIT LicenseMIT

mcbasic

A cross-compiler for MICROCOLOR BASIC 1.0 which runs on a stock TRS-80 MC-10 or on James Tamer's "Virtual MC-10" which runs on Windows and bundles a shareware Telemark cross-assembler.

Requirements

  • A real "stock" TRS-80 MC-10 or an emulator like the "Virtual MC-10"
  • A compatible Telemark cross-assembler capable of assembling the undocumented "negate with carry" instructions.
  • The 16K Expansion is very helpful except for very small programs

Don't have James' Virtual MC-10? You really should. Don't have Windows?

  • You'll find a tasm6801 repository here
  • You'll find a JavaScript based emulator here.

Limitations

  • Darren Atkinson's MCX-BASIC ROM is not yet supported.
  • SQR() LOG() EXP() SIN() COS() TAN() are not yet implemented

Compilation

Requires C++14. Most modern C++ compilers should be able to support this. Tested on Apple clang version 11.0.0 (clang-1100.0.33.12).

c++ -std=c++14 *.cpp -o mcbasic

Some attempt has been made to make the source compatible with the Windows Visual C++ compiler. I've tested it sporadically against it. What works is to follow the instructions here. If the link fails, try searching the internet for "Walkthrough: Compile a C program on the command line".

cl /EHsc *.cpp /link /out:mcbasic.exe

Usage

Save your BASIC program as a text file. You may use any extension (e.g. ".txt" ".bas") Once you have your basic program, you may compile it via:

mcbasic [options] <yourprogram.bas>

Where [options] can be:

Option Description
‑native use native instructions instead of creating bytecode. This improves execution speed at the cost of increased codesize. Many programs are too big to use native.
‑Wfloat warn when the compiler promotes variables to floating-point¹. (default) [-Wno-float to disable].
‑g generate debug instructions to provide the most recent line number when an error is encountered.
‑list output a BASIC³ program listing after optimizations.
‑‑ treat subsequent arguments as file input (so you can compile a file that starts with "-", like "-filename.bas")

It will then generate an assembly file: <yourprogram.asm>.

You can then run your favorite assembler so long as it supports Telemark-style syntax and is equipped to support the MC6801's undocumented NGC (negate-with-carry) instructions.⁴

tasm6801 <yourprogram.asm>

If you use this version, it will generate a .C10 suitable for loading in an emulator. I'll eventually⁵ bundle the assembler into the compiler as well, so this step may be unnecessary in the future.

Notes

¹ The current back-end implementation "emulates" floating-point with fixed-point. While that makes it faster than floating-point; it's far less accurate, takes more memory², and is slower than using integers. Avoid floating-point if you can.

² The current back-end implementation uses three bytes when implementing an integer (24 bit two's complement) and five bytes when implementing fixed-point (24 bit two's complement integer; 16-bit fraction).

³ Some extensions are used during the compilation stage (e.g. += and -= assignment increment/decrement operators and a WHEN..GOTO/GOSUB as a replacement for IF..GOTO/GOSUB ELSE). These extensions are internal and are not available for use in the source BASIC files.

⁴ These instructions are similar to that of the MC6809's undocumented NGC instruction with direct addressing mode (opcode $02). The MC6801 implements NGCA (opcode $42), NGCB (opcode $52), NGC <offset>,X (opcode $62), and NGC <address> (opcode $72).

⁵ The code in this repository was written in brief spurts over the course of perhaps fifteen years. It's been largely relegated to a minor side-project as time and interest have permitted. Originally in K&R C, it was ported to ANSI C, then C++ (98). I've given it just enough treatment to work in C++14, but alas, C++20 is out as of this writing! It needs to be upgraded to comply with more modern programming guidelines. But perhaps, like MICROCOLOR BASIC itself, some of this code may bring you back to a simpler era. Enjoy!