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
9 // pad delay (for 6 button pads)
12 if(Pico.m.padDelay[0]++ > 25) Pico.m.padTHPhase[0]=0; \
13 if(Pico.m.padDelay[1]++ > 25) Pico.m.padTHPhase[1]=0; \
16 #define Z80_RUN(z80_cycles) \
18 if ((PicoOpt&4) && Pico.m.z80Run) \
21 if (Pico.m.z80Run & 2) z80CycleAim += z80_cycles; \
23 cnt = SekCyclesDone() - z80startCycle; \
24 cnt = (cnt>>1)-(cnt>>5); \
25 if (cnt < 0 || cnt > (z80_cycles)) cnt = z80_cycles; \
29 cnt=z80CycleAim-total_z80; \
30 if (cnt > 0) total_z80+=z80_run(cnt); \
36 #define CPUS_RUN(m68k_cycles,z80_cycles,s68k_cycles) \
37 SekRunM68k(m68k_cycles); \
40 #define CPUS_RUN(m68k_cycles,z80_cycles,s68k_cycles) \
42 if ((PicoOpt & 0x2000) && (Pico_mcd->m.busreq&3) == 1) { \
43 SekRunPS(m68k_cycles, s68k_cycles); /* "better/perfect sync" */ \
45 SekRunM68k(m68k_cycles); \
46 if ((Pico_mcd->m.busreq&3) == 1) /* no busreq/no reset */ \
47 SekRunS68k(s68k_cycles); \
49 Z80_RUN(z80_cycles); \
53 // Accurate but slower frame which does hints
54 static int PicoFrameHints(void)
56 struct PicoVideo *pv=&Pico.video;
57 int lines, y, lines_vis = 224, total_z80 = 0, z80CycleAim = 0, line_sample, skip;
58 int hint; // Hint counter
60 if ((PicoOpt&0x10) && !PicoSkipFrame) {
61 // draw a frame just after vblank in alternative render mode
62 // yes, this will cause 1 frame lag, but this is inaccurate mode anyway.
64 #ifdef DRAW_FINISH_FUNC
69 else skip=PicoSkipFrame;
72 //cycles_68k = (int) ((double) OSC_PAL / 7 / 50 / 312 + 0.4); // should compile to a constant (488)
73 //cycles_z80 = (int) ((double) OSC_PAL / 15 / 50 / 312 + 0.4); // 228
75 if(pv->reg[1]&8) lines_vis = 240;
77 //cycles_68k = (int) ((double) OSC_NTSC / 7 / 60 / 262 + 0.4); // 488
78 //cycles_z80 = (int) ((double) OSC_NTSC / 15 / 60 / 262 + 0.4); // 228
87 pv->status&=~0x88; // clear V-Int, come out of vblank
89 hint=pv->reg[10]; // Load H-Int counter
90 //dprintf("-hint: %i", hint);
92 // This is to make active scan longer (needed for Double Dragon 2, mainly)
93 // also trying to adjust for z80 overclock here (due to int line cycle counts)
94 z80CycleAim = Pico.m.pal ? -40 : 7;
95 CPUS_RUN(CYCLES_M68K_ASD, 0, CYCLES_S68K_ASD);
97 for (y=0;y<lines_vis;y++)
99 Pico.m.scanline=(short)y;
102 pv->lwrite_cnt -= 12;
103 if (pv->lwrite_cnt <= 0) {
105 Pico.video.status|=0x200;
114 if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
116 hint=pv->reg[10]; // Reload H-Int counter
117 pv->pending_ints|=0x10;
118 if (pv->reg[0]&0x10) {
119 elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCycleCnt);
124 // decide if we draw this line
125 #if CAN_HANDLE_240_LINES
126 if(!skip && ((!(pv->reg[1]&8) && y<224) || (pv->reg[1]&8)) )
133 sound_timers_and_dac(y);
136 // get samples from sound chips
137 if(y == 32 && PsndOut)
139 else if((y == 224 || y == line_sample) && PsndOut)
144 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
145 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_Z80_LINE, CYCLES_S68K_LINE);
152 #ifdef DRAW_FINISH_FUNC
157 // V-int line (224 or 240)
158 Pico.m.scanline=(short)y;
162 Pico.video.status|=0x200;
172 hint=pv->reg[10]; // Reload H-Int counter
173 pv->pending_ints|=0x10;
174 //printf("rhint: %i @ %06x [%i|%i]\n", hint, SekPc, y, SekCycleCnt);
175 if (pv->reg[0]&0x10) SekInterrupt(4);
179 pv->status|=0x08; // go into vblank
180 pv->pending_ints|=0x20;
182 // the following SekRun is there for several reasons:
183 // there must be a delay after vblank bit is set and irq is asserted (Mazin Saga)
184 // also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants)
185 // also delay between last H-int and V-int (Golden Axe 3)
186 SekRunM68k(CYCLES_M68K_VINT_LAG);
187 if (pv->reg[1]&0x20) {
188 elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt);
191 if (Pico.m.z80Run && (PicoOpt&4))
195 sound_timers_and_dac(y);
197 // get samples from sound chips
205 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
206 CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD,
207 CYCLES_Z80_LINE - CYCLES_Z80_ASD, CYCLES_S68K_LINE - CYCLES_S68K_ASD);
213 // PAL line count might actually be 313 according to Steve Snake, but that would complicate things.
214 lines = Pico.m.pal ? 312 : 262;
216 for (y++;y<lines;y++)
218 Pico.m.scanline=(short)y;
226 sound_timers_and_dac(y);
229 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
230 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_Z80_LINE, CYCLES_S68K_LINE);