Repository navigation
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
bcc09 1.0.1 =========== bcc09 is a C compiler for the Motorola MC6809, with the preprocessor, peephole optimizer, assembler, linker, librarian, binary utilities and C library that go with it. It targets the Tandy Color Computer and the Dragon (Color BASIC, Disk BASIC and ROM cartridges), OS-9 and NitrOS-9, FLEX, and the Vectrex, or any 6809 machine through its own start-up code. It is derived from the 6809 configuration of Bruce Evans' C compiler, as the dev86 project has it. https://github.com/retrotinker/bcc09 The tools --------- bcc09 the compiler driver: runs the passes below, and links as09 the assembler ld09 the linker, with linker scripts (as GNU ld's, smaller) ar09 the librarian objdump09 dumps object files and executables (also installed as nm09 and size09) objcopy09 makes an executable into what a machine loads: raw binary, S-records, Intel hex, a Disk BASIC (LOADM) file, a DragonDOS binary, a cassette image (.cas or .wav), an OS-9 module, or a FLEX command (.CMD) bcc09's passes are cpp (the preprocessor), unproto (which makes ANSI C prototypes into the K&R C the compiler reads, keeping their types), cc1 (the compiler) and copt (the peephole optimizer, with -O). The C it compiles is C89 with prototypes (const accepted and ignored, volatile kept also by the optimizer), plus from C99 // comments, _Bool, declarations after statements and in a for, designated initializers, compound literals, and inline and restrict (accepted and ignored); and __direct for variables in the 6809's direct page (a byte smaller and a cycle faster to reach). char is unsigned, int is 16 bits, long 32 (there is no long long), float and double IEEE single and double precision. The C library is C89's (assert.h, ctype.h, errno.h, float.h, limits.h, locale.h, math.h from Sun's fdlibm, setjmp.h, signal.h with raise() only, stdarg.h, stddef.h, stdio.h with printf and scanf as glibc's, stdlib.h with malloc, string.h and time.h), with stdint.h, stdbool.h, POSIX's getline() and getdelim(), and the system functions each target supports: files on Disk BASIC, OS-9 and FLEX, and directories on OS-9. coco.h has Color BASIC's INKEY$, CLS, LOCATE, JOYSTK, SOUND, PEEK and POKE, and vectrex.h the Vectrex BIOS's routines. Floating point, and printf's conversions of longs, are linked only into programs that use them. Building and installing ----------------------- bcc09 builds on any Unix-like system with a C compiler and make (the tests also need python3 and groff): make make check make install "make check" runs the regression tests: the programs they build run on sim6809, a 6809 simulator (https://github.com/retrotinker/sim6809, 1.3.0 or later; Fedora RPMs are attached to its releases), which must be on PATH (or SIM6809=/path/to/sim6809). The optional "make check-xroar", "make check-nitros9" and "make check-flex" run test programs on real ROMs and systems in the XRoar emulator, and "make check-vectrex" on the Vectrex's BIOS in MAME (see the manual for what each needs). "make install" puts the programs in PREFIX/bin, the passes in PREFIX/libexec/bcc09, the C library and its headers in PREFIX/share/bcc09, and the man pages in PREFIX/share/man. PREFIX is /usr/local unless both make and make install are given another (bcc09 looks for its files where it was built to be installed): "make PREFIX=/opt/bcc09" and "make PREFIX=/opt/bcc09 install", say. On Fedora, "make rpm" builds the RPM packages (bcc09.spec, installed in /usr): bcc09, and bcc09-doc with the PDF manuals, in rpmbuild/; "make srpm" builds the source package. Getting started --------------- A Color BASIC program, on a cassette image for CLOADM:EXEC: bcc09 -Me -O -o hello -X-T0x3000 hello.c objcopy09 -O cas -n HELLO hello hello.cas (or "objcopy09 -O decb hello HELLO.BIN" for LOADM from a disk). A ROM cartridge for the CoCo or the Dragon, its image ready for an EPROM (or XRoar's -cart-rom): bcc09 -Mr -O -o hello.rom hello.c A Vectrex cartridge, drawing through the BIOS's routines (vectrex.h): bcc09 -Mv -O -o hello.bin hello.c An OS-9 program module, and a FLEX command: bcc09 -Mo -O -o hello.out hello.c objcopy09 -O os9 -n hello hello.out hello bcc09 -Mf -O -o hello -X-T0x1000 hello.c objcopy09 -O flex hello HELLO.CMD For a monitor or a machine of your own (the default target has no I/O: main's result is returned to whatever called the program): bcc09 -O -o prog -X-T0x4000 prog.c objcopy09 -O srec prog prog.s19 Color BASIC, OS-9 and FLEX end lines with a carriage return, and the C library passes characters to them as they are: print "\r" (FLEX's terminal wants "\r\n"). Documentation ------------- doc/manual.pdf is the user's manual: building and installing, the C bcc09 compiles, each target, the C library, the calling conventions and how to write assembly for them, the tools and the tests, answers to common questions (chapter 10, also on its own in FAQ.md), and the man pages as an appendix ("make docs" makes it again from doc/manual.md). doc/basic.pdf, "bcc09 for BASIC Programmers", teaches C to those who know Color BASIC (from doc/basic.md), with doc/worm.c, an example game, and doc/vectrex.pdf, "bcc09 for Vectrex Programmers", shows those who know the Vectrex's BIOS and 6809 assembly how to write a cartridge in C (from doc/vectrex.md), with doc/rocks.c, an example game; and doc/os9.pdf, "bcc09 for OS-9 Programmers", and doc/flex.pdf, "bcc09 for FLEX Programmers", are C for OS-9 (and NitrOS-9) and FLEX for those who know each system (from doc/os9.md and doc/flex.md). The man pages are in doc/man: bcc09(1), as09(1), ld09(1), ar09(1), objdump09(1), objcopy09(1), and the passes' bcc09-cpp(1), bcc09-unproto(1), bcc09-cc1(1) and bcc09-copt(1) ("man -l doc/man/bcc09.1" reads one in place). libc/README describes the C library and its changes from dev86's, BUGS the known bugs, and TODO what is still to do. Object formats -------------- Syntax for the assembler seems to be inspired by (and may be compatible with) that described in section C.5 of "INTROL-C COMPILER REFERENCE MANUAL", available here: https://deramp.com/swtpc.com/Introl/REF.pdf Many of the notes in section C.C seem relevant to BCC's 6809 code generator as well, particular those on "REGISTER USAGE" and "PARAMETER PASSING CONVENTIONS"; bcc09's own calling conventions are in the manual's "Calling conventions and assembly" and libc/README. The object file format produced by the assembler and consumed by the linker is the "INTROL LINKABLE BINARY FILE FORMAT", documented in "INTROL LINKER AND LOADER REFERENCE MANUAL", available here: https://deramp.com/swtpc.com/Introl/LOAD.pdf So theoretically, object modules should be compatible with objects generated by the Introl-C/6809 toolchain -- YMMV! The calling conventions would still need to match, of course. License ------- The compiler and tools are under the GNU General Public License (see COPYING). The C library, which is linked into the programs bcc09 builds, is under the GNU Library General Public License, version 2 (see libc/COPYING.LIB), so that those programs can be under any license; its math functions are Sun's fdlibm, under Sun's notice. Please feel free to try things out and to let me know about your successes or failures. If you find something that does not compile or which compiles incorrectly, I would welcome you to send me a minimal source file that exhibits the problem along with a description of what you are attempting to achieve. Thanks, John -- John W. Linville Someday the world will need a hero, and you linville@tuxdriver.com might be all we have. Be ready.