HiROM memory mapping mode with 64KB bank access. More...
Macros | |
| #define | FONT_SIZE (11 * 16) |
| Total font data size in bytes (11 characters x 16 bytes per 2bpp tile) | |
| #define | TILE_B 9 |
| #define | TILE_D 6 |
| #define | TILE_E 7 |
| #define | TILE_H 1 |
| #define | TILE_I 2 |
| #define | TILE_L 8 |
| #define | TILE_M 5 |
| #define | TILE_O 4 |
| #define | TILE_PLUS 10 |
| #define | TILE_R 3 |
| #define | TILE_SPACE 0 |
| Tile index for space (blank tile) | |
| #define | TILEMAP_ADDR 0x0400 |
| VRAM word address for the BG1 tilemap (32x32 = 2KB) | |
| #define | TILES_ADDR 0x0000 |
| VRAM word address for the tile character data. | |
Functions | |
| static void | clear_tilemap (void) |
| Clear the entire BG1 tilemap to blank (space) tiles. | |
| int | main (void) |
| Main entry point – HiROM mode validation demo. | |
| static void | write_tile (u8 x, u8 y, u8 tile) |
| Write a single tile entry to the BG1 tilemap via direct VRAM registers. | |
Variables | |
| static const u8 | font_tiles [] |
| Inline 2bpp font tile data (11 characters, 16 bytes per tile). | |
| static const u8 | init_palette [] |
| Initial 2-color palette (dark blue background, white text). | |
HiROM memory mapping mode with 64KB bank access.
Demonstrates building an OpenSNES ROM in HiROM mode, where each ROM bank provides 64KB of contiguous address space ($0000-$FFFF) instead of LoROM's 32KB ($8000-$FFFF). HiROM is selected by setting USE_HIROM := 1 in the Makefile, which switches the ROM header, memory map, and linker configuration.
HiROM is preferred for games with large contiguous data (streaming tilesets, large lookup tables) because it avoids the 32KB bank boundary that LoROM imposes. The tradeoff is that mirror-region access patterns differ, and some addressing modes behave differently.
This example uses inline 2bpp font tiles (no external assets) and direct VRAM register writes to display text, confirming that the library, ROM header, and memory map are all correctly configured for HiROM operation. Pressing A changes the background color as a simple input validation.
| #define FONT_SIZE (11 * 16) |
Total font data size in bytes (11 characters x 16 bytes per 2bpp tile)
| #define TILE_B 9 |
Tile index for letter B
| #define TILE_D 6 |
Tile index for letter D
| #define TILE_E 7 |
Tile index for letter E
| #define TILE_H 1 |
Tile index for letter H
| #define TILE_I 2 |
Tile index for letter I
| #define TILE_L 8 |
Tile index for letter L
| #define TILE_M 5 |
Tile index for letter M
| #define TILE_O 4 |
Tile index for letter O
| #define TILE_PLUS 10 |
Tile index for plus sign (+)
| #define TILE_R 3 |
Tile index for letter R
| #define TILE_SPACE 0 |
Tile index for space (blank tile)
| #define TILEMAP_ADDR 0x0400 |
VRAM word address for the BG1 tilemap (32x32 = 2KB)
| #define TILES_ADDR 0x0000 |
VRAM word address for the tile character data.
|
static |
Clear the entire BG1 tilemap to blank (space) tiles.
Writes 1024 tilemap entries (32x32) with tile index 0 (space) and zero attributes. Must be called during force blank or VBlank.
| int main | ( | void | ) |
Main entry point – HiROM mode validation demo.
Verifies that the HiROM memory map, ROM header, and library all work correctly by displaying text and responding to input. The display is set up with inline 2bpp font tiles written directly to VRAM registers, proving that code and data addresses resolve properly in HiROM's 64KB-per-bank layout.
Holding the A button changes the backdrop color as a simple demonstration that the library's input system works in HiROM mode.
< Tile index for letter H
< Tile index for letter I
< Tile index for letter R
< Tile index for letter O
< Tile index for letter M
< Tile index for letter M
< Tile index for letter O
< Tile index for letter D
< Tile index for letter E
< Tile index for plus sign (+)
< Tile index for letter L
< Tile index for letter I
< Tile index for letter B
Write a single tile entry to the BG1 tilemap via direct VRAM registers.
Sets the VRAM address to the tilemap position (row * 32 + column) and writes the tile index as a 16-bit tilemap entry (low = tile number, high = attributes). VRAM writes only succeed during VBlank or forced blank – calling this during active display will silently fail.
| x | Column position in the 32-wide tilemap (0-31) |
| y | Row position in the 32-tall tilemap (0-31) |
| tile | Tile character index to write |
|
static |
Inline 2bpp font tile data (11 characters, 16 bytes per tile).
Each 2bpp tile is 8x8 pixels stored as 16 bytes: 8 rows of 2 bytes each (one byte per bitplane). Only 2 colors are used: color 0 (transparent/background) and color 1 (text). This avoids needing an external font asset file – the entire character set is embedded in the C source.
|
static |
Initial 2-color palette (dark blue background, white text).
SNES CGRAM stores BGR555 colors as 2 bytes each (little-endian). Color 0 = backdrop (dark blue), Color 1 = text foreground (white).