Author Topic: Atari 2600 Tomfoolery  (Read 19286 times)

FyberOptic

  • King of Earth
  • Administrator
  • Hero Member
  • *****
  • Posts: 2522
  • Oh god what is that?
    • Fybertech.com
Atari 2600 Tomfoolery
« on: August 07, 2008, 06:55:28 pm »
With RT trying to get into the top 10 high scores of Donkey Kong for Atari 2600 on some website the official world record site, I thought I'd try to see what kind of score I could manage.  So I went and got the newest Stella emulator and started messing around, and while trying to figure out keys, I accidently brought up the debugger.  And it's a pretty swanky one, at that!  So then I decided that I would just modify the high score in ram, and be HIGHEST DK SCORER AT FYBERTECH DOT CORN.  Because cheating electronically is how we win at Fybertech~!  I'll attach a picture, since it's the highest score you can get in the game.

Then I thought that maybe folks might be interested in the Donkey Kong guts, since there's a few things you can mess with, so I'll paste my findings here.  I may come back and update it with other things if I take a notion, since I knew what some things were doing but didn't document them yet.

Anyhoo, the part I was interested in primarily was the score.  The top score displayable in DK is "999900".  So 999,900 points.  Except the game doesn't really interpret it this way.  That's a pretty big number, in fact, and one that the processor in the Atari couldn't even handle natively (there's tricks if it's actually necessary, but in this case, it's not). 

The score is basically broken into three pieces:  [99][99][00].  The two 99's represent a pair of bytes in the Atari's 128 bytes of ram.  The 00 apparently isn't stored anywhere, since the score always comes in increments of 100 (which may have been intentional since it obviously saves them a byte of ram from not storing that third part). 

(INCOMING TECHNICAL PARAGRAPH)  The funny thing about how the score is displayed is that it's done based on the hex value of the byte in ram, not the decimal value.  You might think that in order to display a 99 in one of the score sections that you'd simply fill the associated ram byte with decimal "99" and it would render appropriately.  But if you put in a decimal 99, you'd see a 63 on the screen.  That's because it's displaying the hexadecimal value.  I believe that's because it can be quickly converted into a visual representation with some bit-shifting, since hex is base-16 and easier for a cpu to work with, where as decimal is base-10.  The thing is, you can't put a hex value into ram which contains a character; just the numerals.  0xFF for example would be bad and show up as garble.  So putting hex 0x99 into ram would indeed show up as "99" on the screen. 

Ram locations 0x87 and 0x88 change your total score.  They modify the first and middle sections, respectively (since as we've already covered, the final "00" apparently isn't stored anywhere). 

Other ram values of interest:

0xA4 - Change the current stage bonus (the value that counts down up top as you play a stage).  Works just like the total score in terms of how it displays, using the hex value.  This byte only changes the first two digits of what's displayed.  At the start of a stage, this byte will be 0x50, since the starting stage bonus is 5,000 points.  It can be set up to 0x99, hence a 9,900 bonus.

0xA3 - Changes how many lives you have left.  If you specify more than 3, the lives-remaining indicator will display incorrectly, as just a bunch of oddly-arranged blocks.

0x92 - Changes the screen background color


Stage 1

0xc4 = changes first barrel's X position
0x83 = changes first barrel's Y position


Stage 2 (Snake #1 is bottom-most, #4 is top)

0xc1 = Changes snake #1's X position
0xc2 = Changes snake #2's X position
0xc3 = Changes snake #3's X position
0xc4 = Changes snake #4's X position

0xc5 = Changes snake #1's movement direction (0 = left, 1 = right)
0xc6 = Changes snake #2's movement direction (0 = left, 1 = right)
0xc7 = Changes snake #3's movement direction (0 = left, 1 = right)
0xc8 = Changes snake #4's movement direction (0 = left, 1 = right)
« Last Edit: August 07, 2008, 08:01:48 pm by FyberOptic »

FyberOptic

  • King of Earth
  • Administrator
  • Hero Member
  • *****
  • Posts: 2522
  • Oh god what is that?
    • Fybertech.com
Re: Atari 2600 Tomfoolery
« Reply #1 on: August 23, 2008, 08:21:29 pm »
I just realized what that funky way of storing the score is.  It's call BCD, or "binary-coded decimal".  It's not used much in computers anymore, but was (and probably still is) used a lot in electronics.  It's handy for things like LCD displays in VCRs and whatnot, so that not only could you could pack more displayed digits into less storage space (two per byte), but also so that the values of the digits could be applied almost directly out into electronic components to the proper connections of an LED to light up the various parts of a numeral.

But yeah, I had heard of BCD, but never actually seen it implemented in anything.  While looking at assembly functions for the 8086 today I stumbled across some functions that handle BCD numbers, and in their explanation of what the functions did, I realized that that's what this was with the Atari..!