sek.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. /*
  2. * PicoDrive
  3. * (c) Copyright Dave, 2004
  4. * (C) notaz, 2006-2009
  5. *
  6. * This work is licensed under the terms of MAME license.
  7. * See COPYING file in the top-level directory.
  8. */
  9. #include "pico_int.h"
  10. #include "memory.h"
  11. /* context */
  12. // Cyclone 68000
  13. #ifdef EMU_C68K
  14. struct Cyclone PicoCpuCM68k;
  15. #endif
  16. // MUSASHI 68000
  17. #ifdef EMU_M68K
  18. m68ki_cpu_core PicoCpuMM68k;
  19. #endif
  20. // FAME 68000
  21. #ifdef EMU_F68K
  22. M68K_CONTEXT PicoCpuFM68k;
  23. #endif
  24. /* callbacks */
  25. #ifdef EMU_C68K
  26. // interrupt acknowledgment
  27. static int SekIntAck(int level)
  28. {
  29. // try to emulate VDP's reaction to 68000 int ack
  30. if (level == 4) { Pico.video.pending_ints = 0; elprintf(EL_INTS, "hack: @ %06x [%u]", SekPc, Pico.t.m68c_cnt); }
  31. else if(level == 6) { Pico.video.pending_ints &= ~0x20; elprintf(EL_INTS, "vack: @ %06x [%u]", SekPc, Pico.t.m68c_cnt); }
  32. PicoCpuCM68k.irq = 0;
  33. return CYCLONE_INT_ACK_AUTOVECTOR;
  34. }
  35. static void SekResetAck(void)
  36. {
  37. elprintf(EL_ANOMALY, "Reset encountered @ %06x", SekPc);
  38. }
  39. static int SekUnrecognizedOpcode()
  40. {
  41. unsigned int pc;
  42. pc = SekPc;
  43. elprintf(EL_ANOMALY, "Unrecognized Opcode @ %06x", pc);
  44. // see if we are still in a mapped region
  45. pc &= 0x00ffffff;
  46. if (map_flag_set(m68k_read16_map[pc >> M68K_MEM_SHIFT])) {
  47. elprintf(EL_STATUS|EL_ANOMALY, "m68k crash @%06x", pc);
  48. PicoCpuCM68k.cycles = 0;
  49. PicoCpuCM68k.state_flags |= 1;
  50. return 1;
  51. }
  52. // happened once - may happen again
  53. SekFinishIdleDet();
  54. #ifdef EMU_M68K // debugging cyclone
  55. {
  56. extern int have_illegal;
  57. have_illegal = 1;
  58. }
  59. #endif
  60. return 0;
  61. }
  62. #endif
  63. #ifdef EMU_M68K
  64. static int SekIntAckM68K(int level)
  65. {
  66. if (level == 4) { Pico.video.pending_ints = 0; elprintf(EL_INTS, "hack: @ %06x [%u]", SekPc, Pico.t.m68c_cnt); }
  67. else if(level == 6) { Pico.video.pending_ints &= ~0x20; elprintf(EL_INTS, "vack: @ %06x [%u]", SekPc, Pico.t.m68c_cnt); }
  68. CPU_INT_LEVEL = 0;
  69. return M68K_INT_ACK_AUTOVECTOR;
  70. }
  71. static int SekTasCallback(void)
  72. {
  73. return 0; // no writeback
  74. }
  75. #endif
  76. #ifdef EMU_F68K
  77. static void SekIntAckF68K(unsigned level)
  78. {
  79. if (level == 4) {
  80. Pico.video.pending_ints = 0;
  81. elprintf(EL_INTS, "hack: @ %06x [%u]", SekPc, SekCyclesDone());
  82. }
  83. else if(level == 6) {
  84. Pico.video.pending_ints &= ~0x20;
  85. elprintf(EL_INTS, "vack: @ %06x [%u]", SekPc, SekCyclesDone());
  86. }
  87. PicoCpuFM68k.interrupts[0] = 0;
  88. }
  89. #endif
  90. PICO_INTERNAL void SekInit(void)
  91. {
  92. #ifdef EMU_C68K
  93. CycloneInit();
  94. memset(&PicoCpuCM68k,0,sizeof(PicoCpuCM68k));
  95. PicoCpuCM68k.IrqCallback=SekIntAck;
  96. PicoCpuCM68k.ResetCallback=SekResetAck;
  97. PicoCpuCM68k.UnrecognizedCallback=SekUnrecognizedOpcode;
  98. PicoCpuCM68k.flags=4; // Z set
  99. #endif
  100. #ifdef EMU_M68K
  101. {
  102. void *oldcontext = m68ki_cpu_p;
  103. m68k_set_context(&PicoCpuMM68k);
  104. m68k_set_cpu_type(M68K_CPU_TYPE_68000);
  105. m68k_init();
  106. m68k_set_int_ack_callback(SekIntAckM68K);
  107. m68k_set_tas_instr_callback(SekTasCallback);
  108. //m68k_pulse_reset();
  109. m68k_set_context(oldcontext);
  110. }
  111. #endif
  112. #ifdef EMU_F68K
  113. {
  114. void *oldcontext = g_m68kcontext;
  115. g_m68kcontext = &PicoCpuFM68k;
  116. memset(&PicoCpuFM68k, 0, sizeof(PicoCpuFM68k));
  117. fm68k_init();
  118. PicoCpuFM68k.iack_handler = SekIntAckF68K;
  119. PicoCpuFM68k.sr = 0x2704; // Z flag
  120. g_m68kcontext = oldcontext;
  121. }
  122. #endif
  123. }
  124. // Reset the 68000:
  125. PICO_INTERNAL int SekReset(void)
  126. {
  127. if (Pico.rom==NULL) return 1;
  128. #ifdef EMU_C68K
  129. CycloneReset(&PicoCpuCM68k);
  130. #endif
  131. #ifdef EMU_M68K
  132. m68k_set_context(&PicoCpuMM68k); // if we ever reset m68k, we always need it's context to be set
  133. m68ki_cpu.sp[0]=0;
  134. m68k_set_irq(0);
  135. m68k_pulse_reset();
  136. REG_USP = 0; // ?
  137. #endif
  138. #ifdef EMU_F68K
  139. {
  140. g_m68kcontext = &PicoCpuFM68k;
  141. fm68k_reset();
  142. }
  143. #endif
  144. return 0;
  145. }
  146. void SekStepM68k(void)
  147. {
  148. Pico.t.m68c_aim = Pico.t.m68c_cnt + 1;
  149. #if defined(EMU_CORE_DEBUG)
  150. Pico.t.m68c_cnt += CM_compareRun(1, 0);
  151. #elif defined(EMU_C68K)
  152. PicoCpuCM68k.cycles=1;
  153. CycloneRun(&PicoCpuCM68k);
  154. Pico.t.m68c_cnt += 1 - PicoCpuCM68k.cycles;
  155. #elif defined(EMU_M68K)
  156. Pico.t.m68c_cnt += m68k_execute(1);
  157. #elif defined(EMU_F68K)
  158. Pico.t.m68c_cnt += fm68k_emulate(1, 0);
  159. #endif
  160. }
  161. PICO_INTERNAL void SekSetRealTAS(int use_real)
  162. {
  163. #ifdef EMU_C68K
  164. CycloneSetRealTAS(use_real);
  165. #endif
  166. #ifdef EMU_F68K
  167. // TODO
  168. #endif
  169. }
  170. // Pack the cpu into a common format:
  171. // XXX: rename
  172. PICO_INTERNAL void SekPackCpu(unsigned char *cpu, int is_sub)
  173. {
  174. unsigned int pc=0;
  175. #if defined(EMU_C68K)
  176. struct Cyclone *context = is_sub ? &PicoCpuCS68k : &PicoCpuCM68k;
  177. memcpy(cpu,context->d,0x40);
  178. pc=context->pc-context->membase;
  179. *(unsigned int *)(cpu+0x44)=CycloneGetSr(context);
  180. *(unsigned int *)(cpu+0x48)=context->osp;
  181. cpu[0x4c] = context->irq;
  182. cpu[0x4d] = context->state_flags & 1;
  183. #elif defined(EMU_M68K)
  184. void *oldcontext = m68ki_cpu_p;
  185. m68k_set_context(is_sub ? &PicoCpuMS68k : &PicoCpuMM68k);
  186. memcpy(cpu,m68ki_cpu_p->dar,0x40);
  187. pc=m68ki_cpu_p->pc;
  188. *(unsigned int *)(cpu+0x44)=m68k_get_reg(NULL, M68K_REG_SR);
  189. *(unsigned int *)(cpu+0x48)=m68ki_cpu_p->sp[m68ki_cpu_p->s_flag^SFLAG_SET];
  190. cpu[0x4c] = CPU_INT_LEVEL>>8;
  191. cpu[0x4d] = CPU_STOPPED;
  192. m68k_set_context(oldcontext);
  193. #elif defined(EMU_F68K)
  194. M68K_CONTEXT *context = is_sub ? &PicoCpuFS68k : &PicoCpuFM68k;
  195. memcpy(cpu,context->dreg,0x40);
  196. pc=context->pc;
  197. *(unsigned int *)(cpu+0x44)=context->sr;
  198. *(unsigned int *)(cpu+0x48)=context->asp;
  199. cpu[0x4c] = context->interrupts[0];
  200. cpu[0x4d] = (context->execinfo & FM68K_HALTED) ? 1 : 0;
  201. #endif
  202. *(unsigned int *)(cpu+0x40) = pc;
  203. *(unsigned int *)(cpu+0x50) =
  204. is_sub ? SekCycleCntS68k : Pico.t.m68c_cnt;
  205. }
  206. PICO_INTERNAL void SekUnpackCpu(const unsigned char *cpu, int is_sub)
  207. {
  208. #if defined(EMU_C68K)
  209. struct Cyclone *context = is_sub ? &PicoCpuCS68k : &PicoCpuCM68k;
  210. CycloneSetSr(context, *(unsigned int *)(cpu+0x44));
  211. context->osp=*(unsigned int *)(cpu+0x48);
  212. memcpy(context->d,cpu,0x40);
  213. context->membase = 0;
  214. context->pc = *(unsigned int *)(cpu+0x40);
  215. CycloneUnpack(context, NULL); // rebase PC
  216. context->irq = cpu[0x4c];
  217. context->state_flags = 0;
  218. if (cpu[0x4d])
  219. context->state_flags |= 1;
  220. #elif defined(EMU_M68K)
  221. void *oldcontext = m68ki_cpu_p;
  222. m68k_set_context(is_sub ? &PicoCpuMS68k : &PicoCpuMM68k);
  223. m68k_set_reg(M68K_REG_SR, *(unsigned int *)(cpu+0x44));
  224. memcpy(m68ki_cpu_p->dar,cpu,0x40);
  225. m68ki_cpu_p->pc=*(unsigned int *)(cpu+0x40);
  226. m68ki_cpu_p->sp[m68ki_cpu_p->s_flag^SFLAG_SET]=*(unsigned int *)(cpu+0x48);
  227. CPU_INT_LEVEL = cpu[0x4c] << 8;
  228. CPU_STOPPED = cpu[0x4d];
  229. m68k_set_context(oldcontext);
  230. #elif defined(EMU_F68K)
  231. M68K_CONTEXT *context = is_sub ? &PicoCpuFS68k : &PicoCpuFM68k;
  232. memcpy(context->dreg,cpu,0x40);
  233. context->pc =*(unsigned int *)(cpu+0x40);
  234. context->sr =*(unsigned int *)(cpu+0x44);
  235. context->asp=*(unsigned int *)(cpu+0x48);
  236. context->interrupts[0] = cpu[0x4c];
  237. context->execinfo &= ~FM68K_HALTED;
  238. if (cpu[0x4d]&1) context->execinfo |= FM68K_HALTED;
  239. #endif
  240. if (is_sub)
  241. SekCycleCntS68k = *(unsigned int *)(cpu+0x50);
  242. else
  243. Pico.t.m68c_cnt = *(unsigned int *)(cpu+0x50);
  244. }
  245. /* idle loop detection, not to be used in CD mode */
  246. #ifdef EMU_C68K
  247. #include "cpu/cyclone/tools/idle.h"
  248. #endif
  249. static unsigned short **idledet_ptrs = NULL;
  250. static int idledet_count = 0, idledet_bads = 0;
  251. static int idledet_start_frame = 0;
  252. #if 0
  253. #define IDLE_STATS 1
  254. unsigned int idlehit_addrs[128], idlehit_counts[128];
  255. void SekRegisterIdleHit(unsigned int pc)
  256. {
  257. int i;
  258. for (i = 0; i < 127 && idlehit_addrs[i]; i++) {
  259. if (idlehit_addrs[i] == pc) {
  260. idlehit_counts[i]++;
  261. return;
  262. }
  263. }
  264. idlehit_addrs[i] = pc;
  265. idlehit_counts[i] = 1;
  266. idlehit_addrs[i+1] = 0;
  267. }
  268. #endif
  269. void SekInitIdleDet(void)
  270. {
  271. unsigned short **tmp;
  272. tmp = realloc(idledet_ptrs, 0x200 * sizeof(tmp[0]));
  273. if (tmp == NULL) {
  274. free(idledet_ptrs);
  275. idledet_ptrs = NULL;
  276. }
  277. else
  278. idledet_ptrs = tmp;
  279. idledet_count = idledet_bads = 0;
  280. idledet_start_frame = Pico.m.frame_count + 360;
  281. #ifdef IDLE_STATS
  282. idlehit_addrs[0] = 0;
  283. #endif
  284. #ifdef EMU_C68K
  285. CycloneInitIdle();
  286. #endif
  287. #ifdef EMU_F68K
  288. fm68k_emulate(0, 1);
  289. #endif
  290. }
  291. int SekIsIdleReady(void)
  292. {
  293. return (Pico.m.frame_count >= idledet_start_frame);
  294. }
  295. int SekIsIdleCode(unsigned short *dst, int bytes)
  296. {
  297. // printf("SekIsIdleCode %04x %i\n", *dst, bytes);
  298. switch (bytes)
  299. {
  300. case 2:
  301. if ((*dst & 0xf000) != 0x6000) // not another branch
  302. return 1;
  303. break;
  304. case 4:
  305. if ( (*dst & 0xff3f) == 0x4a38 || // tst.x ($xxxx.w); tas ($xxxx.w)
  306. (*dst & 0xc1ff) == 0x0038 || // move.x ($xxxx.w), dX
  307. (*dst & 0xf13f) == 0xb038) // cmp.x ($xxxx.w), dX
  308. return 1;
  309. if (PicoAHW & (PAHW_MCD|PAHW_32X))
  310. break;
  311. // with no addons, there should be no need to wait
  312. // for byte change anywhere
  313. if ( (*dst & 0xfff8) == 0x4a10 || // tst.b ($aX)
  314. (*dst & 0xfff8) == 0x4a28) // tst.b ($xxxx,a0)
  315. return 1;
  316. break;
  317. case 6:
  318. if ( ((dst[1] & 0xe0) == 0xe0 && ( // RAM and
  319. *dst == 0x4a39 || // tst.b ($xxxxxxxx)
  320. *dst == 0x4a79 || // tst.w ($xxxxxxxx)
  321. *dst == 0x4ab9 || // tst.l ($xxxxxxxx)
  322. (*dst & 0xc1ff) == 0x0039 || // move.x ($xxxxxxxx), dX
  323. (*dst & 0xf13f) == 0xb039))||// cmp.x ($xxxxxxxx), dX
  324. *dst == 0x0838 || // btst $X, ($xxxx.w) [6 byte op]
  325. (*dst & 0xffbf) == 0x0c38) // cmpi.{b,w} $X, ($xxxx.w)
  326. return 1;
  327. break;
  328. case 8:
  329. if ( ((dst[2] & 0xe0) == 0xe0 && ( // RAM and
  330. *dst == 0x0839 || // btst $X, ($xxxxxxxx.w) [8 byte op]
  331. (*dst & 0xffbf) == 0x0c39))||// cmpi.{b,w} $X, ($xxxxxxxx)
  332. *dst == 0x0cb8) // cmpi.l $X, ($xxxx.w)
  333. return 1;
  334. break;
  335. case 12:
  336. if (PicoAHW & (PAHW_MCD|PAHW_32X))
  337. break;
  338. if ( (*dst & 0xf1f8) == 0x3010 && // move.w (aX), dX
  339. (dst[1]&0xf100) == 0x0000 && // arithmetic
  340. (dst[3]&0xf100) == 0x0000) // arithmetic
  341. return 1;
  342. break;
  343. }
  344. return 0;
  345. }
  346. int SekRegisterIdlePatch(unsigned int pc, int oldop, int newop, void *ctx)
  347. {
  348. int is_main68k = 1;
  349. u16 *target;
  350. uptr v;
  351. #if defined(EMU_C68K)
  352. struct Cyclone *cyc = ctx;
  353. is_main68k = cyc == &PicoCpuCM68k;
  354. pc -= cyc->membase;
  355. #elif defined(EMU_F68K)
  356. is_main68k = ctx == &PicoCpuFM68k;
  357. #endif
  358. pc &= ~0xff000000;
  359. if (!(newop&0x200))
  360. elprintf(EL_IDLE, "idle: patch %06x %04x %04x %c %c #%i", pc, oldop, newop,
  361. (newop&0x200)?'n':'y', is_main68k?'m':'s', idledet_count);
  362. // XXX: probably shouldn't patch RAM too
  363. v = m68k_read16_map[pc >> M68K_MEM_SHIFT];
  364. if (!(v & 0x80000000))
  365. target = (u16 *)((v << 1) + pc);
  366. else {
  367. if (++idledet_bads > 128)
  368. return 2; // remove detector
  369. return 1; // don't patch
  370. }
  371. if (idledet_count >= 0x200 && (idledet_count & 0x1ff) == 0) {
  372. unsigned short **tmp;
  373. tmp = realloc(idledet_ptrs, (idledet_count+0x200) * sizeof(tmp[0]));
  374. if (tmp == NULL)
  375. return 1;
  376. idledet_ptrs = tmp;
  377. }
  378. idledet_ptrs[idledet_count++] = target;
  379. return 0;
  380. }
  381. void SekFinishIdleDet(void)
  382. {
  383. if (idledet_count < 0)
  384. return;
  385. #ifdef EMU_C68K
  386. CycloneFinishIdle();
  387. #endif
  388. #ifdef EMU_F68K
  389. fm68k_emulate(0, 2);
  390. #endif
  391. while (idledet_count > 0)
  392. {
  393. unsigned short *op = idledet_ptrs[--idledet_count];
  394. if ((*op & 0xfd00) == 0x7100)
  395. *op &= 0xff, *op |= 0x6600;
  396. else if ((*op & 0xfd00) == 0x7500)
  397. *op &= 0xff, *op |= 0x6700;
  398. else if ((*op & 0xfd00) == 0x7d00)
  399. *op &= 0xff, *op |= 0x6000;
  400. else
  401. elprintf(EL_STATUS|EL_IDLE, "idle: don't know how to restore %04x", *op);
  402. }
  403. idledet_count = -1;
  404. }
  405. #if defined(CPU_CMP_R) || defined(CPU_CMP_W)
  406. #include "debug.h"
  407. struct ref_68k {
  408. u32 dar[16];
  409. u32 pc;
  410. u32 sr;
  411. u32 cycles;
  412. u32 pc_prev;
  413. };
  414. struct ref_68k ref_68ks[2];
  415. static int current_68k;
  416. void SekTrace(int is_s68k)
  417. {
  418. struct ref_68k *x68k = &ref_68ks[is_s68k];
  419. u32 pc = is_s68k ? SekPcS68k : SekPc;
  420. u32 sr = is_s68k ? SekSrS68k : SekSr;
  421. u32 cycles = is_s68k ? SekCycleCntS68k : Pico.t.m68c_cnt;
  422. u32 r;
  423. u8 cmd;
  424. #ifdef CPU_CMP_W
  425. int i;
  426. if (is_s68k != current_68k) {
  427. current_68k = is_s68k;
  428. cmd = CTL_68K_SLAVE | current_68k;
  429. tl_write(&cmd, sizeof(cmd));
  430. }
  431. if (pc != x68k->pc) {
  432. x68k->pc = pc;
  433. tl_write_uint(CTL_68K_PC, x68k->pc);
  434. }
  435. if (sr != x68k->sr) {
  436. x68k->sr = sr;
  437. tl_write_uint(CTL_68K_SR, x68k->sr);
  438. }
  439. for (i = 0; i < 16; i++) {
  440. r = is_s68k ? SekDarS68k(i) : SekDar(i);
  441. if (r != x68k->dar[i]) {
  442. x68k->dar[i] = r;
  443. tl_write_uint(CTL_68K_R + i, r);
  444. }
  445. }
  446. tl_write_uint(CTL_68K_CYCLES, cycles);
  447. #else
  448. int i, bad = 0;
  449. while (1)
  450. {
  451. int ret = tl_read(&cmd, sizeof(cmd));
  452. if (ret == 0) {
  453. elprintf(EL_STATUS, "EOF");
  454. exit(1);
  455. }
  456. switch (cmd) {
  457. case CTL_68K_SLAVE:
  458. case CTL_68K_SLAVE + 1:
  459. current_68k = cmd & 1;
  460. break;
  461. case CTL_68K_PC:
  462. tl_read_uint(&x68k->pc);
  463. break;
  464. case CTL_68K_SR:
  465. tl_read_uint(&x68k->sr);
  466. break;
  467. case CTL_68K_CYCLES:
  468. tl_read_uint(&x68k->cycles);
  469. goto breakloop;
  470. default:
  471. if (CTL_68K_R <= cmd && cmd < CTL_68K_R + 0x10)
  472. tl_read_uint(&x68k->dar[cmd - CTL_68K_R]);
  473. else
  474. elprintf(EL_STATUS, "invalid cmd: %02x", cmd);
  475. }
  476. }
  477. breakloop:
  478. if (is_s68k != current_68k) {
  479. printf("bad 68k: %d %d\n", is_s68k, current_68k);
  480. bad = 1;
  481. }
  482. if (cycles != x68k->cycles) {
  483. printf("bad cycles: %u %u\n", cycles, x68k->cycles);
  484. bad = 1;
  485. }
  486. if ((pc ^ x68k->pc) & 0xffffff) {
  487. printf("bad PC: %08x %08x\n", pc, x68k->pc);
  488. bad = 1;
  489. }
  490. if (sr != x68k->sr) {
  491. printf("bad SR: %03x %03x\n", sr, x68k->sr);
  492. bad = 1;
  493. }
  494. for (i = 0; i < 16; i++) {
  495. r = is_s68k ? SekDarS68k(i) : SekDar(i);
  496. if (r != x68k->dar[i]) {
  497. printf("bad %c%d: %08x %08x\n", i < 8 ? 'D' : 'A', i & 7,
  498. r, x68k->dar[i]);
  499. bad = 1;
  500. }
  501. }
  502. if (bad) {
  503. for (i = 0; i < 8; i++)
  504. printf("D%d: %08x A%d: %08x\n", i, x68k->dar[i],
  505. i, x68k->dar[i + 8]);
  506. printf("PC: %08x, %08x\n", x68k->pc, x68k->pc_prev);
  507. printf("SR: %04x\n", x68k->sr);
  508. PDebugDumpMem();
  509. exit(1);
  510. }
  511. x68k->pc_prev = x68k->pc;
  512. #endif
  513. }
  514. #endif // CPU_CMP_*
  515. #if defined(EMU_M68K) && M68K_INSTRUCTION_HOOK == OPT_SPECIFY_HANDLER
  516. static unsigned char op_flags[0x400000/2] = { 0, };
  517. static int atexit_set = 0;
  518. static void make_idc(void)
  519. {
  520. FILE *f = fopen("idc.idc", "w");
  521. int i;
  522. if (!f) return;
  523. fprintf(f, "#include <idc.idc>\nstatic main() {\n");
  524. for (i = 0; i < 0x400000/2; i++)
  525. if (op_flags[i] != 0)
  526. fprintf(f, " MakeCode(0x%06x);\n", i*2);
  527. fprintf(f, "}\n");
  528. fclose(f);
  529. }
  530. void instruction_hook(void)
  531. {
  532. if (!atexit_set) {
  533. atexit(make_idc);
  534. atexit_set = 1;
  535. }
  536. if (REG_PC < 0x400000)
  537. op_flags[REG_PC/2] = 1;
  538. }
  539. #endif
  540. // vim:shiftwidth=2:ts=2:expandtab