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 __inline void SekRunM68k(int cyc)
35 if ((cyc_do=SekCycleAim-SekCycleCnt) <= 0) return;
36 #if defined(EMU_CORE_DEBUG)
37 // this means we do run-compare
38 SekCycleCnt+=CM_compareRun(cyc_do, 0);
39 #elif defined(EMU_C68K)
40 PicoCpuCM68k.cycles=cyc_do;
41 CycloneRun(&PicoCpuCM68k);
42 SekCycleCnt+=cyc_do-PicoCpuCM68k.cycles;
43 #elif defined(EMU_M68K)
44 SekCycleCnt+=m68k_execute(cyc_do);
45 #elif defined(EMU_F68K)
46 SekCycleCnt+=fm68k_emulate(cyc_do+1, 0, 0);
52 static int PicoFrameHints(void)
54 struct PicoVideo *pv=&Pico.video;
55 int lines, y, lines_vis = 224, line_sample, skip, vcnt_wrap;
56 int hint; // Hint counter
58 pv->v_counter = Pico.m.scanline = 0;
60 if ((PicoOpt&POPT_ALT_RENDERER) && !PicoSkipFrame && (pv->reg[1]&0x40)) { // fast rend., display enabled
61 // draw a frame just after vblank in alternative render mode
62 // yes, this will cause 1 frame lag, but this is inaccurate mode anyway.
64 #ifdef DRAW_FINISH_FUNC
69 else skip=PicoSkipFrame;
73 if (pv->reg[1]&8) lines_vis = 240;
86 pv->status&=~0x88; // clear V-Int, come out of vblank
88 hint=pv->reg[10]; // Load H-Int counter
89 //dprintf("-hint: %i", hint);
91 // This is to make active scan longer (needed for Double Dragon 2, mainly)
92 CPUS_RUN(CYCLES_M68K_ASD, CYCLES_S68K_ASD);
94 for (y = 0; y < lines_vis; y++)
96 pv->v_counter = Pico.m.scanline = y;
97 if ((pv->reg[12]&6) == 6) { // interlace mode 2
99 pv->v_counter |= pv->v_counter >> 8;
100 pv->v_counter &= 0xff;
104 pv->lwrite_cnt -= 12;
105 if (pv->lwrite_cnt <= 0) {
107 Pico.video.status|=0x200;
119 if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
121 hint=pv->reg[10]; // Reload H-Int counter
122 pv->pending_ints|=0x10;
123 if (pv->reg[0]&0x10) {
124 elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCycleCnt);
129 // decide if we draw this line
130 if (!skip && (PicoOpt & POPT_ALT_RENDERER))
132 // find the right moment for frame renderer, when display is no longer blanked
133 if ((pv->reg[1]&0x40) || y > 100) {
135 #ifdef DRAW_FINISH_FUNC
142 // get samples from sound chips
143 if ((y == 224 || y == line_sample) && PsndOut)
145 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
146 PicoSyncZ80(SekCycleCnt);
147 if (ym2612.dacen && PsndDacLine <= y)
153 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
154 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_S68K_LINE);
159 if (PicoLineHook) PicoLineHook();
165 if (DrawScanline < y)
166 PicoDrawSync(y - 1, 0);
167 #ifdef DRAW_FINISH_FUNC
172 // V-int line (224 or 240)
174 pv->v_counter = 0xe0; // bad for 240 mode
175 if ((pv->reg[12]&6) == 6) pv->v_counter = 0xc1;
179 Pico.video.status|=0x200;
181 memcpy(PicoPadInt, PicoPad, sizeof(PicoPadInt));
193 hint=pv->reg[10]; // Reload H-Int counter
194 pv->pending_ints|=0x10;
195 //printf("rhint: %i @ %06x [%i|%i]\n", hint, SekPc, y, SekCycleCnt);
196 if (pv->reg[0]&0x10) SekInterrupt(4);
199 pv->status|=0x08; // go into vblank
200 pv->pending_ints|=0x20;
206 // the following SekRun is there for several reasons:
207 // there must be a delay after vblank bit is set and irq is asserted (Mazin Saga)
208 // also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants)
209 // also delay between last H-int and V-int (Golden Axe 3)
210 CPUS_RUN(CYCLES_M68K_VINT_LAG, CYCLES_S68K_VINT_LAG);
212 if (pv->reg[1]&0x20) {
213 elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt);
216 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) {
217 PicoSyncZ80(SekCycleCnt);
218 elprintf(EL_INTS, "zint");
222 // get samples from sound chips
223 if (y == 224 && PsndOut)
225 if (ym2612.dacen && PsndDacLine <= y)
231 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
232 CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD,
233 CYCLES_S68K_LINE - CYCLES_S68K_VINT_LAG - CYCLES_S68K_ASD);
238 if (PicoLineHook) PicoLineHook();
241 lines = scanlines_total;
242 vcnt_wrap = Pico.m.pal ? 0x103 : 0xEB; // based on Gens, TODO: verify
244 for (y++; y < lines; y++)
246 pv->v_counter = Pico.m.scanline = y;
248 pv->v_counter -= Pico.m.pal ? 56 : 6;
249 if ((pv->reg[12]&6) == 6)
250 pv->v_counter = (pv->v_counter << 1) | 1;
251 pv->v_counter &= 0xff;
262 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
263 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_S68K_LINE);
268 if (PicoLineHook) PicoLineHook();
273 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
274 PicoSyncZ80(Pico.m.pal ? 151809 : 127671); // cycles adjusted for converter
275 if (PsndOut && ym2612.dacen && PsndDacLine <= lines-1)