The processor
The HuC6280 is a CMOS 6502 (the 65C02 instruction set) with extra instructions, the eight mapping registers, the sound generator and the timer on the chip, and a 7.16 MHz fast mode. A HES tune is a program for it, so a player has to run its instructions with the right results and, because the timer and the interrupts depend on it, with the right cycle counts. The Code tab of the explorer shows the code of the data using the instruction names below.
What it adds to the 65C02
| Instructions | What they do | Cycles |
|---|---|---|
CSL, CSH | Slow mode (a 1.79 MHz clock) and fast mode (7.16 MHz). Every cycle in slow mode takes four ticks of the master clock instead of one. | 3 each |
SET | Makes the next instruction work on the zero-page byte addressed by X, not the accumulator (the T flag): ADC, AND, EOR and ORA then add the result to that byte. | 2, and 3 more for each ADC/AND/EOR/ORA while it is set |
CLA, CLX, CLY | Clear A, X and Y. | 2 |
SAX, SAY, SXY | Swap two registers. | 3 |
ST0, ST1, ST2 | Store an immediate byte at the VDC registers $0000, $0002, $0003. | 4 |
TAM, TMA | Write a mapping register from A, or read one into A, with a mask giving which. | 5 and 4 |
TII, TDD, TIN, TIA, TAI | Block transfers of a length from the source to the destination: incrementing, decrementing, with a fixed source or destination, or alternating between two destination addresses. | 17, then 6 for every byte |
TST | Tests an immediate mask against a zero-page, zero-page indexed, absolute or absolute indexed byte. | 7 to 8 |
BSR | A branch to a subroutine (relative). | 8 |
RMB, SMB, BBR, BBS, TSB, TRB, STZ, BRA, PHX, PHY, PLX, PLY | The 65C02 additions (bit set and clear, branch on a bit, test and set or reset, store zero, always branch, push and pull X and Y). | BBR and BBS take 6 (8 when the branch is taken) |
Timing and flags
- Taking an interrupt costs 8 cycles. It pushes the return address and the flags, sets the interrupt-disable flag and clears the decimal and T flags (Mednafen; Game_Music_Emu clears only the decimal flag, since it has no T flag).
- In decimal mode ADC and SBC take one more cycle, and the T flag is cleared after every instruction except the one it modifies.
- The fast clock is 7,159,091 ticks per second; a cycle is one tick, or four in slow mode. This is also the clock of the timer and the PSG.
In the explorer
The Trace tab runs the processor from the init address and shows the first 48 instructions with the registers, the flags and
the tick count of each; the Code tab disassembles every page of the data. The processor is the explorer’s own HuC6280 core (explorer/formats/hes/cpu.js), checked against Game_Music_Emu’s core over 90,000 random instructions for the
results of the registers and flags.
Divergence from the specification
The reference for the processor is Mednafen’s emulation, written from the Hudson HuC6280 manual and tested on the console, which the explorer follows. Game_Music_Emu’s core differs from it in places a HES tune can reach:
- It has no decimal mode: ADC and SBC always add in binary.
- BBR and BBS take 4 cycles (6 taken) there (its table says 6 and it takes 2 off when the branch is not taken), against 6 and 8 in Mednafen.
- It sets the flags of TSB and TRB differently from Mednafen.
- It ignores CSL, CSH and SET: slow mode does not slow it and the T flag has no effect, so the extra cycles are missing.
A tune that does not rely on any of those plays the same under both. The explorer’s timing follows the manual and Mednafen, so a tune that does is timed as on the console.
Sources
- Mednafen,
pce/huc6280.cppandhuc6280_ops.inc(the libretro beetle-pce copy is saved in research/hes/dl): the reference behaviour for flags, decimal mode and the cycle counts, which add up as the table above (the opcode fetch is the first cycle; the last cycle of each instruction is counted byLastCycle). - Game_Music_Emu 0.6.1,
Hes_Cpu.cppandhes_cpu_io.h: the second core, and the cause of each divergence above. - NEZplug++,
cpu/km6502/km6280m.h.