# Memory map, I/O ports, clocks, waits, interrupts Sources, cited by short name: **[TM]** Coleco's ColecoVision Technical Manual (tier 2); **[SCH]** the KiCad redraw of the schematic, Rev J, 2021 (tier 3: a community reading of the board); **[DB]** Dan Boris's hand-traced schematic, 2002 (tier 3, independent of [SCH]; his own note: "accuracy can not be guaranteed"); **[BIOS]** the OS-7 ROM itself, which we hold and which executes (the bytes are a fact; what they mean is our reading); **[CG]** Daniel Bienvenu's Coding Guide, which reprints Coleco's OS-7 listing "REV 7PRIME" (tier 3); **[MAME]** `coleco.cpp` at 0.285 (tier 5, detector); **[CLK]** Clock Signal's `ColecoVision.cpp` (tier 5). "Measured" means a MAME run made here ([mame-oracle.md](mame-oracle.md)): it says what MAME does, not what the console does. ## Memory One 74LS138 (U5) splits the 64K space into eight 8K blocks from A13-A15, enabled by `/MREQ` low and `/RFSH` high [SCH sheet 9; TM p. III-5 "using the U5 decoder"]. | Range | What | Notes | | --- | --- | --- | | `$0000-$1FFF` | BIOS ROM "OS-7", 8K (U2) | [TM]; the Super Game Module can put RAM here ([expansion.md](expansion.md)) | | `$2000-$3FFF` | nothing on the console; on the expansion connector | select `AD2000` leaves the board [SCH] | | `$4000-$5FFF` | nothing on the console; on the expansion connector | `AD4000` | | `$6000-$7FFF` | RAM, 1K (two 2114s, U3/U4), **mirrored 8 times** | the chip select is the whole `AD6000` block and the 2114s see A0-A9 only [SCH]; software uses `$7000-$73FF`; MAME maps `$6000-$63FF` mirror `$1C00` | | `$8000-$FFFF` | cartridge, four 8K selects (`/CS1`-`/CS4` = `AD8000`, `ADA000`, `ADC000`, `ADE000`) | "up to 32K x 8 ... selected in banks of 8K" [TM]; larger cartridges switch banks themselves ([cartridge.md](cartridge.md)) | Unmapped reads: MAME returns `$FF` for unmapped I/O ("comicbak relies on this", `coleco.cpp` l.182); for unmapped memory nothing in hand says what the bus holds (U5). BIOS RAM use: stack top `$73B9` (set at `$0003`, seen in the trace), OS work area at the top of the 1K, sound data from `$7020` [CG]. The expansion connector carries `/MEMMAPOVR` and `/IOMAPOVR` inputs that disable the two decoders [SCH sheet 9]: this is how the ADAM and the Super Game Module replace the BIOS and RAM. They are the board's first two sockets. ## I/O ports A second 74LS138 (U6) decodes I/O: enabled by `/IORQ` low and **A7 high**; its inputs are A6, A5 and `/WR` [SCH sheet 9, read off the drawing here]. Dan Boris's independent hand tracing ([DB], 2002, sheet 2; tier 3) draws the same chip the same way: A = `/WR`, B = A5, C = A6, G1 = A7, /G2A = `/IORQ`, /G2B = the expansion port's `EX_IO_EN` through an open-collector inverter; outputs Y0 `CTRL_EN_2` (`$80` write), Y2 `VDC_W`, Y3 `VDC_R`, Y4 `CTRL_EN_1` (`$C0` write), Y6 `AUD_W`, Y7 `CTRL_R`; Y1 and Y5 unused. So there are four 32-port blocks, each with a write strobe and a read strobe, and only A7-A5 (plus A0 for the VDP and A1 for the controllers) matter: | Ports | Write | Read | | --- | --- | --- | | `$80-$9F` | controller strobe: **keypad** segment selected (both ports) | not connected | | `$A0-$BF` | VDP: A0 = 0 data (`$BE`), A0 = 1 control (`$BF`) | VDP: A0 = 0 data, A0 = 1 status | | `$C0-$DF` | controller strobe: **joystick** segment selected (both ports) | not connected | | `$E0-$FF` | SN76489A sound (`$FF`) | controllers: A1 = 0 port 1 (`$FC`), A1 = 1 port 2 (`$FF`) | | `$00-$7F` | nothing on the console (A7 low); the expansion port's devices live here | | The BIOS uses `$BE`, `$BF`, `$80`, `$C0`, `$FC`, `$FF` (the trace shows writes to `$BE`, `$BF`, `$C0`, `$FF`). MAME's map is the same four blocks [MAME l.180-189]. Two consequences of the decode that no document states and that are **our inference from the two tracings** (U3, U4 in the brief): - The decoder looks at `/WR`, not `/RD`, and has no `/M1` term: **both tracings agree** on this. Any `/IORQ` cycle that is not a write selects a *read* strobe. The Z80's interrupt acknowledge is an `/IORQ` + `/M1` cycle with `/WR` high and the PC on the address bus, so an acknowledge while the low byte of PC is `$A0-$BF` would strobe the VDP's `/CSR` (the TMS9928A has no separate read-enable: `/CSR` low is the read): a data read that advances the VRAM address and refills the read-ahead buffer if A0 = 0, a status read that clears F, C and 5S if A0 = 1. A low byte in `$E0-$FF` would only enable a controller buffer (no side effect). Only the spinner's `/INT` can cause this (the NMI acknowledge has no `/IORQ`). MiSTer's `cv_addr_dec.vhd` (tier 4) gates both VDP and controller reads with `/RD`, so it does *not* do this; MAME's Z80 makes no port access during an acknowledge. Coleco's own schematic is not in the pinned manual scan (section V-1 is missing), so the drawing evidence is two community tracings; a console would settle it. - Writes to `$80-$9F` and `$C0-$DF` ignore the data byte. ## Clocks | Clock | Value | Source | | --- | --- | --- | | crystal | 7.15909 MHz | MAME `XTAL(7'159'090)`; [DB] sheet 4 labels Y1 "7.15909"; [TM] prints "7.19 MHz" (C4), then "divided by two ... the 3.58 MHz that is required for color burst", which fixes it at 7.15909 | | CPU and SN76489A | crystal / 2 = 3.579545 MHz | [TM] | | VDP | 10.738635 MHz, "derived from the 3.58 MHz clock by using a third harmonic wave shaping circuit" | [TM p. III-5]: the VDP is locked to the CPU at exactly 3:1 | | pixel | VDP / 2 = 5.3693175 MHz | TI data manual 3.6 | | VDP memory cycle | VDP / 4: "about 372 nanoseconds" | TI data manual 2.1.5 | So **one timeline in VDP clocks**: a CPU clock is 3, a pixel 2, a memory cycle 4, a line 342 pixels = 684 = **228 CPU clocks**. A frame is 262 lines = 59,736 CPU clocks (59.92 Hz) on the TMS9928A and 313 lines = 71,364 (50.16 Hz) on the TMS9929A [TI data manual table 3-3]; MAME reports 59.922738 Hz. The phase between the CPU clock and the VDP's dot counter at power-up is unknown (U6). Whether PAL consoles use the same crystal is unverified (U7); MAME's `colecop` does. ## The M1 wait state Every opcode fetch takes **5 clocks, not 4**. A 74LS74 (U8A) wired as a toggle and held reset whenever `/M1` is high pulls `/WAIT` low for one clock in each M1 cycle [SCH sheet 9, read here: D = /Q, clock = CPUCLK, /R = inverted /M1, Q through an open-collector 74LS05 to `/WAIT`; [DB] sheet 4 draws the same: U8A 74LS74A, `/CLR` from `/M1` through a 74LS04, Q through U7B to `WAIT`]. MAME models it (`z80_set_m1_cycles(4+1)`, "1 WAIT CLK per M1") and so does Clock Signal ("M1 cycles are extended by a single cycle"). Measured in MAME: `JP nn` 11, `LD SP,nn` 11, `LD HL,(nn)` 17, `LD A,L` 5, `CP n` 8, `CALL nn` 18 clocks. Every prefix byte is its own M1 cycle, so `DD`/`FD`/`ED`/`CB` instructions gain 2 (and `DD CB d op` gains 2: its last two bytes are not M1 fetches). The interrupt and NMI acknowledge cycles are M1 cycles too, and the flip-flop is cleared only while `/M1` is high, so on the drawings **every** M1 cycle gets the wait: opcode fetches, each HALT cycle, the NMI response and the interrupt acknowledge. MAME 0.285 (`z80.lst`, read here) applies `m_m1_cycles` in its `rop` macro only: opcode fetches and the HALT loop (which runs `@rop`) get 5, while `take_nmi` adds a fixed 5 and `take_interrupt` a fixed 2 + 5, so its acknowledges do **not** gain the clock. That is one clock per NMI, so one per frame against MAME (U8, C11). The Technical Manual's troubleshooting section has oscilloscope pictures of `/WAIT` and `/M1` (p. VII-8, 1 and 2 microseconds per division, "during blue menu screen"): the only hardware-captured view of this found, and qualitative. **z80-python has no M1 count to give the board** (open decision 3). Checked in `z80-python` at both 0.4.0 (`500608c`) and the local branch head (`65e7f08`): the constructor takes only `read_byte`, `write_byte`, `read_port`, `write_port`; `step()` returns the instruction's total T-states; the opcode fetch calls the same `read_byte` as a data read, so a board cannot tell an M1 fetch from a memory read; no source file mentions an M1 count, a wait hook or an opcode-fetch callback. ## The sound chip's READY wait The SN76489A's READY output is tied to `/WAIT` [DB sheet 4: pin 4 READY to the `Wait` net; SCH shows the two net names together; TM: "outputs a ready signal to the CPU when it has inputted the data"; Coleco's ADAM manual 2.2.5: "Wait-request hardware has been included in the system because the sound chip is a slow peripheral"]. TI's manual gives about 32 clocks of READY low per write. Measured in MAME: `OUT ($FF),A` costs **40 clocks** (11 + 1 for M1 + 28 of wait); Clock Signal's comment says "thirty-one (!) cycles". The three numbers (32 from the chip's manual, 28 and 31 from two emulators) are C9. A game's sound driver that writes eight registers a frame spends about 320 clocks (1.4 lines) waiting, so this is not optional for timing. ## Interrupts | Line | Source | Notes | | --- | --- | --- | | `/NMI` | the VDP's `/INT` pin | once a frame, at the end of line 191, if register 1 bit 5 is set; held until the status register is read ([vdp.md](vdp.md)). The Z80's NMI is edge-triggered: the board requests it on the falling edge only, and that edge also comes from *setting* the enable bit while the flag is already up | | `/INT` | the two spinner inputs, wired-OR | a short pulse per quadrature edge, not a level held until acknowledged ([controllers.md](controllers.md)). The BIOS runs in IM 1 (vector `$0038`, which jumps through the cartridge's `IRQ_INT_VECT` at `$801E`) | | `/RESET` | the console's switch | the BIOS starts at `$0000`: `LD SP,$73B9; JP $006E` [BIOS, trace] | The expansion connector also has `/INT` and `/NMI` (MAME routes both from its expansion device). ## The BIOS, as far as the board cares - 8,192 bytes at `$0000`. Dumps and hashes: [cartridge.md](cartridge.md). - At `$006E` it reads the word at `$8000` [BIOS bytes `2A 00 80 7D FE 55 ... 7C FE AA ... 2A 0A 80 E9`]: bytes **`55 AA`** make it jump at once through the pointer at `$800A`; anything else goes on to the title screen, which shows the cartridge's name from `$8024` if the bytes are **`AA 55`** and "TURN GAME OFF BEFORE INSERTING CARTRIDGE OR EXPANSION MODULE" otherwise (the no-cartridge screen, seen here under MAME). - Cartridge header [CG; consistent with Zaxxon's first bytes]: `$8000` magic, `$8002` `LOCAL_SPR_TBL`, `$8004` `SPRITE_ORDER`, `$8006` `WORK_BUFFER`, `$8008` `CONTROLLER_MAP`, `$800A` `START_GAME`, `$800C-$801D` the RST `$08-$30` vectors (3 bytes each), `$801E` `IRQ_INT_VECT`, `$8021` `NMI_INT_VECT`, `$8024` `GAME_NAME`. - **Byte `$0069` is the frame rate**: 60 (`$3C`) in the NTSC ROM, 50 (`$32`) in the PAL ROM (measured on both dumps; [CG] calls it `AMERICA`). Games read it for timing. - The title screen's delay is a loop in the ROM (about 12 s); modified ROMs shorten it ([cartridge.md](cartridge.md)). ## Who owns what | Piece | Owner | | --- | --- | | Z80 instruction set, IFFs, IM, HALT, NMI and INT acceptance | `z80-python` | | SN76489A registers, counters, noise, levels | `sn76489-python` | | TMS9928A/9929A | a `tms9918-python` core (recommended) or an in-board package (open decision 1) | | decode, mirrors, BIOS, RAM, the timeline, the M1 wait, the READY wait, NMI edge, INT pulse, controllers, cartridge boards, sockets | the board | | AY-3-8910 of the Super Game Module | `ay8910-python`, inside the add-on |