EN

vcsLib

vcsLib is the library that ELF games use to drive the Atari 2600 and 7800. The game is a C program running on the ARM chip inside the cartridge, and each call to vcsLib puts the bytes of one 6507 instruction on the bus just as the console reads them.

Nobody has written a specification for it, and every emulator and cartridge has ended up with a slightly different set of functions. This site describes what each function does and where it works.

vcsSta3(WSYNC), vcsWrite5(COLUBK, 0x84) and vcsJmp3() on the 6507 bus.
φ2A12–A0D7–D0R/WvcsSta3(WSYNC)vcsWrite5(COLUBK, 0x84)vcsJmp3()$100085$100102$0002A$1002A9$100384$100485$100509$000984$10064C$100700$100810
1 sta zp2 zero page3 the 6507 writes A4 lda #5 value6 sta zp7 COLUBK8 the TIA changes the background9 jmp abs10 low byte11 high byte

served by the cartridgewritten by the 6507

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.

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.

Compatibility table

● complete ◐ works with differences ○ exists but does nothing – missing ? no data

FunctionStellaGopherT7800PlusCartChameleonCham. altNewbrooACE
Startup
elf_main●●●◐●●?●
Flow control
vcsJmp3●●●●●●?●
vcsNop2●●●●●●?●
vcsNop2n●●●●●●?●
vcsNop3–●●–––?–
vcsSleep●●●●●●?●
vcsJsr6●●●●––?–
vcsTxs2●●●●––?–
Loads and stores
vcsLda2●●●●●●?●
vcsLdx2●●●●●●?●
vcsLdy2●●●●●●?●
vcsSta3●●●●●●?●
vcsStx3●●●●●●?●
vcsSty3●●●●●●?●
vcsSax3●●●●●●?–
vcsSta4●◐◐●●●?◐
vcsStx4●◐◐●●●?–
vcsSty4●◐◐●●●?–
vcsWrite5●●●●●●?●
vcsWrite6●●●●●●?●
Reads
vcsRead4●●●◐◐◐?◐
vcsRead6–●●●––?–
Bus stuffing
vcsLdaForBusStuff2◐●●●–●?–
vcsLdxForBusStuff2◐●●●–●?–
vcsLdyForBusStuff2◐●●●–●?–
vcsWrite3◐●●●–●?–
vcsWrite4–●–●––?–
Stack
vcsPha3●●–●––?–
vcsPhp3●●●●––?–
vcsPla4●●●●––?–
vcsPlp4●●●●––?–
vcsPla4Ex–●●◐––?–
vcsPlp4Ex–●●●––?–
Overblank
vcsCopyOverblankToRiotRam●●●●●●?◐
vcsStartOverblank●●●●●●?●
vcsEndOverblank●●●◐◐●?●
7800 bus
vcsJmpToRam3●●●●●◐?○
vcsWaitForAddress–●●●–●?○
vcsSnoopRead––●–●●?○
vcsInjectDmaData––●○◐●?○
Cartridge ROM
vcsPokeRomByte–●●–––?–
vcsSetNextAddress–●●–––?–
Saving
vcsInitNvStore–●●○––?–
vcsWriteNvChunk–●●○––?–
vcsProcessNvStoreEvents–●●○––?–
vcsIsNvBusy–●●○––?–
Utilities
randint●●●●●●?–
ReverseByte●●●●●●?–
ColorLookup●●●–––?–
memset●●●●●●??
memcpy●●●●●●??

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.