Atari 2600 {Hardware} Design: Making One thing out of (Virtually) Nothing
The Atari 2600 wasn’t the primary dwelling online game console with replaceable video games, however it was the primary to be broadly profitable. Launched in 1977 because the Atari VCS (Video Pc System), and later renamed Atari 2600 in 1982, it will definitely bought over 30 million models and established a brand new market that also endures immediately within the PlayStation and Xbox. Previous to the 2600, most online game techniques have been both coin-operated machines present in bars, or fixed-function units restricted to a couple built-in video games like Pong. Atari’s first dwelling system was the start of a brand new age.
This wood-grained block of electronics preoccupied my younger thoughts. I needed one badly, however by no means succeeded at convincing my mother and father. I used to be eleven years outdated in 1982 when my pal Fred acquired an Atari, and I used to be sick with jealousy:
What a day! Not solely did Fred get an Atari system, however I acquired braces and an Izod Lacoste alligator shirt.
Atari 2600 {Hardware} Overview
Not too long ago over the vacation break, I got interested within the 2600’s {hardware} structure and began studying every little thing that I may discover about it. I knew that it was some type of 6502-based system, and I’d heard mentions of “racing the beam”, however that’s so far as my data went. I used to be shocked to find how primitive the 2600 {hardware} was, even in comparison with up to date 6502 techniques just like the Apple II, Commodore PET, and even Atari’s personal 8-bit computer systems.
Inside that wood-grained field there have been solely three digital chips:
- 6507 CPU (pin-reduced model of the 6502)
- 6532 RIOT
- TIA (Atari {custom} IC)
Notably absent from this listing was any RAM or ROM! The ROM got here from no matter recreation cartridge was inserted – there was completely no built-in I/O helper routines or working system, so it was as much as the sport programmer to offer every little thing. Sport cartridges have been restricted to 4 KB and lots of early video games have been solely 2 KB. Any of the photographs on this web page are vastly larger than that.
RAM was restricted to the tiny quantity of cupboard space built-into the 6532 RIOT chip – simply 128 bytes. 128 bytes! That’s… I don’t even… that’s small. Like actually, actually small. I might need guessed 1 KB or 2 KB RAM, however 128 bytes is simply in one other class fully. What’s worse, this tiny quantity of RAM needed to function each the scratchpad/heap and because the stack! Programmers acquired a number of bytes for issues like participant and merchandise areas, energy, rating, and that’s all.
However maintain on, as a result of it was even worse than you assume. This pin-reduced 6507 eradicated the 6502’s NMI and IRQ pins, so there was no {hardware} interrupt functionality in any respect. Every little thing needed to be achieved with software program timing and polling. For a real-time system constructed across the idea of racing the beam, this was simply masochism.
And for the ultimate kick within the nuts, there was no framebuffer. There wasn’t even a line buffer. The programmer solely had a number of TIA registers to play with and nothing extra. Most graphics needed to be generated by the CPU on the fly, on the very second that the tv’s electron beam was scanning previous the pixels of curiosity. Even the VSYNC sign for the tv needed to be dealt with in software program. With {hardware} like this, I’m shocked the Atari 2600 didn’t require a coal-fired steam engine or a picket crank deal with as well the video games! It’s loopy. I find it irresistible.
Contained in the TIA Chip
The guts of the 2600 is Atari’s custom-designed TIA chip – the Tv Interface Adapter. Yow will discover the hand-drawn TIA schematics on the internet for those who’re curious the way it works. The TIA internals look very unusual to trendy eyes, starting with the intensive use of linear suggestions shift registers the place you’ll anticipate finding binary counters, for issues just like the horizontal sync counter or the sprite place registers. I’ve seen LFSRs used as random quantity turbines in different 8-bit designs, however by no means as a general-purpose counter. These LFSRs additionally use two separate clocks, 180 levels out of part, which appears equally unusual. Right here’s the six bit horizontal sync counter:
The chip designers will need to have had their causes: perhaps LFSRs have been cheaper to implement or required fewer transistors than common binary counters? If you happen to simply want a six bit counter, then in the end it doesn’t actually matter if it counts 64 states from 000000 sequentially as much as 111111, or if it follows another random-looking however deterministic sequence of states. Both method you possibly can add logic to test for the terminal state and reset the counter when wanted. If anybody has an thought why the TIA’s designers used LFSRs for these items, I’d love to listen to about it. Luckily the Atari 2600 programmer is usually insulated from this LFSR humorous enterprise.
So how do video games really draw stuff? The best place to start is with what Atari calls the playfield, and is successfully a background sample on the display. The TIA has 20 bits of register state which the programmer can modify, and which is used to create a one-dimensional low-resolution monochrome bitmap on the left half of the scan line. The appropriate half of the road is both a duplicate of the left, or a mirrored copy. Need one thing utterly completely different on the proper aspect? Too dangerous. Need a number of colours? Too dangerous. The identical 20 bits of playfield register state are used on each horizontal scan line, too. Wish to show one thing completely different on every line? That requires continually modifying the playfield registers, earlier than every new scan line is drawn. There are solely 76 CPU clock cycles throughout every scan line, and with most CPU directions requiring 2 to five clock cycles, that doesn’t go away a lot time to do… principally something.
This playfield habits explains why so many Atari video games have left-right symmetry of their backgrounds, partitions, or related content material. Have a look at this picture of Pitfall, and see how the tree cover, tree trunks, floor, pit, and underground cave all present left-right symmetry. These are all constructed from the playfield (plus further tips to be described later). The one sprites are Pitfall Harry, the vine he’s swinging from, the rolling log, and the scorpion.
What about these sprites? Atari known as them gamers and missiles, however the idea is identical. Gamers are sprites eight bits broad, and the pixels are smaller than playfield pixels. They are often positioned wherever on the scan line, however just like the playfield, they’re one-dimensional monochrome bitmaps. If the programmer desires 2D sprites (which they definitely do), then the code should continually modify the participant graphics register, updating it earlier than every new scan line is drawn, together with setting the register to zero for the areas above and under the participant sprite the place nothing ought to be drawn. Does that sound extremely tedious? You wager!
Missiles are just one bit broad as an alternative of eight, however are in any other case equivalent to gamers. The TIA gives two gamers, two missiles, and a ball that’s like a 3rd missile. If the programmer desires extra sprites than this, or desires multi-colored sprites, or the rest that the {hardware} doesn’t present, then they’ll must get fancy by combining a number of gamers and missiles, or else make numerous precisely-timed updates to the TIA registers to create the phantasm of further sprites and colours.
One widespread method was to design video games with distinct horizontal bands of exercise, like Pitfall right here. That allowed the identical participant sprite to be reused a number of occasions because the display was painted from high to backside. For Pitfall, participant 0 may first be used to attract a rating digit on the high of the display. Then the identical participant 0 {hardware} useful resource can be used to attract a part of Pitfall Harry, then to attract the rolling log, and eventually to attract the scorpion. Since none of those overlapped one another horizontally, there was no battle so long as the software program may replace the participant graphics and place shortly between scan strains.
Atari {Hardware} Tips
Below a one-dimensional {hardware} system like this one, collision detection would have been extraordinarily troublesome if it have been left as much as the software program to offer. The required diploma of bookkeeping can be an excessive amount of: checking all of the sprites and the playfield for collisions with one another can be just about unimaginable with solely 76 clock cycles per scan line, on high of all of the CPU’s different vital duties. Luckily the TIA gives the very cool function of {hardware} collision detection, on the pixel degree! Any time a non-zero pixel overlaps one other non-zero pixel of the playfield, a participant, a missile, or the ball, a corresponding collision bit is ready within the TIA, which software program can later test and clear. With a complete of six graphics objects there are (6*5)/2 = 15 potential collisions (an software of the Handshake Problem) to be tracked by the TIA. Good!
Horizontal positioning of gamers and missiles is notoriously troublesome. Most programmers would anticipate that the TIA has registers to specify the horizontal place of every sprite, however no. That will be too simple. On the Atari 2600, the horizontal place of a participant or missile is ready by writing to a particular TIA register on the precise second the electron beam passes the specified place. Take into consideration that for a minute. The precise worth that’s written to the register doesn’t matter. This system isn’t telling the TIA “put participant 0 at place X”, it’s telling the TIA “put participant 0 at… (look ahead to it) RIGHT HERE!” Due to this design, horizontal positioning requires synchronizing a software program loop to the beginning of a scan line, delaying some period of time depending on the specified horizontal place, after which writing to the TIA register. Moderately than setting a selected worth for the horizontal place, the software program is definitely resetting a type of LFSRs within the TIA.
With the usual method for this timing-based horizontal positioning, it’s solely potential to get a horizontal decision of 5 CPU clock cycles, which is equal to fifteen pixels. To assist the programmer get fine-grained management, the TIA gives further registers that allow every sprite to be adjusted between -8 to +7 pixels from its atypical place. It’s clumsy, however the mixture of timing-based positioning plus fine-grained changes allow sprites to be positioned at any horizontal coordinate.
The fine-grained horizontal management includes writing to a TIA register named HMOVE, and its use results in one of many Atari 2600’s most infamous graphical flaws: an irregular sequence of black strains on the left aspect of the display, obscuring a part of the playfield. That is usually known as the HMOVE comb. Right here’s an instance from House Invaders:
It is a side-effect of the way in which the TIA performs fine-grained adjustment of sprite positions, and lots of video games exhibit this downside. Any time HMOVE is written to throughout a scan line, the horizontal blanking interval shall be prolonged by eight pixels on that line, slicing off the left fringe of the road. Is it a bug? An unintended function? The precise particulars are a lot too complicated to explain right here, however Andrew Towers has written a really thorough rationalization of TIA habits which you’ll discover at http://www.atarihq.com/danb/files/TIA_HW_Notes.txt. See the heading Taking part in with the HMOVE Registers.
Why do just some video games show this HMOVE comb impact, and others apparently don’t? It solely seems when video games reuse the identical sprite at completely different vertical positions on the display, which requires adjusting the sprite’s horizontal place mid-frame. House Invaders does this extensively, however easy video games like Fight don’t do that. Fight is restricted to the 2 built-in gamers and two built-in missiles, with no mid-frame repositioning, and subsequently no HMOVE comb.
Pitfall takes a distinct method, with a stable black bar on the left fringe of the display as an alternative of a comb. That is the results of writing to HMOVE on each scan line, even when it’s not wanted. Activision used this method in lots of video games, apparently having concluded {that a} stable black bar seemed nicer than a partial black comb.
There are lots of extra software program tips vital for making a high-quality Atari recreation. A non-symmetrical playfield or multi-colored playfield may be created by modifying the playfield graphics and shade registers at exactly the proper occasions, however it’s not simple! Coloration registers can be modified between strains, to offer extra complete colours on the display even when the variety of colours on a single line is restricted. Sprites may be reused and repositioned at completely different vertical positions, or may even be reused on the similar vertical place with cautious timing and a focus to TIA habits. Atari 2600 programming is a really deep matter, and it’s a protracted journey from bouncing ball demos to a high-quality recreation like Pitfall.
Atari 2600 Growth Right this moment
Wish to attempt your hand at writing some Atari recreation demos? Sure you do, and it’s a lot simpler immediately than it was in 1977. Begin with this Atari 2600 Programming for Newbies tutorial written by Andrew Davies. Software program is written in 6502 meeting language, and for those who’re studying this weblog, then there’s an excellent probability you already comprehend it. To assemble your software program, use DASM, a venerable and feature-filled cross-platform assembler for the 6502 and different 8-bit CPUs. If you happen to’ve acquired an actual Atari 2600 console, you possibly can write your assembled program’s binary picture to an EPROM and make your own game cartridge. If that feels like an excessive amount of trouble, attempt the Z26 or Stella software program emulators.
Did I butcher some technical rationalization right here, or omit vital particulars? Please let me know! I’m only a newbie on this Atari {hardware} journey, with a lot nonetheless to be taught. Search for my first 2600 recreation, coming quickly?