1 // common code for Pico.c and cd/Pico.c
2 // (c) Copyright 2007,2008 Grazvydas "notaz" Ignotas
4 #define CYCLES_M68K_LINE 488 // suitable for both PAL/NTSC
5 #define CYCLES_M68K_VINT_LAG 68
6 #define CYCLES_M68K_ASD 148
7 #define CYCLES_S68K_LINE 795
8 #define CYCLES_S68K_ASD 241
10 // pad delay (for 6 button pads)
12 if (PicoOpt&POPT_6BTN_PAD) { \
13 if(Pico.m.padDelay[0]++ > 25) Pico.m.padTHPhase[0]=0; \
14 if(Pico.m.padDelay[1]++ > 25) Pico.m.padTHPhase[1]=0; \
19 #define CPUS_RUN(m68k_cycles,s68k_cycles) \
20 SekRunM68k(m68k_cycles);
22 #define CPUS_RUN(m68k_cycles,s68k_cycles) \
24 if ((PicoOpt&POPT_EN_MCD_PSYNC) && (Pico_mcd->m.busreq&3) == 1) { \
25 SekRunPS(m68k_cycles, s68k_cycles); /* "better/perfect sync" */ \
27 SekRunM68k(m68k_cycles); \
28 if ((Pico_mcd->m.busreq&3) == 1) /* no busreq/no reset */ \
29 SekRunS68k(s68k_cycles); \
34 // Accurate but slower frame which does hints
35 static int PicoFrameHints(void)
37 struct PicoVideo *pv=&Pico.video;
38 int lines, y, lines_vis = 224, line_sample, skip;
39 int hint; // Hint counter
43 if ((PicoOpt&POPT_ALT_RENDERER) && !PicoSkipFrame && (pv->reg[1]&0x40)) { // fast rend., display enabled
44 // draw a frame just after vblank in alternative render mode
45 // yes, this will cause 1 frame lag, but this is inaccurate mode anyway.
47 #ifdef DRAW_FINISH_FUNC
52 else skip=PicoSkipFrame;
56 if(pv->reg[1]&8) lines_vis = 240;
68 pv->status&=~0x88; // clear V-Int, come out of vblank
70 hint=pv->reg[10]; // Load H-Int counter
71 //dprintf("-hint: %i", hint);
73 // This is to make active scan longer (needed for Double Dragon 2, mainly)
74 CPUS_RUN(CYCLES_M68K_ASD, CYCLES_S68K_ASD);
76 for (y = 0; y < lines_vis; y++)
82 if (pv->lwrite_cnt <= 0) {
84 Pico.video.status|=0x200;
93 if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
95 hint=pv->reg[10]; // Reload H-Int counter
96 pv->pending_ints|=0x10;
97 if (pv->reg[0]&0x10) {
98 elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCycleCnt);
103 // decide if we draw this line
104 if (!skip && (PicoOpt & POPT_ALT_RENDERER))
106 // find the right moment for frame renderer, when display is no longer blanked
107 if ((pv->reg[1]&0x40) || y > 100) {
109 #ifdef DRAW_FINISH_FUNC
117 // get samples from sound chips
118 if (y == 32 && PsndOut)
120 else if ((y == 224 || y == line_sample) && PsndOut)
122 if (Pico.m.z80Run && (PicoOpt&POPT_EN_Z80))
123 PicoSyncZ80(SekCycleCnt);
124 if (ym2612.dacen && PsndDacLine <= y)
131 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
132 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_S68K_LINE);
137 if (PicoLineHook) PicoLineHook(1);
143 if (DrawScanline < y)
144 PicoDrawSync(y - 1, 0);
145 #ifdef DRAW_FINISH_FUNC
150 // V-int line (224 or 240)
155 Pico.video.status|=0x200;
165 hint=pv->reg[10]; // Reload H-Int counter
166 pv->pending_ints|=0x10;
167 //printf("rhint: %i @ %06x [%i|%i]\n", hint, SekPc, y, SekCycleCnt);
168 if (pv->reg[0]&0x10) SekInterrupt(4);
172 pv->status|=0x08; // go into vblank
173 pv->pending_ints|=0x20;
175 // the following SekRun is there for several reasons:
176 // there must be a delay after vblank bit is set and irq is asserted (Mazin Saga)
177 // also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants)
178 // also delay between last H-int and V-int (Golden Axe 3)
179 SekRunM68k(CYCLES_M68K_VINT_LAG);
181 if (pv->reg[1]&0x20) {
182 elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt);
185 if (Pico.m.z80Run && (PicoOpt&POPT_EN_Z80)) {
186 PicoSyncZ80(SekCycleCnt);
187 elprintf(EL_INTS, "zint");
191 // get samples from sound chips
197 if (ym2612.dacen && PsndDacLine <= y)
203 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
204 CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD,
205 CYCLES_S68K_LINE - CYCLES_S68K_ASD);
210 if (PicoLineHook) PicoLineHook(1);
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++)
226 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
227 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_S68K_LINE);
232 if (PicoLineHook) PicoLineHook(1);
237 if (Pico.m.z80Run && (PicoOpt&POPT_EN_Z80))
238 PicoSyncZ80(Pico.m.pal ? 151809 : 127671); // cycles adjusted for converter
239 if (PsndOut && ym2612.dacen && PsndDacLine <= lines-1)