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; \
23 #define CPUS_RUN(m68k_cycles,s68k_cycles) \
25 SekRunM68k(m68k_cycles); \
29 #define CPUS_RUN(m68k_cycles,s68k_cycles) \
31 if ((PicoOpt&POPT_EN_MCD_PSYNC) && (Pico_mcd->m.busreq&3) == 1) { \
32 SekRunPS(m68k_cycles, s68k_cycles); /* "better/perfect sync" */ \
34 SekRunM68k(m68k_cycles); \
35 if ((Pico_mcd->m.busreq&3) == 1) /* no busreq/no reset */ \
36 SekRunS68k(s68k_cycles); \
41 static int PicoFrameHints(void)
43 struct PicoVideo *pv=&Pico.video;
44 int lines, y, lines_vis = 224, line_sample, skip, vcnt_wrap;
45 int hint; // Hint counter
47 pv->v_counter = Pico.m.scanline = 0;
49 if ((PicoOpt&POPT_ALT_RENDERER) && !PicoSkipFrame && (pv->reg[1]&0x40)) { // fast rend., display enabled
50 // draw a frame just after vblank in alternative render mode
51 // yes, this will cause 1 frame lag, but this is inaccurate mode anyway.
53 #ifdef DRAW_FINISH_FUNC
58 else skip=PicoSkipFrame;
62 if (pv->reg[1]&8) lines_vis = 240;
75 pv->status&=~0x88; // clear V-Int, come out of vblank
77 hint=pv->reg[10]; // Load H-Int counter
78 //dprintf("-hint: %i", hint);
80 // This is to make active scan longer (needed for Double Dragon 2, mainly)
81 CPUS_RUN(CYCLES_M68K_ASD, CYCLES_S68K_ASD);
83 for (y = 0; y < lines_vis; y++)
85 pv->v_counter = Pico.m.scanline = y;
86 if ((pv->reg[12]&6) == 6) { // interlace mode 2
88 pv->v_counter |= pv->v_counter >> 8;
89 pv->v_counter &= 0xff;
94 if (pv->lwrite_cnt <= 0) {
96 Pico.video.status|=0x200;
105 if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
107 hint=pv->reg[10]; // Reload H-Int counter
108 pv->pending_ints|=0x10;
109 if (pv->reg[0]&0x10) {
110 elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCycleCnt);
115 // decide if we draw this line
116 if (!skip && (PicoOpt & POPT_ALT_RENDERER))
118 // find the right moment for frame renderer, when display is no longer blanked
119 if ((pv->reg[1]&0x40) || y > 100) {
121 #ifdef DRAW_FINISH_FUNC
128 // get samples from sound chips
129 if ((y == 224 || y == line_sample) && PsndOut)
131 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
132 PicoSyncZ80(SekCycleCnt);
133 if (ym2612.dacen && PsndDacLine <= y)
139 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
140 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_S68K_LINE);
145 if (PicoLineHook) PicoLineHook();
151 if (DrawScanline < y)
152 PicoDrawSync(y - 1, 0);
153 #ifdef DRAW_FINISH_FUNC
158 // V-int line (224 or 240)
160 pv->v_counter = 0xe0; // bad for 240 mode
161 if ((pv->reg[12]&6) == 6) pv->v_counter = 0xc1;
165 Pico.video.status|=0x200;
167 memcpy(PicoPadInt, PicoPad, sizeof(PicoPadInt));
176 hint=pv->reg[10]; // Reload H-Int counter
177 pv->pending_ints|=0x10;
178 //printf("rhint: %i @ %06x [%i|%i]\n", hint, SekPc, y, SekCycleCnt);
179 if (pv->reg[0]&0x10) SekInterrupt(4);
182 pv->status|=0x08; // go into vblank
183 pv->pending_ints|=0x20;
189 // the following SekRun is there for several reasons:
190 // there must be a delay after vblank bit is set and irq is asserted (Mazin Saga)
191 // also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants)
192 // also delay between last H-int and V-int (Golden Axe 3)
193 SekRunM68k(CYCLES_M68K_VINT_LAG);
195 if (pv->reg[1]&0x20) {
196 elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt);
199 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) {
200 PicoSyncZ80(SekCycleCnt);
201 elprintf(EL_INTS, "zint");
205 // get samples from sound chips
206 if (y == 224 && PsndOut)
208 if (ym2612.dacen && PsndDacLine <= y)
214 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
215 CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD,
216 CYCLES_S68K_LINE - CYCLES_S68K_ASD);
221 if (PicoLineHook) PicoLineHook();
224 // PAL line count might actually be 313 according to Steve Snake, but that would complicate things.
225 lines = Pico.m.pal ? 312 : 262;
226 vcnt_wrap = Pico.m.pal ? 0x103 : 0xEB; // based on Gens
228 for (y++; y < lines; y++)
230 pv->v_counter = Pico.m.scanline = y;
232 pv->v_counter -= Pico.m.pal ? 56 : 6;
233 if ((pv->reg[12]&6) == 6)
234 pv->v_counter = (pv->v_counter << 1) | 1;
235 pv->v_counter &= 0xff;
243 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
244 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_S68K_LINE);
249 if (PicoLineHook) PicoLineHook();
254 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
255 PicoSyncZ80(Pico.m.pal ? 151809 : 127671); // cycles adjusted for converter
256 if (PsndOut && ym2612.dacen && PsndDacLine <= lines-1)