Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Here's my favorite, from the Atari 2600.

The graphics chip has two "missile" objects that act like simple sprites that are only one bit wide. They are each enabled or disabled by writing 1 or 0 to a certain bit of a certain hardware register of the graphics chip.

That register is laid out in hardware with that certain bit at bit 1. Why there, why not the low or high bit? Because that corresponds to the location of the zero flag in the flags register of the 6502 CPU.

So the missile objects can be quickly enabled or disabled by setting the stack pointer to the address of that register, doing a compare on the object coordinates, and pushing the flags register. Both missiles can be done in sequence because the registers are adjacent and the push instruction decrements the stack pointer to set up for the next one.

All to save two instructions on rendering the missiles each scanline. With a nice bonus that the code is time-invariant without branching.



2600 programming is an exercise in crazy.

- The parallel port chip has direction bits that control whether a line is an input or an output. This register is read/write, so you can use it as temporary memory when you don't care about reading or writing I/O (which is most of the time).

- Lots of code doesn't need a stack; it doesn't call anything, and it can just jump to where it needs to be at the end. Now we can use the S register for something else.

Many, many other tricks. I used some of them a few years ago on an embedded system that needed to fit into 1920 bytes. I enlisted a cow-orker into the effort and we were both cackling away. [Later, the hardware guys offered us a different chip with twice the memory, but at that point we were too close to shipping to make any changes, and besides, it wouldn't have been as fun... :-) ]


2600 programming is alive in the demo scene. This was just created in 2014 and is completely insane:

http://youtu.be/04Wk9Oi_Fsk


I'd be interested to know if they limited themselves to 4K ROM (standard size of a 2600 cartridge).


That and much much more is discussed here by the authors:

http://xayax.net/bang!/




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: