CMOC

Permalink: http://sarrazip.com/dev/cmoc.html

By Pierre Sarrazin

CMOC is a 6809-generating cross-compiler for a subset of the C language. It produces assembler code for the Motorola 6809 processor in the Color Computer .BIN format, as well as the Intel HEX, Motorola SREC and Vectrex formats. It runs under GNU/Linux and probably also other Unix-like environments. It requires the LWTOOLS assembler (lwasm), by William Astle.

The most significant differences between CMOC and a complete C compiler is the absence of the const keyword and bit fields. Versions 0.1.40 and .41 have introduced the float and long types. (Floats are only usable under Color Basic.)

CMOC is free software distributed under the GNU General Public License, version 3 or later, except for the files of the USim simulator, which is used for testing.

The current version is 0.1.45. It was released on 2017-11-26.

Release notes for 0.1.45:

Release notes for 0.1.44:

  • The switch() statement now uses a jump table in most situations where this takes less memory than a series of compare and branch instructions. The command line now accepts options --switch=ifelse and --switch=jump to force the compiler to always use one mode or the other.
  • Fixed a bug on Mac OS X where the cpp preprocessor failed to generate its result in its standard output because the -D options were passed to it after the C filename. The options are now all passed before the filename.
  • Added --deps-only and --deps command-line options that create a makefile dependency file for the C file being compiled. See the "Generating Prerequisites Automatically" section of the manual. Not available in monolith mode.

Release notes for 0.1.43:

  • Linking and modular compilation are now supported. Pass -c to compile a C file to an object file (whose extension is .o by default). Pass object files to CMOC to have it link them into an executable. Passing a single C file, for both compilation and linking, is also supported.

Release notes for 0.1.42:

  • Fixed a bug with adding a signed short integer to a long integer.
  • Fixed an array initialization bug that happened on ARM platforms.
  • Fixed a relocatability problem with code that compares a float with an unsigned integer.
  • Replaced short branches in the floating-point library with long branches, to prevent assembly errors.

I can be contacted (in French or English) at sarrazip at sarrazip dot com. (Questions regarding Vectrex-specific issues should be addressed to Johan Van den Brande.)

Download

Compiler

See MD5, SHA1 and SHA512 for signatures of these and other files.

Sample programs

FuncPlot

(Version 0.2.0.) Demo program that plots a mathematical function in PMODE 4 graphics. The program implements an expression parser and an RPN interpreter to evaluate the user's function across an interval.

To try the program without having to compile it, download this DSK image. Requires a 32K CoCo with Extended Basic.

Demo of Basic variable access from a CMOC program

This archive contains a .dsk image file that contains VARPTR.BAS and VARPTR.BIN. Type RUN"VARPTR" on a CoCo. The archive also contains the C source file, which is compilable under CMOC. The Basic and C listings can be studied to learn how to access Basic variables from a CMOC binary.

CoCo MiniLisp

A port by Jamie Cho of Rui Ueyama's MiniLisp. Version 0.5.0, released in October 2017, uses CMOC's support for 32-bit arithmetic.

xdaliclock for the CoCo

A port of Jamie Zawinski's xdaliclock to the CoCo, by Jamie Cho.

Splinter

A CoCo 3 break-the-bricks video game written by Jamie Cho with CMOC. Splinter features colorful 320x192 graphics and smooth animation.

Bouncy Ball

A game for all CoCos, by Lee Patterson. (It does not come with the source code.)

parse-coco-bin

A Perl script that lists the blocks of a CoCo Disk Basic .BIN file, along with the entry point.

Color Eights

A card game derived from Crazy Eights that I wrote with CMOC.

Cardgame library

A skeleton for a card game. Contains the generic code used by my Color Eights game: drawing and erasing cards (32x42 pixels in PMODE 4), drawing text (uppercase 32x24 grid). Rename cardgame.c to something else, fill main() and code other functions. These files are in the public domain.

hirestxt: 51x24 text screen

A library that redirects printf() to a software 51x24 black-on-green PMODE 4 text screen. (A sample program is included.) Optionally supports several VT52 terminal sequences (disable this with #define HIRESTEXT_NO_VT52). Useful to get true lowercase, including Latin-1 accented characters, on all CoCos. These files are in the public domain.

nobasic

(Version 0.1.7.) A program that puts the CoCo in all-RAM mode, overwrites the Basic interpreter, moves the program and the stack to the end of the 64K of RAM and redirects the 60 Hz interrupt, as an example of a program that can use the entire 64K of RAM. Contains a disk sector read demo and a CoCo 3 graphics demo. This version requires CMOC 0.1.43 or later, as it is split in two C files (nobasic.c and dskcon.c).

autostart.c

A program to be compiled as a boot loader that goes on track 34, so that the CoCo's DOS command will execute it. (The autostart.bin file is not meant to be loaded with LOADM.) The program feeds Color Basic's console input with the command RUN"*.BAS" in order to run that Basic program automatically. Install this on a disk image with this command: install-coco-boot-loader foo.dsk autostart.bin

Documentation

See the manual that comes with CMOC.

There are also instructions regarding Vectrex support. Questions regarding Vectrex-specific issues should be addressed to Johan Van den Brande.

As of July 2017, I am developing CMOC on an Ubuntu 12.04 GNU/Linux system using GCC 4.6.3.

Building on Mac OS X 10.10

The configure script should recognize that it is running on a Mac OS X system, but if it does not, the following instructions may help.

Thanks to Jamie Cho for these Mac instructions.

Glen Hewlett has posted an article on his blog about using CMOC from Mac OS or Linux.

Other resources


Last update to this page: 2017-12-01 22:45:27 EST5EDT