Chris Collins

Tools · retro

Memotech MTX emulator and Z80 IDE

A Memotech MTX500, MTX512 or RS128 in your browser — Z80 at 4 MHz, the TMS9929A video chip, the SN76489 sound chip, the Z80 CTC's interrupts, the IOBYTE memory paging, the keyboard matrix and .MTX tapes — running your own Memotech ROMs for MTX BASIC, or an open stand-in monitor, with a Z80 assembler, examples and a debugger with breakpoints beside the code.

Added

How to use it

The Memotech MTX (1983) was a black aluminium Z80 machine with the same video chip as the MSX, an SN76489 for sound, a Z80 CTC for its interrupts, and BASIC, an assembler and a front-panel monitor in 24 KB of ROM. Press Power on, or just Assemble & run in the Code & debug tab. Click the screen to give it the keyboard.

ROMs

Memotech’s ROMs are still copyright, and I couldn’t find anyone who owns them saying they may be shared, so this page doesn’t include them. Memotech went into receivership in 1985; Geoff Boyd’s Memotech Computers Ltd bought its assets in 1986. The MTX community and emulators distribute the ROMs anyway — MEMU’s documentation says they are "already available from several places on the net" and "were originally marketed by long defunct companies. Caveat Emptor" — and primrosebank.net notes that they "are not in the public domain". The details are in NOTICE.txt.

If you have the images (from your own MTX, or the copies that come with MEMU), drop them on the ROMs tab. They are recognised by checksum (the UK OS 9ca858cc, BASIC 87b4e59c, ASSEM 9d7538c3, and the German OS and BASIC) or by name, kept in this browser (IndexedDB), and the MTX restarts into MTX BASIC.

Without them the page runs the GW MTX monitor, an open stand-in for the OS ROM that I wrote for this page (MIT licence, Z80 source in mtx-data.js, assembled in your browser when the page opens). It sets the hardware up the way the real OS does — IM 2 interrupts from CTC channel 0 on every VDP frame, the keyboard matrix scanned in the interrupt, the screen in 40-column text mode — and gives you a prompt with D (dump), M (modify memory), G (call an address; RET comes back), I and O (ports), C, B and H, plus calls at $0040 that programs can use: OUTCH, PRINTS, GETKEY, INKEY, CLS, PRHEX2, PRHEX4, LOCATE, BEEP, TXTMODE, and a USERINT hook run every frame. It has no BASIC and no tape routine.

How to use it

Code & debug is a Z80 editor with the screen and debugger beside it. Pick an example and press Assemble & run (Ctrl/⌘+Enter):

  • Hello and Keyboard codes — text and keys through the monitor’s calls.

  • VDP sprites — four 16 × 16 sprites bouncing in Graphic 1, synchronised to the frame interrupt with HALT.

  • SN76489 sound — a scale and a fading chord. The MTX latches a byte with OUT (6),A and the chip takes it when the program reads port 3.

  • Graphic 2 bitmap — the 256 × 192 screen filled with an x XOR y pattern in coloured bands.

  • CTC interrupts — a routine hooked onto the frame interrupt cycles the border colour.

  • Memory paging — the IOBYTE at port 0 switching RAM pages under code at $C000.

The hardware examples (sprites, sound, graphics) drive the chips directly, so they also run under Memotech’s ROMs, where Assemble & run waits for BASIC, puts the code in RAM and types LET Z=USR(49152). On the monitor it calls your code directly. The monitor’s calls, its variables and port names (VDPDATA, VDPCTRL, SNDLATCH, SNDSTB, KBDDRV, KBDSNS, CTC0…) are predefined; ONMON is 1 on the monitor and 0 under the real ROMs. Put programs at $C000 — the 16 KB that never pages out. Load into memory copies the code without a reset (for G or USR yourself), Build .RUN saves it as a .RUN file for other MTX emulators. The assembler is this site’s Z80 assembler.

BASIC & typing types text into the MTX through its keyboard matrix, one key at a time, so anything that reads the keyboard sees it as typing — MTX BASIC, the monitor, a program. With Memotech’s ROMs, NEW, type & RUN enters a listing and runs it. MTX BASIC’s own front-panel monitor (PANEL) and assembler (ASSEM) are in the ROMs too.

