Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2025-04-19 15:57:03

drev
Member
Registered: 2022-10-30
Posts: 10

Maximum size of an array in rom

I'm writing a GBDK Mario Land. (https://github.com/odrevet/marioland-gbdk)

Level data is generated from PNG files. the level arrays are quite large—about 4800 unsigned char per level.

However, levels 3-1, 4-1, 4-2, and 4-3 are larger. For example, level 3-1 is an array of 7040 unsigned char.

When a ROM is compiled with any of these "large levels," the game crashes. I don't understand why, as I am using a 8 banks cartridge,

ROM usage without level 3-1:

Bank    Range              Size     Used   Used%   Free   Free%
-----   ----------------  -------  ------  -----  ------  -----
ROM_0   0x0000 -> 0x3FFF   16384    15597    95%     787     5%
ROM_1   0x4000 -> 0x7FFF   16384    16289    99%      95     1%
ROM_2   0x4000 -> 0x7FFF   16384    16215    99%     169     1%
ROM_3   0x4000 -> 0x7FFF   16384    15863    97%     521     3%
ROM_4   0x4000 -> 0x7FFF   16384     1559    10%   14825    90%

ROM usage with level 3-1:

Bank    Range              Size     Used   Used%   Free   Free%
-----   ----------------  -------  ------  -----  ------  -----
ROM_0   0x0000 -> 0x3FFF   16384    15597    95%     787     5%
ROM_1   0x4000 -> 0x7FFF   16384    16375   100%       9     0%
ROM_2   0x4000 -> 0x7FFF   16384    16344   100%      40     0%
ROM_3   0x4000 -> 0x7FFF   16384    15959    97%     425     3%
ROM_4   0x4000 -> 0x7FFF   16384     8320    51%    8064    49%

their is still some free space when the level is added

Given that each bank is 16KB, shouldn’t the max size of a level array be 16,384 bytes?

So what is the actual maximum supported size for an arrayin ROM ?

The obvious fix is to split levels into multiple sub-level chunks or to compress the data. But out of curiosity, why does the game crash when a level is large? Is it really because of the level size that the game crashes ?

Offline

 

#2 2025-04-20 14:52:43

toxa
Member
Registered: 2020-02-13
Posts: 313

Re: Maximum size of an array in rom

the maximum array size in GBDK-2020 equals to 0xffff. but that does not mean you can DEFINE such constant array, because that is a whole SM83 address space. in practice, your constant arrays must fit 16384, or else you get errors while linking. speaking about your project, arrays look smaller than 16384, which is fine. it is unlikely, that arrays themselves are the source of your problem, more likely, some OTHER problem (likely with the bank switching) triggers when stuff is automatically tossed to the different banks. probably some of your code assumes that some asset is located in the same bank with the other asset, but they are not anymore, after adding levels.

the other problem with your code is enormous amount of warnings, fix them all. it is a good habit to fix warnings as if they were errors.

another suggestion is to use gbdk/* includes, rather than gb/* includes.

Offline

 

#3 2025-04-20 16:47:30

drev
Member
Registered: 2022-10-30
Posts: 10

Re: Maximum size of an array in rom

One again thanks for your response, the error was indeed having at some point the player related functions on autobank and then forgot about that sad
the crash ocurred because large levels were moving thinks around
At this point the levels are all loaded and I will fix warings and includes
BR

Offline

 

#4 2025-04-23 05:20:32

bbbbbr
Member
Registered: 2019-03-04
Posts: 130

Re: Maximum size of an array in rom

Cool project! Looking forward to hearing more about it as it progresses.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson