1 // This is part of Pico Library
\r
3 // (c) Copyright 2004 Dave, All rights reserved.
\r
4 // (c) Copyright 2006 notaz, All rights reserved.
\r
5 // Free for non-commercial use.
\r
7 // For commercial use, separate licencing terms must be obtained.
\r
10 #include "PicoInt.h"
\r
13 int SekCycleCnt=0; // cycles done in this frame
\r
14 int SekCycleAim=0; // cycle aim
\r
15 unsigned int SekCycleCntT=0;
\r
21 struct Cyclone PicoCpuCM68k;
\r
25 m68ki_cpu_core PicoCpuMM68k;
\r
29 M68K_CONTEXT PicoCpuFM68k;
\r
35 // interrupt acknowledgment
\r
36 static int SekIntAck(int level)
\r
38 // try to emulate VDP's reaction to 68000 int ack
\r
39 if (level == 4) { Pico.video.pending_ints = 0; elprintf(EL_INTS, "hack: @ %06x [%i]", SekPc, SekCycleCnt); }
\r
40 else if(level == 6) { Pico.video.pending_ints &= ~0x20; elprintf(EL_INTS, "vack: @ %06x [%i]", SekPc, SekCycleCnt); }
\r
41 PicoCpuCM68k.irq = 0;
\r
42 return CYCLONE_INT_ACK_AUTOVECTOR;
\r
45 static void SekResetAck(void)
\r
47 elprintf(EL_ANOMALY, "Reset encountered @ %06x", SekPc);
\r
50 static int SekUnrecognizedOpcode()
\r
52 unsigned int pc, op;
\r
54 op = PicoCpuCM68k.read16(pc);
\r
55 elprintf(EL_ANOMALY, "Unrecognized Opcode %04x @ %06x", op, pc);
\r
56 // see if we are not executing trash
\r
57 if (pc < 0x200 || (pc > Pico.romsize+4 && (pc&0xe00000)!=0xe00000)) {
\r
58 PicoCpuCM68k.cycles = 0;
\r
59 PicoCpuCM68k.state_flags |= 1;
\r
62 #ifdef EMU_M68K // debugging cyclone
\r
64 extern int have_illegal;
\r
74 static int SekIntAckM68K(int level)
\r
76 if (level == 4) { Pico.video.pending_ints = 0; elprintf(EL_INTS, "hack: @ %06x [%i]", SekPc, SekCycleCnt); }
\r
77 else if(level == 6) { Pico.video.pending_ints &= ~0x20; elprintf(EL_INTS, "vack: @ %06x [%i]", SekPc, SekCycleCnt); }
\r
79 return M68K_INT_ACK_AUTOVECTOR;
\r
82 static int SekTasCallback(void)
\r
84 return 0; // no writeback
\r
90 static void SekIntAckF68K(unsigned level)
\r
92 if (level == 4) { Pico.video.pending_ints = 0; elprintf(EL_INTS, "hack: @ %06x [%i]", SekPc, SekCycleCnt); }
\r
93 else if(level == 6) { Pico.video.pending_ints &= ~0x20; elprintf(EL_INTS, "vack: @ %06x [%i]", SekPc, SekCycleCnt); }
\r
94 PicoCpuFM68k.interrupts[0] = 0;
\r
99 PICO_INTERNAL int SekInit()
\r
103 memset(&PicoCpuCM68k,0,sizeof(PicoCpuCM68k));
\r
104 PicoCpuCM68k.IrqCallback=SekIntAck;
\r
105 PicoCpuCM68k.ResetCallback=SekResetAck;
\r
106 PicoCpuCM68k.UnrecognizedCallback=SekUnrecognizedOpcode;
\r
107 PicoCpuCM68k.flags=4; // Z set
\r
111 void *oldcontext = m68ki_cpu_p;
\r
112 m68k_set_context(&PicoCpuMM68k);
\r
113 m68k_set_cpu_type(M68K_CPU_TYPE_68000);
\r
115 m68k_set_int_ack_callback(SekIntAckM68K);
\r
116 m68k_set_tas_instr_callback(SekTasCallback);
\r
117 //m68k_pulse_reset();
\r
118 m68k_set_context(oldcontext);
\r
123 void *oldcontext = g_m68kcontext;
\r
124 g_m68kcontext = &PicoCpuFM68k;
\r
125 memset(&PicoCpuFM68k, 0, sizeof(PicoCpuFM68k));
\r
127 PicoCpuFM68k.iack_handler = SekIntAckF68K;
\r
128 PicoCpuFM68k.sr = 0x2704; // Z flag
\r
129 g_m68kcontext = oldcontext;
\r
137 // Reset the 68000:
\r
138 PICO_INTERNAL int SekReset()
\r
140 if (Pico.rom==NULL) return 1;
\r
143 PicoCpuCM68k.state_flags=0;
\r
144 PicoCpuCM68k.osp=0;
\r
145 PicoCpuCM68k.srh =0x27; // Supervisor mode
\r
146 PicoCpuCM68k.irq=0;
\r
147 PicoCpuCM68k.a[7]=PicoCpuCM68k.read32(0); // Stack Pointer
\r
148 PicoCpuCM68k.membase=0;
\r
149 PicoCpuCM68k.pc=PicoCpuCM68k.checkpc(PicoCpuCM68k.read32(4)); // Program Counter
\r
152 m68k_set_context(&PicoCpuMM68k); // if we ever reset m68k, we always need it's context to be set
\r
155 m68k_pulse_reset();
\r
160 g_m68kcontext = &PicoCpuFM68k;
\r
169 // data must be word aligned
\r
170 PICO_INTERNAL void SekState(int *data)
\r
173 memcpy32(data,(int *)PicoCpuCM68k.d,0x44/4);
\r
174 data[0x11] = PicoCpuCM68k.flags;
\r
175 #elif defined(EMU_M68K)
\r
176 memcpy32(data, (int *)PicoCpuMM68k.dar, 0x40/4);
\r
177 data[0x10] = PicoCpuMM68k.pc;
\r
178 data[0x11] = m68k_get_reg(&PicoCpuMM68k, M68K_REG_SR);
\r
179 #elif defined(EMU_F68K)
\r
180 memcpy32(data, (int *)PicoCpuFM68k.dreg, 0x40/4);
\r
181 data[0x10] = PicoCpuFM68k.pc;
\r
182 data[0x11] = PicoCpuFM68k.sr;
\r
186 PICO_INTERNAL void SekSetRealTAS(int use_real)
\r
189 CycloneSetRealTAS(use_real);
\r
196 #if defined(EMU_M68K) && M68K_INSTRUCTION_HOOK == OPT_SPECIFY_HANDLER
\r
197 static unsigned char op_flags[0x400000/2] = { 0, };
\r
198 static int atexit_set = 0;
\r
200 static void make_idc(void)
\r
202 FILE *f = fopen("idc.idc", "w");
\r
205 fprintf(f, "#include <idc.idc>\nstatic main() {\n");
\r
206 for (i = 0; i < 0x400000/2; i++)
\r
207 if (op_flags[i] != 0)
\r
208 fprintf(f, " MakeCode(0x%06x);\n", i*2);
\r
213 void instruction_hook(void)
\r
219 if (REG_PC < 0x400000)
\r
220 op_flags[REG_PC/2] = 1;
\r