unsigned int m68k_get_reg(void* context, m68k_register_t reg);
/* Poke values into the internals of the currently running CPU context */
-void m68k_set_reg(m68k_register_t reg, unsigned int value);
+void m68k_set_reg(void *context, m68k_register_t regnum, unsigned int value);
/* Check if an instruction is valid for the specified CPU type */
unsigned int m68k_is_valid_instruction(unsigned int instruction, unsigned int cpu_type);
M68KMAKE_OP(andi, 16, toc, .)
{
- m68ki_set_ccr(m68ki_get_ccr() & OPER_I_8(state));
+ m68ki_set_ccr(state, m68ki_get_ccr(state) & OPER_I_8(state));
}
if(M68KMAKE_CC)
{
m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
- m68ki_branch_8(MASK_OUT_ABOVE_8(REG_IR));
+ m68ki_branch_8(state, MASK_OUT_ABOVE_8(REG_IR));
return;
}
USE_CYCLES(CYC_BCC_NOTAKE_B);
uint offset = OPER_I_16(state);
REG_PC -= 2;
m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
- m68ki_branch_16(offset);
+ m68ki_branch_16(state, offset);
return;
}
REG_PC += 2;
uint offset = OPER_I_32(state);
REG_PC -= 4;
m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
- m68ki_branch_32(offset);
+ m68ki_branch_32(state, offset);
return;
}
REG_PC += 4;
if(M68KMAKE_CC)
{
m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
- m68ki_branch_8(MASK_OUT_ABOVE_8(REG_IR));
+ m68ki_branch_8(state, MASK_OUT_ABOVE_8(REG_IR));
return;
}
USE_CYCLES(CYC_BCC_NOTAKE_B);
M68KMAKE_OP(bra, 8, ., .)
{
m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
- m68ki_branch_8(MASK_OUT_ABOVE_8(REG_IR));
+ m68ki_branch_8(state, MASK_OUT_ABOVE_8(REG_IR));
// TODO: review this...
// if(REG_PC == REG_PPC)
// USE_ALL_CYCLES();
uint offset = OPER_I_16(state);
REG_PC -= 2;
m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
- m68ki_branch_16(offset);
+ m68ki_branch_16(state, offset);
// TODO: review this...
// if(REG_PC == REG_PPC)
// USE_ALL_CYCLES();
uint offset = OPER_I_32(state);
REG_PC -= 4;
m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
- m68ki_branch_32(offset);
+ m68ki_branch_32(state, offset);
// TODO: review this...
// if(REG_PC == REG_PPC)
// USE_ALL_CYCLES();
// TODO: review this...
m68ki_exception_illegal(state);
// m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
-// m68ki_branch_8(MASK_OUT_ABOVE_8(REG_IR));
+// m68ki_branch_8(state, MASK_OUT_ABOVE_8(REG_IR));
// if(REG_PC == REG_PPC)
// USE_ALL_CYCLES();
}
{
m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
m68ki_push_32(state, REG_PC);
- m68ki_branch_8(MASK_OUT_ABOVE_8(REG_IR));
+ m68ki_branch_8(state, MASK_OUT_ABOVE_8(REG_IR));
}
m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
m68ki_push_32(state, REG_PC);
REG_PC -= 2;
- m68ki_branch_16(offset);
+ m68ki_branch_16(state, offset);
}
m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
m68ki_push_32(state, REG_PC);
REG_PC -= 4;
- m68ki_branch_32(offset);
+ m68ki_branch_32(state, offset);
return;
}
else
m68ki_exception_illegal(state);
// m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
// m68ki_push_32(state, REG_PC);
-// m68ki_branch_8(MASK_OUT_ABOVE_8(REG_IR));
+// m68ki_branch_8(state, MASK_OUT_ABOVE_8(REG_IR));
}
}
uint offset = OPER_I_16(state);
REG_PC -= 2;
m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
- m68ki_branch_16(offset);
+ m68ki_branch_16(state, offset);
USE_CYCLES(CYC_DBCC_F_NOEXP);
return;
}
uint offset = OPER_I_16(state);
REG_PC -= 2;
m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
- m68ki_branch_16(offset);
+ m68ki_branch_16(state, offset);
USE_CYCLES(CYC_DBCC_F_NOEXP);
return;
}
M68KMAKE_OP(eori, 16, toc, .)
{
- m68ki_set_ccr(m68ki_get_ccr() ^ OPER_I_8(state));
+ m68ki_set_ccr(state, m68ki_get_ccr(state) ^ OPER_I_8(state));
}
M68KMAKE_OP(jmp, 32, ., .)
{
- m68ki_jump(M68KMAKE_GET_EA_AY_32);
+ m68ki_jump(state, M68KMAKE_GET_EA_AY_32);
m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
}
uint ea = M68KMAKE_GET_EA_AY_32;
m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
m68ki_push_32(state, REG_PC);
- m68ki_jump(ea);
+ m68ki_jump(state, ea);
}
{
if(CPU_TYPE_IS_010_PLUS(CPU_TYPE))
{
- DY = MASK_OUT_BELOW_16(DY) | m68ki_get_ccr();
+ DY = MASK_OUT_BELOW_16(DY) | m68ki_get_ccr(state);
return;
}
m68ki_exception_illegal(state);
{
if(CPU_TYPE_IS_010_PLUS(CPU_TYPE))
{
- m68ki_write_16(state, M68KMAKE_GET_EA_AY_16, m68ki_get_ccr());
+ m68ki_write_16(state, M68KMAKE_GET_EA_AY_16, m68ki_get_ccr(state));
return;
}
m68ki_exception_illegal(state);
M68KMAKE_OP(move, 16, toc, d)
{
- m68ki_set_ccr(DY);
+ m68ki_set_ccr(state, DY);
}
M68KMAKE_OP(move, 16, toc, .)
{
- m68ki_set_ccr(M68KMAKE_GET_OPER_AY_16);
+ m68ki_set_ccr(state, M68KMAKE_GET_OPER_AY_16);
}
M68KMAKE_OP(ori, 16, toc, .)
{
- m68ki_set_ccr(m68ki_get_ccr() | OPER_I_8(state));
+ m68ki_set_ccr(state, m68ki_get_ccr(state) | OPER_I_8(state));
}
m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
REG_A[7] = MASK_OUT_ABOVE_32(REG_A[7] + MAKE_INT_16(OPER_I_16(state)));
- m68ki_jump(new_pc);
+ m68ki_jump(state, new_pc);
return;
}
m68ki_exception_illegal(state);
{
new_sr = m68ki_pull_16(state);
new_pc = m68ki_pull_32(state);
- m68ki_jump(new_pc);
+ m68ki_jump(state, new_pc);
m68ki_set_sr(state, new_sr);
CPU_INSTR_MODE = INSTRUCTION_YES;
new_sr = m68ki_pull_16(state);
new_pc = m68ki_pull_32(state);
m68ki_fake_pull_16(state); /* format word */
- m68ki_jump(new_pc);
+ m68ki_jump(state, new_pc);
m68ki_set_sr(state, new_sr);
CPU_INSTR_MODE = INSTRUCTION_YES;
CPU_RUN_MODE = RUN_MODE_NORMAL;
new_sr = m68ki_pull_16(state);
new_pc = m68ki_pull_32(state);
m68ki_fake_pull_16(state); /* format word */
- m68ki_jump(new_pc);
+ m68ki_jump(state, new_pc);
m68ki_set_sr(state, new_sr);
CPU_INSTR_MODE = INSTRUCTION_YES;
CPU_RUN_MODE = RUN_MODE_NORMAL;
new_sr = m68ki_pull_16(state);
new_pc = m68ki_pull_32(state);
m68ki_fake_pull_16(state); /* format word */
- m68ki_jump(new_pc);
+ m68ki_jump(state, new_pc);
m68ki_set_sr(state, new_sr);
CPU_INSTR_MODE = INSTRUCTION_YES;
CPU_RUN_MODE = RUN_MODE_NORMAL;
new_pc = m68ki_pull_32(state);
m68ki_fake_pull_16(state); /* format word */
m68ki_fake_pull_32(state); /* address */
- m68ki_jump(new_pc);
+ m68ki_jump(state, new_pc);
m68ki_set_sr(state, new_sr);
CPU_INSTR_MODE = INSTRUCTION_YES;
CPU_RUN_MODE = RUN_MODE_NORMAL;
m68ki_fake_pull_32(state); /* $30: pd1 */
m68ki_fake_pull_32(state); /* $34: pd2 */
m68ki_fake_pull_32(state); /* $38: pd3 */
- m68ki_jump(new_pc);
+ m68ki_jump(state, new_pc);
m68ki_set_sr(state, new_sr);
CPU_INSTR_MODE = INSTRUCTION_YES;
CPU_RUN_MODE = RUN_MODE_NORMAL;
m68ki_fake_pull_32(state); /* $18: data output buffer */
m68ki_fake_pull_32(state); /* $1c: internal registers */
- m68ki_jump(new_pc);
+ m68ki_jump(state, new_pc);
m68ki_set_sr(state, new_sr);
CPU_INSTR_MODE = INSTRUCTION_YES;
CPU_RUN_MODE = RUN_MODE_NORMAL;
m68ki_fake_pull_32(state); /* $54: */
m68ki_fake_pull_32(state); /* $58: */
- m68ki_jump(new_pc);
+ m68ki_jump(state, new_pc);
m68ki_set_sr(state, new_sr);
CPU_INSTR_MODE = INSTRUCTION_YES;
CPU_RUN_MODE = RUN_MODE_NORMAL;
M68KMAKE_OP(rtr, 32, ., .)
{
m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
- m68ki_set_ccr(m68ki_pull_16(state));
- m68ki_jump(m68ki_pull_32(state));
+ m68ki_set_ccr(state, m68ki_pull_16(state));
+ m68ki_jump(state, m68ki_pull_32(state));
}
M68KMAKE_OP(rts, 32, ., .)
{
m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
- m68ki_jump(m68ki_pull_32(state));
+ m68ki_jump(state, m68ki_pull_32(state));
}
return 0;
}
-void m68k_set_reg(m68k_register_t regnum, unsigned int value)
+void m68k_set_reg(void *context, m68k_register_t regnum, unsigned int value)
{
+ m68ki_cpu_core* state = context != NULL ?(m68ki_cpu_core*)context : &m68ki_cpu;
switch(regnum)
{
case M68K_REG_D0: REG_D[0] = MASK_OUT_ABOVE_32(value); return;
case M68K_REG_A5: REG_A[5] = MASK_OUT_ABOVE_32(value); return;
case M68K_REG_A6: REG_A[6] = MASK_OUT_ABOVE_32(value); return;
case M68K_REG_A7: REG_A[7] = MASK_OUT_ABOVE_32(value); return;
- case M68K_REG_PC: m68ki_jump(MASK_OUT_ABOVE_32(value)); return;
- case M68K_REG_SR: m68ki_set_sr_noint_nosp(value); return;
+ case M68K_REG_PC:
+ m68ki_jump(state, MASK_OUT_ABOVE_32(value)); return;
+ case M68K_REG_SR:
+ m68ki_set_sr_noint_nosp(state, value); return;
case M68K_REG_SP: REG_SP = MASK_OUT_ABOVE_32(value); return;
case M68K_REG_USP: if(FLAG_S)
REG_USP = MASK_OUT_ABOVE_32(value);
/* Reset VBR */
REG_VBR = 0;
/* Go to supervisor mode */
- m68ki_set_sm_flag(SFLAG_SET | MFLAG_CLEAR);
+ m68ki_set_sm_flag(state, SFLAG_SET | MFLAG_CLEAR);
/* Invalidate the prefetch queue */
#if M68K_EMULATE_PREFETCH
#endif /* M68K_EMULATE_PREFETCH */
/* Read the initial stack pointer and program counter */
- m68ki_jump(0);
+ m68ki_jump(state, 0);
REG_SP = m68ki_read_imm_32(state);
REG_PC = m68ki_read_imm_32(state);
- m68ki_jump(REG_PC);
+ m68ki_jump(state, REG_PC);
CPU_RUN_MODE = RUN_MODE_NORMAL;
/* Get the condition code register */
-#define m68ki_get_ccr() ((COND_XS() >> 4) | \
- (COND_MI() >> 4) | \
- (COND_EQ() << 2) | \
- (COND_VS() >> 6) | \
- (COND_CS() >> 8))
+#define m68ki_get_ccr(state) ((COND_XS() >> 4) | \
+ (COND_MI() >> 4) | \
+ (COND_EQ() << 2) | \
+ (COND_VS() >> 6) | \
+ (COND_CS() >> 8))
/* Get the status register */
-#define m68ki_get_sr() ( FLAG_T1 | \
- FLAG_T0 | \
- (FLAG_S << 11) | \
- (FLAG_M << 11) | \
- FLAG_INT_MASK | \
- m68ki_get_ccr())
+#define m68ki_get_sr(state) ( FLAG_T1 | \
+ FLAG_T0 | \
+ (FLAG_S << 11) | \
+ (FLAG_M << 11) | \
+ FLAG_INT_MASK | \
+ m68ki_get_ccr(state))
* These functions will also call the pc_changed callback if it was enabled
* in m68kconf.h.
*/
-static inline void m68ki_jump(uint new_pc)
+static inline void m68ki_jump(m68ki_cpu_core *state, uint new_pc)
{
REG_PC = new_pc;
m68ki_pc_changed(REG_PC);
* So far I've found no problems with not calling pc_changed for 8 or 16
* bit branches.
*/
-static inline void m68ki_branch_8(uint offset)
+static inline void m68ki_branch_8(m68ki_cpu_core *state, uint offset)
{
REG_PC += MAKE_INT_8(offset);
}
-static inline void m68ki_branch_16(uint offset)
+static inline void m68ki_branch_16(m68ki_cpu_core *state, uint offset)
{
REG_PC += MAKE_INT_16(offset);
}
-static inline void m68ki_branch_32(uint offset)
+static inline void m68ki_branch_32(m68ki_cpu_core *state, uint offset)
{
REG_PC += offset;
m68ki_pc_changed(REG_PC);
/* Set the S flag and change the active stack pointer.
* Note that value MUST be 4 or 0.
*/
-static inline void m68ki_set_s_flag(uint value)
+static inline void m68ki_set_s_flag(m68ki_cpu_core *state, uint value)
{
/* Backup the old stack pointer */
REG_SP_BASE[FLAG_S | ((FLAG_S>>1) & FLAG_M)] = REG_SP;
/* Set the S and M flags and change the active stack pointer.
* Note that value MUST be 0, 2, 4, or 6 (bit2 = S, bit1 = M).
*/
-static inline void m68ki_set_sm_flag(uint value)
+static inline void m68ki_set_sm_flag(m68ki_cpu_core *state, uint value)
{
/* Backup the old stack pointer */
REG_SP_BASE[FLAG_S | ((FLAG_S>>1) & FLAG_M)] = REG_SP;
}
/* Set the S and M flags. Don't touch the stack pointer. */
-static inline void m68ki_set_sm_flag_nosp(uint value)
+static inline void m68ki_set_sm_flag_nosp(m68ki_cpu_core *state, uint value)
{
/* Set the S and M flags */
FLAG_S = value & SFLAG_SET;
/* Set the condition code register */
-static inline void m68ki_set_ccr(uint value)
+static inline void m68ki_set_ccr(m68ki_cpu_core *state, uint value)
{
FLAG_X = BIT_4(value) << 4;
FLAG_N = BIT_3(value) << 4;
FLAG_T1 = BIT_F(value);
FLAG_T0 = BIT_E(value);
FLAG_INT_MASK = value & 0x0700;
- m68ki_set_ccr(value);
- m68ki_set_sm_flag((value >> 11) & 6);
+ m68ki_set_ccr(state, value);
+ m68ki_set_sm_flag(state, (value >> 11) & 6);
}
/* Set the status register but don't check for interrupts nor
* change the stack pointer
*/
-static inline void m68ki_set_sr_noint_nosp(uint value)
+static inline void m68ki_set_sr_noint_nosp(m68ki_cpu_core *state, uint value)
{
/* Mask out the "unimplemented" bits */
value &= CPU_SR_MASK;
FLAG_T1 = BIT_F(value);
FLAG_T0 = BIT_E(value);
FLAG_INT_MASK = value & 0x0700;
- m68ki_set_ccr(value);
- m68ki_set_sm_flag_nosp((value >> 11) & 6);
+ m68ki_set_ccr(state, value);
+ m68ki_set_sm_flag_nosp(state, (value >> 11) & 6);
}
/* Set the status register and check for interrupts */
/* ------------------------- Exception Processing ------------------------- */
/* Initiate exception processing */
-static inline uint m68ki_init_exception(void)
+static inline uint m68ki_init_exception(m68ki_cpu_core *state)
{
/* Save the old status register */
uint sr = m68ki_get_sr();
FLAG_T1 = FLAG_T0 = 0;
m68ki_clear_trace();
/* Enter supervisor mode */
- m68ki_set_s_flag(SFLAG_SET);
+ m68ki_set_s_flag(state, SFLAG_SET);
return sr;
}
*/
static inline void m68ki_exception_trap(m68ki_cpu_core *state, uint vector)
{
- uint sr = m68ki_init_exception();
+ uint sr = m68ki_init_exception(state);
if(CPU_TYPE_IS_010_LESS(CPU_TYPE))
m68ki_stack_frame_0000(state, REG_PC, sr, vector);
/* Trap#n stacks a 0 frame but behaves like group2 otherwise */
static inline void m68ki_exception_trapN(m68ki_cpu_core *state, uint vector)
{
- uint sr = m68ki_init_exception();
+ uint sr = m68ki_init_exception(state);
m68ki_stack_frame_0000(state, REG_PC, sr, vector);
m68ki_jump_vector(state, vector);
/* Exception for trace mode */
static inline void m68ki_exception_trace(m68ki_cpu_core *state)
{
- uint sr = m68ki_init_exception();
+ uint sr = m68ki_init_exception(state);
if(CPU_TYPE_IS_010_LESS(CPU_TYPE))
{
/* Exception for privilege violation */
static inline void m68ki_exception_privilege_violation(m68ki_cpu_core *state)
{
- uint sr = m68ki_init_exception();
+ uint sr = m68ki_init_exception(state);
#if M68K_EMULATE_ADDRESS_ERROR == OPT_ON
if(CPU_TYPE_IS_000(CPU_TYPE))
REG_DA[i] = REG_DA_SAVE[i];
}
- uint sr = m68ki_init_exception();
+ uint sr = m68ki_init_exception(state);
m68ki_stack_frame_1000(state, REG_PPC, sr, EXCEPTION_BUS_ERROR);
m68ki_jump_vector(state, EXCEPTION_BUS_ERROR);
m68ki_disassemble_quick(ADDRESS_68K(REG_PPC),CPU_TYPE)));
#endif
- sr = m68ki_init_exception();
+ sr = m68ki_init_exception(state);
m68ki_stack_frame_0000(state, REG_PPC, sr, EXCEPTION_1010);
m68ki_jump_vector(state, EXCEPTION_1010);
m68ki_disassemble_quick(ADDRESS_68K(REG_PPC),CPU_TYPE)));
#endif
- sr = m68ki_init_exception();
+ sr = m68ki_init_exception(state);
m68ki_stack_frame_0000(state, REG_PPC, sr, EXCEPTION_1111);
m68ki_jump_vector(state, EXCEPTION_1111);
if (m68ki_illg_callback(REG_IR))
return;
- sr = m68ki_init_exception();
+ sr = m68ki_init_exception(state);
#if M68K_EMULATE_ADDRESS_ERROR == OPT_ON
if(CPU_TYPE_IS_000(CPU_TYPE))
/* Exception for format errror in RTE */
static inline void m68ki_exception_format_error(m68ki_cpu_core *state)
{
- uint sr = m68ki_init_exception();
+ uint sr = m68ki_init_exception(state);
m68ki_stack_frame_0000(state, REG_PC, sr, EXCEPTION_FORMAT_ERROR);
m68ki_jump_vector(state, EXCEPTION_FORMAT_ERROR);
/* Exception for address error */
static inline void m68ki_exception_address_error(m68ki_cpu_core *state)
{
- uint32 sr = m68ki_init_exception();
+ uint32 sr = m68ki_init_exception(state);
/* If we were processing a bus error, address error, or reset,
* this is a catastrophic failure.
}
/* Start exception processing */
- sr = m68ki_init_exception();
+ sr = m68ki_init_exception(state);
/* Set the interrupt mask to the level of the one being serviced */
FLAG_INT_MASK = int_level<<8;
if(FLAG_M && CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
{
/* Create throwaway frame */
- m68ki_set_sm_flag(FLAG_S); /* clear M */
+ m68ki_set_sm_flag(state, FLAG_S); /* clear M */
sr |= 0x2000; /* Same as SR in master stack frame except S is forced high */
m68ki_stack_frame_0001(state, REG_PC, sr, vector);
}
- m68ki_jump(new_pc);
+ m68ki_jump(state, new_pc);
/* Defer cycle counting until later */
USE_CYCLES(CYC_EXCEPTION[vector]);
if (TEST_CONDITION(state, condition))
{
m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
- m68ki_branch_16(offset-2);
+ m68ki_branch_16(state, offset - 2);
}
USE_CYCLES(7);
if (TEST_CONDITION(state, condition))
{
m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */
- m68ki_branch_32(offset-4);
+ m68ki_branch_32(state, offset - 4);
}
USE_CYCLES(7);