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;
58 int skip=PicoSkipFrame || (PicoOpt&0x10);
59 int hint; // Hint counter
62 //cycles_68k = (int) ((double) OSC_PAL / 7 / 50 / 312 + 0.4); // should compile to a constant (488)
63 //cycles_z80 = (int) ((double) OSC_PAL / 15 / 50 / 312 + 0.4); // 228
65 if(pv->reg[1]&8) lines_vis = 240;
67 //cycles_68k = (int) ((double) OSC_NTSC / 7 / 60 / 262 + 0.4); // 488
68 //cycles_z80 = (int) ((double) OSC_NTSC / 15 / 60 / 262 + 0.4); // 228
77 pv->status&=~0x88; // clear V-Int, come out of vblank
79 hint=pv->reg[10]; // Load H-Int counter
80 //dprintf("-hint: %i", hint);
82 // This is to make active scan longer (needed for Double Dragon 2, mainly)
83 // also trying to adjust for z80 overclock here (due to int line cycle counts)
84 z80CycleAim = Pico.m.pal ? -40 : 7;
85 CPUS_RUN(CYCLES_M68K_ASD, 0, CYCLES_S68K_ASD);
87 for (y=0;y<lines_vis;y++)
89 Pico.m.scanline=(short)y;
93 if (pv->lwrite_cnt <= 0) {
95 Pico.video.status|=0x200;
104 if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
106 hint=pv->reg[10]; // Reload H-Int counter
107 pv->pending_ints|=0x10;
108 if (pv->reg[0]&0x10) {
109 elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCycleCnt);
114 // decide if we draw this line
115 #if CAN_HANDLE_240_LINES
116 if(!skip && ((!(pv->reg[1]&8) && y<224) || (pv->reg[1]&8)) )
123 sound_timers_and_dac(y);
126 // get samples from sound chips
127 if(y == 32 && PsndOut)
129 else if((y == 224 || y == line_sample) && PsndOut)
134 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
135 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_Z80_LINE, CYCLES_S68K_LINE);
142 #ifdef DRAW_FINISH_FUNC
146 // V-int line (224 or 240)
147 Pico.m.scanline=(short)y;
151 Pico.video.status|=0x200;
161 hint=pv->reg[10]; // Reload H-Int counter
162 pv->pending_ints|=0x10;
163 //printf("rhint: %i @ %06x [%i|%i]\n", hint, SekPc, y, SekCycleCnt);
164 if (pv->reg[0]&0x10) SekInterrupt(4);
168 pv->status|=0x08; // go into vblank
169 pv->pending_ints|=0x20;
171 // the following SekRun is there for several reasons:
172 // there must be a delay after vblank bit is set and irq is asserted (Mazin Saga)
173 // also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants)
174 // also delay between last H-int and V-int (Golden Axe 3)
175 SekRunM68k(CYCLES_M68K_VINT_LAG);
176 if (pv->reg[1]&0x20) {
177 elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt);
180 if (Pico.m.z80Run && (PicoOpt&4))
184 sound_timers_and_dac(y);
186 // get samples from sound chips
194 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
195 CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD,
196 CYCLES_Z80_LINE - CYCLES_Z80_ASD, CYCLES_S68K_LINE - CYCLES_S68K_ASD);
202 // PAL line count might actually be 313 according to Steve Snake, but that would complicate things.
203 lines = Pico.m.pal ? 312 : 262;
205 for (y++;y<lines;y++)
207 Pico.m.scanline=(short)y;
215 sound_timers_and_dac(y);
218 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
219 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_Z80_LINE, CYCLES_S68K_LINE);
226 // draw a frame just after vblank in alternative render mode
227 if (!PicoSkipFrame && (PicoOpt&0x10))