-// This is part of Pico Library\r
-\r
-// (c) Copyright 2004 Dave, All rights reserved.\r
-// (c) Copyright 2006 notaz, All rights reserved.\r
-// Free for non-commercial use.\r
-\r
-// For commercial use, separate licencing terms must be obtained.\r
-\r
+/*\r
+ * PicoDrive\r
+ * (c) Copyright Dave, 2004\r
+ * (C) notaz, 2006-2009\r
+ *\r
+ * This work is licensed under the terms of MAME license.\r
+ * See COPYING file in the top-level directory.\r
+ */\r
\r
#include "pico_int.h"\r
#include "memory.h"\r
\r
static int SekUnrecognizedOpcode()\r
{\r
- unsigned int pc, op;\r
+ unsigned int pc;\r
pc = SekPc;\r
- op = PicoCpuCM68k.read16(pc);\r
- elprintf(EL_ANOMALY, "Unrecognized Opcode %04x @ %06x", op, pc);\r
- // see if we are not executing trash\r
- if (pc < 0x200 || (pc > Pico.romsize+4 && (pc&0xe00000)!=0xe00000)) {\r
+ elprintf(EL_ANOMALY, "Unrecognized Opcode @ %06x", pc);\r
+ // see if we are still in a mapped region\r
+ pc &= 0x00ffffff;\r
+ if (map_flag_set(m68k_read16_map[pc >> M68K_MEM_SHIFT])) {\r
+ elprintf(EL_STATUS|EL_ANOMALY, "m68k crash @%06x", pc);\r
PicoCpuCM68k.cycles = 0;\r
PicoCpuCM68k.state_flags |= 1;\r
return 1;\r
#endif\r
}\r
\r
+// Pack the cpu into a common format:\r
+// XXX: rename\r
+PICO_INTERNAL void SekPackCpu(unsigned char *cpu, int is_sub)\r
+{\r
+ unsigned int pc=0;\r
+\r
+#if defined(EMU_C68K)\r
+ struct Cyclone *context = is_sub ? &PicoCpuCS68k : &PicoCpuCM68k;\r
+ memcpy(cpu,context->d,0x40);\r
+ pc=context->pc-context->membase;\r
+ *(unsigned int *)(cpu+0x44)=CycloneGetSr(context);\r
+ *(unsigned int *)(cpu+0x48)=context->osp;\r
+ cpu[0x4c] = context->irq;\r
+ cpu[0x4d] = context->state_flags & 1;\r
+#elif defined(EMU_M68K)\r
+ void *oldcontext = m68ki_cpu_p;\r
+ m68k_set_context(is_sub ? &PicoCpuMS68k : &PicoCpuMM68k);\r
+ memcpy(cpu,m68ki_cpu_p->dar,0x40);\r
+ pc=m68ki_cpu_p->pc;\r
+ *(unsigned int *)(cpu+0x44)=m68k_get_reg(NULL, M68K_REG_SR);\r
+ *(unsigned int *)(cpu+0x48)=m68ki_cpu_p->sp[m68ki_cpu_p->s_flag^SFLAG_SET];\r
+ cpu[0x4c] = CPU_INT_LEVEL>>8;\r
+ cpu[0x4d] = CPU_STOPPED;\r
+ m68k_set_context(oldcontext);\r
+#elif defined(EMU_F68K)\r
+ M68K_CONTEXT *context = is_sub ? &PicoCpuFS68k : &PicoCpuFM68k;\r
+ memcpy(cpu,context->dreg,0x40);\r
+ pc=context->pc;\r
+ *(unsigned int *)(cpu+0x44)=context->sr;\r
+ *(unsigned int *)(cpu+0x48)=context->asp;\r
+ cpu[0x4c] = context->interrupts[0];\r
+ cpu[0x4d] = (context->execinfo & FM68K_HALTED) ? 1 : 0;\r
+#endif\r
+\r
+ *(unsigned int *)(cpu+0x40) = pc;\r
+ *(unsigned int *)(cpu+0x50) = SekCycleCntT;\r
+}\r
+\r
+PICO_INTERNAL void SekUnpackCpu(const unsigned char *cpu, int is_sub)\r
+{\r
+#if defined(EMU_C68K)\r
+ struct Cyclone *context = is_sub ? &PicoCpuCS68k : &PicoCpuCM68k;\r
+ CycloneSetSr(context, *(unsigned int *)(cpu+0x44));\r
+ context->osp=*(unsigned int *)(cpu+0x48);\r
+ memcpy(context->d,cpu,0x40);\r
+ context->membase = 0;\r
+ context->pc = *(unsigned int *)(cpu+0x40);\r
+ CycloneUnpack(context, NULL); // rebase PC\r
+ context->irq = cpu[0x4c];\r
+ context->state_flags = 0;\r
+ if (cpu[0x4d])\r
+ context->state_flags |= 1;\r
+#elif defined(EMU_M68K)\r
+ void *oldcontext = m68ki_cpu_p;\r
+ m68k_set_context(is_sub ? &PicoCpuMS68k : &PicoCpuMM68k);\r
+ m68k_set_reg(M68K_REG_SR, *(unsigned int *)(cpu+0x44));\r
+ memcpy(m68ki_cpu_p->dar,cpu,0x40);\r
+ m68ki_cpu_p->pc=*(unsigned int *)(cpu+0x40);\r
+ m68ki_cpu_p->sp[m68ki_cpu_p->s_flag^SFLAG_SET]=*(unsigned int *)(cpu+0x48);\r
+ CPU_INT_LEVEL = cpu[0x4c] << 8;\r
+ CPU_STOPPED = cpu[0x4d];\r
+ m68k_set_context(oldcontext);\r
+#elif defined(EMU_F68K)\r
+ M68K_CONTEXT *context = is_sub ? &PicoCpuFS68k : &PicoCpuFM68k;\r
+ memcpy(context->dreg,cpu,0x40);\r
+ context->pc =*(unsigned int *)(cpu+0x40);\r
+ context->sr =*(unsigned int *)(cpu+0x44);\r
+ context->asp=*(unsigned int *)(cpu+0x48);\r
+ context->interrupts[0] = cpu[0x4c];\r
+ context->execinfo &= ~FM68K_HALTED;\r
+ if (cpu[0x4d]&1) context->execinfo |= FM68K_HALTED;\r
+#endif\r
+ SekCycleCntT = *(unsigned int *)(cpu+0x50);\r
+}\r
+\r
\r
/* idle loop detection, not to be used in CD mode */\r
#ifdef EMU_C68K\r
-#include "cpu/Cyclone/tools/idle.h"\r
+#include "cpu/cyclone/tools/idle.h"\r
#endif\r
\r
static unsigned short **idledet_ptrs = NULL;\r