2 * common code for pico.c and cd/pico.c
5 * This work is licensed under the terms of MAME license.
6 * See COPYING file in the top-level directory.
9 #define CYCLES_M68K_LINE 488 // suitable for both PAL/NTSC
10 #define CYCLES_M68K_VINT_LAG 68
11 #define CYCLES_M68K_ASD 148
12 #define CYCLES_S68K_LINE 795
13 #define CYCLES_S68K_VINT_LAG 111
14 #define CYCLES_S68K_ASD 241
16 // pad delay (for 6 button pads)
18 if (PicoOpt&POPT_6BTN_PAD) { \
19 if(Pico.m.padDelay[0]++ > 25) Pico.m.padTHPhase[0]=0; \
20 if(Pico.m.padDelay[1]++ > 25) Pico.m.padTHPhase[1]=0; \
25 #define CPUS_RUN(m68k_cycles,s68k_cycles) \
26 SekRunM68k(m68k_cycles)
29 static int PicoFrameHints(void)
31 struct PicoVideo *pv=&Pico.video;
32 int lines, y, lines_vis = 224, line_sample, skip, vcnt_wrap;
33 int hint; // Hint counter
35 pv->v_counter = Pico.m.scanline = 0;
37 if ((PicoOpt&POPT_ALT_RENDERER) && !PicoSkipFrame && (pv->reg[1]&0x40)) { // fast rend., display enabled
38 // draw a frame just after vblank in alternative render mode
39 // yes, this will cause 1 frame lag, but this is inaccurate mode anyway.
41 #ifdef DRAW_FINISH_FUNC
46 else skip=PicoSkipFrame;
50 if (pv->reg[1]&8) lines_vis = 240;
63 pv->status&=~0x88; // clear V-Int, come out of vblank
65 hint=pv->reg[10]; // Load H-Int counter
66 //dprintf("-hint: %i", hint);
68 // This is to make active scan longer (needed for Double Dragon 2, mainly)
69 CPUS_RUN(CYCLES_M68K_ASD, CYCLES_S68K_ASD);
71 for (y = 0; y < lines_vis; y++)
73 pv->v_counter = Pico.m.scanline = y;
74 if ((pv->reg[12]&6) == 6) { // interlace mode 2
76 pv->v_counter |= pv->v_counter >> 8;
77 pv->v_counter &= 0xff;
82 if (pv->lwrite_cnt <= 0) {
84 Pico.video.status|=0x200;
96 if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
98 hint=pv->reg[10]; // Reload H-Int counter
99 pv->pending_ints|=0x10;
100 if (pv->reg[0]&0x10) {
101 elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCycleCnt);
106 // decide if we draw this line
107 if (!skip && (PicoOpt & POPT_ALT_RENDERER))
109 // find the right moment for frame renderer, when display is no longer blanked
110 if ((pv->reg[1]&0x40) || y > 100) {
112 #ifdef DRAW_FINISH_FUNC
119 // get samples from sound chips
120 if ((y == 224 || y == line_sample) && PsndOut)
122 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
123 PicoSyncZ80(SekCycleCnt);
124 if (ym2612.dacen && PsndDacLine <= y)
130 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
131 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_S68K_LINE);
136 if (PicoLineHook) PicoLineHook();
142 if (DrawScanline < y)
143 PicoDrawSync(y - 1, 0);
144 #ifdef DRAW_FINISH_FUNC
149 // V-int line (224 or 240)
151 pv->v_counter = 0xe0; // bad for 240 mode
152 if ((pv->reg[12]&6) == 6) pv->v_counter = 0xc1;
156 Pico.video.status|=0x200;
158 memcpy(PicoPadInt, PicoPad, sizeof(PicoPadInt));
170 hint=pv->reg[10]; // Reload H-Int counter
171 pv->pending_ints|=0x10;
172 //printf("rhint: %i @ %06x [%i|%i]\n", hint, SekPc, y, SekCycleCnt);
173 if (pv->reg[0]&0x10) SekInterrupt(4);
176 pv->status|=0x08; // go into vblank
177 pv->pending_ints|=0x20;
183 // the following SekRun is there for several reasons:
184 // there must be a delay after vblank bit is set and irq is asserted (Mazin Saga)
185 // also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants)
186 // also delay between last H-int and V-int (Golden Axe 3)
187 CPUS_RUN(CYCLES_M68K_VINT_LAG, CYCLES_S68K_VINT_LAG);
189 if (pv->reg[1]&0x20) {
190 elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt);
193 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) {
194 PicoSyncZ80(SekCycleCnt);
195 elprintf(EL_INTS, "zint");
199 // get samples from sound chips
200 if (y == 224 && PsndOut)
202 if (ym2612.dacen && PsndDacLine <= y)
208 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
209 CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD,
210 CYCLES_S68K_LINE - CYCLES_S68K_VINT_LAG - CYCLES_S68K_ASD);
215 if (PicoLineHook) PicoLineHook();
218 lines = scanlines_total;
219 vcnt_wrap = Pico.m.pal ? 0x103 : 0xEB; // based on Gens, TODO: verify
221 for (y++; y < lines; y++)
223 pv->v_counter = Pico.m.scanline = y;
225 pv->v_counter -= Pico.m.pal ? 56 : 6;
226 if ((pv->reg[12]&6) == 6)
227 pv->v_counter = (pv->v_counter << 1) | 1;
228 pv->v_counter &= 0xff;
239 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
240 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_S68K_LINE);
245 if (PicoLineHook) PicoLineHook();
250 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
251 PicoSyncZ80(Pico.m.pal ? 151809 : 127671); // cycles adjusted for converter
252 if (PsndOut && ym2612.dacen && PsndDacLine <= lines-1)