Why does Super Mario Bros. Have 256 worlds??? Does the lost levels have 256 worlds as well?????

You can talk about almost anything that you want to on this board.

Moderator: Moderators

Post Reply
User avatar
So super
Posts: 12
Joined: Tue Sep 29, 2020 4:37 pm

Why does Super Mario Bros. Have 256 worlds??? Does the lost levels have 256 worlds as well?????

Post by So super »

Now, i really want to know because nobody ever explains it but, im gonna try.
A: Most likely in the code its told to copy levels over and over and extra stuff
B: they are very likely to just be junk data
C: data that has nothing to do with the levels are being used in the worlds beyond 8 then it checks the value and if its using junk data its possible it will or won't load
It seems like it will be C because thats how games get junk data usually to make broken non existing levels
What you think?
User avatar
Nikku4211
Posts: 569
Joined: Sun Dec 15, 2019 1:28 pm
Location: Florida
Contact:

Re: Why does Super Mario Bros. Have 256 worlds??? Does the lost levels have 256 worlds as well?????

Post by Nikku4211 »

I think it's B: they're all junk data.

Combined with the fact that the world number is probably stored in a single byte, which can have up to 256 values, and I think there's your answer.
I have an ASD, so empathy is not natural for me. If I hurt you, I apologise.
User avatar
So super
Posts: 12
Joined: Tue Sep 29, 2020 4:37 pm

Re: Why does Super Mario Bros. Have 256 worlds??? Does the lost levels have 256 worlds as well?????

Post by So super »

That is true because, when i found a txt file on romhacking.net they had a level guide i thought it was werid for them to be in 1 value (00) but then i made a hack that goes above world 1-4 on accident.
C was like B kinda but not really. Because, C was junk data that wasn't a level which of course crashes the game.
Now, i just need to experiment my self with the values and get players to start on world 0-1. World 0-1 is in super mario bros. On bad roms. Which is VERY common.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Why does Super Mario Bros. Have 256 worlds??? Does the lost levels have 256 worlds as well?????

Post by Oziphantom »

You seem to have stumbled in from a high level language with "bounds checking".

In ASM nobody knows how big a thing is, and hence you are free to go past the end as much as you like. However it is clipped to 256 because the level index is a single byte and 8bits gives you 256 values, so you have an array like so

LevelPtrs
lo .byte ...........
hi .byte ...........

And so you get the pointer as lo,x and hi,x and x can be 0-256. While you can read 256 numbers, they only intended you to be able to read as many that are valid, but there is nothing to stop you from doing a read that is invalid and just getting "whatever bytes just so happen to be in the ROM at the end of the table that was meant for something else" back.
User avatar
So super
Posts: 12
Joined: Tue Sep 29, 2020 4:37 pm

Re: Why does Super Mario Bros. Have 256 worlds??? Does the lost levels have 256 worlds as well?????

Post by So super »

Oziphantom wrote: Tue Feb 16, 2021 10:31 pm You seem to have stumbled in from a high level language with "bounds checking".

In ASM nobody knows how big a thing is, and hence you are free to go past the end as much as you like. However it is clipped to 256 because the level index is a single byte and 8bits gives you 256 values, so you have an array like so

LevelPtrs
lo .byte ...........
hi .byte ...........

And so you get the pointer as lo,x and hi,x and x can be 0-256. While you can read 256 numbers, they only intended you to be able to read as many that are valid, but there is nothing to stop you from doing a read that is invalid and just getting "whatever bytes just so happen to be in the ROM at the end of the table that was meant for something else" back.
So you can have a level like 0-0 or FF-FF but thats hundreds of worlds to discover. I wonder if anyone tried to restore them and make them non-junk data.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Why does Super Mario Bros. Have 256 worlds??? Does the lost levels have 256 worlds as well?????

Post by rainwarrior »

You can't restore them; they don't represent any kind of unused or incomplete content. They are just other bits of the game's code being incorrectly interpreted as level data.

You could make a ROMhack that creates 256 new worlds if you wanted, but the content would be coming from you, not anything that was originally planned for the game.
User avatar
So super
Posts: 12
Joined: Tue Sep 29, 2020 4:37 pm

Re: Why does Super Mario Bros. Have 256 worlds??? Does the lost levels have 256 worlds as well?????

Post by So super »

But, you can remake the layout if your lucky and not have it crash. And, make a functional w9-1
User avatar
Gilbert
Posts: 564
Joined: Sun Dec 12, 2010 10:27 pm
Location: Hong Kong
Contact:

Re: Why does Super Mario Bros. Have 256 worlds??? Does the lost levels have 256 worlds as well?????

Post by Gilbert »

