]> git.sesse.net Git - pistorm/blobdiff - m68kcpu.c
introducing CPU state parameter 5 - now switched most register state over
[pistorm] / m68kcpu.c
index d933ecada3bf34f2df3816df04490d9fcf26dfa4..a85f75d40a1d09c48fb5297a5909c0478260e4fb 100644 (file)
--- a/m68kcpu.c
+++ b/m68kcpu.c
@@ -676,8 +676,9 @@ unsigned int m68k_get_reg(void* context, m68k_register_t regnum)
        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;
@@ -696,8 +697,10 @@ void m68k_set_reg(m68k_register_t regnum, unsigned int value)
                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);
@@ -721,7 +724,8 @@ void m68k_set_reg(m68k_register_t regnum, unsigned int value)
                case M68K_REG_CAAR:     REG_CAAR = MASK_OUT_ABOVE_32(value); return;
                case M68K_REG_PPC:      REG_PPC = MASK_OUT_ABOVE_32(value); return;
                case M68K_REG_IR:       REG_IR = MASK_OUT_ABOVE_16(value); return;
-               case M68K_REG_CPU_TYPE: m68k_set_cpu_type(value); return;
+               case M68K_REG_CPU_TYPE:
+                       m68k_set_cpu_type(state, value); return;
                default:                        return;
        }
 }
@@ -778,7 +782,7 @@ void m68k_set_instr_hook_callback(void  (*callback)(unsigned int pc))
 }
 
 /* Set the CPU type. */
