The Commander X16 is a modern small computer with firmware that is based on the ROMs in Commodore's VIC-20 and 64C. It has a couple of I/O chips (WDC65C22 VIA) that are like the ones in the VIC-20.
This file contains an overview of the CX16 run-time system as it comes with the cc65 C compiler. It describes the memory layout, CX16-specific header files, available drivers, and any pitfalls specific to that platform.
Please note that CX16-specific functions just are mentioned here; they might be described in detail in the separate function reference. Even functions marked as "platform dependent" may be available on more than one platform. Please see the function reference for more information.
The standard binary output format generated by the linker for the CX16 target is a machine language program that's prepended with a 16-bit load address and a one-line BASIC stub which calls the machine language part via SYS. That means that a program can be loaded as a BASIC program, and started with RUN. It is, of course, possible to change that behaviour by using a modified program-header file and linker config.
cc65-generated programs with the default setup run with the I/O area, RAM bank one, and the Kernal ROM being visible. That means that Kernal entry points can be called directly. The usable memory ranges are $0800 - $9EFF, $0400 - $07FF, and $A000 - $BFFF.
The C run-time stack is located at $9EFF, and grows downward.
The C heap is located at the end of the program, and grows toward the C run-time stack.
Bank RAM is located at $A000 - $BFFF. It's an eight-Kibibyte window into a half Mebibyte or two Mebibytes of banked RAM.
Bank ROM is located at $C000 - $FFFF. It's a sixteen-Kibibyte window into 128 Kibibytes of banked ROM.
The ld65 linker comes with a default config. file for the Commander X16, which
is used via
-t cx16. The cx16 package comes with additional secondary
linker config. files which are used via
-t cx16 -C <configfile>.
Those files use 94 bytes in the zero page. (The rest of page zero is reserved for Kernal and BASIC.)
The default configuration is tailored to C programs. It supplies the load address and a small BASIC stub that starts the compiled program using a SYS command.
This configuration is made for Assembly programmers who don't need a special
setup. The default start address is $0801. It can be changed with the
linker command-line option
-S. All standard segments,
with the exception of
ZEROPAGE, are written to the output file;
and, a two-byte load address is prepended.
To use that config. file, assemble with
-t cx16, and link with
cx16-asm.cfg. The former will make sure that the correct character
translations are in effect, while the latter supplies the actual config.
cl65, use both command-line options.
Sample command line for
cl65 -o file.prg -t cx16 -C cx16-asm.cfg source.s
To generate code that loads to $A000:
cl65 -o file.prg -Wl -S,$A000 -t cX16 -C cX16-asm.cfg source.s
It also is possible to add a small BASIC header to the program, that uses SYS to jump to the program entry point (which is the start of the code segment). The advantage is that the program can be started using RUN.
To generate a program with a BASIC SYS header, use
cl65 -o file.prg -u __EXEHDR__ -t cx16 -C cx16-asm.cfg source.s
Please note that, in this case, a changed start address doesn't make sense, because the program must be loaded to BASIC's start address.
Programs containing CX16-specific code may use the
header files. Using the later may be an option when writing code for more than
one CBM-like platform, because it includes
cx16.h, and declares several
functions common to all CBM-like platforms.
The functions listed below are special for the CX16. See the function reference for declarations and usage.
Some functions are available for all (or, at least most) of the Commodore-like machines. See the function reference for declarations and usage.
The following pseudo variables declared in the
cx16.h header file do allow
access to hardware located in the address space. Some variables are
structures, accessing the struct fields will access the chip registers.
VERA structure allows access
to the Video Enhanced Retro Adapter chip.
Access to the two VIA (Versatile Interface Adapter) chips is available via
VIA2 variables. The structure behind those variables
is explained in
A character array that mirrors the eight-Kibibyte window, at $A000, into banked RAM.
The names in the parentheses denote the symbols to be used for static linking of the drivers.
No graphics drivers are available currently for the CX16.
No extended memory drivers are available currently for the CX16.
The default drivers,
Supports up to two NES (and SNES) controllers connected to the joystick ports of the CX16. It reads the four directions, and the A, B, Select, and Start buttons. Buttons A and B are the first and second fire buttons.
The default drivers,
Supports a standard 3-button mouse connected to the PS/2 mouse port of the Commander X16.
Currently (r35), this driver doesn't support
No serial drivers are available currently for the CX16.
The Commander X16 still is being designed. Its configuration can change at any time. Some changes could make old programs fail to work.
Esc key acts as Commodore's
STOP key -- or, you can press the
Ctrl key and the
C key together. Pressing the
Shift and the
Esc keys together will type Commodore's
Esc, press the
Ctrl key and the
[ key together.
Command-line arguments can be passed to
main(). Because that is not
supported directly by BASIC, the following syntax was chosen:
RUN:REM ARG1 " ARG2 IS QUOTED" ARG3 "" ARG5
main()is the program name.
The program return code (low byte) is passed back to BASIC by the use of its
The run-time for the CX16 uses routines marked as
interrupt handlers. Such routines must be written as simple machine language
subroutines, and will be called automatically by the interrupt handler code
if they are linked into a program. See the discussion of the
feature in the
This software is provided "as-is", without any expressed or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: