Introduction
The programmer’s registers are those of the 65C02: the accumulator A, the index registers X and Y, the stack pointer S, the program counter and the status register P, all 8 bits except the 16-bit program counter. What is new is the T flag in P and the eight mapping registers, which stand between the 16-bit addresses a program uses and the 21 address lines of the chip.
The registers
| Register | Width | What it holds |
|---|---|---|
A | 8 | Accumulator. |
X, Y | 8 | Index registers. With the T flag set, X is also the zero page address that ADC, AND, EOR and ORA work on. |
S | 8 | Stack pointer. The stack is the page at logical $2100-$21FF, so a push writes $2100 + S. |
PC | 16 | Program counter, a logical address. |
P | 8 | Status, below. |
MPR0-MPR7 | 8 each | The mapping registers, below. They are written and read only with TAM and TMA. |
The status register
| Bit | Flag | Meaning |
|---|---|---|
| 7 | N | Negative: bit 7 of the result. |
| 6 | V | Overflow. BIT, TST, TSB and TRB also copy bit 6 of the memory byte into it. |
| 5 | T | Memory operation. Set by SET; while it is set the next ADC, AND, EOR or ORA works on memory at zero page X instead of on A. Every other instruction clears it. See the T flag. |
| 4 | B | Break. It is set in the copy of P that BRK pushes. |
| 3 | D | Decimal mode: ADC and SBC work on packed decimal digits, and take one more cycle. |
| 2 | I | Interrupt disable. |
| 1 | Z | Zero. |
| 0 | C | Carry. |
The bit positions are those the jspce core uses (T at bit 5, which is the 65C02’s unused bit); the Hudson manual that would state them could not be read.
The mapping registers
The 16-bit logical address space is cut into eight segments of 8 KB. The top three bits of an address choose the mapping register for the segment, and the register’s 8 bits become the top 8 bits of a 21-bit physical address; the low 13 bits pass through:
physical = MPRn × $2000 + (logical AND $1FFF), with n = the top three bits of the logical address.
| Register | Logical range | TAM and TMA mask bit |
|---|---|---|
MPR0 | $0000-$1FFF | $01 |
MPR1 | $2000-$3FFF | $02 |
MPR2 | $4000-$5FFF | $04 |
MPR3 | $6000-$7FFF | $08 |
MPR4 | $8000-$9FFF | $10 |
MPR5 | $A000-$BFFF | $20 |
MPR6 | $C000-$DFFF | $40 |
MPR7 | $E000-$FFFF | $80 |
Example: with MPR1 = $F8, logical $2005 (zero page address $05) is physical $F8 × $2000 + $0005 = $1F0005, in the work RAM.
The program sets a register with TAM: lda #$F8 then tam #$02
(mask $02 selects MPR1). TMA reads one back into A.
At reset the reset vector is read from logical $FFFE, and the sources read put it at physical $001FFE, the last two bytes of the first 8 KB of the HuCard; so MPR7 must be $00 at reset. The sources read do not say what the other registers hold at reset, so they are not known here; a program sets them before it uses them. Programs and the system software usually set MPR0 to $FF (the hardware page) and MPR1 to $F8 (the work RAM).
The explorer’s decoder takes the registers as eight options. Its defaults are the usual setup (MPR0 = $FF, MPR1 = $F8, MPR7 = $00, the others not known), and it learns
the rest from a lda #n (or cla) directly followed by a tam in the code it is reading.
The physical memory map
The value in a mapping register is a bank number; the physical space has 256 banks of 8 KB (2 MB).
| Banks | What is there |
|---|---|
| $00-$7F | The HuCard (up to 1 MB). A card smaller than that is repeated or leaves the rest unmapped; most HuCards have no memory mapper and use the highest address bit as a chip enable. |
| $80-$F6 | Not used by a plain system. Expansion hardware (the CD-ROM system, the Super System Card, the Arcade Card, the SuperGrafx) uses some of them; the sources read do not give the numbers reliably, so they are not listed. |
| $F7 | Backup (save game) memory, where the system has it. |
| $F8 | The work RAM, 8 KB. Its first page is the zero page, the second the stack. |
| $F9-$FB | On the PC Engine, mirrors of $F8. The SuperGrafx has more RAM here. |
| $FC-$FE | Nothing. |
| $FF | The hardware page: the chip’s own registers, below. |
Zero page and stack are at fixed logical addresses, $2000-$20FF and $2100-$21FF; where they land physically depends on MPR1, and a program that maps something else at $2000-$3FFF moves them.
The hardware page (bank $FF)
With MPR0 = $FF the registers are at the start of the logical space. Each block is mirrored through its 1 KB.
| Offset in the page | Block |
|---|---|
| $0000-$03FF | The video display controller (HuC6270 VDC), 4 registers. |
| $0400-$07FF | The video colour encoder (HuC6260 VCE), 8 registers. |
| $0800-$0BFF | The programmable sound generator (PSG). |
| $0C00-$0FFF | The timer, 2 registers. |
| $1000-$13FF | The input/output port (the joypads), 1 register. |
| $1400-$17FF | The interrupt controller, 4 registers. |
| $1800-$1FFF | Unmapped on a plain system; the CD-ROM interface registers begin at $1800 on the PC Engine CD. |
The SuperGrafx puts two VDCs and a priority controller (VPC) at $0000-$001F instead. ST0, ST1 and ST2 write the VDC directly.
Interrupt vectors
The vectors are at the top of the logical space, so they come from whatever bank MPR7 maps at $E000-$FFFF (on a HuCard, its last 8 KB).
| Logical address | Vector |
|---|---|
| $FFF6-$FFF7 | IRQ2, and BRK |
| $FFF8-$FFF9 | IRQ1 (the VDC) |
| $FFFA-$FFFB | TIQ (the timer) |
| $FFFC-$FFFD | NMI |
| $FFFE-$FFFF | Reset |
Unlike the 65C02, BRK does not go through $FFFE (here the reset vector) but through $FFF6, shared with IRQ2. Each vector is a 16-bit address, low byte first.
Not described
Known, not yet covered
- Reference: the registers of the VDC, VCE, PSG, timer, I/O port and interrupt controller (only their address blocks are listed).
- Reference: the banks used by the CD-ROM system, the Super System Card and the Arcade Card, and the Street Fighter II mapper.
Unknown
- Reference: the value of MPR0-MPR6 at reset, and the exact bit position of T in a pushed status byte on real hardware.
Links
Reference
- CPU memory map – the PCEdev wiki: the virtual and physical spaces, the hardware page, the vectors
- Memory Mapping – the mapping registers, the 21-bit address and the TAM and TMA mask