The Banana Counter

Share ROM offsets and general DKC hacking documentation

The Banana Counter

Postby Kingizor » January 29th, 2011, 4:45 am

The "banana counter", is the counter at the top left of the screen which tells you the amount of bananas you have. By default, once you exceed 99 bananas, the counter resets to 0. This is an explanation of how the counter works (or how it seems to work), and how to alter the values it uses.

In DKC, the values are located at either end of this hex string:

63 00 30 24 AD 7B 05 38 E9 64 00 - USA & Europe
63 00 30 24 AD 8B 05 38 E9 64 00 - Japan

(Notice the Japanese version is slightly different, although this seems irrelevant)

Anyway, the important values are 63 00 and 64 00. If you've got any experience with hex digits, you'll have already noticed that these represent 99 and 100 respectively (The bytes are reversed, e.g. 6300 = 0063). The way the game handles these is as follows: 63 00 is the highest amount of bananas you can have, if you get any more, the second value is the amount deducted from the counter. So if you have 99 bananas, and you get one more, you have 100 taken away:

99 + 1 - 100 = 0

For the counter to return to 0 every time, the second value must be one value higher than the first. The counter doesn't have to reset to zero though, it can reset to any value higher than zero, but lower than the first value.

These values can, of course, be changed to whatever. Four bytes indicates that the highest value could be FFFF (65535), but the game won't allow anything higher than
E7 03 (999) for either value. This means by setting each value to the maximum (E6 03 & E7 03 respectively), you could collect 998 bananas, and when you collect one more the counter would reset to zero and you'd get your extra life. If either value is set higher, you will be able to get 999 bananas, but the counter will not go any higher.

It should go without saying, that setting either value to something outwith these limitations can and will cause all kinds of havoc. Remember the DKC beta video? Where you could collect hundreds of bananas? Well now you can do the same...

-------

DKC2 & DKC3 are different enough to make this whole thing a nightmare. In DKC2, it seems possible to set the values up to 999 as well, but the game uses very screwy values for bananas. DKC3 does not seem to be able to go beyond 99 bananas, and also uses the same screwy values that DKC2 uses.

The hex value for one banana seems to be 01, which makes perfect sense, but for 10 bananas, the hex value is 10 (it may not seem it, but this makes everything very confusing). Between 9 and 10 bananas, the A to F hex values seem to be skipped, so the hex goes from 9 straight to 10.

Confused? Good.
Jungle Explorer
Bananas received 57
Posts: 194
Joined: 2010

Re: The Banana Counter

Postby Simion32 » January 29th, 2011, 6:26 am

kingizor wrote:The hex value for one banana seems to be 01, which makes perfect sense, but for 10 bananas, the hex value is 10 (it may not seem it, but this makes everything very confusing). Between 9 and 10 bananas, the A to F hex values seem to be skipped, so the hex goes from 9 straight to 10.

That sounds like Binary-coded decimal numbers. No wonder it won't go above 99. There's not enough room for more than 99 given that encoding.

Essentially, the A-F have special meanings. Otherwise the digits are treated as regular decimal digits, but are coded in a hex format.

There is a "decimal" flag on the SNES processor, so I'd bet that flag defines whether to treat values as decimal digits.
Sage of Discovery
Bananas received 241
Posts: 2651
Joined: 2008

Re: The Banana Counter

Postby Kingizor » February 21st, 2011, 8:42 pm

I did, of course, manage to find the relevant strings for DKC2 and DKC3:

Spoiler!
99 00 8D 6D 09 D8 9C 6B 09 A9 01 00 22 4E C6 BE 80 2C 2C 6F 09 30 06 A9 3C 00 8D 6F 09 B0 0C A5 2A 29 03 00 D0 18 A9 99 99 80 0B AD 6B 09 C9 99 00 - U&J 1.0
99 00 8D 6D 09 D8 9C 6B 09 A9 01 00 22 59 C6 BE 80 2C 2C 6F 09 30 06 A9 3C 00 8D 6F 09 B0 0C A5 2A 29 03 00 D0 18 A9 99 99 80 0B AD 6B 09 C9 99 00 - U&J 1.1 & E
99 00 8D CD 18 D8 9C CB 18 A9 01 00 22 81 80 B8 80 2C 2C CF 18 30 06 A9 3C 00 8D CF 18 B0 0C A5 00 29 03 00 D0 18 A9 99 99 80 0B AD CB 18 C9 99 00 - USA
99 00 8D 53 19 D8 9C 51 19 A9 01 00 22 81 80 B8 80 2C 2C 55 19 30 06 A9 3C 00 8D 55 19 B0 0C A5 00 29 03 00 D0 18 A9 99 99 80 0B AD 51 19 C9 99 00 - Europe & Japan


These are the relevant strings for DKC2 and DKC3 respectively. The 99 00 at the start is the amount that will be deducted when the second amount is exceeded. The second 99 00 is the amount of bananas you have before the counter flips over and you get your extra life.

The only thing that makes this slightly more awkward is the first value; it is actually one higher than it appears to be - 99 00 is actually 100.

By setting these values higher than 99 00 (e.g. 99 09), it is again possible to exceed 100 bananas in game. I can only assume that the highest acceptable value would again be 999. Another problem, is that while you can collect hundreds of bananas, whenever you leave a level or enter a bonus, the counter that you see "resets" to 109. So for instance, if you collect 200 bananas in a level, then exit the level, then re-enter the level, the counter will show you as having 109 bananas. I haven't confirmed this, but I'm quite sure your total and what is displayed are stored separately, so while the game says you only have 109, you still have whatever amount you had. Believe me when I say this is f**king annoying.
Jungle Explorer
Bananas received 57
Posts: 194
Joined: 2010


Re: The Banana Counter

Postby Kingizor » September 25th, 2017, 8:23 am

I didn't have much finesse in those days. If memory serves, I found these values by modifying every instance of 6400 in the ROM one at a time and checking the results. :oops:

More experienced eyes identify the hex snippet as a code segment.

Code: Select all
?? 60 00 - SBC #$6300 (Probably SBC)
30 24    - BMI +$24
AD 7B 05 - LDA $057B
E9 64 00 - SBC #$6400
...

It looks like the first subtraction checks if the banana counter is greater than or equal to 99, in which case the BMI won't fire and 100 is subtracted from the total.

Code: Select all
if (banana_counter >= 99) {
  banana_counter -= 100;
}

Can't say for sure what's going on after that final subtraction from just this though. :p

The snippet or at least my interpretation of it thus far suggests the Japanese version reads the counter from $058B while others read from $057B.

I don't know anything about how or if $0529 is used. The game might use one address as the "main" counter while the others are temporary for specific routines for instance.

There might be a post somewhere describing the counter in more detail, or maybe I'm imagining that. :?
Jungle Explorer
Bananas received 57
Posts: 194
Joined: 2010

Re: The Banana Counter

Postby rainbowsprinklez » September 26th, 2017, 3:34 am

It seems as if you are right. I apologize :oops: $0529 seems to be bananas, but the code doesnt use it except to match it to $057B... It might be used for display purposes? Which is odd, but it makes sense. Lives do the same thing. Whereas dkc2 they use 1 address for both. It's cool to see how they've learned!

It seemed sure to me because bananas graphical digits start at $052B, so $0529 (a 2 byte value) made sense there. But I guess it only made sense because it was a duplicate :?
Jungle Explorer
Bananas received 11
Posts: 187
Joined: 2016


Return to Documentation

Who is online

Users browsing this forum: No registered users and 1 guest