The MEGA65 is a modern 8-bit computer that is based on the never-released Commodore 65. It uses the 45GS02 CPU and has a VIC-IV graphics controller with 256 colors and an 80-column text mode. It has two CIA (6526) I/O chips and SID sound chips. It supports file storage on Secure Digital cards, and allows two joysticks and a mouse to be connected.
This file contains an overview of the MEGA65 run-time system as it comes with the cc65 C compiler. It describes the memory layout, MEGA65-specific header files, available drivers, and any pitfalls specific to that platform.
Please note that the functions mentioned here are 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 MEGA65 target is a machine language program that's prepended with a 16-bit load address and a one-line BASIC stub which selects bank 0 and 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 use the memory configuration that is active when the program is started. The usable memory range is $2001 - $7FFF. The area above $7FFF is not used by the default configuration, because it may contain ROM, I/O, or memory that is reserved by the MEGA65 firmware.
Special locations:
The C run-time stack is located at $8000, and grows downward.
The C heap is located at the end of the program, and grows toward the C run-time stack.
The default configuration uses the zero page locations $18 - $31. The rest of page zero is reserved for BASIC and the Kernal.
The ld65 linker comes with a default config. file for the MEGA65, which
is used via -t mega65. The MEGA65 package comes with additional secondary
linker config. files which are used via -t mega65 -C <configfile>.
The default configuration uses 26 bytes in the zero page, at $18 - $31. (The rest of page zero is reserved for BASIC and the Kernal.) The assembly configuration makes the zero page from $0002 to $00FF available to the program.
mega65.cfg)
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.
mega65-asm.cfg
This configuration is made for Assembly programmers who don't need a special
setup. The default start address is $2001. It can be changed with the
linker command-line option --start-addr or -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 mega65, and link with -C
mega65-asm.cfg. The former will make sure that the correct character
translations are in effect, while the latter supplies the actual config.
When using cl65, use both command-line options.
Sample command line for cl65:
cl65 -o file.prg -t mega65 -C mega65-asm.cfg source.s
To generate code that loads to $4000:
cl65 -o file.prg -Wl -S,$4000 -t mega65 -C mega65-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 mega65 -C mega65-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 MEGA65-specific code may use the mega65.h or cbm.h
header files. Using the latter may be an option when writing code for more than
one CBM-like platform, because it includes mega65.h, and declares several
functions common to all CBM-like platforms.
There are no functions that are specific to the MEGA65. See the function reference for the functions that are available on all CBM-like platforms.
cpeekcolor() works differently on the MEGA65 than it does on other
platforms. Each character has two colors: background and text (foreground).
cpeekcolor() returns both colors. The high nybble describes the
background color, the low nybble describes the text color. For example, if the
function is used on the default screen, then it returns $61, which means
white-on-blue.
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 mega65.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.
VICThe VIC structure allows access to the VIC-IV (the graphics
controller). The structure is currently identical to the VIC-II register
layout; see the _vic2.h header file located in the include directory
for the declaration of the structure.
SID1, SID2Access to the two SID (sound interface device) chips is available via the
SID1 and SID2 variables. The structure behind these variables is
explained in _sid.h.
CIA1, CIA2Access to the two CIA (complex interface adapter) chips is available via
the CIA1 and CIA2 variables. The structure behind these variables
is explained in _6526.h.
COLOR_RAMA pointer to the color RAM at $D800.
The names in the parentheses denote the symbols to be used for static linking of the drivers.
No graphics drivers are currently available for the MEGA65.
No extended memory drivers are currently available for the MEGA65.
The default drivers, joy_stddrv (joy_static_stddrv),
point to m65-stdjoy.joy (mega65_stdjoy_joy).
m65-stdjoy.joy (mega65_stdjoy_joy)Supports up to two standard joysticks connected to the joystick ports of the MEGA65.
No mouse drivers are currently available for the MEGA65.
No serial drivers are currently available for the MEGA65.
The MEGA65's firmware and memory configuration can change at any time. Some changes could make old programs fail to work.
The RUN/STOP key stops a running program. Holding Shift while
pressing it runs the first program on disk.
The ESC key is used to start escape sequences. Press and release it, and
then press the key that selects the desired function. See the MEGA65 user
guide for the available escape sequences.
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
ST variable.
The run-time for the MEGA65 uses routines marked as .INTERRUPTOR for
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 .CONDES
feature in the
assembler manual.
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: