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 new_irq_level(int level)
28 int level_new = 0, irqs;
29 Pico_mcd->m.s68k_pend_ints &= ~(1 << level);
30 irqs = Pico_mcd->m.s68k_pend_ints;
31 irqs &= Pico_mcd->s68k_regs[0x33];
32 while ((irqs >>= 1)) level_new++;
38 static int SekIntAckS68k(int level)
40 int level_new = new_irq_level(level);
41 dprintf("s68kACK %i -> %i", level, level_new);
42 CPU_INT_LEVEL = level_new << 8;
43 return M68K_INT_ACK_AUTOVECTOR;
48 // interrupt acknowledgment
49 static void SekIntAckS68k(int level)
51 int level_new = new_irq_level(level);
53 dprintf("s68kACK %i -> %i", level, level_new);
54 PicoCpuS68k.irq = level_new;
57 static void SekResetAck()
59 dprintf("s68k: Reset encountered @ %06x", SekPcS68k);
62 static int SekUnrecognizedOpcode()
66 op = PicoCpuS68k.read16(pc);
67 dprintf("Unrecognized Opcode %04x @ %06x", op, pc);
79 memset(&PicoCpuS68k,0,sizeof(PicoCpuS68k));
80 PicoCpuS68k.IrqCallback=SekIntAckS68k;
81 PicoCpuS68k.ResetCallback=SekResetAck;
82 PicoCpuS68k.UnrecognizedCallback=SekUnrecognizedOpcode;
86 // Musashi is not very context friendly..
87 void *oldcontext = m68ki_cpu_p;
88 m68k_set_context(&PicoS68kCPU);
89 m68k_set_cpu_type(M68K_CPU_TYPE_68000);
91 m68k_set_int_ack_callback(SekIntAckS68k);
92 // m68k_pulse_reset(); // not yet, memmap is not set up
93 m68k_set_context(oldcontext);
103 if (Pico.rom==NULL) return 1;
106 PicoCpuS68k.stopped=0;
108 PicoCpuS68k.srh =0x27; // Supervisor mode
109 PicoCpuS68k.flags=4; // Z set
111 PicoCpuS68k.a[7]=PicoCpuS68k.read32(0); // Stack Pointer
112 PicoCpuS68k.membase=0;
113 PicoCpuS68k.pc=PicoCpuS68k.checkpc(PicoCpuS68k.read32(4)); // Program Counter
117 void *oldcontext = m68ki_cpu_p;
119 m68k_set_context(&PicoS68kCPU);
121 m68k_set_context(oldcontext);
128 int SekInterruptS68k(int irq)
130 int irqs, real_irq = 1;
131 Pico_mcd->m.s68k_pend_ints |= 1 << irq;
132 irqs = Pico_mcd->m.s68k_pend_ints >> 1;
133 while ((irqs >>= 1)) real_irq++; // this is probably only needed for Cyclone
136 PicoCpuS68k.irq=real_irq;
139 void *oldcontext = m68ki_cpu_p;
140 m68k_set_context(&PicoS68kCPU);
141 m68k_set_irq(real_irq); // raise irq (gets lowered after taken or must be done in ack)
142 m68k_set_context(oldcontext);