1 // (c) Copyright 2006 notaz, All rights reserved.
4 #include "../PicoInt.h"
7 int SekCycleCntS68k=0; // cycles done in this frame
8 int SekCycleAimS68k=0; // cycle aim
11 // ---------------------- Cyclone 68000 ----------------------
12 struct Cyclone PicoCpuS68k;
16 // ---------------------- MUSASHI 68000 ----------------------
17 m68ki_cpu_core PicoS68kCPU; // Mega CD's CPU
20 static int new_irq_level(int level)
22 int level_new = 0, irqs;
23 Pico_mcd->m.s68k_pend_ints &= ~(1 << level);
24 irqs = Pico_mcd->m.s68k_pend_ints;
25 irqs &= Pico_mcd->s68k_regs[0x33];
26 while ((irqs >>= 1)) level_new++;
32 static int SekIntAckS68kM(int level)
34 int level_new = new_irq_level(level);
35 dprintf("s68kACK %i -> %i", level, level_new);
36 CPU_INT_LEVEL = level_new << 8;
37 return M68K_INT_ACK_AUTOVECTOR;
42 // interrupt acknowledgment
43 static void SekIntAckS68k(int level)
45 int level_new = new_irq_level(level);
47 dprintf("s68kACK %i -> %i", level, level_new);
48 PicoCpuS68k.irq = level_new;
51 static void SekResetAck()
53 dprintf("s68k: Reset encountered @ %06x", SekPcS68k);
56 static int SekUnrecognizedOpcode()
60 op = PicoCpuS68k.read16(pc);
61 dprintf("Unrecognized Opcode %04x @ %06x", op, pc);
73 memset(&PicoCpuS68k,0,sizeof(PicoCpuS68k));
74 PicoCpuS68k.IrqCallback=SekIntAckS68k;
75 PicoCpuS68k.ResetCallback=SekResetAck;
76 PicoCpuS68k.UnrecognizedCallback=SekUnrecognizedOpcode;
80 // Musashi is not very context friendly..
81 void *oldcontext = m68ki_cpu_p;
82 m68k_set_context(&PicoS68kCPU);
83 m68k_set_cpu_type(M68K_CPU_TYPE_68000);
85 m68k_set_int_ack_callback(SekIntAckS68kM);
86 // m68k_pulse_reset(); // not yet, memmap is not set up
87 m68k_set_context(oldcontext);
97 if (Pico.rom==NULL) return 1;
100 PicoCpuS68k.stopped=0;
102 PicoCpuS68k.srh =0x27; // Supervisor mode
103 PicoCpuS68k.flags=4; // Z set
105 PicoCpuS68k.a[7]=PicoCpuS68k.read32(0); // Stack Pointer
106 PicoCpuS68k.membase=0;
107 PicoCpuS68k.pc=PicoCpuS68k.checkpc(PicoCpuS68k.read32(4)); // Program Counter
111 void *oldcontext = m68ki_cpu_p;
113 m68k_set_context(&PicoS68kCPU);
117 m68k_set_context(oldcontext);
124 int SekInterruptS68k(int irq)
126 int irqs, real_irq = 1;
127 Pico_mcd->m.s68k_pend_ints |= 1 << irq;
128 irqs = Pico_mcd->m.s68k_pend_ints >> 1;
129 while ((irqs >>= 1)) real_irq++; // this is probably only needed for Cyclone
132 PicoCpuS68k.irq=real_irq;
135 void *oldcontext = m68ki_cpu_p;
136 m68k_set_context(&PicoS68kCPU);
137 m68k_set_irq(real_irq); // raise irq (gets lowered after taken or must be done in ack)
138 m68k_set_context(oldcontext);