Even though a level is functional does not mean it is not junk data. This can just be a coincidence.
AFAIK games like SMB use some compression for the level layouts, so that there is some restriction on how stuff are placed on a screen, i.e. the chance of having a passable game screen is not really that low compared to having a completely chaotic one.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Why does Super Mario Bros. Have 256 worlds??? Does the lost levels have 256 worlds as well?????

Post by Oziphantom »

you can't get FF-FF you only get one FF worth of which you have 4 maps per world.
So 3F-4 is as high as you could go. You would need to expand the ROM a lot though to get that far.
There is no 9-1. Just the code looks up level number / 4 = 9 and number % 4 = 0 + 1 = 1 and so it prints 9-1 and then there is data in the ROM at the point a 9-1 would be if it existed. But these are just factors of how it works. If it was a modern language and you tried to go to world 37 it would give you an out of bounds exception and crash.
User avatar
nesrocks
Posts: 563
Joined: Thu Aug 13, 2015 4:40 pm
Location: Rio de Janeiro - Brazil
Contact:

Re: Why does Super Mario Bros. Have 256 worlds??? Does the lost levels have 256 worlds as well?????

Post by nesrocks »

In layman terms: 256 is not the amount of levels, it is the amount of possible level addresses.
There are no more data for levels than the real game has. The addresses that don't point to real level data point to other sections of code from the ROM which have nothing to do with levels. It can be code for music, code for graphics, code for goomba's behaviors, etc.
https://twitter.com/bitinkstudios <- Follow me on twitter! Thanks!
https://www.patreon.com/bitinkstudios <- Support me on Patreon!
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Why does Super Mario Bros. Have 256 worlds??? Does the lost levels have 256 worlds as well?????

Post by Pokun »

Both B and C are kind of true, except that it doesn't check if the data is junk data or not. The bug causes the level generator routine to load code or other data and interpret it as level data even though it isn't, like everyone has been saying. Sometimes a junk level makes sense and partly looks like one of the real levels though. I guess that just means it stumbled upon some real level data. There are usually something that doesn't make sense though, like being able to swim in an overworld level, or cheep-cheep or bloopers swiming in mid-air. This bug inspired Nintendo to create fantasy world (world 9) in In SMB2j, which includes overworld levels with swimming. Flying bloopers are also part of the SMB2j enemies.
User avatar
So super
Posts: 12
Joined: Tue Sep 29, 2020 4:37 pm

Re: Why does Super Mario Bros. Have 256 worlds??? Does the lost levels have 256 worlds as well?????

Post by So super »

Oziphantom wrote: Wed Feb 17, 2021 3:39 am you can't get FF-FF you only get one FF worth of which you have 4 maps per world.
So 3F-4 is as high as you could go. You would need to expand the ROM a lot though to get that far.
There is no 9-1. Just the code looks up level number / 4 = 9 and number % 4 = 0 + 1 = 1 and so it prints 9-1 and then there is data in the ROM at the point a 9-1 would be if it existed. But these are just factors of how it works. If it was a modern language and you tried to go to world 37 it would give you an out of bounds exception and crash.
But, its actually possible to get 1-5 if you modified the level order in a certain way obviously its junk data.
User avatar
Yave Yu
Posts: 67
Joined: Sun Jan 19, 2014 6:15 pm

Re: Why does Super Mario Bros. Have 256 worlds??? Does the lost levels have 256 worlds as well?????

Post by Yave Yu »

Just read junk data as level, and surprisely works.
Same thing is use Notepad to open an NES file on PC.
User avatar
So super
Posts: 12
Joined: Tue Sep 29, 2020 4:37 pm

Re: Why does Super Mario Bros. Have 256 worlds??? Does the lost levels have 256 worlds as well?????

Post by So super »

Yave Yu wrote: Sun Feb 21, 2021 5:37 pm Just read junk data as level,
What do you mean by read as if its a level? Do you mean put it in the level order???
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Why does Super Mario Bros. Have 256 worlds??? Does the lost levels have 256 worlds as well?????

Post by Dwedit »

Here is how Super Mario Bros 1 level numbers work.

First the RAM variables used:
75C = Displayed number after the dash (Only used for display, and making world 5 harder once you reach 5-3)
75F = WorldNumber, 0 to 7. (1 is added to this number when it is displayed)
760 = AreaNumber, 0 to 4, or 0 to 3.

A world will have either 4 or 5 "areas".
Example: World 1 has five areas:
- 1-1
- 1-2 (pipe entry animation)
- 1-2 (actual level)
- 1-3
- 1-4

Because world 1-2, 2-2, 4-2, and 7-2 begin with an animation where Mario enters a pipe, those worlds have 5 areas instead of 4.

So now we have a World Number, and an Area Number.

-------------------------------

