A Great Old-Timey Game-Programming Hack (2013)
blog.moertel.com
blog.moertel.com
I'll let you know you were in good company. At Williams (pinball/video game company, later became Midway) that exact same hack was used in almost every game that used the 6809. We definitely used it in all the dot-matrix pinball machines to blit large pieces of data in RAM.
There's another documentary called Tilt: The Battle to Save Pinball by Greg Maletec that describes what we were going through on the pinball side near the end. It's streamable on a few services.
The stories themselves? Way too many to relate. But it was certainly like the doc. A cutthroat company where anything could happen. But probably the most talented and creative group of engineers I've ever worked with.
[0] https://retrocomputing.stackexchange.com/questions/4744/how-...
On pretty much all the micros of that era, stack operations would be the fastest instruction due to the auto-decrement behavior. If one could leverage the stack for bitblts, it was usually a win.
The 2600's video hardware is actually intentionally designed for such a trick. The register to enable the "missile" objects has its hot bit at bit 1. Why that, why not bit 0 or 7? Because bit 1 is the location of the zero flag in the 6502's flags register. You can enable/disable an object by doing a compare on its coordinate, then push the flags register. No conditionals or branching needed, and you even get a consistent cycle-invariant code path, a useful property on this machine. And there are registers for several such objects adjacent in addressing space, so you can handle them with consecutive push instructions without resetting the stack pointer.
As for inverting the storage to deal with the directionality, that trick was also known on the 2600. Store a sprite bottom-first in memory, so that your indexing counter decrements towards zero rather than incrementing upwards, so you can "branch if zero flag" to know when you're done rather than needing a compare instruction.
For those wondering whether the 2600 even _had_ a stack: it had 128 bytes of RAM that appeared at both $80-$FF _and_ $180-$1FF (maybe also other places) in the address map.
The former means you can read and write it using zero page addressing (faster, shorter instructions), the latter that you’d have half of the 6502 hardware stack, which the CPU thought was at $100-$1FF. It was up to the programmer to ensure the stack didn’t accidentally ran into your variable storage.
When bit 9 is 1 (pages $02xx, $03xx, $07xx, $08xx, etc), you're accessing the timer and console input registers instead. When bit 12 is 1, you're accessing ROM instead of anything onboard.
It's not really useful to mirror the RAM anywhere else besides page 1 for the stack, but the architecture just ended up that way for simplicity - no need to decode any other lines than 9 and 12. It would have been possible to use that address space for more ROM, but at the cost of more logic gates - as-is, address line 12 is simply directly wired to the ROM chip-enable line.
https://news.ycombinator.com/item?id=6913467 (2013, 145 comments)
https://news.ycombinator.com/item?id=10491768 (2015, 11 comments)
https://news.ycombinator.com/item?id=18206463 (2018, 22 comments)
> You'll love my 64-bit ring-0-only identity-mapped operating system.
RIP
I wonder how much software assumes it's being mapped in the lower portion of the address space.
Might boot up TempleOS for a bit and play around with it later.
F
That's how programming ought to feel.
You can definitely try that one.