vincente b63a331744 Robustness: always restore terminal after G (ACIA raw mode)
- acia.h now exports acia_poll_input() and acia_end_run()
- set_raw/restore_term are now safe no-ops on non-ttys (heredoc, pipes, the test harness)
- debug.c cmd_go and main direct -g path now unconditionally call acia_end_run() on every exit from a run (bp, SIGINT/break_flag, stop_requested, halt). This prevents the monitor (or outer shell) from being left in raw/cbreak mode.
- acia_poll_input() is called during G loops so programs using the emulated 6850 for input work.
- Added clear stop messages (** Breakpoint at xxxx **, ** Break (SIGINT) **, etc.).
- The exact A + S + B + G heredoc scenario that previously left a background process / raw term now cleanly returns to the m9> prompt and the calling shell has echo restored.

This makes scripted / non-interactive use of the monitor (including the cc09 workflow) far more reliable.
2026-06-12 15:02:16 -05:00
…
…
…

mimic09 — Fast Motorola 6809/6309 Emulator with C64-Style Monitor

mimic09 is an extremely efficient 6809 and 6309 emulator for macOS and UNIX/Linux. It includes a powerful built-in debugger/monitor inspired by classic Commodore 64 machine language monitors, a built-in assembler/disassembler, S-Record + Intel HEX + binary loaders, and emulation of the 6850 ACIA and 6821 PIA.

It is designed to work hand-in-hand with the cc09 project (the modern recreation of the WINTEK 6809 assembler and C compiler).

Quick Start

make                  # optimized release build → bin/mimic09
make debug            # for development
./bin/mimic09 -h
./bin/mimic09 -i      # enter interactive monitor immediately
./bin/mimic09 -l samples/2299.HEX -g   # load and go (if it has a sensible start vector)

In the monitor you will see a prompt (e.g. m9>). Type ? for help.

Key Features

  • Full 6809 instruction set + major 6309 extensions
  • Very high performance interpreter (tuned for modern CPUs)
  • C64-style monitor/debugger:
    • Single step, step-over, breakpoints
    • Memory view/edit (M / : )
    • Disassemble (D) and Assemble (A) — round-trippable
    • Register view/edit (R / ;)
    • Load/Save S-Records, Intel HEX, raw binary
  • 6850 ACIA and 6821 PIA emulation (configurable base addresses)
  • Excellent for running and debugging code produced by cc09

Monitor Commands (C64-inspired)

R                     show registers + flags
; <new values>        edit registers (copy/paste from R line)
M <addr> [len]        dump memory (hex + ASCII)
:<addr> <bytes...>    write bytes starting at addr
D [addr] [count]      disassemble
A <addr> <mnemonic>   assemble one line (e.g. A 1000 LDA #$2A)
G [addr]              run (until breakpoint or Ctrl-C)
S [n]                 single-step n instructions (default 1)
N                     step over (JSR/BSR/BSR counted as one)
B [addr]              set/clear breakpoint (no addr = list)
BC                    clear all breakpoints
L <file> [addr]       load SREC / IHEX / BIN (addr forces raw load)
S <file> <start> <end> [S19|IHEX|BIN]
F <s> <e> <val>       fill
H <s> <e> <pat...>    hunt (search)
! <cmd>               run shell command
? or H                help
X or Q                quit

While a program is running (after G), Ctrl-C will usually return you to the monitor.

Loading Programs

mimic09 understands:

  • Motorola S-Records (.s19, .srec, many .HEX files from 6809 tools)
  • Intel HEX (.hex)
  • Raw binary (use L foo.bin 0xC000 to load at a specific address)

After loading, set the PC (; PC=xxxx or use the G xxxx form) or let the reset vector (usually at 0xFFFE) be used.

ACIA / Serial Console

When your 6809/6309 code uses a 6850 ACIA for I/O, mimic09 can wire it to your terminal during G runs. Use the -acia 0xA000 (or whatever base your code expects) flag.

Simple programs that do polled serial I/O will "just work" for interactive debugging.

Building & Installing

make
make debug
sudo make install PREFIX=/usr/local

The binary is bin/mimic09. A convenience symlink mimic is also created by install.

Interfacing with cc09

  1. Build your program with the cc09 toolchain → produces S-Record or binary + optional listing.
  2. mimic09 -l myprog.s19
  3. In the monitor: set breakpoints, inspect, single-step.
  4. G to run at full speed with emulated peripherals.
  5. Capture ACIA output or interact live.

This gives you a very fast "edit–assemble–debug on real 6809 semantics" loop on a modern machine.

Status

This is an active re-creation and modernization of the 1994 "mimic09" effort. The original incomplete sources live in attic/.

Core goals: correctness + extreme speed + delightful C64-monitor debugging experience.

License

See LICENSE (heritage code fragments retain original copyright notices where applicable; new code is under the terms in LICENSE).

Enjoy the 6809 on modern iron.

S
Description
6809/6309 Emulator and Debugger
Readme 102 KiB
Languages
C 95.4%
C++ 3.1%
Makefile 1.5%