Posted March 22, 2025 by 8BitGlitch
##snes
While creating my game for the SNES, I encountered a problem with dynamically generating maps. Due to the limited amount of RAM in the console, I couldn't simply allocate a large array to store the entire map. I had to find a more memory-efficient solution.
ROM (Read-Only Memory) is a type of memory that stores game data on a SNES cartridge. Unlike RAM, the content of ROM doesn't change during the game. Thanks to this, I can store pre-prepared resources like graphics, sounds, and game levels in ROM and read them into RAM when needed. This is crucial because the SNES has very limited RAM (128 KB), while cartridges can have from 512 KB up to even 8 MB of ROM.
Each map consists of rooms with dimensions of 10x10. The rooms are pre-designed and stored in ROM. The key aspect of this approach is that all rooms have entrances and exits in the same positions. This allows me to connect them freely, creating dynamic maps.
Why did I choose rooms with dimensions of 10x10? With this division, I can create diverse layouts. Rooms can take various shapes — they can be classic large chambers, sets of smaller rooms, short corridors, or even small mazes. This modularity allows for generating more interesting, non-linear levels without consuming large amounts of memory.
The room layout scheme is currently quite simple. I just declare a two-dimensional array where I store room identifiers. However, to prevent the map from looking like a simple rectangle, I added a special type of room representing 'nothing' — a room with no entrances. This way, the map stops resembling a typical rectangle and gains a more organic shape.
If I tried to store the entire map in RAM, I would quickly run out of available memory. By saving predefined rooms in ROM and combining them randomly, I can create large, dynamic maps without occupying valuable RAM. This also makes it easy to add new rooms and increase level variety without increasing memory demand.
This approach has another advantage — I can create many interesting rooms myself, which will then be used randomly. Since each room takes up only 100 bytes, I can create a lot of them without worrying about technical limitations. If necessary, I could further reduce the room size. In its current form, a room consists of only two types of characters: ' ' (floor) and 'x' (wall). Nothing stops me from using 0s and 1s instead, which would allow storing a room as 8x8 bits, requiring only 8 bytes.
Thanks to this solution, I can create diverse maps without consuming a large amount of RAM, which is crucial for the SNES platform.