/* Execute some instructions until we use up cycles clock cycles */ int m68k_execute(m68ki_cpu_core *m68k, unsigned int cycles) { m68k->initial_cycles = cycles; /* eat up any reset cycles */ if (m68k->reset_cycles) { int rc = m68k->reset_cycles; m68k->reset_cycles = 0; cycles -= rc; if (cycles <= 0) return rc; } /* Set our pool of clock cycles available */ m68k->remaining_cycles = cycles; /* See if interrupts came in */ m68ki_check_interrupts(m68k); /* Make sure we're not stopped */ if(!m68k->stopped) { /* Return point if we had an address error */ m68ki_set_address_error_trap(m68k); /* auto-disable (see m68kcpu.h) */ /* Main loop. Keep going until we run out of clock cycles */ do { /* Set tracing accodring to T1. (T0 is done inside instruction) */ m68ki_trace_t1(); /* auto-disable (see m68kcpu.h) */ /* Record previous program counter */ REG_PPC = REG_PC; /* Read an instruction and call its handler */ m68k->ir = m68ki_read_imm_16(m68k); m68ki_instruction_jump_table[m68k->ir](m68k); m68k->remaining_cycles -= m68k->cyc_instruction[m68k->ir]; /* Trace m68k_exception, if necessary */ m68ki_exception_if_trace(); /* auto-disable (see m68kcpu.h) */ } while (m68k->remaining_cycles > 0); /* set previous PC to current PC for the next entry into the loop */ REG_PPC = REG_PC; } else if (m68k->remaining_cycles > 0) m68k->remaining_cycles = 0; /* return how many clocks we used */ return m68k->initial_cycles - m68k->remaining_cycles; }
int m68k_execute(int num_cycles) { if (regs.stopped) { regs.remainingCycles = 0; // int32_t regs.interruptCycles = 0; // uint32_t return num_cycles; } #if 0 /* Set our pool of clock cycles available */ SET_CYCLES(num_cycles); m68ki_initial_cycles = num_cycles; /* ASG: update cycles */ USE_CYCLES(CPU_INT_CYCLES); CPU_INT_CYCLES = 0; /* Return point if we had an address error */ m68ki_set_address_error_trap(); /* auto-disable (see m68kcpu.h) */ #else regs.remainingCycles = num_cycles; /*int32_t*/ initialCycles = num_cycles; regs.remainingCycles -= regs.interruptCycles; regs.interruptCycles = 0; #endif /* Main loop. Keep going until we run out of clock cycles */ do { // This is so our debugging code can break in on a dime. // Otherwise, this is just extra slow down :-P if (regs.spcflags & SPCFLAG_DEBUGGER) { // Not sure this is correct... :-P num_cycles = initialCycles - regs.remainingCycles; regs.remainingCycles = 0; // int32_t regs.interruptCycles = 0; // uint32_t return num_cycles; } #if 0 /* Set tracing accodring to T1. (T0 is done inside instruction) */ m68ki_trace_t1(); /* auto-disable (see m68kcpu.h) */ /* Set the address space for reads */ m68ki_use_data_space(); /* auto-disable (see m68kcpu.h) */ /* Call external hook to peek at CPU */ m68ki_instr_hook(); /* auto-disable (see m68kcpu.h) */ /* Record previous program counter */ REG_PPC = REG_PC; /* Read an instruction and call its handler */ REG_IR = m68ki_read_imm_16(); m68ki_instruction_jump_table[REG_IR](); USE_CYCLES(CYC_INSTRUCTION[REG_IR]); /* Trace m68k_exception, if necessary */ m68ki_exception_if_trace(); /* auto-disable (see m68kcpu.h) */ #else //Testing Hover Strike... #if 0 //Dasm(regs.pc, 1); static int hitCount = 0; static int inRoutine = 0; static int instSeen; //if (regs.pc == 0x80340A) if (regs.pc == 0x803416) { hitCount++; inRoutine = 1; instSeen = 0; printf("%i: $80340A start. A0=%08X, A1=%08X ", hitCount, regs.regs[8], regs.regs[9]); } else if (regs.pc == 0x803422) { inRoutine = 0; printf("(%i instructions)\n", instSeen); } if (inRoutine) instSeen++; #endif // AvP testing... (problem was: 32 bit addresses on 24 bit address cpu--FIXED) #if 0 static int go = 0; if (regs.pc == 0x94BA) { go = 1; printf("\n"); } if (regs.pc == 0x94C6) go = 0; // if (regs.regs[10] == 0xFFFFFFFF && go) if (go) { // printf("A2=-1, PC=%08X\n", regs.pc); // go = 0; // Dasm(regs.pc, 130); Dasm(regs.pc, 1); DumpRegisters(); } //94BA: 2468 0000 MOVEA.L (A0,$0000) == $0002328A, A2 //94BE: 200A MOVE.L A2, D0 //94C0: 6A02 BPL.B $94C4 //94C2: 2452 MOVEA.L (A2), A2 ; <--- HERE //94C4: 4283 CLR.L D3 #endif // pthread_mutex_lock(&executionLock); if (checkForIRQToHandle) { checkForIRQToHandle = 0; m68k_set_irq2(IRQLevelToHandle); } #ifdef M68K_HOOK_FUNCTION M68KInstructionHook(); #endif uint32_t opcode = get_iword(0); //if ((opcode & 0xFFF8) == 0x31C0) //{ // printf("MOVE.W D%i, EA\n", opcode & 0x07); //} int32_t cycles = (int32_t)(*cpuFunctionTable[opcode])(opcode); regs.remainingCycles -= cycles; // pthread_mutex_unlock(&executionLock); //printf("Executed opcode $%04X (%i cycles)...\n", opcode, cycles); #endif } while (regs.remainingCycles > 0); #if 0 /* set previous PC to current PC for the next entry into the loop */ REG_PPC = REG_PC; /* ASG: update cycles */ USE_CYCLES(CPU_INT_CYCLES); CPU_INT_CYCLES = 0; /* return how many clocks we used */ return m68ki_initial_cycles - GET_CYCLES(); #else regs.remainingCycles -= regs.interruptCycles; regs.interruptCycles = 0; // Return # of clock cycles used return initialCycles - regs.remainingCycles; #endif }