First there is a small table (8 bytes long) to find a 'Level List Index' for the level list.
The contents of the table begin with 0, then you add either 5 or 4 to the number, depending on whether there was a pipe transition level or not.
Values are 0, 5, 10, 14, 19, 23, 27, 33.

Then there is a level table for the 8 worlds. It lists all the level numbers of the game.
AreaAddrOffsets:
World1 (0) .db 0x25, 0x29, 0xc0, 0x26, 0x60
World2 (5) .db 0x28, 0x29, 0x01, 0x27, 0x62
World3 (10) .db 0x24, 0x35, 0x20, 0x63
World4 (14) .db 0x22, 0x29, 0x41, 0x2c, 0x61
World5 (19) .db 0x2a, 0x31, 0x26, 0x62
World6 (23) .db 0x2e, 0x23, 0x2d, 0x60
World7 (27) .db 0x33, 0x29, 0x01, 0x27, 0x64
World8 (33) .db 0x30, 0x32, 0x21, 0x65

From looking at the table we can see this:
Level 0x29 is the pipe transition level.
Level 0x26 appears as both World 1-3, and World 5-3.
Level 0x60 appears as both World 1-4, and World 6-4.
Level 0x01 appears as both World 2-2, and World 7-2.
Level 0x27 appears as both World 2-3, and World 7-3.
Level 0x62 appears as both World 2-4, and World 5-4.

Looking good so far, we have a table of valid world numbers, and valid level numbers.

-----------------------------

Now what happens if the world number is invalid?

It won't pick one of these 8 numbers: 0, 5, 10, 14, 19, 23, 27, 33
And instead, it will pick some other data as a starting number for level table.
Then it will load some out-of-range level number afterwards.
At this point, you're just getting random data from other parts of ROM being treated as a level number.

--------------------------------

Why do you get lots of variations of existing levels with the wrong world type?

It's in the level number itself. (Ignore the top bit for now, treat 80-FF as the same as 00-7F)
If the level number is between 00 and 1F, it's a water level.
If the level number is between 20 and 3F, it's an overworld level
If the level number is between 40 and 5F, it's an underground level
If the level number is between 60 and 7F, it's a castle level.

There are 3 valid water levels. (Water bonus area, 2-2, Bowser moat)
There are 21 valid overworld levels.
There are 3 valid underground levels. (1-2, 4-2, Bonus Areas)
There are 6 valid castles. (1-4, 2-4, 3-4, 4-4, 7-4, 8-4)

When you exceed level 3 (0x03+) for a water level, it proceeds to the overworld levels, then the underground levels, then the castle levels. (3-4 is the last possible level that would appear as a water level)
When you exceed level 21 (0x36+) for an overworld level, it proceeds to the underground levels, then the castle levels, then JUNK DATA
When you exceed level 3 (0x43+) for an underground level, it proceeds to the castle levels, then JUNK DATA
When you exceed level 6 (0x66+) for a castle level, you get JUNK DATA

So then...
0x00-0x02 = normal water levels
0x03-0x18 = underwater versions of overworld levels
0x19-0x1B = underwater versions of underground levels
0x1C-0x1F = underwater versions of castle levels
0x20-0x35 = normal overworld levels
0x36-0x38 = overworld versions of underground levels
0x39-0x3E = overworld versions of castle levels
0x3F = JUNK DATA (this one crashes)
0x40-0x42 = normal underground levels
0x43-0x48 = underground versions of castle levels
0x49-0x5F = JUNK DATA
0x60-0x65 = normal castles
0x66-0x7F = JUNK DATA

So out of 128 possible levels, 50 of them are complete JUNK DATA, and 78 of them will look like regular levels.

---------------------------------------

Examples of out-of-range worlds:

World Table is at 0x9CB4 in ROM.
Level Lists are at 0x9CBC in ROM.

You add the world number to 0x9CB4, read the byte, that tells you what the index for the first level is when you use the level list.
You add the index to 0x9CBC, read the byte, that tells you what level number to load.

Let's say you want to load World 9 (0x08)
Read from World Table 0x9CB4+0x08 (address 0x9CBC, value 0x25)
Read from Level Number Table 0x9CBC+0x25 (address 0x9CE1, value 0x06)
You are now in level 0x06, an underwater variation of an overworld level.

Or let's say world Z (0x22).
Read from World Table 0x9CB4+0x22 (address 0x9CD6, value 0x60)
Read from Level Number Table 0x9CBC+0x60 (address 0x9D1C, value 0x9F)
You are now in level 0x9F (same as 0x1F), an underwater variation of world 3-4.

------------------------------------

In short, reading out of bounds data does strange things. You aren't reading valid data anymore, you're just reading whatever happens to be in the ROM at that address.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
Post Reply