\r
\r
#include "pico_int.h"\r
+#include "memory.h"\r
\r
\r
int SekCycleCnt=0; // cycles done in this frame\r
#include "cpu/Cyclone/tools/idle.h"\r
#endif\r
\r
-static int *idledet_addrs = NULL;\r
+static unsigned short **idledet_ptrs = NULL;\r
static int idledet_count = 0, idledet_bads = 0;\r
int idledet_start_frame = 0;\r
\r
\r
void SekInitIdleDet(void)\r
{\r
- void *tmp = realloc(idledet_addrs, 0x200*4);\r
+ unsigned short **tmp = realloc(idledet_ptrs, 0x200*4);\r
if (tmp == NULL) {\r
- free(idledet_addrs);\r
- idledet_addrs = NULL;\r
+ free(idledet_ptrs);\r
+ idledet_ptrs = NULL;\r
}\r
else\r
- idledet_addrs = tmp;\r
+ idledet_ptrs = tmp;\r
idledet_count = idledet_bads = 0;\r
idledet_start_frame = Pico.m.frame_count + 360;\r
#ifdef IDLE_STATS\r
int SekRegisterIdlePatch(unsigned int pc, int oldop, int newop, void *ctx)\r
{\r
int is_main68k = 1;\r
+ u16 *target;\r
+ uptr v;\r
+\r
#if defined(EMU_C68K)\r
struct Cyclone *cyc = ctx;\r
is_main68k = cyc == &PicoCpuCM68k;\r
elprintf(EL_IDLE, "idle: patch %06x %04x %04x %c %c #%i", pc, oldop, newop,\r
(newop&0x200)?'n':'y', is_main68k?'m':'s', idledet_count);\r
\r
- if (pc > Pico.romsize && !(PicoAHW & PAHW_SVP)) {\r
- if (++idledet_bads > 128) return 2; // remove detector\r
+ // XXX: probably shouldn't patch RAM too\r
+ v = m68k_read16_map[pc >> M68K_MEM_SHIFT];\r
+ if (!(v & 0x80000000))\r
+ target = (u16 *)((v << 1) + pc);\r
+ else {\r
+ if (++idledet_bads > 128)\r
+ return 2; // remove detector\r
return 1; // don't patch\r
}\r
\r
if (idledet_count >= 0x200 && (idledet_count & 0x1ff) == 0) {\r
- void *tmp = realloc(idledet_addrs, (idledet_count+0x200)*4);\r
- if (tmp == NULL) return 1;\r
- idledet_addrs = tmp;\r
+ unsigned short **tmp = realloc(idledet_ptrs, (idledet_count+0x200)*4);\r
+ if (tmp == NULL)\r
+ return 1;\r
+ idledet_ptrs = tmp;\r
}\r
\r
- if (pc < Pico.romsize)\r
- idledet_addrs[idledet_count++] = pc;\r
+ idledet_ptrs[idledet_count++] = target;\r
\r
return 0;\r
}\r
#endif\r
while (idledet_count > 0)\r
{\r
- unsigned short *op = (unsigned short *)&Pico.rom[idledet_addrs[--idledet_count]];\r
+ unsigned short *op = idledet_ptrs[--idledet_count];\r
if ((*op & 0xfd00) == 0x7100)\r
*op &= 0xff, *op |= 0x6600;\r
else if ((*op & 0xfd00) == 0x7500)\r