The Atari VCS's RIOT
Task 3 of the Atari 2600 plan: Riot6532, the 6532 RIOT, chip alone, built from riot.md. Nothing runs a program yet: the bus is task 4, and the suite’s riot/ tests run from there, so none is claimed here.
What was built
src/Dbhq.Machines.Atari2600/Riot6532.cs, with the plan’s interface: 128 bytes of RAM, ports A and B with their direction registers, the interval timer, the PA7 edge detect, the flag register and the chip’s own IRQ pin, which goes nowhere on the 2600. ReadRegister is the CPU’s read with its side effects; PeekRegister returns the same byte with none, for the bus’s Peek. The chip has no clock of its own: the bus calls Tick once at the start of every CPU cycle, halted or not, then makes the cycle’s access. So a timer write’s cycle is the sheet’s cycle 0 and the count first falls on cycle 1. The register methods decode A0 to A4 only and the RAM methods A0 to A6, so the bus can pass any address of the chip’s half, mirrors included.
It is a new class, as the spec decided. The KIM-1’s Rriot6530 was read for its shape (the timer’s countdown and its “set this cycle” guard came out the same way) and nothing was taken from it or changed in it.
The 6530 against the 6532, row by row
riot.md section 1 checked the spec’s table against the data sheets. As built:
| Row | Verdict | In the code |
|---|---|---|
| Memory | Confirmed: no ROM, 128 bytes of RAM | RamSize, A0 to A6 |
| Selecting RAM or I/O | 6530 corrected (a mask-programmed decode of RS0 and A6 to A9), 6532 confirmed: RS, which the 2600 wires to A9 | The bus’s, in task 4; the chip has separate RAM and register methods |
| Interrupt output | Confirmed: a pin of its own, not connected | Irq, for the chip’s tests only |
| PA7 edge detect | Confirmed, with detail: polarity and enable come from the write’s address (A0 and A1), the data is ignored, and the flag is set whether or not the enable is on | WriteRegister with A2 high and A4 low |
| Reading the flags | Confirmed, with detail: bit 7 the timer, bit 6 the edge, bits 5 to 0 zero; reading clears the edge flag only; the timer flag is cleared by a timer read or write | ReadRegister with A2 and A0 high |
| Timer | Confirmed, and the open point settled: the flag is set on cycle D x N + 1, and a read on that very cycle returns $FF and leaves the flag set | Tick and ReadRegister |
Decisions
Tickruns before the cycle’s access, as the KIM-1’s does, over after it. The sheet’s cycle numbers then fall out with no offset: the write is cycle 0 and its own cycle does not count. Task 4’sCyclecalls it in that order.- The edge detect runs when the pin can change (an ORA or DDRA write, or a new
PortAInput), over comparing the pin on everyTick. A flag set on the change is there for a read on any later cycle, which is all the suite needs, andTick, which runs every cycle, does no work for the ports. When the real flag becomes visible is not stated (riot.mdsection 12 item 5)[guessing - verify]. - A port A output pin is the AND of ORA and what drives it, so an output at 1 reads 0 while its switch is closed. This is
riot.mdsection 5’s inference, marked[guessing - verify]there and in the code; task 9 decides it for the joysticks and may change it. Port B’s outputs are push-pull and read ORB, which the sheet does state. - The inputs default to
$FF, nothing pressed and every pull-up high, so the chip alone reads as a 2600 with nothing plugged in. Task 9’s controllers set them. - The power-on state. RES’s part as the sheet gives it (the I/O registers zeroed, both interrupts off, the negative edge armed). The rest is the model’s choice, so runs repeat: the RAM clear, both flags clear, and the count at
$00at divide by 1, so the first cycle passes zero and the timer free-runs, as the real one is taken to have since its own reset ended, before the CPU’s: that rests on the two reset circuits’ RC values, whichriot.mdsection 9 marks[guessing - verify]. Chosen over a count at$00waiting at divide by 1024, which a real chip would not be doing by the time the program starts. Indocs/known-differences.md. - The constructor powers the chip on, so a new chip and a powered-on one are the same.
What is guessed, and marked
Each is [guessing - verify] in a comment in Riot6532.cs and in docs/known-differences.md:
- After a read ends the free run, the first fall comes a whole divider after the read (
riot.mdsection 12 item 1). - A read on the cycle the flag is set leaves the free run going, as it leaves the flag (section 12 item 2).
- In the free run, when the count wraps past
$00again, a read on that cycle clears the flag: only the first pass of zero is “the interrupt occurring”. No source reaches this; the KIM-1’sRriot6530protects a read on every wrap, which is the other reading. - A port A output at 1 reads 0 against a closed switch (section 5).
- The edge flag is seen from the cycle the pin changes (section 12 item 5).
- PB2, PB4 and PB5 read 1 as inputs, through the pull-ups; no source states the value read on a 2600 (section 12 item 6).
- The real timer has been running since the RIOT’s own reset ended, before the CPU’s, which the power-on choice leans on (section 9).
The tests, test first
tests/Dbhq.Machines.Atari2600.Tests/Riot6532Tests.cs, each test named after the section or worked example it is taken from: RAM and its address-identity march (section 4); the decode’s mirrors and A4 on a write (worked example 1); port A’s output register (worked example 2) and port B’s (worked example 3); the timer at each divider (worked example 4), the count on every cycle by section 6’s rule, the data sheet’s own case of 52 at divide by 8, a write of 0, the flag’s clearing rules (worked example 5), the read on the cycle it passes zero (worked example 6, the suite’s timer-underflow-read), the suite’s timer-vblank-spin counts at one-cycle resolution (worked example 7); the enables and the IRQ pin (worked example 8); the PA7 edges (worked example 9), arming that sets nothing, the ignored data, and edges from the joystick and from DDRA; power on; and PeekRegister against a twin chip that is never peeked.
The file was written before the chip: the first build failed to compile with CS0246, Riot6532 not found. With the chip written, every test passed on the first run. On 14 October 2026 dotnet test -c Release tests/Dbhq.Machines.Atari2600.Tests --filter "FullyQualifiedName~Riot6532Tests" passed 43 test cases, and the whole project (dotnet test -c Release tests/Dbhq.Machines.Atari2600.Tests) passed 249. dotnet build -c Release of the solution gave no warnings.
Every test shown able to fail
The fault pass ran on 14 October 2026 in a scratch copy outside the repository (python3 -I tools/probes/atari-2600/riot-faults.py /tmp/atari-riot-faults, which copies the projects, plants one fault at a time in Riot6532.cs, builds, runs Riot6532Tests and puts the file back). Two faults, T4 and D1, did not build at first, because warnings are errors (an unused field and unreachable code); they were rewritten to build and run again on their own (... riot-faults.py /tmp/atari-riot-faults-2 T4 D1). There is one test file, Riot6532Tests, so every fault was written against it. The figure is the number of its test cases that failed.
| Fault | Planted | Test cases that failed |
|---|---|---|
| T1 | first fall a whole divider after the write | 16 |
| T2 | flag set on reaching zero, one cycle early (the 1981 figure) | 24 |
| T3 | count after zero held at the divider | 8 |
| T4 | a read on the flag’s cycle clears it | 2 |
| T5 | TIMINT read clears the timer flag | 5 |
| T6 | INTIM read leaves the timer flag | 5 |
| T7 | a read after zero leaves the free run | 1 |
| T8 | the re-armed divider one cycle sooner | 1 |
| T9 | dividers 8 and 64 swapped | 11 |
| T10 | a timer write leaves the flag | 8 |
| T11 | the free run’s wrap protects a read | 1 |
| D1 | A4 not decoded on a write: edge control starts the timer | 4 |
| D2 | the port registers decode A3 | 1 |
| D3 | TIMINT drives bits 5 to 0 from the count | 2 |
| D4 | RAM of 64 bytes on write | 1 |
| I1 | an INTIM read ignores A3 | 1 |
| I2 | a timer write ignores A3 | 2 |
| I3 | the IRQ pin ignores the enables | 3 |
| E1 | the edge polarity inverted | 10 |
| E2 | TIMINT read leaves the edge flag | 9 |
| E3 | an INTIM read clears the edge flag | 1 |
| E4 | arming sets the flag when the level matches | 3 |
| E5 | the detector ignores DDRA | 3 |
| E6 | the detector ignores the joystick | 2 |
| E7 | the edge interrupt enable from A0 | 1 |
| P1 | port A output reads ORA, not the pin | 1 |
| P2 | port B output reads the pin | 1 |
| P3 | an ORA write kept only for output bits | 2 |
| P4 | port B reads its output register for every bit | 3 |
| O1 | power on keeps the RAM | 1 |
| O2 | power on keeps ORA and DDRA | 1 |
| O3 | power on keeps the polarity | 2 |
| O4 | power on keeps the interrupt enables | 1 |
| O5 | the power-on timer at divide by 1024 | 1 |
| O6 | a new chip not powered on | 6 |
| O7 | power on keeps the flags | 1 |
| K1 | Peek of TIMINT clears the edge flag | 2 |
| K2 | Peek of INTIM clears the timer flag | 2 |
| K3 | Peek of INTIM ends the free run | 4 |
No fault survived, and no test case went uncaught: the probe lists each test case with the faults that made it fail, and every one has at least one. The cases reached by a single fault only:
Ram_holds_all_128_bytes_and_no_two_addresses_share_a_cell: D4Section_5_a_port_a_output_reads_low_while_its_switch_pulls_it_low: P1Section_5_an_input_pin_reads_what_drives_it: P4Section_6_the_count_on_every_cycle_by_the_rule(timer: 660, divider: 1): T2Worked_example_1_read_028c_is_intim_and_sets_the_timer_interrupt_enable: I1Worked_example_1_the_port_registers_repeat_every_eight_and_ignore_a5_and_a6: D2Worked_example_2_port_a_output_register_keeps_all_eight_bits: P3Worked_example_6_the_read_on_the_cycle_it_passes_zero(v: 16, intim: 0, flagOnCycle23: True): T2
After the review
The review of this task, the same day, planted four faults that every test above let through, and found the test that should have caught each one weaker than its name. Each test was strengthened, and each fault was added to riot-faults.py and run against the new tests alone (python3 -I tools/probes/atari-2600/riot-faults.py <scratch> I4 I5 E8 D5, 14 October 2026). Each was caught by the one test case written for it:
| Fault | Planted | Caught by |
|---|---|---|
| I4 | any A2-high read sets the timer enable from A3 | Worked_example_8_the_timer_enable_follows_a3_on_every_timer_read_and_write, which now reads TIMINT at $0285, where A3 is 0, with the enable on |
| I5 | an edge control write sets the timer enable from A3 | the same test, which now writes $0286 with the enable on |
| E8 | a port read clears the edge flag | Section_8_only_a_timint_read_clears_the_edge_flag, which now reads all four port registers with the flag set |
| D5 | RAM writes decode A0 to A7 | Ram_offsets_above_127_reach_the_cell_a0_to_a6_pick, new: the bus passes a mirror’s address whole |
The old TIMINT check read $028D, whose A3 is 1, with the enable already on, so a fault that set the enable from A3 could not show. The review also found that the guesses in docs/known-differences.md were described as guesses but not tagged; each now carries [guessing - verify], the power-on bullet and the comment on PowerOn no longer state the timer’s run before the CPU’s reset as fact, and PB2, PB4 and PB5 reading 1 joins the list above as guess 6, with the timer’s early run as guess 7.