Tapes: drop an .MTX file on the screen (or the Tape & printer tab) and, with the ROMs, the page types LOAD "". The OS’s tape routine at $0AAE is trapped and answered straight from the file, so loading is instant; SAVE "NAME" writes a new .MTX you can download, and VERIFY checks against the tape. .RUN files (load address, length, code) are copied into RAM and started. There’s no standard MTX snapshot format, so Quick save and Download state use this page’s own.

Debugging

Beside the editor: Run/Continue (F5), Pause (F6), Step (F11), Step over (F10), Step out (Shift+F11), the registers (type to change one), the flags (click to flip), the code around PC, the stack and watches. Click a line number to set a breakpoint; right-click it to run to that line.

  • Debugger — registers, interrupt state (whether the VDP and the CTC are asking), the scan line, a disassembly with the monitor’s calls named, breakpoints, which ROM or RAM block each 8 KB shows now, and memory as the CPU sees it (click a byte to change it).

  • VDP — registers R0–R7 decoded (click to change), status, the tables, the pattern table, sprites and the 16 KB of video memory.

  • CTC, sound, memory — the four CTC channels (mode, constant, rate, pending or in service), the vector and the IM 2 table address; the SN76489’s tones as frequencies; the IOBYTE and the memory map.

The machine

  • Z80 at 4 MHz — this site’s core, with every undocumented instruction. A frame is 313 lines of 255 T-states: 50.1 Hz, as on the PAL TMS9929A.

  • Memory — the IOBYTE (port 0): ROM mode puts the OS at $0000, one of eight paged ROMs at $2000 (0 BASIC, 1 ASSEM) and RAM page P at $4000–$BFFF; bit 7 maps RAM everywhere (for CP/M); $C000–$FFFF is always the first 16 KB. The MTX500 (32 KB, nothing at $4000–$7FFF), MTX512 (64 KB) and RS128 (128 KB) follow MEMU’s rules for which block appears where.

  • TMS9929A — every mode and the sprites, from the MSX emulator's video chip, used unchanged.

  • Z80 CTC — timers and counters, the daisy-chained interrupt priority and RETI, which the CTC spots on the bus as the real chip does. Channel 0 counts the VDP’s frame interrupt.

  • SN76489A — three tones and noise, behind the MTX’s latch and strobe; the same chip model as the BBC Micro emulator.

  • Keyboard — the 8 × 10 matrix on ports 5 and 6, UK layout.

  • Printer — bytes sent to the Centronics port (port 4, strobed by reading port 0) are collected on the Tape & printer tab.

Keys

Printable characters map by what they are, so the MTX’s own symbol layout doesn’t matter: type * and the page presses SHIFT + :. Enter is RET, Backspace BS, Caps Lock ALPHA LOCK, the arrows are the keypad cursor keys, Home HOME, End EOL, Page Up PAGE, Page Down CLS, Insert, Delete, Pause or F9 BRK, and F1–F4, F7, F8 the function keys (F5, F6, F10 and F11 belong to the debugger; the on-screen keyboard has all of them). The on-screen keyboard (toolbar) is for phones.

Browser support

Any current browser. Sound starts after your first click on the page.

Limits

  • No disc systems (FDX, SDX), CP/M, the 80-column board or the RS128’s serial ports. .COM (CP/M) files can’t run.

  • Tapes load and save only through the OS tape routine; there are no WAV tapes and no turbo loaders.

  • The VDP’s VRAM access timing isn’t modelled.

  • I haven’t been able to check this page against Memotech’s ROMs (they aren’t available to the site), so MTX BASIC, the tape trap and the BASIC examples follow MEMU’s and MAME’s descriptions of the hardware rather than a run on this page. The monitor, the CTC, the paging and every assembly example are tested.

Linking to an example

Share link copies a URL with the example (or your source), the tab and the model — never tapes or ROMs.

Parameter Values

example

hello, keys, sprites, sound, graphics, interrupt, paging

mode

the tab: asm, basic, debug, video, chips, tape, roms, software, keys, refs

model

mtx500, mtx512 or rs128

basicExample

b-hello, b-usr, b-inkey, b-circles

run

1 assembles and runs the program when the page opens

For example ?example=sprites&mode=video&run=1 opens the sprites running with the VDP tab showing.

Privacy

Everything runs in your browser. ROM images, tapes and saved states you load stay in this browser (IndexedDB); nothing is uploaded. The Software tab fetches a file only when you give it a URL or an archive.org item.

Runs entirely in your browser; nothing you type leaves this page.