|
Rocket 68
A Motorola 68000 CPU emulator in C
|
Core CPU state, memory access, execution, and exception handling. More...
Macros | |
| #define | AERR_INSTRUCTION_NO 0x08u |
| #define | AERR_MODE_READ 0x10u |
| #define | M68K_STATE_VERSION 1u |
Enumerations | |
| enum | { MEMORY_CALLBACK_IDLE , MEMORY_CALLBACK_ACTIVE , MEMORY_CALLBACK_FAILED } |
| enum | { M68K_TAG_DREGS = 1 , M68K_TAG_AREGS = 2 , M68K_TAG_PC = 3 , M68K_TAG_SR = 4 , M68K_TAG_USP = 5 , M68K_TAG_SSP = 6 , M68K_TAG_VBR = 7 , M68K_TAG_SFC = 8 , M68K_TAG_DFC = 9 , M68K_TAG_FLAGS = 10 , M68K_TAG_DECODE = 11 , M68K_TAG_CYCLES = 12 , M68K_TAG_MODEL = 13 } |
Functions | |
| void | m68k_init (M68kCpu *cpu, u8 *memory, u32 memory_size) |
| Initialize a CPU context and bind memory. | |
| void | m68k_reset (M68kCpu *cpu) |
| Reset CPU state and load initial vectors from memory. | |
| void | m68k_set_pc (M68kCpu *cpu, u32 pc) |
| Set the program counter. | |
| u32 | m68k_get_pc (M68kCpu *cpu) |
| Get the current program counter. | |
| void | m68k_set_model (M68kCpu *cpu, M68kModel model) |
| Select the CPU model profile. | |
| M68kModel | m68k_get_model (M68kCpu *cpu) |
| Read the selected CPU model profile. | |
| void | m68k_set_dr (M68kCpu *cpu, int reg, u32 value) |
| Set data register value. | |
| u32 | m68k_get_dr (M68kCpu *cpu, int reg) |
| Get data register value. | |
| void | m68k_set_ar (M68kCpu *cpu, int reg, u32 value) |
| Set address register value. | |
| u32 | m68k_get_ar (M68kCpu *cpu, int reg) |
| Get address register value. | |
| void | m68k_set_wait_bus_callback (M68kCpu *cpu, M68kWaitBusCallback callback) |
| Install wait bus callback. | |
| void | m68k_set_int_ack_callback (M68kCpu *cpu, M68kIntAckCallback callback) |
| Install interrupt acknowledge callback. | |
| void | m68k_set_fc_callback (M68kCpu *cpu, M68kFcCallback callback) |
| Install function code callback. | |
| void | m68k_set_instr_hook_callback (M68kCpu *cpu, M68kInstrHookCallback callback) |
| Install instruction hook callback. | |
| void | m68k_set_pc_changed_callback (M68kCpu *cpu, M68kPcChangedCallback callback) |
| Install PC-changed callback. | |
| void | m68k_set_reset_callback (M68kCpu *cpu, M68kResetCallback callback) |
| Install reset callback. | |
| void | m68k_set_tas_callback (M68kCpu *cpu, M68kTasCallback callback) |
| Install TAS callback. | |
| void | m68k_set_illg_callback (M68kCpu *cpu, M68kIllgCallback callback) |
| Install illegal opcode callback. | |
| void | m68k_set_read8_callback (M68kCpu *cpu, M68kRead8Callback callback) |
| Install host memory read callback (8-bit). | |
| void | m68k_set_read16_callback (M68kCpu *cpu, M68kRead16Callback callback) |
| Install host memory read callback (16-bit). | |
| void | m68k_set_read32_callback (M68kCpu *cpu, M68kRead32Callback callback) |
| Install host memory read callback (32-bit). | |
| void | m68k_set_write8_callback (M68kCpu *cpu, M68kWrite8Callback callback) |
| Install host memory write callback (8-bit). | |
| void | m68k_set_write16_callback (M68kCpu *cpu, M68kWrite16Callback callback) |
| Install host memory write callback (16-bit). | |
| void | m68k_set_write32_callback (M68kCpu *cpu, M68kWrite32Callback callback) |
| Install host memory write callback (32-bit). | |
| void | m68k_raise_illegal_ea (M68kCpu *cpu) |
| void | m68k_raise_odd_target_fault (M68kCpu *cpu, u32 target, u32 fault_pc) |
| bool | m68k_is_unmapped_target (M68kCpu *cpu, u32 target) |
| void | m68k_raise_bus_target_fault (M68kCpu *cpu, u32 target, u32 fault_pc) |
| void | m68k_raise_bus_error (M68kCpu *cpu) |
| Report a bus error from the current host memory callback. | |
| u8 | m68k_read_8 (M68kCpu *cpu, u32 address) |
| Read one byte from emulated memory. | |
| u16 | m68k_read_16 (M68kCpu *cpu, u32 address) |
| Read one word from emulated memory. | |
| u32 | m68k_read_32 (M68kCpu *cpu, u32 address) |
| Read one longword from emulated memory. | |
| void | m68k_write_8 (M68kCpu *cpu, u32 address, u8 value) |
| Write one byte to emulated memory. | |
| void | m68k_write_16 (M68kCpu *cpu, u32 address, u16 value) |
| Write one word to emulated memory. | |
| void | m68k_write_32 (M68kCpu *cpu, u32 address, u32 value) |
| Write one longword to emulated memory. | |
| u16 | m68k_fetch (M68kCpu *cpu) |
| u32 | fetch_extension (M68kCpu *cpu) |
| u32 | m68k_read_size (M68kCpu *cpu, u32 address, M68kSize size) |
| void | m68k_write_size (M68kCpu *cpu, u32 address, u32 value, M68kSize size) |
| M68kEA | m68k_calc_ea (M68kCpu *cpu, int mode, int reg, M68kSize size) |
| M68kEA | m68k_calc_ea_addr (M68kCpu *cpu, int mode, int reg, M68kSize size) |
| int | m68k_control_ea_cycles (int mode, int reg, bool is_jmp) |
| M68kEA | m68k_calc_ea_ctl (M68kCpu *cpu, int mode, int reg, bool is_jmp) |
| M68kEA | m68k_calc_ea_addr_nocost (M68kCpu *cpu, int mode, int reg, M68kSize size) |
| int | m68k_movem_ea_cycles (int mode, int reg, bool mem_to_reg) |
| void | update_flags_add (M68kCpu *cpu, u32 src, u32 dest, u32 result, M68kSize size) |
| void | update_flags_sub (M68kCpu *cpu, u32 src, u32 dest, u32 result, M68kSize size) |
| void | update_flags_cmp (M68kCpu *cpu, u32 src, u32 dest, u32 result, M68kSize size) |
| void | update_flags_logic (M68kCpu *cpu, u32 result, M68kSize size) |
| void | m68k_push_32 (M68kCpu *cpu, u32 value) |
| u32 | m68k_pop_32 (M68kCpu *cpu) |
| void | m68k_push_16 (M68kCpu *cpu, u16 value) |
| u16 | m68k_pop_16 (M68kCpu *cpu) |
| void | m68k_set_sr (M68kCpu *cpu, u16 new_sr) |
| Set the status register. | |
| void | m68k_exception (M68kCpu *cpu, int vector) |
| void | m68k_set_irq (M68kCpu *cpu, int level) |
| Set the asserted interrupt level (the virtual IPL lines). | |
| void | m68k_step_ex (M68kCpu *cpu, bool check_exceptions) |
| Execute one instruction with optional interrupt and trace checks. | |
| void | m68k_step (M68kCpu *cpu) |
| Execute one instruction step. | |
| int | m68k_execute (M68kCpu *cpu, int cycles_requested) |
| Execute instructions for a cycle budget. | |
| int | m68k_cycles_run (M68kCpu *cpu) |
| Get cycles consumed in the active timeslice accounting model. | |
| int | m68k_cycles_remaining (M68kCpu *cpu) |
| Get remaining cycles in the current timeslice. | |
| void | m68k_modify_timeslice (M68kCpu *cpu, int cycles) |
| Add cycles to current timeslice. | |
| void | m68k_end_timeslice (M68kCpu *cpu) |
| End current timeslice immediately. | |
| unsigned int | m68k_context_size (void) |
| Get serialized context size. | |
| void | m68k_get_context (M68kCpu *cpu, void *dst) |
| Copy CPU context into an external buffer. | |
| void | m68k_set_context (M68kCpu *cpu, const void *src) |
| Restore CPU context from an external buffer. | |
| size_t | m68k_serialize (const M68kCpu *cpu, u8 *buffer, size_t capacity) |
| Serialize architectural CPU state into a portable save state. | |
| bool | m68k_deserialize (M68kCpu *cpu, const u8 *buffer, size_t length) |
| Restore architectural CPU state from a portable save state. | |
Core CPU state, memory access, execution, and exception handling.
| #define AERR_INSTRUCTION_NO 0x08u |
| #define AERR_MODE_READ 0x10u |
| #define M68K_STATE_VERSION 1u |
| anonymous enum |
| unsigned int m68k_context_size | ( | void | ) |
Get serialized context size.
| int m68k_control_ea_cycles | ( | int | mode, |
| int | reg, | ||
| bool | is_jmp ) |
| int m68k_cycles_remaining | ( | M68kCpu * | cpu | ) |
Get remaining cycles in the current timeslice.
| cpu | CPU context. |
| int m68k_cycles_run | ( | M68kCpu * | cpu | ) |
Get cycles consumed in the active timeslice accounting model.
| cpu | CPU context. |
Restore architectural CPU state from a portable save state.
| cpu | CPU context; its memory binding and callbacks are kept. |
| buffer | Serialized state produced by m68k_serialize. |
| length | Length of the serialized state in bytes. |
Fields with unknown tags are skipped, so states written by newer library versions restore their known fields.
| void m68k_end_timeslice | ( | M68kCpu * | cpu | ) |
End current timeslice immediately.
| cpu | CPU context. |
| void m68k_exception | ( | M68kCpu * | cpu, |
| int | vector ) |
| int m68k_execute | ( | M68kCpu * | cpu, |
| int | cycles ) |
Execute instructions for a cycle budget.
| cpu | CPU context. |
| cycles | Requested number of cycles to add to the current timeslice. |
Get address register value.
| cpu | CPU context. |
| reg | Address register index [0,7]. |
| void m68k_get_context | ( | M68kCpu * | cpu, |
| void * | dst ) |
Copy CPU context into an external buffer.
Memory pointer and size are copied as part of the context payload.
| cpu | CPU context. |
| dst | Destination buffer with at least m68k_context_size bytes. |
Get data register value.
| cpu | CPU context. |
| reg | Data register index [0,7]. |
Read the selected CPU model profile.
| cpu | CPU context. |
Get the current program counter.
| cpu | CPU context. |
Initialize a CPU context and bind memory.
| cpu | CPU context to initialize. |
| memory | Pointer to emulated memory. |
| memory_size | Size of memory in bytes. |
| void m68k_modify_timeslice | ( | M68kCpu * | cpu, |
| int | cycles ) |
Add cycles to current timeslice.
| cpu | CPU context. |
| cycles | Number of cycles to add. |
| int m68k_movem_ea_cycles | ( | int | mode, |
| int | reg, | ||
| bool | mem_to_reg ) |
| void m68k_raise_bus_error | ( | M68kCpu * | cpu | ) |
Report a bus error from the current host memory callback.
| cpu | CPU context supplied to the callback. |
Return immediately after this call (read callbacks may return any value). The core processes vector 2 after the callback returns, using the current access address and direction. This function does not unwind the callback. Calls outside a CPU memory access, including disassembly and internal peeks, have no effect. Callbacks must not reenter execution or memory access helpers on the same CPU. Earlier bus side effects are not rolled back.
| void m68k_raise_illegal_ea | ( | M68kCpu * | cpu | ) |
Read one word from emulated memory.
| cpu | CPU context. |
| address | Emulated address. |
Read one longword from emulated memory.
| cpu | CPU context. |
| address | Emulated address. |
Read one byte from emulated memory.
| cpu | CPU context. |
| address | Emulated address. |
| void m68k_reset | ( | M68kCpu * | cpu | ) |
Reset CPU state and load initial vectors from memory.
| cpu | CPU context. |
Serialize architectural CPU state into a portable save state.
| cpu | CPU context. |
| buffer | Output buffer, or NULL to query the required size. |
| capacity | Size of the output buffer in bytes. |
The format is versioned, tagged, and big-endian, so it is stable across builds, compilers, and host architectures, unlike the raw m68k_get_context blob. Host bindings (memory, callbacks) and transient fault latches are not serialized. Serializing in the middle of exception processing is not supported.
Set address register value.
| cpu | CPU context. |
| reg | Address register index [0,7]. |
| value | New 32-bit value. |
| void m68k_set_context | ( | M68kCpu * | cpu, |
| const void * | src ) |
Restore CPU context from an external buffer.
The bound memory pointer and memory size from the destination context are preserved.
| cpu | CPU context. |
| src | Source buffer with at least m68k_context_size bytes. |
Set data register value.
| cpu | CPU context. |
| reg | Data register index [0,7]. |
| value | New 32-bit value. |
| void m68k_set_fc_callback | ( | M68kCpu * | cpu, |
| M68kFcCallback | callback ) |
Install function code callback.
| cpu | CPU context. |
| callback | Callback function pointer or NULL. |
The callback is invoked before memory/program accesses with the active function code.
| void m68k_set_illg_callback | ( | M68kCpu * | cpu, |
| M68kIllgCallback | callback ) |
Install illegal opcode callback.
| cpu | CPU context. |
| callback | Callback function pointer or NULL. |
| void m68k_set_instr_hook_callback | ( | M68kCpu * | cpu, |
| M68kInstrHookCallback | callback ) |
Install instruction hook callback.
| cpu | CPU context. |
| callback | Callback function pointer or NULL. |
| void m68k_set_int_ack_callback | ( | M68kCpu * | cpu, |
| M68kIntAckCallback | callback ) |
Install interrupt acknowledge callback.
| cpu | CPU context. |
| callback | Callback function pointer or NULL. |
| void m68k_set_irq | ( | M68kCpu * | cpu, |
| int | level ) |
Set the asserted interrupt level (the virtual IPL lines).
Levels 1-6 are level-sensitive. Without an INT ACK callback the request clears automatically when serviced; with a callback installed the level stays asserted until the host calls this function with 0 (or a new level). Level 7 is edge-sensitive: each transition to 7 latches one non-maskable interrupt.
| cpu | CPU context. |
| level | Interrupt level in range [0,7]. |
Select the CPU model profile.
| cpu | CPU context. |
| model | Model profile; the default after m68k_init is the 68000. |
On the 68000 profile the later-family instructions MOVEC, MOVES, RTD, and BKPT raise illegal-instruction exceptions, matching real hardware.
Set the program counter.
| cpu | CPU context. |
| pc | New program counter value. |
| void m68k_set_pc_changed_callback | ( | M68kCpu * | cpu, |
| M68kPcChangedCallback | callback ) |
Install PC-changed callback.
| cpu | CPU context. |
| callback | Callback function pointer or NULL. |
| void m68k_set_read16_callback | ( | M68kCpu * | cpu, |
| M68kRead16Callback | callback ) |
Install host memory read callback (16-bit).
| cpu | CPU context. |
| callback | Callback function pointer or NULL. |
| void m68k_set_read32_callback | ( | M68kCpu * | cpu, |
| M68kRead32Callback | callback ) |
Install host memory read callback (32-bit).
| cpu | CPU context. |
| callback | Callback function pointer or NULL. |
| void m68k_set_read8_callback | ( | M68kCpu * | cpu, |
| M68kRead8Callback | callback ) |
Install host memory read callback (8-bit).
| cpu | CPU context. |
| callback | Callback function pointer or NULL. |
| void m68k_set_reset_callback | ( | M68kCpu * | cpu, |
| M68kResetCallback | callback ) |
Install reset callback.
| cpu | CPU context. |
| callback | Callback function pointer or NULL. |
Set the status register.
| cpu | CPU context. |
| new_sr | New status register value. |
| void m68k_set_tas_callback | ( | M68kCpu * | cpu, |
| M68kTasCallback | callback ) |
Install TAS callback.
| cpu | CPU context. |
| callback | Callback function pointer or NULL. |
| void m68k_set_wait_bus_callback | ( | M68kCpu * | cpu, |
| M68kWaitBusCallback | callback ) |
Install wait bus callback.
| cpu | CPU context. |
| callback | Callback function pointer or NULL. |
| void m68k_set_write16_callback | ( | M68kCpu * | cpu, |
| M68kWrite16Callback | callback ) |
Install host memory write callback (16-bit).
| cpu | CPU context. |
| callback | Callback function pointer or NULL. |
| void m68k_set_write32_callback | ( | M68kCpu * | cpu, |
| M68kWrite32Callback | callback ) |
Install host memory write callback (32-bit).
| cpu | CPU context. |
| callback | Callback function pointer or NULL. |
| void m68k_set_write8_callback | ( | M68kCpu * | cpu, |
| M68kWrite8Callback | callback ) |
Install host memory write callback (8-bit).
| cpu | CPU context. |
| callback | Callback function pointer or NULL. |
| void m68k_step | ( | M68kCpu * | cpu | ) |
Execute one instruction step.
| cpu | CPU context. |
| void m68k_step_ex | ( | M68kCpu * | cpu, |
| bool | check_exceptions ) |
Execute one instruction with optional interrupt and trace checks.
| cpu | CPU context. |
| check_exceptions | If true, check interrupts and deliver trace exceptions. Instruction-generated exceptions are processed regardless of this flag. |
Write one word to emulated memory.
| cpu | CPU context. |
| address | Emulated address. |
| value | Value to write. |
Write one longword to emulated memory.
| cpu | CPU context. |
| address | Emulated address. |
| value | Value to write. |
Write one byte to emulated memory.
| cpu | CPU context. |
| address | Emulated address. |
| value | Value to write. |