News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Understanding Super Mario Bros. graphics  (Read 2474 times)

NesDraug

  • RHDN Patreon Supporter!
  • Full Member
  • *****
  • Posts: 102
    • View Profile
Understanding Super Mario Bros. graphics
« on: January 11, 2019, 01:30:49 am »
I'm working on a SMB hack... http://www.romhacking.net/forum/index.php?topic=27628.0

...and I'm trying to understand why I can't have 9+ lives without this strange symbol showing up instead of a "1".


https://66.media.tumblr.com/d41528a2a995cc7ef97016a0dbd3db73/tumblr_pl5urm46KV1y1nex7o1_400.png

My question is: what does this do and can paint a 1 over it without messing up the game? It has to be graphics.


https://66.media.tumblr.com/7c6f5c21d47da4e2db393c6540552836/tumblr_pl5urm46KV1y1nex7o2_540.jpg
« Last Edit: January 11, 2019, 04:43:02 am by NesDraug »
Hello! You found my shop of strange and wonderful things!
https://www.tumblr.com/blog/nesdraug

Jorpho

  • Hero Member
  • *****
  • Posts: 4160
  • The cat screams with the voice of a man.
    • View Profile
Re: Understanding Super Mario Bros. graphics
« Reply #1 on: January 11, 2019, 02:39:57 am »
Are you aware that even unhacked SMB can't display more than 9 lives properly?  It is a very well-known bug.  People tend to call the strange symbol a "crown".

I'm sure I've seen a detailed explanation of exactly why this happens, but can't seem to find it at the moment.
This signature is an illusion and is a trap devised by Satan. Go ahead dauntlessly! Make rapid progres!

NesDraug

  • RHDN Patreon Supporter!
  • Full Member
  • *****
  • Posts: 102
    • View Profile
Re: Understanding Super Mario Bros. graphics
« Reply #2 on: January 11, 2019, 04:41:21 am »
Are you aware that even unhacked SMB can't display more than 9 lives properly?  It is a very well-known bug.  People tend to call the strange symbol a "crown".

I'm sure I've seen a detailed explanation of exactly why this happens, but can't seem to find it at the moment.

I wasn't aware. Guess I never got more than 10 lives. Well, I redrew that strange crown symbol into a “1″ but it was the wrong color so I had to change the HEX with FCEUX. 30 means white. Hopefully nothing else changed

Original:


New:


Result:
Hello! You found my shop of strange and wonderful things!
https://www.tumblr.com/blog/nesdraug

nesrocks

  • Hero Member
  • *****
  • Posts: 596
    • View Profile
    • nesrocks.com
Re: Understanding Super Mario Bros. graphics
« Reply #3 on: January 11, 2019, 07:47:02 am »
Smb is famous for not wasting graphics and code, so I would guess that yes, something else was changed. You should probably check it through.
Not to mention that if you get 20 lives it will probably show another garbage character. This would ideally be fixed in code, but there's not enough free space for this, so you'd have to remove some feature from the game or expand the rom.

Psyklax

  • Hero Member
  • *****
  • Posts: 1055
    • View Profile
    • Psyklax Translations
Re: Understanding Super Mario Bros. graphics
« Reply #4 on: January 11, 2019, 07:58:54 am »
Time for Uncle Psyklax to get out the old debugger and explain what's going on. :)

The routine that does this weird 'crown' thing is at $883C, and starts by loading the current amount of lives from $75A, then checking if it's more than ten. If not, no problem, just move on. But if it IS, then it loads $308 with 9F, and $309 with the lives minus ten.

So let's say you have 12 lives left. $75A has 0B (because the game uses one less than the actual number). The routine will add one to make twelve (0C) and notice that it's higher than ten (0A), whereby it subtracts 0A from it, leaving 02. it stores that to $309, and stores $9F to $308. Thus, we'll see a 'crown' and 2, to mean 12.

It would be simple to replace 9F with 01 (change $859 in the ROM), but then the palette is wrong on that tile. But also, what happens if you have over 19? You'll see a 'crown' with a letter.

This, plus the differing palette, makes something very clear: this is no bug. Although your lives can obviously go up to 255 before running over to zero, there's no way you can see it on the screen. Doing so would require a longer routine that subtracts ten, checks, subtracts ten, checks, and so on. Anyone why knows about SMB's inner workings is aware that there's next to no bytes left at all inside the ROM, so clearly the programmers decided "well, not many people are ever going to acquire more than nine lives anyway" (they obviously didn't know about the infinite shell kick thing) and did this quick and dirty routine as a compromise.

So, if I were you, I wouldn't bother fixing it, but if you really want to at least go up to 19, do this:

$7A6 - change BA to AA (fixes the palette)
$859 - change 9F to 01 (fixes the 'crown')

NesDraug

  • RHDN Patreon Supporter!
  • Full Member
  • *****
  • Posts: 102
    • View Profile
Re: Understanding Super Mario Bros. graphics
« Reply #5 on: January 11, 2019, 11:00:07 am »

$7A6 - change BA to AA (fixes the palette)
$859 - change 9F to 01 (fixes the 'crown')

Thank you! That's really helpful. It works great! And you're positive that it won't come with some nasty bugs? 

And another thing... What do you think of this:
It always bothered me that Mario’s feet shows when he enters a sideway pipe (if there’s nothing else covering it up). I simply took out a small portion of his feet. Problem solved! Should work?




