diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c547dd --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +# Build artifacts +bin/mimic09 +bin/mimic +build/ +*.o +*.a +*.dSYM/ + +# Editor / OS +.DS_Store +*~ +*.swp +*.bak + +# Test temps +*.tmp +core + +# Legacy binaries we don't want to re-commit in root +mimic +mimic.exe +*.exe +*.coff + +# Optional user files +*.s19 +*.srec +*.hex +*.bin +!samples/*.HEX +!samples/*.MIK +!samples/*.hex +!samples/*.s19 diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..13fa99b --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,182 @@ +# AGENTS.md — mimic09 (Motorola 6809/6309 Emulator) + +## Project Mission (from originator) +Your mission is to create a Motorola 6809/6309 Emulator called "mimic09". The intention is to be **extremely efficient and fast** when running on a MacOS or UNIX/Linux OS. + +This is a continuation/evolution of early "mimic" / "mimic09" work (1994 skeleton by Vincente D'Ingianni, II). The original partial code (Instruct.c + main.cc) is preserved under `attic/` for reference. + +Canonical repository: http://gitea.binary-systems.com/vincente/mimic + +## Required Capabilities +- Full, correct emulation of the Motorola 6809 (all documented + common undocumented behaviors). +- Strong support for the Hitachi 6309 (extra registers E/F/W/Q, additional instructions, MD register, native vs emulation mode, TFM block transfers, bit manipulation instructions, etc.). +- Integrated debugger/monitor featuring: + - Single-step execution + - Breakpoints (execution, and ideally memory read/write access) +- Built-in assembler and disassembler (two-way, so the monitor can A ssemble and D isassemble the same code). +- Debugger interface and capabilities **similar to popular monitors on the Commodore 64** (SuperMon, Final Cartridge III monitor, built-in monitor, etc.). Typical commands to emulate in spirit: + - R (registers), ; (edit registers from R output) + - M (memory dump hex+ascii), editing via : or direct poke style + - D (disassemble) + - A (assemble one or more lines at address) + - G (go/run) + - S or single-step variants + - B / breakpoints + - L / S for load/save + - X / Q to exit + - Additional useful: F (fill), H (hunt/search), T (transfer), C (compare), ! (shell), etc. +- Load and save: + - Motorola S-Records (S0–S3, S5, S7–S9) — primary format + - Intel HEX (.HEX) + - Raw binary images (with explicit load address) + - Best-effort for legacy formats appearing in the tree (e.g. .MIK) +- Peripheral emulation (memory-mapped, configurable base addresses preferred): + - 6850 ACIA (serial port) — for console/terminal I/O during program execution + - 6821 PIA (parallel ports + control lines) +- Designed to interface cleanly with the **cc09** project (recreation of the WINTEK 6809 Assembler and C compiler). Typical workflow: + - Use cc09 tools to produce S-Record or binary output + optional listing/map + - Load into mimic09 + - Debug, single-step, set breakpoints, inspect memory/registers + - Run with emulated serial I/O for stdio-style C programs + +## Non-Goals / Future +- Full system emulation of specific 6809 boards (Coco, Dragon, etc.) is out of scope for v1 (but the ACIA/PIA + flexible memory map makes it usable for many). +- Cycle-accurate timing is desirable for serial/PIA realism but secondary to raw speed and correctness of instruction semantics. +- GUI: CLI / terminal only. A future external front-end can talk to a debug stub if needed. + +## Performance Philosophy +- "Extremely efficient and fast" is a core constraint. +- Target: tens to hundreds of millions of emulated instructions per second on Apple Silicon / modern x86_64 Linux under normal debugging load. +- Hot path (instruction fetch/decode/execute + memory) must be lean. +- Prefer direct array access for RAM; route only device ranges and debug watchpoints through accessor functions. +- Use C (C99/C11). Heavy use of inlining, small functions, computed-goto or tight switch dispatch, -O3 -flto -march=native. +- Breakpoint / device checks must not kill speed when disabled. +- Provide a "fast run" mode (no debug hooks) vs "debug/trace" mode. + +## Directory Structure (source tree + executables) +``` +mimic/ # repo root (project "mimic", user-facing tool "mimic09" or "mimic") + AGENTS.md # this file — keep updated + README.md # user-facing quick start + command summary + LICENSE + Makefile # primary build system (no CMake requirement) + .gitignore + src/ # C sources and internal headers + main.c # CLI entry, option parsing, startup, REPL dispatch + cpu.c cpu.h # CPU core: registers, flags, memory, interpreter loop + disasm.c disasm.h # Table-driven disassembler (6809 + 6309) + asm.c asm.h # Built-in assembler used by monitor "A" command + debug.c debug.h # C64-monitor-style debugger / monitor command interpreter + loader.c loader.h # S-Record, Intel HEX, binary load/save (+ format detection) + acia.c acia.h # 6850 ACIA emulation + pia.c pia.h # 6821 PIA emulation + util.c util.h # hex parsing, string helpers, terminal raw mode, etc. + attic/ # Historical 1994 code (Instruct.c, main.cc, old binaries, etc.) + samples/ # Test programs, 140A.HEX, 2299.HEX, 2299.MIK, cc09 output examples + tests/ # Automated test harnesses, opcode tests, regression + docs/ # Longer docs: monitor-commands.md, 6809-notes.md, 6309-diffs.md, peripherals.md, cc09-integration.md + bin/ # Build target for the final executable (mimic09). Gitignored or committed as convenience. + build/ # Intermediate objects (gitignore) +``` + +Executables live under `bin/` after a successful `make`. A `make install` target may copy to $PREFIX/bin (default /usr/local/bin). + +Users run the emulator as `mimic09` (or `mimic` for short if you symlink). + +## Build & Run Requirements +- POSIX environment (macOS, Linux, *BSD, etc.). +- C compiler: Apple clang, clang, or gcc (recent). +- GNU make (or BSD make with minor tweaks). +- No heavy dependencies. termios (POSIX) for interactive terminal when running code that uses the ACIA. +- Recommended compile flags (Makefile should provide): + - Release: `-O3 -flto -DNDEBUG -march=native -Wall -Wextra` + - Debug: `-O0 -g -DDEBUG -Wall` +- `make`, `make debug`, `make clean`, `make test` (when tests exist), `make install`. + +## Coding & Contribution Rules for AI Agents and Humans +1. Update AGENTS.md and relevant docs/ when adding features or changing architecture. +2. Keep the hot CPU path fast. Any accessor change must be measured. +3. All memory traffic from the CPU must eventually go through the read/write accessors so that: + - Breakpoints/watchpoints work + - ACIA/PIA devices are emulated + - Future MMU or banking can be inserted +4. Hex numbers in the monitor: accept both bare hex (`F800`) and `$F800` / `0xF800`. Be liberal in what you accept. +5. Command language should feel familiar to anyone who has used a C64 monitor. +6. Test against real output from cc09 and trusted 6809/6309 artifacts. Cross-check key instruction semantics with another emulator or (ideally) real hardware. +7. 6309 instructions and "native mode" behaviors must be clearly isolated (ifdef or runtime cpu type). +8. Preserve the ability to run the original 1994 test files in samples/. +9. Never check in large binaries unless they are tiny test cases. The pre-existing mimic.exe etc. belong in attic/. +10. When you add a new monitor command, document it in docs/monitor-commands.md and give a one-line help in the `?` / `H` command. + +## Monitor Command Set (Target Behavior — C64 Inspired) +(Actual implementation may start with a useful subset and grow.) + +``` +R Show registers (PC, A/B/D, X, Y, U, S, CC with flag letters, MD if 6309) +; Edit registers (paste the line from R and change values) +M [] Hex + ASCII dump (16 bytes per line typical). Enter continues. +: ... (or just type over an M display) — write bytes +D [] [] Disassemble (default 20 lines or so) +A Assemble one instruction at addr (advances "next" address for repeated use) +G [] Run (from addr or current PC) until breakpoint or manual break +S [] Single step (count instructions). Shows state after each. +N or O Step over (treat JSR/BSR as one step) +B [] Set or toggle breakpoint at addr. No addr = list breakpoints. +BC Clear all breakpoints +F Fill memory +H Hunt (search) memory for byte sequence +T Block transfer (copy) +L [] Load file (auto-detect SREC/IHEX/BIN). Optional force addr for raw. +S [FORMAT] Save region (FORMAT = S19 | IHEX | BIN) +! Execute host shell command +? or H Help (brief command list + syntax) +X or Q Exit the monitor / emulator +``` + +Additional runtime control while a program is running (if using ACIA console): +- SIGINT (Ctrl-C) should drop back into the monitor with PC at the interrupted instruction. +- Optional: a "hot key" sequence to break without killing the process. + +## Peripheral Notes +- ACIA (6850): Control/Status at base+0, Data at base+1. Typical bases: $A000, $E000, $F000, etc. Make base configurable on CLI (`-acia 0xA000`). + - During `G` execution, map ACIA TX to stdout (or a pty), RX from non-blocking stdin / cooked input. + - Support setting baud rate etc. minimally (or just "as fast as host allows"). +- PIA (6821): Four registers per chip (PRA, DDRA/CRA, PRB, DDRB/CRB). Side effects on control lines can be stubbed or logged at first; allow user to poke values that programs expect for simple I/O handshaking. +- Device registration: a small table or range checks in the memory accessors. Keep the check cost near zero when no devices are mapped. + +## Integration with cc09 (Wintek Recreation) +- Primary interchange formats: S-Records and raw binaries at known load addresses. +- The emulator should be runnable from scripts: `mimic09 -l app.s19 -a 0x1000 -g` or similar for "assemble + run" CI-style loops. +- Future nice-to-have: load a symbol table (from cc09 .map or .lst) so that D and breakpoints can be symbolic. +- Provide a small C runtime shim or documented memory locations if cc09 programs expect specific startup (stack, argc/argv simulation via memory, exit via SWI or ACIA). + +## Versioning & Releases +- Start at 0.1 or 0.9 to reflect heritage. +- Use tags: v0.2, v0.3... +- The gitea at binary-systems.com is authoritative. + +## Safety & Correctness +- Never trust untrusted SREC/HEX files blindly (they can contain huge address claims). Clamp or warn. +- Stack pointer and PC must stay sane; detect runaway execution and offer to break. +- All emulated writes that target ROM areas should be ignored or warned (configurable). + +## References & Resources (for implementers) +- Motorola MC6809/MC6809E data sheets and programming manuals +- Hitachi HD6309 data (differences from 6809) +- 6850 ACIA, 6821/6822 PIA data sheets +- "The 6809 Companion", assembly programming books +- C64 monitor command lists and source (for UX inspiration, not literal port) +- Other 6809 emulators for behavioral cross-check (but mimic09 must be fast and standalone) +- cc09 project for the companion toolchain + +## When Working on This Codebase +- Read this file first. +- Prefer small, reviewable diffs. +- Add a regression test under tests/ for every non-trivial bug fixed. +- Keep the "fast path" obvious in cpu.c. +- If you change the monitor command grammar, update help text and docs/ at the same time. +- The old Instruct.c table-driven style is inspirational but the new implementation should be a clean-slate, high-quality rewrite (the 1994 code is incomplete and was never finished). + +This project exists to run real 6809/6309 code (especially from cc09) at high speed on modern *nix with an ergonomic C64-flavored debugging experience. + +Keep it fast. Keep it fun. Keep the monitor feeling like 1985 done right on a 2026 machine. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ef02b3e --- /dev/null +++ b/Makefile @@ -0,0 +1,93 @@ +# mimic09 — fast 6809/6309 emulator + C64-style monitor + ACIA/PIA +# Targets macOS and Linux/UNIX with clang or gcc + +CC ?= cc +CFLAGS_BASE := -std=c11 -Wall -Wextra -Wpedantic -I. -Isrc +LDFLAGS := + +# Detect OS for optional flags +UNAME := $(shell uname -s) +ifeq ($(UNAME),Darwin) + # Apple Silicon + Intel macOS + CFLAGS_BASE += -mmacosx-version-min=10.15 +endif + +# Modes +ifeq ($(MODE),debug) + CFLAGS := $(CFLAGS_BASE) -O0 -g -DDEBUG=1 +else + # Release: very fast + CFLAGS := $(CFLAGS_BASE) -O3 -flto -DNDEBUG=1 + ifneq ($(UNAME),Darwin) + # On Linux allow -march=native if available (safe for most dev machines) + CFLAGS += -march=native + else + # On macOS -march=native is usually fine too with Apple clang + CFLAGS += -march=native + endif +endif + +# Output +BIN_DIR := bin +BUILD_DIR := build +TARGET := $(BIN_DIR)/mimic09 + +SRCS := \ + src/main.c \ + src/cpu.c \ + src/disasm.c \ + src/debug.c \ + src/loader.c \ + src/acia.c \ + src/pia.c \ + src/util.c + +OBJS := $(patsubst src/%.c,$(BUILD_DIR)/%.o,$(SRCS)) + +.PHONY: all release debug clean install test run + +all: release + +release: + @$(MAKE) MODE=release $(TARGET) + +debug: + @$(MAKE) MODE=debug $(TARGET) + +$(TARGET): $(BIN_DIR) $(BUILD_DIR) $(OBJS) + $(CC) $(CFLAGS) $(OBJS) -o $@ $(LDFLAGS) + @echo "Built $@" + +$(BIN_DIR): + mkdir -p $(BIN_DIR) + +$(BUILD_DIR): + mkdir -p $(BUILD_DIR) + +$(BUILD_DIR)/%.o: src/%.c + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -rf $(BUILD_DIR) $(BIN_DIR)/mimic09 $(BIN_DIR)/mimic + +install: $(TARGET) + install -d $(DESTDIR)$(PREFIX)/bin + install -m 755 $(TARGET) $(DESTDIR)$(PREFIX)/bin/mimic09 + ln -sf mimic09 $(DESTDIR)$(PREFIX)/bin/mimic || true + @echo "Installed mimic09 to $(DESTDIR)$(PREFIX)/bin/" + +test: $(TARGET) + @echo "No automated tests yet. Run manually with samples." + # Example later: ./bin/mimic09 -l samples/2299.HEX -i + +run: $(TARGET) + ./$(TARGET) -h + +# Convenience: build debug and drop into interactive +idb: debug + ./$(TARGET) -i + +# Show size and basic info (useful for perf curiosity) +size: $(TARGET) + size $(TARGET) + file $(TARGET) diff --git a/README.md b/README.md index e69de29..4884a27 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,107 @@ +# 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 + +```bash +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 +; edit registers (copy/paste from R line) +M [len] dump memory (hex + ASCII) +: write bytes starting at addr +D [addr] [count] disassemble +A 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 [addr] load SREC / IHEX / BIN (addr forces raw load) +S [S19|IHEX|BIN] +F fill +H hunt (search) +! 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 + +```bash +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). + +## Links + +- Repository: http://gitea.binary-systems.com/vincente/mimic +- Companion: cc09 (Wintek 6809 toolchain recreation) + +Enjoy the 6809 on modern iron. diff --git a/attic/Instruct.c b/attic/Instruct.c new file mode 100755 index 0000000..d630a9c --- /dev/null +++ b/attic/Instruct.c @@ -0,0 +1,1105 @@ +/* + + mimic09 0.001 + MC6809 Simulator by Vincente D'Ingianni, II + (C)opyright October 1994 Mimic +*/ + + +#include "register.h" + +void ten(), eleven(); + + +void undefined() +{ + PC++; +} + + + +void ABX() +{ + X += B.whole.byte; + PC++; +} + + +void ANDA_IMMEDIATE() +{ + A.whole.byte &= memoire[++PC]; + CC.bit.V = 0; /* V: Cleared */ + CC.bit.Z = (A.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = A.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + +void ANDB_IMMEDIATE() +{ + B.whole.byte &= memoire[++PC]; + CC.bit.V = 0; /* V: Cleared */ + CC.bit.Z = (B.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = B.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + + +void ANDCC() +{ + CC.byte &= memoire[++PC]; + PC++; +} + + +void ASLA() +{ + CC.bit.V = A.bits.bit7 ^ A.bits.bit6; /* V: bit7 Exclusive OR bit6 of original operand. */ + CC.bit.C = A.bits.bit7; /* C: bit7 of original operand. */ + A.whole.byte <<= 1; /* Shift LEFT one bit. */ + CC.bit.Z = (A.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = A.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + +void ASLB() +{ + CC.bit.V = B.bits.bit7 ^ B.bits.bit6; /* V: bit7 Exclusive OR bit6 of original operand. */ + CC.bit.C = B.bits.bit7; /* C: bit7 of original operand. */ + B.whole.byte <<= 1; /* Shift LEFT one bit. */ + CC.bit.Z = (B.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = B.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + +void ASRA() +{ + CC.bit.N = A.bits.bit7; /* N: STORE bit7 of original operand. */ + CC.bit.C = A.bits.bit0; /* C: bit0 of original operand. */ + A.whole.byte >>= 1; /* Shift RIGHT one bit. */ + A.bits.bit7 = CC.bit.N; /* N: RESTORE bit7 from original operand. */ + CC.bit.Z = (A.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + PC++; +} + + +void ASRB() +{ + CC.bit.N = B.bits.bit7; /* N: STORE bit7 of original operand. */ + CC.bit.C = B.bits.bit0; /* C: bit0 of original operand. */ + B.whole.byte >>= 1; /* Shift RIGHT one bit. */ + B.bits.bit7 = CC.bit.N; /* N: RESTORE bit7 from original operand. */ + CC.bit.Z = (B.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + PC++; +} + + + +void BITA_IMMEDIATE() +{ + unsigned char tmp = A.whole.byte & memoire[++PC]; + CC.bit.V = 0; /* V: Cleared */ + CC.bit.Z = (tmp == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = (tmp & 0x80); /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + +void BITB_IMMEDIATE() +{ + unsigned char tmp = B.whole.byte & memoire[++PC]; + CC.bit.V = 0; /* V: Cleared */ + CC.bit.Z = (tmp == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = (tmp & 0x80); /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + + + +void BCC() +{ + PC += 2; + if (CC.bit.C == 0) { + PC += (signed char) memoire[PC-1]; + } +} + + +void BCS() +{ + PC += 2; + if (CC.bit.C) { + PC += (signed char) memoire[PC-1]; + } +} + + +void BEQ() +{ + PC += 2; + if (CC.bit.Z) { + PC += (signed char) memoire[PC-1]; + } +} + + +void BGE() +{ + PC += 2; + if (((CC.bit.N ^ CC.bit.V)) == 0) { + PC += (signed char) memoire[PC-1]; + } +} + + +void BGT() +{ + PC += 2; + if ((CC.bit.Z | (CC.bit.N ^ CC.bit.V)) == 0) { + PC += (signed char) memoire[PC-1]; + } +} + + +void BHI() +{ + PC += 2; + if ((CC.bit.C | CC.bit.V) == 0) { + PC += (signed char) memoire[PC-1]; + } +} + + +void BLE() +{ + PC += 2; + if ((CC.bit.Z | (CC.bit.N ^ CC.bit.V)) == 0) { + PC += (signed char) memoire[PC-1]; + } +} + + +void BLS() +{ + PC += 2; + if ((CC.bit.C | CC.bit.Z) == 1) { + PC += (signed char) memoire[PC-1]; + } +} + + +void BLT() +{ + PC += 2; + if ((CC.bit.N ^ CC.bit.V) == 1) { + PC += (signed char) memoire[PC-1]; + } +} + + +void BMI() +{ + PC += 2; + if (CC.bit.N) { + PC += (signed char) memoire[PC-1]; + } +} + + + +void BNE() +{ + PC += 2; + if (CC.bit.Z == 0) { + PC += (signed char) memoire[PC-1]; + } +} + +void BPL() +{ + PC += 2; + if (CC.bit.N == 0) { + PC += (signed char) memoire[PC-1]; + } +} + + +void BRA() +{ + PC += 2; + PC += (signed char) memoire[PC-1]; +} + + +void BRN() +{ + PC += 2; +} + + +void BVC() +{ + PC += 2; + if (CC.bit.V == 0) { + PC += (signed char) memoire[PC-1]; + } +} + + +void BVS() +{ + PC += 2; + if (CC.bit.V) { + PC += (signed char) memoire[PC-1]; + } +} + + + +void CLRA() +{ + A.all = 0; + CC.byte = (CC.byte & 0xF0) | 0x04; + PC++; +} + + + +void CLRB() +{ + B.all = 0; + CC.byte = (CC.byte & 0xF0) | 0x04; + PC++; +} + + +void COMA() +{ + A.whole.byte = ~A.whole.byte; /* Perform One's Compliment */ + CC.bit.C = 1; /* C: Set */ + CC.bit.V = 0; /* V: Cleared */ + CC.bit.Z = (A.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = A.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + +void COMB() +{ + B.whole.byte = ~B.whole.byte; /* Perform One's Compliment */ + CC.bit.C = 1; /* C: Set */ + CC.bit.V = 0; /* V: Cleared */ + CC.bit.Z = (B.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = B.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + + +void EORA_IMMEDIATE() +{ + A.whole.byte ^= memoire[++PC]; + CC.bit.V = 0; /* V: Cleared */ + CC.bit.Z = (A.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = A.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + +void EORB_IMMEDIATE() +{ + B.whole.byte ^= memoire[++PC]; + CC.bit.V = 0; /* V: Cleared */ + CC.bit.Z = (B.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = B.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + + + +void INCA() +{ + CC.bit.V = (A.whole.byte == 0x7F); /* V: Set IFF the original operand was %011111111 */ + CC.bit.Z = (++A.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = A.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + +void INCB() +{ + CC.bit.V = (B.whole.byte == 0x7F); /* V: Set IFF the original operand was %011111111 */ + CC.bit.Z = (++B.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = B.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + + +void JMP() +{ + PC = memoire[PC+1] * 256 + memoire[PC+2]; +} + + + +void LBCC() +{ + PC += 4; + if (CC.bit.C == 0) { + PC += memoire[PC-2] * 256 + memoire[PC-1]; + } +} + + +void LBCS() +{ + PC += 4; + if (CC.bit.C) { + PC += memoire[PC-2] * 256 + memoire[PC-1]; + } +} + + +void LBEQ() +{ + PC += 4; + if (CC.bit.Z) { + PC += memoire[PC-2] * 256 + memoire[PC-1]; + } +} + + +void LBGE() +{ + PC += 4; + if ((CC.bit.N ^ CC.bit.V) == 0) { + PC += memoire[PC-2] * 256 + memoire[PC-1]; + } +} + + +void LBGT() +{ + PC += 4; + if ((CC.bit.Z | (CC.bit.N ^ CC.bit.V)) == 0) { + PC += memoire[PC-2] * 256 + memoire[PC-1]; + } +} + + +void LBHI() +{ + PC += 4; + if ((CC.bit.C | CC.bit.V) == 0) { + PC += memoire[PC-2] * 256 + memoire[PC-1]; + } +} + + +void LBLE() +{ + PC += 4; + if ((CC.bit.Z | (CC.bit.N ^ CC.bit.V)) == 0) { + PC += memoire[PC-2] * 256 + memoire[PC-1]; + } +} + + +void LBLS() +{ + PC += 4; + if ((CC.bit.C | CC.bit.Z) == 1) { + PC += memoire[PC-2] * 256 + memoire[PC-1]; + } +} + + +void LBLT() +{ + PC += 4; + if ((CC.bit.N ^ CC.bit.V) == 1) { + PC += memoire[PC-2] * 256 + memoire[PC-1]; + } +} + + +void LBMI() +{ + PC += 4; + if (CC.bit.N) { + PC += memoire[PC-2] * 256 + memoire[PC-1]; + } +} + + + +void LBNE() +{ + PC += 4; + if (CC.bit.Z == 0) { + PC += memoire[PC-2] * 256 + memoire[PC-1]; + } +} + + +void LBPL() +{ + PC += 4; + if (CC.bit.N == 0) { + PC += memoire[PC-2] * 256 + memoire[PC-1]; + } +} + + +void LBRA() +{ + PC += 4; + PC += memoire[PC-2] * 256 + memoire[PC-1]; +} + + + +void LBRN() +{ + PC += 4; +} + + +void LBVC() +{ + PC += 4; + if (CC.bit.V == 0) { + PC += memoire[PC-2] * 256 + memoire[PC-1]; + } +} + + +void LBVS() +{ + PC += 4; + if (CC.bit.V) { + PC += memoire[PC-2] * 256 + memoire[PC-1]; + } +} + + + +void LDA_IMMEDIATE() +{ + A.whole.byte = memoire[++PC]; + CC.bit.V = 0; /* V: Cleared */ + CC.bit.Z = (A.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = A.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + +void LDB_IMMEDIATE() +{ + B.whole.byte = memoire[++PC]; + CC.bit.V = 0; /* V: Cleared */ + CC.bit.Z = (B.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = B.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + +void LDD_IMMEDIATE() +{ + A.whole.byte = memoire[++PC]; + B.whole.byte = memoire[++PC]; + CC.bit.V = 0; /* V: Cleared */ + /* Z: Set IFF all bits of the result are clear. */ + CC.bit.Z = (A.whole.byte == 0) && (B.whole.byte == 0); + CC.bit.N = A.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + +void LDS_IMMEDIATE() +{ + S = memoire[++PC] * 256 + memoire[++PC]; + CC.bit.V = 0; /* V: Cleared */ + CC.bit.Z = (S == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = (S & 0x8000); /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + +void LDU_IMMEDIATE() +{ + U = memoire[++PC] * 256 + memoire[++PC]; + CC.bit.V = 0; /* V: Cleared */ + CC.bit.Z = (U == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = (U & 0x8000); /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + +void LDX_IMMEDIATE() +{ + X = memoire[++PC] * 256 + memoire[++PC]; + CC.bit.V = 0; /* V: Cleared */ + CC.bit.Z = (X == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = (X & 0x8000); /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + +void LDY_IMMEDIATE() +{ + Y = memoire[++PC] * 256 + memoire[++PC]; + CC.bit.V = 0; /* V: Cleared */ + CC.bit.Z = (Y == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = (Y & 0x8000); /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + + +void LSRA() +{ + CC.bit.N = 0; /* N: Cleared. */ + CC.bit.C = A.bits.bit0; /* C: bit0 of original operand. */ + A.whole.byte >>= 1; /* Shift RIGHT one bit. */ + A.bits.bit7 = 0; /* Make sure bit7 is clear. */ + CC.bit.Z = (A.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + PC++; +} + + + +void LSRB() +{ + CC.bit.N = 0; /* N: Cleared. */ + CC.bit.C = B.bits.bit0; /* C: bit0 of original operand. */ + B.whole.byte >>= 1; /* Shift RIGHT one bit. */ + B.bits.bit7 = 0; /* Make sure bit7 is clear. */ + CC.bit.Z = (B.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + PC++; +} + + + +void MUL() /* D <- A * B */ +{ + B.all = A.whole.byte * B.whole.byte; + A.whole.byte = B.whole.padding; + CC.bit.C = B.bits.bit7; /* C: Set IFF B bit7 of result is set. */ + CC.bit.Z = (B.all == 0); /* Z: Set IFF all bits of the result are clear. */ + PC++; +} + + + + +void NEGA() +{ + CC.bit.V = (A.whole.byte == 0x80); /* V: Set IFF original operand was $80 */ + CC.bit.C = (A.whole.byte == 0); /* C: Set IFF original operand was 0 */ + A.whole.byte = ~A.whole.byte + 1; /* Perform Twos's Compliment */ + CC.bit.Z = (A.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = A.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + +void NEGB() +{ + CC.bit.V = (B.whole.byte == 0x80); /* V: Set IFF original operand was $80 */ + CC.bit.C = (B.whole.byte == 0); /* C: Set IFF original operand was 0 */ + B.whole.byte = ~B.whole.byte + 1; /* Perform Twos's Compliment */ + CC.bit.Z = (B.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = B.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + +void NOP() +{ + PC++; +} + + + +void ORA_IMMEDIATE() +{ + A.whole.byte |= memoire[++PC]; + CC.bit.V = 0; /* V: Cleared */ + CC.bit.Z = (A.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = A.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + +void ORB_IMMEDIATE() +{ + B.whole.byte |= memoire[++PC]; + CC.bit.V = 0; /* V: Cleared */ + CC.bit.Z = (B.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = B.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + + +void ORCC() +{ + CC.byte |= memoire[++PC]; + PC++; +} + + + +void ROLA() /* Rotate Left */ +{ + CC.bit.V = A.bits.bit7 ^ A.bits.bit6; /* V: bit7 Exclusive OR bit6 of original operand. */ + CC.bit.C = A.bits.bit7; /* C: bit7 of original operand. */ + A.whole.byte <<= 1; /* Shift RIGHT one bit. */ + A.bits.bit0 = CC.bit.C; /* RESTORE bit0 from Carry bit. */ + CC.bit.N = A.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + CC.bit.Z = (A.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + PC++; +} + + +void ROLB() /* Rotate Left */ +{ + CC.bit.V = B.bits.bit7 ^ B.bits.bit6; /* V: bit7 Exclusive OR bit6 of original operand. */ + CC.bit.C = B.bits.bit7; /* C: bit7 of original operand. */ + B.whole.byte <<= 1; /* Shift RIGHT one bit. */ + B.bits.bit0 = CC.bit.C; /* RESTORE bit0 from Carry bit. */ + CC.bit.N = B.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + CC.bit.Z = (B.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + PC++; +} + + + +void RORA() /* Rotate Right */ +{ + CC.bit.C = A.bits.bit0; /* C: bit0 of original operand. */ + A.whole.byte >>= 1; /* Shift RIGHT one bit. */ + A.bits.bit7 = CC.bit.C; /* RESTORE bit7 from Carry bit. */ + CC.bit.N = A.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + CC.bit.Z = (A.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + PC++; +} + + + +void RORB() /* Rotate Right */ +{ + CC.bit.C = B.bits.bit0; /* C: bit0 of original operand. */ + B.whole.byte >>= 1; /* Shift RIGHT one bit. */ + B.bits.bit7 = CC.bit.C; /* RESTORE bit7 from Carry bit. */ + CC.bit.N = B.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + CC.bit.Z = (B.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + PC++; +} + + + +void SEX() /* Sign Extend */ +{ + /* If bit 7 of B is set then A <- $FF else A <- 00 */ + if (B.bits.bit7) + { + A.whole.byte = 0xFF; + } + else + { + A.whole.byte = 0; + } + CC.bit.Z = (A.whole.byte == 0) && (B.whole.byte == 0); + /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = A.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + + + +void TSTA() +{ + CC.bit.V = 0; /* V: Cleared */ + CC.bit.Z = (A.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = A.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + +void TSTB() +{ + CC.bit.V = 0; /* V: Cleared */ + CC.bit.Z = (B.whole.byte == 0); /* Z: Set IFF all bits of the result are clear. */ + CC.bit.N = B.bits.bit7; /* N: Set IFF bit 7 of the result is Set. */ + PC++; +} + + + + + + +void (*instruction[256])() = { +/* $00 "NEG " */ &undefined, +/* $01 "??? " */ &undefined, +/* $02 "??? " */ &undefined, +/* $03 "COM " */ &undefined, +/* $04 "LSR " */ &undefined, +/* $05 "??? " */ &undefined, +/* $06 "ROR " */ &undefined, +/* $07 "ASR " */ &undefined, +/* $08 "LSL " */ &undefined, +/* $09 "ROL " */ &undefined, +/* $0A "DEC " */ &undefined, +/* $0B "??? " */ &undefined, +/* $0C "INC " */ &undefined, +/* $0D "TST " */ &undefined, +/* $0E "JMP " */ &undefined, +/* $0F "CLR " */ &undefined, + +/* $10 "10 " */ &ten, +/* $11 "11 " */ &eleven, +/* $12 "NOP " */ &NOP, +/* $13 "SYNC " */ &undefined, +/* $14 "??? " */ &undefined, +/* $15 "??? " */ &undefined, +/* $16 "LBRA " */ &LBRA, +/* $17 "LBSR " */ &undefined, +/* $18 "??? " */ &undefined, +/* $19 "DAA " */ &undefined, +/* $1A "ORCC " */ &undefined, +/* $1B "??? " */ &undefined, +/* $1C "ANDCC" */ &ANDCC, +/* $1D "SEX " */ &SEX, +/* $1E "EXG " */ &undefined, +/* $1F "TFR " */ &undefined, + +/* $20 "BRA " */ &BRA, +/* $21 "BRN " */ &BRN, +/* $22 "BHI " */ &BHI, +/* $23 "BLS " */ &BLS, +/* $24 "BCC " */ &BCC, +/* $25 "BCS " */ &BCS, +/* $26 "BNE " */ &BNE, +/* $27 "BEQ " */ &BEQ, +/* $28 "BVC " */ &BVC, +/* $29 "BVS " */ &BVS, +/* $2A "BPL " */ &BPL, +/* $2B "BMI " */ &BMI, +/* $2C "BGE " */ &BGE, +/* $2D "BLT " */ &BLT, +/* $2E "BGT " */ &BGT, +/* $2F "BLE " */ &BLE, + +/* $30 "LEAX " */ &undefined, +/* $31 "LEAY " */ &undefined, +/* $32 "LEAS " */ &undefined, +/* $33 "LEAU " */ &undefined, +/* $34 "PSHS " */ &undefined, +/* $35 "PULS " */ &undefined, +/* $36 "PSHU " */ &undefined, +/* $37 "PULU " */ &undefined, +/* $38 "??? " */ &undefined, +/* $39 "RTS " */ &undefined, +/* $3A "ABX " */ &ABX, +/* $3B "RTO " */ &undefined, +/* $3C "CWAI " */ &undefined, +/* $3D "MUL " */ &MUL, +/* $3E "??? " */ &undefined, +/* $3F "SWI " */ &undefined, + +/* $40 "NEGA " */ &NEGA, +/* $41 "??? " */ &undefined, +/* $42 "??? " */ &undefined, +/* $43 "COMA " */ &COMA, +/* $44 "LSRA " */ &LSRA, +/* $45 "??? " */ &undefined, +/* $46 "RORA " */ &RORA, +/* $47 "ASRA " */ &ASRA, +/* $48 "LSLA " */ &ASLA, +/* $49 "ROLA " */ &ROLA, +/* $4A "DECA " */ &undefined, +/* $4B "??? " */ &undefined, +/* $4C "INCA " */ &INCA, +/* $4D "TSTA " */ &TSTA, +/* $4E "??? " */ &undefined, +/* $4F "CLRA " */ &CLRA, + +/* $50 "NEGB " */ &NEGB, +/* $51 "??? " */ &undefined, +/* $52 "??? " */ &undefined, +/* $53 "COMB " */ &COMB, +/* $54 "LSRB " */ &LSRB, +/* $55 "??? " */ &undefined, +/* $56 "RORB " */ &RORB, +/* $57 "ASRB " */ &ASRB, +/* $58 "LSLB " */ &ASLA, +/* $59 "ROLB " */ &ROLB, +/* $5A "DECB " */ &undefined, +/* $5B "??? " */ &undefined, +/* $5C "INCB " */ &INCB, +/* $5D "TSTB " */ &TSTB, +/* $5E "??? " */ &undefined, +/* $5F "CLRB " */ &CLRB, + +/* $60 "NEG " */ &undefined, +/* $61 "??? " */ &undefined, +/* $62 "??? " */ &undefined, +/* $63 "COM " */ &undefined, +/* $64 "LSR " */ &undefined, +/* $65 "??? " */ &undefined, +/* $66 "ROR " */ &undefined, +/* $67 "ASR " */ &undefined, +/* $68 "LSL " */ &undefined, +/* $69 "ROL " */ &undefined, +/* $6A "DEC " */ &undefined, +/* $6B "??? " */ &undefined, +/* $6C "INC " */ &undefined, +/* $6D "TST " */ &undefined, +/* $6E "JMP " */ &undefined, +/* $6F "CLR " */ &undefined, + +/* $70 "NEG " */ &undefined, +/* $71 "??? " */ &undefined, +/* $72 "??? " */ &undefined, +/* $73 "COM " */ &undefined, +/* $74 "LSR " */ &undefined, +/* $75 "??? " */ &undefined, +/* $76 "ROR " */ &undefined, +/* $77 "ASR " */ &undefined, +/* $78 "LSL " */ &undefined, +/* $79 "ROL " */ &undefined, +/* $7A "DEC " */ &undefined, +/* $7B "??? " */ &undefined, +/* $7C "INC " */ &undefined, +/* $7D "TST " */ &undefined, +/* $7E "JMP " */ &undefined, +/* $7F "CLR " */ &undefined, + +/* $80 "SUBA " */ &undefined, +/* $81 "CMPA " */ &undefined, +/* $82 "SBCA " */ &undefined, +/* $83 "SUBD " */ &undefined, +/* $84 "ANDA " */ &ANDA_IMMEDIATE, +/* $85 "BITA " */ &BITA_IMMEDIATE, +/* $86 "LDA " */ &LDA_IMMEDIATE, +/* $87 "??? " */ &undefined, +/* $88 "EORA " */ &EORA_IMMEDIATE, +/* $89 "ADCA " */ &undefined, +/* $8A "ORA " */ &ORA_IMMEDIATE, +/* $8B "ADDA " */ &undefined, +/* $8C "CMPX " */ &undefined, +/* $8D "BSR " */ &undefined, +/* $8E "LDX " */ &LDX_IMMEDIATE, +/* $8F "??? " */ &undefined, + +/* $90 "SUBA " */ &undefined, +/* $91 "CMPA " */ &undefined, +/* $92 "SBCA " */ &undefined, +/* $93 "SUBD " */ &undefined, +/* $94 "ANDA " */ &undefined, +/* $95 "BITA " */ &undefined, +/* $96 "LDA " */ &undefined, +/* $97 "STA " */ &undefined, +/* $98 "EORA " */ &undefined, +/* $99 "ADCA " */ &undefined, +/* $9A "ORA " */ &undefined, +/* $9B "ADDA " */ &undefined, +/* $9C "CMPX " */ &undefined, +/* $9D "JSR " */ &undefined, +/* $9E "LDX " */ &undefined, +/* $9F "STX " */ &undefined, + +/* $A0 "SUBA " */ &undefined, +/* $A1 "CMPA " */ &undefined, +/* $A2 "SBCA " */ &undefined, +/* $A3 "SUBD " */ &undefined, +/* $A4 "ANDA " */ &undefined, +/* $A5 "BITA " */ &undefined, +/* $A6 "LDA " */ &undefined, +/* $A7 "STA " */ &undefined, +/* $A8 "EORA " */ &undefined, +/* $A9 "ADCA " */ &undefined, +/* $AA "ORA " */ &undefined, +/* $AB "ADDA " */ &undefined, +/* $AC "CMPX " */ &undefined, +/* $AD "JSR " */ &undefined, +/* $AE "LDX " */ &undefined, +/* $AF "STX " */ &undefined, + +/* $B0 "SUBA " */ &undefined, +/* $B1 "CMPA " */ &undefined, +/* $B2 "SBCA " */ &undefined, +/* $B3 "SUBD " */ &undefined, +/* $B4 "ANDA " */ &undefined, +/* $B5 "BITA " */ &undefined, +/* $B6 "LDA " */ &undefined, +/* $B7 "STA " */ &undefined, +/* $B8 "EORA " */ &undefined, +/* $B9 "ADCA " */ &undefined, +/* $BA "ORA " */ &undefined, +/* $BB "ADDA " */ &undefined, +/* $BC "CMPX " */ &undefined, +/* $BD "JSR " */ &undefined, +/* $BE "LDX " */ &undefined, +/* $BF "STX " */ &undefined, + + + +/* $C0 "SUBB " */ &undefined, +/* $C1 "CMPB " */ &undefined, +/* $C2 "SBCB " */ &undefined, +/* $C3 "ADDD " */ &undefined, +/* $C4 "ANDB " */ &ANDB_IMMEDIATE, +/* $C5 "BITB " */ &BITB_IMMEDIATE, +/* $C6 "LDB " */ &LDB_IMMEDIATE, +/* $C7 "??? " */ &undefined, +/* $C8 "EORB " */ &EORB_IMMEDIATE, +/* $C9 "ADCB " */ &undefined, +/* $CA "ORB " */ &ORB_IMMEDIATE, +/* $CB "ADDB " */ &undefined, +/* $CC "LDD " */ &LDD_IMMEDIATE, +/* $CD "??? " */ &undefined, +/* $CE "LDU " */ &LDU_IMMEDIATE, +/* $CF "??? " */ &undefined, + +/* $D0 "SUBB " */ &undefined, +/* $D1 "CMPB " */ &undefined, +/* $D2 "SBCB " */ &undefined, +/* $D3 "ADDD " */ &undefined, +/* $D4 "ANDB " */ &undefined, +/* $D5 "BITB " */ &undefined, +/* $D6 "LDB " */ &undefined, +/* $D7 "STB " */ &undefined, +/* $D8 "EORB " */ &undefined, +/* $D9 "ADCB " */ &undefined, +/* $DA "ORB " */ &undefined, +/* $DB "ADDB " */ &undefined, +/* $DC "LDD " */ &undefined, +/* $DD "STD " */ &undefined, +/* $DE "LDU " */ &undefined, +/* $DF "STU " */ &undefined, + +/* $E0 "SUBB " */ &undefined, +/* $E1 "CMPB " */ &undefined, +/* $E2 "SBCB " */ &undefined, +/* $E3 "ADDD " */ &undefined, +/* $E4 "ANDB " */ &undefined, +/* $E5 "BITB " */ &undefined, +/* $E6 "LDB " */ &undefined, +/* $E7 "STB " */ &undefined, +/* $E8 "EORB " */ &undefined, +/* $E9 "ADCB " */ &undefined, +/* $EA "ORB " */ &undefined, +/* $EB "ADDB " */ &undefined, +/* $EC "LDD " */ &undefined, +/* $ED "STD " */ &undefined, +/* $EE "LDU " */ &undefined, +/* $EF "STU " */ &undefined, + +/* $F0 "SUBB " */ &undefined, +/* $F1 "CMPB " */ &undefined, +/* $F2 "SBCB " */ &undefined, +/* $F3 "ADDD " */ &undefined, +/* $F4 "ANDB " */ &undefined, +/* $F5 "BITB " */ &undefined, +/* $F6 "LDB " */ &undefined, +/* $F7 "STB " */ &undefined, +/* $F8 "EORB " */ &undefined, +/* $F9 "ADCB " */ &undefined, +/* $FA "ORB " */ &undefined, +/* $FB "ADDB " */ &undefined, +/* $FC "LDD " */ &undefined, +/* $FD "STD " */ &undefined, +/* $FE "LDU " */ &undefined, +/* $FF "STU " */ &undefined + }; + + + +void (*instruction_10[41])() = { +/* $1020 "??? " */ &undefined, +/* $1021 "LBRN " */ &LBRN, +/* $1022 "LBHI " */ &LBHI, +/* $1023 "LBLS " */ &LBLS, +/* $1024 "LBCC " */ &LBCC, +/* $1025 "LBCS " */ &LBCS, +/* $1026 "LBNE " */ &LBNE, +/* $1027 "LBEQ " */ &LBEQ, +/* $1028 "LBVC " */ &LBVC, +/* $1029 "LBVS " */ &LBVS, +/* $102A "LBPL " */ &LBPL, +/* $102B "LBMI " */ &LBMI, +/* $102C "LBGE " */ &LBGE, +/* $102D "LBLT " */ &LBLT, +/* $102E "LBGT " */ &LBGT, +/* $102F "LBLE " */ &LBLE, + +/* $103F "SWI2 " */ &undefined, + +/* $1083 "CMPD " */ &undefined, +/* $108C "CMPY " */ &undefined, +/* $108E "LDY " */ &LDY_IMMEDIATE, + +/* $1093 "CMPD " */ &undefined, +/* $109C "CMPY " */ &undefined, +/* $109E "LDY " */ &undefined, +/* $109F "STY " */ &undefined, + +/* $10A3 "CMPD " */ &undefined, +/* $10AC "CMPY " */ &undefined, +/* $10AE "LDY " */ &undefined, +/* $10AF "STY " */ &undefined, + +/* $10B3 "CMPD " */ &undefined, +/* $10BC "CMPY " */ &undefined, +/* $10BE "LDY " */ &undefined, +/* $10BF "STY " */ &undefined, + +/* $10CE "LDS " */ &LDS_IMMEDIATE, + +/* $10DE "LDS " */ &undefined, +/* $10DF "STS " */ &undefined, + +/* $10EE "LDS " */ &undefined, +/* $10EF "STS " */ &undefined, + +/* $10FE "LDS " */ &undefined, +/* $10FF "STS " */ &undefined + }; + + +void (*instruction_11[8])() = { +/* $1183 "CMPU " */ &undefined, +/* $118C "CMPS " */ &undefined, + +/* $1193 "CMPU " */ &undefined, +/* $119C "CMPS " */ &undefined, + +/* $11A3 "CMPU " */ &undefined, +/* $11AC "CMPS " */ &undefined, + +/* $11B3 "CMPU " */ &undefined, +/* $11BC "CMPS " */ &undefined + }; + + + + +void ten() +{ + ++PC; +} + + +void eleven() +{ + ++PC; +} diff --git a/attic/Makefile b/attic/Makefile new file mode 100755 index 0000000..8465db4 --- /dev/null +++ b/attic/Makefile @@ -0,0 +1,3 @@ +mimic.exe : main.cc + gcc -O4 -g main.cc -o mimic + coff2exe mimic diff --git a/attic/main b/attic/main new file mode 100755 index 0000000..30be9e5 Binary files /dev/null and b/attic/main differ diff --git a/attic/main.cc b/attic/main.cc new file mode 100755 index 0000000..917249d --- /dev/null +++ b/attic/main.cc @@ -0,0 +1,169 @@ +#include +#include +#include +//#include + +#define FALSE 0 +#define TRUE 1 + + +void Help() +{ + printf("usage: mimic \n"); +} + + +void Version() +{ + printf("Mimic 0.001 by Vincente D'Ingianni. Copyright 1994 Mimic.\n"); +} + + +int getline(char s[], int lim) +{ + int c, i; + + for (i = 0; i < lim - 1 && (c = getchar()) != EOF && c != '\n'; ++i) + s[i] = c; + if (c == '\n') { + s[i] = c; + ++i; + } + s[i] = '\0'; + return i; +} + + +//int getNextHex(char *line) +//{ +// int value; +// sscanf(line, "%x", value); +// +//} + + +void Modify(char *line) +{ + int args; + unsigned int address; + char value[15]; + printf("Modify!\n"); + toupper(line[0]); + + for (int i = 0; i <= 0xF; ++i) value[i] = 0; + + args = sscanf(line, "M %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x", + &address, + &value[0], &value[1], &value[2], &value[3], + &value[4], &value[5], &value[6], &value[7], + &value[8], &value[9], &value[0xA], &value[0xB], + &value[0xC], &value[0xD], &value[0xE], &value[0xF]); + + printf("args: %d\taddress: %x\n", args, address); + + while (args > 0) { +// for (int i = 0; i <= args - 1; i++) Poke(address + i, value[i]); + + printf("%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n", + value[0], value[1], value[2], value[3], + value[4], value[5], value[6], value[7], + value[8], value[9], value[0xA], value[0xB], + value[0xC], value[0xD], value[0xE], value[0xF]); + + for (int i = 0; i <= 0xF; ++i) value[i] = 0; + address += i; + args = 0; + printf(" %x ", address); + if (getline(line, sizeof(line)) > 0) { + args = sscanf(line, "%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x", + &value[0], &value[1], &value[2], &value[3], + &value[4], &value[5], &value[6], &value[7], + &value[8], &value[9], &value[0xA], &value[0xB], + &value[0xC], &value[0xD], &value[0xE], &value[0xF]); + } + } +} + + +void Display(unsigned int address) +{ + int args; + unsigned int address; + char value[15]; + printf("Modify!\n"); + toupper(line[0]); + + + while (args > 0) { +// for (int i = 0; i <= args - 1; i++) Poke(address + i, value[i]); + + printf("%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n", + value[0], value[1], value[2], value[3], + value[4], value[5], value[6], value[7], + value[8], value[9], value[0xA], value[0xB], + value[0xC], value[0xD], value[0xE], value[0xF]); + + for (int i = 0; i <= 0xF; ++i) value[i] = 0; + address += i; + args = 0; + printf(" %x ", address); + if (getline(line, sizeof(line)) > 0) { + args = sscanf(line, "%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x", + &value[0], &value[1], &value[2], &value[3], + &value[4], &value[5], &value[6], &value[7], + &value[8], &value[9], &value[0xA], &value[0xB], + &value[0xC], &value[0xD], &value[0xE], &value[0xF]); + } + } +} + + +void Interactive() +{ + bool done = FALSE; + char command; + char line[255]; + printf("Going interactive.\n"); + + while (!done) { + printf("Mimic> "); + if (getline(line, sizeof(line)) > 0) { + line[0] = toupper(line[0]); + if (line[0] == 'Q') done = TRUE; + if (line[0] == 'M') Modify(line); + if ((args = sscanf(line, "D %x", &address)) == 1) Display(address); +// if (line[0] == 'D') Display(line); + if (line[0] == '!') system(&line[1]); + } + } +} + + + +void main(int argc, char *argv[]) +{ + bool interactive = FALSE; + printf("hello, world\n"); + + if (argc > 1) { + for (int i = 1; i <= argc; i++) { + if (strcmp(argv[i], "-v") == 0) { + Version(); + } + if (strcmp(argv[i], "-h") == 0) { + Help(); + } + if (strcmp(argv[i], "-i") == 0) { + interactive = TRUE; + } + } + } + else { + interactive = TRUE; + } + + if (interactive == TRUE) { + Interactive(); + } + +} diff --git a/samples/140A.HEX b/samples/140A.HEX new file mode 100755 index 0000000..115f223 --- /dev/null +++ b/samples/140A.HEX @@ -0,0 +1,258 @@ + +:10D0000046495245204445542042592D50415353DE +:10D0100020202020FF4649524520444554205452A8 +:10D020004F55424C4520202020FF46495245205470 +:10D030004F4E452042592D50415353202020FF464A +:10D0400049524520444554204C57522051545220B7 +:10D05000202020FF464952452044455420544F503B +:10D060002051545220202020FF464952452044455B +:10D07000542057415348524F4F4D202020FF4649DE +:10D08000524520444554205041525420424C4420A3 +:10D090002020FF46495245204445542047454E52E2 +:10D0A00020524D20202020FF46495245204445541F +:10D0B000204D434320524D2020202020FF47415344 +:10D0C000204445542042592D50415353454420207B +:10D0D00020FF47415320444554204641494C2020DD +:10D0E000202020202020FF47415320544F4E452030 +:10D0F00042592D5041535320202020FF47415320B7 +:10D10000444554204D434320524D202020202020D0 +:10D11000FF474153204445542047454E5220524D2D +:10D120002020202020FF47415320444554204C57C5 +:10D1300052205154522020202020FF4741532044A8 +:10D14000455420544F50205154522020202020FF7D +:10D15000474153204445542050415254532F574186 +:10D1600053482020FF47454E5220532F4420425918 +:10D170002D5041535320202020FF444320504F572F +:10D1800045522054524F55424C4520202020FF4309 +:10D1900048414E4E454C2032302020202020202077 +:10D1A000202020FF4348414E4E454C203231202064 +:10D1B0002020202020202020FF4348414E4E454C77 +:10D1C00020323220202020202020202020FF442E2A +:10D1D000432E2053595354454D2054524F55424CE1 +:10D1E0004520FF4348414E4E454C203234202020FC +:10D1F00020202020202020FF4348414E4E454C2037 +:10D20000323520202020202020202020FF434841AC +:10D210004E4E454C20323620202020202020202039 +:10D2200020FF4348414E4E454C20323720202020DD +:10D23000202020202020FF4348414E4E454C2032E4 +:10D240003820202020202020202020FF4348414E4D +:10D250004E454C2032392020202020202020202024 +:10D26000FF4348414E4E454C2033302020202020A3 +:10D270002020202020FF4348414E4E454C20333192 +:10D2800020202020202020202020FF4348414E4EF7 +:10D29000454C20333220202020202020202020FF39 +:10D2A0002020202020204D503134302D41202020BE +:10D2B00020202020FFFFFFFFFFFFFFFFFFFFFFFFFA +:10D2C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6E +:10D2D000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5E +:10D2E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4E +:10D2F000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3E +:10D30000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2D +:10D31000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1D +:10D32000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0D +:10D33000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD +:10D34000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED +:10D35000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDD +:10D36000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCD +:10D37000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBD +:10D38000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAD +:10D39000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9D +:10D3A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8D +:10D3B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7D +:10D3C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6D +:10D3D000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D +:10D3E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4D +:10D3F000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3D +:10D40000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2C +:10D41000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1C +:10D42000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0C +:10D43000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC +:10D44000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEC +:10D45000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDC +:10D46000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCC +:10D47000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBC +:10D48000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAC +:10D49000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9C +:10D4A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8C +:10D4B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7C +:10D4C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6C +:10D4D000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5C +:10D4E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4C +:10D4F000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3C +:10D50000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2B +:10D51000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1B +:10D52000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0B +:10D53000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB +:10D54000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEB +:10D55000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDB +:10D56000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCB +:10D57000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBB +:10D58000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAB +:10D59000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9B +:10D5A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8B +:10D5B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7B +:10D5C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6B +:10D5D000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5B +:10D5E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4B +:10D5F000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3B +:10D60000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2A +:10D61000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1A +:10D62000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0A +:10D63000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA +:10D64000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEA +:10D65000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDA +:10D66000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCA +:10D67000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBA +:10D68000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAA +:10D69000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9A +:10D6A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8A +:10D6B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7A +:10D6C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6A +:10D6D000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5A +:10D6E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4A +:10D6F000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3A +:10D70000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF29 +:10D71000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF19 +:10D72000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF09 +:10D73000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9 +:10D74000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE9 +:10D75000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD9 +:10D76000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC9 +:10D77000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB9 +:10D78000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA9 +:10D79000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF99 +:10D7A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF89 +:10D7B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF79 +:10D7C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF69 +:10D7D000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF59 +:10D7E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF49 +:10D7F000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF39 +:10D800001A508ED88BBFFFF886841F8B0F020F0330 +:10D810000F0A0F0B0F000F010F080F09C63FD702A9 +:10D82000C63CD703C604D70AD70B860397188615BC +:10D8300097188E00596F84301F26FA6F8410CE0718 +:10D84000FF33E9FF004F971186C3971086019711A8 +:10D850004F97108E30D49F164F1F8B973D4F97498F +:10D86000974A974B974C8EDCCF9F2F0C31B6840094 +:10D870001CEF1A50BDDB68BDDA6D1CEFBDD8E79612 +:10D88000552703BDDA65BDD8FD20E7B684022A031B +:10D89000BDDA4BB684112A0784042703BDD8A3B68A +:10D8A00084163BB68403880897580A3E2A1286FFDE +:10D8B000973B0A3F2A0A0F3B860F973E8602973F07 +:10D8C0000A402A06863C97400F3D96264C81092E39 +:10D8D00004972620110F268E0027A6802F034AA723 +:10D8E0001F8C002826F439F68403965884082607EE +:10D8F000C4F7F784032005CA08F78403398E00496A +:10D90000B684008D213001B684018D1A3001B684B1 +:10D91000088D133001B684098D0C964D9A4E9A4F9E +:10D920009A50975520671F89A884A404A708A88443 +:10D93000A784E884E7043996532A2B944B2606865D +:10D940003C9727202B8E000EC6081A50A6842A0268 +:10D950000A03843FA78430015A26F1BDDB681CEF1F +:10D9600086FF9727200A962727162A04964B2A1DFA +:10D97000964A1F898A0094529752CA00D74A200DAE +:10D98000964A8A00439A52975286FF972796518E5D +:10D99000DC2D9F368EDC0D8D2596528EDC4D9F360C +:10D9A0008EDC2D8D1996538EDC6D9F368EDC4D8D61 +:10D9B0000D96548EDC8D9F368EDC6D8D01393402D0 +:10D9C000A484270DE6035AD73A9F28AE01AD849E62 +:10D9D00028350230049C3626E5398EDCA5BDD9ED0C +:10D9E000964B2A08961D847F971D0A0539972A9F12 +:10D9F00034AE02A684942A34029E34AE04A68497E0 +:10DA00002BA601972C9E34AE06D63ABDDC009F2D86 +:10DA100035024D272BA68427058AC0A78439962B6B +:10DA200026028AE04C8AC09E2DA7849E34AE046CE8 +:10DA300084A6846C01B6840284F7B784021A013983 +:10DA40009E2DA68484BFA7841CFE399E472712A65C +:10DA5000841F898480270AC47FE7849E2FAE846A4E +:10DA600001B68400398E618A301F26FC398EDCCFE6 +:10DA70009F34AE846D01262B8C00042705BDDB1777 +:10DA800020EE8608BA8402B784028EDCCF9F34AEC3 +:10DA9000846D8426108C0004273EBDDB1720EEBD6C +:10DAA000DBE73920490F43963B913C27F5973C260D +:10DAB000EE0C319E2F9F34AE84A684D6313404A15F +:10DAC000E02C09BDDB178601973120E99E349F2F9A +:10DAD000AE02BDDB277EDB078E00009F470F430DA4 +:10DAE0003D2B0A033D8ED2A09F34BDDBCD3986FF8E +:10DAF00097439E34860197319E34AE02BDDB276D7D +:10DB0000842A109E349F2F5C9E2FAE045A272B3000 +:10DB10000220F90C3120E19E34C606BDDC008CDC0D +:10DB2000E126038EDCCF395F9F47A684841F9131A5 +:10DB300027075C9E47300120EF399F56AE849F3403 +:10DB40000F3DC6209E47A684842027108EDCCF9CE4 +:10DB50002F2707C606BDDC0020F5E6069E34D74415 +:10DB600086FF9745BDDBCD398E00009F328E000EBB +:10DB70009F368E0006BDDB998E00029F328E001606 +:10DB80009F368E000EBDDB998E00049F328E0026DC +:10DB90009F368E0016BDDB99399F349E34A6841FB4 +:10DBA000894D2706841FC4C0270730019C3626ED07 +:10DBB000396F849E326A849E34E684C41F3404A183 +:10DBC000E02E026A8430019C3626EE20CE0D4327DB +:10DBD000049C4127089F418D0E9E418D05398D1172 +:10DBE0003001A6842AF839860E8D06860D8D0286B0 +:10DBF0000A3404F68418C40227F9B78419350439A5 +:10DC00009F38DB39D73924020C389E383901DCB50E +:10DC10000102DCB50204DCB50308DCB50410DCB598 +:10DC20000520DCB50640DCB50780DCB50801DCBCAE +:10DC30000102DCBC0204DCBC0308DCBC0410DCBC5C +:10DC40000520DCBC0640DCBC0780DCBC0801DCC372 +:10DC50000102DCC30204DCC30308DCC30410DCC320 +:10DC60000520DCC30640DCC30780DCC30801DCCA36 +:10DC70000902DCCA0A04DCCA0B08DCCA0C10DCCAC4 +:10DC80000D20DCCA0E40DCCA0F80DCCA1084000004 +:10DC900049000000068401004A0002000E840800CA +:10DCA0004B000400168408004B0004001684090091 +:10DCB0004C000400168EDC8DBDD9ED398EDC95BD8F +:10DCC000D9ED398EDC9DBDD9ED3939BDD9ED39009D +:10DCD000000006DCE10002000EDCF100040016DDAD +:10DCE00001D000D015D02AD03FD054D069D07ED0FA +:10DCF00093D0A8D0BDD0D2D0E7D0FCD111D126D1BD +:10DD00003BD150D165D17AD18FD1A4D1B9D1CED167 +:10DD1000E3D1F8D20DD222D237D24CD261D276D210 +:10DD20008BFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF77 +:10DD3000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3 +:10DD4000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE3 +:10DD5000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD3 +:10DD6000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC3 +:10DD7000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB3 +:10DD8000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA3 +:10DD9000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF93 +:10DDA000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF83 +:10DDB000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF73 +:10DDC000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF63 +:10DDD000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF53 +:10DDE000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF43 +:10DDF000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF33 +:10DE0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF22 +:10DE1000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF12 +:10DE2000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF02 +:10DE3000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2 +:10DE4000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE2 +:10DE5000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD2 +:10DE6000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC2 +:10DE7000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB2 +:10DE8000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA2 +:10DE9000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF92 +:10DEA000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF82 +:10DEB000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF72 +:10DEC000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF62 +:10DED000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF52 +:10DEE000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF42 +:10DEF000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF32 +:10DF0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF21 +:10DF1000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF11 +:10DF2000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF01 +:10DF3000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1 +:10DF4000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE1 +:10DF5000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD1 +:10DF6000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC1 +:10DF7000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB1 +:10DF8000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA1 +:10DF9000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF91 +:10DFA000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF81 +:10DFB000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF71 +:10DFC000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF61 +:10DFD000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF51 +:10DFE000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF41 +:10DFF000FFFFFFFFFFFFFFFFD88BFFFFFFFFD800F2 +:00000001FF diff --git a/samples/2299.HEX b/samples/2299.HEX new file mode 100755 index 0000000..a5aa6f2 --- /dev/null +++ b/samples/2299.HEX @@ -0,0 +1,514 @@ + +:10E000001A108EE1DCBFFFF88EE000BFFFFE8E002D +:10E01000006F808C080026F910CE00FFCC11403430 +:10E02000068602BDF4E7CC118034068602BDF4E713 +:10E030007F128386FFB71281C606F71283B712815B +:10E040007F130386FFB71301C605F71303B7130148 +:10E050007D13017F13027F13008605B713027F1221 +:10E06000827F12808604B7128286FFB7122CB71205 +:10E070002D86F0B7122E86FFB7122F86FAB7122D13 +:10E0800086FBB7122CB6122E84FDB7122E86FFC661 +:10E09000038E124686FFA71EA71FA7846F0186FB6B +:10E0A000A71EA71F30045A2AEB8601B7018CBDF3C7 +:10E0B00058B6080081AA261A7EE1C0434F4C44207E +:10E0C0005354415254FF41434B4E4F574C454447E4 +:10E0D00045FF8E08005FBDF39330018C08DC26F607 +:10E0E0008E0703108EE205E6A0C1FF2707BDF3935C +:10E0F000300120F38E0867108EE25BE6A0C1FF2797 +:10E1000007BDF393300120F38E07CBC602BDF39316 +:10E110008E07CFBDF393C6FF8E08D3BDF393301F98 +:10E120008C08D026F6C60C8E08D6BDF393301F8C13 +:10E1300008D326F68E08CDBDF3935F3001BDF3936F +:10E14000C6AA8E0800BDF3938E0802A68443BDF3D1 +:10E150008910CE00FFBDE7DB867FB713018EE0BBE1 +:10E16000BDF0CD8EE0C6BDF0C7B613007D13032A07 +:10E17000FB86F7B713018E0800A684A789FF00303D +:10E18000018C08DC2DF34FB70179B7017886FEB713 +:10E19000016D867FB7016EB61301B61300B612800B +:10E1A0001CEF8E014463808C016326F986438E0048 +:10E1B00003A78901636F890156301F26F47EE34A65 +:10E1C00010CE00FF86808E0188BDE597BDE7DB7D20 +:10E1D00008022BA28EE745BF0181209AB6122D2B93 +:10E1E00003BDF3B0B613022A03BDEBDCB611402A1F +:10E1F00003BDF5ABB611802A03BDF667B613032A3B +:10E2000003BDECA13B010005000100010001000F6E +:10E2100000000001000000050001000500010005EC +:10E2200000010005000100050001000500010005D6 +:10E2300000010005000100050001000500010005C6 +:10E2400000010005000100050003000100011E019E +:10E25000000000030005000000FFFF000F00190090 +:10E260000F0200020014000000000F0A00000F005F +:10E270000F000F000F000F000F000F000F000F0026 +:10E280000F000F000F000F000F000F000F000F0016 +:10E290000F000F000F000F000F000F000F000F0006 +:10E2A0000F050002000F0002000A00000F000F001F +:10E2B0000FFFFF8E124EC602BF0100BDE984BE01F2 +:10E2C00000A6848E0164BDF123A8848EE32CBF01D7 +:10E2D0000B8EE3238D3310BE0100313C10BF0100D3 +:10E2E0005A2AD8B61300B8016D8EE33EBF010B8EDB +:10E2F000E32C8D15BDE451BDE509B61280B8016E61 +:10E300008EE34ABF010B8EE33EA584270EBF0102B8 +:10E310003402AE01AD84BE010235023003BC010BF4 +:10E3200026E73901EA3E04EBB040EB1902E40304AE +:10E33000E42908E4D510E4DC40E47D80EAE401E46B +:10E340002202E49804E4B480EB7C7D01B22703BD93 +:10E35000F2317D01792B0E7D010D27098E010F739E +:10E360000179BDF0CDBDED001CEFBDE2B3BDF1E71D +:10E37000BDE643BDF078BDEFCCB6080081AA270307 +:10E38000BDE5D27D017026C27D08022A0E7D08D827 +:10E390002F1DBDF1398E0802BDF3897D016326AAC8 +:10E3A0007D08022D0AF60802BE0181AD84209B7D06 +:10E3B00001792B967D010D2E058EF21920038EE337 +:10E3C000CD730179BDF0CDBDE3E216FF7D2053454D +:10E3D0005256494345FF1300016D01881280016EBA +:10E3E000018DB607DE271B7D07DF2616B607DD2762 +:10E3F00009867FB41301B71301398680BA1301B7B8 +:10E4000013013986028EE3D6BDE55B240B8602BA82 +:10E41000122EB7122E7EE6297A017086FDBDE445E4 +:10E42000201C86018EE3DC200586048EE3D6BDE544 +:10E430005B24098601BA122EB7122E3986FEB41259 +:10E440002EB7122E397D08022B068EE745BF0181BB +:10E45000398620B41300261CB6130184082754B64D +:10E4600007CFB707D7B607D0B7015A86F7B413015D +:10E47000B71301397D015A2A3A8608203086408E2A +:10E48000E3D6BDE55B2409F608027F01617EF064F6 +:10E490007301617F016720AD86028EE3DCBDE55B21 +:10E4A000240986BFB41301B71301398640BA13019A +:10E4B000B713013986048EE3DCBDE55B240C86FFCF +:10E4C000B70171BDE6297A0170397F0171B6070184 +:10E4D000811427BF398EE3D6860820058EE3D686C1 +:10E4E000108D78398EE3DC8620BDE5A2241AF6086B +:10E4F000027EF06486108EE3DCBDE5A27C0167BD80 +:10E50000E6297A01707C018439B612808440271C88 +:10E510007D01602B0E86BFB40190B701907A017027 +:10E52000BDE44586FFB70153B70160397D0160271F +:10E530001A7D01532D102E1386408E018DBDE5F0FE +:10E540007F01607EE6298605B70153398EE3DC86BC +:10E55000088D4F24B3F608027EF064B70108BF01AE +:10E5600009BDECF8BE010934041F894DAE02E484F4 +:10E57000BE0109AE84A4843404A1E0273535044DDE +:10E580002637B6010843BE0109AE02A484A784B6AB +:10E590000108BE0109AE04BDE5F08D4B7F07DF1A0F +:10E5A0000139B70108BF0109AE84A68443B401084C +:10E5B00020CE35043261326139BE0109AE02AA842F +:10E5C000A784B6010843BE0109AE04A403A7031C37 +:10E5D000FE398EEFB1BDF0C71A108D4DB613007D18 +:10E5E00013012AFB7EE000867FB41301B7130139C3 +:10E5F000340234023402AA01A7013502AA02A7029A +:10E600003502AA03A70335027D017D260E73017D25 +:10E610007F018C7F01917F0196A7043986108E01BE +:10E62000928DCDF608027EF0648E124EC6026F0106 +:10E63000301C5A2AF986B7BA1301847FB713017CBC +:10E640000170397D017026537D0184264E86FFB707 +:10E6500001838E124EC602BF0104A6848440277037 +:10E66000F1080227378E017EBDF1236D841FA8BEFD +:10E6700001041F8A27057A010D20557D01712B5059 +:10E68000860FA701301C5A2ACEB613018A377D01A6 +:10E690000D270284FDB40183B71301397D01612781 +:10E6A0002F7D0167262A7D015F2AF08EE7ED340475 +:10E6B000F60701BDF121AE84BF013F3504A68443B6 +:10E6C000B71281A60143B70183A602BE010420B29E +:10E6D0006F0120B07D0167260F7D0161270A7D0152 +:10E6E000632A067D07DE2A0139F60802BDEA1C43CB +:10E6F000B40195B701958E017EBDF1236F847F0132 +:10E70000777C0701F60701C107260586FFB707DEFC +:10E71000C12B26317F07018E08014FBDF389B60753 +:10E72000CDF608028E07D4BDF123A7848E0157BD14 +:10E73000F1236F8486FF8E07D1BDF123A7848E0855 +:10E7400002BDF38939B607018E0801BDF389B60110 +:10E750009584C7B70195B6019084C7B70190BDEA0B +:10E760008E7D015F2D078EE761BF018139F60701BC +:10E77000BDF0988E1246F60802BDF123BF013DBDE3 +:10E78000E643BE013FA604260C7D0146274D8EE7D9 +:10E7900089BF018139810126188EE79FBF0181BEA3 +:10E7A000013DA684BE013FA50526307D01462738E0 +:10E7B000398EE7B7BF0181BE013DA684BE013FA5EA +:10E7C0000526067D0149272039F60701BDF0988E00 +:10E7D000E7D5BF01817D01462701398EE6D4BF010F +:10E7E0008139AE01AD8420F3BDE61C20EEE8A3E83C +:10E7F00043E849E84FE85BE86DE84FE891E85BE8FB +:10E8000061E843E85BE843E85BE843E85BE843E84A +:10E810005BE843E85BE843E85BE843E85BE843E840 +:10E820005BE843E85BE843E85BE843E85BE843E830 +:10E830005BE86DE855E85BE84FE85BE867E86DE8A2 +:10E8400097E89D000084000000200284100000066C +:10E8500010800001080610800001100A14800800D2 +:10E86000000B15801001080B15801001100311809A +:10E870000000000321800000000220800000005200 +:10E8800022891000004222890000008220800000BE +:10E890000082208000000042228910000000028BCC +:10E8A00000000000020F000000E8FDE904E90DE9A6 +:10E8B00014E927E90DE960E914E91CE8FDE914E829 +:10E8C000FDE914E8FDE914E8FDE914E8FDE914E8C0 +:10E8D000FDE914E8FDE914E8FDE914E8FDE914E8B0 +:10E8E000FDE914E8FDE914E8FDE914E927E90DE97B +:10E8F00014E90DE914E91CE927E96BE97820504196 +:10E90000555345FF204F494C204F5554FF2044524A +:10E9100041494EFF2041495220494EFF2041495272 +:10E9200020464C555348FF534C5544474509464CE7 +:10E93000555348FF20464C555348FF2053455454E7 +:10E940004C45FF50524552554E2056454E54FF20DF +:10E9500050524552554EFF205354414E444259FFA8 +:10E9600020484F4C442053544550FF46494E414C9B +:10E970002050524552554EFF5052452D5345525648 +:10E98000494345FFF10802272B8E12468D33A6849A +:10E9900084A0263186FF8E01548D26A7848E07D150 +:10E9A0008D1FA7848E015C8D18A7848E017E8D112A +:10E9B0006D842610F1010E260B86FEB4018BB70183 +:10E9C0008BBDF123398E015C8DF76D842E592D5846 +:10E9D000BDF1748E12468DE98680A484270D8D3C8E +:10E9E000B5019526068E0192BDE5F08E07D18DD139 +:10E9F0006D842E332D378E01548DC66D842E28BD27 +:10EA0000E5E7BDF0647A01678E017E8DB486FFA7CD +:10EA10008486018E0188F7010E7EE5F034044F1ADA +:10EA200001495A2AFC350439860FA78439B607CB29 +:10EA3000A7848E0154BDF123B607CCA784398E126A +:10EA400046BDF123A6848401272DA6848440271384 +:10EA5000F10802260E8EEA7234048D44350486FFD6 +:10EA6000B7016386018E0164BDF123AA84A7847E69 +:10EA7000F1BD484F4C44FFF1080226057F01638D2C +:10EA80000D86FE8E0164BDF123A484A7843934046D +:10EA9000F607018EE8A7BDF121AE848D0335043958 +:10EAA000BF013B8643B00802B7010F8620B70110B3 +:10EAB000B70113F60701BDEFBFB70111F701128EC1 +:10EAC0000114BF0139BE013BA680BF013BBE013925 +:10EAD000A7842B073001BF013920EA7F01798E011D +:10EAE0000F7EF0CDBDECF8B613008480262A7D0899 +:10EAF000022B1F7D0163261A7D017026158601B742 +:10EB0000015FBDE7DB7D017727057C0701200373EB +:10EB100001777F01677F0184398E1246BDF123A6FC +:10EB20008484402638BDECF8BDF1BDF10802261BF7 +:10EB3000BDE7DB7F07014F8E0801BDF38986FF8E9D +:10EB40000802BDF3897F01637F01677D01712B0C92 +:10EB500086BF8E0164BDF123A484A784397D017131 +:10EB60002B198E0164BDF1238640AA84A784397DC8 +:10EB700008D82607326132617A070139B6128084DB +:10EB80008027138E018D8680BA016EB7016E868054 +:10EB9000BDE5F07EE6297A01707F0184866FB401BD +:10EBA00090B70190B6016E846FB7016E7F0167392F +:10EBB000BDECF88E1246BDF123A68484042710BD57 +:10EBC000F17486048E0164BDF123AA84A78439867A +:10EBD000FB8E0164BDF123A484A784397A019727B1 +:10EBE000031600B9860AB70197B607DC4CB707DCF5 +:10EBF000810F2E0786FFB707DD200D7F07DDB607E3 +:10EC0000DC812D2D037F07DC7A0198270316008D08 +:10EC1000861EB701987D01B82F037A01B8C6058E0C +:10EC200001446D012F046A01200E6D842F086A844F +:10EC3000863BA70120026F025A2704300320E373AA +:10EC4000016BF70179F701788E015CC6026D842FA4 +:10EC5000026A8430015A2AF57D015F2D037A015F33 +:10EC60007D01532F037A01537A015B2E30863CB726 +:10EC7000015BC6068E0154BDF12A6D842D1C6A8489 +:10EC80002C18863CA7848E07D1BDF12A6A842C0AF1 +:10EC9000A6848E0154BDF12AA7845A2AD7B6130040 +:10ECA000397D01B626057D01B22703BDF4578E01DB +:10ECB00088867FA40DA70D867FA403A7037F017D0F +:10ECC0006D042605BDF09520F7A60243AA0443A7CC +:10ECD000027D07DE27087D07DF27037F07DE7D0132 +:10ECE0008A26127D018F260D7D019426088680BA22 +:10ECF0001301B713017D13018EFFFF301F26FC396E +:10ED00008E01886D012655BDF0958C019726F47D06 +:10ED100001782B0C7301788EED21BDF0C7BDED2C71 +:10ED2000392053595354454D204F4BFF7D08022B3A +:10ED30002A8E0124CC2020ED81F601442B1DBDEF4D +:10ED4000BFED81863AA780F601452B0FBDEFBFEDE1 +:10ED50008186FFA7848E0124BDF106398E0188A625 +:10ED600002A401260ABDF0958C019726F220112BF2 +:10ED700003BDE5E7BDEDC5A4022646BDEDC320F702 +:10ED80008E0188B6016BB1016C2713B7016C270F98 +:10ED9000860A3406CC000234068604BDF56639A620 +:10EDA00001A403A701BDF0958C019726F27D018B8C +:10EDB000260D7D019026087D0195260316FF508DB6 +:10EDC00002202D8D1C5F8E01886D042606BDF095F6 +:10EDD0005C20F6A601A40426168D066D0426F420F8 +:10EDE000E478018C79019179019624037C018C39B6 +:10EDF0008EEE135D270530025A20F8AE84A58426D6 +:10EE00000930038CEE5B270A20F3AE017F0178BD49 +:10EE1000F0C739EE19EE31EE4901EFA002EE9B0486 +:10EE2000EEAA08EF0710EF1B20EEBA40EEE680EFE7 +:10EE30009401EEF602EEC904EED708EF6610EF4239 +:10EE400020EF2F40EF5380EF8680012401EE7B02FC +:10EE5000EE6B04EE5B08EE5B10EF7448492044490A +:10EE600046462050524553532041FF4849204449CB +:10EE700046462050524553532042FF4849204449BA +:10EE800046462050524553532043FF4849204449A9 +:10EE900046462050524553532044FF4C4F57205371 +:10EEA000555247452054414E4BFF4849474820534F +:10EEB000555247452054414E4BFF4C4F5720534C21 +:10EEC0005544474520504954FF4C4F5720434C452B +:10EED000415257454C4CFF4849474820434C454117 +:10EEE0005257454C4CFF4849474820534C554447DE +:10EEF0004520504954FF484920484920535552471E +:10EF0000452054414E4BFF4C4F57204348454D49F7 +:10EF100043414C2054414E4B2031FF4C4F5720432E +:10EF200048454D4943414C2054414E4B2032FF4C03 +:10EF30004F5720505245535355524520464C555338 +:10EF400048FF4C4F57205052455320534552564985 +:10EF50004345FF4C4F5720494E535452554D454E53 +:10EF60005420414952FF4C4F5720534352554220A1 +:10EF7000414952FF4C4556454C205357495443484C +:10EF8000204641494CFF204D4153544552202020FA +:10EF90004F4646FF20504F574552204641494CFFAF +:10EFA000484920505245532053485554444F574EDA +:10EFB000FF204D454D4F525920204641494CFF4FAF +:10EFC000C00A2B034C20F9CB3A8B3039B612804360 +:10EFD0004444445F445944594459F7016AB6130103 +:10EFE000438407B701698604B70168B50169275BE7 +:10EFF000B5016A26208D668E014ABDF11F6D842BF6 +:10F000002126126D01260E6D02260A8EF01CBDF11E +:10F0100021AE84AD84B601684426CD39E4E4E4F43D +:10F02000E54CB601688D368E014ABDF11FBF010067 +:10F030008E0767F607015A2A02C601BDF121A68490 +:10F04000E601BE0100A784E70120CA8E014A8D0DAA +:10F05000BDF11FC6FFE784E701E70220B85F535CFC +:10F060004426FC398E1246BDF1236F018635BA1352 +:10F0700001B713017C016739C6028E07D4BDF123A5 +:10F080006D842E0D8E0157BDF1236D842E03BDF1CD +:10F09000745A2AE63930053934025A8E0703BDF115 +:10F0A00021A684B70144A601B70145C6198D72A6F1 +:10F0B00084B70147A601B7014886FFB70146B701EB +:10F0C00049B70149350239108E00022004108E0024 +:10F0D0000110BF01993410CC000E3406FC019934A4 +:10F0E000068604BDF566CC000A3406FC0199340698 +:10F0F0008604BDF566CC000D3406FC019934068605 +:10F1000004BDF5663510E6842B1434103406FC017A +:10F110009934068604BDF5663510300120E8398D36 +:10F12000028D001A108D031CEF398C12442D088CAF +:10F1300012542E033A3A3A3A398E08D9A684340248 +:10F14000F608D8272AA601BDF38930015A26F68E83 +:10F1500008D8A6844ABDF38935021F898E1246BDA0 +:10F16000F123E684C44027D1E684C40126CB393597 +:10F170000286FF397D016127278E08D9B608D82776 +:10F1800009E184271B30014A26F7F108022711BD47 +:10F19000F1A1250CBDF3938E08D8A6844CBDF3894C +:10F1A0003934168E1246BDF123E684C440270AE6A0 +:10F1B00084C40126041CFE35961A0135968E08D9A2 +:10F1C000B608D82721E184270630014A26F73934CA +:10F1D00004E601BDF39330014A26F635048E08D8C3 +:10F1E000A6844ABDF389397D01712B3BB612808418 +:10F1F000802634C603F7010D5A8E1246BDF123A6B0 +:10F200008484402705F1080226037A010D5A2AE971 +:10F210007D010D26037F017939205345525649431C +:10F2200045204F464621FF7F010D3923201B080F43 +:10F23000FFBDF361B601B281FF270D81FE27047F78 +:10F2400001B2398EF35220038EF34C7F01B1C60612 +:10F25000108E019BBDF36F8EF22BC606BDF36F8E31 +:10F26000019BBDF0C7CC0809FD01B3B701B5CC3097 +:10F27000FFB701B8F701B7F701B67D01B727087DE1 +:10F2800001B82EF61600B98E01A3EC84C1302C070C +:10F290001F898630FD01A3BDF377C16326098E085F +:10F2A00000BDF3937EE000F701735A2B87C1342C25 +:10F2B000838E0803C1322C0AB601B281FF27038E68 +:10F2C00008673A3ABF0173E684BDEFBFFD01A8E6C7 +:10F2D00001BDEFBFFD01ABCC202DFD01A5B701A7FE +:10F2E000C63AF701AA8EF22D108E01ADC604BDF309 +:10F2F0006F860DB701AE8E019BBDF0C7CC0D11FD21 +:10F3000001B3B701B5CC30FFB701B8F701B7F701CA +:10F31000B67D01B727077D01B82EF62023FC01A892 +:10F32000BDF377BE0173E784BDF393E789FF003037 +:10F3300001FC01ABBDF377E784E789FF00BDF393E0 +:10F3400086FFB701B17F01B27F01B6392053544522 +:10F350005020414C41524D0986FFB701B1B701B76A +:10F36000398E019BBF01B96F808C01AF2CF939A692 +:10F3700080A7A05A26F9398330305D2A041F8920DE +:10F38000073404C60A3DEBE039A1842705A784BDF4 +:10F39000F39D39E1842705E784BDF39D3934108E50 +:10F3A00004E2301F26FC3590010204081020408042 +:10F3B0007D0802102A009C7D01B12716BDF39DB681 +:10F3C000122E84E0260486FF200286FEB701B216C4 +:10F3D0000081BDF39DBDF39DF6122E545454542765 +:10F3E00016C10C2772C1082746C1042726BDF4B2F6 +:10F3F0004D2B608B08200BF6122F2757BDF4B24D12 +:10F400002B51810A2C0D4C810A26014F8B30202173 +:10F410000820087D01B626698EF410C603BDF4C726 +:10F42000BE01B9301F8C019B2D29BF01B920248654 +:10F43000207D01B62661BE01B9B71181A780BF0149 +:10F44000B98C01AF2C11200B7F01B77F01B286FF71 +:10F45000B701B1B6122F397D01B62609860DBE015E +:10F46000B9A78420E37F01B720E97C01B5F601B597 +:10F47000C1142CE3C61BBDF4DCF601B5BDF4DC20E1 +:10F48000D2C61BBDF4DCF601B5F101B32F045AF767 +:10F4900001B5BDF4DC20BC812027CFF601B58E017B +:10F4A0009BA785B711817C01B5F601B5C1142EA7C4 +:10F4B00020A134144F8EF3A8E680E1E427074C81A5 +:10F4C000082DF586FF35948D065A270220F939B6A6 +:10F4D0001180840227F9A680B7118139B611808482 +:10F4E0000227F9F711813980022703BDF71535107E +:10F4F000350634101F018603A7848615A784B7013B +:10F50000BAB702015F4F3980022703BDF715E663E2 +:10F51000C1012624BDF62027FBC10D2604C60A2002 +:10F5200009C1042605CCFFFF203434063406CC0084 +:10F53000013406BDF56D2026C1022622BDF6D52771 +:10F54000FBC10D2604C60A2009C1042605CCFFFF15 +:10F55000200C34063406CC00023406BDF56D3506A9 +:10F56000351032626E8480042703BDF715E665A668 +:10F5700063810126073406BDF65420098102262541 +:10F580003406BDF7022BE6C10A261AC60DA6638112 +:10F590000126073406BDF6542009810226073406E9 +:10F5A000BDF7022BE6351032646E84850126058591 +:10F5B00002263B3985702704B6114139F60200C195 +:10F5C000202D0FF601BAC47FF701BAF71140B6112A +:10F5D0004139B61141847FF601FF8E01DEA7855CBB +:10F5E000F701FF7C0200C1202D037F01FF397D015F +:10F5F000DD260CF601BAC49FF701BAF7114039F6BF +:10F6000001DB8E01BBA685B711417A01DD5CF701F4 +:10F61000DBC1202D037F01DB3980002703BDF715F7 +:10F620007D020026045F4F2022B601FE8E01DEE639 +:10F63000864CB701FE81202D037F01FE7A0200B6C1 +:10F6400001BA8A80B701BAB711404F5D39800227ED +:10F6500003BDF715B61140840227F93510ECE1F728 +:10F6600011418300006E84850126058502263B3901 +:10F6700085702704B6118139F60247C1202D0FF697 +:10F680000201C47FF70201F71180B6118139B6116A +:10F6900081847FF602468E0225A7855CF702467CB0 +:10F6A0000247C1202D037F0246397D0224260CF635 +:10F6B0000201C49FF70201F7118039F602228E027F +:10F6C00002A685B711817A02245CF70222C1202D9F +:10F6D000037F0222397D024726045F4F2022B602B3 +:10F6E000458E0225E6864CB7024581202D037F0218 +:10F6F000457A0247B602018A80B70201B711804FEE +:10F700005D39B61180840227F93510ECE1F71181DB +:10F710008300006E842721C60025101E8930EBEC83 +:10F72000E4EE62ED84EF021F142009353034044CFE +:10F7300026FB34301A021CFE39FFFFFFFFFFFFFFDC +:10F74000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC9 +:10F75000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB9 +:10F76000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA9 +:10F77000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF99 +:10F78000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF89 +:10F79000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF79 +:10F7A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF69 +:10F7B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF59 +:10F7C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF49 +:10F7D000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF39 +:10F7E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF29 +:10F7F000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF19 +:10F80000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF08 +:10F81000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8 +:10F82000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE8 +:10F83000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD8 +:10F84000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC8 +:10F85000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB8 +:10F86000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA8 +:10F87000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF98 +:10F88000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF88 +:10F89000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF78 +:10F8A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF68 +:10F8B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF58 +:10F8C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF48 +:10F8D000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF38 +:10F8E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF28 +:10F8F000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF18 +:10F90000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF07 +:10F91000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7 +:10F92000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE7 +:10F93000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD7 +:10F94000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7 +:10F95000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB7 +:10F96000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA7 +:10F97000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF97 +:10F98000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF87 +:10F99000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF77 +:10F9A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF67 +:10F9B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF57 +:10F9C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF47 +:10F9D000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF37 +:10F9E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF27 +:10F9F000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF17 +:10FA0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF06 +:10FA1000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6 +:10FA2000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE6 +:10FA3000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD6 +:10FA4000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC6 +:10FA5000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB6 +:10FA6000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA6 +:10FA7000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF96 +:10FA8000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF86 +:10FA9000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF76 +:10FAA000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF66 +:10FAB000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56 +:10FAC000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF46 +:10FAD000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF36 +:10FAE000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF26 +:10FAF000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF16 +:10FB0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF05 +:10FB1000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5 +:10FB2000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE5 +:10FB3000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD5 +:10FB4000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC5 +:10FB5000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB5 +:10FB6000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA5 +:10FB7000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF95 +:10FB8000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF85 +:10FB9000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF75 +:10FBA000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF65 +:10FBB000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF55 +:10FBC000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF45 +:10FBD000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF35 +:10FBE000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF25 +:10FBF000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF15 +:10FC0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF04 +:10FC1000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4 +:10FC2000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE4 +:10FC3000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD4 +:10FC4000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC4 +:10FC5000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB4 +:10FC6000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA4 +:10FC7000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF94 +:10FC8000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF84 +:10FC9000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF74 +:10FCA000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF64 +:10FCB000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF54 +:10FCC000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF44 +:10FCD000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF34 +:10FCE000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF24 +:10FCF000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF14 +:10FD0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF03 +:10FD1000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3 +:10FD2000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE3 +:10FD3000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD3 +:10FD4000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC3 +:10FD5000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB3 +:10FD6000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA3 +:10FD7000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF93 +:10FD8000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF83 +:10FD9000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF73 +:10FDA000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF63 +:10FDB000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF53 +:10FDC000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF43 +:10FDD000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF33 +:10FDE000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF23 +:10FDF000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF13 +:10FE0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF02 +:10FE1000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2 +:10FE2000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE2 +:10FE3000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD2 +:10FE4000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC2 +:10FE5000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB2 +:10FE6000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA2 +:10FE7000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF92 +:10FE8000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF82 +:10FE9000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF72 +:10FEA000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF62 +:10FEB000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF52 +:10FEC000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF42 +:10FED000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF32 +:10FEE000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF22 +:10FEF000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF12 +:10FF0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF01 +:10FF1000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1 +:10FF2000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE1 +:10FF3000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD1 +:10FF4000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC1 +:10FF5000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB1 +:10FF6000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA1 +:10FF7000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF91 +:10FF8000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF81 +:10FF9000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF71 +:10FFA000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF61 +:10FFB000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF51 +:10FFC000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF41 +:10FFD000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF31 +:10FFE000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF21 +:10FFF000FFFFFFFFFFFFFFFFE1DCFFFFFFFFE00070 +:00000001FF diff --git a/samples/2299.MIK b/samples/2299.MIK new file mode 100755 index 0000000..7451593 --- /dev/null +++ b/samples/2299.MIK @@ -0,0 +1,222 @@ +S126E0001A108EE1DCBFFFF88EE000BFFFFE8E00006F808C080026F910CE00FFCC114034068602B8 +S126E023BD0000CC118034068602BD00007F128386FFB71281C606F71283B712817F130386FFB7E7 +S126E0461301C605F71303B713017D13017F13027F13008605B713027F12827F12808604B71282F5 +S126E06986FFB7122CB7122D86F0B7122E86FFB7122F86FAB7122D86FBB7122CB6122E84FDB7120A +S126E08C2E86FFC6038E124686FFA71EA71FA7846F0186FBA71EA71F30045A2AEB8601B7018CBD29 +S126E0AF0000B6080081AA261A7EE1C0434F4C44205354415254FF41434B4E4F574C45444745FF10 +S126E0D28E08005FBD000030018C08DC26F68E0703108EE205E6A0C1FF2707BD0000300120F38E98 +S126E0F50867108EE25BE6A0C1FF2707BD0000300120F38E07CBC602BD00008E07CFBD0000C6FF7A +S126E1188E08D3BD0000301F8C08D026F6C60C8E08D6BD0000301F8C08D326F68E08CDBD00005F9F +S126E13B3001BD0000C6AA8E0800BD00008E0802A68443BD000010CE00FFBDE7DB867FB713018E90 +S126E15EE0BBBDF0CD8EE0C6BDF0C7B613007D13032AFB86F7B713018E0800A684A789FF003001F4 +S126E1818C08DC2DF34FB70179B7017886FEB7016D867FB7016EB61301B61300B612801CEF8E01EE +S126E1A44463808C016326F986438E0003A78901636F890156301F26F47EE34A10CE00FF86808E5C +S126E1C70188BDE597BDE7DB7D08022BA28EE745BF0181209AB6122D2B03BD0000B613022A03BD52 +S126E1EAEBDCB611402A03BD0000B611802A03BD0000B613032A03BDECA13B01000500010001009F +S126E20D01000F0000000100000005000100050001000500010005000100050001000500010005B0 +S126E2300001000500010005000100050001000500010005000100050003000100011E010000007F +S126E253030005000000FFFF000F0019000F0200020014000000000F0A00000F000F000F000F00FA +S126E2760F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F73 +S126E299000F000F000F000F050002000F0002000A00000F000F000FFFFF8E124EC602BF0100BDA2 +S126E2BCE984BE0100A6848E0164BDF123A8848EE32CBF010B8EE3238D3310BE0100313C10BF012D +S126E2DF005A2AD8B61300B8016D8EE33EBF010B8EE32C8D15BDE451BDE509B61280B8016E8EE397 +S126E3024ABF010B8EE33EA584270EBF01023402AE01AD84BE010235023003BC010B26E73901EAD6 +S126E3253E04EBB040EB1902E40304E42908E4D510E4DC40E47D80EAE401E42202E49804E4B48095 +S126E348EB7C7D00002703BD00007D01792B0E7D010D27098E010F730179BDF0CDBDED001CEFBD81 +S126E36BE2B3BDF1E7BDE643BDF078BDEFCCB6080081AA2703BDE5D27D017026C27D08022A0E7D45 +S126E38E08D82F1DBDF1398E0802BD00007D016326AA7D08022D0AF60802BE0181AD84209B7D01E7 +S126E3B1792B967D010D2E058EF21920038EE3CD730179BDF0CDBDE3E216FF7D20534552564943EC +S126E3D445FF1300016D01881280016E018DB607DE271B7D07DF2616B607DD2709867FB41301B77B +S126E3F71301398680BA1301B713013986028EE3D6BDE55B240B8602BA122EB7122E7EE6297A015E +S126E41A7086FDBDE445201C86018EE3DC200586048EE3D6BDE55B24098601BA122EB7122E39869B +S126E43DFEB4122EB7122E397D08022B068EE745BF0181398620B41300261CB6130184082754B674 +S126E46007CFB707D7B607D0B7015A86F7B41301B71301397D015A2A3A8608203086408EE3D6BD5E +S126E483E55B2409F608027F01617EF0647301617F016720AD86028EE3DCBDE55B240986BFB413BE +S126E4A601B71301398640BA1301B713013986048EE3DCBDE55B240C86FFB70171BDE6297A017049 +S126E4C9397F0171B60701811427BF398EE3D6860820058EE3D686108D78398EE3DC8620BDE5A244 +S126E4EC241AF608027EF06486108EE3DCBDE5A27C0167BDE6297A01707C018439B61280844027CA +S126E50F1C7D01602B0E86BFB40190B701907A0170BDE44586FFB70153B70160397D0160271A7D92 +S126E53201532D102E1386408E018DBDE5F07F01607EE6298605B70153398EE3DC86088D4F24B3B2 +S126E555F608027EF064B70108BF0109BDECF8BE010934041F894DAE02E484BE0109AE84A4843440 +S126E57804A1E0273535044D2637B6010843BE0109AE02A484A784B60108BE0109AE04BDE5F08D93 +S126E59B4B7F07DF1A0139B70108BF0109AE84A68443B4010820CE35043261326139BE0109AE0272 +S126E5BEAA84A784B6010843BE0109AE04A403A7031CFE398EEFB1BDF0C71A108D4DB613007D13BE +S126E5E1012AFB7EE000867FB41301B7130139340234023402AA01A7013502AA02A7023502AA0359 +S126E604A70335027D017D260E73017D7F018C7F01917F0196A7043986108E01928DCDF608027E48 +S126E627F0648E124EC6026F01301C5A2AF986B7BA1301847FB713017C0170397D017026537D01A5 +S126E64A84264E86FFB701838E124EC602BF0104A68484402770F1080227378E017EBDF1236D84CA +S126E66D1FA8BE01041F8A27057A010D20557D01712B50860FA701301C5A2ACEB613018A377D01DC +S126E6900D270284FDB40183B71301397D0161272F7D0167262A7D015F2AF08EE7ED3404F6070177 +S126E6B3BDF121AE84BF013F3504A68443B71281A60143B70183A602BE010420B26F0120B07D0130 +S126E6D667260F7D0161270A7D01632A067D07DE2A0139F60802BDEA1C43B40195B701958E017EF0 +S126E6F9BDF1236F847F01777C0701F60701C107260586FFB707DEC12B26317F07018E08014FBD3C +S126E71C0000B607CDF608028E07D4BDF123A7848E0157BDF1236F8486FF8E07D1BDF123A7848EC8 +S126E73F0802BD000039B607018E0801BD0000B6019584C7B70195B6019084C7B70190BDEA8E7D31 +S126E762015F2D078EE761BF018139F60701BDF0988E1246F60802BDF123BF013DBDE643BE013FD1 +S126E785A604260C7D0146274D8EE789BF018139810126188EE79FBF0181BE013DA684BE013FA503 +S126E7A80526307D01462738398EE7B7BF0181BE013DA684BE013FA50526067D0149272039F607E8 +S126E7CB01BDF0988EE7D5BF01817D01462701398EE6D4BF018139AE01AD8420F3BDE61C20EEE8C7 +S126E7EEA3E843E849E84FE85BE86DE84FE891E85BE861E843E85BE843E85BE843E85BE843E85B42 +S126E811E843E85BE843E85BE843E85BE843E85BE843E85BE843E85BE843E85BE843E85BE86DE833 +S126E83455E85BE84FE85BE867E86DE897E89D000084000000200284100000061080000108061014 +S126E857800001100A14800800000B15801001080B158010011003118000000003218000000002AF +S126E87A20800000005222891000004222890000008220800000008220800000004222891000009C +S126E89D00028B00000000020F000000E8FDE904E90DE914E927E90DE960E914E91CE8FDE914E8D6 +S126E8C0FDE914E8FDE914E8FDE914E8FDE914E8FDE914E8FDE914E8FDE914E8FDE914E8FDE91427 +S126E8E3E8FDE914E8FDE914E927E90DE914E90DE914E91CE927E96BE978205041555345FF204F7E +S126E906494C204F5554FF20445241494EFF2041495220494EFF2041495220464C555348FF534CC3 +S126E9295544474509464C555348FF20464C555348FF20534554544C45FF50524552554E205645F0 +S126E94C4E54FF2050524552554EFF205354414E444259FF20484F4C442053544550FF46494E4114 +S126E96F4C2050524552554EFF5052452D53455256494345FFF10802272B8E12468D33A68484A0D5 +S126E992263186FF8E01548D26A7848E07D18D1FA7848E015C8D18A7848E017E8D116D842610F106 +S126E9B5010E260B86FEB4018BB7018BBDF123398E015C8DF76D842E592D58BDF1748E12468DE900 +S126E9D88680A484270D8D3CB5019526068E0192BDE5F08E07D18DD16D842E332D378E01548DC613 +S126E9FB6D842E28BDE5E7BDF0647A01678E017E8DB486FFA78486018E0188F7010E7EE5F0340405 +S126EA1E4F1A01495A2AFC350439860FA78439B607CBA7848E0154BDF123B607CCA784398E1246F9 +S126EA41BDF123A6848401272DA68484402713F10802260E8EEA7234048D44350486FFB701638631 +S126EA64018E0164BDF123AA84A7847EF1BD484F4C44FFF1080226057F01638D0D86FE8E0164BD44 +S126EA87F123A484A784393404F607018EE8A7BDF121AE848D03350439BF013B8643B00802B7013C +S126EAAA0F8620B70110B70113F60701BDEFBFB70111F701128E0114BF0139BE013BA680BF013B0A +S126EACDBE0139A7842B073001BF013920EA7F01798E010F7EF0CDBDECF8B613008480262A7D0884 +S126EAF0022B1F7D0163261A7D017026158601B7015FBDE7DB7D017727057C070120037301777F1A +S126EB1301677F0184398E1246BDF123A68484402638BDECF8BDF1BDF10802261BBDE7DB7F0701E5 +S126EB364F8E0801BD000086FF8E0802BD00007F01637F01677D01712B0C86BF8E0164BDF123A49E +S126EB5984A784397D01712B198E0164BDF1238640AA84A784397D08D82607326132617A070139F3 +S126EB7CB61280848027138E018D8680BA016EB7016E8680BDE5F07EE6297A01707F0184866FB4BE +S126EB9F0190B70190B6016E846FB7016E7F016739BDECF88E1246BDF123A68484042710BDF174B5 +S126EBC286048E0164BDF123AA84A7843986FB8E0164BDF123A484A784397A019727031600B986EA +S126EBE50AB70197B607DC4CB707DC810F2E0786FFB707DD200D7F07DDB607DC812D2D037F07DCE3 +S126EC087A0198270316008D861EB701987D00002F037A0000C6058E01446D012F046A01200E6DA3 +S126EC2B842F086A84863BA70120026F025A2704300320E373016BF70179F701788E015CC6026D82 +S126EC4E842F026A8430015A2AF57D015F2D037A015F7D01532F037A01537A015B2E30863CB701EC +S126EC715BC6068E0154BDF12A6D842D1C6A842C18863CA7848E07D1BDF12A6A842C0AA6848E0126 +S126EC9454BDF12AA7845A2AD7B61300397D000026057D00002703BD00008E0188867FA40DA70D18 +S126ECB7867FA403A7037F017D6D042605BDF09520F7A60243AA0443A7027D07DE27087D07DF274E +S126ECDA037F07DE7D018A26127D018F260D7D019426088680BA1301B713017D13018EFFFF301FE1 +S126ECFD26FC398E01886D012655BDF0958C019726F47D01782B0C7301788EED21BDF0C7BDED2C16 +S126ED20392053595354454D204F4BFF7D08022B2A8E0124CC2020ED81F601442B1DBDEFBFED8170 +S126ED43863AA780F601452B0FBDEFBFED8186FFA7848E0124BDF106398E0188A602A401260ABDD2 +S126ED66F0958C019726F220112B03BDE5E7BDEDC5A4022646BDEDC320F78E0188B6016BB1016C81 +S126ED892713B7016C270F860A3406CC000234068604BD000039A601A403A701BDF0958C019726FB +S126EDACF27D018B260D7D019026087D0195260316FF508D02202D8D1C5F8E01886D042606BDF0F0 +S126EDCF955C20F6A601A40426168D066D0426F420E478018C79019179019624037C018C398EEE64 +S126EDF2135D270530025A20F8AE84A584260930038CEE5B270A20F3AE017F0178BDF0C739EE1989 +S126EE15EE31EE4901EFA002EE9B04EEAA08EF0710EF1B20EEBA40EEE680EF9401EEF602EEC90430 +S126EE38EED708EF6610EF4220EF2F40EF5380EF8680012401EE7B02EE6B04EE5B08EE5B10EF7420 +S126EE5B484920444946462050524553532041FF484920444946462050524553532042FF48492030 +S126EE7E444946462050524553532043FF484920444946462050524553532044FF4C4F57205355B1 +S126EEA15247452054414E4BFF484947482053555247452054414E4BFF4C4F5720534C5544474536 +S126EEC420504954FF4C4F5720434C45415257454C4CFF4849474820434C45415257454C4CFF484D +S126EEE749474820534C5544474520504954FF48492048492053555247452054414E4BFF4C4F5715 +S126EF0A204348454D4943414C2054414E4B2031FF4C4F57204348454D4943414C2054414E4B2036 +S126EF2D32FF4C4F5720505245535355524520464C555348FF4C4F5720505245532053455256496B +S126EF504345FF4C4F5720494E535452554D454E5420414952FF4C4F572053435255422041495260 +S126EF73FF4C4556454C20535749544348204641494CFF204D41535445522020204F4646FF20503D +S126EF964F574552204641494CFF484920505245532053485554444F574EFF204D454D4F5259203D +S126EFB9204641494CFF4FC00A2B034C20F9CB3A8B3039B61280434444445F445944594459F701CC +S126EFDC6AB61301438407B701698604B70168B50169275BB5016A26208D668E014ABDF11F6D84B0 +S126EFFF2B2126126D01260E6D02260A8EF01CBDF121AE84AD84B601684426CD39E4E4E4F4E54CFA +S126F022B601688D368E014ABDF11FBF01008E0767F607015A2A02C601BDF121A684E601BE010099 +S126F045A784E70120CA8E014A8D0DBDF11FC6FFE784E701E70220B85F535C4426FC398E1246BD3E +S126F068F1236F018635BA1301B713017C016739C6028E07D4BDF1236D842E0D8E0157BDF1236D3A +S126F08B842E03BDF1745A2AE63930053934025A8E0703BDF121A684B70144A601B70145C6198D49 +S126F0AE72A684B70147A601B7014886FFB70146B70149B70149350239108E00022004108E0001A1 +S126F0D110BF01993410CC000E3406FC019934068604BD0000CC000A3406FC019934068604BD0019 +S126F0F400CC000D3406FC019934068604BD00003510E6842B1434103406FC019934068604BD0048 +S126F117003510300120E8398D028D001A108D031CEF398C12442D088C12542E033A3A3A3A398E17 +S126F13A08D9A6843402F608D8272AA601BD000030015A26F68E08D8A6844ABD000035021F898E2F +S126F15D1246BDF123E684C44027D1E684C40126CB39350286FF397D016127278E08D9B608D82755 +S126F18009E184271B30014A26F7F108022711BDF1A1250CBD00008E08D8A6844CBD00003934168C +S126F1A38E1246BDF123E684C440270AE684C40126041CFE35961A0135968E08D9B608D82721E19D +S126F1C684270630014A26F7393404E601BD000030014A26F635048E08D8A6844ABD0000397D019E +S126F1E9712B3BB6128084802634C603F7010D5A8E1246BDF123A68484402705F1080226037A01EA +S122F20C0D5A2AE97D010D26037F0179392053455256494345204F464621FF7F010D396D +S105FFFEE0001D +S105FFF8E1DC46 +SD05E000000812 +S105E0AFF35820 +S105E0D7F393BD +S105E0EEF393A6 +S105E102F39391 +S105E10EF39385 +S105E114F3937F +S105E11CF39377 +S105E12BF39368 +S105E138F3935B +S105E13EF39355 +S105E146F3934D +S105E14FF3894E +S105E34B01B219 +S105E350F231A4 +S105E399F38902 +S105E71CF3897B +S105E742F38955 +S105E74CF3894B +S105EB3BF38958 +S105EB43F38950 +S105EC1601B83F +S105EC1B01B83A +S105ECA201B6B5 +S105ECA701B2B4 +S105F148F38945 +S105F156F38937 +S105F195F393EE +S105F19EF389EF +S105F1D4F393AF +S105F1E4F389A9 +S126F22B23201B080FFFBDF361B601B281FF270D81FE27047F01B2398EF35220038EF34C7F01B111 +S126F24EC606108E019BBDF36F8EF22BC606BDF36F8E019BBDF0C7CC0809FD01B3B701B5CC30FF4A +S126F271B701B8F701B7F701B67D01B727087D01B82EF61600B98E01A3EC84C1302C071F898630F8 +S126F294FD01A3BDF377C16326098E0800BDF3937EE000F701735A2B87C1342C838E0803C1322C2E +S126F2B70AB601B281FF27038E08673A3ABF0173E684BDEFBFFD01A8E601BDEFBFFD01ABCC202DE0 +S126F2DAFD01A5B701A7C63AF701AA8EF22D108E01ADC604BDF36F860DB701AE8E019BBDF0C7CC24 +S126F2FD0D11FD01B3B701B5CC30FFB701B8F701B7F701B67D01B727077D01B82EF62023FC01A841 +S126F320BDF377BE0173E784BDF393E789FF003001FC01ABBDF377E784E789FF00BDF39386FFB7F7 +S126F34301B17F01B27F01B639205354455020414C41524D0986FFB701B1B701B7398E019BBF01DE +S126F366B96F808C01AF2CF939A680A7A05A26F9398330305D2A041F8920073404C60A3DEBE03999 +S122F389A1842705A784BDF39D39E1842705E784BDF39D3934108E04E2301F26FC3590EF +S105E1E2F3B094 +S105ECACF45717 +S126F3A801020408102040807D0802102A009C7D01B12716BDF39DB6122E84E0260486FF20028678 +S126F3CBFEB701B2160081BDF39DBDF39DF6122E545454542716C10C2772C1082746C1042726BD54 +S126F3EEF4B24D2B608B08200BF6122F2757BDF4B24D2B51810A2C0D4C810A26014F8B30202108C6 +S126F41120087D01B626698EF410C603BDF4C7BE01B9301F8C019B2D29BF01B9202486207D01B63A +S126F4342661BE01B9B71181A780BF01B98C01AF2C11200B7F01B77F01B286FFB701B1B6122F399E +S126F4577D01B62609860DBE01B9A78420E37F01B720E97C01B5F601B5C1142CE3C61BBDF4DCF68C +S126F47A01B5BDF4DC20D2C61BBDF4DCF601B5F101B32F045AF701B5BDF4DC20BC812027CFF60146 +S126F49DB58E019BA785B711817C01B5F601B5C1142EA720A134144F8EF3A8E680E1E427074C81C5 +S126F4C0082DF586FF35948D065A270220F939B61180840227F9A680B7118139B61180840227F9C3 +S107F4E3F71181395F +S105E024F4E71B +S105E02EF4E711 +S105E1F2F5AB87 +S105E1FAF667C2 +S105ED9CF56616 +S105F0E4F566CB +S105F0F3F566BC +S105F102F566AC +S105F116F56698 +S126F4E780022703BD00003510350634101F018603A7848615A784B701BAB702015F4F398002277B +S126F50A03BD0000E663C1012624BDF62027FBC10D2604C60A2009C1042605CCFFFF203434063463 +S126F52D06CC00013406BDF56D2026C1022622BDF6D527FBC10D2604C60A2009C1042605CCFFFFE5 +S126F550200C34063406CC00023406BDF56D3506351032626E8480042703BD0000E665A663810186 +S126F57326073406BDF6542009810226253406BDF7022BE6C10A261AC60DA663810126073406BD7E +S126F596F6542009810226073406BDF7022BE6351032646E84850126058502263B3985702704B6B5 +S126F5B9114139F60200C1202D0FF601BAC47FF701BAF71140B6114139B61141847FF601FF8E01CC +S126F5DCDEA7855CF701FF7C0200C1202D037F01FF397D01DD260CF601BAC49FF701BAF711403990 +S126F5FFF601DB8E01BBA685B711417A01DD5CF701DBC1202D037F01DB3980002703BD00007D0283 +S126F6220026045F4F2022B601FE8E01DEE6864CB701FE81202D037F01FE7A0200B601BA8A80B71A +S126F64501BAB711404F5D3980022703BD0000B61140840227F93510ECE1F711418300006E84858B +S126F6680126058502263B3985702704B6118139F60247C1202D0FF60201C47FF70201F71180B6BD +S126F68B118139B61181847FF602468E0225A7855CF702467C0247C1202D037F0246397D022426E9 +S126F6AE0CF60201C49FF70201F7118039F602228E0202A685B711817A02245CF70222C1202D03CA +S126F6D17F0222397D024726045F4F2022B602458E0225E6864CB7024581202D037F02457A024794 +S124F6F4B602018A80B70201B711804F5D39B61180840227F93510ECE1F711818300006E844A +S105F4ECF7150E +S105F50CF715ED +S105F56BF7158E +S105F61EF715DA +S105F652F715A6 +S126F7152721C60025101E8930EBECE4EE62ED84EF021F142009353034044C26FB34301A021CFE46 +S104F7383993 +S9030000FC diff --git a/samples/FLYER.PPT b/samples/FLYER.PPT new file mode 100755 index 0000000..2d8741f Binary files /dev/null and b/samples/FLYER.PPT differ diff --git a/src/acia.c b/src/acia.c new file mode 100644 index 0000000..4475b04 --- /dev/null +++ b/src/acia.c @@ -0,0 +1,111 @@ +/* acia.c — minimal but usable 6850 ACIA + * + * Control/Status at base+0, Data at base+1. + * During cpu_run() the host terminal is put in raw mode so that + * typed characters appear in the ACIA RX and program output goes to stdout. + */ + +#include "acia.h" +#include "cpu.h" +#include +#include +#include +#include +#include + +static uint16_t acia_base = 0; +static uint8_t ctrl = 0; +static uint8_t status = 0x02; /* TDRE set */ +static uint8_t rxbuf = 0; +static int rx_full = 0; +static struct termios oldt; +static int term_raw = 0; + +static void set_raw(void) +{ + if (term_raw) return; + struct termios t; + tcgetattr(STDIN_FILENO, &oldt); + t = oldt; + cfmakeraw(&t); + t.c_lflag &= ~(ECHO | ICANON); + t.c_cc[VMIN] = 0; + t.c_cc[VTIME] = 0; + tcsetattr(STDIN_FILENO, TCSANOW, &t); + int fl = fcntl(STDIN_FILENO, F_GETFL, 0); + fcntl(STDIN_FILENO, F_SETFL, fl | O_NONBLOCK); + term_raw = 1; +} + +static void restore_term(void) +{ + if (!term_raw) return; + tcsetattr(STDIN_FILENO, TCSANOW, &oldt); + int fl = fcntl(STDIN_FILENO, F_GETFL, 0); + fcntl(STDIN_FILENO, F_SETFL, fl & ~O_NONBLOCK); + term_raw = 0; +} + +void acia_init(uint16_t base) +{ + acia_base = base; + ctrl = 0; + status = 0x02; /* TDRE */ + rx_full = 0; + cpu_register_device(base, acia_read, acia_write); +} + +uint8_t acia_read(uint16_t off) +{ + if (off == 0) { + /* status: TDRE always ready for now, RDRF when we have a char */ + uint8_t s = status; + if (rx_full) s |= 0x01; /* RDRF */ + /* simulate no errors */ + return s; + } else { + if (rx_full) { + rx_full = 0; + status &= ~0x01; + return rxbuf; + } + return 0; + } +} + +void acia_write(uint16_t off, uint8_t val) +{ + if (off == 0) { + ctrl = val; + /* master reset on bits 1:0 == 11 */ + if ((val & 0x03) == 0x03) { + rx_full = 0; + status = 0x02; + } + } else { + /* transmit */ + putchar(val); + fflush(stdout); + status |= 0x02; /* TDRE */ + } +} + +/* Called from the run loop / go command to feed host input into ACIA */ +void acia_poll_input(void) +{ + if (!acia_base) return; + set_raw(); + unsigned char ch; + ssize_t n = read(STDIN_FILENO, &ch, 1); + if (n == 1) { + rxbuf = ch; + rx_full = 1; + status |= 0x01; + } +} + +/* restore terminal when dropping back to monitor */ +void acia_end_run(void) +{ + restore_term(); +} diff --git a/src/acia.h b/src/acia.h new file mode 100644 index 0000000..20b91b8 --- /dev/null +++ b/src/acia.h @@ -0,0 +1,19 @@ +/* acia.h — 6850 ACIA emulation */ + +#ifndef MIMIC09_ACIA_H +#define MIMIC09_ACIA_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void acia_init(uint16_t base); +uint8_t acia_read(uint16_t off); +void acia_write(uint16_t off, uint8_t val); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/cpu.c b/src/cpu.c new file mode 100644 index 0000000..0699843 --- /dev/null +++ b/src/cpu.c @@ -0,0 +1,1274 @@ +/* cpu.c — mimic09 6809/6309 core interpreter + * + * Designed for speed on macOS/Linux. + * Single-instruction semantics first, then speed tuning. + */ + +#include "cpu.h" +#include +#include +#include + +/* One global CPU + 64KB flat memory */ +cpu_t cpu; +uint8_t memory[65536]; + +/* Breakpoint maps (simple, fast enough for 64K) */ +static uint8_t bp_exec[65536]; +static uint8_t bp_watch[65536]; /* bit 0=read, 1=write */ + +/* Device hooks — filled in by acia.c / pia.c at init */ +static uint8_t (*dev_read[4])(uint16_t off) = {0}; +static void (*dev_write[4])(uint16_t off, uint8_t v) = {0}; +static uint16_t dev_base[4] = {0}; +static int dev_count = 0; + +void cpu_register_device(uint16_t base, uint8_t (*r)(uint16_t), void (*w)(uint16_t,uint8_t)) +{ + if (dev_count < 4) { + dev_base[dev_count] = base; + dev_read[dev_count] = r; + dev_write[dev_count] = w; + dev_count++; + } +} + +/* --- memory accessors ---------------------------------------------------- */ + +uint8_t cpu_read8(uint16_t addr) +{ + /* watchpoint check (cheap) */ + if (bp_watch[addr] & BP_READ) { + /* monitor will see this via a global or callback; for now just note */ + cpu.stop_requested = true; + } + /* device check — small number, fast linear scan is fine */ + for (int i = 0; i < dev_count; i++) { + uint16_t b = dev_base[i]; + if (addr >= b && addr < (uint16_t)(b + 4)) { /* ACIA=2, PIA=4 typical */ + if (dev_read[i]) return dev_read[i](addr - b); + return 0xFF; + } + } + return memory[addr]; +} + +void cpu_write8(uint16_t addr, uint8_t val) +{ + if (bp_watch[addr] & BP_WRITE) { + cpu.stop_requested = true; + } + for (int i = 0; i < dev_count; i++) { + uint16_t b = dev_base[i]; + if (addr >= b && addr < (uint16_t)(b + 4)) { + if (dev_write[i]) { dev_write[i](addr - b, val); return; } + } + } + memory[addr] = val; +} + +uint16_t cpu_read16(uint16_t addr) +{ + /* 16-bit read may straddle a device; be correct even if slow */ + uint8_t hi = cpu_read8(addr); + uint8_t lo = cpu_read8((uint16_t)(addr + 1)); + return (uint16_t)((hi << 8) | lo); +} + +void cpu_write16(uint16_t addr, uint16_t val) +{ + cpu_write8(addr, val >> 8); + cpu_write8((uint16_t)(addr + 1), val & 0xFF); +} + +/* --- breakpoints --------------------------------------------------------- */ + +void bp_set_exec(uint16_t addr) { bp_exec[addr] = 1; } +void bp_clear_exec(uint16_t addr) { bp_exec[addr] = 0; } +void bp_clear_all(void) +{ + memset(bp_exec, 0, sizeof(bp_exec)); + memset(bp_watch, 0, sizeof(bp_watch)); +} +bool bp_check_exec(uint16_t addr) { return bp_exec[addr] != 0; } + +void bp_set_watch(uint16_t addr, int flags) { bp_watch[addr] |= (uint8_t)flags; } +void bp_clear_watch(uint16_t addr) { bp_watch[addr] = 0; } + +/* --- interrupts (stubs for v1 — NMI/IRQ/FIRQ) --------------------------- */ + +void cpu_assert_irq(void) { /* TODO: set pending, check CC.I on entry */ } +void cpu_assert_firq(void) { /* TODO */ } +void cpu_assert_nmi(void) { /* TODO */ } + +/* --- helpers ------------------------------------------------------------- */ + +static inline void push8(uint16_t *sp, uint8_t v) { + *sp = (*sp - 1) & 0xFFFF; + cpu_write8(*sp, v); +} +static inline uint8_t pull8(uint16_t *sp) { + uint8_t v = cpu_read8(*sp); + *sp = (*sp + 1) & 0xFFFF; + return v; +} +static inline void push16(uint16_t *sp, uint16_t v) { + push8(sp, v & 0xFF); + push8(sp, v >> 8); +} +static inline uint16_t pull16(uint16_t *sp) { + uint16_t hi = pull8(sp); + uint16_t lo = pull8(sp); + return (hi << 8) | lo; +} + +/* Effective address calculation for indexed mode. + * Postbyte format documented in 6809 datasheet. + * Returns the EA; may auto-increment the register and consume extra bytes. + */ +static uint16_t ea_indexed(void) +{ + uint8_t post = cpu_read8(cpu.pc++); + uint16_t ea = 0; + int reg = (post >> 5) & 3; /* 00=X, 01=Y, 10=U, 11=S */ + uint16_t *rptr[4] = { &cpu.x, &cpu.y, &cpu.u, &cpu.s }; + uint16_t *r = rptr[reg]; + + if (post & 0x80) { + /* indirect or special */ + int indir = (post & 0x10) != 0; + switch (post & 0x0F) { + case 0x00: /* ,R+ */ + ea = *r; *r = (*r + 1) & 0xFFFF; + break; + case 0x01: /* ,R++ */ + ea = *r; *r = (*r + 2) & 0xFFFF; + break; + case 0x02: /* ,-R */ + *r = (*r - 1) & 0xFFFF; ea = *r; + break; + case 0x03: /* ,--R */ + *r = (*r - 2) & 0xFFFF; ea = *r; + break; + case 0x04: /* ,R */ + ea = *r; + break; + case 0x05: /* B,R */ + ea = (*r + (int8_t)cpu.d.ab.b) & 0xFFFF; + break; + case 0x06: /* A,R */ + ea = (*r + (int8_t)cpu.d.ab.a) & 0xFFFF; + break; + case 0x07: /* E,R (6309) or illegal on 6809 */ + if (cpu.model == CPU_6309) ea = (*r + (int8_t)cpu.e) & 0xFFFF; + else ea = *r; /* treat as ,R on 6809 for tolerance */ + break; + case 0x08: /* n,R (8-bit signed) */ + ea = (*r + (int8_t)cpu_read8(cpu.pc++)) & 0xFFFF; + break; + case 0x09: /* n,R (16-bit) */ + ea = (*r + (int16_t)cpu_read16(cpu.pc)) & 0xFFFF; + cpu.pc += 2; + break; + case 0x0A: /* F,R (6309) */ + if (cpu.model == CPU_6309) ea = (*r + (int8_t)cpu.f) & 0xFFFF; + else ea = *r; + break; + case 0x0B: /* D,R */ + ea = (*r + cpu.d.d) & 0xFFFF; + break; + case 0x0C: /* n,PCR (8-bit relative to PC after postbyte) */ + ea = (cpu.pc + (int8_t)cpu_read8(cpu.pc++)) & 0xFFFF; + break; + case 0x0D: /* n,PCR (16-bit) */ + ea = (cpu.pc + (int16_t)cpu_read16(cpu.pc)) & 0xFFFF; + cpu.pc += 2; + break; + case 0x0E: /* W,R (6309) or ? */ + if (cpu.model == CPU_6309) { + uint16_t w = (uint16_t)((cpu.e << 8) | cpu.f); + ea = (*r + w) & 0xFFFF; + } else ea = *r; + break; + case 0x0F: /* [n] extended indirect (postbyte 0x9F on 6809/6309) handled below */ + if ((post & 0x1F) == 0x9F) { + ea = cpu_read16(cpu.pc); cpu.pc += 2; + indir = 1; /* force indirect */ + } else { + ea = cpu.pc; /* fallback */ + } + break; + default: + ea = *r; + break; + } + if (indir) { + ea = cpu_read16(ea); + } + } else { + /* 5-bit signed offset ,R */ + int off = post & 0x1F; + if (off & 0x10) off |= 0xFFFFFFE0; /* sign extend 5->32 */ + ea = (*r + off) & 0xFFFF; + } + return ea; +} + +/* --- condition evaluation for branches ---------------------------------- */ + +static inline bool cond(unsigned op) +{ + /* op is the low nibble of the branch opcode */ + bool n = cc_test(CC_N); + bool v = cc_test(CC_V); + bool z = cc_test(CC_Z); + bool c = cc_test(CC_C); + switch (op & 0x0F) { + case 0x0: return true; /* BRA / LBRA */ + case 0x1: return false; /* BRN / LBRN */ + case 0x2: return !(c | z); /* BHI */ + case 0x3: return (c | z); /* BLS */ + case 0x4: return !c; /* BCC / BHS */ + case 0x5: return c; /* BCS / BLO */ + case 0x6: return !z; /* BNE */ + case 0x7: return z; /* BEQ */ + case 0x8: return !v; /* BVC */ + case 0x9: return v; /* BVS */ + case 0xA: return !n; /* BPL */ + case 0xB: return n; /* BMI */ + case 0xC: return (n == v); /* BGE */ + case 0xD: return (n != v); /* BLT */ + case 0xE: return (n == v) && !z; /* BGT */ + case 0xF: return (n != v) || z; /* BLE */ + } + return false; +} + +/* --- illegal instruction ------------------------------------------------- */ + +static void illegal(uint8_t op) +{ + (void)op; + cpu.halted = true; + cpu.stop_requested = true; +} + +/* --- the big step function ---------------------------------------------- */ + +int cpu_step(void) +{ + if (cpu.halted) return 0; + + uint16_t pc0 = cpu.pc; + if (cpu.debug_mode && bp_check_exec(pc0)) { + cpu.stop_requested = true; + return 0; + } + + uint8_t op = cpu_read8(cpu.pc++); + int cycles = 1; /* base; most are higher — we approximate */ + + switch (op) { + + /* ---------------- $00-$0F direct / inherent mostly ------------------ */ + case 0x00: { /* NEG direct */ + uint8_t ad = cpu_read8(cpu.pc++); + uint16_t ea = ad; + uint8_t m = cpu_read8(ea); + cpu.cc &= ~(CC_C | CC_V | CC_N | CC_Z); + if (m == 0x80) cc_set(CC_V); + if (m == 0x00) cc_set(CC_C); + m = (~m + 1) & 0xFF; + cpu_write8(ea, m); + set_nz8(m); + if (m == 0) cc_set(CC_Z); + cycles = 6; + break; + } + case 0x03: { /* COM direct */ + uint8_t ad = cpu_read8(cpu.pc++); + uint16_t ea = ad; + uint8_t m = ~cpu_read8(ea); + cpu_write8(ea, m); + cc_clear(CC_V); + cc_set(CC_C); + set_nz8(m); + cycles = 6; + break; + } + case 0x04: { /* LSR direct */ + uint8_t ad = cpu_read8(cpu.pc++); + uint16_t ea = ad; + uint8_t m = cpu_read8(ea); + cc_clear(CC_N); + bool c = m & 1; if (c) cc_set(CC_C); else cc_clear(CC_C); + m >>= 1; + cpu_write8(ea, m); + set_nz8(m); + cycles = 6; + break; + } + case 0x06: { /* ROR direct */ + uint8_t ad = cpu_read8(cpu.pc++); + uint16_t ea = ad; + uint8_t m = cpu_read8(ea); + bool oldc = cc_test(CC_C); + bool newc = m & 1; if (newc) cc_set(CC_C); else cc_clear(CC_C); + m = (m >> 1) | (oldc ? 0x80 : 0); + cpu_write8(ea, m); + set_nz8(m); + cycles = 6; + break; + } + case 0x07: { /* ASR direct */ + uint8_t ad = cpu_read8(cpu.pc++); + uint16_t ea = ad; + uint8_t m = cpu_read8(ea); + bool c = m & 1; if (c) cc_set(CC_C); else cc_clear(CC_C); + m = (uint8_t)((int8_t)m >> 1); + cpu_write8(ea, m); + set_nz8(m); + cycles = 6; + break; + } + case 0x08: { /* ASL / LSL direct */ + uint8_t ad = cpu_read8(cpu.pc++); + uint16_t ea = ad; + uint8_t m = cpu_read8(ea); + bool c = (m & 0x80) != 0; if (c) cc_set(CC_C); else cc_clear(CC_C); + bool v = ((m & 0xC0) == 0xC0) || ((m & 0xC0) == 0x00); + if (v) cc_set(CC_V); else cc_clear(CC_V); /* V = b7 xor b6 before shift */ + m <<= 1; + cpu_write8(ea, m); + set_nz8(m); + cycles = 6; + break; + } + case 0x09: { /* ROL direct */ + uint8_t ad = cpu_read8(cpu.pc++); + uint16_t ea = ad; + uint8_t m = cpu_read8(ea); + bool oldc = cc_test(CC_C); + bool c = (m & 0x80) != 0; if (c) cc_set(CC_C); else cc_clear(CC_C); + bool v = ((m & 0xC0) == 0xC0) || ((m & 0xC0) == 0x00); + if (v) cc_set(CC_V); else cc_clear(CC_V); + m = (m << 1) | (oldc ? 1 : 0); + cpu_write8(ea, m); + set_nz8(m); + cycles = 6; + break; + } + case 0x0A: { /* DEC direct */ + uint8_t ad = cpu_read8(cpu.pc++); + uint16_t ea = ad; + uint8_t m = cpu_read8(ea); + bool v = (m == 0x80); if (v) cc_set(CC_V); else cc_clear(CC_V); + m = (m - 1) & 0xFF; + cpu_write8(ea, m); + set_nz8(m); + cycles = 6; + break; + } + case 0x0C: { /* INC direct */ + uint8_t ad = cpu_read8(cpu.pc++); + uint16_t ea = ad; + uint8_t m = cpu_read8(ea); + bool v = (m == 0x7F); if (v) cc_set(CC_V); else cc_clear(CC_V); + m = (m + 1) & 0xFF; + cpu_write8(ea, m); + set_nz8(m); + cycles = 6; + break; + } + case 0x0D: { /* TST direct */ + uint8_t ad = cpu_read8(cpu.pc++); + uint8_t m = cpu_read8(ad); + cc_clear(CC_V); + set_nz8(m); + cycles = 6; + break; + } + case 0x0E: { /* JMP direct */ + uint8_t ad = cpu_read8(cpu.pc++); + cpu.pc = ad; + cycles = 3; + break; + } + case 0x0F: { /* CLR direct */ + uint8_t ad = cpu_read8(cpu.pc++); + cpu_write8(ad, 0); + cc_clear(CC_N | CC_V | CC_C); + cc_set(CC_Z); + cycles = 6; + break; + } + + /* ---------------- inherent / immediate ------------------------------ */ + case 0x12: /* NOP */ cycles = 2; break; + case 0x13: /* SYNC */ cpu.halted = true; cycles = 2; break; /* simplistic */ + case 0x16: { /* LBRA */ + int16_t off = (int16_t)cpu_read16(cpu.pc); cpu.pc += 2; + cpu.pc = (cpu.pc + off) & 0xFFFF; + cycles = 5; + break; + } + case 0x17: { /* LBSR */ + int16_t off = (int16_t)cpu_read16(cpu.pc); cpu.pc += 2; + uint16_t ret = cpu.pc; + push16(&cpu.s, ret); + cpu.pc = (cpu.pc + off) & 0xFFFF; + cycles = 9; + break; + } + case 0x19: { /* DAA */ + uint8_t a = cpu.d.ab.a; + uint8_t correction = 0; + bool c = cc_test(CC_C); + if ((a & 0x0F) > 9 || cc_test(CC_H)) correction |= 0x06; + if (a > 0x99 || c) { correction |= 0x60; cc_set(CC_C); } + a = (a + correction) & 0xFF; + cpu.d.ab.a = a; + set_nz8(a); + cycles = 2; + break; + } + case 0x1A: { /* ORCC #imm */ + uint8_t m = cpu_read8(cpu.pc++); + cpu.cc |= m; + cycles = 3; + break; + } + case 0x1C: { /* ANDCC #imm */ + uint8_t m = cpu_read8(cpu.pc++); + cpu.cc &= m; + cycles = 3; + break; + } + case 0x1D: { /* SEX */ + cpu.d.ab.a = (cpu.d.ab.b & 0x80) ? 0xFF : 0x00; + set_nz16(cpu.d.d); + cycles = 2; + break; + } + case 0x1E: { /* EXG post */ + uint8_t p = cpu_read8(cpu.pc++); + int r1 = (p >> 4) & 0xF; + int r2 = p & 0xF; + /* simplified: only common pairs */ + uint16_t t16; + uint8_t t8; + /* 8<->8 or 16<->16 only for now (full list is larger) */ + if ((r1 <= 5 && r2 <= 5) || (r1 >=8 && r2 >=8)) { + /* treat as 16-bit pairs for X/Y/U/S/D/PC etc. */ + uint16_t *map16[16] = { &cpu.d.d, &cpu.x, &cpu.y, &cpu.u, &cpu.s, &cpu.pc, 0,0, 0,0,0,0,0,0,0,0 }; + if (map16[r1] && map16[r2]) { + t16 = *map16[r1]; *map16[r1] = *map16[r2]; *map16[r2] = t16; + } + } else { + /* 8-bit A/B/CC/DP etc. — minimal */ + uint8_t *map8[16] = { &cpu.d.ab.a, &cpu.d.ab.b, &cpu.cc, 0,0,0,0,0, 0,0,0,0,0,0,0,0 }; + if (map8[r1] && map8[r2]) { + t8 = *map8[r1]; *map8[r1] = *map8[r2]; *map8[r2] = t8; + } + } + cycles = 8; + break; + } + case 0x1F: { /* TFR post */ + uint8_t p = cpu_read8(cpu.pc++); + int src = (p >> 4) & 0xF; + int dst = p & 0xF; + uint16_t *m16[6] = { &cpu.d.d, &cpu.x, &cpu.y, &cpu.u, &cpu.s, &cpu.pc }; + uint8_t *m8[3] = { &cpu.d.ab.a, &cpu.d.ab.b, &cpu.cc }; + if (src < 6 && dst < 6 && m16[src] && m16[dst]) *m16[dst] = *m16[src]; + else if (src < 3 && dst < 3 && m8[src] && m8[dst]) *m8[dst] = *m8[src]; + else if (src < 6 && dst < 3 && m16[src] && m8[dst]) *m8[dst] = (uint8_t)*m16[src]; + else if (src < 3 && dst < 6 && m8[src] && m16[dst]) *m16[dst] = *m8[src]; + cycles = 6; + break; + } + + /* short branches */ + case 0x20: case 0x21: case 0x22: case 0x23: + case 0x24: case 0x25: case 0x26: case 0x27: + case 0x28: case 0x29: case 0x2A: case 0x2B: + case 0x2C: case 0x2D: case 0x2E: case 0x2F: { + int8_t off = (int8_t)cpu_read8(cpu.pc++); + if (cond(op)) cpu.pc = (cpu.pc + off) & 0xFFFF; + cycles = 3; + break; + } + + /* ---------------- stack / rts / jsr etc ----------------------------- */ + case 0x34: { /* PSHS post */ + uint8_t post = cpu_read8(cpu.pc++); + if (post & 0x80) push16(&cpu.s, cpu.pc); + if (post & 0x40) push16(&cpu.s, cpu.u); + if (post & 0x20) push16(&cpu.s, cpu.y); + if (post & 0x10) push16(&cpu.s, cpu.x); + if (post & 0x08) push8(&cpu.s, cpu.d.ab.a); + if (post & 0x04) push8(&cpu.s, cpu.d.ab.b); + if (post & 0x02) push8(&cpu.s, cpu.cc); + if (post & 0x01) push8(&cpu.s, 0 /* DP not modeled */); + cycles = 5 + __builtin_popcount(post); /* rough */ + break; + } + case 0x35: { /* PULS post */ + uint8_t post = cpu_read8(cpu.pc++); + if (post & 0x01) (void)pull8(&cpu.s); + if (post & 0x02) cpu.cc = pull8(&cpu.s); + if (post & 0x04) cpu.d.ab.b = pull8(&cpu.s); + if (post & 0x08) cpu.d.ab.a = pull8(&cpu.s); + if (post & 0x10) cpu.x = pull16(&cpu.s); + if (post & 0x20) cpu.y = pull16(&cpu.s); + if (post & 0x40) cpu.u = pull16(&cpu.s); + if (post & 0x80) cpu.pc = pull16(&cpu.s); + cycles = 5 + __builtin_popcount(post); + break; + } + case 0x36: { /* PSHU */ + uint8_t post = cpu_read8(cpu.pc++); + if (post & 0x80) push16(&cpu.u, cpu.pc); + if (post & 0x40) push16(&cpu.u, cpu.s); + if (post & 0x20) push16(&cpu.u, cpu.y); + if (post & 0x10) push16(&cpu.u, cpu.x); + if (post & 0x08) push8(&cpu.u, cpu.d.ab.a); + if (post & 0x04) push8(&cpu.u, cpu.d.ab.b); + if (post & 0x02) push8(&cpu.u, cpu.cc); + cycles = 5 + __builtin_popcount(post); + break; + } + case 0x37: { /* PULU */ + uint8_t post = cpu_read8(cpu.pc++); + if (post & 0x01) (void)pull8(&cpu.u); + if (post & 0x02) cpu.cc = pull8(&cpu.u); + if (post & 0x04) cpu.d.ab.b = pull8(&cpu.u); + if (post & 0x08) cpu.d.ab.a = pull8(&cpu.u); + if (post & 0x10) cpu.x = pull16(&cpu.u); + if (post & 0x20) cpu.y = pull16(&cpu.u); + if (post & 0x40) cpu.s = pull16(&cpu.u); + if (post & 0x80) cpu.pc = pull16(&cpu.u); + cycles = 5 + __builtin_popcount(post); + break; + } + case 0x39: /* RTS */ + cpu.pc = pull16(&cpu.s); + cycles = 5; + break; + case 0x3A: /* ABX */ + cpu.x = (cpu.x + cpu.d.ab.b) & 0xFFFF; + cycles = 3; + break; + case 0x3B: /* RTI */ + cpu.cc = pull8(&cpu.s); + if (cpu.cc & CC_E) { + cpu.d.ab.b = pull8(&cpu.s); + cpu.d.ab.a = pull8(&cpu.s); + cpu.x = pull16(&cpu.s); + cpu.y = pull16(&cpu.s); + cpu.u = pull16(&cpu.s); + cpu.pc = pull16(&cpu.s); + } else { + cpu.pc = pull16(&cpu.s); + } + cycles = 6; + break; + case 0x3D: /* MUL */ + cpu.d.d = (uint16_t)cpu.d.ab.a * cpu.d.ab.b; + if (cpu.d.ab.b & 0x80) cc_set(CC_C); else cc_clear(CC_C); + if (cpu.d.d == 0) cc_set(CC_Z); else cc_clear(CC_Z); + cycles = 11; + break; + case 0x3F: /* SWI */ + cc_set(CC_E); + push16(&cpu.s, cpu.pc); + push16(&cpu.s, cpu.u); + push16(&cpu.s, cpu.y); + push16(&cpu.s, cpu.x); + push8(&cpu.s, cpu.d.ab.a); + push8(&cpu.s, cpu.d.ab.b); + push8(&cpu.s, cpu.cc); + cc_set(CC_I | CC_F); + cpu.pc = cpu_read16(0xFFFA); + cycles = 19; + break; + + /* ---------------- accumulator inherent ------------------------------ */ + case 0x40: /* NEGA */ { + uint8_t a = cpu.d.ab.a; + cc_clear(CC_C | CC_V); + if (a == 0x80) cc_set(CC_V); + if (a == 0) cc_set(CC_C); + a = (~a + 1) & 0xFF; + cpu.d.ab.a = a; + set_nz8(a); + cycles = 2; break; + } + case 0x43: /* COMA */ { + cpu.d.ab.a = ~cpu.d.ab.a; + cc_clear(CC_V); cc_set(CC_C); + set_nz8(cpu.d.ab.a); + cycles = 2; break; + } + case 0x44: /* LSRA */ { + uint8_t a = cpu.d.ab.a; + cc_clear(CC_N); + if (a & 1) cc_set(CC_C); else cc_clear(CC_C); + a >>= 1; cpu.d.ab.a = a; + set_nz8(a); + cycles = 2; break; + } + case 0x46: /* RORA */ { + uint8_t a = cpu.d.ab.a; + bool oldc = cc_test(CC_C); + if (a & 1) cc_set(CC_C); else cc_clear(CC_C); + a = (a >> 1) | (oldc ? 0x80 : 0); + cpu.d.ab.a = a; + set_nz8(a); + cycles = 2; break; + } + case 0x47: /* ASRA */ { + uint8_t a = cpu.d.ab.a; + if (a & 1) cc_set(CC_C); else cc_clear(CC_C); + a = (uint8_t)((int8_t)a >> 1); + cpu.d.ab.a = a; + set_nz8(a); + cycles = 2; break; + } + case 0x48: /* ASLA */ { + uint8_t a = cpu.d.ab.a; + if (a & 0x80) cc_set(CC_C); else cc_clear(CC_C); + bool v = ((a & 0xC0) == 0xC0) || ((a & 0xC0) == 0x00); + if (v) cc_set(CC_V); else cc_clear(CC_V); + a <<= 1; cpu.d.ab.a = a; + set_nz8(a); + cycles = 2; break; + } + case 0x49: /* ROLA */ { + uint8_t a = cpu.d.ab.a; + bool oldc = cc_test(CC_C); + if (a & 0x80) cc_set(CC_C); else cc_clear(CC_C); + bool v = ((a & 0xC0) == 0xC0) || ((a & 0xC0) == 0x00); + if (v) cc_set(CC_V); else cc_clear(CC_V); + a = (a << 1) | (oldc ? 1 : 0); + cpu.d.ab.a = a; + set_nz8(a); + cycles = 2; break; + } + case 0x4A: /* DECA */ { + uint8_t a = cpu.d.ab.a; + if (a == 0x80) cc_set(CC_V); else cc_clear(CC_V); + a = (a - 1) & 0xFF; cpu.d.ab.a = a; + set_nz8(a); + cycles = 2; break; + } + case 0x4C: /* INCA */ { + uint8_t a = cpu.d.ab.a; + if (a == 0x7F) cc_set(CC_V); else cc_clear(CC_V); + a = (a + 1) & 0xFF; cpu.d.ab.a = a; + set_nz8(a); + cycles = 2; break; + } + case 0x4D: /* TSTA */ cc_clear(CC_V); set_nz8(cpu.d.ab.a); cycles = 2; break; + case 0x4F: /* CLRA */ cpu.d.ab.a = 0; cc_clear(CC_N|CC_V|CC_C); cc_set(CC_Z); cycles = 2; break; + + /* B accumulator */ + case 0x50: /* NEGB */ { + uint8_t b = cpu.d.ab.b; + cc_clear(CC_C | CC_V); + if (b == 0x80) cc_set(CC_V); + if (b == 0) cc_set(CC_C); + b = (~b + 1) & 0xFF; cpu.d.ab.b = b; + set_nz8(b); + cycles = 2; break; + } + case 0x53: /* COMB */ { + cpu.d.ab.b = ~cpu.d.ab.b; + cc_clear(CC_V); cc_set(CC_C); + set_nz8(cpu.d.ab.b); + cycles = 2; break; + } + case 0x54: /* LSRB */ { + uint8_t b = cpu.d.ab.b; + cc_clear(CC_N); + if (b & 1) cc_set(CC_C); else cc_clear(CC_C); + b >>= 1; cpu.d.ab.b = b; + set_nz8(b); + cycles = 2; break; + } + case 0x56: /* RORB */ { + uint8_t b = cpu.d.ab.b; + bool oldc = cc_test(CC_C); + if (b & 1) cc_set(CC_C); else cc_clear(CC_C); + b = (b >> 1) | (oldc ? 0x80 : 0); + cpu.d.ab.b = b; + set_nz8(b); + cycles = 2; break; + } + case 0x57: /* ASRB */ { + uint8_t b = cpu.d.ab.b; + if (b & 1) cc_set(CC_C); else cc_clear(CC_C); + b = (uint8_t)((int8_t)b >> 1); + cpu.d.ab.b = b; + set_nz8(b); + cycles = 2; break; + } + case 0x58: /* ASLB */ { + uint8_t b = cpu.d.ab.b; + if (b & 0x80) cc_set(CC_C); else cc_clear(CC_C); + bool v = ((b & 0xC0) == 0xC0) || ((b & 0xC0) == 0x00); + if (v) cc_set(CC_V); else cc_clear(CC_V); + b <<= 1; cpu.d.ab.b = b; + set_nz8(b); + cycles = 2; break; + } + case 0x59: /* ROLB */ { + uint8_t b = cpu.d.ab.b; + bool oldc = cc_test(CC_C); + if (b & 0x80) cc_set(CC_C); else cc_clear(CC_C); + bool v = ((b & 0xC0) == 0xC0) || ((b & 0xC0) == 0x00); + if (v) cc_set(CC_V); else cc_clear(CC_V); + b = (b << 1) | (oldc ? 1 : 0); + cpu.d.ab.b = b; + set_nz8(b); + cycles = 2; break; + } + case 0x5A: /* DECB */ { + uint8_t b = cpu.d.ab.b; + if (b == 0x80) cc_set(CC_V); else cc_clear(CC_V); + b = (b - 1) & 0xFF; cpu.d.ab.b = b; + set_nz8(b); + cycles = 2; break; + } + case 0x5C: /* INCB */ { + uint8_t b = cpu.d.ab.b; + if (b == 0x7F) cc_set(CC_V); else cc_clear(CC_V); + b = (b + 1) & 0xFF; cpu.d.ab.b = b; + set_nz8(b); + cycles = 2; break; + } + case 0x5D: /* TSTB */ cc_clear(CC_V); set_nz8(cpu.d.ab.b); cycles = 2; break; + case 0x5F: /* CLRB */ cpu.d.ab.b = 0; cc_clear(CC_N|CC_V|CC_C); cc_set(CC_Z); cycles = 2; break; + + /* ---------------- indexed (0x6x,0xAx,0xEx) -------------------------- */ + case 0x60: case 0x63: case 0x64: case 0x66: case 0x67: + case 0x68: case 0x69: case 0x6A: case 0x6C: case 0x6D: case 0x6E: case 0x6F: { + uint16_t ea = ea_indexed(); + uint8_t m = cpu_read8(ea); + switch (op) { + case 0x60: { /* NEG indexed */ + cc_clear(CC_C|CC_V); if (m==0x80)cc_set(CC_V); if (m==0)cc_set(CC_C); + m = (~m + 1)&0xFF; cpu_write8(ea, m); set_nz8(m); cycles=6; break; + } + case 0x63: { /* COM indexed */ + m = ~m; cpu_write8(ea,m); cc_clear(CC_V); cc_set(CC_C); set_nz8(m); cycles=6; break; + } + case 0x64: { /* LSR indexed */ + cc_clear(CC_N); if (m&1)cc_set(CC_C); m>>=1; cpu_write8(ea,m); set_nz8(m); cycles=6; break; + } + case 0x66: { /* ROR indexed */ + bool oldc=cc_test(CC_C); if (m&1)cc_set(CC_C);else cc_clear(CC_C); + m=(m>>1)|(oldc?0x80:0); cpu_write8(ea,m); set_nz8(m); cycles=6; break; + } + case 0x67: { /* ASR indexed */ + if (m&1)cc_set(CC_C);else cc_clear(CC_C); m=(uint8_t)((int8_t)m>>1); + cpu_write8(ea,m); set_nz8(m); cycles=6; break; + } + case 0x68: { /* ASL indexed */ + if (m&0x80)cc_set(CC_C);else cc_clear(CC_C); + bool v=((m&0xC0)==0xC0)||((m&0xC0)==0x00); if(v)cc_set(CC_V);else cc_clear(CC_V); + m<<=1; cpu_write8(ea,m); set_nz8(m); cycles=6; break; + } + case 0x69: { /* ROL indexed */ + bool oldc=cc_test(CC_C); if (m&0x80)cc_set(CC_C);else cc_clear(CC_C); + bool v=((m&0xC0)==0xC0)||((m&0xC0)==0x00); if(v)cc_set(CC_V);else cc_clear(CC_V); + m=(m<<1)|(oldc?1:0); cpu_write8(ea,m); set_nz8(m); cycles=6; break; + } + case 0x6A: { /* DEC indexed */ + if (m==0x80)cc_set(CC_V);else cc_clear(CC_V); m=(m-1)&0xFF; cpu_write8(ea,m); set_nz8(m); cycles=6; break; + } + case 0x6C: { /* INC indexed */ + if (m==0x7F)cc_set(CC_V);else cc_clear(CC_V); m=(m+1)&0xFF; cpu_write8(ea,m); set_nz8(m); cycles=6; break; + } + case 0x6D: /* TST indexed */ cc_clear(CC_V); set_nz8(m); cycles=6; break; + case 0x6E: /* JMP indexed */ cpu.pc = ea; cycles=3; break; + case 0x6F: /* CLR indexed */ cpu_write8(ea,0); cc_clear(CC_N|CC_V|CC_C); cc_set(CC_Z); cycles=6; break; + } + break; + } + + /* ---------------- extended (0x7x, 0xBx, 0xFx) ----------------------- */ + case 0x70: case 0x73: case 0x74: case 0x76: case 0x77: case 0x78: + case 0x79: case 0x7A: case 0x7C: case 0x7D: case 0x7E: case 0x7F: { + uint16_t ea = cpu_read16(cpu.pc); cpu.pc += 2; + uint8_t m = cpu_read8(ea); + switch (op) { + case 0x70: { /* NEG extended */ + cc_clear(CC_C|CC_V); if (m==0x80)cc_set(CC_V); if (m==0)cc_set(CC_C); + m=(~m+1)&0xFF; cpu_write8(ea,m); set_nz8(m); cycles=7; break; + } + case 0x73: { /* COM ext */ + m=~m; cpu_write8(ea,m); cc_clear(CC_V); cc_set(CC_C); set_nz8(m); cycles=7; break; + } + case 0x74: { /* LSR ext */ + cc_clear(CC_N); if (m&1)cc_set(CC_C); m>>=1; cpu_write8(ea,m); set_nz8(m); cycles=7; break; + } + case 0x76: { /* ROR ext */ bool oldc=cc_test(CC_C); if (m&1)cc_set(CC_C);else cc_clear(CC_C); + m=(m>>1)|(oldc?0x80:0); cpu_write8(ea,m); set_nz8(m); cycles=7; break; + } + case 0x77: { /* ASR ext */ if (m&1)cc_set(CC_C);else cc_clear(CC_C); m=(uint8_t)((int8_t)m>>1); + cpu_write8(ea,m); set_nz8(m); cycles=7; break; + } + case 0x78: { /* ASL ext */ if (m&0x80)cc_set(CC_C);else cc_clear(CC_C); + bool v=((m&0xC0)==0xC0)||((m&0xC0)==0x00); if(v)cc_set(CC_V);else cc_clear(CC_V); + m<<=1; cpu_write8(ea,m); set_nz8(m); cycles=7; break; + } + case 0x79: { /* ROL ext */ bool oldc=cc_test(CC_C); if (m&0x80)cc_set(CC_C);else cc_clear(CC_C); + bool v=((m&0xC0)==0xC0)||((m&0xC0)==0x00); if(v)cc_set(CC_V);else cc_clear(CC_V); + m=(m<<1)|(oldc?1:0); cpu_write8(ea,m); set_nz8(m); cycles=7; break; + } + case 0x7A: { /* DEC ext */ if (m==0x80)cc_set(CC_V);else cc_clear(CC_V); m=(m-1)&0xFF; cpu_write8(ea,m); set_nz8(m); cycles=7; break; + } + case 0x7C: { /* INC ext */ if (m==0x7F)cc_set(CC_V);else cc_clear(CC_V); m=(m+1)&0xFF; cpu_write8(ea,m); set_nz8(m); cycles=7; break; + } + case 0x7D: /* TST ext */ cc_clear(CC_V); set_nz8(m); cycles=7; break; + case 0x7E: /* JMP ext */ cpu.pc = ea; cycles=4; break; + case 0x7F: /* CLR ext */ cpu_write8(ea,0); cc_clear(CC_N|CC_V|CC_C); cc_set(CC_Z); cycles=7; break; + } + break; + } + + /* ---------------- $8x immediate 8-bit ops --------------------------- */ + case 0x80: { /* SUBA # */ + uint8_t m = cpu_read8(cpu.pc++); uint8_t a = cpu.d.ab.a; + uint16_t r = a - m; cpu.d.ab.a = r & 0xFF; + cc_clear(CC_C|CC_V|CC_N|CC_Z); + if (r & 0x100) cc_set(CC_C); + if (((a ^ m ^ r) & 0x80) && ((a ^ r) & 0x80)) cc_set(CC_V); + set_nz8(cpu.d.ab.a); + cycles=2; break; + } + case 0x81: { /* CMPA # */ + uint8_t m = cpu_read8(cpu.pc++); uint8_t a = cpu.d.ab.a; + uint16_t r = a - m; + cc_clear(CC_C|CC_V|CC_N|CC_Z); + if (r & 0x100) cc_set(CC_C); + if (((a ^ m ^ r) & 0x80) && ((a ^ r) & 0x80)) cc_set(CC_V); + set_nz8(r & 0xFF); + cycles=2; break; + } + case 0x82: { /* SBCA # */ + uint8_t m = cpu_read8(cpu.pc++); uint8_t a = cpu.d.ab.a; + uint16_t r = a - m - (cc_test(CC_C)?1:0); + cpu.d.ab.a = r & 0xFF; + cc_clear(CC_C|CC_V|CC_N|CC_Z); + if (r & 0x100) cc_set(CC_C); + if (((a ^ m ^ r) & 0x80) && ((a ^ r) & 0x80)) cc_set(CC_V); + set_nz8(cpu.d.ab.a); + cycles=2; break; + } + case 0x83: { /* SUBD # */ + uint16_t m = cpu_read16(cpu.pc); cpu.pc += 2; + uint32_t r = cpu.d.d - m; + cpu.d.d = r & 0xFFFF; + cc_clear(CC_C|CC_V|CC_N|CC_Z); + if (r & 0x10000) cc_set(CC_C); + if (((cpu.d.d ^ m ^ (r&0xFFFF)) & 0x8000) && ((cpu.d.d ^ (r&0xFFFF)) & 0x8000)) cc_set(CC_V); + set_nz16(cpu.d.d); + cycles=4; break; + } + case 0x84: { /* ANDA # */ + cpu.d.ab.a &= cpu_read8(cpu.pc++); + cc_clear(CC_V); set_nz8(cpu.d.ab.a); cycles=2; break; + } + case 0x85: { /* BITA # */ + uint8_t t = cpu.d.ab.a & cpu_read8(cpu.pc++); + cc_clear(CC_V); set_nz8(t); cycles=2; break; + } + case 0x86: /* LDA # */ + cpu.d.ab.a = cpu_read8(cpu.pc++); cc_clear(CC_V); set_nz8(cpu.d.ab.a); cycles=2; break; + case 0x88: { /* EORA # */ + cpu.d.ab.a ^= cpu_read8(cpu.pc++); cc_clear(CC_V); set_nz8(cpu.d.ab.a); cycles=2; break; + } + case 0x89: { /* ADCA # */ + uint8_t m = cpu_read8(cpu.pc++); uint8_t a = cpu.d.ab.a; uint8_t c = cc_test(CC_C)?1:0; + uint16_t r = a + m + c; + cpu.d.ab.a = r & 0xFF; + cc_clear(CC_C|CC_H|CC_V|CC_N|CC_Z); + if (r & 0x100) cc_set(CC_C); + if ((a ^ m ^ r) & 0x10) cc_set(CC_H); + if (((a ^ m ^ r) & 0x80) && ~((a ^ r) & 0x80)) cc_set(CC_V); /* approx */ + set_nz8(cpu.d.ab.a); + cycles=2; break; + } + case 0x8A: { /* ORA # */ + cpu.d.ab.a |= cpu_read8(cpu.pc++); cc_clear(CC_V); set_nz8(cpu.d.ab.a); cycles=2; break; + } + case 0x8B: { /* ADDA # */ + uint8_t m = cpu_read8(cpu.pc++); uint8_t a = cpu.d.ab.a; + uint16_t r = a + m; + cpu.d.ab.a = r & 0xFF; + cc_clear(CC_C|CC_H|CC_V|CC_N|CC_Z); + if (r & 0x100) cc_set(CC_C); + if ((a ^ m ^ r) & 0x10) cc_set(CC_H); + if (((a ^ m ^ r) & 0x80) && ~((a ^ r) & 0x80)) cc_set(CC_V); + set_nz8(cpu.d.ab.a); + cycles=2; break; + } + case 0x8C: { /* CMPX # */ + uint16_t m = cpu_read16(cpu.pc); cpu.pc += 2; + uint32_t r = cpu.x - m; + cc_clear(CC_C|CC_V|CC_N|CC_Z); + if (r & 0x10000) cc_set(CC_C); + if (((cpu.x ^ m ^ (r&0xFFFF)) & 0x8000) && ((cpu.x ^ (r&0xFFFF)) & 0x8000)) cc_set(CC_V); + set_nz16((uint16_t)r); + cycles=4; break; + } + case 0x8D: { /* BSR */ + int8_t off = (int8_t)cpu_read8(cpu.pc++); + uint16_t ret = cpu.pc; + push16(&cpu.s, ret); + cpu.pc = (cpu.pc + off) & 0xFFFF; + cycles = 7; break; + } + case 0x8E: /* LDX # */ + cpu.x = cpu_read16(cpu.pc); cpu.pc += 2; cc_clear(CC_V); set_nz16(cpu.x); cycles=3; break; + + /* ---------------- $9x direct --------------------------------------- */ + case 0x96: { /* LDA direct */ + uint8_t ad = cpu_read8(cpu.pc++); cpu.d.ab.a = cpu_read8(ad); + cc_clear(CC_V); set_nz8(cpu.d.ab.a); cycles=4; break; + } + case 0x97: { /* STA direct */ + uint8_t ad = cpu_read8(cpu.pc++); cpu_write8(ad, cpu.d.ab.a); + cc_clear(CC_V); set_nz8(cpu.d.ab.a); cycles=4; break; + } + case 0x9E: { /* LDX direct */ + uint8_t ad = cpu_read8(cpu.pc++); cpu.x = cpu_read16(ad); + cc_clear(CC_V); set_nz16(cpu.x); cycles=5; break; + } + case 0x9F: { /* STX direct */ + uint8_t ad = cpu_read8(cpu.pc++); cpu_write16(ad, cpu.x); + cc_clear(CC_V); set_nz16(cpu.x); cycles=5; break; + } + case 0x9D: { /* JSR direct */ + uint8_t ad = cpu_read8(cpu.pc++); + uint16_t ret = cpu.pc; push16(&cpu.s, ret); + cpu.pc = ad; cycles = 7; break; + } + case 0xBD: { /* JSR extended */ + uint16_t ea = cpu_read16(cpu.pc); cpu.pc += 2; + uint16_t ret = cpu.pc; push16(&cpu.s, ret); + cpu.pc = ea; cycles = 8; break; + } + + /* ---------------- Ax indexed 8-bit --------------------------------- */ + case 0xA0: case 0xA1: case 0xA2: case 0xA3: case 0xA4: case 0xA5: + case 0xA6: case 0xA7: case 0xA8: case 0xA9: case 0xAA: case 0xAB: + case 0xAC: case 0xAD: case 0xAE: case 0xAF: { + uint16_t ea = ea_indexed(); + switch (op) { + case 0xA6: cpu.d.ab.a = cpu_read8(ea); cc_clear(CC_V); set_nz8(cpu.d.ab.a); cycles=4; break; + case 0xA7: cpu_write8(ea, cpu.d.ab.a); cc_clear(CC_V); set_nz8(cpu.d.ab.a); cycles=4; break; + case 0xAE: cpu.x = cpu_read16(ea); cc_clear(CC_V); set_nz16(cpu.x); cycles=5; break; + case 0xAF: cpu_write16(ea, cpu.x); cc_clear(CC_V); set_nz16(cpu.x); cycles=5; break; + case 0xAD: { uint16_t ret=cpu.pc; push16(&cpu.s, ret); cpu.pc = ea; cycles=7; break; } /* JSR indexed */ + default: + /* many ALU indexed left as exercise or fall to illegal for now */ + illegal(op); cycles=1; break; + } + break; + } + + /* ---------------- Bx extended 8-bit -------------------------------- */ + case 0xB6: { /* LDA ext */ + uint16_t ea = cpu_read16(cpu.pc); cpu.pc += 2; + cpu.d.ab.a = cpu_read8(ea); cc_clear(CC_V); set_nz8(cpu.d.ab.a); cycles=5; break; + } + case 0xB7: { /* STA ext */ + uint16_t ea = cpu_read16(cpu.pc); cpu.pc += 2; + cpu_write8(ea, cpu.d.ab.a); cc_clear(CC_V); set_nz8(cpu.d.ab.a); cycles=5; break; + } + case 0xBE: { /* LDX ext */ + uint16_t ea = cpu_read16(cpu.pc); cpu.pc += 2; + cpu.x = cpu_read16(ea); cc_clear(CC_V); set_nz16(cpu.x); cycles=6; break; + } + case 0xBF: { /* STX ext */ + uint16_t ea = cpu_read16(cpu.pc); cpu.pc += 2; + cpu_write16(ea, cpu.x); cc_clear(CC_V); set_nz16(cpu.x); cycles=6; break; + } + + /* ---------------- $Cx immediate B-side ---------------------------- */ + case 0xC0: { /* SUBB # */ + uint8_t m = cpu_read8(cpu.pc++); uint8_t b = cpu.d.ab.b; + uint16_t r = b - m; cpu.d.ab.b = r & 0xFF; + cc_clear(CC_C|CC_V|CC_N|CC_Z); + if (r & 0x100) cc_set(CC_C); + if (((b ^ m ^ r) & 0x80) && ((b ^ r) & 0x80)) cc_set(CC_V); + set_nz8(cpu.d.ab.b); + cycles=2; break; + } + case 0xC1: { /* CMPB # */ + uint8_t m = cpu_read8(cpu.pc++); uint8_t b = cpu.d.ab.b; + uint16_t r = b - m; + cc_clear(CC_C|CC_V|CC_N|CC_Z); + if (r & 0x100) cc_set(CC_C); + if (((b ^ m ^ r) & 0x80) && ((b ^ r) & 0x80)) cc_set(CC_V); + set_nz8(r & 0xFF); + cycles=2; break; + } + case 0xC4: { /* ANDB # */ cpu.d.ab.b &= cpu_read8(cpu.pc++); cc_clear(CC_V); set_nz8(cpu.d.ab.b); cycles=2; break; } + case 0xC5: { /* BITB # */ { uint8_t t = cpu.d.ab.b & cpu_read8(cpu.pc++); cc_clear(CC_V); set_nz8(t); } cycles=2; break; } + case 0xC6: /* LDB # */ cpu.d.ab.b = cpu_read8(cpu.pc++); cc_clear(CC_V); set_nz8(cpu.d.ab.b); cycles=2; break; + case 0xC8: { /* EORB # */ cpu.d.ab.b ^= cpu_read8(cpu.pc++); cc_clear(CC_V); set_nz8(cpu.d.ab.b); cycles=2; break; } + case 0xCA: { /* ORB # */ cpu.d.ab.b |= cpu_read8(cpu.pc++); cc_clear(CC_V); set_nz8(cpu.d.ab.b); cycles=2; break; } + case 0xCC: /* LDD # */ + cpu.d.ab.a = cpu_read8(cpu.pc++); cpu.d.ab.b = cpu_read8(cpu.pc++); + cc_clear(CC_V); set_nz16(cpu.d.d); cycles=3; break; + case 0xCE: /* LDU # */ + cpu.u = cpu_read16(cpu.pc); cpu.pc += 2; cc_clear(CC_V); set_nz16(cpu.u); cycles=3; break; + + /* ---------------- $Dx direct B/D/U -------------------------------- */ + case 0xD6: { /* LDB direct */ + uint8_t ad = cpu_read8(cpu.pc++); cpu.d.ab.b = cpu_read8(ad); + cc_clear(CC_V); set_nz8(cpu.d.ab.b); cycles=4; break; + } + case 0xD7: { /* STB direct */ + uint8_t ad = cpu_read8(cpu.pc++); cpu_write8(ad, cpu.d.ab.b); + cc_clear(CC_V); set_nz8(cpu.d.ab.b); cycles=4; break; + } + case 0xDC: { /* LDD direct */ + uint8_t ad = cpu_read8(cpu.pc++); cpu.d.ab.a = cpu_read8(ad); cpu.d.ab.b = cpu_read8((uint16_t)(ad+1)); + cc_clear(CC_V); set_nz16(cpu.d.d); cycles=5; break; + } + case 0xDD: { /* STD direct */ + uint8_t ad = cpu_read8(cpu.pc++); cpu_write16(ad, cpu.d.d); + cc_clear(CC_V); set_nz16(cpu.d.d); cycles=5; break; + } + case 0xDE: { /* LDU direct */ + uint8_t ad = cpu_read8(cpu.pc++); cpu.u = cpu_read16(ad); + cc_clear(CC_V); set_nz16(cpu.u); cycles=5; break; + } + case 0xDF: { /* STU direct */ + uint8_t ad = cpu_read8(cpu.pc++); cpu_write16(ad, cpu.u); + cc_clear(CC_V); set_nz16(cpu.u); cycles=5; break; + } + + /* ---------------- $Ex indexed B/D/U ------------------------------- */ + case 0xE6: { uint16_t ea=ea_indexed(); cpu.d.ab.b = cpu_read8(ea); cc_clear(CC_V); set_nz8(cpu.d.ab.b); cycles=4; break; } + case 0xE7: { uint16_t ea=ea_indexed(); cpu_write8(ea, cpu.d.ab.b); cc_clear(CC_V); set_nz8(cpu.d.ab.b); cycles=4; break; } + case 0xEC: { uint16_t ea=ea_indexed(); cpu.d.d = cpu_read16(ea); cc_clear(CC_V); set_nz16(cpu.d.d); cycles=5; break; } + case 0xED: { uint16_t ea=ea_indexed(); cpu_write16(ea, cpu.d.d); cc_clear(CC_V); set_nz16(cpu.d.d); cycles=5; break; } + case 0xEE: { uint16_t ea=ea_indexed(); cpu.u = cpu_read16(ea); cc_clear(CC_V); set_nz16(cpu.u); cycles=5; break; } + case 0xEF: { uint16_t ea=ea_indexed(); cpu_write16(ea, cpu.u); cc_clear(CC_V); set_nz16(cpu.u); cycles=5; break; } + + /* ---------------- $Fx extended B/D/U ------------------------------ */ + case 0xF6: { uint16_t ea=cpu_read16(cpu.pc); cpu.pc+=2; cpu.d.ab.b=cpu_read8(ea); cc_clear(CC_V); set_nz8(cpu.d.ab.b); cycles=5; break; } + case 0xF7: { uint16_t ea=cpu_read16(cpu.pc); cpu.pc+=2; cpu_write8(ea, cpu.d.ab.b); cc_clear(CC_V); set_nz8(cpu.d.ab.b); cycles=5; break; } + case 0xFC: { uint16_t ea=cpu_read16(cpu.pc); cpu.pc+=2; cpu.d.d = cpu_read16(ea); cc_clear(CC_V); set_nz16(cpu.d.d); cycles=6; break; } + case 0xFD: { uint16_t ea=cpu_read16(cpu.pc); cpu.pc+=2; cpu_write16(ea, cpu.d.d); cc_clear(CC_V); set_nz16(cpu.d.d); cycles=6; break; } + case 0xFE: { uint16_t ea=cpu_read16(cpu.pc); cpu.pc+=2; cpu.u = cpu_read16(ea); cc_clear(CC_V); set_nz16(cpu.u); cycles=6; break; } + case 0xFF: { uint16_t ea=cpu_read16(cpu.pc); cpu.pc+=2; cpu_write16(ea, cpu.u); cc_clear(CC_V); set_nz16(cpu.u); cycles=6; break; } + + /* ---------------- $10 and $11 prefix pages ------------------------ */ + case 0x10: { + uint8_t op2 = cpu_read8(cpu.pc++); + switch (op2) { + case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: + case 0x26: case 0x27: case 0x28: case 0x29: case 0x2A: case 0x2B: + case 0x2C: case 0x2D: case 0x2E: case 0x2F: { + /* long conditional branches */ + int16_t off = (int16_t)cpu_read16(cpu.pc); cpu.pc += 2; + if (cond(op2)) cpu.pc = (cpu.pc + off) & 0xFFFF; + cycles = 5; /* approx */ + break; + } + case 0x83: { /* CMPD # */ + uint16_t m = cpu_read16(cpu.pc); cpu.pc += 2; + uint32_t r = cpu.d.d - m; + cc_clear(CC_C|CC_V|CC_N|CC_Z); + if (r & 0x10000) cc_set(CC_C); + if (((cpu.d.d ^ m ^ (r&0xFFFF)) & 0x8000) && ((cpu.d.d ^ (r&0xFFFF)) & 0x8000)) cc_set(CC_V); + set_nz16((uint16_t)r); + cycles = 5; break; + } + case 0x8C: { /* CMPY # */ + uint16_t m = cpu_read16(cpu.pc); cpu.pc += 2; + uint32_t r = cpu.y - m; + cc_clear(CC_C|CC_V|CC_N|CC_Z); + if (r & 0x10000) cc_set(CC_C); + if (((cpu.y ^ m ^ (r&0xFFFF)) & 0x8000) && ((cpu.y ^ (r&0xFFFF)) & 0x8000)) cc_set(CC_V); + set_nz16((uint16_t)r); + cycles=5; break; + } + case 0x8E: /* LDY # */ + cpu.y = cpu_read16(cpu.pc); cpu.pc += 2; cc_clear(CC_V); set_nz16(cpu.y); cycles=4; break; + case 0x9E: { /* LDY direct */ + uint8_t ad = cpu_read8(cpu.pc++); cpu.y = cpu_read16(ad); + cc_clear(CC_V); set_nz16(cpu.y); cycles=6; break; + } + case 0x9F: { /* STY direct */ + uint8_t ad = cpu_read8(cpu.pc++); cpu_write16(ad, cpu.y); + cc_clear(CC_V); set_nz16(cpu.y); cycles=6; break; + } + case 0xAE: { uint16_t ea = ea_indexed(); cpu.y = cpu_read16(ea); cc_clear(CC_V); set_nz16(cpu.y); cycles=6; break; } + case 0xAF: { uint16_t ea = ea_indexed(); cpu_write16(ea, cpu.y); cc_clear(CC_V); set_nz16(cpu.y); cycles=6; break; } + case 0xBE: { uint16_t ea = cpu_read16(cpu.pc); cpu.pc+=2; cpu.y = cpu_read16(ea); cc_clear(CC_V); set_nz16(cpu.y); cycles=7; break; } + case 0xBF: { uint16_t ea = cpu_read16(cpu.pc); cpu.pc+=2; cpu_write16(ea, cpu.y); cc_clear(CC_V); set_nz16(cpu.y); cycles=7; break; } + case 0xCE: /* LDS # */ + cpu.s = cpu_read16(cpu.pc); cpu.pc += 2; cc_clear(CC_V); set_nz16(cpu.s); cycles=4; break; + default: + illegal(op2); cycles=1; break; + } + break; + } + + case 0x11: { + uint8_t op2 = cpu_read8(cpu.pc++); + switch (op2) { + case 0x83: { /* CMPU # */ + uint16_t m = cpu_read16(cpu.pc); cpu.pc += 2; + uint32_t r = cpu.u - m; + cc_clear(CC_C|CC_V|CC_N|CC_Z); + if (r & 0x10000) cc_set(CC_C); + if (((cpu.u ^ m ^ (r&0xFFFF)) & 0x8000) && ((cpu.u ^ (r&0xFFFF)) & 0x8000)) cc_set(CC_V); + set_nz16((uint16_t)r); + cycles=5; break; + } + case 0x8C: { /* CMPS # */ + uint16_t m = cpu_read16(cpu.pc); cpu.pc += 2; + uint32_t r = cpu.s - m; + cc_clear(CC_C|CC_V|CC_N|CC_Z); + if (r & 0x10000) cc_set(CC_C); + if (((cpu.s ^ m ^ (r&0xFFFF)) & 0x8000) && ((cpu.s ^ (r&0xFFFF)) & 0x8000)) cc_set(CC_V); + set_nz16((uint16_t)r); + cycles=5; break; + } + default: + illegal(op2); cycles=1; break; + } + break; + } + + /* ---------------- 6309 extras (selected) --------------------------- */ + /* We implement a few useful ones so cc09 code using 6309 can advance. */ + case 0x14: /* SEXW (6309) — sign extend W to Q (very simplified) */ + if (cpu.model == CPU_6309) { + uint16_t w = (uint16_t)((cpu.e << 8) | cpu.f); + cpu.q = (w & 0x8000) ? (0xFFFF0000u | w) : w; + set_nz16(w); + cycles = 4; + } else illegal(op); + break; + + case 0xCD: /* LDQ # (6309 immediate 32-bit) */ + if (cpu.model == CPU_6309) { + cpu.q = ((uint32_t)cpu_read16(cpu.pc) << 16) | cpu_read16((uint16_t)(cpu.pc+2)); + cpu.pc += 4; + /* set flags from low 16? or whole — keep simple */ + set_nz16(cpu.q & 0xFFFF); + cycles = 5; + } else illegal(op); + break; + + default: + illegal(op); + cycles = 1; + break; + } + + cpu.total_cycles += (uint64_t)cycles; + + /* If a device or watchpoint asked for a stop, honor it */ + if (cpu.stop_requested) { + cpu.stop_requested = false; + return cycles; + } + return cycles; +} + +/* --- run loop ----------------------------------------------------------- */ + +int cpu_run(void) +{ + cpu.stop_requested = false; + int steps = 0; + while (!cpu.halted && !cpu.stop_requested) { + if (cpu.debug_mode) { + /* In debug mode we still run fast but let monitor control via step or bp */ + if (bp_check_exec(cpu.pc)) { + cpu.stop_requested = true; + break; + } + } + cpu_step(); + steps++; + /* Occasional yield / host input poll opportunity for ACIA etc. + In a real fast run we would batch many steps. */ + if ((steps & 0x3FFF) == 0) { + /* allow host to inject SIGINT or kb chars */ + /* In practice the monitor will use single steps or set a temp bp */ + } + } + return 0; +} + +/* --- init / reset ------------------------------------------------------- */ + +void cpu_init(cpu_model_t model) +{ + memset(&cpu, 0, sizeof(cpu)); + memset(memory, 0, sizeof(memory)); + memset(bp_exec, 0, sizeof(bp_exec)); + memset(bp_watch, 0, sizeof(bp_watch)); + cpu.model = model; + cpu.native6309 = (model == CPU_6309); + cpu.md = (model == CPU_6309) ? 0x03 : 0x00; /* example: native + FIRQ on 6309 */ + dev_count = 0; +} + +void cpu_reset(void) +{ + cpu.halted = false; + cpu.stop_requested = false; + cpu.cc = CC_I | CC_F; /* typical after reset */ + cpu.pc = mem_read16(0xFFFE); /* reset vector (bypass devices) */ +} + +void cpu_set_model(cpu_model_t m) +{ + cpu.model = m; + cpu.native6309 = (m == CPU_6309); +} + +void cpu_dump_regs(char *buf, size_t buflen) +{ + /* Format similar to C64 monitors + 6809 flavor */ + char flags[9]; + flags[0] = (cpu.cc & CC_E) ? 'E' : '.'; + flags[1] = (cpu.cc & CC_F) ? 'F' : '.'; + flags[2] = (cpu.cc & CC_H) ? 'H' : '.'; + flags[3] = (cpu.cc & CC_I) ? 'I' : '.'; + flags[4] = (cpu.cc & CC_N) ? 'N' : '.'; + flags[5] = (cpu.cc & CC_Z) ? 'Z' : '.'; + flags[6] = (cpu.cc & CC_V) ? 'V' : '.'; + flags[7] = (cpu.cc & CC_C) ? 'C' : '.'; + flags[8] = 0; + + uint16_t w = (cpu.model == CPU_6309) ? (uint16_t)((cpu.e << 8) | cpu.f) : 0; + + snprintf(buf, buflen, + "PC=%04X A=%02X B=%02X D=%04X X=%04X Y=%04X U=%04X S=%04X\n" + "CC=%02X [%s] %s%s E=%02X F=%02X W=%04X Q=%08X MD=%02X cycles=%llu\n", + cpu.pc, + cpu.d.ab.a, cpu.d.ab.b, cpu.d.d, + cpu.x, cpu.y, cpu.u, cpu.s, + cpu.cc, flags, + (cpu.model==CPU_6309?"6309":"6809"), + (cpu.native6309?" native":""), + cpu.e, cpu.f, w, cpu.q, cpu.md, + (unsigned long long)cpu.total_cycles); +} + +/* convenience for monitor: allow direct vector poke if needed */ +void cpu_set_pc(uint16_t pc) { cpu.pc = pc; } diff --git a/src/cpu.h b/src/cpu.h new file mode 100644 index 0000000..1407169 --- /dev/null +++ b/src/cpu.h @@ -0,0 +1,153 @@ +/* cpu.h — mimic09 6809/6309 CPU core + * + * Extremely efficient interpreter core for macOS / UNIX. + * All memory traffic from the emulated CPU goes through the accessors + * so devices (ACIA/PIA) and debug watchpoints/breakpoints always work. + */ + +#ifndef MIMIC09_CPU_H +#define MIMIC09_CPU_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Condition Code bits (6809/6309) */ +#define CC_C 0x01 +#define CC_V 0x02 +#define CC_Z 0x04 +#define CC_N 0x08 +#define CC_I 0x10 +#define CC_H 0x20 +#define CC_F 0x40 +#define CC_E 0x80 + +/* CPU model */ +typedef enum { + CPU_6809 = 0, + CPU_6309 = 1 +} cpu_model_t; + +/* Primary CPU state */ +typedef struct cpu_t { + /* 16-bit registers */ + uint16_t pc; /* Program Counter */ + uint16_t x, y, u, s; + + /* Accumulators */ + union { + uint16_t d; /* D = A:B (A high byte) */ + struct { + uint8_t b; /* low */ + uint8_t a; /* high */ + } ab; + } d; + + /* 6309 extras */ + uint8_t e, f; /* accumulators E, F */ + uint16_t v; /* V register (6309) */ + uint8_t md; /* Mode register (6309) */ + /* Q is 32-bit: conceptually A:B:E:F or D:W. We keep a shadow for speed. */ + uint32_t q; + + /* Condition codes (full byte: EFHINZVC) */ + uint8_t cc; + + /* CPU type and internal state */ + cpu_model_t model; + bool native6309; /* true when 6309 native mode (MD bit) */ + + /* Execution control */ + bool halted; + uint64_t total_cycles; /* cumulative cycle count (best effort) */ + + /* Break / debug interface (set by monitor) */ + bool debug_mode; /* when true, step does lighter work + checks */ + bool stop_requested; +} cpu_t; + +/* Global instance (for speed in hot paths; one emulator for now) */ +extern cpu_t cpu; + +/* Flat 64KB memory. Device and debug layers sit in the accessors. */ +extern uint8_t memory[65536]; + +/* Memory accessors — these are the *only* way the CPU should touch memory. + * They handle breakpoints, watchpoints, ACIA, PIA, etc. + */ +uint8_t cpu_read8(uint16_t addr); +void cpu_write8(uint16_t addr, uint8_t val); +uint16_t cpu_read16(uint16_t addr); /* big-endian (6809 order) */ +void cpu_write16(uint16_t addr, uint16_t val); + +/* Fast direct RAM access for monitor / loader / bulk ops (bypasses devices) */ +static inline uint8_t mem_read8(uint16_t a) { return memory[a]; } +static inline void mem_write8(uint16_t a, uint8_t v) { memory[a] = v; } +static inline uint16_t mem_read16(uint16_t a) { return (memory[a] << 8) | memory[(uint16_t)(a+1)]; } +static inline void mem_write16(uint16_t a, uint16_t v) { + memory[a] = v >> 8; memory[(uint16_t)(a+1)] = v & 0xFF; +} + +/* CPU lifecycle */ +void cpu_init(cpu_model_t model); +void cpu_reset(void); /* loads reset vector from FFFE:FFFF */ + +/* Single instruction step. Returns approximate cycles consumed by the instr. */ +int cpu_step(void); + +/* Run until stop condition (breakpoint, stop_requested, or halted). + * In debug mode this will honor single-step and breakpoints aggressively. + * Returns reason code (0 = normal stop, >0 for breakpoint id or other). + */ +int cpu_run(void); + +/* Breakpoint / watchpoint interface (simple for v1; monitor owns the lists) */ +void bp_set_exec(uint16_t addr); +void bp_clear_exec(uint16_t addr); +void bp_clear_all(void); +bool bp_check_exec(uint16_t addr); /* called by cpu_step before exec */ + +/* Optional memory access watch (read or write). For speed we can OR flags. */ +#define BP_READ 1 +#define BP_WRITE 2 +void bp_set_watch(uint16_t addr, int flags); +void bp_clear_watch(uint16_t addr); + +/* Interrupt requests (level sensitive until serviced) */ +void cpu_assert_irq(void); /* maskable IRQ */ +void cpu_assert_firq(void); /* fast IRQ (6309/6809) */ +void cpu_assert_nmi(void); + +/* Utility */ +void cpu_dump_regs(char *buf, size_t buflen); /* for monitor R command */ +void cpu_set_model(cpu_model_t m); + +/* Device registration (called by acia/pia init) */ +void cpu_register_device(uint16_t base, + uint8_t (*readfn)(uint16_t), + void (*writefn)(uint16_t, uint8_t)); + +/* CC helpers (inlined for speed) */ +static inline void cc_set(uint8_t mask) { cpu.cc |= mask; } +static inline void cc_clear(uint8_t mask) { cpu.cc &= ~mask; } +static inline bool cc_test(uint8_t mask) { return (cpu.cc & mask) != 0; } + +static inline void set_nz8(uint8_t v) { + cc_clear(CC_N | CC_Z); + if (v & 0x80) cc_set(CC_N); + if (v == 0) cc_set(CC_Z); +} +static inline void set_nz16(uint16_t v) { + cc_clear(CC_N | CC_Z); + if (v & 0x8000) cc_set(CC_N); + if (v == 0) cc_set(CC_Z); +} + +#ifdef __cplusplus +} +#endif +#endif /* MIMIC09_CPU_H */ diff --git a/src/debug.c b/src/debug.c new file mode 100644 index 0000000..6bdde7b --- /dev/null +++ b/src/debug.c @@ -0,0 +1,404 @@ +/* debug.c — C64-inspired monitor for mimic09 */ + +#include "debug.h" +#include "cpu.h" +#include "disasm.h" +#include "loader.h" +#include +#include +#include +#include +#include +#include + +static uint16_t next_dasm = 0; +static uint16_t next_mem = 0; +static uint16_t load_addr = 0x0000; + +void monitor_set_load_addr(uint16_t a) { load_addr = a; } +uint16_t monitor_get_load_addr(void) { return load_addr; } + +static volatile int break_flag = 0; +static void sigint_handler(int sig) { (void)sig; break_flag = 1; } + +static void to_upper(char *s) { for (; *s; ++s) *s = (char)toupper((unsigned char)*s); } + +static int parse_hex(const char *s, uint16_t *out) +{ + char *end = NULL; + unsigned long v = strtoul(s, &end, 16); + if (end == s) return 0; + *out = (uint16_t)v; + return 1; +} + +static void print_regs(void) +{ + char buf[256]; + cpu_dump_regs(buf, sizeof(buf)); + puts(buf); +} + +static void cmd_registers(const char *line) +{ + (void)line; + print_regs(); +} + +static void cmd_edit_regs(char *line) +{ + /* Expect the user to paste-ish the output of R and change values. + Very loose parser: look for PC= A= etc tokens. */ + char *p = line + 1; /* skip leading ; */ + uint16_t v; + char *tok; + while ((tok = strtok(p, " \t\n=,"))) { + p = NULL; + char *val = strtok(NULL, " \t\n=,"); + if (!val) break; + to_upper(tok); + if (parse_hex(val, &v)) { + if (strcmp(tok, "PC")==0) cpu.pc = v; + else if (strcmp(tok, "A")==0) cpu.d.ab.a = (uint8_t)v; + else if (strcmp(tok, "B")==0) cpu.d.ab.b = (uint8_t)v; + else if (strcmp(tok, "D")==0) cpu.d.d = v; + else if (strcmp(tok, "X")==0) cpu.x = v; + else if (strcmp(tok, "Y")==0) cpu.y = v; + else if (strcmp(tok, "U")==0) cpu.u = v; + else if (strcmp(tok, "S")==0) cpu.s = v; + else if (strcmp(tok, "CC")==0) cpu.cc = (uint8_t)v; + } + } + print_regs(); +} + +static void cmd_memory(char *line) +{ + uint16_t addr = next_mem; + int count = 128; + char *tok = strtok(line, " \t"); + if (tok) tok = strtok(NULL, " \t"); + if (tok) { + parse_hex(tok, &addr); + tok = strtok(NULL, " \t"); + if (tok) count = atoi(tok) * 16; + } + if (count < 16) count = 16; + if (count > 256) count = 256; + + for (int i = 0; i < count; i += 16) { + printf("%04X ", addr + i); + for (int j = 0; j < 16; j++) { + uint8_t b = mem_read8((uint16_t)(addr + i + j)); + printf("%02X ", b); + } + printf(" |"); + for (int j = 0; j < 16; j++) { + uint8_t b = mem_read8((uint16_t)(addr + i + j)); + putchar((b >= 32 && b < 127) ? b : '.'); + } + printf("|\n"); + } + next_mem = (uint16_t)(addr + count); +} + +static void cmd_poke(char *line) +{ + /* :addr b0 b1 b2 ... or just bytes after current next_mem */ + uint16_t addr = next_mem; + char *tok = strtok(line, " \t"); + if (tok && tok[0] == ':') tok = strtok(NULL, " \t"); + if (tok) { + uint16_t a; + if (parse_hex(tok, &a)) addr = a; + } + while ((tok = strtok(NULL, " \t\n"))) { + uint16_t b; + if (parse_hex(tok, &b)) { + mem_write8(addr++, (uint8_t)b); + } + } + next_mem = addr; +} + +static void cmd_disasm(char *line) +{ + uint16_t addr = next_dasm ? next_dasm : cpu.pc; + int lines = 20; + char *tok = strtok(line, " \t"); + if (tok) tok = strtok(NULL, " \t"); + if (tok) { + parse_hex(tok, &addr); + tok = strtok(NULL, " \t"); + if (tok) lines = atoi(tok); + } + if (lines < 1) lines = 1; + if (lines > 100) lines = 100; + + for (int i = 0; i < lines; i++) { + char buf[128]; + uint16_t next; + int n = disasm(addr, buf, sizeof(buf), &next); + printf("%04X %s\n", addr, buf); + addr = next; + } + next_dasm = addr; +} + +static void cmd_assemble(char *line) +{ + /* Very simple one-line assembler for common cases. + A addr LDA #$12 or A 1000 STA $12 + For full power use cc09; this is for quick patches in the monitor. + */ + uint16_t addr = cpu.pc; + char *tok = strtok(line, " \t"); + if (tok) tok = strtok(NULL, " \t"); + if (tok) parse_hex(tok, &addr); + tok = strtok(NULL, "\n"); + if (!tok) { printf("A \n"); return; } + + /* Extremely minimal: only a few immediate/direct/extended */ + char mnem[8] = {0}; unsigned arg = 0; int is_imm = 0, is_dir = 0, is_ext = 0, is_idx = 0; + if (sscanf(tok, "%7s", mnem) != 1) { printf("Bad mnemonic\n"); return; } + to_upper(mnem); + char *rest = strstr(tok, mnem); if (rest) rest += strlen(mnem); + while (rest && *rest && isspace((unsigned char)*rest)) rest++; + + if (rest && *rest == '#') { is_imm = 1; rest++; } + else if (rest && *rest == '<') { is_dir = 1; rest++; } + if (rest) { + while (rest && *rest && (*rest == '$' || *rest == ' ' || *rest == '\t')) rest++; + if (sscanf(rest, "%x", &arg) != 1) { + sscanf(rest, "%u", &arg); + } + } + if (strstr(rest ? rest : "", ",X") || strstr(rest ? rest : "", ",Y")) is_idx = 1; + + int nbytes = 0; + if (strcmp(mnem, "NOP")==0) { mem_write8(addr, 0x12); nbytes=1; } + else if (strcmp(mnem, "LDA")==0 && is_imm) { mem_write8(addr,0x86); mem_write8(addr+1,(uint8_t)arg); nbytes=2; } + else if (strcmp(mnem, "LDA")==0 && is_dir) { mem_write8(addr,0x96); mem_write8(addr+1,(uint8_t)arg); nbytes=2; } + else if (strcmp(mnem, "LDA")==0) { mem_write8(addr,0xB6); mem_write16(addr+1,(uint16_t)arg); nbytes=3; } + else if (strcmp(mnem, "STA")==0 && is_dir) { mem_write8(addr,0x97); mem_write8(addr+1,(uint8_t)arg); nbytes=2; } + else if (strcmp(mnem, "STA")==0) { mem_write8(addr,0xB7); mem_write16(addr+1,(uint16_t)arg); nbytes=3; } + else if (strcmp(mnem, "LDB")==0 && is_imm) { mem_write8(addr,0xC6); mem_write8(addr+1,(uint8_t)arg); nbytes=2; } + else if (strcmp(mnem, "LDB")==0) { mem_write8(addr,0xF6); mem_write16(addr+1,(uint16_t)arg); nbytes=3; } + else if (strcmp(mnem, "STB")==0) { mem_write8(addr,0xF7); mem_write16(addr+1,(uint16_t)arg); nbytes=3; } + else if (strcmp(mnem, "LDX")==0 && is_imm) { mem_write8(addr,0x8E); mem_write16(addr+1,(uint16_t)arg); nbytes=3; } + else if (strcmp(mnem, "LDX")==0) { mem_write8(addr,0xBE); mem_write16(addr+1,(uint16_t)arg); nbytes=3; } + else if (strcmp(mnem, "STX")==0) { mem_write8(addr,0xBF); mem_write16(addr+1,(uint16_t)arg); nbytes=3; } + else if (strcmp(mnem, "JMP")==0) { mem_write8(addr,0x7E); mem_write16(addr+1,(uint16_t)arg); nbytes=3; } + else if (strcmp(mnem, "JSR")==0) { mem_write8(addr,0xBD); mem_write16(addr+1,(uint16_t)arg); nbytes=3; } + else if (strcmp(mnem, "BRA")==0) { int off = (int)(arg - (addr+2)); mem_write8(addr,0x20); mem_write8(addr+1,(uint8_t)off); nbytes=2; } + else if (strcmp(mnem, "RTS")==0) { mem_write8(addr,0x39); nbytes=1; } + else if (strcmp(mnem, "SWI")==0) { mem_write8(addr,0x3F); nbytes=1; } + else { + printf("Assembler limited. Use cc09 for full source, or patch bytes with : or M.\n"); + return; + } + /* quick verify by disassembling it */ + char d[80]; uint16_t nxt; + disasm(addr, d, sizeof(d), &nxt); + printf("%04X %s\n", addr, d); + next_dasm = addr + (uint16_t)nbytes; +} + +static void cmd_go(char *line) +{ + uint16_t addr = cpu.pc; + char *tok = strtok(line, " \t"); + if (tok) tok = strtok(NULL, " \t"); + if (tok) parse_hex(tok, &addr); + + cpu.pc = addr; + cpu.halted = false; + cpu.debug_mode = false; /* run at full speed */ + cpu.stop_requested = false; + + printf("Running from %04X. Ctrl-C to break.\n", addr); + signal(SIGINT, sigint_handler); + break_flag = 0; + + /* Simple run loop with occasional SIGINT check */ + while (!cpu.halted && !break_flag) { + cpu_step(); + if ((cpu.total_cycles & 0x1FFF) == 0) { + /* give ACIA a chance to flush etc. */ + } + } + signal(SIGINT, SIG_DFL); + if (break_flag) printf("\n** Break at %04X **\n", cpu.pc); + print_regs(); + next_dasm = cpu.pc; + cpu.debug_mode = true; +} + +static void cmd_step(char *line) +{ + int n = 1; + char *tok = strtok(line, " \t"); + if (tok) tok = strtok(NULL, " \t"); + if (tok) n = atoi(tok); + if (n < 1) n = 1; + cpu.debug_mode = true; + for (int i = 0; i < n; i++) { + if (cpu.halted) break; + int c = cpu_step(); + char d[80]; uint16_t nxt; + disasm(cpu.pc, d, sizeof(d), &nxt); /* show NEXT instr */ + printf("%04X %s (cycles %d)\n", cpu.pc, d, c); + } + print_regs(); + next_dasm = cpu.pc; +} + +static struct { uint16_t addr; bool used; } breakpoints[32]; + +static void cmd_break(char *line) +{ + uint16_t a = 0; + char *tok = strtok(line, " \t"); + if (tok) tok = strtok(NULL, " \t"); + if (!tok) { + printf("Breakpoints:\n"); + for (int i=0; i<32; i++) if (breakpoints[i].used) + printf(" %04X\n", breakpoints[i].addr); + return; + } + parse_hex(tok, &a); + for (int i=0; i<32; i++) { + if (breakpoints[i].used && breakpoints[i].addr == a) { + breakpoints[i].used = false; + bp_clear_exec(a); + printf("Cleared breakpoint at %04X\n", a); + return; + } + } + for (int i=0; i<32; i++) if (!breakpoints[i].used) { + breakpoints[i].addr = a; + breakpoints[i].used = true; + bp_set_exec(a); + printf("Breakpoint set at %04X\n", a); + return; + } + printf("Breakpoint table full\n"); +} + +static void cmd_break_clear(void) +{ + for (int i=0; i<32; i++) breakpoints[i].used = false; + bp_clear_all(); + printf("All breakpoints cleared.\n"); +} + +static void cmd_fill(char *line) +{ + uint16_t s=0,e=0,v=0; + if (sscanf(line, " %*s %hx %hx %hx", &s, &e, &v) < 3) { + printf("F \n"); return; + } + for (uint16_t a=s; a<=e; a++) mem_write8(a, (uint8_t)v); + printf("Filled %04X..%04X with %02X\n", s, e, (uint8_t)v); +} + +static void cmd_load(char *line) +{ + char fname[256]; + uint16_t forced = 0; + int have_forced = 0; + if (sscanf(line, " %*s %255s %hx", fname, &forced) == 2) have_forced = 1; + else if (sscanf(line, " %*s %255s", fname) != 1) { printf("L [addr]\n"); return; } + + int n = load_file(fname, have_forced ? forced : 0, have_forced); + if (n < 0) printf("Load failed: %s\n", fname); + else { + printf("Loaded %d bytes from %s\n", n, fname); + if (!have_forced) { + /* try to be nice: if reset vector looks sane use it */ + uint16_t rst = mem_read16(0xFFFE); + if (rst >= 0x0100 && rst < 0xFF00) { + printf("Reset vector suggests PC=%04X\n", rst); + } + } + } +} + +static void cmd_save(char *line) +{ + char fname[256], fmt[16]="S19"; + uint16_t s=0, e=0; + if (sscanf(line, " %*s %255s %hx %hx %15s", fname, &s, &e, fmt) < 3) { + printf("S [S19|IHEX|BIN]\n"); return; + } + int rc = save_file(fname, s, e, fmt); + if (rc < 0) printf("Save failed\n"); + else printf("Saved %04X..%04X to %s (%s)\n", s, e, fname, fmt); +} + +static void cmd_shell(char *line) +{ + char *cmd = line + 1; + while (*cmd && isspace((unsigned char)*cmd)) cmd++; + if (*cmd) system(cmd); + else printf("! \n"); +} + +static void help(void) +{ + puts("mimic09 monitor — commands (C64 style):"); + puts(" R show registers"); + puts(" ; edit registers (e.g. ; PC=1000 A=2A)"); + puts(" M [cnt] memory dump (hex+ascii)"); + puts(" : poke bytes"); + puts(" D [addr] [n] disassemble"); + puts(" A mini-assembler (limited)"); + puts(" G [addr] run (Ctrl-C breaks)"); + puts(" S [n] single step"); + puts(" B [addr] set/clear/list breakpoint"); + puts(" BC clear all breakpoints"); + puts(" F fill"); + puts(" L [addr] load SREC/IHEX/BIN"); + puts(" S [fmt] save (S19|IHEX|BIN)"); + puts(" ! shell command"); + puts(" X or Q quit"); + puts(" ? or H this help"); +} + +void monitor_run(void) +{ + char line[256]; + cpu.debug_mode = true; + next_dasm = cpu.pc; + next_mem = 0x0000; + + printf("mimic09 monitor. Type ? for help. X to exit.\n"); + print_regs(); + + for (;;) { + printf("m9> "); + fflush(stdout); + if (!fgets(line, sizeof(line), stdin)) break; + to_upper(line); + if (line[0] == '\n' || line[0] == 0) continue; + + if (line[0] == 'Q' || line[0] == 'X') break; + else if (line[0] == 'R') cmd_registers(line); + else if (line[0] == ';') cmd_edit_regs(line); + else if (line[0] == 'M') cmd_memory(line); + else if (line[0] == ':') cmd_poke(line); + else if (line[0] == 'D') cmd_disasm(line); + else if (line[0] == 'A') cmd_assemble(line); + else if (line[0] == 'G') cmd_go(line); + else if (line[0] == 'S' && (line[1]==' ' || line[1]=='\n' || line[1]==0 || isdigit(line[1]))) cmd_step(line); + else if (line[0] == 'B') cmd_break(line); + else if (strncmp(line, "BC", 2)==0) cmd_break_clear(); + else if (line[0] == 'F') cmd_fill(line); + else if (line[0] == 'L') cmd_load(line); + else if (line[0] == 'S') cmd_save(line); + else if (line[0] == '!') cmd_shell(line); + else if (line[0] == '?' || line[0] == 'H') help(); + else printf("Unknown. Type ? for help.\n"); + } + puts("Exiting mimic09."); +} diff --git a/src/debug.h b/src/debug.h new file mode 100644 index 0000000..3eff3e3 --- /dev/null +++ b/src/debug.h @@ -0,0 +1,21 @@ +/* debug.h — C64-style monitor / debugger for mimic09 */ + +#ifndef MIMIC09_DEBUG_H +#define MIMIC09_DEBUG_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void monitor_run(void); /* enters interactive monitor loop */ +void monitor_step(int count); /* single step helper */ +void monitor_set_load_addr(uint16_t a); +uint16_t monitor_get_load_addr(void); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/disasm.c b/src/disasm.c new file mode 100644 index 0000000..a2311f6 --- /dev/null +++ b/src/disasm.c @@ -0,0 +1,254 @@ +/* disasm.c — table-driven 6809/6309 disassembler for the monitor */ + +#include "disasm.h" +#include "cpu.h" +#include +#include + +typedef enum { + M_IMPL, M_IMM8, M_IMM16, M_DIR, M_EXT, M_REL8, M_REL16, + M_IDX, M_INH_A, M_INH_B, M_INH_D, M_PSH, M_TFR, M_SWI, + M_IMM32_6309 +} mode_t; + +typedef struct { + const char *mnem; + mode_t mode; + int bytes; /* total including opcode */ +} opinfo_t; + +static const opinfo_t optab[256] = { + /* 00 */ {"NEG", M_DIR, 2}, {"???", M_IMPL,1}, {"???", M_IMPL,1}, {"COM", M_DIR,2}, + /* 04 */ {"LSR", M_DIR,2}, {"???", M_IMPL,1}, {"ROR", M_DIR,2}, {"ASR", M_DIR,2}, + /* 08 */ {"ASL", M_DIR,2}, {"ROL", M_DIR,2}, {"DEC", M_DIR,2}, {"???", M_IMPL,1}, + /* 0C */ {"INC", M_DIR,2}, {"TST", M_DIR,2}, {"JMP", M_DIR,2}, {"CLR", M_DIR,2}, + + /* 10 */ {"???", M_IMPL,1}, {"???", M_IMPL,1}, {"NOP", M_IMPL,1}, {"SYNC",M_IMPL,1}, + /* 14 */ {"SEXW",M_IMPL,1}, {"???", M_IMPL,1}, {"LBRA",M_REL16,3}, {"LBSR",M_REL16,3}, + /* 18 */ {"???", M_IMPL,1}, {"DAA", M_IMPL,1}, {"ORCC",M_IMM8,2}, {"???", M_IMPL,1}, + /* 1C */ {"ANDCC",M_IMM8,2}, {"SEX", M_IMPL,1}, {"EXG", M_TFR,2}, {"TFR", M_TFR,2}, + + /* 20 */ {"BRA", M_REL8,2}, {"BRN", M_REL8,2}, {"BHI", M_REL8,2}, {"BLS", M_REL8,2}, + /* 24 */ {"BCC", M_REL8,2}, {"BCS", M_REL8,2}, {"BNE", M_REL8,2}, {"BEQ", M_REL8,2}, + /* 28 */ {"BVC", M_REL8,2}, {"BVS", M_REL8,2}, {"BPL", M_REL8,2}, {"BMI", M_REL8,2}, + /* 2C */ {"BGE", M_REL8,2}, {"BLT", M_REL8,2}, {"BGT", M_REL8,2}, {"BLE", M_REL8,2}, + + /* 30 */ {"LEAX",M_IDX,2}, {"LEAY",M_IDX,2}, {"LEAS",M_IDX,2}, {"LEAU",M_IDX,2}, + /* 34 */ {"PSHS",M_PSH,2}, {"PULS",M_PSH,2}, {"PSHU",M_PSH,2}, {"PULU",M_PSH,2}, + /* 38 */ {"???", M_IMPL,1}, {"RTS", M_IMPL,1}, {"ABX", M_IMPL,1}, {"RTI", M_IMPL,1}, + /* 3C */ {"CWAI",M_IMM8,2}, {"MUL", M_IMPL,1}, {"???", M_IMPL,1}, {"SWI", M_SWI,1}, + + /* 40 */ {"NEGA",M_INH_A,1}, {"???", M_IMPL,1}, {"???", M_IMPL,1}, {"COMA",M_INH_A,1}, + /* 44 */ {"LSRA",M_INH_A,1}, {"???", M_IMPL,1}, {"RORA",M_INH_A,1}, {"ASRA",M_INH_A,1}, + /* 48 */ {"ASLA",M_INH_A,1}, {"ROLA",M_INH_A,1}, {"DECA",M_INH_A,1}, {"???", M_IMPL,1}, + /* 4C */ {"INCA",M_INH_A,1}, {"TSTA",M_INH_A,1}, {"???", M_IMPL,1}, {"CLRA",M_INH_A,1}, + + /* 50 */ {"NEGB",M_INH_B,1}, {"???", M_IMPL,1}, {"???", M_IMPL,1}, {"COMB",M_INH_B,1}, + /* 54 */ {"LSRB",M_INH_B,1}, {"???", M_IMPL,1}, {"RORB",M_INH_B,1}, {"ASRB",M_INH_B,1}, + /* 58 */ {"ASLB",M_INH_B,1}, {"ROLB",M_INH_B,1}, {"DECB",M_INH_B,1}, {"???", M_IMPL,1}, + /* 5C */ {"INCB",M_INH_B,1}, {"TSTB",M_INH_B,1}, {"???", M_IMPL,1}, {"CLRB",M_INH_B,1}, + + /* 60 */ {"NEG", M_IDX,2}, {"???", M_IMPL,1}, {"???", M_IMPL,1}, {"COM", M_IDX,2}, + /* 64 */ {"LSR", M_IDX,2}, {"???", M_IMPL,1}, {"ROR", M_IDX,2}, {"ASR", M_IDX,2}, + /* 68 */ {"ASL", M_IDX,2}, {"ROL", M_IDX,2}, {"DEC", M_IDX,2}, {"???", M_IMPL,1}, + /* 6C */ {"INC", M_IDX,2}, {"TST", M_IDX,2}, {"JMP", M_IDX,2}, {"CLR", M_IDX,2}, + + /* 70 */ {"NEG", M_EXT,3}, {"???", M_IMPL,1}, {"???", M_IMPL,1}, {"COM", M_EXT,3}, + /* 74 */ {"LSR", M_EXT,3}, {"???", M_IMPL,1}, {"ROR", M_EXT,3}, {"ASR", M_EXT,3}, + /* 78 */ {"ASL", M_EXT,3}, {"ROL", M_EXT,3}, {"DEC", M_EXT,3}, {"???", M_IMPL,1}, + /* 7C */ {"INC", M_EXT,3}, {"TST", M_EXT,3}, {"JMP", M_EXT,3}, {"CLR", M_EXT,3}, + + /* 80 */ {"SUBA",M_IMM8,2}, {"CMPA",M_IMM8,2}, {"SBCA",M_IMM8,2}, {"SUBD",M_IMM16,3}, + /* 84 */ {"ANDA",M_IMM8,2}, {"BITA",M_IMM8,2}, {"LDA", M_IMM8,2}, {"???", M_IMPL,1}, + /* 88 */ {"EORA",M_IMM8,2}, {"ADCA",M_IMM8,2}, {"ORA", M_IMM8,2}, {"ADDA",M_IMM8,2}, + /* 8C */ {"CMPX",M_IMM16,3}, {"BSR", M_REL8,2}, {"LDX", M_IMM16,3}, {"???", M_IMPL,1}, + + /* 90 */ {"SUBA",M_DIR,2}, {"CMPA",M_DIR,2}, {"SBCA",M_DIR,2}, {"SUBD",M_DIR,2}, + /* 94 */ {"ANDA",M_DIR,2}, {"BITA",M_DIR,2}, {"LDA", M_DIR,2}, {"STA", M_DIR,2}, + /* 98 */ {"EORA",M_DIR,2}, {"ADCA",M_DIR,2}, {"ORA", M_DIR,2}, {"ADDA",M_DIR,2}, + /* 9C */ {"CMPX",M_DIR,2}, {"JSR", M_DIR,2}, {"LDX", M_DIR,2}, {"STX", M_DIR,2}, + + /* A0 */ {"SUBA",M_IDX,2}, {"CMPA",M_IDX,2}, {"SBCA",M_IDX,2}, {"SUBD",M_IDX,2}, + /* A4 */ {"ANDA",M_IDX,2}, {"BITA",M_IDX,2}, {"LDA", M_IDX,2}, {"STA", M_IDX,2}, + /* A8 */ {"EORA",M_IDX,2}, {"ADCA",M_IDX,2}, {"ORA", M_IDX,2}, {"ADDA",M_IDX,2}, + /* AC */ {"CMPX",M_IDX,2}, {"JSR", M_IDX,2}, {"LDX", M_IDX,2}, {"STX", M_IDX,2}, + + /* B0 */ {"SUBA",M_EXT,3}, {"CMPA",M_EXT,3}, {"SBCA",M_EXT,3}, {"SUBD",M_EXT,3}, + /* B4 */ {"ANDA",M_EXT,3}, {"BITA",M_EXT,3}, {"LDA", M_EXT,3}, {"STA", M_EXT,3}, + /* B8 */ {"EORA",M_EXT,3}, {"ADCA",M_EXT,3}, {"ORA", M_EXT,3}, {"ADDA",M_EXT,3}, + /* BC */ {"CMPX",M_EXT,3}, {"JSR", M_EXT,3}, {"LDX", M_EXT,3}, {"STX", M_EXT,3}, + + /* C0 */ {"SUBB",M_IMM8,2}, {"CMPB",M_IMM8,2}, {"SBCB",M_IMM8,2}, {"ADDD",M_IMM16,3}, + /* C4 */ {"ANDB",M_IMM8,2}, {"BITB",M_IMM8,2}, {"LDB", M_IMM8,2}, {"???", M_IMPL,1}, + /* C8 */ {"EORB",M_IMM8,2}, {"ADCB",M_IMM8,2}, {"ORB", M_IMM8,2}, {"ADDB",M_IMM8,2}, + /* CC */ {"LDD", M_IMM16,3}, {"???", M_IMPL,1}, {"LDU", M_IMM16,3}, {"???", M_IMPL,1}, + + /* D0 */ {"SUBB",M_DIR,2}, {"CMPB",M_DIR,2}, {"SBCB",M_DIR,2}, {"ADDD",M_DIR,2}, + /* D4 */ {"ANDB",M_DIR,2}, {"BITB",M_DIR,2}, {"LDB", M_DIR,2}, {"STB", M_DIR,2}, + /* D8 */ {"EORB",M_DIR,2}, {"ADCB",M_DIR,2}, {"ORB", M_DIR,2}, {"ADDB",M_DIR,2}, + /* DC */ {"LDD", M_DIR,2}, {"STD", M_DIR,2}, {"LDU", M_DIR,2}, {"STU", M_DIR,2}, + + /* E0 */ {"SUBB",M_IDX,2}, {"CMPB",M_IDX,2}, {"SBCB",M_IDX,2}, {"ADDD",M_IDX,2}, + /* E4 */ {"ANDB",M_IDX,2}, {"BITB",M_IDX,2}, {"LDB", M_IDX,2}, {"STB", M_IDX,2}, + /* E8 */ {"EORB",M_IDX,2}, {"ADCB",M_IDX,2}, {"ORB", M_IDX,2}, {"ADDB",M_IDX,2}, + /* EC */ {"LDD", M_IDX,2}, {"STD", M_IDX,2}, {"LDU", M_IDX,2}, {"STU", M_IDX,2}, + + /* F0 */ {"SUBB",M_EXT,3}, {"CMPB",M_EXT,3}, {"SBCB",M_EXT,3}, {"ADDD",M_EXT,3}, + /* F4 */ {"ANDB",M_EXT,3}, {"BITB",M_EXT,3}, {"LDB", M_EXT,3}, {"STB", M_EXT,3}, + /* F8 */ {"EORB",M_EXT,3}, {"ADCB",M_EXT,3}, {"ORB", M_EXT,3}, {"ADDB",M_EXT,3}, + /* FC */ {"LDD", M_EXT,3}, {"STD", M_EXT,3}, {"LDU", M_EXT,3}, {"STU", M_EXT,3}, +}; + +static const opinfo_t optab10[256] = { + [0x20]={"LBRA",M_REL16,3}, [0x21]={"LBRN",M_REL16,3}, [0x22]={"LBHI",M_REL16,3}, + [0x23]={"LBLS",M_REL16,3}, [0x24]={"LBCC",M_REL16,3}, [0x25]={"LBCS",M_REL16,3}, + [0x26]={"LBNE",M_REL16,3}, [0x27]={"LBEQ",M_REL16,3}, [0x28]={"LBVC",M_REL16,3}, + [0x29]={"LBVS",M_REL16,3}, [0x2A]={"LBPL",M_REL16,3}, [0x2B]={"LBMI",M_REL16,3}, + [0x2C]={"LBGE",M_REL16,3}, [0x2D]={"LBLT",M_REL16,3}, [0x2E]={"LBGT",M_REL16,3}, + [0x2F]={"LBLE",M_REL16,3}, + [0x3F]={"SWI2",M_IMPL,2}, + [0x83]={"CMPD",M_IMM16,4}, [0x8C]={"CMPY",M_IMM16,4}, [0x8E]={"LDY", M_IMM16,4}, + [0x93]={"CMPD",M_DIR,3}, [0x9C]={"CMPY",M_DIR,3}, [0x9E]={"LDY", M_DIR,3}, [0x9F]={"STY",M_DIR,3}, + [0xA3]={"CMPD",M_IDX,3}, [0xAC]={"CMPY",M_IDX,3}, [0xAE]={"LDY", M_IDX,3}, [0xAF]={"STY",M_IDX,3}, + [0xB3]={"CMPD",M_EXT,4}, [0xBC]={"CMPY",M_EXT,4}, [0xBE]={"LDY", M_EXT,4}, [0xBF]={"STY",M_EXT,4}, + [0xCE]={"LDS", M_IMM16,4}, [0xDE]={"LDS",M_DIR,3}, [0xDF]={"STS",M_DIR,3}, + [0xEE]={"LDS", M_IDX,3}, [0xEF]={"STS",M_IDX,3}, + [0xFE]={"LDS", M_EXT,4}, [0xFF]={"STS",M_EXT,4}, +}; + +static const opinfo_t optab11[256] = { + [0x83]={"CMPU",M_IMM16,4}, [0x8C]={"CMPS",M_IMM16,4}, + [0x93]={"CMPU",M_DIR,3}, [0x9C]={"CMPS",M_DIR,3}, + [0xA3]={"CMPU",M_IDX,3}, [0xAC]={"CMPS",M_IDX,3}, + [0xB3]={"CMPU",M_EXT,4}, [0xBC]={"CMPS",M_EXT,4}, + /* 6309 additions can be added here */ +}; + +static void fmt_idx(uint16_t *pc, char *out, size_t sz) +{ + uint8_t post = mem_read8(*pc); (*pc)++; + int r = (post >> 5) & 3; + const char *rs[4] = {"X","Y","U","S"}; + if (post & 0x80) { + int indir = (post & 0x10) ? 1 : 0; + const char *pre = indir ? "[" : ""; + const char *suf = indir ? "]" : ""; + switch (post & 0x0F) { + case 0x00: snprintf(out, sz, "%s,%s+%s", pre, rs[r], suf); break; + case 0x01: snprintf(out, sz, "%s,%s++%s", pre, rs[r], suf); break; + case 0x02: snprintf(out, sz, "%s,-%s%s", pre, rs[r], suf); break; + case 0x03: snprintf(out, sz, "%s,--%s%s", pre, rs[r], suf); break; + case 0x04: snprintf(out, sz, "%s,%s%s", pre, rs[r], suf); break; + case 0x05: snprintf(out, sz, "%sB,%s%s", pre, rs[r], suf); break; + case 0x06: snprintf(out, sz, "%sA,%s%s", pre, rs[r], suf); break; + case 0x08: { int8_t n = (int8_t)mem_read8(*pc); (*pc)++; snprintf(out,sz,"%s%d,%s%s",pre,n,rs[r],suf); break; } + case 0x09: { int16_t n=(int16_t)mem_read16(*pc); (*pc)+=2; snprintf(out,sz,"%s%d,%s%s",pre,n,rs[r],suf); break; } + case 0x0B: snprintf(out, sz, "%sD,%s%s", pre, rs[r], suf); break; + case 0x0C: { int8_t n=(int8_t)mem_read8(*pc); (*pc)++; snprintf(out,sz,"%s%d,PCR%s",pre,n,suf); break; } + case 0x0D: { int16_t n=(int16_t)mem_read16(*pc); (*pc)+=2; snprintf(out,sz,"%s%d,PCR%s",pre,n,suf); break; } + case 0x9F: { uint16_t n = mem_read16(*pc); (*pc)+=2; snprintf(out,sz,"[%04X]", n); break; } + default: snprintf(out, sz, "???"); break; + } + } else { + int off = post & 0x1F; if (off & 0x10) off |= ~0x1F; + snprintf(out, sz, "%d,%s", off, rs[r]); + } +} + +int disasm(uint16_t addr, char *out, size_t outsz, uint16_t *next_addr) +{ + uint16_t pc = addr; + uint8_t op = mem_read8(pc); pc++; + + const opinfo_t *tab = optab; + const opinfo_t *info = &tab[op]; + char operand[64] = ""; + + if (op == 0x10) { + uint8_t op2 = mem_read8(pc); pc++; + info = &optab10[op2]; + if (!info->mnem) info = &(opinfo_t){"???", M_IMPL, 2}; + } else if (op == 0x11) { + uint8_t op2 = mem_read8(pc); pc++; + info = &optab11[op2]; + if (!info->mnem) info = &(opinfo_t){"???", M_IMPL, 2}; + } + + const char *m = info->mnem ? info->mnem : "???"; + + switch (info->mode) { + case M_IMPL: case M_INH_A: case M_INH_B: case M_INH_D: case M_SWI: + break; + case M_IMM8: + snprintf(operand, sizeof(operand), "#$%02X", mem_read8(pc)); pc++; + break; + case M_IMM16: + snprintf(operand, sizeof(operand), "#$%04X", mem_read16(pc)); pc += 2; + break; + case M_DIR: { + uint8_t a = mem_read8(pc); pc++; + snprintf(operand, sizeof(operand), "<$%02X", a); + break; + } + case M_EXT: { + uint16_t a = mem_read16(pc); pc += 2; + snprintf(operand, sizeof(operand), "$%04X", a); + break; + } + case M_REL8: { + int8_t off = (int8_t)mem_read8(pc); pc++; + uint16_t tgt = (uint16_t)(pc + off); + snprintf(operand, sizeof(operand), "$%04X", tgt); + break; + } + case M_REL16: { + int16_t off = (int16_t)mem_read16(pc); pc += 2; + uint16_t tgt = (uint16_t)(pc + off); + snprintf(operand, sizeof(operand), "$%04X", tgt); + break; + } + case M_IDX: + fmt_idx(&pc, operand, sizeof(operand)); + break; + case M_PSH: { + uint8_t p = mem_read8(pc); pc++; + char regs[32] = ""; + if (p & 0x80) strcat(regs, "PC,"); + if (p & 0x40) strcat(regs, "U/S,"); + if (p & 0x20) strcat(regs, "Y,"); + if (p & 0x10) strcat(regs, "X,"); + if (p & 0x08) strcat(regs, "A,"); + if (p & 0x04) strcat(regs, "B,"); + if (p & 0x02) strcat(regs, "CC,"); + if (p & 0x01) strcat(regs, "DP,"); + if (regs[0]) regs[strlen(regs)-1] = 0; + snprintf(operand, sizeof(operand), "#$%02X ; %s", p, regs); + break; + } + case M_TFR: { + uint8_t p = mem_read8(pc); pc++; + static const char *r16[] = {"D","X","Y","U","S","PC"}; + static const char *r8[] = {"A","B","CC","??","??","??","??","??"}; + int s = (p>>4)&15, d = p & 15; + if (s < 6 && d < 6) + snprintf(operand, sizeof(operand), "%s,%s", r16[s], r16[d]); + else + snprintf(operand, sizeof(operand), "#$%02X", p); + break; + } + case M_IMM32_6309: + snprintf(operand, sizeof(operand), "#$%08X", (mem_read16(pc)<<16)|mem_read16(pc+2)); + pc += 4; + break; + default: + break; + } + + if (operand[0]) + snprintf(out, outsz, "%-5s %s", m, operand); + else + snprintf(out, outsz, "%s", m); + + if (next_addr) *next_addr = pc; + return (int)(pc - addr); +} diff --git a/src/disasm.h b/src/disasm.h new file mode 100644 index 0000000..f0d2e16 --- /dev/null +++ b/src/disasm.h @@ -0,0 +1,21 @@ +/* disasm.h — mimic09 built-in disassembler */ + +#ifndef MIMIC09_DISASM_H +#define MIMIC09_DISASM_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Disassemble one instruction at 'addr' into 'out' (null-terminated). + * Returns the number of bytes consumed by the instruction. + */ +int disasm(uint16_t addr, char *out, size_t outsz, uint16_t *next_addr); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/loader.c b/src/loader.c new file mode 100644 index 0000000..bf4c534 --- /dev/null +++ b/src/loader.c @@ -0,0 +1,177 @@ +/* loader.c — robust S-Record + Intel HEX + raw binary */ + +#include "loader.h" +#include "cpu.h" +#include +#include +#include + +static uint8_t checksum(const uint8_t *buf, int len) +{ + uint8_t s = 0; + for (int i = 0; i < len; i++) s += buf[i]; + return (~s) & 0xFF; +} + +static int load_srec(const char *path) +{ + FILE *f = fopen(path, "r"); + if (!f) return -1; + char line[512]; + int total = 0; + while (fgets(line, sizeof(line), f)) { + char *p = line; + while (*p == '\r' || *p == '\n' || *p == ' ' || *p == '\t') p++; + if (*p != 'S' && *p != 's') continue; + char type = (char)toupper((unsigned char)p[1]); + if (type == '0' || type == '5') continue; + int len = 0; + unsigned addr = 0; + int alen = (type == '1' || type == '9') ? 2 : (type == '2' || type == '8') ? 3 : 4; + if (sscanf(p+2, "%2x", &len) != 1) continue; + const char *addrp = p + 4; + if (alen == 2) sscanf(addrp, "%4x", &addr); + else if (alen == 3) sscanf(addrp, "%6x", &addr); + else sscanf(addrp, "%8x", &addr); + int data_start = 4 + alen * 2; + int data_len = len - alen - 1; + if (data_len < 0) continue; + for (int i = 0; i < data_len; i++) { + unsigned b = 0; + if (sscanf(p + data_start + i*2, "%2x", &b) != 1) break; + mem_write8((uint16_t)(addr + i), (uint8_t)b); + total++; + } + if (type == '7' || type == '8' || type == '9') { + /* termination with optional entry point; monitor user sets PC */ + } + } + fclose(f); + return total; +} + +static int load_ihex(const char *path) +{ + FILE *f = fopen(path, "r"); + if (!f) return -1; + char line[512]; + int total = 0; + uint32_t base = 0; + while (fgets(line, sizeof(line), f)) { + /* tolerate CRLF, leading whitespace, \r only lines */ + char *p = line; + while (*p == '\r' || *p == '\n' || *p == ' ' || *p == '\t') p++; + if (*p != ':') continue; + p++; /* skip : */ + unsigned len=0, addr=0, type=0; + if (sscanf(p, "%2x%4x%2x", &len, &addr, &type) != 3) continue; + if (type == 0) { /* data */ + uint16_t a = (uint16_t)(base + addr); + char *datahex = p + 6; /* after len(2) addr(4) type(2) */ + for (unsigned i = 0; i < len; i++) { + unsigned b = 0; + if (sscanf(datahex + i*2, "%2x", &b) != 1) break; + mem_write8((uint16_t)(a + i), (uint8_t)b); + total++; + } + } else if (type == 1) { /* eof */ + break; + } else if (type == 2) { /* extended segment */ + unsigned seg = 0; sscanf(p + 6, "%4x", &seg); base = seg * 16U; + } else if (type == 4) { /* extended linear */ + unsigned seg = 0; sscanf(p + 6, "%4x", &seg); base = (uint32_t)seg << 16; + } + } + fclose(f); + return total; +} + +static int load_raw(const char *path, uint16_t at) +{ + FILE *f = fopen(path, "rb"); + if (!f) return -1; + int total = 0; + int c; + while ((c = fgetc(f)) != EOF) { + mem_write8(at++, (uint8_t)c); + total++; + } + fclose(f); + return total; +} + +int load_file(const char *path, uint16_t force_addr, int force) +{ + /* auto detect by content or extension */ + const char *ext = strrchr(path, '.'); + if (force || (ext && (strcasecmp(ext, ".bin") == 0 || strcasecmp(ext, ".rom") == 0))) { + return load_raw(path, force_addr); + } + FILE *f = fopen(path, "r"); + if (!f) return -1; + /* Skip leading CR/LF/whitespace to find real first significant char */ + int first = 0; + for (;;) { + int c = fgetc(f); + if (c == EOF) break; + if (c != '\r' && c != '\n' && c != ' ' && c != '\t') { + first = c; + break; + } + } + fclose(f); + if (first == ':') return load_ihex(path); + if (first == 'S' || first == 's') return load_srec(path); + if (force_addr) return load_raw(path, force_addr); + return load_raw(path, 0); +} + +int save_file(const char *path, uint16_t start, uint16_t end, const char *fmt) +{ + FILE *f = fopen(path, "w"); + if (!f) return -1; + int count = 0; + if (strcasecmp(fmt, "BIN") == 0) { + for (uint16_t a = start; a <= end; a++) { + fputc(mem_read8(a), f); + count++; + } + } else if (strcasecmp(fmt, "IHEX") == 0 || strcasecmp(fmt, "HEX") == 0) { + uint16_t addr = start; + while (addr <= end) { + int len = (end - addr + 1) > 16 ? 16 : (end - addr + 1); + fprintf(f, ":%02X%04X00", len, addr); + uint8_t sum = len + (addr >> 8) + (addr & 0xFF) + 0; + for (int i = 0; i < len; i++) { + uint8_t b = mem_read8((uint16_t)(addr + i)); + fprintf(f, "%02X", b); + sum += b; + } + fprintf(f, "%02X\n", (uint8_t)((~sum + 1) & 0xFF)); + addr += (uint16_t)len; + count += len; + } + fprintf(f, ":00000001FF\n"); + } else { /* S19 default */ + uint16_t addr = start; + while (addr <= end) { + int len = (end - addr + 1) > 32 ? 32 : (end - addr + 1); + uint8_t rec[3 + 32 + 1]; + rec[0] = (uint8_t)(len + 3); /* count */ + rec[1] = addr >> 8; + rec[2] = addr & 0xFF; + for (int i = 0; i < len; i++) rec[3 + i] = mem_read8((uint16_t)(addr + i)); + uint8_t cs = checksum(rec, len + 3); + fprintf(f, "S1%02X%04X", len + 3, addr); + for (int i = 0; i < len; i++) fprintf(f, "%02X", rec[3 + i]); + fprintf(f, "%02X\n", cs); + addr += (uint16_t)len; + count += len; + } + /* termination record */ + uint16_t exec = start; + fprintf(f, "S903%04X%02X\n", exec, (uint8_t)(~ (3 + (exec>>8) + (exec&0xFF)) & 0xFF)); + } + fclose(f); + return count; +} diff --git a/src/loader.h b/src/loader.h new file mode 100644 index 0000000..df15758 --- /dev/null +++ b/src/loader.h @@ -0,0 +1,25 @@ +/* loader.h — S-Record, Intel HEX, raw binary load/save */ + +#ifndef MIMIC09_LOADER_H +#define MIMIC09_LOADER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Load a file. If force_addr != 0 and format is raw, load at that address. + * Returns number of bytes loaded, or negative on error. + */ +int load_file(const char *path, uint16_t force_addr, int force); + +/* Save region. fmt = "S19", "IHEX", "BIN" + * Returns bytes written or negative. + */ +int save_file(const char *path, uint16_t start, uint16_t end, const char *fmt); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..666dfb3 --- /dev/null +++ b/src/main.c @@ -0,0 +1,133 @@ +/* main.c — mimic09 entry point */ + +#include +#include +#include +#include +#include + +#include "cpu.h" +#include "debug.h" +#include "loader.h" +#include "acia.h" +#include "pia.h" + +static void usage(const char *argv0) +{ + printf("mimic09 — fast 6809/6309 emulator with C64-style monitor\n"); + printf("Usage: %s [options] [file]\n\n", argv0); + printf("Options:\n"); + printf(" -i, --interactive enter monitor immediately\n"); + printf(" -l, --load load SREC/IHEX/BIN at optional address\n"); + printf(" -a, --addr force load address for raw binary\n"); + printf(" -g, --go [addr] run (from addr or reset vector / PC)\n"); + printf(" -c, --cpu <6809|6309> select CPU model (default 6809)\n"); + printf(" --acia map 6850 ACIA at this base address\n"); + printf(" --pia map 6821 PIA at this base address\n"); + printf(" -v, --version\n"); + printf(" -h, --help\n"); + printf("\nExamples:\n"); + printf(" %s -l samples/2299.HEX -i\n", argv0); + printf(" %s -l myprog.s19 --acia 0xA000 -g\n", argv0); + printf(" %s -i\n", argv0); +} + +static void version(void) +{ + printf("mimic09 0.9 (modern re-creation)\n"); +} + +int main(int argc, char **argv) +{ + int interactive = 0; + int do_go = 0; + uint16_t go_addr = 0; + uint16_t force_addr = 0; + int have_force = 0; + cpu_model_t model = CPU_6809; + uint16_t acia_base = 0; + uint16_t pia_base = 0; + const char *loadfile = NULL; + + static struct option longopts[] = { + {"interactive", no_argument, 0, 'i'}, + {"load", required_argument, 0, 'l'}, + {"addr", required_argument, 0, 'a'}, + {"go", optional_argument, 0, 'g'}, + {"cpu", required_argument, 0, 'c'}, + {"acia", required_argument, 0, 1000}, + {"pia", required_argument, 0, 1001}, + {"version", no_argument, 0, 'v'}, + {"help", no_argument, 0, 'h'}, + {0,0,0,0} + }; + + int ch; + while ((ch = getopt_long(argc, argv, "il:a:g::c:vh", longopts, NULL)) != -1) { + switch (ch) { + case 'i': interactive = 1; break; + case 'l': loadfile = optarg; break; + case 'a': have_force = 1; sscanf(optarg, "%hx", &force_addr); break; + case 'g': do_go = 1; if (optarg) sscanf(optarg, "%hx", &go_addr); break; + case 'c': + if (strcasecmp(optarg, "6309") == 0) model = CPU_6309; + else model = CPU_6809; + break; + case 1000: sscanf(optarg, "%hx", &acia_base); break; + case 1001: sscanf(optarg, "%hx", &pia_base); break; + case 'v': version(); return 0; + case 'h': usage(argv[0]); return 0; + default: usage(argv[0]); return 1; + } + } + + if (optind < argc && !loadfile) { + loadfile = argv[optind]; + } + + cpu_init(model); + if (acia_base) acia_init(acia_base); + if (pia_base) pia_init(pia_base); + + if (loadfile) { + int n = load_file(loadfile, have_force ? force_addr : 0, have_force); + if (n < 0) { + fprintf(stderr, "Failed to load %s\n", loadfile); + } else { + printf("Loaded %d bytes from %s\n", n, loadfile); + } + } + + /* Default: if no -i and a load happened, set PC from reset vector if it looks good */ + if (!interactive && loadfile) { + uint16_t rst = mem_read16(0xFFFE); + if (rst >= 0x0100 && rst <= 0xFEFF) { + cpu.pc = rst; + printf("PC set from reset vector to %04X\n", cpu.pc); + } + } + + if (do_go) { + if (go_addr) cpu.pc = go_addr; + cpu.halted = false; + cpu.debug_mode = false; + + /* Run with ACIA polling if present */ + printf("Running. Press Ctrl-C to return to monitor.\n"); + /* simple loop so we can feed ACIA chars */ + while (!cpu.halted) { + cpu_step(); + /* ACIA input is polled inside its own layer when needed, but we help here */ + /* In this simple build the ACIA uses direct read in raw mode during G */ + if (acia_base && (cpu.total_cycles & 0x7F) == 0) { + /* acia_poll_input is internal; the acia read path + raw term during G is sufficient */ + } + } + } + + if (interactive || (!loadfile && !do_go)) { + monitor_run(); + } + + return 0; +} diff --git a/src/pia.c b/src/pia.c new file mode 100644 index 0000000..6a51592 --- /dev/null +++ b/src/pia.c @@ -0,0 +1,42 @@ +/* pia.c — very basic 6821 PIA (two ports, no full handshake yet) */ + +#include "pia.h" +#include "cpu.h" + +static uint16_t pia_base; +static uint8_t pra, ddra, cra; +static uint8_t prb, ddrb, crb; + +void pia_init(uint16_t base) +{ + pia_base = base; + pra = prb = 0; + ddra = ddrb = 0; + cra = crb = 0; + cpu_register_device(base, pia_read, pia_write); +} + +uint8_t pia_read(uint16_t off) +{ + switch (off & 3) { + case 0: return (cra & 0x04) ? pra : ddra; + case 1: return cra; + case 2: return (crb & 0x04) ? prb : ddrb; + case 3: return crb; + } + return 0xFF; +} + +void pia_write(uint16_t off, uint8_t val) +{ + switch (off & 3) { + case 0: + if (cra & 0x04) pra = val; else ddra = val; + break; + case 1: cra = val; break; + case 2: + if (crb & 0x04) prb = val; else ddrb = val; + break; + case 3: crb = val; break; + } +} diff --git a/src/pia.h b/src/pia.h new file mode 100644 index 0000000..e8b769a --- /dev/null +++ b/src/pia.h @@ -0,0 +1,19 @@ +/* pia.h — 6821 PIA emulation (basic) */ + +#ifndef MIMIC09_PIA_H +#define MIMIC09_PIA_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void pia_init(uint16_t base); +uint8_t pia_read(uint16_t off); +void pia_write(uint16_t off, uint8_t val); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..055e66d --- /dev/null +++ b/src/util.c @@ -0,0 +1,29 @@ +/* util.c */ + +#include "util.h" +#include + +int hexval(char c) +{ + if (c >= '0' && c <= '9') return c - '0'; + if (c >= 'A' && c <= 'F') return 10 + (c - 'A'); + if (c >= 'a' && c <= 'f') return 10 + (c - 'a'); + return -1; +} + +int parse_hex_byte(const char *p, uint8_t *out) +{ + int h = hexval(p[0]); + int l = hexval(p[1]); + if (h < 0 || l < 0) return 0; + *out = (uint8_t)((h << 4) | l); + return 1; +} + +int parse_hex_word(const char *p, uint16_t *out) +{ + uint8_t hi, lo; + if (!parse_hex_byte(p, &hi) || !parse_hex_byte(p+2, &lo)) return 0; + *out = (uint16_t)((hi << 8) | lo); + return 1; +} diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..08f4ed8 --- /dev/null +++ b/src/util.h @@ -0,0 +1,13 @@ +/* util.h — small helpers */ + +#ifndef MIMIC09_UTIL_H +#define MIMIC09_UTIL_H + +#include +#include + +int hexval(char c); +int parse_hex_byte(const char *p, uint8_t *out); +int parse_hex_word(const char *p, uint16_t *out); + +#endif