m68kemu/README.md
2026-04-12 17:08:20 +02:00

60 lines
1.7 KiB
Markdown

# m68kemu
A very minimalistic Motorola 68000 user-mode emulation written in Kotlin,
with the actual cpu core emulation being less than 750 lines of code.
It can be used to emulate short pieces of 68000 binary code.
I used it for validation of the [Raspberry Casket Pretracker replayer](https://git.platon42.de/chrisly42/PretrackerRaspberryCasket).
I had it lying around for so many years, I thought I could just publish
it and maybe someone finds it useful.
## Features
- Memory access abstraction
- User-mode only (no exceptions, interrupts, supervisor-instructions etc.)
- Instructions not implemented (might not be decoded correctly!):
- abcd, sbcd, nbcd
- movep, cmpm, addx/subx/tas on memory
- ori/andi/eori to CCR/SR, move from SR, move to CCR/SR, move USP
- illegal, trap, trapv, chk, stop, reset, rte, rtr
Note: Illegal (unavailable) addressing modes may not be detected as such.
No 68020+ instructions or addressing modes are supported.
## Usage
Create an instance of M68kCpu():
```kotlin
val cpu = M68kCpu()
```
Create some memory, custom chips, etc:
```kotlin
val ram = Ram(0x0, 0x10000)
val rom = Rom(0xfc0000, kickromimage)
val customChips = CustomChips()
ram.writeWord(0x100, 0x4e75) // just an rts
```
Configure your system, registers, program counter and run `decode()` for every instruction as long as you like:
```kotlin
with(cpu) {
memRegions.add(ram)
memRegions.add(rom)
memRegions.add(customChips)
a[7] = ram.start + ram.size // setup stack register
pushStack(OpSize.OS_LONG, 0) // write 0 return address
pc = 0x100 // start of program
while (pc != 0) {
decode()
}
}
```
The CustomChip classes are minimal stubs. There's also some Paula-Recorder class you might find useful.