Hello! You found my shop of strange and wonderful things!
https://www.tumblr.com/blog/nesdraug

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6905
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Understanding Super Mario Bros. graphics
« Reply #6 on: January 11, 2019, 12:40:44 pm »
Although your lives can obviously go up to 255 before running over to zero,
127, because SMB uses the sign bit to detect Game Over. The more famous bug (though probably only famous because of the infinite shell jump bug that can grant infinite lives). I don't know if SMAS fixed it but even then Nintendo themselves warned to not go over 100 lives to avoid it.
"My watch says 30 chickens" Google, 2018

Psyklax

  • Hero Member
  • *****
  • Posts: 1055
    • View Profile
    • Psyklax Translations
Re: Understanding Super Mario Bros. graphics
« Reply #7 on: January 11, 2019, 02:39:34 pm »
Thank you! That's really helpful. It works great! And you're positive that it won't come with some nasty bugs? 

If you just change those two bytes, nothing else should be affected. There's no logical reason why it should.

127, because SMB uses the sign bit to detect Game Over. The more famous bug (though probably only famous because of the infinite shell jump bug that can grant infinite lives). I don't know if SMAS fixed it but even then Nintendo themselves warned to not go over 100 lives to avoid it.

Ah, I didn't know that. I just assumed. Still, it's interesting that the coins can display to 99, so you'd think they could borrow the routine for the lives counter, but whatever, I guess they figured this was easier since what, really, are the chances (sans shell trick) of getting over 9 lives? You'd have to both never die and also collect lots of coins and the secret 1-ups as well. Not many people would be able to do it.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6905
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Understanding Super Mario Bros. graphics
« Reply #8 on: January 11, 2019, 06:08:55 pm »
I thought it was confirmed that the shell trick wasn't intentional, so yes, getting more than nine lives in a single game seemed unlikely (as I think there was generally only one 1-Up per world and most were one-time spawns with a certain condition).
"My watch says 30 chickens" Google, 2018

Eden.GT

  • Full Member
  • ***
  • Posts: 103
  • Hardcore SMB1 Player and Hacker
    • View Profile
Re: Understanding Super Mario Bros. graphics
« Reply #9 on: January 11, 2019, 11:40:01 pm »
I'm just going to dump this to you here- out of the bunch it contains a patch that changes the display of lives so that exceeding 9, it will be 10. It will correctly display the number of lives up to 99, in which it will proceed to A0, B0, and so on.

adjust_remain.ips
https://www.dropbox.com/s/8etf3dia6z7ktkl/100%2B%20IPS%20patches.zip?dl=0

I believe every sprite and enemy has been coded in SMB so that the very last bottom pixels will be stuck on the first pixels of solid BG tiles.
Is the pool clean?

NesDraug

  • RHDN Patreon Supporter!
  • Full Member
  • *****
  • Posts: 102
    • View Profile
Re: Understanding Super Mario Bros. graphics
« Reply #10 on: January 12, 2019, 05:06:21 am »
I'm just going to dump this to you here- out of the bunch it contains a patch that changes the display of lives so that exceeding 9, it will be 10. It will correctly display the number of lives up to 99, in which it will proceed to A0, B0, and so on.

adjust_remain.ips
https://www.dropbox.com/s/8etf3dia6z7ktkl/100%2B%20IPS%20patches.zip?dl=0

I believe every sprite and enemy has been coded in SMB so that the very last bottom pixels will be stuck on the first pixels of solid BG tiles.

Thank you so much! What a awesome collection of patches. My hack already had ATA's scroll patch when I got it from w7n so I think that is messing things up with some of these (Black hole and Break Bricks wont work for example). Anyways adjust_remain works. So thanks again! Now I'm inspired to do some other hacks with that Break Brick β! 
Hello! You found my shop of strange and wonderful things!
https://www.tumblr.com/blog/nesdraug

SaveState

  • Jr. Member
  • **
  • Posts: 15
  • I hack GBA, NES, and sometimes GBC
    • View Profile
    • SaveState's ROM Hacking Site
Re: Understanding Super Mario Bros. graphics
« Reply #11 on: March 08, 2019, 08:23:43 am »
Hey, about that infinite lives trick, I heard that the developers intentionally put that there because it only works with that certain background of the level and it was mentioned in some gaming magazines supported by Nintendo.

szemigi

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
Re: Understanding Super Mario Bros. graphics
« Reply #12 on: March 19, 2019, 10:40:00 am »
I'm just going to dump this to you here- out of the bunch it contains a patch that changes the display of lives so that exceeding 9, it will be 10. It will correctly display the number of lives up to 99, in which it will proceed to A0, B0, and so on.

adjust_remain.ips
https://www.dropbox.com/s/8etf3dia6z7ktkl/100%2B%20IPS%20patches.zip?dl=0

I believe every sprite and enemy has been coded in SMB so that the very last bottom pixels will be stuck on the first pixels of solid BG tiles.

Would be much better if it was written down, so that anybody, who wants work with the source code could understand it.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6905
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Understanding Super Mario Bros. graphics
« Reply #13 on: March 21, 2019, 08:09:06 pm »
Hey, about that infinite lives trick, I heard that the developers intentionally put that there because it only works with that certain background of the level and it was mentioned in some gaming magazines supported by Nintendo.
I really doubt it was intentional. Given that getting too many lives causes a Game Over, they'd have put a limit on it if they intended players to use. And given that even 10 lives causes a glitched counter, they probably were only intending players to get a few extra lives at most.
"My watch says 30 chickens" Google, 2018