Assembly quick reference
Numbers: $1700 hex, %10110000 binary, 42 decimal, 'A' character. Labels end in :. Constants: NAME = expr. Origin: *= $0200 or .org. Expressions take + and -, * is the current address, and </> take the low/high byte.
LDA #$01 — immediate
LDA $D0 — zero page
LDA $D0,X — zero page,X
LDX $D0,Y — zero page,Y
LDA $0300 — absolute
LDA $0300,X — absolute,X
LDA $0300,Y — absolute,Y
LDA ($02,X) — indexed indirect
LDA ($02),Y — indirect indexed
JMP ($02FF) — indirect
ASL A — accumulator
BNE loop — relative.byte 1, $ff, %1010
.word $0200, label
.text "RAW ASCII"
.fill 16, $EA
RAM is $0000–$03FF and
$1780–$17FF. The monitor
uses $EF–$FB, and the
stack is page one.
A program starts by itself: unless the source writes $17FC, the loader puts the program's first address there, and the monitor's reset code jumps through it. Write .word 0 at $17FC to boot into the monitor instead. $17FA (NMI) and $17FE (IRQ, BRK) get the monitor's STOP routine unless the source sets them. A label named DONE gets a breakpoint.
Model & limitations
Cycle-level emulation. Each clock cycle performs exactly one bus access, as the 6502 does, and every documented and stable undocumented opcode is built from its real cycle sequence: dummy reads at PC, the unindexed zero-page read, the wrong-page read before an index carry is fixed, the extra read before any indexed store, and the double write of read-modify-write. JSR fetches its high byte after pushing. Reset, IRQ, NMI and BRK share one seven-cycle sequence, and reset suppresses its writes. Cycle counts are not taken from a table. They come from those sequences, and the tests compare them with the data sheet for every opcode.
Register and flag changes are applied in the cycle that finishes the instruction. On the chip some of them land a cycle later, during the next opcode fetch, which is the overlap that makes INX take two cycles. Nothing on the bus shows the difference. Half-cycles (φ1/φ2) are not modelled: the analyser draws the clock for reference only.
Interrupts: IRQ and NMI are sampled once per cycle. An instruction acts on what was sampled at the end of its second-to-last cycle, so an IRQ is delayed by one instruction after CLI, gets in right after SEI, and is delayed by a taken branch that stays in its page. NMI is edge-triggered. The vector is chosen in the fifth cycle of the sequence, so an NMI can take over a BRK or an IRQ already under way. The decimal flag is left alone by interrupts and reset, as on the NMOS part. RDY and SO are not connected.
Undocumented opcodes: SLO RLA SRE RRA SAX LAX DCP ISC ANC ALR ARR SBX LAS, the undocumented NOPs and SBC $EB run with the same cycle sequences as their documented neighbours. ARR in decimal mode uses its binary result. JAM stops the timing generator until reset. The unstable six (ANE LXA SHA SHX SHY TAS) are fetched and then stop the machine rather than invent a value. Power-on registers are undefined on the real chip; here they start at zero with I set, and the stack pointer comes out of reset at $FD.
The board: 1 KB of RAM at $0000, two 6530 RRIOTs at $1700 and $1740 with their 64 bytes of RAM each, and ROM at $1800–$1FFF. Only A0–A12 are decoded, so everything repeats every 8 KB and the CPU's vectors at $FFFA are read from $1FFA. Unfitted addresses return the last byte that was on the data bus. The 6530 model has the ports, the direction registers and the interval timer (divide by 1, 8, 64 or 1024). The timer flags n×divider+1 cycles after it is written and then counts once per cycle. Reading or writing it clears the flag. The 6530-003 timer is wired to IRQ, as a jumper does on the real board. The other 6530 features (PA7 edge detection, the PB7 interrupt pin, and mask ROM options) are absent.
The KIM-1's cassette and teletype interfaces, and its 6530-003 ROM, are not here: $1800–$1BFF reads zero. Keys do not bounce. A click holds a key for at least 30 ms of machine time, so the monitor's scan sees it whatever the clock speed. The LED brightness is the fraction of time each segment was driven, mapped through a curve that stands in for the eye. When the clock is slow or paused you see only the digit that is lit at that moment, which is what a camera with a short exposure would show.
Keyboard: Space run/pause, S one cycle, N to the end of the instruction, B back one cycle, R power on. Shortcuts do not work while a control has focus. Back undoes up to 4,096 cycles, including the RIOTs and RAM.