PicoFrameHints.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. #define CYCLES_M68K_LINE 488 // suitable for both PAL/NTSC
  2. #define CYCLES_M68K_VINT_LAG 68
  3. #define CYCLES_M68K_ASD 148
  4. #define CYCLES_Z80_LINE 228
  5. #define CYCLES_Z80_ASD 69
  6. #define CYCLES_S68K_LINE 795
  7. #define CYCLES_S68K_ASD 241
  8. // pad delay (for 6 button pads)
  9. #define PAD_DELAY \
  10. if (PicoOpt&0x20) { \
  11. if(Pico.m.padDelay[0]++ > 25) Pico.m.padTHPhase[0]=0; \
  12. if(Pico.m.padDelay[1]++ > 25) Pico.m.padTHPhase[1]=0; \
  13. }
  14. #define Z80_RUN(z80_cycles) \
  15. { \
  16. if ((PicoOpt&4) && Pico.m.z80Run) \
  17. { \
  18. int cnt; \
  19. if (Pico.m.z80Run & 2) z80CycleAim += z80_cycles; \
  20. else { \
  21. cnt = SekCyclesDone() - z80startCycle; \
  22. cnt = (cnt>>1)-(cnt>>5); \
  23. if (cnt < 0 || cnt > (z80_cycles)) cnt = z80_cycles; \
  24. Pico.m.z80Run |= 2; \
  25. z80CycleAim+=cnt; \
  26. } \
  27. cnt=z80CycleAim-total_z80; \
  28. if (cnt > 0) total_z80+=z80_run(cnt); \
  29. } \
  30. }
  31. // CPUS_RUN
  32. #ifndef PICO_CD
  33. #define CPUS_RUN(m68k_cycles,z80_cycles,s68k_cycles) \
  34. SekRunM68k(m68k_cycles); \
  35. Z80_RUN(z80_cycles);
  36. #else
  37. #define CPUS_RUN(m68k_cycles,z80_cycles,s68k_cycles) \
  38. { \
  39. if ((PicoOpt & 0x2000) && (Pico_mcd->m.busreq&3) == 1) { \
  40. SekRunPS(m68k_cycles, s68k_cycles); /* "better/perfect sync" */ \
  41. } else { \
  42. SekRunM68k(m68k_cycles); \
  43. if ((Pico_mcd->m.busreq&3) == 1) /* no busreq/no reset */ \
  44. SekRunS68k(s68k_cycles); \
  45. } \
  46. Z80_RUN(z80_cycles); \
  47. }
  48. #endif
  49. // Accurate but slower frame which does hints
  50. static int PicoFrameHints(void)
  51. {
  52. struct PicoVideo *pv=&Pico.video;
  53. int lines,y,lines_vis = 224,total_z80 = 0,z80CycleAim = 0,line_sample;
  54. int skip=PicoSkipFrame || (PicoOpt&0x10);
  55. int hint; // Hint counter
  56. if (Pico.m.pal) {
  57. //cycles_68k = (int) ((double) OSC_PAL / 7 / 50 / 312 + 0.4); // should compile to a constant (488)
  58. //cycles_z80 = (int) ((double) OSC_PAL / 15 / 50 / 312 + 0.4); // 228
  59. line_sample = 68;
  60. if(pv->reg[1]&8) lines_vis = 240;
  61. } else {
  62. //cycles_68k = (int) ((double) OSC_NTSC / 7 / 60 / 262 + 0.4); // 488
  63. //cycles_z80 = (int) ((double) OSC_NTSC / 15 / 60 / 262 + 0.4); // 228
  64. line_sample = 93;
  65. }
  66. SekCyclesReset();
  67. #ifdef PICO_CD
  68. SekCyclesResetS68k();
  69. #endif
  70. pv->status&=~0x88; // clear V-Int, come out of vblank
  71. hint=pv->reg[10]; // Load H-Int counter
  72. //dprintf("-hint: %i", hint);
  73. // This is to make active scan longer (needed for Double Dragon 2, mainly)
  74. // also trying to adjust for z80 overclock here (due to int line cycle counts)
  75. z80CycleAim = Pico.m.pal ? -40 : 7;
  76. CPUS_RUN(CYCLES_M68K_ASD, 0, CYCLES_S68K_ASD);
  77. for (y=0;y<lines_vis;y++)
  78. {
  79. Pico.m.scanline=(short)y;
  80. // VDP FIFO
  81. pv->lwrite_cnt -= 12;
  82. if (pv->lwrite_cnt <= 0) {
  83. pv->lwrite_cnt=0;
  84. Pico.video.status|=0x200;
  85. }
  86. PAD_DELAY
  87. #ifdef PICO_CD
  88. check_cd_dma();
  89. #endif
  90. // H-Interrupts:
  91. if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
  92. {
  93. hint=pv->reg[10]; // Reload H-Int counter
  94. pv->pending_ints|=0x10;
  95. if (pv->reg[0]&0x10) {
  96. elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCycleCnt);
  97. SekInterrupt(4);
  98. }
  99. }
  100. // decide if we draw this line
  101. #if CAN_HANDLE_240_LINES
  102. if(!skip && ((!(pv->reg[1]&8) && y<224) || (pv->reg[1]&8)) )
  103. #else
  104. if(!skip && y<224)
  105. #endif
  106. PicoLine(y);
  107. if(PicoOpt&1)
  108. sound_timers_and_dac(y);
  109. #ifndef PICO_CD
  110. // get samples from sound chips
  111. if(y == 32 && PsndOut)
  112. emustatus &= ~1;
  113. else if((y == 224 || y == line_sample) && PsndOut)
  114. getSamples(y);
  115. #endif
  116. // Run scanline:
  117. if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
  118. CPUS_RUN(CYCLES_M68K_LINE, CYCLES_Z80_LINE, CYCLES_S68K_LINE);
  119. #ifdef PICO_CD
  120. update_chips();
  121. #endif
  122. }
  123. #ifdef DRAW_FINISH_FUNC
  124. DRAW_FINISH_FUNC();
  125. #endif
  126. // V-int line (224 or 240)
  127. Pico.m.scanline=(short)y;
  128. // VDP FIFO
  129. pv->lwrite_cnt=0;
  130. Pico.video.status|=0x200;
  131. PAD_DELAY
  132. #ifdef PICO_CD
  133. check_cd_dma();
  134. #endif
  135. // Last H-Int:
  136. if (--hint < 0)
  137. {
  138. hint=pv->reg[10]; // Reload H-Int counter
  139. pv->pending_ints|=0x10;
  140. //printf("rhint: %i @ %06x [%i|%i]\n", hint, SekPc, y, SekCycleCnt);
  141. if (pv->reg[0]&0x10) SekInterrupt(4);
  142. }
  143. // V-Interrupt:
  144. pv->status|=0x08; // go into vblank
  145. pv->pending_ints|=0x20;
  146. // the following SekRun is there for several reasons:
  147. // there must be a delay after vblank bit is set and irq is asserted (Mazin Saga)
  148. // also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants)
  149. // also delay between last H-int and V-int (Golden Axe 3)
  150. SekRunM68k(CYCLES_M68K_VINT_LAG);
  151. if (pv->reg[1]&0x20) {
  152. elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt);
  153. SekInterrupt(6);
  154. }
  155. if (Pico.m.z80Run && (PicoOpt&4))
  156. z80_int();
  157. if (PicoOpt&1)
  158. sound_timers_and_dac(y);
  159. // get samples from sound chips
  160. #ifndef PICO_CD
  161. if (y == 224)
  162. #endif
  163. if (PsndOut)
  164. getSamples(y);
  165. // Run scanline:
  166. if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
  167. CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD,
  168. CYCLES_Z80_LINE - CYCLES_Z80_ASD, CYCLES_S68K_LINE - CYCLES_S68K_ASD);
  169. #ifdef PICO_CD
  170. update_chips();
  171. #endif
  172. // PAL line count might actually be 313 according to Steve Snake, but that would complicate things.
  173. lines = Pico.m.pal ? 312 : 262;
  174. for (y++;y<lines;y++)
  175. {
  176. Pico.m.scanline=(short)y;
  177. PAD_DELAY
  178. #ifdef PICO_CD
  179. check_cd_dma();
  180. #endif
  181. if(PicoOpt&1)
  182. sound_timers_and_dac(y);
  183. // Run scanline:
  184. if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
  185. CPUS_RUN(CYCLES_M68K_LINE, CYCLES_Z80_LINE, CYCLES_S68K_LINE);
  186. #ifdef PICO_CD
  187. update_chips();
  188. #endif
  189. }
  190. // draw a frame just after vblank in alternative render mode
  191. if (!PicoSkipFrame && (PicoOpt&0x10))
  192. PicoFrameFull();
  193. return 0;
  194. }
  195. #undef PAD_DELAY
  196. #undef Z80_RUN
  197. #undef CPUS_RUN