-void m68k_set_cpu_type(unsigned int cpu_type)
+void m68k_set_cpu_type(struct m68ki_cpu_core *state, unsigned int cpu_type)
 {
        switch(cpu_type)
        {
@@ -801,7 +805,7 @@ void m68k_set_cpu_type(unsigned int cpu_type)
                        HAS_FPU          = 0;
                        return;
                case M68K_CPU_TYPE_SCC68070:
-                       m68k_set_cpu_type(M68K_CPU_TYPE_68010);
+                       m68k_set_cpu_type(state, M68K_CPU_TYPE_68010);
                        CPU_ADDRESS_MASK = 0xffffffff;
                        CPU_TYPE         = CPU_TYPE_SCC070;
                        return;
@@ -980,7 +984,7 @@ int m68k_execute(m68ki_cpu_core *state, int num_cycles)
        if(!CPU_STOPPED)
        {
                /* Return point if we had an address error */
-               m68ki_set_address_error_trap(); /* auto-disable (see m68kcpu.h) */
+               m68ki_set_address_error_trap(state); /* auto-disable (see m68kcpu.h) */
 
 #ifdef M68K_BUSERR_THING
                m68ki_check_bus_error_trap();
@@ -1115,9 +1119,9 @@ void m68k_init(void)
 }
 
 /* Trigger a Bus Error exception */
-void m68k_pulse_bus_error(void)
+void m68k_pulse_bus_error(m68ki_cpu_core *state)
 {
-       m68ki_exception_bus_error();
+       m68ki_exception_bus_error(state);
 }
 
 /* Pulse the RESET line on the CPU */
@@ -1148,7 +1152,7 @@ void m68k_pulse_reset(m68ki_cpu_core *state)
        /* 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
@@ -1157,10 +1161,10 @@ void m68k_pulse_reset(m68ki_cpu_core *state)
 #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;
 
@@ -1202,7 +1206,7 @@ void m68k_set_context(void* src)
 
 #if M68K_SEPARATE_READS
 /* Read data immediately following the PC */
-inline unsigned int  m68k_read_immediate_16(unsigned int address) {
+inline unsigned int m68k_read_immediate_16(m68ki_cpu_core *state, unsigned int address) {
 #if M68K_EMULATE_PREFETCH == OPT_ON
        for (int i = 0; i < m68ki_cpu.read_ranges; i++) {
                if(address >= m68ki_cpu.read_addr[i] && address < m68ki_cpu.read_upper[i]) {
@@ -1213,7 +1217,7 @@ inline unsigned int  m68k_read_immediate_16(unsigned int address) {
 
        return m68k_read_memory_16(address);
 }
-inline unsigned int  m68k_read_immediate_32(unsigned int address) {
+inline unsigned int m68k_read_immediate_32(m68ki_cpu_core *state, unsigned int address) {
 #if M68K_EMULATE_PREFETCH == OPT_ON
        for (int i = 0; i < m68ki_cpu.read_ranges; i++) {
                if(address >= m68ki_cpu.read_addr[i] && address < m68ki_cpu.read_upper[i]) {
@@ -1226,7 +1230,7 @@ inline unsigned int  m68k_read_immediate_32(unsigned int address) {
 }
 
 /* Read data relative to the PC */
-inline unsigned int  m68k_read_pcrelative_8(unsigned int address) {
+inline unsigned int m68k_read_pcrelative_8(m68ki_cpu_core *state, unsigned int address) {
        for (int i = 0; i < m68ki_cpu.read_ranges; i++) {
                if(address >= m68ki_cpu.read_addr[i] && address < m68ki_cpu.read_upper[i]) {
                        return m68ki_cpu.read_data[i][address - m68ki_cpu.read_addr[i]];
@@ -1235,7 +1239,7 @@ inline unsigned int  m68k_read_pcrelative_8(unsigned int address) {
 
        return m68k_read_memory_8(address);
 }
-inline unsigned int  m68k_read_pcrelative_16(unsigned int address) {
+inline unsigned int  m68k_read_pcrelative_16(m68ki_cpu_core *state, unsigned int address) {
        for (int i = 0; i < m68ki_cpu.read_ranges; i++) {
                if(address >= m68ki_cpu.read_addr[i] && address < m68ki_cpu.read_upper[i]) {
                        return be16toh(((unsigned short *)(m68ki_cpu.read_data[i] + (address - m68ki_cpu.read_addr[i])))[0]);
@@ -1244,7 +1248,7 @@ inline unsigned int  m68k_read_pcrelative_16(unsigned int address) {
 
        return m68k_read_memory_16(address);
 }
-inline unsigned int  m68k_read_pcrelative_32(unsigned int address) {
+inline unsigned int  m68k_read_pcrelative_32(m68ki_cpu_core *state, unsigned int address) {
        for (int i = 0; i < m68ki_cpu.read_ranges; i++) {
                if(address >= m68ki_cpu.read_addr[i] && address < m68ki_cpu.read_upper[i]) {
                        return be32toh(((unsigned int *)(m68ki_cpu.read_data[i] + (address - m68ki_cpu.read_addr[i])))[0]);
@@ -1256,7 +1260,7 @@ inline unsigned int  m68k_read_pcrelative_32(unsigned int address) {
 #endif
 
 
-uint m68ki_read_imm6_addr_slowpath(uint32_t pc, address_translation_cache *cache)
+uint m68ki_read_imm16_addr_slowpath(m68ki_cpu_core *state, uint32_t pc, address_translation_cache *cache)
 {
     uint32_t address = ADDRESS_68K(pc);
     uint32_t pc_address_diff = pc - address;
@@ -1274,21 +1278,21 @@ uint m68ki_read_imm6_addr_slowpath(uint32_t pc, address_translation_cache *cache
        m68ki_cpu.mmu_tmp_fc = FLAG_S | FUNCTION_CODE_USER_PROGRAM;
        m68ki_cpu.mmu_tmp_rw = 1;
        m68ki_cpu.mmu_tmp_sz = M68K_SZ_WORD;
-       m68ki_check_address_error(REG_PC, MODE_READ, FLAG_S | FUNCTION_CODE_USER_PROGRAM); /* auto-disable (see m68kcpu.h) */
+       m68ki_check_address_error(state, REG_PC, MODE_READ, FLAG_S | FUNCTION_CODE_USER_PROGRAM); /* auto-disable (see m68kcpu.h) */
 
 #if M68K_EMULATE_PREFETCH
 {
        uint result;
        if(REG_PC != CPU_PREF_ADDR)
        {
-               CPU_PREF_DATA = m68ki_ic_readimm16(REG_PC);
+               CPU_PREF_DATA = m68ki_ic_readimm16(state, REG_PC);
                CPU_PREF_ADDR = m68ki_cpu.mmu_tmp_buserror_occurred ? ((uint32)~0) : REG_PC;
        }
        result = MASK_OUT_ABOVE_16(CPU_PREF_DATA);
        REG_PC += 2;
        if (!m68ki_cpu.mmu_tmp_buserror_occurred) {
                // prefetch only if no bus error occurred in opcode fetch
-               CPU_PREF_DATA = m68ki_ic_readimm16(REG_PC);
+               CPU_PREF_DATA = m68ki_ic_readimm16(state, REG_PC);
                CPU_PREF_ADDR = m68ki_cpu.mmu_tmp_buserror_occurred ? ((uint32)~0) : REG_PC;
                // ignore bus error on prefetch
                m68ki_cpu.mmu_tmp_buserror_occurred = 0;