Writing a 256-Byte Intro: Sizecoding on the Atari 8-bit

Concentric purple rings in 16 shades on an Atari GTIA screen, with finer moiré stripes towards the left and right edges

A 256-byte intro is a complete audiovisual program, with an effect and usually sound, in a file no bigger than 256 bytes. Size-coding competitions for these "bytetros" are a fixture of today's demoparties. At Lovebyte, an online party devoted to them, Atari coders have entered everything from 16-byte intros up to the 256-byte showpiece category. Silly Venture in Gdańsk runs a 256-byte intro compo for the XL/XE and, in 2025, a separate 256-byte game compo too.

This guide builds Rings, an animated intro of concentric rings in 16 shades with a colour cycle and a falling tone. The finished file is 195 bytes. Along the way it covers the habits that make sizecoding work: knowing exactly what each byte does, generating data instead of storing it, and checking every "saving" on screen.

What you need: the MADS assembler, an emulator and some 6502 assembly (see Getting Started with 6502 Assembly on the Atari 8-bit). The intro was assembled with MADS 2.1.7 and run in atari800 with its built-in Altirra OS. It uses only documented OS entry points, so it should run on any XL/XE OS.

1. The budget

Competition limits apply to the file you hand in, so an Atari executable's headers count against you. A minimal XEX has:

Part Bytes
$FF $FF marker 2
Load start and end addresses 4
Your code and data n
Run-address segment ($02E0–$02E1 header plus the address) 6

That leaves 244 bytes for the program itself. Rules vary between parties, including the machine and OS the entry must run on, so read them before you start (see section 8).

2. Choosing an effect that's cheap

The best size-coding effects come from a short formula evaluated for every pixel. Rings uses the distance from the centre of the screen:

shade = top four bits of ((dx² + dy²) / 4 + t)

where t is a frame counter. Constant distance gives circles; adding t makes them flow inwards or outwards; and taking only four bits makes the value wrap round, so you get repeating bands rather than one smooth gradient.

GTIA mode 9 suits this perfectly. It shows 80 × 192 pixels, each a 4-bit luminance of one hue, packed two to a byte. Writing the same shade into both halves of a byte gives a 40 × 192 grid of "fat pixels", one byte each, which keeps the inner loop simple. The hue comes from the background colour register, so a single store to COLOR4 recolours the entire picture.

3. Opening the screen through CIO

start   ldx #$60        ; IOCB 6
        lda #3          ; command: OPEN
        sta $342,x      ; ICCOM
        lda #<sname
        sta $344,x      ; ICBAL/ICBAH: address of "S:"
        lda #>sname
        sta $345,x
        lda #12         ; read and write
        sta $34a,x      ; ICAX1
        lda #9          ; mode 9: 16 shades of one hue
        sta $34b,x      ; ICAX2
        jsr $e456       ; CIOV, the documented CIO entry point

This is exactly what BASIC's GRAPHICS 9 does: open the S: device on channel 6 with the mode number in the second auxiliary byte. It costs 30 bytes plus 2 for the string S:. Building your own display list would cost more.

Many published intros save bytes by jumping straight into the OS ROM's graphics, PLOT and DRAWTO code at fixed addresses. That works, but only on the OS revision the author used: entries made this way typically specify a stock 800XL with the revision 2 OS, and fail under replacement OSes such as Altirra's. $E456 (CIOV) is one of the documented vectors that stays put on every Atari OS, which is why Rings runs anywhere.

4. Generate tables, don't store them

The formula needs squares. Multiplying on a 6502 is slow and long. A 256-byte table is fast, but far too big to include. So Rings builds the table at start-up, using the fact that the squares are sums of odd numbers (1, 1+3, 1+3+5 …):

        lda #0
        sta slo
        sta shi
        tax             ; n = 0
        lda #1
        sta odd
mk      lda shi         ; A = (n*n)/4, low byte
        sta tmp
        lda slo
        lsr tmp
        ror
        lsr tmp
        ror
        sta sq,x        ; sq[n]
        pha
        txa
        eor #$ff
        tay
        iny             ; Y = -n
        pla
        sta sq,y        ; sq[-n]
        lda slo         ; square += odd
        clc
        adc odd
        sta slo
        bcc no1
        inc shi
no1     inc odd
        inc odd
        inx
        bpl mk          ; n = 0..127

