Difference between revisions of "Memory Map"

From GbdevWiki
Jump to: navigation, search
(Created page with 'The gameboy is having a 16bit address bus, that is used to address ROM, RAM, and I/O registers. == General Memory Map == 0000-3FFF 16KB ROM Bank 00 (in cartridge, fixed …')
 
($0000-$3FFF is only usually fixed. MBC1M and Wisdom Tree regularly switch it.)
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
The gameboy is having a 16bit address bus, that is used to address ROM, RAM, and I/O registers.
+
The gameboy has a 16bit address bus, that is used to address [[ROM]], [[RAM]], and [[I/O registers]].
  
 
== General Memory Map ==
 
== General Memory Map ==
  0000-3FFF   16KB ROM Bank 00     (in cartridge, fixed at bank 00)
+
{| cellpadding="2" cellspacing="0" border="1"
  4000-7FFF   16KB ROM Bank 01..NN (in cartridge, switchable bank number)
+
|'''Start'''
  8000-9FFF   8KB Video RAM (VRAM) (switchable bank 0-1 in CGB Mode)
+
|'''End'''
  A000-BFFF   8KB External RAM     (in cartridge, switchable bank, if any)
+
|'''Description'''
  C000-CFFF   4KB Work RAM Bank 0 (WRAM)
+
|'''Notes'''
  D000-DFFF   4KB Work RAM Bank 1 (WRAM) (switchable bank 1-7 in CGB Mode)
+
|-
  E000-FDFF   Same as C000-DDFF (ECHO)   (typically not used)
+
|0000
  FE00-FE9F   Sprite Attribute Table (OAM)
+
|3FFF
  FEA0-FEFF   Not Usable
+
|16KB ROM bank 00
  FF00-FF7F   I/O Ports
+
|From cartridge, usually a fixed bank
  FF80-FFFE   High RAM (HRAM)
+
|-
  FFFF       Interrupt Enable Register
+
|4000
 +
|7FFF
 +
|16KB ROM Bank 01~NN  
 +
|From cartridge, switchable bank via [[Memory_Bank_Controllers|MBC]] (if any)
 +
|-
 +
|8000
 +
|9FFF
 +
|8KB Video RAM (VRAM)
 +
|Only bank 0 in Non-CGB mode
 +
Switchable bank 0/1 in CGB mode
 +
|-
 +
|A000
 +
|BFFF
 +
|8KB External RAM
 +
|In cartridge, switchable bank if any
 +
|-
 +
|C000
 +
|CFFF
 +
|4KB Work RAM (WRAM) bank 0
 +
|
 +
|-
 +
|D000
 +
|DFFF
 +
|4KB Work RAM (WRAM) bank 1~N
 +
|Only bank 1 in Non-CGB mode
 +
Switchable bank 1~7 in CGB mode
 +
|-
 +
|E000
 +
|FDFF
 +
|Mirror of C000~DDFF (ECHO RAM)
 +
|Typically not used
 +
|-
 +
|FE00
 +
|FE9F
 +
|Sprite attribute table ([[Video_Display#VRAM_Sprite_Attribute_Table_.28OAM.29|OAM]])
 +
|
 +
|-
 +
|FEA0
 +
|FEFF
 +
|Not Usable
 +
|
 +
|-
 +
|FF00
 +
|FF7F
 +
|I/O Registers
 +
|
 +
|-
 +
|FF80
 +
|FFFE
 +
|High RAM (HRAM)
 +
|
 +
|-
 +
|FFFF
 +
|FFFF
 +
|[[Interrupts]] Enable Register (IE)
 +
|
 +
|}
  
== Jump Vectors in First ROM Bank ==
+
== Jump Vectors in first ROM bank ==
 
The following addresses are supposed to be used as jump vectors:
 
The following addresses are supposed to be used as jump vectors:
  0000,0008,0010,0018,0020,0028,0030,0038   for RST commands
+
*RST commands: 0000,0008,0010,0018,0020,0028,0030,0038
  0040,0048,0050,0058,0060                 for Interrupts
+
*Interrupts: 0040,0048,0050,0058,0060
However, the memory may be used for any other purpose in case that your program doesn't use any (or only some) RST commands or Interrupts. RST commands are 1-byte opcodes that work similiar to CALL opcodes, except that the destination address is fixed.
+
However, the memory may be used for any other purpose in case that your program doesn't use any (or only some) RST commands or interrupts. RST commands are 1-byte opcodes that work similar to CALL opcodes, except that the destination address is fixed. Since they are only 1 byte large, they are also slightly faster.
  
== Cartridge Header in First ROM Bank ==
+
== Cartridge Header in first ROM bank ==
 
The memory at 0100-014F contains the [[The Cartridge Header|cartridge header]]. This area contains information about the program, its entry point, checksums, information about the used MBC chip, the ROM and RAM sizes, etc. Most of the bytes in this area are required to be specified correctly. For more information read the chapter about The Cartridge Header.
 
The memory at 0100-014F contains the [[The Cartridge Header|cartridge header]]. This area contains information about the program, its entry point, checksums, information about the used MBC chip, the ROM and RAM sizes, etc. Most of the bytes in this area are required to be specified correctly. For more information read the chapter about The Cartridge Header.
  
 
== External Memory and Hardware ==
 
== External Memory and Hardware ==
The areas from 0000-7FFF and A000-BFFF may be used to connect external hardware. The first area is typically used to address ROM (read only, of course), cartridges with [[Memory Bank Controllers|Memory Bank Controllers (MBCs)]] are additionally using this area to output data (write only) to the MBC chip. The second area is often used to address external RAM, or to address other external hardware (Real Time Clock, etc). External memory is often battery buffered, and may hold saved game positions and high score tables (etc.) even when the gameboy is turned of, or when the cartridge is removed. For specific information read the chapter about Memory Bank Controllers.
+
The areas from 0000-7FFF and A000-BFFF may be used to connect external hardware. The first area is typically used to address ROM (read only, of course), cartridges with [[Memory Bank Controllers|Memory Bank Controllers (MBCs)]] are additionally using this area to output data (write only) to the MBC chip. The second area is often used to address external RAM, or to address other external hardware ([[RTC|Real Time Clock]], etc). External memory is often battery buffered, and may hold saved game positions and high score tables (etc.) even when the Game Boy is turned off, or when the cartridge is removed. For specific information read the chapter about Memory Bank Controllers.
 +
 
 +
== Echo RAM ==
 +
The memory range E000-FDFF is a mirror (or "echo") of WRAM, both for reading and writing. For example, writing to $E123 will modify both $C123 and $E123. It is recommended to avoid using this memory range anyways.
 +
This memory range's behavior has been confirmed on all grey GBs as well as on CGB and GBA. Some emulators (such as VisualBoyAdvance <1.8) don't emulate Echo RAM. It is possible to check if Echo RAM is properly emulated by writing to WRAM (avoid values 00 and FF) and checking if said value is mirrored in Echo RAM.
 +
 
 +
== FEA0-FEFF range ==
 +
This range is very poorly documented. It doesn't even have a name ! From my experience, this stays 00 on DMG, and alternates between 00 and seemingly random values on CGB.

Latest revision as of 15:47, 8 July 2019

The gameboy has a 16bit address bus, that is used to address ROM, RAM, and I/O registers.

General Memory Map

Start End Description Notes
0000 3FFF 16KB ROM bank 00 From cartridge, usually a fixed bank
4000 7FFF 16KB ROM Bank 01~NN From cartridge, switchable bank via MBC (if any)
8000 9FFF 8KB Video RAM (VRAM) Only bank 0 in Non-CGB mode

Switchable bank 0/1 in CGB mode

A000 BFFF 8KB External RAM In cartridge, switchable bank if any
C000 CFFF 4KB Work RAM (WRAM) bank 0
D000 DFFF 4KB Work RAM (WRAM) bank 1~N Only bank 1 in Non-CGB mode

Switchable bank 1~7 in CGB mode

E000 FDFF Mirror of C000~DDFF (ECHO RAM) Typically not used
FE00 FE9F Sprite attribute table (OAM)
FEA0 FEFF Not Usable
FF00 FF7F I/O Registers
FF80 FFFE High RAM (HRAM)
FFFF FFFF Interrupts Enable Register (IE)

Jump Vectors in first ROM bank

The following addresses are supposed to be used as jump vectors:

  • RST commands: 0000,0008,0010,0018,0020,0028,0030,0038
  • Interrupts: 0040,0048,0050,0058,0060

However, the memory may be used for any other purpose in case that your program doesn't use any (or only some) RST commands or interrupts. RST commands are 1-byte opcodes that work similar to CALL opcodes, except that the destination address is fixed. Since they are only 1 byte large, they are also slightly faster.

Cartridge Header in first ROM bank

The memory at 0100-014F contains the cartridge header. This area contains information about the program, its entry point, checksums, information about the used MBC chip, the ROM and RAM sizes, etc. Most of the bytes in this area are required to be specified correctly. For more information read the chapter about The Cartridge Header.

External Memory and Hardware

The areas from 0000-7FFF and A000-BFFF may be used to connect external hardware. The first area is typically used to address ROM (read only, of course), cartridges with Memory Bank Controllers (MBCs) are additionally using this area to output data (write only) to the MBC chip. The second area is often used to address external RAM, or to address other external hardware (Real Time Clock, etc). External memory is often battery buffered, and may hold saved game positions and high score tables (etc.) even when the Game Boy is turned off, or when the cartridge is removed. For specific information read the chapter about Memory Bank Controllers.

Echo RAM

The memory range E000-FDFF is a mirror (or "echo") of WRAM, both for reading and writing. For example, writing to $E123 will modify both $C123 and $E123. It is recommended to avoid using this memory range anyways. This memory range's behavior has been confirmed on all grey GBs as well as on CGB and GBA. Some emulators (such as VisualBoyAdvance <1.8) don't emulate Echo RAM. It is possible to check if Echo RAM is properly emulated by writing to WRAM (avoid values 00 and FF) and checking if said value is mirrored in Echo RAM.

FEA0-FEFF range

This range is very poorly documented. It doesn't even have a name ! From my experience, this stays 00 on DMG, and alternates between 00 and seemingly random values on CGB.