debug.c 16 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, "VDP regs 00-07: %02x %02x %02x %02x %02x %02x %02x %02x\n",reg[0],reg[1],reg[2],reg[3],reg[4],reg[5],reg[6],reg[7]); MVP;
  41. sprintf(dstrp, "VDP regs 08-0f: %02x %02x %02x %02x %02x %02x %02x %02x\n",reg[8],reg[9],reg[10],reg[11],reg[12],reg[13],reg[14],reg[15]); MVP;
  42. sprintf(dstrp, "VDP regs 10-17: %02x %02x %02x %02x %02x %02x %02x %02x\n",reg[16],reg[17],reg[18],reg[19],reg[20],reg[21],reg[22],reg[23]); MVP;
  43. sprintf(dstrp, "VDP regs 18-1f: %02x %02x %02x %02x %02x %02x %02x %02x\n",reg[24],reg[25],reg[26],reg[27],reg[28],reg[29],reg[30],reg[31]); MVP;
  44. r = (reg[5]<<9)+(reg[6]<<11);
  45. sprintf(dstrp, "sprite #0: %04x %04x %04x %04x\n",PicoMem.vram[r/2],PicoMem.vram[r/2+1],PicoMem.vram[r/2+2],PicoMem.vram[r/2+3]); MVP;
  46. sprintf(dstrp, "pal: %i, hw: %02x, frame#: %i, cycles: %u\n", Pico.m.pal, Pico.m.hardware, Pico.m.frame_count, SekCyclesDone()); MVP;
  47. sprintf(dstrp, "M68k: PC: %06lx, SR: %04x, irql: %i\n", (ulong)SekPc, SekSr, SekIrqLevel); MVP;
  48. for (r = 0; r < 8; r++) {
  49. sprintf(dstrp, "d%i=%08lx, a%i=%08lx\n", r, (ulong)SekDar(r), r, (ulong)SekDar(r+8)); MVP;
  50. }
  51. sprintf(dstrp, "z80Run: %i, z80_reset: %i, z80_bnk: %06x\n", Pico.m.z80Run, Pico.m.z80_reset, Pico.m.z80_bank68k<<15); MVP;
  52. z80_debug(dstrp); MVP;
  53. if (strlen(dstr) > sizeof(dstr))
  54. elprintf(EL_STATUS, "warning: debug buffer overflow (%i/%i)\n", strlen(dstr), sizeof(dstr));
  55. return dstr;
  56. }
  57. char *PDebug32x(void)
  58. {
  59. #ifndef NO_32X
  60. char *dstrp = dstr;
  61. unsigned short *r;
  62. int i;
  63. r = Pico32x.regs;
  64. sprintf(dstrp, "regs:\n"); MVP;
  65. for (i = 0; i < 0x40/2; i += 8) {
  66. sprintf(dstrp, "%02x: %04x %04x %04x %04x %04x %04x %04x %04x\n",
  67. 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;
  68. }
  69. r = Pico32x.sh2_regs;
  70. sprintf(dstrp, "SH: %04x %04x %04x IRQs: %02x eflags: %02x\n",
  71. r[0], r[1], r[2], Pico32x.sh2irqs, Pico32x.emu_flags); MVP;
  72. i = 0;
  73. r = Pico32x.vdp_regs;
  74. sprintf(dstrp, "VDP regs:\n"); MVP;
  75. sprintf(dstrp, "%02x: %04x %04x %04x %04x %04x %04x %04x %04x\n",
  76. 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;
  77. sprintf(dstrp, " mSH2 sSH2\n"); MVP;
  78. sprintf(dstrp, "PC,SR %08lx, %03x %08lx, %03x\n", (ulong)sh2_pc(&msh2), (uint)sh2_sr(0), (ulong)sh2_pc(&ssh2), (uint)sh2_sr(1)); MVP;
  79. for (i = 0; i < 16/2; i++) {
  80. sprintf(dstrp, "R%d,%2d %08lx,%08lx %08lx,%08lx\n", i, i + 8,
  81. (ulong)sh2_reg(0,i), (ulong)sh2_reg(0,i+8), (ulong)sh2_reg(1,i), (ulong)sh2_reg(1,i+8)); MVP;
  82. }
  83. sprintf(dstrp, "gb,vb %08lx,%08lx %08lx,%08lx\n", (ulong)sh2_gbr(0), (ulong)sh2_vbr(0), (ulong)sh2_gbr(1), (ulong)sh2_vbr(1)); MVP;
  84. sprintf(dstrp, "IRQs/mask: %02x/%02x %02x/%02x\n",
  85. Pico32x.sh2irqi[0], Pico32x.sh2irq_mask[0], Pico32x.sh2irqi[1], Pico32x.sh2irq_mask[1]); MVP;
  86. #else
  87. dstr[0] = 0;
  88. #endif
  89. return dstr;
  90. }
  91. char *PDebugSpriteList(void)
  92. {
  93. struct PicoVideo *pvid=&Pico.video;
  94. int table=0,u,link=0;
  95. int max_sprites = 80;
  96. char *dstrp;
  97. if (!(pvid->reg[12]&1))
  98. max_sprites = 64;
  99. dstr[0] = 0;
  100. dstrp = dstr;
  101. table=pvid->reg[5]&0x7f;
  102. if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode
  103. table<<=8; // Get sprite table address/2
  104. for (u=0; u < max_sprites; u++)
  105. {
  106. unsigned int *sprite;
  107. int code, code2, sx, sy, height;
  108. sprite=(unsigned int *)(PicoMem.vram+((table+(link<<2))&0x7ffc)); // Find sprite
  109. // get sprite info
  110. code = sprite[0];
  111. // check if it is on this line
  112. sy = (code&0x1ff)-0x80;
  113. height = ((code>>24)&3)+1;
  114. // masking sprite?
  115. code2 = sprite[1];
  116. sx = ((code2>>16)&0x1ff)-0x80;
  117. sprintf(dstrp, "#%02i x:%4i y:%4i %ix%i %s\n", u, sx, sy, ((code>>26)&3)+1, height,
  118. (code2&0x8000)?"hi":"lo");
  119. MVP;
  120. link=(code>>16)&0x7f;
  121. if(!link) break; // End of sprites
  122. }
  123. return dstr;
  124. }
  125. #define GREEN1 0x0700
  126. #if defined(USE_BGR555)
  127. #define YELLOW1 0x039c
  128. #define BLUE1 0x7800
  129. #define RED1 0x001e
  130. #elif defined(USE_BGR565)
  131. #define YELLOW1 0x071c
  132. #define BLUE1 0xf000
  133. #define RED1 0x001e
  134. #else
  135. #define YELLOW1 0xe700
  136. #define BLUE1 0x001e
  137. #define RED1 0xf000
  138. #endif
  139. static void set16(unsigned short *p, unsigned short d, int cnt)
  140. {
  141. while (cnt-- > 0)
  142. *p++ = d;
  143. }
  144. void PDebugShowSpriteStats(unsigned short *screen, int stride)
  145. {
  146. int lines, i, u, step;
  147. unsigned short *dest;
  148. unsigned char *p;
  149. step = (320-4*4-1) / MAX_LINE_SPRITES;
  150. lines = 240;
  151. if (!Pico.m.pal || !(Pico.video.reg[1]&8))
  152. lines = 224, screen += stride*8;
  153. for (i = 0; i < lines; i++)
  154. {
  155. dest = screen + stride*i;
  156. p = &HighLnSpr[i][0];
  157. // sprite graphs
  158. for (u = 0; u < (p[0] & 0x7f); u++) {
  159. set16(dest, (p[3+u] & 0x80) ? YELLOW1 : GREEN1, step);
  160. dest += step;
  161. }
  162. // flags
  163. dest = screen + stride*i + 320-4*4;
  164. if (p[1] & 0x40) set16(dest+4*0, GREEN1, 4);
  165. if (p[1] & 0x80) set16(dest+4*1, YELLOW1, 4);
  166. if (p[1] & 0x20) set16(dest+4*2, BLUE1, 4);
  167. if (p[1] & 0x10) set16(dest+4*3, RED1, 4);
  168. }
  169. // draw grid
  170. for (i = step*5; i <= 320-4*4-1; i += step*5) {
  171. for (u = 0; u < lines; u++)
  172. screen[i + u*stride] = 0x182;
  173. }
  174. }
  175. void PDebugShowPalette(unsigned short *screen, int stride)
  176. {
  177. struct PicoEState *est = &Pico.est;
  178. int x, y;
  179. Pico.m.dirtyPal = 1;
  180. if (PicoIn.AHW & PAHW_SMS)
  181. PicoDoHighPal555SMS();
  182. else
  183. PicoDoHighPal555(1, 0, est);
  184. Pico.m.dirtyPal = 1;
  185. screen += 16*stride+8;
  186. for (y = 0; y < 8*4; y++)
  187. for (x = 0; x < 8*16; x++)
  188. screen[x + y*stride] = est->HighPal[x/8 + (y/8)*16];
  189. screen += 160;
  190. for (y = 0; y < 8*4; y++)
  191. for (x = 0; x < 8*16; x++)
  192. screen[x + y*stride] = est->HighPal[(x/8 + (y/8)*16) | 0x40];
  193. screen += stride*48;
  194. for (y = 0; y < 8*4; y++)
  195. for (x = 0; x < 8*16; x++)
  196. screen[x + y*stride] = est->HighPal[(x/8 + (y/8)*16) | 0x80];
  197. }
  198. #if defined(DRAW2_OVERRIDE_LINE_WIDTH)
  199. #define DRAW2_LINE_WIDTH DRAW2_OVERRIDE_LINE_WIDTH
  200. #else
  201. #define DRAW2_LINE_WIDTH 328
  202. #endif
  203. void PDebugShowSprite(unsigned short *screen, int stride, int which)
  204. {
  205. struct PicoVideo *pvid=&Pico.video;
  206. int table=0,u,link=0,*sprite=0,*fsprite,oldsprite[2];
  207. int x,y,max_sprites = 80, oldcol, oldreg;
  208. unsigned char olddbg;
  209. if (!(pvid->reg[12]&1))
  210. max_sprites = 64;
  211. table=pvid->reg[5]&0x7f;
  212. if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode
  213. table<<=8; // Get sprite table address/2
  214. for (u=0; u < max_sprites && u <= which; u++)
  215. {
  216. sprite=(int *)(PicoMem.vram+((table+(link<<2))&0x7ffc)); // Find sprite
  217. link=(sprite[0]>>16)&0x7f;
  218. if (!link) break; // End of sprites
  219. }
  220. if (u >= max_sprites) return;
  221. fsprite = (int *)(PicoMem.vram+(table&0x7ffc));
  222. oldsprite[0] = fsprite[0];
  223. oldsprite[1] = fsprite[1];
  224. fsprite[0] = (sprite[0] & ~0x007f01ff) | 0x000080;
  225. fsprite[1] = (sprite[1] & ~0x01ff8000) | 0x800000;
  226. oldreg = pvid->reg[7];
  227. oldcol = PicoMem.cram[0];
  228. olddbg = pvid->debug_p;
  229. pvid->reg[7] = 0;
  230. PicoMem.cram[0] = 0;
  231. pvid->debug_p = PVD_KILL_A | PVD_KILL_B;
  232. PicoFrameFull();
  233. for (y = 0; y < 8*4; y++)
  234. {
  235. unsigned char *ps = Pico.est.Draw2FB + DRAW2_LINE_WIDTH*y + 8;
  236. for (x = 0; x < 8*4; x++)
  237. if (ps[x]) screen[x] = Pico.est.HighPal[ps[x]], ps[x] = 0;
  238. screen += stride;
  239. }
  240. fsprite[0] = oldsprite[0];
  241. fsprite[1] = oldsprite[1];
  242. pvid->reg[7] = oldreg;
  243. PicoMem.cram[0] = oldcol;
  244. pvid->debug_p = olddbg;
  245. }
  246. #define dump_ram_m(ram,fname,mode) \
  247. { \
  248. unsigned short *sram = (unsigned short *) ram; \
  249. FILE *f; \
  250. int i; \
  251. \
  252. for (i = 0; i < sizeof(ram)/2; i++) \
  253. sram[i] = (sram[i]<<8) | (sram[i]>>8); \
  254. f = fopen(fname, mode); \
  255. if (f) { \
  256. fwrite(ram, 1, sizeof(ram), f); \
  257. fclose(f); \
  258. } \
  259. for (i = 0; i < sizeof(ram)/2; i++) \
  260. sram[i] = (sram[i]<<8) | (sram[i]>>8); \
  261. }
  262. #define dump_ram(ram,fname) \
  263. dump_ram_m(ram,fname,"wb")
  264. #define dump_ram_noswab(ram,fname) \
  265. { \
  266. FILE *f; \
  267. f = fopen(fname, "wb"); \
  268. if (f) { \
  269. fwrite(ram, 1, sizeof(ram), f); \
  270. fclose(f); \
  271. } \
  272. }
  273. void PDebugDumpMem(void)
  274. {
  275. #if 0
  276. char buf[1 << M68K_MEM_SHIFT];
  277. unsigned int a;
  278. for (a = 0; ; a++) {
  279. uptr v = m68k_read16_map[a];
  280. if (map_flag_set(v))
  281. break;
  282. v <<= 1;
  283. v += a << M68K_MEM_SHIFT;
  284. memcpy(buf, (void *)v, sizeof(buf));
  285. dump_ram_m(buf, "dumps/cart.bin", a ? "ab" : "wb");
  286. }
  287. #endif
  288. dump_ram_noswab(PicoMem.zram, "dumps/zram.bin");
  289. dump_ram(PicoMem.cram, "dumps/cram.bin");
  290. if (PicoIn.AHW & PAHW_SMS)
  291. {
  292. dump_ram_noswab(PicoMem.vramb, "dumps/vram.bin");
  293. }
  294. else
  295. {
  296. dump_ram(PicoMem.ram, "dumps/ram.bin");
  297. dump_ram(PicoMem.vram, "dumps/vram.bin");
  298. dump_ram(PicoMem.vsram,"dumps/vsram.bin");
  299. }
  300. if (PicoIn.AHW & PAHW_MCD)
  301. {
  302. dump_ram(Pico_mcd->prg_ram, "dumps/prg_ram.bin");
  303. if (Pico_mcd->s68k_regs[3]&4) // 1M mode?
  304. wram_1M_to_2M(Pico_mcd->word_ram2M);
  305. dump_ram(Pico_mcd->word_ram2M, "dumps/word_ram_2M.bin");
  306. wram_2M_to_1M(Pico_mcd->word_ram2M);
  307. dump_ram(Pico_mcd->word_ram1M[0], "dumps/word_ram_1M_0.bin");
  308. dump_ram(Pico_mcd->word_ram1M[1], "dumps/word_ram_1M_1.bin");
  309. if (!(Pico_mcd->s68k_regs[3]&4)) // 2M mode?
  310. wram_2M_to_1M(Pico_mcd->word_ram2M);
  311. dump_ram_noswab(Pico_mcd->pcm_ram,"dumps/pcm_ram.bin");
  312. dump_ram_noswab(Pico_mcd->bram, "dumps/bram.bin");
  313. }
  314. #ifndef NO_32X
  315. if (PicoIn.AHW & PAHW_32X)
  316. {
  317. dump_ram(Pico32xMem->sdram, "dumps/sdram.bin");
  318. dump_ram(Pico32xMem->dram[0], "dumps/dram0.bin");
  319. dump_ram(Pico32xMem->dram[1], "dumps/dram1.bin");
  320. dump_ram(Pico32xMem->pal, "dumps/pal32x.bin");
  321. dump_ram(msh2.data_array, "dumps/data_array0.bin");
  322. dump_ram(ssh2.data_array, "dumps/data_array1.bin");
  323. }
  324. #endif
  325. }
  326. void PDebugZ80Frame(void)
  327. {
  328. int lines;
  329. if (PicoIn.AHW & PAHW_SMS)
  330. return;
  331. if (Pico.m.pal)
  332. lines = 313;
  333. else
  334. lines = 262;
  335. z80_resetCycles();
  336. PsndStartFrame();
  337. if (/*Pico.m.z80Run &&*/ !Pico.m.z80_reset && (PicoIn.opt&POPT_EN_Z80)) {
  338. PicoSyncZ80(Pico.t.m68c_cnt + 224 * 488);
  339. z80_int();
  340. }
  341. // sync z80
  342. if (/*Pico.m.z80Run &&*/ !Pico.m.z80_reset && (PicoIn.opt&POPT_EN_Z80)) {
  343. Pico.t.m68c_cnt += Pico.m.pal ? 151809 : 127671; // cycles adjusted for converter
  344. PicoSyncZ80(Pico.t.m68c_cnt);
  345. }
  346. if (PicoIn.sndOut)
  347. PsndGetSamples(lines);
  348. timers_cycle();
  349. Pico.t.m68c_aim = Pico.t.m68c_cnt;
  350. }
  351. void PDebugCPUStep(void)
  352. {
  353. if (PicoIn.AHW & 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