Hasty Briefsbeta

Bilingual

Dirty tricks 6502 programmers use

a year ago
  • #optimization
  • #6502
  • #Commodore64
  • The article discusses a Commodore 64 coding competition where participants aimed to draw two lines with minimal byte usage.
  • Participants submitted PRG files with byte-length and MD5 hash, with Philip Heron and Geir Straume tying at 34 bytes.
  • The C64's default graphics mode involves screen RAM at $0400 and color RAM at $d800, with color settings at $d020 and $d021.
  • A C implementation demonstrates drawing lines by hardcoding slopes and using screen RAM manipulations.
  • 6502 assembly optimizations include unrolling loops, incremental screen pointer advancement, and ROM routine utilization.
  • Key tricks include using the 'scroll up' ROM function to avoid manual screen updates, self-modifying code for compactness, and exploiting the C64's power-on state.
  • Participants minimized startup code by overwriting stack or BASIC warm reset vectors, and used unconventional control flow to save bytes.
  • Bitpacked line drawing and extreme zeropage usage were among the advanced optimizations.
  • Philip Heron's winning 34-byte entry combines several tricks, including stack manipulation for entry and indirect-indexed addressing.
  • Post-competition discussions led to even smaller variants, showcasing the community's ingenuity.