debug.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. /*
  2. * debug stuff
  3. * (C) notaz, 2006-2009
  4. *
  5. * This work is licensed under the terms of MAME license.
  6. * See COPYING file in the top-level directory.
  7. */
  8. #include "pico_int.h"
  9. #include "sound/ym2612.h"
  10. #include "memory.h"
  11. #include "debug.h"
  12. #define bit(r, x) ((r>>x)&1)
  13. #define MVP dstrp+=strlen(dstrp)
  14. void z80_debug(char *dstr);
  15. static char dstr[1024*8];
  16. char *PDebugMain(void)
  17. {
  18. struct PicoVideo *pv=&Pico.video;
  19. unsigned char *reg=pv->reg, r;
  20. int i, sprites_lo, sprites_hi;
  21. char *dstrp;
  22. sprites_lo = sprites_hi = 0;
  23. for (i = 0; Pico.est.HighPreSpr[i] != 0; i+=2)
  24. if (Pico.est.HighPreSpr[i+1] & 0x8000)
  25. sprites_hi++;
  26. else sprites_lo++;
  27. dstrp = dstr;
  28. sprintf(dstrp, "mode set 1: %02x spr lo: %2i, spr hi: %2i\n", (r=reg[0]), sprites_lo, sprites_hi); MVP;
  29. sprintf(dstrp, "display_disable: %i, M3: %i, palette: %i, ?, hints: %i\n", bit(r,0), bit(r,1), bit(r,2), bit(r,4)); MVP;
  30. sprintf(dstrp, "mode set 2: %02x hcnt: %i\n", (r=reg[1]), pv->reg[10]); MVP;
  31. sprintf(dstrp, "SMS/gen: %i, pal: %i, dma: %i, vints: %i, disp: %i, TMS: %i\n",bit(r,2),bit(r,3),bit(r,4),bit(r,5),bit(r,6),bit(r,7)); MVP;
  32. sprintf(dstrp, "mode set 3: %02x\n", (r=reg[0xB])); MVP;
  33. sprintf(dstrp, "LSCR: %i, HSCR: %i, 2cell vscroll: %i, IE2: %i\n", bit(r,0), bit(r,1), bit(r,2), bit(r,3)); MVP;
  34. sprintf(dstrp, "mode set 4: %02x\n", (r=reg[0xC])); MVP;
  35. sprintf(dstrp, "interlace: %i%i, cells: %i, shadow: %i\n", bit(r,2), bit(r,1), (r&0x80) ? 40 : 32, bit(r,3)); MVP;
  36. sprintf(dstrp, "scroll size: w: %i, h: %i SRAM: %i; eeprom: %i (%i)\n", reg[0x10]&3, (reg[0x10]&0x30)>>4,
  37. !!(Pico.sv.flags & SRF_ENABLED), !!(Pico.sv.flags & SRF_EEPROM), Pico.sv.eeprom_type); MVP;
  38. sprintf(dstrp, "sram range: %06x-%06x, reg: %02x\n", Pico.sv.start, Pico.sv.end, Pico.m.sram_reg); MVP;
  39. sprintf(dstrp, "pend int: v:%i, h:%i, vdp status: %04x\n", bit(pv->pending_ints,5), bit(pv->pending_ints,4), pv->status); MVP;
  40. sprintf(dstrp, "pal: %i, hw: %02x, frame#: %i, cycles: %u\n", Pico.m.pal, Pico.m.hardware, Pico.m.frame_count, SekCyclesDone()); MVP;
  41. sprintf(dstrp, "M68k: PC: %06x, SR: %04x, irql: %i\n", SekPc, SekSr, SekIrqLevel); MVP;
  42. for (r = 0; r < 8; r++) {
  43. sprintf(dstrp, "d%i=%08x, a%i=%08x\n", r, SekDar(r), r, SekDar(r+8)); MVP;
  44. }
  45. sprintf(dstrp, "z80Run: %i, z80_reset: %i, z80_bnk: %06x\n", Pico.m.z80Run, Pico.m.z80_reset, Pico.m.z80_bank68k<<15); MVP;
  46. z80_debug(dstrp); MVP;
  47. if (strlen(dstr) > sizeof(dstr))
  48. elprintf(EL_STATUS, "warning: debug buffer overflow (%i/%i)\n", strlen(dstr), sizeof(dstr));
  49. return dstr;
  50. }
  51. char *PDebug32x(void)
  52. {
  53. #ifndef NO_32X
  54. char *dstrp = dstr;
  55. unsigned short *r;
  56. int i;
  57. r = Pico32x.regs;
  58. sprintf(dstrp, "regs:\n"); MVP;
  59. for (i = 0; i < 0x40/2; i += 8) {
  60. sprintf(dstrp, "%02x: %04x %04x %04x %04x %04x %04x %04x %04x\n",
  61. i*2, r[i+0], r[i+1], r[i+2], r[i+3], r[i+4], r[i+5], r[i+6], r[i+7]); MVP;
  62. }
  63. r = Pico32x.sh2_regs;
  64. sprintf(dstrp, "SH: %04x %04x %04x IRQs: %02x eflags: %02x\n",
  65. r[0], r[1], r[2], Pico32x.sh2irqs, Pico32x.emu_flags); MVP;
  66. i = 0;
  67. r = Pico32x.vdp_regs;
  68. sprintf(dstrp, "VDP regs:\n"); MVP;
  69. sprintf(dstrp, "%02x: %04x %04x %04x %04x %04x %04x %04x %04x\n",
  70. i*2, r[i+0], r[i+1], r[i+2], r[i+3], r[i+4], r[i+5], r[i+6], r[i+7]); MVP;
  71. sprintf(dstrp, " mSH2 sSH2\n"); MVP;
  72. sprintf(dstrp, "PC,SR %08x, %03x %08x, %03x\n", sh2_pc(&msh2), sh2_sr(0), sh2_pc(&ssh2), sh2_sr(1)); MVP;
  73. for (i = 0; i < 16/2; i++) {
  74. sprintf(dstrp, "R%d,%2d %08x,%08x %08x,%08x\n", i, i + 8,
  75. sh2_reg(0,i), sh2_reg(0,i+8), sh2_reg(1,i), sh2_reg(1,i+8)); MVP;
  76. }
  77. sprintf(dstrp, "gb,vb %08x,%08x %08x,%08x\n", sh2_gbr(0), sh2_vbr(0), sh2_gbr(1), sh2_vbr(1)); MVP;
  78. sprintf(dstrp, "IRQs/mask: %02x/%02x %02x/%02x\n",
  79. Pico32x.sh2irqi[0], Pico32x.sh2irq_mask[0], Pico32x.sh2irqi[1], Pico32x.sh2irq_mask[1]); MVP;
  80. #else
  81. dstr[0] = 0;
  82. #endif
  83. return dstr;
  84. }
  85. char *PDebugSpriteList(void)
  86. {
  87. struct PicoVideo *pvid=&Pico.video;
  88. int table=0,u,link=0;
  89. int max_sprites = 80;
  90. char *dstrp;
  91. if (!(pvid->reg[12]&1))
  92. max_sprites = 64;
  93. dstr[0] = 0;
  94. dstrp = dstr;
  95. table=pvid->reg[5]&0x7f;
  96. if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode
  97. table<<=8; // Get sprite table address/2
  98. for (u=0; u < max_sprites; u++)
  99. {
  100. unsigned int *sprite;
  101. int code, code2, sx, sy, height;
  102. sprite=(unsigned int *)(PicoMem.vram+((table+(link<<2))&0x7ffc)); // Find sprite
  103. // get sprite info
  104. code = sprite[0];
  105. // check if it is on this line
  106. sy = (code&0x1ff)-0x80;
  107. height = ((code>>24)&3)+1;
  108. // masking sprite?
  109. code2 = sprite[1];
  110. sx = ((code2>>16)&0x1ff)-0x80;
  111. sprintf(dstrp, "#%02i x:%4i y:%4i %ix%i %s\n", u, sx, sy, ((code>>26)&3)+1, height,
  112. (code2&0x8000)?"hi":"lo");
  113. MVP;
  114. link=(code>>16)&0x7f;
  115. if(!link) break; // End of sprites
  116. }
  117. return dstr;
  118. }
  119. #define GREEN1 0x0700
  120. #ifdef USE_BGR555
  121. #define YELLOW1 0x071c
  122. #define BLUE1 0xf000
  123. #define RED1 0x001e
  124. #else
  125. #define YELLOW1 0xe700
  126. #define BLUE1 0x001e
  127. #define RED1 0xf000
  128. #endif
  129. static void set16(unsigned short *p, unsigned short d, int cnt)
  130. {
  131. while (cnt-- > 0)
  132. *p++ = d;
  133. }
  134. void PDebugShowSpriteStats(unsigned short *screen, int stride)
  135. {
  136. int lines, i, u, step;
  137. unsigned short *dest;
  138. unsigned char *p;
  139. step = (320-4*4-1) / MAX_LINE_SPRITES;
  140. lines = 240;
  141. if (!Pico.m.pal || !(Pico.video.reg[1]&8))
  142. lines = 224, screen += stride*8;
  143. for (i = 0; i < lines; i++)
  144. {
  145. dest = screen + stride*i;
  146. p = &HighLnSpr[i][0];
  147. // sprite graphs
  148. for (u = 0; u < (p[0] & 0x7f); u++) {
  149. set16(dest, (p[3+u] & 0x80) ? YELLOW1 : GREEN1, step);
  150. dest += step;
  151. }
  152. // flags
  153. dest = screen + stride*i + 320-4*4;
  154. if (p[1] & 0x40) set16(dest+4*0, GREEN1, 4);
  155. if (p[1] & 0x80) set16(dest+4*1, YELLOW1, 4);
  156. if (p[1] & 0x20) set16(dest+4*2, BLUE1, 4);
  157. if (p[1] & 0x10) set16(dest+4*3, RED1, 4);
  158. }
  159. // draw grid
  160. for (i = step*5; i <= 320-4*4-1; i += step*5) {
  161. for (u = 0; u < lines; u++)
  162. screen[i + u*stride] = 0x182;
  163. }
  164. }
  165. void PDebugShowPalette(unsigned short *screen, int stride)
  166. {
  167. struct PicoEState *est = &Pico.est;
  168. int x, y;
  169. Pico.m.dirtyPal = 1;
  170. if (PicoAHW & PAHW_SMS)
  171. PicoDoHighPal555M4();
  172. else
  173. PicoDoHighPal555(1, 0, est);
  174. Pico.m.dirtyPal = 1;
  175. screen += 16*stride+8;
  176. for (y = 0; y < 8*4; y++)
  177. for (x = 0; x < 8*16; x++)
  178. screen[x + y*stride] = est->HighPal[x/8 + (y/8)*16];
  179. screen += 160;
  180. for (y = 0; y < 8*4; y++)
  181. for (x = 0; x < 8*16; x++)
  182. screen[x + y*stride] = est->HighPal[(x/8 + (y/8)*16) | 0x40];
  183. screen += stride*48;
  184. for (y = 0; y < 8*4; y++)
  185. for (x = 0; x < 8*16; x++)
  186. screen[x + y*stride] = est->HighPal[(x/8 + (y/8)*16) | 0x80];
  187. }
  188. #if defined(DRAW2_OVERRIDE_LINE_WIDTH)
  189. #define DRAW2_LINE_WIDTH DRAW2_OVERRIDE_LINE_WIDTH
  190. #else
  191. #define DRAW2_LINE_WIDTH 328
  192. #endif
  193. void PDebugShowSprite(unsigned short *screen, int stride, int which)
  194. {
  195. struct PicoVideo *pvid=&Pico.video;
  196. int table=0,u,link=0,*sprite=0,*fsprite,oldsprite[2];
  197. int x,y,max_sprites = 80, oldcol, oldreg;
  198. unsigned char olddbg;
  199. if (!(pvid->reg[12]&1))
  200. max_sprites = 64;
  201. table=pvid->reg[5]&0x7f;
  202. if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode
  203. table<<=8; // Get sprite table address/2
  204. for (u=0; u < max_sprites && u <= which; u++)
  205. {
  206. sprite=(int *)(PicoMem.vram+((table+(link<<2))&0x7ffc)); // Find sprite
  207. link=(sprite[0]>>16)&0x7f;
  208. if (!link) break; // End of sprites
  209. }
  210. if (u >= max_sprites) return;
  211. fsprite = (int *)(PicoMem.vram+(table&0x7ffc));
  212. oldsprite[0] = fsprite[0];
  213. oldsprite[1] = fsprite[1];
  214. fsprite[0] = (sprite[0] & ~0x007f01ff) | 0x000080;
  215. fsprite[1] = (sprite[1] & ~0x01ff8000) | 0x800000;
  216. oldreg = pvid->reg[7];
  217. oldcol = PicoMem.cram[0];
  218. olddbg = pvid->debug_p;
  219. pvid->reg[7] = 0;
  220. PicoMem.cram[0] = 0;
  221. pvid->debug_p = PVD_KILL_A | PVD_KILL_B;
  222. PicoFrameFull();
  223. for (y = 0; y < 8*4; y++)
  224. {
  225. unsigned char *ps = Pico.est.Draw2FB + DRAW2_LINE_WIDTH*y + 8;
  226. for (x = 0; x < 8*4; x++)
  227. if (ps[x]) screen[x] = Pico.est.HighPal[ps[x]], ps[x] = 0;
  228. screen += stride;
  229. }
  230. fsprite[0] = oldsprite[0];
  231. fsprite[1] = oldsprite[1];
  232. pvid->reg[7] = oldreg;
  233. PicoMem.cram[0] = oldcol;
  234. pvid->debug_p = olddbg;
  235. }
  236. #define dump_ram_m(ram,fname,mode) \
  237. { \
  238. unsigned short *sram = (unsigned short *) ram; \
  239. FILE *f; \
  240. int i; \
  241. \
  242. for (i = 0; i < sizeof(ram)/2; i++) \
  243. sram[i] = (sram[i]<<8) | (sram[i]>>8); \
  244. f = fopen(fname, mode); \
  245. if (f) { \
  246. fwrite(ram, 1, sizeof(ram), f); \
  247. fclose(f); \
  248. } \
  249. for (i = 0; i < sizeof(ram)/2; i++) \
  250. sram[i] = (sram[i]<<8) | (sram[i]>>8); \
  251. }
  252. #define dump_ram(ram,fname) \
  253. dump_ram_m(ram,fname,"wb")
  254. #define dump_ram_noswab(ram,fname) \
  255. { \
  256. FILE *f; \
  257. f = fopen(fname, "wb"); \
  258. if (f) { \
  259. fwrite(ram, 1, sizeof(ram), f); \
  260. fclose(f); \
  261. } \
  262. }
  263. void PDebugDumpMem(void)
  264. {
  265. #if 0
  266. char buf[1 << M68K_MEM_SHIFT];
  267. unsigned int a;
  268. for (a = 0; ; a++) {
  269. uptr v = m68k_read16_map[a];
  270. if (map_flag_set(v))
  271. break;
  272. v <<= 1;
  273. v += a << M68K_MEM_SHIFT;
  274. memcpy(buf, (void *)v, sizeof(buf));
  275. dump_ram_m(buf, "dumps/cart.bin", a ? "ab" : "wb");
  276. }
  277. #endif
  278. dump_ram_noswab(PicoMem.zram, "dumps/zram.bin");
  279. dump_ram(PicoMem.cram, "dumps/cram.bin");
  280. if (PicoAHW & PAHW_SMS)
  281. {
  282. dump_ram_noswab(PicoMem.vramb, "dumps/vram.bin");
  283. }
  284. else
  285. {
  286. dump_ram(PicoMem.ram, "dumps/ram.bin");
  287. dump_ram(PicoMem.vram, "dumps/vram.bin");
  288. dump_ram(PicoMem.vsram,"dumps/vsram.bin");
  289. }
  290. if (PicoAHW & PAHW_MCD)
  291. {
  292. dump_ram(Pico_mcd->prg_ram, "dumps/prg_ram.bin");
  293. if (Pico_mcd->s68k_regs[3]&4) // 1M mode?
  294. wram_1M_to_2M(Pico_mcd->word_ram2M);
  295. dump_ram(Pico_mcd->word_ram2M, "dumps/word_ram_2M.bin");
  296. wram_2M_to_1M(Pico_mcd->word_ram2M);
  297. dump_ram(Pico_mcd->word_ram1M[0], "dumps/word_ram_1M_0.bin");
  298. dump_ram(Pico_mcd->word_ram1M[1], "dumps/word_ram_1M_1.bin");
  299. if (!(Pico_mcd->s68k_regs[3]&4)) // 2M mode?
  300. wram_2M_to_1M(Pico_mcd->word_ram2M);
  301. dump_ram_noswab(Pico_mcd->pcm_ram,"dumps/pcm_ram.bin");
  302. dump_ram_noswab(Pico_mcd->bram, "dumps/bram.bin");
  303. }
  304. #ifndef NO_32X
  305. if (PicoAHW & PAHW_32X)
  306. {
  307. dump_ram(Pico32xMem->sdram, "dumps/sdram.bin");
  308. dump_ram(Pico32xMem->dram[0], "dumps/dram0.bin");
  309. dump_ram(Pico32xMem->dram[1], "dumps/dram1.bin");
  310. dump_ram(Pico32xMem->pal, "dumps/pal32x.bin");
  311. dump_ram(msh2.data_array, "dumps/data_array0.bin");
  312. dump_ram(ssh2.data_array, "dumps/data_array1.bin");
  313. }
  314. #endif
  315. }
  316. void PDebugZ80Frame(void)
  317. {
  318. int lines, line_sample;
  319. if (PicoAHW & PAHW_SMS)
  320. return;
  321. if (Pico.m.pal) {
  322. lines = 313;
  323. line_sample = 68;
  324. } else {
  325. lines = 262;
  326. line_sample = 93;
  327. }
  328. z80_resetCycles();
  329. PsndStartFrame();
  330. if (/*Pico.m.z80Run &&*/ !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
  331. PicoSyncZ80(Pico.t.m68c_cnt + line_sample * 488);
  332. if (PsndOut)
  333. PsndGetSamples(line_sample);
  334. if (/*Pico.m.z80Run &&*/ !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) {
  335. PicoSyncZ80(Pico.t.m68c_cnt + 224 * 488);
  336. z80_int();
  337. }
  338. if (PsndOut)
  339. PsndGetSamples(224);
  340. // sync z80
  341. if (/*Pico.m.z80Run &&*/ !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) {
  342. Pico.t.m68c_cnt += Pico.m.pal ? 151809 : 127671; // cycles adjusted for converter
  343. PicoSyncZ80(Pico.t.m68c_cnt);
  344. }
  345. if (PsndOut && ym2612.dacen && PsndDacLine < lines)
  346. PsndDoDAC(lines - 1);
  347. PsndDoPSG(lines - 1);
  348. timers_cycle();
  349. Pico.t.m68c_aim = Pico.t.m68c_cnt;
  350. }
  351. void PDebugCPUStep(void)
  352. {
  353. if (PicoAHW & PAHW_SMS)
  354. z80_run_nr(1);
  355. else
  356. SekStepM68k();
  357. }
  358. #ifdef EVT_LOG
  359. static struct evt_t {
  360. unsigned int cycles;
  361. short cpu;
  362. short evt;
  363. } *evts;
  364. static int first_frame;
  365. static int evt_alloc;
  366. static int evt_cnt;
  367. void pevt_log(unsigned int cycles, enum evt_cpu c, enum evt e)
  368. {
  369. if (first_frame == 0)
  370. first_frame = Pico.m.frame_count;
  371. if (evt_alloc == evt_cnt) {
  372. evt_alloc = evt_alloc * 2 + 16 * 1024;
  373. evts = realloc(evts, evt_alloc * sizeof(evts[0]));
  374. }
  375. evts[evt_cnt].cycles = cycles;
  376. evts[evt_cnt].cpu = c;
  377. evts[evt_cnt].evt = e;
  378. evt_cnt++;
  379. }
  380. static int evt_cmp(const void *p1, const void *p2)
  381. {
  382. const struct evt_t *e1 = p1, *e2 = p2;
  383. int ret = (int)(e1->cycles - e2->cycles);
  384. if (ret)
  385. return ret;
  386. if (e1->evt == EVT_RUN_END || e1->evt == EVT_POLL_END)
  387. return -1;
  388. if (e1->evt == EVT_RUN_START || e1->evt == EVT_POLL_START)
  389. return 1;
  390. if (e2->evt == EVT_RUN_END || e2->evt == EVT_POLL_END)
  391. return 1;
  392. if (e1->evt == EVT_RUN_START || e1->evt == EVT_POLL_START)
  393. return -1;
  394. return 0;
  395. }
  396. void pevt_dump(void)
  397. {
  398. static const char *evt_names[EVT_CNT] = {
  399. "x", "x", "+run", "-run", "+poll", "-poll",
  400. };
  401. char evt_print[EVT_CPU_CNT][EVT_CNT] = {{0,}};
  402. unsigned int start_cycles[EVT_CPU_CNT] = {0,};
  403. unsigned int run_cycles[EVT_CPU_CNT] = {0,};
  404. unsigned int frame_cycles[EVT_CPU_CNT] = {0,};
  405. unsigned int frame_resched[EVT_CPU_CNT] = {0,};
  406. unsigned int cycles = 0;
  407. int frame = first_frame - 1;
  408. int line = 0;
  409. int cpu_mask = 0;
  410. int dirty = 0;
  411. int i;
  412. qsort(evts, evt_cnt, sizeof(evts[0]), evt_cmp);
  413. for (i = 0; i < evt_cnt; i++) {
  414. int c = evts[i].cpu, e = evts[i].evt;
  415. int ei, ci;
  416. if (cycles != evts[i].cycles || (cpu_mask & (1 << c))
  417. || e == EVT_FRAME_START || e == EVT_NEXT_LINE)
  418. {
  419. if (dirty) {
  420. printf("%u:%03u:%u ", frame, line, cycles);
  421. for (ci = 0; ci < EVT_CPU_CNT; ci++) {
  422. int found = 0;
  423. for (ei = 0; ei < EVT_CNT; ei++) {
  424. if (evt_print[ci][ei]) {
  425. if (ei == EVT_RUN_END) {
  426. printf("%8s%4d", evt_names[ei], run_cycles[ci]);
  427. run_cycles[ci] = 0;
  428. }
  429. else
  430. printf("%8s ", evt_names[ei]);
  431. found = 1;
  432. }
  433. }
  434. if (!found)
  435. printf("%12s", "");
  436. }
  437. printf("\n");
  438. memset(evt_print, 0, sizeof(evt_print));
  439. cpu_mask = 0;
  440. dirty = 0;
  441. }
  442. cycles = evts[i].cycles;
  443. }
  444. switch (e) {
  445. case EVT_FRAME_START:
  446. frame++;
  447. line = 0;
  448. printf("%u:%03u:%u ", frame, line, cycles);
  449. for (ci = 0; ci < EVT_CPU_CNT; ci++) {
  450. printf("%12u", frame_cycles[ci]);
  451. frame_cycles[ci] = 0;
  452. }
  453. printf("\n");
  454. printf("%u:%03u:%u ", frame, line, cycles);
  455. for (ci = 0; ci < EVT_CPU_CNT; ci++) {
  456. printf("%12u", frame_resched[ci]);
  457. frame_resched[ci] = 0;
  458. }
  459. printf("\n");
  460. break;
  461. case EVT_NEXT_LINE:
  462. line++;
  463. printf("%u:%03u:%u\n", frame, line, cycles);
  464. break;
  465. case EVT_RUN_START:
  466. start_cycles[c] = cycles;
  467. goto default_;
  468. case EVT_RUN_END:
  469. run_cycles[c] += cycles - start_cycles[c];
  470. frame_cycles[c] += cycles - start_cycles[c];
  471. frame_resched[c]++;
  472. goto default_;
  473. default_:
  474. default:
  475. evt_print[c][e] = 1;
  476. cpu_mask |= 1 << c;
  477. dirty = 1;
  478. break;
  479. }
  480. }
  481. }
  482. #endif
  483. #if defined(CPU_CMP_R) || defined(CPU_CMP_W) || defined(DRC_CMP)
  484. static FILE *tl_f;
  485. void tl_write(const void *ptr, size_t size)
  486. {
  487. if (tl_f == NULL)
  488. tl_f = fopen("tracelog", "wb");
  489. fwrite(ptr, 1, size, tl_f);
  490. }
  491. void tl_write_uint(unsigned char ctl, unsigned int v)
  492. {
  493. tl_write(&ctl, sizeof(ctl));
  494. tl_write(&v, sizeof(v));
  495. }
  496. int tl_read(void *ptr, size_t size)
  497. {
  498. if (tl_f == NULL)
  499. tl_f = fopen("tracelog", "rb");
  500. return fread(ptr, 1, size, tl_f);
  501. }
  502. int tl_read_uint(void *ptr)
  503. {
  504. return tl_read(ptr, 4);
  505. }
  506. #endif
  507. // vim:shiftwidth=2:ts=2:expandtab