1 // This is part of Pico Library
3 // (c) Copyright 2004 Dave, All rights reserved.
4 // (c) Copyright 2006 notaz, All rights reserved.
5 // Free for non-commercial use.
7 // For commercial use, separate licencing terms must be obtained.
10 #include "../PicoInt.h"
13 int SekCycleCntS68k=0; // cycles done in this frame
14 int SekCycleAimS68k=0; // cycle aim
17 // ---------------------- Cyclone 68000 ----------------------
18 struct Cyclone PicoCpuS68k;
22 // ---------------------- MUSASHI 68000 ----------------------
23 m68ki_cpu_core PicoS68kCPU; // Mega CD's CPU
26 static int irqs = 0; // TODO: 2 context
30 static int SekIntAckS68k(int level)
33 irqs &= ~(1 << level);
34 irqs &= Pico_mcd->s68k_regs[0x33];
37 while (level_new > 0) { if (irqs & (1 << level_new)) break; level_new--; }
40 dprintf("s68kACK %i -> %i", level, level_new);
41 CPU_INT_LEVEL = level_new << 8;
42 return M68K_INT_ACK_AUTOVECTOR;
47 // interrupt acknowledgment
48 static void SekIntAck(int level)
51 irqs &= ~(1 << level);
52 irqs &= Pico_mcd->s68k_regs[0x33];
55 while (level_new > 0) { if (irqs & (1 << level_new)) break; level_new--; }
58 dprintf("s68kACK %i -> %i", level, level_new);
59 PicoCpuS68k.irq = level_new;
62 static void SekResetAck()
64 dprintf("s68k: Reset encountered @ %06x", SekPcS68k);
67 static int SekUnrecognizedOpcode()
71 op = PicoCpuS68k.read16(pc);
72 dprintf("Unrecognized Opcode %04x @ %06x", op, pc);
84 memset(&PicoCpuS68k,0,sizeof(PicoCpuS68k));
85 PicoCpuS68k.IrqCallback=SekIntAck;
86 PicoCpuS68k.ResetCallback=SekResetAck;
87 PicoCpuS68k.UnrecognizedCallback=SekUnrecognizedOpcode;
91 // Musashi is not very context friendly..
92 void *oldcontext = m68ki_cpu_p;
93 m68k_set_context(&PicoS68kCPU);
94 m68k_set_cpu_type(M68K_CPU_TYPE_68000);
96 m68k_set_int_ack_callback(SekIntAckS68k);
97 // m68k_pulse_reset(); // not yet, memmap is not set up
98 m68k_set_context(oldcontext);
108 if (Pico.rom==NULL) return 1;
111 PicoCpuS68k.stopped=0;
113 PicoCpuS68k.srh =0x27; // Supervisor mode
114 PicoCpuS68k.flags=4; // Z set
116 PicoCpuS68k.a[7]=PicoCpuS68k.read32(0); // Stack Pointer
117 PicoCpuS68k.membase=0;
118 PicoCpuS68k.pc=PicoCpuS68k.checkpc(PicoCpuS68k.read32(4)); // Program Counter
122 void *oldcontext = m68ki_cpu_p;
124 m68k_set_context(&PicoS68kCPU);
126 m68k_set_context(oldcontext);
133 int SekInterruptS68k(int irq)
140 void *oldcontext = m68ki_cpu_p;
141 m68k_set_context(&PicoS68kCPU);
142 m68k_set_irq(irq); // raise irq (gets lowered after taken or must be done in ack)
143 m68k_set_context(oldcontext);