The mapping registers
The HuC6280 addresses 64 KB (the logical space) and a 2 MB physical space. Eight mapping registers MPR0 to
MPR7 each choose which 8 KB page of the physical space appears in one 8 KB window of the logical space: MPR0 for
$0000 to $1FFF, MPR1 for $2000 to $3FFF, and so on up to MPR7 for
$E000 to $FFFF. A logical address L reaches the physical address
(MPR[L >> 13] << 13) | (L & $1FFF). The registers are set with the instruction
TAM #mask (the accumulator goes to every MPR whose bit is set in the mask) and read with
TMA #mask (the register of the lowest set bit goes to the accumulator). The
header holds the values at the start of the song.
What a page value selects
| MPR value | Page | Physical address |
|---|---|---|
$00 to $7F | ROM, 128 pages of 8 KB: the 1 MB that the DATA blocks fill (bytes that no block fills read $FF) | $000000 to $0FFFFF |
$80 to $F7 | Nothing: reads $FF, writes are ignored | |
$F8 | The 8 KB of RAM | $1F0000 to $1F1FFF |
$F9 to $FB | SuperGrafx RAM, three more pages of 8 KB (Game_Music_Emu and NEZplug++ both provide them) | $1F2000 to $1F7FFF |
$FC to $FE | Nothing | |
$FF | The hardware page: the chip registers below | $1FE000 to $1FFFFF |
The RAM is cleared to zero before a song starts (some tunes rely on that).
Zero page and stack
The HuC6280’s zero page is not at $0000 but at logical $2000 to $20FF, and the stack at
$2100 to $21FF: the processor adds $2000 to every zero-page and stack address. They
reach the RAM only while MPR1 holds $F8, which is what the header’s usual mapping
($FF $F8 …) arranges. A tune that changes MPR1 moves its zero page and stack with it.
The hardware page
With a page value of $FF the 8 KB window shows the chip registers. Each block is mirrored through its range.
| Offset | Chip | Registers a tune uses |
|---|---|---|
$0000 to $03FF | VDC (HuC6270 video) | $0000 register select (the instruction ST0 writes it), $0002/$0003 data low/high (ST1, ST2). Only register 5 matters to a tune: bit 3 enables the vertical-blank interrupt. A read of $0000 returns the status and acknowledges that interrupt |
$0400 to $07FF | VCE (HuC6260 colour) | Ignored by the explorer and by the players |
$0800 to $0BFF | PSG | $0800 to $0809: see The PSG |
$0C00 to $0FFF | Timer | $0C00 reload, $0C01 start and stop: see INIT, timer and interrupts |
$1000 to $13FF | Input/output port | Joypads and country bits: not used by a tune |
$1400 to $17FF | Interrupt controller | $1402 mask (a set bit disables: 1 IRQ2, 2 IRQ1 (VDC), 4 timer), $1403 status (a write acknowledges the timer) |
$1800 to $1FFF | CD-ROM unit | The ADPCM registers $1808 to $180F and the interrupt registers $1802 and $1803 (The ADPCM unit), and the signature bytes $00, $AA, $55, $03 at $18C0 to $18C3 that a program reads to find the CD system. The SCSI registers $1800 to $1807 are not emulated (a CD drive is not part of a HES player): they read 0 and writes to them are ignored (as are those of $1804 to $1807). The 16 registers repeat every 16 addresses up to $1BFF (Game_Music_Emu maps the same 1 KB), except that $18C0 to $18FF read the signature or $FF. Addresses from $1C00 read $FF |
Interrupt vectors
The vectors sit at the top of the logical space, in whatever page MPR7 shows (usually ROM page 0, so the last bytes of the first 8 KB of the data):
| Address | Interrupt |
|---|---|
$FFF6 | IRQ2 and BRK |
$FFF8 | IRQ1: the VDC (vertical blank) |
$FFFA | Timer |
$FFFC | NMI |
$FFFE | Reset (a HES player never resets the processor: it jumps to the init address instead) |
In the explorer
The Memory tab lists MPR0 to MPR7 with the page each selects and the vectors found in the page of MPR7. The Code tab shows each 8 KB page of the data at the
logical address its MPR gives it (a page that no MPR maps at the start is shown at $E000), and follows TAM instructions to track the
mapping through straight-line code.
Divergence from the specification
There is no specification. Game_Music_Emu and NEZplug++ give the same pages. Mednafen, which models a whole PC Engine, has only 8 KB
of RAM (SuperGrafx: 32 KB) and maps no ROM at $00 to $7F beyond what a cartridge provides; the HES
players fill the ROM from the file.
Sources
- Game_Music_Emu 0.6.1,
Hes_Emu.cpp(set_mmr,cpu_read_,cpu_write_,start_track_) andhes_cpu_io.h: the pages, the registers and the start state. - NEZplug++,
m_hes.c:read_event,write_event,alloc_physical_address: the same map, with RAM at$F8and SuperGrafx RAM at$F9to$FB. - Mednafen’s
huc6280.cpp: the zero-page and stack addresses, TAM and TMA.