Post subject: Technical Question
Joined: 3/25/2004
Posts: 459
I thought of something a few months ago and then forgot about it until now... I was goofing off with a hex editor, seeing what I could change in my Zelda 1 file. I found the location for the ring. When I had no ring (value: 00) say I would lose life in one hit from a certain bad guy. Then when I changed it to 01, it would take two hits. Then 02, would be four hits. It keeps doubling. 02, the red ring, is the highest you could legally get in the game. But if you change it to FF, 255, that would be 2^255 hits. I imagine there is a counter for that, but since the highest value in the game would be four, they probably made it a small data type. Like an int, or short int. My question is, what if you changed the value to FF and then got hit more than 65,536, or whatever the highest value an int can hold is? Would it cause an overflow? Do you thing there's some kind of error handling that would take care of it? I never tried it, but I was just curious. I guess I could just put it on 999% speed and wait a while. Any guesses as to what would happen?
Joined: 4/11/2004
Posts: 155
Location: Fairfax, VA, USA
These games usually have next-to-nothing as far as error-handling goes. If you changed that number to an unexpected value, expect weird side-effects or even an outright crash. That said, programmers dont use 16-bit quantities on the NES unless they have a good reason. So I think whatever hit counter Zelda uses is going to be 8 bits. Meaning the most you could get away with is 2^7 or 2^6, depending on whether the counter is a signed or unsgned quantity -- you'd have to either look at the code or try a little experiment to find out. Zelda might not even use a "hit counter" however. It might internally store Link's health with a fractional component. Why not try changing the number to 3 and see what happens?
Active player (411)
Joined: 3/16/2004
Posts: 2623
Location: America, Québec
How about using a Game Genie instead :P
Joined: 3/25/2004
Posts: 459
When I changed the number to three it doubled again. 00 01 02 03 04 05 06 07 etc 1 2 4 8 16 32 64 128 etc What do you mean "internally store"? There has to be some way for the game to know that Link's "shield" value is decreasing. Either with a counter that counts up, or a counter that counts down. Or I'm stupid. Unfortunately I don't have the code to look at. With no error handling, we'd overflow the int and then what do you think would happen?
Joined: 4/11/2004
Posts: 155
Location: Fairfax, VA, USA
Ramzi wrote:
When I changed the number to three it doubled again.
That kind of rules out the fractional health hypothesis. Fractional health would work like this: Let's say link has five hearts. Internally, the game could store this number as 20, and before displaying it, divides by 4. The numbers 17-19 are the fractional values that lie between 4 and 5 hearts. For example 18 would be 4.5 hearts. If it's setting the "hit counter" using a bitshift, then any shift greater than 7 would just cause the number to become zero.
Joined: 3/25/2004
Posts: 459
Well, to store the 08 ring, it would need to hold up to 256, which is more than 8 bits. It would look like. 00000001 00000000. The counter, which is 8 bits, spills over when it goes past 255, so it essentially goes back to zero. It would also be 00000001 "00000000". However, it only compares to quoted section, because that's the area it was told to compare. Because of this, link is indestructible. But there's something I don't understand. How come it reads more than 8 bits for the ring? It too spills over, but it includes that new memory also. I would have thought that 00000001 00000000 would be treated just like when Link has no ring, because the original 8 bits that are supposed to be checked is zero. And that goes for 512, 1028, and everything past that. Unfortunately, the ring works as powers of two, so I can't make it so he needs to be hit 263 times, for example, before losing life. If I could though, it would look like: 00000001 00000111. 256 + 7 = 263. Do you think that after Link got hit 7 times, he would lose life? I don't, I think it looks at all bits holding the strength of the ring. I just don't get why it reads more than 8 bits for the ring strength, but it only reads 8 bits for the counter.
Former player
Joined: 3/19/2004
Posts: 710
Location: USA
I remember messing around with this game a while ago and I think it did do something similar to what Blip suggested. I have the values for all the items if you want them. I'll go see if I can find out exactly how the hearts are stored.
Joined: 3/25/2004
Posts: 459
I found where all the weapons are located in a savestate. Savestates are also different from emulator to emulator, but the processes should be the same. What do you hypothesize? That there's a number of health and it's multiplied by the ring strength, or what? Why do you become invincible after ring 08 then?
Joined: 4/25/2004
Posts: 498
I'm guessing because the amount of health the game thinks you lose is so small (between 0 and 1), it rounds it down to 0... =P
Player (206)
Joined: 5/29/2004
Posts: 5712
Rounding error STRIKES AGAIN!
put yourself in my rocketpack if that poochie is one outrageous dude