X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FSek.c;h=449a4d7a59d62d96844f0db9d560cc6011da9c90;hb=3aa1e148a28da9b4e10e824984f7b3a4908b1ace;hp=df98d9d345846aec773e17bace0e00a2a1039db8;hpb=cc68a136aa179a5f32fe40208371eb9c2b0aadae;p=picodrive.git diff --git a/Pico/Sek.c b/Pico/Sek.c index df98d9d..449a4d7 100644 --- a/Pico/Sek.c +++ b/Pico/Sek.c @@ -14,65 +14,57 @@ int SekCycleCnt=0; // cycles done in this frame int SekCycleAim=0; // cycle aim unsigned int SekCycleCntT=0; + +/* context */ +// Cyclone 68000 #ifdef EMU_C68K -// ---------------------- Cyclone 68000 ---------------------- -struct Cyclone PicoCpu; +struct Cyclone PicoCpuCM68k; #endif - +// MUSASHI 68000 #ifdef EMU_M68K -// ---------------------- MUSASHI 68000 ---------------------- -m68ki_cpu_core PicoM68kCPU; // MD's CPU +m68ki_cpu_core PicoCpuMM68k; #endif - -#ifdef EMU_A68K -// ---------------------- A68K ---------------------- - -void __cdecl M68000_RESET(); -int m68k_ICount=0; -unsigned int mem_amask=0xffffff; // 24-bit bus -unsigned int mame_debug=0,cur_mrhard=0,m68k_illegal_opcode=0,illegal_op=0,illegal_pc=0,opcode_entry=0; // filler - -static int IrqCallback(int i) { i; return -1; } -static int DoReset() { return 0; } -static int (*ResetCallback)()=DoReset; - -#pragma warning (disable:4152) +// FAME 68000 +#ifdef EMU_F68K +M68K_CONTEXT PicoCpuFM68k; #endif - -// interrupt acknowledgment +/* callbacks */ #ifdef EMU_C68K -static void SekIntAck(int level) +// interrupt acknowledgment +static int SekIntAck(int level) { // try to emulate VDP's reaction to 68000 int ack - if (level == 4) Pico.video.pending_ints = 0; - else if(level == 6) Pico.video.pending_ints &= ~0x20; - PicoCpu.irq = 0; + if (level == 4) { Pico.video.pending_ints = 0; elprintf(EL_INTS, "hack: @ %06x [%i]", SekPc, SekCycleCnt); } + else if(level == 6) { Pico.video.pending_ints &= ~0x20; elprintf(EL_INTS, "vack: @ %06x [%i]", SekPc, SekCycleCnt); } + PicoCpuCM68k.irq = 0; + return CYCLONE_INT_ACK_AUTOVECTOR; } -static void SekResetAck() +static void SekResetAck(void) { -#if defined(__DEBUG_PRINT) || defined(WIN32) - dprintf("Reset encountered @ %06x", SekPc); -#endif + elprintf(EL_ANOMALY, "Reset encountered @ %06x", SekPc); } static int SekUnrecognizedOpcode() { unsigned int pc, op; pc = SekPc; - op = PicoCpu.read16(pc); -#if defined(__DEBUG_PRINT) || defined(WIN32) - dprintf("Unrecognized Opcode %04x @ %06x", op, pc); -#endif + op = PicoCpuCM68k.read16(pc); + elprintf(EL_ANOMALY, "Unrecognized Opcode %04x @ %06x", op, pc); // see if we are not executing trash if (pc < 0x200 || (pc > Pico.romsize+4 && (pc&0xe00000)!=0xe00000)) { - PicoCpu.cycles = 0; - PicoCpu.stopped = 1; + PicoCpuCM68k.cycles = 0; + PicoCpuCM68k.state_flags |= 1; return 1; } - //exit(1); +#ifdef EMU_M68K // debugging cyclone + { + extern int have_illegal; + have_illegal = 1; + } +#endif return 0; } #endif @@ -81,73 +73,90 @@ static int SekUnrecognizedOpcode() #ifdef EMU_M68K static int SekIntAckM68K(int level) { - if (level == 4) { Pico.video.pending_ints = 0; } // dprintf("hack: [%i|%i]", Pico.m.scanline, SekCyclesDone()); } - else if(level == 6) { Pico.video.pending_ints &= ~0x20; } // dprintf("vack: [%i|%i]", Pico.m.scanline, SekCyclesDone()); } + if (level == 4) { Pico.video.pending_ints = 0; elprintf(EL_INTS, "hack: @ %06x [%i]", SekPc, SekCycleCnt); } + else if(level == 6) { Pico.video.pending_ints &= ~0x20; elprintf(EL_INTS, "vack: @ %06x [%i]", SekPc, SekCycleCnt); } CPU_INT_LEVEL = 0; return M68K_INT_ACK_AUTOVECTOR; } + +static int SekTasCallback(void) +{ + return 0; // no writeback +} #endif +#ifdef EMU_F68K +static void SekIntAckF68K(unsigned level) +{ + if (level == 4) { Pico.video.pending_ints = 0; elprintf(EL_INTS, "hack: @ %06x [%i]", SekPc, SekCycleCnt); } + else if(level == 6) { Pico.video.pending_ints &= ~0x20; elprintf(EL_INTS, "vack: @ %06x [%i]", SekPc, SekCycleCnt); } + PicoCpuFM68k.interrupts[0] = 0; +} +#endif -int SekInit() + +PICO_INTERNAL int SekInit() { #ifdef EMU_C68K CycloneInit(); - memset(&PicoCpu,0,sizeof(PicoCpu)); - PicoCpu.IrqCallback=SekIntAck; - PicoCpu.ResetCallback=SekResetAck; - PicoCpu.UnrecognizedCallback=SekUnrecognizedOpcode; -#endif -#ifdef EMU_A68K - memset(&M68000_regs,0,sizeof(M68000_regs)); - M68000_regs.IrqCallback=IrqCallback; - M68000_regs.pResetCallback=ResetCallback; - M68000_RESET(); // Init cpu emulator + memset(&PicoCpuCM68k,0,sizeof(PicoCpuCM68k)); + PicoCpuCM68k.IrqCallback=SekIntAck; + PicoCpuCM68k.ResetCallback=SekResetAck; + PicoCpuCM68k.UnrecognizedCallback=SekUnrecognizedOpcode; #endif #ifdef EMU_M68K { void *oldcontext = m68ki_cpu_p; - m68k_set_context(&PicoM68kCPU); + m68k_set_context(&PicoCpuMM68k); m68k_set_cpu_type(M68K_CPU_TYPE_68000); m68k_init(); m68k_set_int_ack_callback(SekIntAckM68K); + m68k_set_tas_instr_callback(SekTasCallback); m68k_pulse_reset(); // Init cpu emulator m68k_set_context(oldcontext); } #endif +#ifdef EMU_F68K + { + void *oldcontext = g_m68kcontext; + g_m68kcontext = &PicoCpuFM68k; + memset(&PicoCpuFM68k, 0, sizeof(PicoCpuFM68k)); + m68k_init(); + PicoCpuFM68k.iack_handler = SekIntAckF68K; + g_m68kcontext = oldcontext; + } +#endif return 0; } + // Reset the 68000: -int SekReset() +PICO_INTERNAL int SekReset() { if (Pico.rom==NULL) return 1; #ifdef EMU_C68K - PicoCpu.stopped=0; - PicoCpu.osp=0; - PicoCpu.srh =0x27; // Supervisor mode - PicoCpu.flags=4; // Z set - PicoCpu.irq=0; - PicoCpu.a[7]=PicoCpu.read32(0); // Stack Pointer - PicoCpu.membase=0; - PicoCpu.pc=PicoCpu.checkpc(PicoCpu.read32(4)); // Program Counter -#endif -#ifdef EMU_A68K - // Reset CPU: fetch SP and PC - M68000_regs.srh=0x27; // Supervisor mode - M68000_regs.a[7]=PicoRead32(0); - M68000_regs.pc =PicoRead32(4); - PicoInitPc(M68000_regs.pc); + PicoCpuCM68k.state_flags=0; + PicoCpuCM68k.osp=0; + PicoCpuCM68k.srh =0x27; // Supervisor mode + PicoCpuCM68k.flags=4; // Z set + PicoCpuCM68k.irq=0; + PicoCpuCM68k.a[7]=PicoCpuCM68k.read32(0); // Stack Pointer + PicoCpuCM68k.membase=0; + PicoCpuCM68k.pc=PicoCpuCM68k.checkpc(PicoCpuCM68k.read32(4)); // Program Counter #endif #ifdef EMU_M68K + m68k_set_context(&PicoCpuMM68k); // if we ever reset m68k, we always need it's context to be set + m68ki_cpu.sp[0]=0; + m68k_set_irq(0); + m68k_pulse_reset(); +#endif +#ifdef EMU_F68K { - void *oldcontext = m68ki_cpu_p; - m68k_set_context(&PicoM68kCPU); - m68k_pulse_reset(); - m68k_set_context(oldcontext); + g_m68kcontext = &PicoCpuFM68k; + m68k_reset(); } #endif @@ -155,38 +164,54 @@ int SekReset() } -int SekInterrupt(int irq) +PICO_INTERNAL int SekInterrupt(int irq) { -#ifdef EMU_C68K - PicoCpu.irq=irq; +#if defined(EMU_C68K) && defined(EMU_M68K) + { + extern unsigned int dbg_irq_level; + dbg_irq_level=irq; + return 0; + } #endif -#ifdef EMU_A68K - M68000_regs.irq=irq; // raise irq (gets lowered after taken) +#ifdef EMU_C68K + PicoCpuCM68k.irq=irq; #endif #ifdef EMU_M68K { void *oldcontext = m68ki_cpu_p; - m68k_set_context(&PicoM68kCPU); + m68k_set_context(&PicoCpuMM68k); m68k_set_irq(irq); // raise irq (gets lowered after taken or must be done in ack) m68k_set_context(oldcontext); } #endif +#ifdef EMU_F68K + PicoCpuFM68k.interrupts[0]=irq; +#endif + return 0; } -//int SekPc() { return PicoCpu.pc-PicoCpu.membase; } -//int SekPc() { return M68000_regs.pc; } -//int SekPc() { return m68k_get_reg(NULL, M68K_REG_PC); } - -void SekState(unsigned char *data) +// data must be word aligned +PICO_INTERNAL void SekState(int *data) { #ifdef EMU_C68K - memcpy(data,PicoCpu.d,0x44); -#elif defined(EMU_A68K) - memcpy(data, M68000_regs.d, 0x40); - memcpy(data+0x40,&M68000_regs.pc,0x04); + memcpy32(data,PicoCpuCM68k.d,0x44/4); #elif defined(EMU_M68K) - memcpy(data, PicoM68kCPU.dar,0x40); - memcpy(data+0x40,&PicoM68kCPU.pc, 0x04); + memcpy32(data, PicoCpuMM68k.dar, 0x40/4); + data[0x10] = PicoCpuMM68k.pc; +#elif defined(EMU_F68K) + memcpy32(data, (int *)PicoCpuFM68k.dreg, 0x40/4); + data[0x10] = PicoCpuFM68k.pc; #endif } + +PICO_INTERNAL void SekSetRealTAS(int use_real) +{ +#ifdef EMU_C68K + CycloneSetRealTAS(use_real); +#endif +#ifdef EMU_F68K + // TODO +#endif +} +