# Undocumented, undefined and unimplemented behaviour ## How to read this page Three different things get confused under one heading, and they are kept apart here: | Tag | Meaning | | --- | --- | | **documented** | The *TMS34010 User's Guide* states it. A core must do it. | | **undefined** | The manual says the result is undefined, or says nothing. A core must choose, document the choice, and not pretend the choice is evidence. | | `[unverified]` | The only account available is MAME's. It may be right; nothing here establishes that it is. | There is **no hardware-tier oracle for this processor** ([validation.md](validation.md)), which changes what this page can be. On the Z80 and 8086 there are captured corpora that settle undefined flags with a number from a die. Here there are none. So every `[unverified]` below stays `[unverified]` until somebody puts a TMS34010 on a bench. All MAME citations are `src/devices/cpu/tms34010/` at GitHub tag `mame0285`, BSD-3-Clause, copyright Alex Pasadyn and Zsolt Vasvari (with Aaron Giles on `34010gfx.hxx`). Note that these files moved from `src/mame/midway/` to `src/mame/williams/` **after** 0.285, so line numbers against `master` will not match; pin the tag. --- ## Undefined opcodes: two behaviours, not one The TMS34010's opcode space is 16 bits, dispatched in MAME through a 4096-entry table on `opcode >> 4`. Every slot is filled. The undefined encodings split into two groups, and **MAME treats them differently on purpose**: **`illop` — the documented illegal-opcode trap.** 624 of the 4096 slots. Pushes PC and ST, resets ST, vectors through 0xFFFFFC20 (which is TRAP 30), and charges 16 cycles (`34010ops.hxx:92-108`). The 16 is `COUNT_UNKNOWN_CYCLES`, i.e. invented. **documented** that TRAP 30 is the illegal-opcode vector; `[unverified]` for the cycle count. **`unimpl` — encodings that do not trap.** 154 of the 4096 slots. MAME logs `"TMS34010 reserved opcode %04Xh encountered at %08x"`, charges one cycle, and **continues to the next instruction** (`34010ops.hxx:78-90`). The comment at `:81` states the reason as a fact about hardware: > Not all illegal opcodes cause TRAP 30 exceptions on TMS34010, and some > games only work because of this. and names two cases: **9 Ball Shootout** (`9ballsht`) calls to 0xFFDF7468 and expects execution to resume at 0xFFDF7470 even though 0xFFDF7460 holds the word 0x0001 (`:83-85`); and **Super High Impact** (`shimpact`) executes the word 0x0007 at several entry points (`:87`). This is the most important single fact on this page. It is **hardware evidence of a kind**: two shipped games, on real boards, depended on certain reserved encodings *not* trapping, which is why MAME's authors made the distinction. It is not a captured value — nobody read a register off a die — so it does not reach tier 1. Call it what it is: behaviour inferred from shipped software, which is the same class of evidence as a self-checking test program. The *partition* (which 154 encodings are inert and which 624 trap) is `[unverified]` in its details; only the two named cases have any independent support. A core must implement both behaviours and must expose which encodings it treats which way, because that partition is a testable claim and somebody will eventually test it. **`TRAP n`** vectors to `0xFFFFFFE0 - (n << 5)` (`34010ops.hxx:1905`). **documented.** --- ## Odd program counters `CALL`, `CALLA`, `EXGPC`, `JUMP`, `RETI`, `RETS`, `TRAP` and the 8-bit conditional jumps all pass their target through `CORRECT_ODD_PC` (`34010ops.hxx:28`), which logs and then masks `m_pc &= ~0x0f`. So MAME silently rounds a misaligned jump target down to the nearest word. What real hardware does with a PC whose low four bits are not zero is **not documented here and not reproduced by MAME**. `[unverified]`. There is a related inconsistency inside MAME worth knowing about if you lockstep against it: `device_reset` masks the reset vector with `& 0xfffffff0` (`tms34010.cpp:796`), but the *deferred* reset path taken when `halt_on_reset` is set does **not** (`:874`). A ROM with a non-word-aligned reset vector would start at different PCs depending on a configuration flag. No known ROM does this. --- ## Reserved I/O register bits, and inert registers The I/O file is thirty-two 16-bit registers. Not all of them do anything, and not all of their bits are defined. **Registers MAME stores and never reads** — a write is remembered, a read returns it, nothing else happens (`tms34010.cpp:1584`): | Register | Note | | --- | --- | | HESYNC, VESYNC | Sync-generator values. A core that leaves the CRTC to the host need not care; a *host* must. **documented** that they program the sync generator. | | HSTDATA | The host-interface data register. MAME never uses it: `host_r`/`host_w` read and write memory directly through `(HSTADRH << 16) | HSTADRL` and bypass HSTDATA entirely (`tms34010.cpp:1663`, `:1722`). `[unverified]` what a read of HSTDATA returns on hardware when no host transfer is in flight. | | PMASK | See below. | | The four reserved slots at C0000170-C00001A0 | MAME names them `REG_UNK23`..`REG_UNK26` and calls them "RESERVED" (`tms34010.h:87-90`). Their behaviour on hardware is **undefined**; a core should store and return them, and say it is a guess. | **Registers synthesized on read**, i.e. whose stored value is irrelevant: - **HCOUNT** is computed from the screen's horizontal position scaled to HTOTAL and offset by HEBLNK (`tms34010.cpp:1556-1568`). A write is stored and then ignored. **documented** that HCOUNT tracks the horizontal counter; `[unverified]` what writing it does on hardware. - **REFCNT** is computed as `(total_cycles() / 16) & 0xfffc` (`:1570-1571`) — a synthetic DRAM refresh counter with no refresh behind it. `[unverified]`. **INTPEND's bits are not all writable. documented, and MAME enforces it** (`tms34010.cpp:1345-1353`, and the TMS34020 copy at `:1482-1490`): X1P, X2P and HIP are read-only, and WVP and DIP accept only zeros — software can clear them but not set them. A core that lets software raise its own display interrupt by writing INTPEND is wrong, and a program that clears an interrupt this way will behave differently. **DPYINT is returned early on purpose.** Reading INTPEND fabricates a set DI bit when `VCOUNT + 1 == DPYINT` and the scanline timer has less than `attotime::from_hz(40000000/8/3)` left to run (`tms34010.cpp:1571-1582`). MAME's own comment gives the reason: *Cool Pool loops in mainline code on the appearance of the DI, even though they have an IRQ handler. For this reason, we return it signalled a bit early in order to make it past these loops.* The 40 MHz constant is hardcoded regardless of the CPU's actual clock. This is a **game-specific workaround in an emulator**, not hardware behaviour, and it is precisely the kind of thing a lockstep will find. `[unverified]` — do not copy it. **Interlace is a fatal error in MAME.** Clearing DPYCTL bit 14 raises `fatalerror("Interlaced video configured on the TMS34010 (unsupported)")` (`tms34010.cpp:1087`). Interlaced operation is **documented** in the manual and simply not emulated. **HEBLNK/HSBLNK changes are debounced** — MAME reconfigures the screen only after a horizontal-blank change has been stable for more than two frames, "because many games play with the HEBLNK/HSBLNK for effects" (`tms34010.cpp:1071-1080`). A heuristic, not hardware. **`REV` returns a hardcoded 0x0008** for both the TMS34010 and the TMS34020 (`34010ops.hxx:1887-1893`). The real silicon-revision value depends on the part. `[unverified]`. **`EMU` is a NOP** — MAME's comment: "in RUN state, this instruction is a NOP", 6 cycles (`34010ops.hxx:1543-1547`). `EMU` is the emulator-mode entry instruction and is **documented** to do nothing outside emulation mode. --- ## What MAME's core does not implement at all Each of these is a place where a core written from the manual will **diverge from MAME**, and the divergence is MAME's. **Plane masking (PMASK) is entirely unimplemented.** Writing a nonzero PMASK logs "Plane masking not supported." once and is then ignored (`tms34010.cpp:1277`; the TMS34020's PMASKL/PMASKH at `:1429`). Sixteen `/* TODO: plane masking */` markers sit in the pixel read and write primitives (`:391`, `:400`, `:405`, `:431`, `:438`, `:446`, `:456`, `:467`, `:482`, `:487`, `:498`, `:504`, `:516`, `:522`, `:534`, `:543`). PMASK is **documented** in the manual. Implement it; expect the divergence; record it as MAME's. **Window checking modes 1 and 2 are incomplete.** `apply_window` logs "apply_window window mode %d not supported!" for **mode 2** (write inside the window, no interrupt) and then proceeds as if it were mode 3 (`34010gfx.hxx:89`). `LINE` logs "Window Checking Mode %d not supported" for anything other than mode 0 or 3 (`:26`). Mode 1 (interrupt on a write inside the window) *is* handled for PIXBLT — it sets WV in INTPEND and returns early (`:1002-1011`) — but not for LINE. All four modes are **documented**. **The shift-register transfer has no internal model.** `read_pixel_shiftreg` and `write_pixel_shiftreg` call the driver's `to_shiftreg`/`from_shiftreg` callbacks and return `m_shiftreg[0]`; if the driver installed no callback they `fatalerror` (`tms34010.cpp:409-417`, `:552-558`). The shift register itself is an 8192-entry array of which only element 0 is ever touched by the core (`tms34010.h:351`); the rest is driver scratch. SRT mode is selected purely by DPYCTL bit 11 (`tms34010.cpp:938-944`, `34010gfx.hxx:967-972`). All the Midway drivers install the callbacks (`midtunit.cpp:617-618`, `midwunit.cpp:636-637`, `midyunit.cpp:1254-1255`, `:1294-1295`) and Mortal Kombat's boot code really does use it ([mame-oracle.md](mame-oracle.md#sample-output)). **No 32-bpp block transfer.** MAME's blitter generator instantiates 1, 2, 4, 8 and 16 bits per pixel only; 32-bpp goes through the single-pixel path. `[unverified]` whether hardware blits 32-bpp; PSIZE = 32 is a TMS34020 feature (`tms34010.cpp:1421`). **The host interface is approximate.** MAME implements the documented *pre*-increment as a post-increment, with the comment "it says preincrement, but data is preloaded, so it is effectively a postincrement" (`tms34010.cpp:1718-1719`), because it does not prefetch. The increment is a fixed 0x10 bits in both directions (`:1666`, `:1724`), so the TMS34020's larger increment modes are not modelled. HSTCTLL's read/write masks deliberately split CPU-side and host-side privileges (`:1310-1320`), and the INTIN edge is described in the source itself as something that "should really be state-based, but the functions don't exist!" (`:1324`, `:1471`). **Interrupts are not polled per instruction.** MAME checks for interrupts once at the top of each `execute_run` timeslice (`tms34010.cpp:882-883`) and otherwise only when ST is written (EINT, POPST, RETI, PUTST — `:216-221`), when INTENB is written (`:1342`), or from the window-violation path. `check_interrupt` also early-returns unless the CPU is inside its execute loop (`:621-622`). Hardware accepts an interrupt at an instruction boundary. **This will produce timing divergences in any lockstep and they are not core bugs.** **A halted CPU takes no interrupts.** `execute_run` returns immediately when HSTCTLH bit 15 is set, with the comment "Absolutely no interrupts must be taken!!!" (`tms34010.cpp:862-868`). **documented.** **Big-endian TMS34020 mode is unimplemented**, stated in MAME's own file header (`tms34010.cpp:10-11`). **39 of the TMS34020's 53 new opcode bodies do nothing but log their name** — see [start-here.md](start-here.md#10-the-tms34020-in-one-section) for the list. --- ## Two actual bugs in MAME's core Found while reading the source for this page. They are recorded because a lockstep against MAME will hit them and the right response is to trust the manual, not to "fix" the core to match. **1. `ADDC` computes the carry-out from the wrong operands.** `34010ops.hxx:349-350` carries the comment *"I'm not sure to which side the carry is added to, should verify it against the examples"*. The implementation is `r = a + b + (C ? 1 : 0)` followed by `SET_NZCV_ADD(a, b, r)` — the carry-out is derived from `a` and `b` alone, ignoring the incoming carry. So `ADDC` where `a + b == 0xFFFFFFFF` and C = 1 produces `r == 0` and leaves C **clear**, where hardware must set it. The comment is an author's uncertainty; the missing carry is a defect independent of it. **2. `write_pixel_32` drops the top sixteen bits.** `tms34010.cpp:485-489` calls `TMS34010_WRMEM_WORD(offset & 0xffffffe0, data)` where every sibling 32-bpp path — `write_pixel_t_32` (`:499-506`), `write_pixel_r_32` (`:541-546`) and `read_pixel_32` (`:403-407`) — uses the DWORD accessor. A 32-bpp opaque pixel write with no raster op writes only its low word. **A live debugger breakpoint is still in the shipped source.** `34010gfx.hxx:208-216` contains, unguarded by any `#if 0`: `if ((offset << 3) == 0x02005010 && data == 0x0000) { machine().debug_break(); }`. Not a behaviour difference, but it tells you how much of this core is still somebody's working scratchpad. --- ## What this page cannot tell you Everything above is either the manual or MAME. There is no bench capture, no cycle log, no die photo, no second independent implementation whose disagreement would be informative ([validation.md](validation.md)). Specifically undetermined, and marked `[unverified]` wherever they appear elsewhere in these documents: - the register file's contents after reset (MAME zeroes them; the manual says undefined); - the exact partition of the 778 undefined encodings into trapping and non-trapping; - the flag results of `DIVS`/`DIVU`/`MODS`/`MODU` on a zero divisor or an overflowing quotient; - what a misaligned jump target does; - what reading a write-only or reserved I/O register returns; - every cycle count marked `COUNT_UNKNOWN_CYCLES` in MAME ([timing.md](timing.md)). If a later session finds a hardware-tier source for any of these, it belongs in [validation.md](validation.md) with its tier stated, and this page should shrink.