5 * This work is licensed under the terms of MAME license.
6 * See COPYING file in the top-level directory.
9 #include "../pico_int.h"
12 unsigned int SekCycleCntS68k;
13 unsigned int SekCycleAimS68k;
19 struct Cyclone PicoCpuCS68k;
23 m68ki_cpu_core PicoCpuMS68k;
27 M68K_CONTEXT PicoCpuFS68k;
31 static int new_irq_level(int level)
33 int level_new = 0, irqs;
34 Pico_mcd->m.s68k_pend_ints &= ~(1 << level);
35 irqs = Pico_mcd->m.s68k_pend_ints;
36 irqs &= Pico_mcd->s68k_regs[0x33];
37 while ((irqs >>= 1)) level_new++;
43 // interrupt acknowledgement
44 static int SekIntAckS68k(int level)
46 int level_new = new_irq_level(level);
48 elprintf(EL_INTS, "s68kACK %i -> %i", level, level_new);
49 PicoCpuCS68k.irq = level_new;
50 return CYCLONE_INT_ACK_AUTOVECTOR;
53 static void SekResetAckS68k(void)
55 elprintf(EL_ANOMALY, "s68k: Reset encountered @ %06x", SekPcS68k);
58 static int SekUnrecognizedOpcodeS68k(void)
60 elprintf(EL_ANOMALY, "Unrecognized Opcode @ %06x", SekPcS68k);
67 static int SekIntAckMS68k(int level)
69 #ifndef EMU_CORE_DEBUG
70 int level_new = new_irq_level(level);
71 elprintf(EL_INTS, "s68kACK %i -> %i", level, level_new);
72 CPU_INT_LEVEL = level_new << 8;
76 return M68K_INT_ACK_AUTOVECTOR;
81 static void SekIntAckFS68k(unsigned level)
83 int level_new = new_irq_level(level);
84 elprintf(EL_INTS, "s68kACK %i -> %i", level, level_new);
85 #ifndef EMU_CORE_DEBUG
86 PicoCpuFS68k.interrupts[0] = level_new;
89 extern int dbg_irq_level_sub;
90 dbg_irq_level_sub = level_new;
91 PicoCpuFS68k.interrupts[0] = 0;
98 PICO_INTERNAL void SekInitS68k(void)
102 memset(&PicoCpuCS68k,0,sizeof(PicoCpuCS68k));
103 PicoCpuCS68k.IrqCallback=SekIntAckS68k;
104 PicoCpuCS68k.ResetCallback=SekResetAckS68k;
105 PicoCpuCS68k.UnrecognizedCallback=SekUnrecognizedOpcodeS68k;
109 // Musashi is not very context friendly..
110 void *oldcontext = m68ki_cpu_p;
111 m68k_set_context(&PicoCpuMS68k);
112 m68k_set_cpu_type(M68K_CPU_TYPE_68000);
114 m68k_set_int_ack_callback(SekIntAckMS68k);
115 // m68k_pulse_reset(); // not yet, memmap is not set up
116 m68k_set_context(oldcontext);
121 void *oldcontext = g_m68kcontext;
122 g_m68kcontext = &PicoCpuFS68k;
123 memset(&PicoCpuFS68k, 0, sizeof(PicoCpuFS68k));
125 PicoCpuFS68k.iack_handler = SekIntAckFS68k;
126 PicoCpuFS68k.sr = 0x2704; // Z flag
127 g_m68kcontext = oldcontext;
133 PICO_INTERNAL int SekResetS68k(void)
135 if (Pico.rom==NULL) return 1;
138 CycloneReset(&PicoCpuCS68k);
142 void *oldcontext = m68ki_cpu_p;
144 m68k_set_context(&PicoCpuMS68k);
148 m68k_set_context(oldcontext);
153 void *oldcontext = g_m68kcontext;
154 g_m68kcontext = &PicoCpuFS68k;
156 g_m68kcontext = oldcontext;
163 PICO_INTERNAL int SekInterruptS68k(int irq)
165 int irqs, real_irq = 1;
166 Pico_mcd->m.s68k_pend_ints |= 1 << irq;
167 irqs = Pico_mcd->m.s68k_pend_ints >> 1;
168 while ((irqs >>= 1)) real_irq++;
170 #ifdef EMU_CORE_DEBUG
172 extern int dbg_irq_level_sub;
173 dbg_irq_level_sub=real_irq;
178 PicoCpuCS68k.irq=real_irq;
181 // avoid m68k_set_irq() for delaying to work
182 PicoCpuMS68k.int_level = real_irq << 8;
185 PicoCpuFS68k.interrupts[0]=real_irq;
190 void SekInterruptClearS68k(int irq)
192 int level_new = new_irq_level(irq);
195 PicoCpuCS68k.irq = level_new;
198 CPU_INT_LEVEL = level_new << 8;
201 PicoCpuFS68k.interrupts[0] = level_new;