# Memory maps, memory control and timing Source: GBATEK "DS Memory Maps", "DS Memory Control" (WRAM, VRAM, BIOS, Cartridges and Main RAM), "DS Main Memory Control", "DS Memory Timings". Tagged DOC unless marked. ## The two CPUs' maps | Address | ARM9 (arm946es-python core) | ARM7 (arm7tdmi-python core) | | --- | --- | --- | | 00000000h | ITCM, 32 KB, mirrored over the virtual size (the core's, not the board's) | ARM7 BIOS, 16 KB (read-protected, below) | | (movable) | DTCM, 16 KB (the core's) | | | 02000000h | main RAM, 4 MB (8 MB on debug units), mirrored to 02FFFFFFh | main RAM, same memory | | 03000000h | shared WRAM: 0, 16 or 32 KB by WRAMCNT, mirrored over 03000000h-03FFFFFFh; empty when 0 KB | shared WRAM 0/16/32 KB in 03000000h-037FFFFFh; when 0 KB the ARM7's own WRAM shows there | | 03800000h | (part of the WRAM area above) | ARM7 WRAM, 64 KB, mirrored | | 04000000h | ARM9 I/O | ARM7 I/O | | 04100000h | IPCFIFORECV, cartridge data in (40100010h) | same | | 04800000h | | wireless: 8 KB RAM at 04804000h, registers at 04808000h (two wait-state mirrors) | | 05000000h | palettes, 2 KB (engine A BG/OBJ, engine B BG/OBJ) | | | 06000000h | VRAM by bank mapping: engine A BG (max 512 KB), 06200000h engine B BG (128 KB), 06400000h engine A OBJ (256 KB), 06600000h engine B OBJ (128 KB), 06800000h "LCDC" (plain CPU, all 656 KB) | VRAM C and/or D as ARM7 WRAM (max 256 KB) | | 07000000h | OAM, 2 KB (engine A 1 KB, engine B 1 KB) | | | 08000000h | GBA slot ROM (32 MB), 0A000000h GBA slot RAM (64 KB) | same; one CPU owns the slot (EXMEMCNT bit 7) | | FFFF0000h | ARM9 BIOS, 4 KB used of 32 KB, unprotected | | Not on either bus: 3D polygon RAM (2 x 52 KB) and vertex RAM (2 x 72 KB), the firmware flash (SPI), the GBA BIOS (GBA mode only), the DS cartridge ROM and save (serial). Unmapped 16 MB blocks are undefined; blocks with memory mirror it in their unused upper part, except TCM and BIOS. Undefined ARM9 I/O reads 0. 8-bit writes to VRAM, palette and OAM are ignored, except ARM7 VRAM (so GBA mode can use VRAM as its 256 KB WRAM). ## WRAMCNT (ARM9 4000247h, read on the ARM7 as WRAMSTAT 4000241h) | Value | ARM9 gets | ARM7 gets | | --- | --- | --- | | 0 | 32 KB | 0 (its 64 KB WRAM shows instead) | | 1 | second 16 KB | first 16 KB | | 2 | first 16 KB | second 16 KB | | 3 | 0 (undefined data) | 32 KB | ## VRAM banks (VRAMCNT_A..I, ARM9 4000240h-4000249h) Nine banks, A-D 128 KB, E 64 KB, F and G 16 KB, H 32 KB, I 16 KB (656 KB). Each has an enable bit, a 3-bit MST (what it is: LCDC, engine A BG or OBJ, extended palettes, texture image, texture palette, engine B BG or OBJ, ARM7 WRAM) and a 2-bit offset; the full table is GBATEK "DS Memory Control - VRAM" (to be transcribed as data in the build). In extended-palette and texture modes a bank is invisible to the CPUs. VRAMSTAT (ARM7 4000240h) says whether C and D are the ARM7's. **Overlapping mappings** (two banks at one address) are allowed by the registers; what a read returns then is a U-item (U1). ## External memory control (EXMEMCNT 4000204h, EXMEMSTAT on the ARM7) Bits 0-6 per CPU (GBA slot SRAM and ROM access times, PHI output); bits 7-15 owned by the ARM9 and visible to both: GBA slot owner (7), DS slot owner (11), main memory interface mode (14), **main memory priority: ARM9 or ARM7 (15)**. A GBA slot owned by the other CPU reads 0; an empty slot reads open bus (ROM: address/2 or garbage by access time, SRAM: FFh). ## BIOS protection (BIOSPROT, ARM7 4000308h) The ARM7 BIOS can read itself only from code inside it ("normal protection", always active); the BIOS sets BIOSPROT to 1204h before starting the cartridge, after which the region 0-1203h (vectors, some code, the KEY1 table) cannot be read even by BIOS code outside it. Other readers get FFh. The ARM9 BIOS is unprotected. ## Access times (GBATEK "DS Memory Timings", in 33.51 MHz bus cycles) | Region | ARM7 code N32/S32/N16/S16 | ARM7 data N32/S32/N16/S16 | Bus width | | --- | --- | --- | --- | | main RAM | 9 / 2 / 8 / 1 | 10 / 2 / 9 / 1 | 16 | | WRAM, BIOS, I/O, OAM | 1 / 1 / 1 / 1 | 1 / 1 / 1 / 1 | 32 | | VRAM, palette | 2 / 2 / 1 / 1 | 1? / 2 / 1 / 1 | 16 | | GBA ROM (10,6 setting) | 16 / 12 / 10 / 6 | 15 / 12 / 9 / 6 | 16 | | GBA RAM (10) | | 9 / 10 / 9 / 10 | 8 | The ARM9 columns and the nonsequential penalty are in arm946es-python docs/timing.md. Korth's notes: main RAM always carries a 3-cycle nonsequential penalty, on the ARM7 too; the display controller reads VRAM every 6 cycles and a simultaneous ARM9 access waits 1 cycle (capture adds VRAM writes every 6 cycles); VRAM mapped to the ARM7 has no extra waits. ## Unknowns (U) and contradictions (C) - U1 Overlapping VRAM bank mappings: OR of the banks, priority, or garbage? (Software sometimes does it by accident.) Judge: rockwrestler's VRAMCNT group (run only, its cases are not documented in prose); default HYPOTHESIS: OR of the data. - U2 Main-RAM arbitration between the ARM9, the ARM7 and eight DMA channels: how long a loser waits, and what EXMEMCNT bit 15 changes. No document gives cycle numbers. - U3 The main-RAM nonsequential penalty's exact rule (also arm946es-python timing.md U1). - U4 "1?" in GBATEK's ARM7 VRAM data N32 entry. - U5 What reads of the 0 KB ARM9 WRAM region return ("undefined data"). - C1 GBATEK's memory map says the ARM9 BIOS area is "32KB (only 3K used)" and its technical data "4K NDS9"; the dump is 4,096 bytes (census.md). Mirroring of the 4 KB over 32 KB is assumed (HYPOTHESIS).