Hardware and Memory - TypeDefinition/NautiBuoy GitHub Wiki
Specs
Info | |
---|---|
CPU | 4mHz |
RAM | 8kb |
VRAM | 8kb |
Screen Resolution | 160 pixels x 144 pixels |
Screen buffer (background) | 256 pixels x 256 pixels (32 x 32 tiles) |
Tile size | 8 pixels x 8 pixels |
Sprite size | 8 pixels x 8 pixels or 8 pixels x 16 pixels |
Max Tile Patterns | 256 tiles |
Max Sprite Patterns | 256 tiles |
Max Sprites on screen | 40 (max 10 in 1 line) |
Total Colors | 4 |
Please note, that the term tiles and sprites are a little different. We'll go into that later.
Gameboy Memory Layout
Memory address | Name | Description | Physical location |
---|---|---|---|
$0000 - $00FF | Bootstrap ROM* | This is part of the 16kb ROM BANK 0, space is reserved for the Boot ROM. | CPU of Gameboy |
$0000 - $3FFF | ROM Bank 0 (ROM0) | 16kb ROM BANK 0. Read-only. Our codes generally go here. | Cartridge |
$4000 - $7FFF | ROM Bank 1 - n (ROMX) | 16kb ROM BANKX. Read-only. Our codes generally go here. | Cartridge |
$8000 - $9FFF | Video RAM (VRAM) | 8kb of VRAM. Hold patterns for tiles and sprites to show on the screen. | Built into Gameboy |
$A000 - $BFFF | External RAM (SRAM) | 8kb of external RAM. Store game saves. | Cartridge |
$C000 - $DFFF | Work RAM (WRAM) | 8kb, able to read and write into it. | Built into Gameboy |
$E000 - $FDFF | Echo Work RAM | 8kb, just a mirror of WRAM, use unknown. | Built into Gameboy |
$FE00 - $FE9F | Sprite attribute table (OAM RAM) | 160b, stores sprites data such as rendering pos, flags eg. | Gameboy? |
$FF00 - $FF7F | I/O Registers | Registers to deal with input/output like buttons eg. | Gameboy? |
$FF80 - $FFFE | High RAM (HRAM) | Smaller than WRAM, but faster. Can be written and read. | Gameboy? |
$FFFF | Interrupt register | Just takes note of which interrupts to enable. | Gameboy? |
Boot ROM: 256B of instructions built into the CPU of the Game Boy. Used to initialise the console and compare the Nintendo logo in the Boot ROM to the Nintendo logo in the cartridge for copyright and legal reasons. During boot-up, this area is reserved for the Boot ROM located in the Game Boy's CPU. After boot-up, the normal memory in ROM is then loaded in. More info
ROM Bank 0 (ROM0): 16KB of memory located on the cartridge. This is where the header and game code goes. However, since memory addresses $0000 - $00FF are reserved for the Boot ROM, we cannot use those. So we actually only have 16KB - 256B worth of usable memory. ROM0 is always accessible
ROM Bank 1 - n (ROMX):
ROMX is where the banks are. 16KB of memory located on the cartridge. This is where the game code goes. Larger games may be greater than 32KB, but the 8-bit CPU can only address up to 64KB of memory. To get around this, it is possible to map this 32KB of the memory address to different sections of the cartridge’s memory. For example, if we have a larger game that takes up 128KB, we cannot access all 128KB at the same time, but we can access 16KB - 256B in ROM0, and another swappable 16KB in ROMX. To switch banks, we init the bank value to [$2000].
ld [$2000], 1 ; go to bank 1
Echo Work RAM: A copy of the Work RAM located at $E000 - $FDFF. Any data in the Work RAM will be copied into this area and vice versa. Its purpose is unknown. Game programmers should NOT use these memory addresses. Eg. If I write something in $C000 (starting address of WRAM), that data is going to be in $E000 (starting address of Echo WRAM) too.
HRAM vs WRAM vs ROM:
- ROM is read-only memory, suited for codes or variables that are just for reading like storing the tilemap data, sprite data eg.
- HRAM and WRAM, can be written to.
- HRAM is smaller than WRAM but a lot faster, good for storing variables that are called in numerous places in the code.
- Typically try placing variables in WRAM by default and move them to HRAM if there's a significant improvement.
- Also during DMA transfer (transfer data to OAM), the CPU can only access HRAM.
Video Memory (VRAM):
- 8kb, $8000 - $9FFF
- Hold data on tiles and sprites patterns that are used to be constructed for the graphics shown on screen.
- Also holds data to tell the Gameboy how to draw and where to the tiles on the background (draw the map eg.)
- Can only be accessed (written and read) during VBLANK or HBLANK.
- 4kb for Sprite tiles, 4kb for BG tiles (overlaps with the sprite tiles), 1kb for background map, 1kb for window map
- More info on the graphics page of the wiki
References for memory layout and more info:
- https://gbdev.gg8.se/wiki/articles/Memory_Map
- http://hisimon.dk/misc/pandocs/
- http://marc.rawer.de/Gameboy/Docs/GBCPUman.pdf
- Ultimate Gameboy talk
- Gameboy Hardware autosopy part 2, memory map
CPU Architecture
Processor:
- 8-bit processor, thus, can generally only process 8 bit at once
- 8-bit data bus can only transfer data 8-bit at a time, so numbers 0 - 255
- 16-bit address bus, so memory address can go from 0 - 65535 or 64kb
- 8-bit accumulator, most operations like addition, subtraction eg, will go through the accumulator, which only register a can handle
- 16-bit stack, the stack stores 16-bit numbers
- Registers A-F are 8-bit, can store and load 8-bit numbers. Can also combine registers (AF, BC, DE, HL) to make it 16 bits.