void cpuSetUpInterrupt(ULO new_interrupt_level) { UWO vector_offset = (UWO) (0x60 + new_interrupt_level*4); ULO vector_address = memoryReadLong(cpuGetVbr() + vector_offset); cpuActivateSSP(); // Switch to using ssp or msp. Loads a7 and preserves usp if we came from user-mode. cpuStackFrameGenerate(vector_offset, cpuGetPC()); // This will end up on msp if master is enabled, or on the ssp/isp if not. cpuSetSR(cpuGetSR() & 0x38ff); // Clear interrupt level cpuSetSR(cpuGetSR() | 0x2000); // Set supervisor mode cpuSetSR(cpuGetSR() | (UWO)(new_interrupt_level << 8)); // Set interrupt level #ifdef CPU_INSTRUCTION_LOGGING cpuCallInterruptLoggingFunc(new_interrupt_level, vector_address); #endif if (cpuGetModelMajor() >= 2 && cpuGetModelMajor() < 6) { if (cpuGetFlagMaster()) { // If the cpu was in master mode, preserve msp, and switch to using ssp (isp) in a7. ULO oldA7 = cpuGetAReg(7); cpuSetMspDirect(oldA7); cpuSetAReg(7, cpuGetSspDirect()); cpuFrame1(vector_offset, cpuGetPC()); // Make the throwaway frame on ssp/isp cpuSetSR(cpuGetSR() & 0xefff); // Clear master bit } } cpuInitializeFromNewPC(vector_address); cpuSetStop(FALSE); cpuSetRaiseInterrupt(FALSE); }
UWO cpuGetNextWord(void) { UWO tmp = cpu_prefetch_word; cpu_prefetch_word = cpuGetNextWordInternal(); cpuSetPC(cpuGetPC() + 2); return tmp; }
ULO cpuGetNextLong(void) { ULO tmp = cpu_prefetch_word << 16; ULO data = cpuGetNextLongInternal(); cpu_prefetch_word = (UWO) data; cpuSetPC(cpuGetPC() + 4); return tmp | (data >> 16); }
void cpuThrowAddressErrorException(void) { cpuThrowException(0xc, cpuGetPC(), TRUE); }
void cpuThrowTraceException(void) { // The saved pc points to the next instruction, which is now in pc cpuThrowException(0x24, cpuGetPC(), FALSE); }
void cpuThrowTrapException(ULO vector_no) { // The saved pc points to the next instruction, which is now in pc cpuThrowException(0x80 + vector_no*4, cpuGetPC(), FALSE); }
void cpuThrowDivisionByZeroException(BOOLE executejmp) { // The saved pc points to the next instruction, which is now in pc cpuThrowException(0x14, cpuGetPC(), executejmp); }
uint16_t vmPeekPC() { return cpuGetPC(vm->cpu); }
void vmTick() { cpuRunCMD(vm->cpu, memROMRead(vm->mem, cpuGetPC(vm->cpu))); }
void cpuSkipNextLong(void) { cpuSetPC(cpuGetPC() + 4); cpuInitializePrefetch(); }
void cpuSkipNextWord(void) { cpuSetPC(cpuGetPC() + 2); cpuInitializePrefetch(); }
void cpuInitializePrefetch(void) { cpu_prefetch_word = memoryReadWord(cpuGetPC()); }
static ULO cpuGetNextLongInternal(void) { ULO data = memoryReadLong(cpuGetPC() + 2); return data; }
static UWO cpuGetNextWordInternal(void) { UWO data = memoryReadWord(cpuGetPC() + 2); return data; }