Skip to content

256 Bytes

You'll write an intro that fits in 256 bytes of machine code, where every byte is a decision and no library can help you.

About

Sizecoding is the scene's purest sport. The whole program (screen setup, effect, animation, exit) has to fit in 256 bytes, which is about two sentences of this paragraph. The well-worn target is a DOS .COM file run in DOSBox, because mode 13h gives you a 320 by 200 screen with 256 colours for four bytes of code, and the rest of your budget goes on the effect. NASM, DOSBox and the sizecoding wiki are all free. What counts is an assembled file of 256 bytes or fewer that animates in colour and exits on a keypress; the same badge on a ZX Spectrum, C64 or Amstrad counts just as well. What does not count is writing C and hoping the compiler is small, because it never is. You will spend the last week cutting single bytes, and that week is the badge.

At a glance

Per requirement
35 XP
Completion bonus
300 XP
Requirements
6
Takes
A few weeks of evenings
Skill level
Advanced (years of practice)
Cost
Free
Supplies
Nothing special
Where
At home
Other people
On your own
Locked for now
Earn two more Uncommon badges in Demoscene to open this one. Log in to see how far along you are.

Requirements

  1. 1
    Assemble a .COM that sets mode 13h and fills the screen, and show its size. mov al,13h and int 10h switch modes, then point ES at segment A000h and use rep stosb to fill the screen. Assemble with nasm -f bin, run it in DOSBox, and list the file size, which should be under 20 bytes. Take a screenshot of the filled screen and the size. Photo
  2. 2
    Draw something per pixel with a stosb loop. Loop over 64,000 pixels, compute a value from the pixel's x and y (an XOR pattern or a sum of two sines from a table), and stosb it. DI counts the pixel for you, so x and y come from dividing DI by 320. Film it in DOSBox. Video
  3. 3
    Animate it by waiting for the vertical retrace. Read port 3DAh until bit 3 flips, which marks the start of the retrace, then advance a time counter and redraw. Without this it tears or runs at whatever speed the emulator feels like. Film ten seconds of smooth motion. Video
  4. 4
    Set your own palette through ports 3C8h and 3C9h. Send the index to 3C8h, then red, green and blue to 3C9h, six bits each, in a loop of 256. A palette computed from the loop counter costs about a dozen bytes and makes the default VGA colours go away. Take a screenshot. Photo
  5. 5
    Get it under 256 bytes with motion, colour and a clean exit. Check for a key with int 16h and return when one is pressed. Then cut: use one-byte instructions, reuse registers that happen to hold the right value, and lean on the known register state at startup. Take a screenshot of the hex dump and the directory listing with the size. Photo
  6. 6
    Release it on Pouet or Demozoo and write down three bytes you cut and how. Give it a name and your handle, upload the file with a capture, and write a short note on three specific cuts, like swapping a mov for an xchg or dropping a cmp that a flag already answered. Record a 20-second capture. Video