debug.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  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: %06x, SR: %04x, irql: %i\n", SekPc, SekSr, SekIrqLevel); MVP;
  48. for (r = 0; r < 8; r++) {
  49. sprintf(dstrp, "d%i=%08x, a%i=%08x\n", r, SekDar(r), r, 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 %08x, %03x %08x, %03x\n", sh2_pc(&msh2), sh2_sr(0), sh2_pc(&ssh2), sh2_sr(1)); MVP;
  79. for (i = 0; i < 16/2; i++) {
  80. sprintf(dstrp, "R%d,%2d %08x,%08x %08x,%08x\n", i, i + 8,
  81. sh2_reg(0,i), sh2_reg(0,i+8), sh2_reg(1,i), sh2_reg(1,i+8)); MVP;
  82. }
  83. sprintf(dstrp, "gb,vb %08x,%08x %08x,%08x\n", sh2_gbr(0), sh2_vbr(0), sh2_gbr(1), 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. #ifdef USE_BGR555
  127. #define YELLOW1 0x071c
  128. #define BLUE1 0xf000
  129. #define RED1 0x001e
  130. #else
  131. #define YELLOW1 0xe700
  132. #define BLUE1 0x001e
  133. #define RED1 0xf000
  134. #endif
  135. static void set16(unsigned short *p, unsigned short d, int cnt)
  136. {
  137. while (cnt-- > 0)
  138. *p++ = d;
  139. }
  140. void PDebugShowSpriteStats(unsigned short *screen, int stride)
  141. {
  142. int lines, i, u, step;
  143. unsigned short *dest;
  144. unsigned char *p;
  145. step = (320-4*4-1) / MAX_LINE_SPRITES;
  146. lines = 240;
  147. if (!Pico.m.pal || !(Pico.video.reg[1]&8))
  148. lines = 224, screen += stride*8;
  149. for (i = 0; i < lines; i++)
  150. {
  151. dest = screen + stride*i;
  152. p = &HighLnSpr[i][0];
  153. // sprite graphs
  154. for (u = 0; u < (p[0] & 0x7f); u++) {
  155. set16(dest, (p[3+u] & 0x80) ? YELLOW1 : GREEN1, step);
  156. dest += step;
  157. }
  158. // flags
  159. dest = screen + stride*i + 320-4*4;
  160. if (p[1] & 0x40) set16(dest+4*0, GREEN1, 4);
  161. if (p[1] & 0x80) set16(dest+4*1, YELLOW1, 4);
  162. if (p[1] & 0x20) set16(dest+4*2, BLUE1, 4);
  163. if (p[1] & 0x10) set16(dest+4*3, RED1, 4);
  164. }
  165. // draw grid
  166. for (i = step*5; i <= 320-4*4-1; i += step*5) {
  167. for (u = 0; u < lines; u++)
  168. screen[i + u*stride] = 0x182;
  169. }
  170. }
  171. void PDebugShowPalette(unsigned short *screen, int stride)
  172. {
  173. struct PicoEState *est = &Pico.est;
  174. int x, y;
  175. Pico.m.dirtyPal = 1;
  176. if (PicoIn.AHW & PAHW_SMS)
  177. PicoDoHighPal555M4();
  178. else
  179. PicoDoHighPal555(1, 0, est);
  180. Pico.m.dirtyPal = 1;
  181. screen += 16*stride+8;
  182. for (y = 0; y < 8*4; y++)
  183. for (x = 0; x < 8*16; x++)
  184. screen[x + y*stride] = est->HighPal[x/8 + (y/8)*16];
  185. screen += 160;
  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) | 0x40];
  189. screen += stride*48;
  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) | 0x80];
  193. }
  194. #if defined(DRAW2_OVERRIDE_LINE_WIDTH)
  195. #define DRAW2_LINE_WIDTH DRAW2_OVERRIDE_LINE_WIDTH
  196. #else
  197. #define DRAW2_LINE_WIDTH 328
  198. #endif
  199. void PDebugShowSprite(unsigned short *screen, int stride, int which)
  200. {
  201. struct PicoVideo *pvid=&Pico.video;
  202. int table=0,u,link=0,*sprite=0,*fsprite,oldsprite[2];
  203. int x,y,max_sprites = 80, oldcol, oldreg;
  204. unsigned char olddbg;
  205. if (!(pvid->reg[12]&1))
  206. max_sprites = 64;
  207. table=pvid->reg[5]&0x7f;
  208. if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode
  209. table<<=8; // Get sprite table address/2
  210. for (u=0; u < max_sprites && u <= which; u++)
  211. {
  212. sprite=(int *)(PicoMem.vram+((table+(link<<2))&0x7ffc)); // Find sprite
  213. link=(sprite[0]>>16)&0x7f;
  214. if (!link) break; // End of sprites
  215. }
  216. if (u >= max_sprites) return;
  217. fsprite = (int *)(PicoMem.vram+(table&0x7ffc));
  218. oldsprite[0] = fsprite[0];
  219. oldsprite[1] = fsprite[1];
  220. fsprite[0] = (sprite[0] & ~0x007f01ff) | 0x000080;
  221. fsprite[1] = (sprite[1] & ~0x01ff8000) | 0x800000;
  222. oldreg = pvid->reg[7];
  223. oldcol = PicoMem.cram[0];
  224. olddbg = pvid->debug_p;
  225. pvid->reg[7] = 0;
  226. PicoMem.cram[0] = 0;
  227. pvid->debug_p = PVD_KILL_A | PVD_KILL_B;
  228. PicoFrameFull();
  229. for (y = 0; y < 8*4; y++)
  230. {
  231. unsigned char *ps = Pico.est.Draw2FB + DRAW2_LINE_WIDTH*y + 8;
  232. for (x = 0; x < 8*4; x++)
  233. if (ps[x]) screen[x] = Pico.est.HighPal[ps[x]], ps[x] = 0;
  234. screen += stride;
  235. }
  236. fsprite[0] = oldsprite[0];
  237. fsprite[1] = oldsprite[1];
  238. pvid->reg[7] = oldreg;
  239. PicoMem.cram[0] = oldcol;
  240. pvid->debug_p = olddbg;
  241. }
  242. #define dump_ram_m(ram,fname,mode) \
  243. { \
  244. unsigned short *sram = (unsigned short *) ram; \
  245. FILE *f; \
  246. int i; \
  247. \
  248. for (i = 0; i < sizeof(ram)/2; i++) \
  249. sram[i] = (sram[i]<<8) | (sram[i]>>8); \
  250. f = fopen(fname, mode); \
  251. if (f) { \
  252. fwrite(ram, 1, sizeof(ram), f); \
  253. fclose(f); \
  254. } \
  255. for (i = 0; i < sizeof(ram)/2; i++) \
  256. sram[i] = (sram[i]<<8) | (sram[i]>>8); \
  257. }
  258. #define dump_ram(ram,fname) \
  259. dump_ram_m(ram,fname,"wb")
  260. #define dump_ram_noswab(ram,fname) \
  261. { \
  262. FILE *f; \
  263. f = fopen(fname, "wb"); \
  264. if (f) { \
  265. fwrite(ram, 1, sizeof(ram), f); \
  266. fclose(f); \
  267. } \
  268. }
  269. void PDebugDumpMem(void)
  270. {
  271. #if 0
  272. char buf[1 << M68K_MEM_SHIFT];
  273. unsigned int a;
  274. for (a = 0; ; a++) {
  275. uptr v = m68k_read16_map[a];
  276. if (map_flag_set(v))
  277. break;
  278. v <<= 1;
  279. v += a << M68K_MEM_SHIFT;
  280. memcpy(buf, (void *)v, sizeof(buf));
  281. dump_ram_m(buf, "dumps/cart.bin", a ? "ab" : "wb");
  282. }
  283. #endif
  284. dump_ram_noswab(PicoMem.zram, "dumps/zram.bin");
  285. dump_ram(PicoMem.cram, "dumps/cram.bin");
  286. if (PicoIn.AHW & PAHW_SMS)
  287. {
  288. dump_ram_noswab(PicoMem.vramb, "dumps/vram.bin");
  289. }
  290. else
  291. {
  292. dump_ram(PicoMem.ram, "dumps/ram.bin");
  293. dump_ram(PicoMem.vram, "dumps/vram.bin");
  294. dump_ram(PicoMem.vsram,"dumps/vsram.bin");
  295. }
  296. if (PicoIn.AHW & PAHW_MCD)
  297. {
  298. dump_ram(Pico_mcd->prg_ram, "dumps/prg_ram.bin");
  299. if (Pico_mcd->s68k_regs[3]&4) // 1M mode?
  300. wram_1M_to_2M(Pico_mcd->word_ram2M);
  301. dump_ram(Pico_mcd->word_ram2M, "dumps/word_ram_2M.bin");
  302. wram_2M_to_1M(Pico_mcd->word_ram2M);
  303. dump_ram(Pico_mcd->word_ram1M[0], "dumps/word_ram_1M_0.bin");
  304. dump_ram(Pico_mcd->word_ram1M[1], "dumps/word_ram_1M_1.bin");
  305. if (!(Pico_mcd->s68k_regs[3]&4)) // 2M mode?
  306. wram_2M_to_1M(Pico_mcd->word_ram2M);
  307. dump_ram_noswab(Pico_mcd->pcm_ram,"dumps/pcm_ram.bin");
  308. dump_ram_noswab(Pico_mcd->bram, "dumps/bram.bin");
  309. }
  310. #ifndef NO_32X
  311. if (PicoIn.AHW & PAHW_32X)
  312. {
  313. dump_ram(Pico32xMem->sdram, "dumps/sdram.bin");
  314. dump_ram(Pico32xMem->dram[0], "dumps/dram0.bin");
  315. dump_ram(Pico32xMem->dram[1], "dumps/dram1.bin");
  316. dump_ram(Pico32xMem->pal, "dumps/pal32x.bin");
  317. dump_ram(msh2.data_array, "dumps/data_array0.bin");
  318. dump_ram(ssh2.data_array, "dumps/data_array1.bin");
  319. }
  320. #endif
  321. }
  322. void PDebugZ80Frame(void)
  323. {
  324. int lines;
  325. if (PicoIn.AHW & PAHW_SMS)
  326. return;
  327. if (Pico.m.pal)
  328. lines = 313;
  329. else
  330. lines = 262;
  331. z80_resetCycles();
  332. PsndStartFrame();
  333. if (/*Pico.m.z80Run &&*/ !Pico.m.z80_reset && (PicoIn.opt&POPT_EN_Z80)) {
  334. PicoSyncZ80(Pico.t.m68c_cnt + 224 * 488);
  335. z80_int();
  336. }
  337. // sync z80
  338. if (/*Pico.m.z80Run &&*/ !Pico.m.z80_reset && (PicoIn.opt&POPT_EN_Z80)) {
  339. Pico.t.m68c_cnt += Pico.m.pal ? 151809 : 127671; // cycles adjusted for converter
  340. PicoSyncZ80(Pico.t.m68c_cnt);
  341. }
  342. if (PicoIn.sndOut)
  343. PsndGetSamples(lines);
  344. timers_cycle();
  345. Pico.t.m68c_aim = Pico.t.m68c_cnt;
  346. }
  347. void PDebugCPUStep(void)
  348. {
  349. if (PicoIn.AHW & PAHW_SMS)
  350. z80_run_nr(1);
  351. else
  352. SekStepM68k();
  353. }
  354. #ifdef EVT_LOG
  355. static struct evt_t {
  356. unsigned int cycles;
  357. short cpu;
  358. short evt;
  359. } *evts;
  360. static int first_frame;
  361. static int evt_alloc;
  362. static int evt_cnt;
  363. void pevt_log(unsigned int cycles, enum evt_cpu c, enum evt e)
  364. {
  365. if (first_frame == 0)
  366. first_frame = Pico.m.frame_count;
  367. if (evt_alloc == evt_cnt) {
  368. evt_alloc = evt_alloc * 2 + 16 * 1024;
  369. evts = realloc(evts, evt_alloc * sizeof(evts[0]));
  370. }
  371. evts[evt_cnt].cycles = cycles;
  372. evts[evt_cnt].cpu = c;
  373. evts[evt_cnt].evt = e;
  374. evt_cnt++;
  375. }
  376. static int evt_cmp(const void *p1, const void *p2)
  377. {
  378. const struct evt_t *e1 = p1, *e2 = p2;
  379. int ret = (int)(e1->cycles - e2->cycles);
  380. if (ret)
  381. return ret;
  382. if (e1->evt == EVT_RUN_END || e1->evt == EVT_POLL_END)
  383. return -1;
  384. if (e1->evt == EVT_RUN_START || e1->evt == EVT_POLL_START)
  385. return 1;
  386. if (e2->evt == EVT_RUN_END || e2->evt == EVT_POLL_END)
  387. return 1;
  388. if (e1->evt == EVT_RUN_START || e1->evt == EVT_POLL_START)
  389. return -1;
  390. return 0;
  391. }
  392. void pevt_dump(void)
  393. {
  394. static const char *evt_names[EVT_CNT] = {
  395. "x", "x", "+run", "-run", "+poll", "-poll",
  396. };
  397. char evt_print[EVT_CPU_CNT][EVT_CNT] = {{0,}};
  398. unsigned int start_cycles[EVT_CPU_CNT] = {0,};
  399. unsigned int run_cycles[EVT_CPU_CNT] = {0,};
  400. unsigned int frame_cycles[EVT_CPU_CNT] = {0,};
  401. unsigned int frame_resched[EVT_CPU_CNT] = {0,};
  402. unsigned int cycles = 0;
  403. int frame = first_frame - 1;
  404. int line = 0;
  405. int cpu_mask = 0;
  406. int dirty = 0;
  407. int i;
  408. qsort(evts, evt_cnt, sizeof(evts[0]), evt_cmp);
  409. for (i = 0; i < evt_cnt; i++) {
  410. int c = evts[i].cpu, e = evts[i].evt;
  411. int ei, ci;
  412. if (cycles != evts[i].cycles || (cpu_mask & (1 << c))
  413. || e == EVT_FRAME_START || e == EVT_NEXT_LINE)
  414. {
  415. if (dirty) {
  416. printf("%u:%03u:%u ", frame, line, cycles);
  417. for (ci = 0; ci < EVT_CPU_CNT; ci++) {
  418. int found = 0;
  419. for (ei = 0; ei < EVT_CNT; ei++) {
  420. if (evt_print[ci][ei]) {
  421. if (ei == EVT_RUN_END) {
  422. printf("%8s%4d", evt_names[ei], run_cycles[ci]);
  423. run_cycles[ci] = 0;
  424. }
  425. else
  426. printf("%8s ", evt_names[ei]);
  427. found = 1;
  428. }
  429. }
  430. if (!found)
  431. printf("%12s", "");
  432. }
  433. printf("\n");
  434. memset(evt_print, 0, sizeof(evt_print));
  435. cpu_mask = 0;
  436. dirty = 0;
  437. }
  438. cycles = evts[i].cycles;
  439. }
  440. switch (e) {
  441. case EVT_FRAME_START:
  442. frame++;
  443. line = 0;
  444. printf("%u:%03u:%u ", frame, line, cycles);
  445. for (ci = 0; ci < EVT_CPU_CNT; ci++) {
  446. printf("%12u", frame_cycles[ci]);
  447. frame_cycles[ci] = 0;
  448. }
  449. printf("\n");
  450. printf("%u:%03u:%u ", frame, line, cycles);
  451. for (ci = 0; ci < EVT_CPU_CNT; ci++) {
  452. printf("%12u", frame_resched[ci]);
  453. frame_resched[ci] = 0;
  454. }
  455. printf("\n");
  456. break;
  457. case EVT_NEXT_LINE:
  458. line++;
  459. printf("%u:%03u:%u\n", frame, line, cycles);
  460. break;
  461. case EVT_RUN_START:
  462. start_cycles[c] = cycles;
  463. goto default_;
  464. case EVT_RUN_END:
  465. run_cycles[c] += cycles - start_cycles[c];
  466. frame_cycles[c] += cycles - start_cycles[c];
  467. frame_resched[c]++;
  468. goto default_;
  469. default_:
  470. default:
  471. evt_print[c][e] = 1;
  472. cpu_mask |= 1 << c;
  473. dirty = 1;
  474. break;
  475. }
  476. }
  477. }
  478. #endif
  479. #if defined(CPU_CMP_R) || defined(CPU_CMP_W) || defined(DRC_CMP)
  480. static FILE *tl_f;
  481. void tl_write(const void *ptr, size_t size)
  482. {
  483. if (tl_f == NULL)
  484. tl_f = fopen("tracelog", "wb");
  485. fwrite(ptr, 1, size, tl_f);
  486. }
  487. void tl_write_uint(unsigned char ctl, unsigned int v)
  488. {
  489. tl_write(&ctl, sizeof(ctl));
  490. tl_write(&v, sizeof(v));
  491. }
  492. int tl_read(void *ptr, size_t size)
  493. {
  494. if (tl_f == NULL)
  495. tl_f = fopen("tracelog", "rb");
  496. return fread(ptr, 1, size, tl_f);
  497. }
  498. int tl_read_uint(void *ptr)
  499. {
  500. return tl_read(ptr, 4);
  501. }
  502. #endif
  503. // vim:shiftwidth=2:ts=2:expandtab