# The TLCS-900/H as this core will model it The Toshiba TLCS-900/H is the 16-bit CPU core (32-bit registers, 16-bit external bus, 24-bit addresses) inside the Neo Geo Pocket's SoC. Page citations below are to the pinned Toshiba documents (`scripts/pinned_files.json`), by printed page number: **H1/H2** = TLCS-900/H data book ch. 3 parts 1-2 (2001-03-16, "CPU900H-n"), **HA1-3** = its appendix A (instruction details), **HB** = appendices B-D (instruction lists with states, "CPU900H-157" on), **DIFF** = the older 900/900L/900H book on bitsavers ("CPU900-n"), **C061** = TMP95C061F data sheet. These are scans; `scripts/ocr_references.py` makes greppable text, and each fact below was read on the page. ## The 900 family, and which one this is | | 900 | 900/L | 900/H | 900/H2 | | --- | --- | --- | --- | --- | | Register mode | MIN at reset, MAX by instruction | MAX at reset | **MAX only** | MAX | | Operating modes | system and normal (XNSP exists) | system only | **system only** | system | | Interrupt nesting counter INTNEST | no | yes | **yes** | yes | | ALU | 16-bit | 16-bit | **32-bit** | 32-bit | | Branch-destination prefetch | only when branching | | **only when branching** | even when not branching | | Instruction states | e.g. `LD R,r` 4 | | e.g. `LD R,r` **2** | | Sources: H1 CPU900H-1 (the differences table), H1 CPU900H-2 (32-bit ALU, 4-byte queue), DIFF CPU900-1 and CPU900-168ff (the 900's state column: `LD R,r` 4.4.4), HB CPU900H-158 (the 900/H's: 2.2.2). So the 900/H is not the 900 with a new name: its timing table is roughly half the 900's, and it lacks the 900's normal mode and minimum mode. **Which part the NGP has** is not documented by SNK in anything found. Judge's ngpctech.txt (c. 2000) says "TLCS-900H (based on the TMP95CS64F package)"; MAME 0.285 names the device "Toshiba TMP95C061" (a plain TLCS-900 part, C061 p. 1) but its debugger state table lists XSSP and XNSP (900 features), while the states it charges agree with the 900/H table (see [mame-oracle.md](mame-oracle.md)). Toshiba's own 900/H book uses the TMP95C061 as its example device for bus timing (H2, figure 7.8). Recorded as C1 in the handoff brief; this core models the **900/H** CPU and leaves the SoC's peripherals to the board. ## Registers (H1 CPU900H-3 to -10) - **Four banks** (0-3) of four 32-bit registers: XWA, XBC, XDE, XHL, each split into 16-bit WA, BC, DE, HL and 8-bit W, A, B, C, D, E, H, L. The current bank is SR's `RFP` (bits 8-10; RFP2 fixed to 0 in maximum mode, CPU900H-7); the previous bank is RFP-1 (`WA'`...); every bank register is also reachable by absolute name (`RW0`, `RA0`...). `LDF imm`, `INCF`, `DECF` change RFP and wrap modulo 4 (CPU900H-10). - **Four dedicated 32-bit registers**: XIX, XIY, XIZ, XSP (the system stack pointer, `XSP = 100H` after reset: CPU900H-4). - **PC**, 32 bits in maximum mode, upper 8 bits ignored with 24 address pins (CPU900H-9). Reset reads the reset vector from the vector base (CPU900H-9; the NGP BIOS starts at FF204A in MAME's trace of the NGPC BIOS). - **SR**: SYSM (=1, CPU900H-6), IFF2-0 (interrupt mask, 111 after reset), MAX (=1), RFP2-0 (000 after reset), and the flag byte F: bit 7 S, 6 Z, 5 "0", 4 H, 3 "0", 2 V, 1 N, 0 C (CPU900H-7, read on the page image; H is undefined after 32-bit operations), with F' an alternate flag register (`EX F,F'`). - **Control registers** (`LDC cr,r`): the micro-DMA source, destination, count and mode registers for four channels (DMAS0-3, DMAD0-3, DMAC0-3, DMAM0-3) and INTNEST (CPU900H-9; their behaviour is described in "Chapter 4 TLCS-900/H LSI Devices", which is per device and **not in hand**: U3). ## Instructions (H2, HA1-3, HB) Nine addressing modes (H1 CPU900H-14): register, immediate, register indirect, pre-decrement, post-increment, register + 8/16-bit displacement, register + register, absolute 8/16/24-bit, PC-relative. Operand size is byte, word or long word, chosen by the prefix byte (`C8+zz+r` register prefix, `80+zz+mem` / `B0+mem` memory prefixes), so the decode is two-level: a first byte that selects addressing or a short form, then an operation byte. Groups (HB): load, exchange (including `TSET`, `BS1F/BS1B`), block transfer (`LDI/LDIR/LDD/LDDR/CPI/CPIR...`), arithmetic and logic with 8/16/32-bit forms, 16x16 multiply and 32/16 divide (`MUL`, `MULS`, `DIV`, `DIVS`), filter maths (`MULA`, `MINC/MDEC` modulo), decimal (`DAA`), bit operations (`BIT`, `SET`, `RES`, `CHG`, `TSET`, `STCF/LDCF/ANDCF/ORCF/XORCF`), rotate and shift, jumps, calls and returns with conditions (`JR`, `JRL`, `JP`, `CALL`, `CALR`, `RET cc`, `RETD`, `RETI`, `DJNZ`), and CPU control (`EI n`, `DI`, `SWI n`, `HALT`, `LDF`, `INCF`, `DECF`, `LDC`, `LINK`, `UNLK`, `SCC`, `NOP`, `LDX`). - `SWI n` pushes PC and SR and jumps through FFFF00H + 4 x n (HB CPU900H-164; the NGP BIOS's system calls use `SWI 1`, Judge's ngpctech.txt). - `EI n` sets IFF to n, effective immediately (unlike the TLCS-90); on accepting an interrupt the mask is set to the accepted level + 1 (7 stays 7): H1 CPU900H-6, HB CPU900H-164. - `RETI` pops SR and PC (12 states, HB CPU900H-166; "0.96 us at 25 MHz" in H1 CPU900H-11 agrees with 1 state = 80 ns). - Undefined flags are marked "X" in HB; the 900 book adds that they are "partly different in 900/H" (DIFF CPU900-167): undefined-flag values are an open item (U4) with no hardware oracle. ## What the core owns and what the board owns The core owns: the registers, banks and SR; decode and execution; the instruction queue and its refill on the bus; states per instruction and per bus access; interrupt acceptance at instruction boundaries (level compare against IFF, vector fetch, push of PC and SR, INTNEST); micro-DMA **transfer** when the board requests a channel (the four channels' registers live in the CPU's control-register file). The board (ngp-python) owns: the SoC's I/O window 000000-0000FF (timers, the interrupt controller's priority and enable registers, serial, ports, ADC, watchdog, clock gear, RTC, Z80 control), which interrupt source requests which vector at which level, which source triggers which micro-DMA channel, wait states per address range, and memory. This split is a proposal (open decision 2 in [handoff-brief.md](handoff-brief.md)): Toshiba's 900/H parts differ exactly in their peripherals, and no document of the NGP SoC's peripheral set exists, so keeping them out of the CPU core keeps the core a faithful 900/H.