The 13-bit address bus
The 6507 has address lines A0 to A12, so every address is taken modulo 8 KiB: $F000 and $1000 are the same
place. Three chips decode the bus:
| Address (13 bits) | What | How it is decoded |
|---|---|---|
$0000-$007F | TIA registers | A12 low and A7 low; a write uses address lines A0-A5, so $40-$7F repeats $00-$3F (the Programmer’s Guide calls the TIA address “6 bit”); a read is mirrored eight times in the window, at $00, $10, $20 … $70 (Nocash) |
$0080-$00FF | RIOT RAM, 128 bytes | A12 low, A9 low, A7 high. The zero page, and the stack at $0180-$01FF is the same RAM |
$0280-$029F | RIOT I/O and timer | A12 low, A9 high, A7 high; the registers repeat in the range |
$1000-$1FFF | Cartridge ROM | A12 high. Bank-switching hotspots are decoded here (and a few below) |
The mirrors of the TIA and the RAM are real and used by some programs. The operand of an instruction shows the names listed below only at those exact
addresses, but the note of the instruction in the disassembly names every mirror too (“TIA COLUBK (a mirror of $09)”, “RIOT RAM $F0”), by the decoding described here and in
Address decoding. The decoding in the table agrees with Nocash’s Atari 2600 Specifications
(“Memory Mirrors”): the TIA is selected by A12=0 and A7=0, the RAM by A12=0, A9=0 and A7=1, the RIOT I/O by A12=0, A9=1 and
A7=1, and the cartridge by A12=1. The same document says the TIA lies at $0000-$007F, $0100-$017F,
$0200-$027F and so on up to $0F00-$0F7F, that the RAM mirrors at $0180-$01FF, $0480-$04FF,
$0580-$05FF and so on (the stack uses $0180), and that each $80-byte RIOT I/O area holds sixteen copies of the
ports, eight bytes apart, each with two copies of INTIM and of INSTAT (for example $0284 and $0286). The 13-bit
address bus and the 8 KiB mirroring of the whole space are also from that document (the CPU space repeats every $2000).
What was checked against which source (sources are kept in the project’s samples folder):
- Verified against the Stella Programmer’s Guide (Steve Wright, 1979; the 1993 reconstructed copy on AtariHQ,
pages 45 and 46, “Write address summary” and “Read address summary”), Nocash’s specification and Stella’s
own debugger tables (
CartDebug.cxx,ourTIAMnemonicW,ourTIAMnemonicR,ourIOMnemonic): every register name and address in the three tables below, the strobe registers (WSYNC,RSYNC,RESP0toRESBL,HMOVE,HMCLR,CXCLR), the 128 bytes of RAM at$80-$FF, and the four timer addresses with their intervals of 1, 8, 64 and 1024 clocks. - Verified against the Programmer’s Guide: the one-line meaning of each TIA register as far as the guide’s summaries
give it, the dumped inputs (
INPT0toINPT3, discharged by D7 ofVBLANK) and the latched inputs (INPT4andINPT5, latch enabled by D6 ofVBLANK), the joystick and console-switch bits ofSWCHAandSWCHB, and the timer rule (counts down per interval, then at one count per clock after zero). - Sources of the bit layouts and the RIOT semantics (all kept in the project’s samples folder
a26/sources, with URL, size and SHA-256 insamples/README.md): the Programmer’s Guide and Nocash for the TIA bits; for the RIOT the MOS 6532 RIOT data sheet as an OCR text (mos-6532-riot-reversing.txt, from a copy of the data sheet on reversing.pl; a third-party scan, not the MOS original), and the text of Stella’sM6532.cxxandM6532.hxx(read to check behaviour, never copied: GPL). - Settled from Nocash:
INPT4is the fire button of the left joystick port (player 0, port 1) andINPT5that of the right port (player 1, port 2): Nocash’s joystick table lists “Pin 6: INPT4.7 for player P0, INPT5.7 for player P1, button, 0 = pressed” and his pin-out table “6 INPT4 (port 1) INPT5 (port 2)”. The Programmer’s Guide itself only says that the trigger buttons connect to these two ports, and that the paddle and keyboard text uses INPT0, INPT1 and INPT4 for the keypad’s columns.
Vectors
Three 16-bit little-endian addresses at the top of the 6502’s memory: NMI at $FFFA, RESET at $FFFC and IRQ/BRK at
$FFFE. With 13 address lines they are read from $1FFA-$1FFF, the last six bytes of the bank that is in the window. The 6507
has no interrupt pins, so a 2600 program uses only RESET (and BRK, which many programs use as a second entry). The values are usually
written for $F000, such as $F000 in both starfield.bin and flapping.bin, and the explorer shows the code at the
address you choose in the options bar ($F000 by default).
Banked ROMs have vectors in every bank. On real hardware the console does not know which bank is selected at power-up, so a good ROM has a reset vector in every bank that leads to the same code. The explorer reads the vectors of the bank chosen in the options bar (the scheme’s usual start bank by default) and tabulates the vectors of every bank.
TIA registers
The names are those of the standard “stella” register file. Reading and writing the same address reach different registers; a name with a slash is write / read. The explorer cannot tell a read from a write, so it shows both names.
| Address | Name | What |
|---|---|---|
| $00 | VSYNC/CXM0P | Write: vertical sync (bit 1). Read: collision of missile 0 with players |
| $01 | VBLANK/CXM1P | Write: vertical blank, input latch, paddle dump. Read: collision of missile 1 with players |
| $02 | WSYNC/CXP0FB | Write: halt the CPU until the next line. Read: player 0 with playfield and ball |
| $03 | RSYNC/CXP1FB | Write: reset the horizontal sync counter. Read: player 1 with playfield and ball |
| $04 | NUSIZ0/CXM0FB | Write: number and size of player and missile 0. Read: missile 0 with playfield and ball |
| $05 | NUSIZ1/CXM1FB | Write: number and size of player and missile 1. Read: missile 1 with playfield and ball |
| $06 | COLUP0/CXBLPF | Write: colour of player and missile 0. Read: ball with playfield |
| $07 | COLUP1/CXPPMM | Write: colour of player and missile 1. Read: players with players, missiles with missiles |
| $08 | COLUPF/INPT0 | Write: colour of playfield and ball. Read: paddle input 0 |
| $09 | COLUBK/INPT1 | Write: colour of the background. Read: paddle input 1 |
| $0A | CTRLPF/INPT2 | Write: playfield control and ball size. Read: paddle input 2 |
| $0B | REFP0/INPT3 | Write: reflect player 0. Read: paddle input 3 |
| $0C | REFP1/INPT4 | Write: reflect player 1. Read: fire button of joystick 0 |
| $0D | PF0/INPT5 | Write: playfield graphics, first part. Read: fire button of joystick 1 |
| $0E | PF1 | Playfield graphics, second part |
| $0F | PF2 | Playfield graphics, third part |
| $10 | RESP0 | Reset the position of player 0 |
| $11 | RESP1 | Reset the position of player 1 |
| $12 | RESM0 | Reset the position of missile 0 |
| $13 | RESM1 | Reset the position of missile 1 |
| $14 | RESBL | Reset the position of the ball |
| $15 | AUDC0 | Audio control of channel 0 |
| $16 | AUDC1 | Audio control of channel 1 |
| $17 | AUDF0 | Audio frequency of channel 0 |
| $18 | AUDF1 | Audio frequency of channel 1 |
| $19 | AUDV0 | Audio volume of channel 0 |
| $1A | AUDV1 | Audio volume of channel 1 |
| $1B | GRP0 | Graphics of player 0 |
| $1C | GRP1 | Graphics of player 1 |
| $1D | ENAM0 | Enable missile 0 |
| $1E | ENAM1 | Enable missile 1 |
| $1F | ENABL | Enable the ball |
| $20 | HMP0 | Horizontal motion of player 0 |
| $21 | HMP1 | Horizontal motion of player 1 |
| $22 | HMM0 | Horizontal motion of missile 0 |
| $23 | HMM1 | Horizontal motion of missile 1 |
| $24 | HMBL | Horizontal motion of the ball |
| $25 | VDELP0 | Vertical delay of player 0 |
| $26 | VDELP1 | Vertical delay of player 1 |
| $27 | VDELBL | Vertical delay of the ball |
| $28 | RESMP0 | Reset missile 0 to player 0 |
| $29 | RESMP1 | Reset missile 1 to player 1 |
| $2A | HMOVE | Apply the horizontal motion registers |
| $2B | HMCLR | Clear the horizontal motion registers |
| $2C | CXCLR | Clear the collision latches |
RIOT registers
The 6532 RIOT has 128 bytes of RAM at $80-$FF (not named in the disassembly) and these registers. The same addresses and names were
checked against the register numbers js7800 uses for the 7800’s RIOT, which is the same chip at the same addresses.
| Address | Name | What |
|---|---|---|
| $280 | SWCHA | Port A data: the joysticks |
| $281 | SWACNT | Port A data direction |
| $282 | SWCHB | Port B data: the console switches |
| $283 | SWBCNT | Port B data direction |
| $284 | INTIM | Read: the timer |
| $285 | INSTAT | Read: timer interrupt flags (Nocash: “Timer Status, read only, undocumented”; the Programmer’s Guide does not list it). The name differs: Nocash writes INSTAT, Stella’s debugger TIMINT |
| $294 | TIM1T | Set the timer, one count per cycle |
| $295 | TIM8T | Set the timer, one count per 8 cycles |
| $296 | TIM64T | Set the timer, one count per 64 cycles |
| $297 | T1024T | Set the timer, one count per 1024 cycles |
| $29C | TIM1I | Set the timer, one count per cycle, with address line A3 set. Name from Stella’s debugger (ourIOMnemonic); not in Nocash’s list or the Programmer’s Guide. The MOS 6532 data sheet says address line A3 enables the timer interrupt to the IRQ pin (A3 = 1 enables, 0 disables; table 1, note (a)); the 6507 has no IRQ pin, so on the 2600 it has no visible effect. Stella gives the names and never looks at A3 |
| $29D | TIM8I | Set the timer, one count per 8 cycles, A3 set (as $29C) |
| $29E | TIM64I | Set the timer, one count per 64 cycles, A3 set (as $29C) |
| $29F | T1024I | Set the timer, one count per 1024 cycles, A3 set (as $29C) |
TIA write registers: the bits
Bit numbers are D7 (the high bit) to D0. Bits not listed are not used (they are ignored on a write). From the Programmer’s Guide (“Write address detailed functions”, pages 43 to 49) and Nocash’s tables; where the two say the same only one is quoted. The disassembly shows the
meaning of an immediate value stored in one of these registers in the note of the STA, STX or STY (for the pair LDA #$9E, STA COLUBK the note reads “$9E = colour (hue) 9; luminance 7”).
| Address | Name | Bits | Meaning |
|---|---|---|---|
| $00 | VSYNC | D1 | vertical sync: 1 starts it, 0 stops it (hold it for three scanlines) |
| $01 | VBLANK | D7, D6, D1 | D1: 1 starts vertical blank, 0 stops it. D6: 1 enables the latches of INPT4 and INPT5, 0 disables them (and resets them to 1). D7: 1 dumps INPT0 to INPT3 to ground, 0 removes the ground |
| $02 | WSYNC | strobe | any value: the CPU is halted (RDY low) until the start of the next horizontal blank |
| $03 | RSYNC | strobe | any value: resets the horizontal sync counter (for chip testing) |
| $04, $05 | NUSIZ0, NUSIZ1 | D5-D4, D2-D0 | D5-D4: missile width 1, 2, 4 or 8 clocks (00, 01, 10, 11). D2-D0: player copies and size: 0 one copy; 1 two copies close; 2 two copies medium; 3 three copies close; 4 two copies wide; 5 double-size player; 6 three copies medium; 7 quad-size player |
| $06 to $09 | COLUP0, COLUP1, COLUPF, COLUBK | D7-D4, D3-D1 | D7-D4: colour (hue) 0 to 15; D3-D1: luminance 0 to 7 (D0 is unused). On PAL the hues differ and on SECAM only the luminance counts (an RGB value 0 to 7) |
| $0A | CTRLPF | D5-D4, D2, D1, D0 | D0: reflect (0 the right half repeats the left, 1 mirrors it). D1: score mode (the left half is drawn in COLUP0, the right in COLUP1; only when D2 = 0). D2: priority (1 puts playfield and ball above players and missiles; the score bit is then ignored). D5-D4: ball width 1, 2, 4 or 8 clocks |
| $0B, $0C | REFP0, REFP1 | D3 | 1 reflects the player (bit 0 of GRP on the left), 0 draws bit 7 on the left |
| $0D | PF0 | D7-D4 | the first four playfield dots, D4 leftmost to D7; 1 draws the dot in COLUPF, 0 in COLUBK |
| $0E | PF1 | D7-D0 | the next eight dots, D7 leftmost to D0 |
| $0F | PF2 | D7-D0 | the last eight dots of the left half, D0 leftmost to D7. Each dot is four clocks wide; with reflect the right half is PF2 D7-D0, PF1 D0-D7, PF0 D7-D4 |
| $10 to $14 | RESP0, RESP1, RESM0, RESM1, RESBL | strobe | any value: the object starts at the beam’s current position (inside horizontal blank it is at the left edge; Nocash, Stella and Gopher2600 give pixel 3 for players and 2 for missiles and ball, Towers says the first player pixel is pixel 1: see the position counters) |
| $15, $16 | AUDC0, AUDC1 | D3-D0 | sound type: 0 and B constant (silent); 1 4-bit poly; 2 divide by 15 then 4-bit poly; 3 5-bit poly then 4-bit poly; 4 and 5 divide by 2 (pure tone); 6 and A divide by 31 (pure tone); 7 5-bit poly then divide by 2; 8 9-bit poly (white noise); 9 5-bit poly; C and D divide by 6; E divide by 93; F 5-bit poly divided by 6 |
| $17, $18 | AUDF0, AUDF1 | D4-D0 | the 30 kHz clock (31,399.5 Hz NTSC, 31,113.1 Hz PAL, two per scanline) divided by n + 1 |
| $19, $1A | AUDV0, AUDV1 | D3-D0 | volume 0 (off) to 15 |
| $1B, $1C | GRP0, GRP1 | D7-D0 | the eight dots of the player, D7 on the left (unless reflected); 0 transparent, 1 the player colour |
| $1D, $1E, $1F | ENAM0, ENAM1, ENABL | D1 | 1 shows the missile or ball, 0 hides it |
| $20 to $24 | HMP0, HMP1, HMM0, HMM1, HMBL | D7-D4 | horizontal motion as a 4-bit two’s complement number, applied by HMOVE: 0 none; 1 to 7 move left by that many clocks; 8 to 15 (−8 to −1) move right by 16 minus the value. Do not change them within 24 cycles of HMOVE |
| $25, $26, $27 | VDELP0, VDELP1, VDELBL | D0 | 1 delays the player or ball: a write of GRP0 shows only when GRP1 is written (and ENABL when GRP1 is written); 0 no delay |
| $28, $29 | RESMP0, RESMP1 | D1 | 1 hides the missile and locks it to the centre of its player (offset +3 for a normal, +6 for a double and +10 for a quad-size player); 0 frees it |
| $2A | HMOVE | strobe | any value: adds the five motion registers to the object positions (use it right after WSYNC; it blanks the first 8 pixels of the line it is struck in: see HMOVE timing) |
| $2B | HMCLR | strobe | any value: clears the five motion registers |
| $2C | CXCLR | strobe | any value: clears all fifteen collision latches |
The vertical-delay description says one thing the two sources word differently: the Guide says the delay is “one vertical line”, Nocash that GRPx is copied when GRPy is written. The page follows Nocash, who states the mechanism (a second register that is loaded when the other player’s register is written). The priority order is, normally: P0 and M0, P1 and M1, the ball and playfield, the background; with CTRLPF D2 set: the playfield and ball first.
TIA read registers: the bits
A read decodes only address lines A0 to A3, so the registers are at $30 to $3D in the TIA’s own numbering and at every address whose low four bits are the same (the table above lists them at $00 to $0D, the form the programs use). The bits not listed read as undefined.
| Address | Name | D7 | D6 |
|---|---|---|---|
| $00 | CXM0P | missile 0 and player 1 | missile 0 and player 0 |
| $01 | CXM1P | missile 1 and player 0 | missile 1 and player 1 |
| $02 | CXP0FB | player 0 and the playfield | player 0 and the ball |
| $03 | CXP1FB | player 1 and the playfield | player 1 and the ball |
| $04 | CXM0FB | missile 0 and the playfield | missile 0 and the ball |
| $05 | CXM1FB | missile 1 and the playfield | missile 1 and the ball |
| $06 | CXBLPF | the ball and the playfield | unused |
| $07 | CXPPMM | player 0 and player 1 | missile 0 and missile 1 |
A 1 means the two objects overlapped since the last CXCLR; a 0 means they did not. The fifteen latches are read two at a time, usually in vertical blank. The inputs:
| Address | Name | D7 |
|---|---|---|
| $08 to $0B | INPT0 to INPT3 | the paddle inputs (dumped): the capacitor charged through the paddle’s pot makes the bit go 1; D7 of VBLANK = 1 discharges it. Time how long it takes to read 1 |
| $0C | INPT4 | the fire button of the left joystick port (player 0): 0 = pressed. With the latch enabled (VBLANK D6 = 1) it stays 0 once the button has been pressed, until the latch is disabled |
| $0D | INPT5 | the same for the right port (player 1) |
INPT4 and INPT5 are assigned from Nocash’s joystick table (pin 6: INPT4.7 for P0, INPT5.7 for P1) and his pin-out table (INPT4 port 1, INPT5 port 2); the Programmer’s Guide does not say which is which.
RIOT registers: the bits, the timer and the interrupt flags
The sources for this section: the Programmer’s Guide (“The PIA (6532)”, pages 12 to 15 of the guide), Nocash, the MOS 6532 RIOT data sheet (an OCR copy of it from reversing.pl, see the sources in the list under the register tables; it is a scan of a MOS Technology document, not an original file) and the text of Stella’s M6532.cxx.
| Address | Name | Bits | Meaning |
|---|---|---|---|
| $280 | SWCHA | D7-D0 | port A data. Read: the pins, 0 = a switch is closed. Joysticks: D7 right, D6 left, D5 down, D4 up of player 0; D3 right, D2 left, D1 down, D0 up of player 1. Paddle triggers: D7 paddle 0, D6 paddle 1, D3 paddle 2, D2 paddle 3. Keypad: the pins are outputs that select a row (D7 bottom row of player 0 ... D4 top row; D3 to D0 for player 1). A write sets the output register; a pin whose SWACNT bit is 1 drives it. After writing the keypad rows wait about 400 microseconds before reading the TIA inputs |
| $281 | SWACNT | D7-D0 | data direction of port A: bit n = 0 makes pin PAn an input, 1 an output (write $00 for joysticks and paddles, $FF for a keypad) |
| $282 | SWCHB | D7, D6, D3, D1, D0 | the console switches (read): D7 player 1 difficulty (0 = B, amateur; 1 = A, pro), D6 player 0 difficulty, D3 colour (1) or black and white (0; always 0 on SECAM consoles), D1 game select (0 = pressed), D0 game reset (0 = pressed). D5, D4 and D2 are not connected |
| $283 | SWBCNT | D7-D0 | data direction of port B: the console wires it as inputs and programs write $00; the three unconnected pins (D5, D4, D2) can be made outputs to store three bits (Combat does) |
| $284 | INTIM | D7-D0 | the timer (read). It counts down once per interval from the value written to TIM1T to T1024T; after it reaches 0 it holds 0 for one interval, then shows $FF and counts down once per cycle whatever the interval, so the program can tell how long ago it expired. Reading it sets the interval counting again (and clears the timer flag) |
| $285 | INSTAT | D7, D6 | the interrupt flags (read): D7 the timer flag (the timer ran out since it was set), D6 the PA7 edge flag. D5-D0 read as 0 |
The timer
A write to $294 to $297 (TIM1T, TIM8T, TIM64T, T1024T) sets the timer to the value and chooses the interval (address lines A1 and A0: 1, 8, 64 or 1024 cycles per count; with A4 = 1 and A2 = 1). The timer is decremented once straight away (a value of 0 expires at once). The timer flag is cleared by this write.
A read of the timer ($284) clears the flag too, unless the timer wrapped on that very cycle. The data sheet and Nocash differ in their account of INSTAT: Nocash calls bit 7 “underflow flag 2, since the last write of TIMnnT” and bit 6 “underflow flag 1, since the last read of INSTAT”; the data sheet and Stella
make bit 7 the timer flag (cleared by writing or reading the timer) and bit 6 the PA7 edge flag (cleared by reading INSTAT). This page follows the data sheet and Stella, which agree.
Edge detect on PA7
PA7 (SWCHA D7, the right direction of joystick 0, also the first paddle’s trigger) can set a flag when it changes. The flag is set on an active edge whether PA7 is an input or an output; the edge’s direction (and whether the interrupt is enabled) is chosen by a write to one of four addresses, with address line A4 = 0 and A2 = 1; the data written is ignored. On the 2600 these are:
| Address | A1 (interrupt enable) | A0 (edge) | Effect |
|---|---|---|---|
| $0284 | 0 | 0 | negative edge (high to low), interrupt disabled |
| $0285 | 0 | 1 | positive edge (low to high), interrupt disabled |
| $0286 | 1 | 0 | negative edge, interrupt enabled |
| $0287 | 1 | 1 | positive edge, interrupt enabled |
(A3 does not matter for these writes, so $028C to $028F do the same.) Reset disables the interrupt and selects the negative edge; the flag may be set during reset, so read INSTAT once after reset to clear it. The flag stays set until INSTAT is read. The 6507 has no IRQ pin, so enabling the interrupt does nothing on the 2600: the program polls bit 6 of INSTAT. Stella models only A0 (the polarity), as a flag set when PA7 changes in that direction, and ignores A1. Reads decode alike: A2 = 1 with A0 = 0 is the timer ($0284, $0286) and A0 = 1 is the interrupt flag register ($0285, $0287), A1 and A4 ignored. A3 = 1 on a timer write enables the timer interrupt (the “I” names TIM1I to T1024I at $29C to $29F); the data sheet advises reading the timer with A3 low after an interrupt so it does not interrupt again.
Address decoding of the RIOT
| Lines | Meaning |
|---|---|
| A12 low, A7 high | the RIOT is selected |
| A9 low (RS low) | RAM: $80-$FF and its mirrors $180-$1FF, $480-$4FF, $580-$5FF and so on |
| A9 high (RS high) | I/O registers, timer and edge detect |
| A2 low | the ports: A1 and A0 choose SWCHA (00), SWACNT (01), SWCHB (10), SWBCNT (11) |
| A2 high, A4 high (a write) | the timer: A1 and A0 choose the interval (00 1T, 01 8T, 10 64T, 11 1024T); A3 enables the timer interrupt |
| A2 high, A4 low (a write) | the edge detect control: A0 = polarity, A1 = interrupt enable |
| A2 high (a read) | A0 low: the timer; A0 high: the interrupt flags |
The disassembly note applies these rules to any address, so a store to $0394 shows as a mirror of TIM1T and a store to $0109 as a mirror of COLUBK. TIA writes use A0 to A5 (the unnamed addresses $2D to $3F do nothing), TIA reads use A0 to A3.
Not described
Known, not yet covered
- Reference: the exact cycle timing of the TIA (the position of the objects after a RESPx strobe or HMOVE at each cycle, the extra HMOVE offsets Nocash lists as “seem to apply only when HMxx = 0”) and the real analogue colour values are not described; the bit layouts are above and what the bits do is on the video, audio and controllers pages, the pins on the connectors page.
Unknown
- Reference: the 6532 data sheet was read as a page image of the Commodore Semiconductor Group (MOS) data sheet dated 2/81, 10 pages (
mos_6532_riot.pdf, 5,371,185 bytes, SHA-256a48e7f8a…57ce4, from the applefritter EightBit repository), and the table 1 rows, the timer example, the interrupt flag register and the edge-detect text on this page were checked against pages 7 to 10 of it. It is the MOS data sheet as Commodore reissued it, not a 1970s MOS print: bitsavers answered 403 for its own folder, and 6502.org returned 404. The 1982 MOS Technology data catalogue (bitsavers mirror) was downloaded as well. The earlier OCR text from reversing.pl agrees with the PDF on every row used here.