From 4581c366ed8ce53bec3daf47b5ae0e58f6704020 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Sun, 18 Feb 2024 13:59:29 +0100 Subject: [PATCH] Add a description of the VRAM memory map --- src/Memory_Map.md | 52 ++++++++++++++++++++++++++++++++++++++- src/imgs/src/vram_map.svg | 8 +++--- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/Memory_Map.md b/src/Memory_Map.md index 39e7b32d..9b7e98a3 100644 --- a/src/Memory_Map.md +++ b/src/Memory_Map.md @@ -37,11 +37,61 @@ $FF70 | | CGB | [WRAM Bank Select](<#FF70 — SVBK (CGB Mod ## VRAM memory map -TODO: descr +VRAM is, by itself, normal RAM, and may be used as such; however, the PPU interprets it in specific ways. + +Bank 1 does not exist except on CGB, where it can be switched to (only in CGB Mode) using [the `VBK` register](<#FF4F — VBK (CGB Mode only): VRAM bank>). + +Each bank first contains 384 tiles, of 16 bytes each. +These tiles are commonly thought of as grouped in three "blocks" of 128 tiles each; see [this detailed explanation](<#VRAM Tile Data>) for the relevance of the blocks. + +:::tip + +The ID of a tile can be obtained from its address using the following equation: +ID = address / 16 mod 256. + +This is equivalent to only looking at the address' middle two hexadecimal digits. + +::: + +After the tiles, each bank contains two maps, 32×32 (= 1024) bytes each. +The two banks are however different here: bank 0 contains [tile maps](<#VRAM Tile Maps>), while bank 1 contains the corresponding [attribute maps](<#BG Map Attributes (CGB Mode only)>). + +:::tip + +Each entry corresponds to a set of coordinates, linked to its address: + +- X = address mod 32 +- Y = address / 32 mod 32 + +In fact, the address of any entry can be thought of as a bitfield: + +{{#bits 16 > + "" 15:"1" 14:"0" 13:"0" 12:"1" 11:"1" 10:"tilemap" 9-5:"Y" 4-0:"X" +}} + +::: + +Here is a visualisation of how VRAM is laid out; hover over elements to see some details. + + {{#include imgs/src/vram_map.svg}} +:::tip + +The diagram is not to scale: each map takes up only half as much memory as a tile "block", despite the maps being visually twice as tall. + +::: + ## Jump Vectors in first ROM bank The following addresses are supposed to be used as jump vectors: diff --git a/src/imgs/src/vram_map.svg b/src/imgs/src/vram_map.svg index d1a38e5a..de9f47f5 100644 --- a/src/imgs/src/vram_map.svg +++ b/src/imgs/src/vram_map.svg @@ -150,13 +150,13 @@ - Tilemap 0 + Tile map 0 - Tilemap 1 + Tile map 1 - Attrmap 0 + Attr map 0 - Attrmap 1 + Attr map 1