# Memory map, memory control and what each access costs Sources: psx-spx `memorymap.md`, `memorycontrol.md`, `iomap.md` at `6d7d1bc` (tier 3); ps1-tests `cpu/access-time/psx.log` and `cpu/io-access-bitwidth` (MIT, tier 3: console outputs, presumed; U13 in r3000a-python). ## Who answers what The CPU core (r3000a-python) answers the scratchpad and FFFE0130h and hands every other access to the board as a **physical** address with a size, a kind (fetch, refill, queued write...) and, for stores, the full 32-bit register. The board decodes it. ## Memory control registers (DOC psx-spx `memorycontrol.md`) 1F801000h DEV0 base, 1F801004h DEV8 base, 1F801008h-1Ch delay/size for DEV0, DEV1, DEV2 (BIOS), DEV4 (SPU), DEV5 (CD-ROM), DEV8; 1F801020h COM_DELAY; 1F801060h DRAM_CTRL. Each delay/size word: write delay, read delay, recovery/hold/floating/pre-strobe enables, bus width 8/16, auto-increment, address bits (window size; beyond it a bus error), DMA timing override, wide DMA. psx-spx gives a "(somehow) like so" formula for first and sequential access time from these fields: **FITTED**, not measured; U1 below. The BIOS's first instruction writes DEV2 = 0013243Fh; a logic analyser shows the fetch two instructions later still uses the reset timing (psx-spx, MEASURED by its contributors, tier 3). DRAM_CTRL: the BIOS writes 0B88h (an 8 MB bank on a 2 MB chip), so 2 MB RAM mirrors to 8 MB; Puzzle Bobble, Gundam Battle Assault 2 and FreePSXBoot rely on the mirrors; Wipeout shrinks it with SetMem(). Bit 7 (one idle cycle between RAM accesses) cleared hangs games on early boards (psx-spx). ## Measured access costs (TEST ROM: ps1-tests `cpu/access-time/psx.log`) CPU cycles per load, 8 / 16 / 32-bit, BIOS defaults: | Region | 8-bit | 16-bit | 32-bit | | --- | ---: | ---: | ---: | | RAM 80000000h | 5.21 | 5.3 | 5.14 | | BIOS BFC00000h | 7.6 | 12.94 | 24.94 | | scratchpad | 1.5 | 1.1 | 0.94 | | expansion 1 / 2 / 3 | 6.94 / 10.99 / 6.7 | 13.7 / 25.99 / 6.1 | 25.7 / 55.98 / 9.95 | | DMA, SIO, RAM size, I_STAT, timers, MDEC, GPU status | ~3-4 | ~3-4 | ~3-4 | | CD-ROM status | 8.0 | 14.0 | 25.93 | | SPU control | 17.99 | 17.99 | 38.94 | | cache control FFFE0130h | 0.95 | 1.9 | 1.9 | These numbers include the test loop's own cost (the scratchpad's 0.94 shows it); the spec fits its memory-control model to them and says so (FITTED against TEST ROM). ## Bus-width quirks (DOC psx-spx; TEST ROM ps1-tests io-access-bitwidth) - 8/16-bit CPU stores carry all 32 bits; 32-bit registers (DMA) see the whole word. - SPU: 16-bit bus; 8-bit writes to odd addresses ignored, to even addresses done as 16-bit writes of the low half; 32-bit writes "particularly unstable" (psx-spx `soundprocessing unitspu.md` "SPU Bus-Width"; ps1-tests `spu/test`: "data is lost randomly on 32bit access"). - The DMA control registers at 1F8010x8h mirror at 1F8010xCh. - Unused I/O gaps raise bus errors; reads of some registers return "garbage" upper bits (the next opcode, per psx-spx's timers page): **U2**, which ones exactly. ## Write queue reordering The CPU's 4-word write queue makes KUSEG/KSEG0 device writes leave late, after later reads (r3000a-python cop0-and-caches.md). Sony's libraries write dummy values to flush it; the board sees writes when they leave the queue, which is what the hardware's devices see. ## Unknowns - U1 The access-time formula from the delay fields (psx-spx's is approximate); fit it to access-time/psx.log and amidog's timing pages, mark FITTED. - U2 The "garbage" upper bits on reads of 16-bit registers through 32-bit loads. - U3 Uncached RAM instruction fetch cost ("0..4 cycles added", psx-spx COM_DELAY note).