The running total slo/shi is a 16-bit square. Each entry is divided by 4 with two shift-and-rotate pairs, then stored twice: at index n and at index −n (256 − n). With that mirror, a signed distance can be used directly as an index, so sq,x works for dx from −127 to 127 without any sign handling. The table lives in page 6 ($0600), which the OS leaves free for programs. The whole table builder is 54 bytes; the table it makes is 256.

5. The drawing loop

For each of the 192 rows, the row's share of the formula is worked out once:

rowlp   lda row         ; dy = row/2 - 48
        lsr
        sec
        sbc #48
        tax
        lda sq,x
        clc
        adc t           ; add the frame counter: the rings move
        sta ry

Then each of the 40 bytes across adds the column's part and writes the result:

        ldy #39         ; 40 bytes per row, right to left
collp   tya             ; dx = column*4 - 80
        asl
        asl
        sec
        sbc #80
        tax
        lda sq,x
        clc
        adc ry          ; (dx*dx + dy*dy)/4 + t
        and #$f0        ; keep the top four bits ...
        sta tmp
        lsr
        lsr
        lsr
        lsr
        ora tmp         ; ... and copy them into both pixels
        sta (ptr),y
        dey
        bpl collp

The scale factors keep the circles round. A mode 9 byte is about as wide as eight scan lines are tall, so one column step is worth 4 units of distance and one row is worth half a unit. Counting Y down to zero and using bpl avoids a compare instruction, a standard size-coding habit. The screen address comes from SAVMSC ($58/$59), where the OS left it after the OPEN.

6. Colour and sound for free

        lda t           ; next frame
        sec
        sbc #8
        sta t
        sta $2c8        ; COLOR4: the hue of the whole screen
        sta $d200       ; AUDF1: a falling tone
        lda #$a4        ; pure tone, volume 4
        sta $d201       ; AUDC1
        jmp frame

One value does three jobs. It moves the rings, it sets the hue through the OS shadow COLOR4 (copied to the hardware every vertical blank), and it sets the pitch of POKEY voice 1. Reusing a value you already have is the cheapest effect there is.

7. The complete intro

; RINGS - a small intro for the Atari 8-bit (assemble with MADS)
t       = $80           ; frame counter
ptr     = $82           ; screen pointer (2 bytes)
row     = $84           ; current row, 0..191
ry      = $85           ; this row's part of the pattern
tmp     = $86
odd     = $87           ; 1, 3, 5, 7 ...
slo     = $88           ; 16-bit running square
shi     = $89
sq      = $0600         ; table: sq[n] = (n*n)/4, for n = -127..127

        org $2000

; --- open a GRAPHICS 9 screen through CIO, exactly as BASIC would ---
start   ldx #$60        ; IOCB 6
        lda #3          ; command: OPEN
        sta $342,x      ; ICCOM
        lda #<sname
        sta $344,x      ; ICBAL/ICBAH: address of "S:"
        lda #>sname
        sta $345,x
        lda #12         ; read and write
        sta $34a,x      ; ICAX1
        lda #9          ; mode 9: 16 shades of one hue
        sta $34b,x      ; ICAX2
        jsr $e456       ; CIOV, the documented CIO entry point

; --- build the table of squares by adding odd numbers ---
        lda #0
        sta slo
        sta shi
        tax             ; n = 0
        lda #1
        sta odd
mk      lda shi         ; A = (n*n)/4, low byte
        sta tmp
        lda slo
        lsr tmp
        ror
        lsr tmp
        ror
        sta sq,x        ; sq[n]
        pha
        txa
        eor #$ff
        tay
        iny             ; Y = -n
        pla
        sta sq,y        ; sq[-n]
        lda slo         ; square += odd
        clc
        adc odd
        sta slo
        bcc no1
        inc shi
no1     inc odd
        inc odd
        inx
        bpl mk          ; n = 0..127

; --- draw one frame ---
frame   lda $58         ; SAVMSC: start of screen memory
        sta ptr
        lda $59
        sta ptr+1
        lda #0
        sta row

rowlp   lda row         ; dy = row/2 - 48
        lsr
        sec
        sbc #48
        tax
        lda sq,x
        clc
        adc t           ; add the frame counter: the rings move
        sta ry

        ldy #39         ; 40 bytes per row, right to left
