Programming the Atari 2600, and Me - Part 7

Please spread the word if you like this content!
Digg Button submit to reddit
 

The last post promised a discussion of collision detection.  Well, actually the last Atari-based post was regarding a portable Windows solution for 2600 development.  The Atari-centric post before that was a script for setting up a Linux-based 2600 development environment.  But before that, I'd promised collision detection, and now, here 'tis...

Collisions on the 2600 are extremely simple to conceptualize as well as handle.  A collision occurs when one object is drawn over another.  More specifically, when two objects have bits enabled on the same "pixel", you have a collision.  This distinction is important to make, actually, as two objects can easily sit on top of each other without throwing a collision flag.  Consider the diagrams below:

figure-1

figure-2

Notice in figure 1, the two players are shaped so that, when they are at the same location, none of their enabled bits overlap.  With a slight change to player 0 (figure 2), we should get a collision due to the two center pixels (the red squares).  The source code verifying this can be had here.

The Stella guide provides a diagram detailing the collision process (pg.34):

stella-collision-0

So basically, when two or more analog signals occur simultaneously during a scanning (scan)line, they will be “caught” by a series of AND gates, which feed through a multiplexer to their appropriate bits and collision address locations.  Per the Stella guide, two player objects, two missiles, the ball, and the playfield comprise fifteen different collision combinations, which are read (e.g. LDA) through data bits 6 and 7 (D6 and D7, or values 64 and 128, respectively) on (zeropage) addresses 00 through 07.  Below is the chart from the Stella guide showing this relationship.

stella-collision-1

Note, too, that more than one collision may be detected at a time.  Player 0 may be getting hit by Missile 1 the same frame Missile 0 hits Player 1, all while the Ball is colliding with the Playfield.  Per our chart above, we would check the D7 bit of CXM1P, CXM0P, and CXBLPF, respectively, to test for those collisions.  Again, refer to and play around with the source code previously mentioned above to get a feel for this.

Note, also, that the Stella guide recommends clearing the collision registers after doing your checks.  This is because the registers do not reset themselves, so if you are checking them, you’ll want to ensure the values are “fresh” collisions, and not the remainder of a rastering several frames ago.  This is simply accomplished via a call to CXCLR.

On that note, I leave with Smiley racing diagonally across the screen while a missile shoots the opposite direction which demonstrates our articles to this point, including collision.  Needless to say, catastrophic events happen when Smiley meets the missile, so be sure to build it to end your sleepless nights wondering what happens!  Next we’ll look at incorporating sound, and we also need to look at user input (e.g. joysticks and paddles).  We’ll then look at some algorithms to take care of common tasks, such as efficient horizontal placement of our objects, vertical drawing routines, keeping / writing a score, and anything else we can think of.

~ZagNut

Portable Atari 2600 Development, and Me...

Please spread the word if you like this content!
Digg Button submit to reddit
 

Greetings.

So, I use PortableApps on an external hard drive formatted with TrueCrypt.  It’s a tasty, secure setup.  As with any of my computers, I try to do a re-install maybe 2 – 3 times a year to keep things fresh-n-tasty.  Whenever I do this with this external drive, I inevitably go through an initial PortableApps frenzy, installing / creating a bunch of apps on my menu I end up never using.  This time, however, there is an exception…

atari2600devLadies and gentlemen, I present: the Portable Atari Programming System (with Machine Emulator and Archived References) (md5).  Or if you don’t like the PAPSMEAR acronym, Portable 2600 Dev will suffice, I guess.

Just extract the .zip to wherever you want and double-click the 2600.exe.  This is a simple .NET launcher for SciTE, which has been pared-down to just assembly stuff.  Compiling will build via DASM and launch in StellaMichal Kowalski’s 6502 emulator, the Stella Guide, and a pdf’ed 6502 reference I use frequently can be “launched” from within SciTE, as well (you’ll need to open an assembly file, first).

tools

You can get it here (md5):

~ZagNut

«January»
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345