Skip to content

The 6502 standard library

On the native targets (arm64, x86_64, win64, arm9) the standard library uses a host operating system for everyday services: a clock, a process heap, a way to exit with a status. The xt6502 target has none of these. It is a bare banked 6502 with the platform ROM, so the library provides those services itself, in hand-written 6502.

The classes below exist on every target where the service makes sense. On the native backends they are thin wrappers over the host OS. On the 6502 they are the full implementation: reading hardware registers, walking a free list, chaining an interrupt vector.

  • Time: the RTCLOK jiffy clock, with elapsed time in jiffies and seconds, plus busy-wait delays. On native targets it reads a monotonic host clock instead.
  • Heap: introspection on the coalescing free-list allocator (free bytes, largest extent, capacity). The 6502 walks the free list; native targets report host-heap figures.
  • Vbi: install and remove vertical-blank interrupt handlers through the OS-safe SETVBV path. 6502-only; no native target has these vectors.
  • System: process control, to exit the program back to DOS from anywhere. 6502-only; on native targets you return from main.
  • Memory: bulk fill / clear / copy / move with self-modifying page-aligned inner loops. Its bodies are inline 6502 assembly, so it is effectively 6502-only.

The 6502 also has more than these utilities:

  • Strings and collections use narrower types. The 6502 String is byte-oriented with u16 indexes and has no UTF-8 character layer, because a decoder is too costly on a 6502. Array/Number store narrower primitives unless -DENABLE_64BIT=1 widens them. See Foundation for how the containers differ, and String (xt6502) for the byte-oriented string API.
  • Graphics and files exist on 6502 too. The Gfx* classes drive the ANTIC display modes, and FILE provides buffered file I/O over DOS.

If a class from the native library is missing here, it usually wraps an OS facility the bare 6502 does not have. Where the service is useful, the library provides a 6502 implementation rather than a stub.