# The HuC6272 "KING" Keys as in [start-here.md](start-here.md). Main source T15 "HuC6272 (KING)" (tier 3), cross-checked against LIB `king.h` (tier 3, "basic support exists and backgrounds have been tested working"). The KING "handles processing BG transfers, SCSI transfers, ADPCM transfers, and RAINBOW transfers. Main RAM cannot be accessed directly, transfer data to KRAM with the KRAM interface" (T15). It is four things on one chip: a background generator, a KRAM controller with DMA engines, a SCSI controller and the feeder for the ADPCM and the Rainbow. ## Ports (T15) 600h register select (write) / status (read: selected register in bits 0-6, busy bit 9, interrupt flags in bits 10-14 (ADPCM buffer, raster, CD subcode, SCSI DMA end, SCSI "block"), SCSI status in 16-23, subcode in 24-31); 602h status 2; 604h data; 606h data 2. Registers are 16 or 32 bits wide (marked "Half"/"Word" per register). ## KRAM - Addresses are 18 bits of halfwords plus a page bit (registers 0Ch/0Dh: address 0-17, increment 18-27, page 31), so **2 pages x 256K halfwords = 1 MB** (HYPOTHESIS from the field widths; the part count on the board would confirm, U3). - Register 0Fh assigns a page to each client: SCSI (bit 0), BG (bit 8), Rainbow (bit 16), ADPCM (bit 24). - 0Eh is the data window with auto-increment. T15 says writes go to "the address in 0Ch" (the **read** address) and reads come from 0Dh (the **write** address): swapped against the register names (C2). LIB's `eris_king_set_kram_read/write` keep the names' meaning; the build follows the names (HYPOTHESIS until a test). ## Backgrounds - Four layers BG0-BG3, each with a mode (10h: 4, 16, 256 palette colours, 64K colours, 16M colours, or palette "block modes" that read a BAT), a priority (12h, 3 bits each, 0 hidden), a BAT and CG base in KRAM (20h-29h, in 1 KB units; BG0 also has a "sub" BAT/CG), a size (2Ch-2Fh: 8 to 512 px per axis, 1024 for BG0 only; BG0 also a sub size), scroll (30h-37h) and an endless/single scroll mode (16h). - **Rotation and scaling:** coefficients A-D in 8.8 fixed point (38h-3Bh: (1/a)cos r, -(1/b)sin r, (1/a)sin r, (1/b)cos r) and a centre (3Ch-3Dh). T15 contradicts itself on which layer rotates: "BG0 rotation enable" is bit 12 of the priority register, yet "BG0 cannot be rotated" in the microprogram limits (C3). LIB's header comments are to be read on this point before the build (U4). - **The microprogram:** 16 halfwords (two banks of 8) in the KING, written through 13h/14h (address, data with auto-increment), started by 15h. Each opcode names a BG (bits 6-7), an access type (CG data, the BAT's CG, the BAT; bits 3-4), an offset (bits 0-2), a rotation flag (bit 5) and a NOP flag (bit 8). T15 lists the standard programs per mode. **This is a fetch schedule**: within each character period the KRAM bus serves the slots the microprogram lists, so a mode needs as many slots as its bit depth demands, and the eight slots per bank cap what the four layers can show together (T15's "Limit" notes). The slot timing against the dot clock is U3. ## SCSI (registers 00h-0Bh) A SCSI initiator with the bus signals visible as registers (data, initiator command: bus/ATN/select/ACK/reset; target phase bits I/O, C/D, MSG; bus status with REQ, BSY, SEL...), a sequential/DMA mode, and **DMA into KRAM** (start address 09h with an A/B page bit, byte count 0Ah, control 0Bh with end interrupt). The CD-ROM drive is the only target on the PC-FX (the FX-SCSI adapter adds an external bus). See [cdrom.md](cdrom.md). ## ADPCM feed (registers 50h-5Eh) Two channels: play bits and a sampling rate (50h: 31.47, 15.73, 7.87, 3.93 kHz), per channel ring or sequential buffer mode and end/intermediate interrupts (51h/52h), status (53h, cleared by reading; level-triggered), start (in 256-byte units), end and intermediate addresses in KRAM. The HuC6230 decodes and mixes ([sound.md](sound.md)); the HuC6230's own register 120h gives the rates as 32, 16, 8 and 4 kHz (C1). 31.47 kHz is 21.47727 MHz / 682.5 = 2 x the 15.73 kHz line rate: the KING's figures look like line-locked rates, the HuC6230's like rounded labels (HYPOTHESIS, U12). ## Rainbow feed (registers 40h-44h) Enable, raster interrupt enable, the KRAM address of the stream, the start raster (0-261), the block count (0-31) and the interrupt raster. See video.md. ## Interrupt PC-FX level 13 (T15 "Interrupt"), with the causes in the status word. ## What is unknown KRAM size confirmation and access timing; the microprogram's slot timing; rotation arithmetic (rounding, which BG); the block modes' BAT format (T15 shows the microprograms but not the BAT entry layout: LIB's `king.h` is the place to look); SCSI DMA rate; whether the CPU waits (status busy bit 9) on KRAM access and how long (PGN: "many interfaces to other hardware (such as KRAM) are able to block writes/reads").