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
7 // pad delay (for 6 button pads)
10 if(Pico.m.padDelay[0]++ > 25) Pico.m.padTHPhase[0]=0; \
11 if(Pico.m.padDelay[1]++ > 25) Pico.m.padTHPhase[1]=0; \
14 #define Z80_RUN(z80_cycles) \
16 if ((PicoOpt&4) && Pico.m.z80Run) \
18 if (Pico.m.z80Run & 2) z80CycleAim += z80_cycles; \
20 int cnt = SekCyclesDone() - z80startCycle; \
21 cnt = (cnt>>1)-(cnt>>5); \
22 if (cnt > (z80_cycles)) cnt = z80_cycles; \
26 total_z80+=z80_run(z80CycleAim-total_z80); \
30 // Accurate but slower frame which does hints
31 static int PicoFrameHints(void)
33 struct PicoVideo *pv=&Pico.video;
34 int total_z80=0,lines,y,lines_vis = 224,z80CycleAim = 0,line_sample;
35 int skip=PicoSkipFrame || (PicoOpt&0x10);
36 int hint; // Hint counter
39 //cycles_68k = (int) ((double) OSC_PAL / 7 / 50 / 312 + 0.4); // should compile to a constant (488)
40 //cycles_z80 = (int) ((double) OSC_PAL / 15 / 50 / 312 + 0.4); // 228
42 if(pv->reg[1]&8) lines_vis = 240;
44 //cycles_68k = (int) ((double) OSC_NTSC / 7 / 60 / 262 + 0.4); // 488
45 //cycles_z80 = (int) ((double) OSC_NTSC / 15 / 60 / 262 + 0.4); // 228
51 pv->status&=~0x88; // clear V-Int, come out of vblank
53 hint=pv->reg[10]; // Load H-Int counter
54 //dprintf("-hint: %i", hint);
56 // This is to make active scan longer (needed for Double Dragon 2, mainly)
57 SekRun(CYCLES_M68K_ASD);
58 Z80_RUN(CYCLES_Z80_ASD);
60 for (y=0;y<lines_vis;y++)
62 Pico.m.scanline=(short)y;
66 if (pv->lwrite_cnt <= 0) {
68 Pico.video.status|=0x200;
74 if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
76 hint=pv->reg[10]; // Reload H-Int counter
77 pv->pending_ints|=0x10;
78 if (pv->reg[0]&0x10) {
79 elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCycleCnt);
84 // decide if we draw this line
85 #if CAN_HANDLE_240_LINES
86 if(!skip && ((!(pv->reg[1]&8) && y<224) || (pv->reg[1]&8)) )
93 sound_timers_and_dac(y);
95 // get samples from sound chips
96 if(y == 32 && PsndOut)
98 else if((y == 224 || y == line_sample) && PsndOut)
102 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
103 SekRun(CYCLES_M68K_LINE);
104 Z80_RUN(CYCLES_Z80_LINE);
107 // V-int line (224 or 240)
108 Pico.m.scanline=(short)y;
112 Pico.video.status|=0x200;
119 hint=pv->reg[10]; // Reload H-Int counter
120 pv->pending_ints|=0x10;
121 //printf("rhint: %i @ %06x [%i|%i]\n", hint, SekPc, y, SekCycleCnt);
122 if (pv->reg[0]&0x10) SekInterrupt(4);
126 pv->status|=0x08; // go into vblank
127 pv->pending_ints|=0x20;
129 // the following SekRun is there for several reasons:
130 // there must be a delay after vblank bit is set and irq is asserted (Mazin Saga)
131 // also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants)
132 // also delay between last H-int and V-int (Golden Axe 3)
133 SekRun(CYCLES_M68K_VINT_LAG);
134 if (pv->reg[1]&0x20) {
135 elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt);
138 if (Pico.m.z80Run && (PicoOpt&4))
142 sound_timers_and_dac(y);
144 // get samples from sound chips
145 if ((y == 224) && PsndOut)
149 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
150 SekRun(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD);
151 Z80_RUN(CYCLES_Z80_LINE - CYCLES_Z80_ASD);
153 // PAL line count might actually be 313 according to Steve Snake, but that would complicate things.
154 lines = Pico.m.pal ? 312 : 262;
156 for (y++;y<lines;y++)
158 Pico.m.scanline=(short)y;
163 sound_timers_and_dac(y);
166 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
167 SekRun(CYCLES_M68K_LINE);
168 Z80_RUN(CYCLES_Z80_LINE);
171 // draw a frame just after vblank in alternative render mode
172 if (!PicoSkipFrame && (PicoOpt&0x10))