1 // (c) Copyright 2007 notaz, All rights reserved.
4 #include "../pico_int.h"
7 int SekCycleCntS68k=0; // cycles done in this frame
8 int SekCycleAimS68k=0; // cycle aim
14 struct Cyclone PicoCpuCS68k;
18 m68ki_cpu_core PicoCpuMS68k;
22 M68K_CONTEXT PicoCpuFS68k;
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 // interrupt acknowledgement
39 static int SekIntAckS68k(int level)
41 int level_new = new_irq_level(level);
43 elprintf(EL_INTS, "s68kACK %i -> %i", level, level_new);
44 PicoCpuCS68k.irq = level_new;
45 return CYCLONE_INT_ACK_AUTOVECTOR;
48 static void SekResetAckS68k(void)
50 elprintf(EL_ANOMALY, "s68k: Reset encountered @ %06x", SekPcS68k);
53 static int SekUnrecognizedOpcodeS68k(void)
57 op = PicoCpuCS68k.read16(pc);
58 elprintf(EL_ANOMALY, "Unrecognized Opcode %04x @ %06x", op, pc);
65 static int SekIntAckMS68k(int level)
67 #ifndef EMU_CORE_DEBUG
68 int level_new = new_irq_level(level);
69 elprintf(EL_INTS, "s68kACK %i -> %i", level, level_new);
70 CPU_INT_LEVEL = level_new << 8;
74 return M68K_INT_ACK_AUTOVECTOR;
79 static void SekIntAckFS68k(unsigned level)
81 int level_new = new_irq_level(level);
82 elprintf(EL_INTS, "s68kACK %i -> %i", level, level_new);
83 #ifndef EMU_CORE_DEBUG
84 PicoCpuFS68k.interrupts[0] = level_new;
87 extern int dbg_irq_level_sub;
88 dbg_irq_level_sub = level_new;
89 PicoCpuFS68k.interrupts[0] = 0;
96 PICO_INTERNAL void SekInitS68k(void)
100 memset(&PicoCpuCS68k,0,sizeof(PicoCpuCS68k));
101 PicoCpuCS68k.IrqCallback=SekIntAckS68k;
102 PicoCpuCS68k.ResetCallback=SekResetAckS68k;
103 PicoCpuCS68k.UnrecognizedCallback=SekUnrecognizedOpcodeS68k;
107 // Musashi is not very context friendly..
108 void *oldcontext = m68ki_cpu_p;
109 m68k_set_context(&PicoCpuMS68k);
110 m68k_set_cpu_type(M68K_CPU_TYPE_68000);
112 m68k_set_int_ack_callback(SekIntAckMS68k);
113 // m68k_pulse_reset(); // not yet, memmap is not set up
114 m68k_set_context(oldcontext);
119 void *oldcontext = g_m68kcontext;
120 g_m68kcontext = &PicoCpuFS68k;
121 memset(&PicoCpuFS68k, 0, sizeof(PicoCpuFS68k));
123 PicoCpuFS68k.iack_handler = SekIntAckFS68k;
124 PicoCpuFS68k.sr = 0x2704; // Z flag
125 g_m68kcontext = oldcontext;
131 PICO_INTERNAL int SekResetS68k(void)
133 if (Pico.rom==NULL) return 1;
136 CycloneReset(&PicoCpuCS68k);
140 void *oldcontext = m68ki_cpu_p;
142 m68k_set_context(&PicoCpuMS68k);
146 m68k_set_context(oldcontext);
151 void *oldcontext = g_m68kcontext;
152 g_m68kcontext = &PicoCpuFS68k;
154 g_m68kcontext = oldcontext;
161 PICO_INTERNAL int SekInterruptS68k(int irq)
163 int irqs, real_irq = 1;
164 Pico_mcd->m.s68k_pend_ints |= 1 << irq;
165 irqs = Pico_mcd->m.s68k_pend_ints >> 1;
166 while ((irqs >>= 1)) real_irq++;
168 #ifdef EMU_CORE_DEBUG
170 extern int dbg_irq_level_sub;
171 dbg_irq_level_sub=real_irq;
176 PicoCpuCS68k.irq=real_irq;
179 void *oldcontext = m68ki_cpu_p;
180 m68k_set_context(&PicoCpuMS68k);
181 m68k_set_irq(real_irq);
182 m68k_set_context(oldcontext);
185 PicoCpuFS68k.interrupts[0]=real_irq;