1 // common code for Pico.c and cd/Pico.c
2 // (c) Copyright 2007-2009 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)
23 static int PicoFrameHints(void)
25 struct PicoVideo *pv=&Pico.video;
26 int lines, y, lines_vis = 224, line_sample, skip, vcnt_wrap;
27 int hint; // Hint counter
29 pv->v_counter = Pico.m.scanline = 0;
31 if ((PicoOpt&POPT_ALT_RENDERER) && !PicoSkipFrame && (pv->reg[1]&0x40)) { // fast rend., display enabled
32 // draw a frame just after vblank in alternative render mode
33 // yes, this will cause 1 frame lag, but this is inaccurate mode anyway.
35 #ifdef DRAW_FINISH_FUNC
40 else skip=PicoSkipFrame;
44 if (pv->reg[1]&8) lines_vis = 240;
57 pv->status&=~0x88; // clear V-Int, come out of vblank
59 hint=pv->reg[10]; // Load H-Int counter
60 //dprintf("-hint: %i", hint);
62 // This is to make active scan longer (needed for Double Dragon 2, mainly)
63 CPUS_RUN(CYCLES_M68K_ASD, CYCLES_S68K_ASD);
65 for (y = 0; y < lines_vis; y++)
67 pv->v_counter = Pico.m.scanline = y;
68 if ((pv->reg[12]&6) == 6) { // interlace mode 2
70 pv->v_counter |= pv->v_counter >> 8;
71 pv->v_counter &= 0xff;
76 if (pv->lwrite_cnt <= 0) {
78 Pico.video.status|=0x200;
86 p32x_pwm_irq_check(1);
90 if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
92 hint=pv->reg[10]; // Reload H-Int counter
93 pv->pending_ints|=0x10;
94 if (pv->reg[0]&0x10) {
95 elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCycleCnt);
100 // decide if we draw this line
101 if (!skip && (PicoOpt & POPT_ALT_RENDERER))
103 // find the right moment for frame renderer, when display is no longer blanked
104 if ((pv->reg[1]&0x40) || y > 100) {
106 #ifdef DRAW_FINISH_FUNC
113 // get samples from sound chips
114 if ((y == 224 || y == line_sample) && PsndOut)
116 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
117 PicoSyncZ80(SekCycleCnt);
118 if (ym2612.dacen && PsndDacLine <= y)
124 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
125 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_S68K_LINE);
130 if (PicoLineHook) PicoLineHook();
136 if (DrawScanline < y)
137 PicoDrawSync(y - 1, 0);
138 #ifdef DRAW_FINISH_FUNC
143 // V-int line (224 or 240)
145 pv->v_counter = 0xe0; // bad for 240 mode
146 if ((pv->reg[12]&6) == 6) pv->v_counter = 0xc1;
150 Pico.video.status|=0x200;
152 memcpy(PicoPadInt, PicoPad, sizeof(PicoPadInt));
158 p32x_pwm_irq_check(1);
164 hint=pv->reg[10]; // Reload H-Int counter
165 pv->pending_ints|=0x10;
166 //printf("rhint: %i @ %06x [%i|%i]\n", hint, SekPc, y, SekCycleCnt);
167 if (pv->reg[0]&0x10) SekInterrupt(4);
170 pv->status|=0x08; // go into vblank
171 pv->pending_ints|=0x20;
177 // the following SekRun is there for several reasons:
178 // there must be a delay after vblank bit is set and irq is asserted (Mazin Saga)
179 // also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants)
180 // also delay between last H-int and V-int (Golden Axe 3)
181 SekRunM68k(CYCLES_M68K_VINT_LAG);
183 if (pv->reg[1]&0x20) {
184 elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt);
187 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) {
188 PicoSyncZ80(SekCycleCnt);
189 elprintf(EL_INTS, "zint");
193 // get samples from sound chips
194 if (y == 224 && PsndOut)
196 if (ym2612.dacen && PsndDacLine <= y)
202 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
203 CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD,
204 CYCLES_S68K_LINE - CYCLES_S68K_ASD);
209 if (PicoLineHook) PicoLineHook();
212 lines = scanlines_total;
213 vcnt_wrap = Pico.m.pal ? 0x103 : 0xEB; // based on Gens, TODO: verify
215 for (y++; y < lines; y++)
217 pv->v_counter = Pico.m.scanline = y;
219 pv->v_counter -= Pico.m.pal ? 56 : 6;
220 if ((pv->reg[12]&6) == 6)
221 pv->v_counter = (pv->v_counter << 1) | 1;
222 pv->v_counter &= 0xff;
229 p32x_pwm_irq_check(1);
233 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
234 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_S68K_LINE);
239 if (PicoLineHook) PicoLineHook();
244 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
245 PicoSyncZ80(Pico.m.pal ? 151809 : 127671); // cycles adjusted for converter
246 if (PsndOut && ym2612.dacen && PsndDacLine <= lines-1)