collp   tya             ; dx = column*4 - 80
        asl
        asl
        sec
        sbc #80
        tax
        lda sq,x
        clc
        adc ry          ; (dx*dx + dy*dy)/4 + t
        and #$f0        ; keep the top four bits ...
        sta tmp
        lsr
        lsr
        lsr
        lsr
        ora tmp         ; ... and copy them into both pixels
        sta (ptr),y
        dey
        bpl collp

        lda ptr         ; next row is 40 bytes on
        clc
        adc #40
        sta ptr
        bcc no2
        inc ptr+1
no2     inc row
        lda row
        cmp #192
        bne rowlp

        lda t           ; next frame
        sec
        sbc #8
        sta t
        sta $2c8        ; COLOR4: the hue of the whole screen
        sta $d200       ; AUDF1: a falling tone
        lda #$a4        ; pure tone, volume 4
        sta $d201       ; AUDC1
        jmp frame

sname   dta c'S:'

        run start

Assemble it with a listing file, which shows the address and bytes of every instruction:

mads rings.asm -o:rings.xex -l:rings.lst

MADS reports 195 bytes written. The listing shows the code running from $2000 to $20B6, which is 183 bytes, plus the 12 bytes of headers. Run rings.xex in any emulator or from DOS.

8. Squeezing it, carefully

Once something works, size coders go looking for bytes. Two savings in Rings are safe, and both were checked on screen:

  • jmp frame becomes bne frame. The last value loaded before it is $A4, never zero, so the branch is always taken. A branch is 2 bytes instead of 3. The target is 96 bytes back, inside the 128-byte branch range.
  • Drop the clc before adc #40. At that point the carry is provably clear: the last instructions to touch it are the four lsrs in the inner loop, and after and #$f0 they only ever shift out zero bits.

Together those take the file to 193 bytes with an identical picture.

A third idea looks just as safe but isn't. The sec before sbc #80 seems removable too: the carry is clear there, so the subtraction becomes column*4 - 81 and the centre shifts by a quarter of a unit. On screen, though, the result has three sets of rings instead of one, and a different background. Rings is a sampled pattern, and the many wraparounds at the edges alias. Moving every sample by an odd amount changes which "ghost" centres appear. The lesson for every size coder: run each saving before you keep it.

Other standard tricks to try on your own intros:

  • Load into zero page. Code and variables in page zero use 2-byte instructions instead of 3-byte ones, and some intros are loaded straight there.
  • Know your registers. After an OS call or a loop, registers and flags often hold known values. Using them saves loads and clc/sec instructions, as above.
  • Let values wrap. 8-bit overflow is often the effect, not a bug, as with the bands in Rings.
  • Trade exactness for size. Size-coded "sine" waves are often parabolas or table approximations built at run time.

9. Releasing it

  • Parties. Lovebyte is held online, with sizecoding compos from 8 to 512 bytes, so you can take part from home. Silly Venture in Gdańsk has run XL/XE 256-byte intro and game compos. Read each party's rules for size limits, target machine and OS.
  • Release notes. State the machine, OS and memory your intro needs (for example "800XL, OS rev 2, BASIC off") and whether it needs PAL or NTSC.
  • Archives. After the party, productions are listed on Demozoo and Pouët and archived on scene.org. Many coders now publish their source too, which is the best way to learn: ivop's Lovebyte entries and the full source of Slight's demo RERZÓGED are on GitHub.

Troubleshooting

  • Black screen, nothing happens: the run address is missing. Check for run start (MADS) or a $02E0 segment.
  • Works in one emulator but not another, or not on hardware: you are probably calling an undocumented ROM address. Use the documented vectors, or state the required OS.
  • Garbage at the top or bottom: a pointer has run past the screen. A mode 9 screen is exactly 40 × 192 = 7,680 bytes from SAVMSC.
  • The picture looks wrong after "optimising": undo the last change. Then check which flags and registers it assumed.

Further reading

  • De Re Atari, chapter 8 (the operating system and CIO), and Ian Chadwick's Mapping the Atari (IOCB layout, SAVMSC, COLOR4, POKEY registers).
  • The sizecoding.org wiki, whose 6502 section includes Atari 8-bit material.
  • On this site: GTIA Graphics Modes 9, 10 and 11, CIO and IOCBs: How Atari Input/Output Really Works, Inside the XEX: The Atari DOS Binary-Load File Format, MADS (Mad-Assembler): A Practical Guide, Lovebyte 2022: Atari Sizecoders Bring the Love in 16 to 256 Bytes, Silly Venture 2025 Winter Edition: The XL/XE Results.

Credits