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) \
20 if (Pico.m.z80Run & 2) z80CycleAim += z80_cycles; \
22 int cnt = SekCyclesDone() - z80startCycle; \
23 cnt = (cnt>>1)-(cnt>>5); \
24 if (cnt > (z80_cycles)) cnt = z80_cycles; \
28 total_z80+=z80_run(z80CycleAim-total_z80); \
34 #define CPUS_RUN(m68k_cycles,z80_cycles,s68k_cycles) \
35 SekRunM68k(m68k_cycles); \
38 #define CPUS_RUN(m68k_cycles,z80_cycles,s68k_cycles) \
40 if ((PicoOpt & 0x2000) && (Pico_mcd->m.busreq&3) == 1) { \
41 SekRunPS(m68k_cycles, s68k_cycles); /* "better/perfect sync" */ \
43 SekRunM68k(m68k_cycles); \
44 if ((Pico_mcd->m.busreq&3) == 1) /* no busreq/no reset */ \
45 SekRunS68k(s68k_cycles); \
47 Z80_RUN(z80_cycles); \
51 // Accurate but slower frame which does hints
52 static int PicoFrameHints(void)
54 struct PicoVideo *pv=&Pico.video;
55 int total_z80=0,lines,y,lines_vis = 224,z80CycleAim = 0,line_sample;
56 int skip=PicoSkipFrame || (PicoOpt&0x10);
57 int hint; // Hint counter
60 //cycles_68k = (int) ((double) OSC_PAL / 7 / 50 / 312 + 0.4); // should compile to a constant (488)
61 //cycles_z80 = (int) ((double) OSC_PAL / 15 / 50 / 312 + 0.4); // 228
63 if(pv->reg[1]&8) lines_vis = 240;
65 //cycles_68k = (int) ((double) OSC_NTSC / 7 / 60 / 262 + 0.4); // 488
66 //cycles_z80 = (int) ((double) OSC_NTSC / 15 / 60 / 262 + 0.4); // 228
75 pv->status&=~0x88; // clear V-Int, come out of vblank
77 hint=pv->reg[10]; // Load H-Int counter
78 //dprintf("-hint: %i", hint);
80 // This is to make active scan longer (needed for Double Dragon 2, mainly)
81 CPUS_RUN(CYCLES_M68K_ASD, CYCLES_Z80_ASD, CYCLES_S68K_ASD);
83 for (y=0;y<lines_vis;y++)
85 Pico.m.scanline=(short)y;
89 if (pv->lwrite_cnt <= 0) {
91 Pico.video.status|=0x200;
100 if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
102 hint=pv->reg[10]; // Reload H-Int counter
103 pv->pending_ints|=0x10;
104 if (pv->reg[0]&0x10) {
105 elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCycleCnt);
110 // decide if we draw this line
111 #if CAN_HANDLE_240_LINES
112 if(!skip && ((!(pv->reg[1]&8) && y<224) || (pv->reg[1]&8)) )
119 sound_timers_and_dac(y);
122 // get samples from sound chips
123 if(y == 32 && PsndOut)
125 else if((y == 224 || y == line_sample) && PsndOut)
130 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
131 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_Z80_LINE, CYCLES_S68K_LINE);
138 // V-int line (224 or 240)
139 Pico.m.scanline=(short)y;
143 Pico.video.status|=0x200;
153 hint=pv->reg[10]; // Reload H-Int counter
154 pv->pending_ints|=0x10;
155 //printf("rhint: %i @ %06x [%i|%i]\n", hint, SekPc, y, SekCycleCnt);
156 if (pv->reg[0]&0x10) SekInterrupt(4);
160 pv->status|=0x08; // go into vblank
161 pv->pending_ints|=0x20;
163 // the following SekRun is there for several reasons:
164 // there must be a delay after vblank bit is set and irq is asserted (Mazin Saga)
165 // also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants)
166 // also delay between last H-int and V-int (Golden Axe 3)
167 SekRunM68k(CYCLES_M68K_VINT_LAG);
168 if (pv->reg[1]&0x20) {
169 elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt);
172 if (Pico.m.z80Run && (PicoOpt&4))
176 sound_timers_and_dac(y);
178 // get samples from sound chips
186 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
187 CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD,
188 CYCLES_Z80_LINE - CYCLES_Z80_ASD, CYCLES_S68K_LINE - CYCLES_S68K_ASD);
194 // PAL line count might actually be 313 according to Steve Snake, but that would complicate things.
195 lines = Pico.m.pal ? 312 : 262;
197 for (y++;y<lines;y++)
199 Pico.m.scanline=(short)y;
207 sound_timers_and_dac(y);
210 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
211 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_Z80_LINE, CYCLES_S68K_LINE);
218 // draw a frame just after vblank in alternative render mode
219 if (!PicoSkipFrame && (PicoOpt&0x10))