Atari 7800 specific information for cc65

Karri Kaksonen


An overview over the Atari 7800 runtime system as it is implemented for the cc65 C compiler.

1. Overview

2. Binary format

3. A78 header

4. Encryption

5. Memory layout

6. Start-up condition

7. Platform specific header files

8. Loadable drivers

9. Limitations

10. Other hints

11. License


1. Overview

This file contains an overview of the Atari 7800 runtime system as it comes with the cc65 C compiler. It describes the memory layout, Atari 7800 specific header files and any pitfalls specific to that platform.

2. Binary format

The default binary output format generated by the linker for the Atari 7800 target is a 48K cartridge image.

3. A78 header

There is lots of different cart hardware available for the atari7800. Some carts have ROM, RAM, sound hardware, non-volatile high score chips. In order to know what kind of hardware the cart build requires there is a header file of 128 bytes in front of the binary.

The default build creates a cart file for a 48K rom cart without any extra features like the pokey audio chip or extra RAM.

In order to make cc65 more user friendly the build will add the a78 header automatically. This allows you to run the binary on emulators and flash carts on the real console.

4. Encryption

In order to boot the game in a mode that supports atari7800 functions the cart must be encrypted after the linking phase. There is a program called sign7800 that can be used to sign the cart. The encryption is not required for running the cart on emulators. You can also run atari2600 games without encryption.

5. Memory layout

cc65 generated programs with the default setup can use RAM from from $1800 to $203f. The 4k RAM is then mapped to zero page area. $2040 to $20ff is visible as zero page. After that we have a vero small RAM area that is unused. $2100 to $213f. Then we mirror a second block from the RAM to become the hardware stack. This would be from $2140 to $21ff.

The C-stack starts at $2800 and it can grow down to $2200.

size of the system stack can be customized by defining the __STACKSIZE__ linker variable.

Special locations:

Stack

The C runtime stack is located at $2800 - __STACKSIZE__ and growing downwards.

Heap

The C heap is located at $2200 and grows upwards.

6. Start-up condition

When powered-up, the Atari 7800 TIA registers contain random values. During the initialization phase, the start-up code needs to initialize the TIA registers to sound values (or else the console has an unpredictable behavior). In this implementation, zeros are written to all of TIA registers during the start-up phase.

Note that RIOT registers (mostly timers) are left uninitialized, as they don't have any consequence on the console behavior.

7. Platform specific header files

Programs containing Atari 7800 specific code may use the atari7800.h header file.

The following pseudo variables declared in the atari7800.h header file allow access to the Atari 7800 TIA, MARIA & RIOT chips registers.

TIA

The TIA structure allows read/write access to the Atari 7800 TIA chip registers. See the _tia.h header file located in the include directory for the declaration of the structure. Also refer to the Stella Programmer's Guide by Steve Wright for a detailed description of the chip and its registers.

RIOT

The RIOT structure allows read/write access to the Atari 7800 RIOT chip registers. See the _riot.h header file located in the include directory for the declaration of the structure. Also refer to the Stella Programmer's Guide by Steve Wright for a detailed description of the chip and its registers.

MARIA

The MARIA structure allows read/write access to the Atari 7800 MARIA chip registers. See the _maria.h header file located in the include directory for the declaration of the structure.

8. Loadable drivers

There are no drivers for the Atari 7800.

9. Limitations

TBD

10. Other hints

One may write a custom linker configuration file to tune the memory layout of a program. See the atari7800.cfg file in the cfg directory as a starting point.

11. License

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:

  1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.