Functions
There are 51 of them, grouped by what they do.
- Startup How the game starts and what the loader tells it.
- Flow control Jumps and delays. They keep the 6507 inside the cartridge’s 4 KB and let you use up an exact number of cycles.
- Loads and stores Loading A, X and Y, and writing to the TIA or to RAM.
- Reads Joysticks, console switches, collisions and the timer.
- Bus stuffing Three-cycle writes where the cartridge forces the data onto the bus while the 6507 writes.
- Stack PHA, PHP, PLA, PLP and JSR, usually with the stack pointing at the TIA.
- Overblank The 6507 runs VSYNC, VBLANK and overscan by itself from RIOT RAM, which leaves the ARM free.
- 7800 bus The 7800’s 6502 doesn’t wait for the cartridge, so these functions park it, listen to the bus and feed MARIA’s DMA.
- Cartridge ROM What the cartridge serves when the 6507 reads on its own.
- Saving Non-volatile storage with two slots.
- Utilities Tables and C library functions provided by the loader.
Coverage
How many of the 51 functions each implementation has in full, in its latest version.
- Stella33 + 4
- Gopher260046 + 3
- Test780046 + 3
- PlusCart and UnoCart37 + 4
- Chameleon Cart25 + 3
- Chameleon Cart, alternative firmware31 + 2
- Newbroo Wild Cart and Deckerno data
- VCSIDE ACE adapter15 + 3
Blue is complete, orange works with differences, and the striped part exists but does nothing.
Differences between implementations
Cases where the same game behaves differently depending on the emulator or the cartridge.
- vcsJmpToRam3 on the Chameleon Cart expects the return one byte earlier
- Some implementations of vcsSta4 only use the low byte
- vcsRead4 doesn’t take the same number of cycles everywhere
- You can’t test bus stuffing in Stella
- Functions with a different name, or that do nothing
- Where the game code runs
- The Chameleon Cart calls elf_main with the console already running
Compatibility table
● complete ◐ works with differences ○ exists but does nothing – missing ? no data
A minimal game
The ARM sends every instruction of the visible lines. During the overblank the 6507 runs VSYNC, VBLANK and overscan by itself from RIOT RAM, and the ARM is free to run the game logic.
#include "vcsLib.h"
void elf_main(uint32_t *args)
{
int frame = 0;
if (args[MP_FEATURE_FLAGS] & FF_CHAMELEON_CART)
vcsEndOverblank(); /* the Chameleon starts in its overblank */
vcsJmp3(); /* 6507 to $1000 */
vcsCopyOverblankToRiotRam(); /* overblank program at $80 */
vcsStartOverblank();
for (;;) {
vcsEndOverblank(); /* first visible line */
for (int line = 0; line < 192; line++) {
vcsSta3(WSYNC);
vcsWrite5(COLUBK, (uint8_t)(line + frame));
vcsJmp3(); /* keep the PC inside the 4 KB */
}
vcsWrite5(VBLANK, 2);
uint8_t joy = vcsRead4(SWCHA);
vcsStartOverblank();
frame += (joy & 0x80) ? 1 : 2; /* game logic, during the overblank */
}
}“PXE” is the name the Chameleon Cart kit and some other cartridges are sold under. It’s the same format, a relocatable ELF linked against vcsLib. It has nothing to do with the “VCSLib” from 8bitworkshop, which is a C library for cc65.