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;
116 if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
118 hint=pv->reg[10]; // Reload H-Int counter
119 pv->pending_ints|=0x10;
120 if (pv->reg[0]&0x10) {
121 elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCycleCnt);
126 // decide if we draw this line
127 if (!skip && (PicoOpt & POPT_ALT_RENDERER))
129 // find the right moment for frame renderer, when display is no longer blanked
130 if ((pv->reg[1]&0x40) || y > 100) {
132 #ifdef DRAW_FINISH_FUNC
139 // get samples from sound chips
140 if ((y == 224 || y == line_sample) && PsndOut)
142 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
143 PicoSyncZ80(SekCycleCnt);
144 if (ym2612.dacen && PsndDacLine <= y)
147 p32x_sync_sh2s(SekCycleCntT + SekCycleCnt);
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));
190 hint=pv->reg[10]; // Reload H-Int counter
191 pv->pending_ints|=0x10;
192 //printf("rhint: %i @ %06x [%i|%i]\n", hint, SekPc, y, SekCycleCnt);
193 if (pv->reg[0]&0x10) SekInterrupt(4);
196 pv->status|=0x08; // go into vblank
197 pv->pending_ints|=0x20;
199 // the following SekRun is there for several reasons:
200 // there must be a delay after vblank bit is set and irq is asserted (Mazin Saga)
201 // also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants)
202 // also delay between last H-int and V-int (Golden Axe 3)
203 CPUS_RUN(CYCLES_M68K_VINT_LAG, CYCLES_S68K_VINT_LAG);
205 if (pv->reg[1]&0x20) {
206 elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt);
209 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) {
210 PicoSyncZ80(SekCycleCnt);
211 elprintf(EL_INTS, "zint");
216 p32x_sync_sh2s(SekCycleCntT + SekCycleCnt);
220 // get samples from sound chips
221 if (y == 224 && PsndOut)
223 if (ym2612.dacen && PsndDacLine <= y)
229 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
230 CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD,
231 CYCLES_S68K_LINE - CYCLES_S68K_VINT_LAG - CYCLES_S68K_ASD);
236 if (PicoLineHook) PicoLineHook();
239 lines = scanlines_total;
240 vcnt_wrap = Pico.m.pal ? 0x103 : 0xEB; // based on Gens, TODO: verify
242 for (y++; y < lines; y++)
244 pv->v_counter = Pico.m.scanline = y;
246 pv->v_counter -= Pico.m.pal ? 56 : 6;
247 if ((pv->reg[12]&6) == 6)
248 pv->v_counter = (pv->v_counter << 1) | 1;
249 pv->v_counter &= 0xff;
257 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
258 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_S68K_LINE);
263 if (PicoLineHook) PicoLineHook();
268 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
269 PicoSyncZ80(Pico.m.pal ? 151809 : 127671); // cycles adjusted for converter
270 if (PsndOut && ym2612.dacen && PsndDacLine <= lines-1)
274 p32x_sync_sh2s(SekCycleCntT + SekCycleCnt);