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_VINT_LAG 111
9 #define CYCLES_S68K_ASD 241
11 // pad delay (for 6 button pads)
13 if (PicoOpt&POPT_6BTN_PAD) { \
14 if(Pico.m.padDelay[0]++ > 25) Pico.m.padTHPhase[0]=0; \
15 if(Pico.m.padDelay[1]++ > 25) Pico.m.padTHPhase[1]=0; \
20 #define CPUS_RUN(m68k_cycles,s68k_cycles) \
21 SekRunM68k(m68k_cycles)
24 static int PicoFrameHints(void)
26 struct PicoVideo *pv=&Pico.video;
27 int lines, y, lines_vis = 224, line_sample, skip, vcnt_wrap;
28 int hint; // Hint counter
30 pv->v_counter = Pico.m.scanline = 0;
32 if ((PicoOpt&POPT_ALT_RENDERER) && !PicoSkipFrame && (pv->reg[1]&0x40)) { // fast rend., display enabled
33 // draw a frame just after vblank in alternative render mode
34 // yes, this will cause 1 frame lag, but this is inaccurate mode anyway.
36 #ifdef DRAW_FINISH_FUNC
41 else skip=PicoSkipFrame;
45 if (pv->reg[1]&8) lines_vis = 240;
58 pv->status&=~0x88; // clear V-Int, come out of vblank
60 hint=pv->reg[10]; // Load H-Int counter
61 //dprintf("-hint: %i", hint);
63 // This is to make active scan longer (needed for Double Dragon 2, mainly)
64 CPUS_RUN(CYCLES_M68K_ASD, CYCLES_S68K_ASD);
66 for (y = 0; y < lines_vis; y++)
68 pv->v_counter = Pico.m.scanline = y;
69 if ((pv->reg[12]&6) == 6) { // interlace mode 2
71 pv->v_counter |= pv->v_counter >> 8;
72 pv->v_counter &= 0xff;
77 if (pv->lwrite_cnt <= 0) {
79 Pico.video.status|=0x200;
91 if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
93 hint=pv->reg[10]; // Reload H-Int counter
94 pv->pending_ints|=0x10;
95 if (pv->reg[0]&0x10) {
96 elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCycleCnt);
101 // decide if we draw this line
102 if (!skip && (PicoOpt & POPT_ALT_RENDERER))
104 // find the right moment for frame renderer, when display is no longer blanked
105 if ((pv->reg[1]&0x40) || y > 100) {
107 #ifdef DRAW_FINISH_FUNC
114 // get samples from sound chips
115 if ((y == 224 || y == line_sample) && PsndOut)
117 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
118 PicoSyncZ80(SekCycleCnt);
119 if (ym2612.dacen && PsndDacLine <= y)
125 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
126 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_S68K_LINE);
131 if (PicoLineHook) PicoLineHook();
137 if (DrawScanline < y)
138 PicoDrawSync(y - 1, 0);
139 #ifdef DRAW_FINISH_FUNC
144 // V-int line (224 or 240)
146 pv->v_counter = 0xe0; // bad for 240 mode
147 if ((pv->reg[12]&6) == 6) pv->v_counter = 0xc1;
151 Pico.video.status|=0x200;
153 memcpy(PicoPadInt, PicoPad, sizeof(PicoPadInt));
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);
171 pv->status|=0x08; // go into vblank
172 pv->pending_ints|=0x20;
178 // the following SekRun is there for several reasons:
179 // there must be a delay after vblank bit is set and irq is asserted (Mazin Saga)
180 // also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants)
181 // also delay between last H-int and V-int (Golden Axe 3)
182 CPUS_RUN(CYCLES_M68K_VINT_LAG, CYCLES_S68K_VINT_LAG);
184 if (pv->reg[1]&0x20) {
185 elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt);
188 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) {
189 PicoSyncZ80(SekCycleCnt);
190 elprintf(EL_INTS, "zint");
194 // get samples from sound chips
195 if (y == 224 && PsndOut)
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_VINT_LAG - CYCLES_S68K_ASD);
210 if (PicoLineHook) PicoLineHook();
213 lines = scanlines_total;
214 vcnt_wrap = Pico.m.pal ? 0x103 : 0xEB; // based on Gens, TODO: verify
216 for (y++; y < lines; y++)
218 pv->v_counter = Pico.m.scanline = y;
220 pv->v_counter -= Pico.m.pal ? 56 : 6;
221 if ((pv->reg[12]&6) == 6)
222 pv->v_counter = (pv->v_counter << 1) | 1;
223 pv->v_counter &= 0xff;
234 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
235 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_S68K_LINE);
240 if (PicoLineHook) PicoLineHook();
245 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
246 PicoSyncZ80(Pico.m.pal ? 151809 : 127671); // cycles adjusted for converter
247 if (PsndOut && ym2612.dacen && PsndDacLine <= lines-1)