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)
33 pevt_log_m68k_o(EVT_RUN_START);
36 if ((cyc_do=SekCycleAim-SekCycleCnt) <= 0)
39 #if defined(EMU_CORE_DEBUG)
40 // this means we do run-compare
41 SekCycleCnt+=CM_compareRun(cyc_do, 0);
42 #elif defined(EMU_C68K)
43 PicoCpuCM68k.cycles=cyc_do;
44 CycloneRun(&PicoCpuCM68k);
45 SekCycleCnt+=cyc_do-PicoCpuCM68k.cycles;
46 #elif defined(EMU_M68K)
47 SekCycleCnt+=m68k_execute(cyc_do);
48 #elif defined(EMU_F68K)
49 SekCycleCnt+=fm68k_emulate(cyc_do, 0, 0);
54 pevt_log_m68k_o(EVT_RUN_END);
58 static int PicoFrameHints(void)
60 struct PicoVideo *pv=&Pico.video;
61 int lines, y, lines_vis = 224, line_sample, skip, vcnt_wrap;
62 int hint; // Hint counter
64 pevt_log_m68k_o(EVT_FRAME_START);
65 pv->v_counter = Pico.m.scanline = 0;
67 if ((PicoOpt&POPT_ALT_RENDERER) && !PicoSkipFrame && (pv->reg[1]&0x40)) { // fast rend., display enabled
68 // draw a frame just after vblank in alternative render mode
69 // yes, this will cause 1 frame lag, but this is inaccurate mode anyway.
71 #ifdef DRAW_FINISH_FUNC
76 else skip=PicoSkipFrame;
80 if (pv->reg[1]&8) lines_vis = 240;
93 pv->status&=~0x88; // clear V-Int, come out of vblank
95 hint=pv->reg[10]; // Load H-Int counter
96 //dprintf("-hint: %i", hint);
98 // This is to make active scan longer (needed for Double Dragon 2, mainly)
99 CPUS_RUN(CYCLES_M68K_ASD, CYCLES_S68K_ASD);
101 for (y = 0; y < lines_vis; y++)
103 pv->v_counter = Pico.m.scanline = y;
104 if ((pv->reg[12]&6) == 6) { // interlace mode 2
106 pv->v_counter |= pv->v_counter >> 8;
107 pv->v_counter &= 0xff;
111 pv->lwrite_cnt -= 12;
112 if (pv->lwrite_cnt <= 0) {
114 Pico.video.status|=0x200;
123 if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
125 hint=pv->reg[10]; // Reload H-Int counter
126 pv->pending_ints|=0x10;
127 if (pv->reg[0]&0x10) {
128 elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCycleCnt);
133 // decide if we draw this line
134 if (!skip && (PicoOpt & POPT_ALT_RENDERER))
136 // find the right moment for frame renderer, when display is no longer blanked
137 if ((pv->reg[1]&0x40) || y > 100) {
139 #ifdef DRAW_FINISH_FUNC
146 // get samples from sound chips
147 if ((y == 224 || y == line_sample) && PsndOut)
149 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
150 PicoSyncZ80(SekCycleCnt);
151 if (ym2612.dacen && PsndDacLine <= y)
154 p32x_sync_sh2s(SekCyclesDoneT2());
160 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
161 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_S68K_LINE);
166 if (PicoLineHook) PicoLineHook();
168 pevt_log_m68k_o(EVT_NEXT_LINE);
173 if (DrawScanline < y)
174 PicoDrawSync(y - 1, 0);
175 #ifdef DRAW_FINISH_FUNC
180 // V-int line (224 or 240)
182 pv->v_counter = 0xe0; // bad for 240 mode
183 if ((pv->reg[12]&6) == 6) pv->v_counter = 0xc1;
187 Pico.video.status|=0x200;
189 memcpy(PicoPadInt, PicoPad, sizeof(PicoPadInt));
198 hint=pv->reg[10]; // Reload H-Int counter
199 pv->pending_ints|=0x10;
200 //printf("rhint: %i @ %06x [%i|%i]\n", hint, SekPc, y, SekCycleCnt);
201 if (pv->reg[0]&0x10) SekInterrupt(4);
204 pv->status|=0x08; // go into vblank
205 pv->pending_ints|=0x20;
207 // the following SekRun is there for several reasons:
208 // there must be a delay after vblank bit is set and irq is asserted (Mazin Saga)
209 // also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants)
210 // also delay between last H-int and V-int (Golden Axe 3)
211 CPUS_RUN(CYCLES_M68K_VINT_LAG, CYCLES_S68K_VINT_LAG);
213 if (pv->reg[1]&0x20) {
214 elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt);
217 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) {
218 PicoSyncZ80(SekCycleCnt);
219 elprintf(EL_INTS, "zint");
224 p32x_sync_sh2s(SekCyclesDoneT2());
228 // get samples from sound chips
229 if (y == 224 && PsndOut)
231 if (ym2612.dacen && PsndDacLine <= y)
237 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
238 CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD,
239 CYCLES_S68K_LINE - CYCLES_S68K_VINT_LAG - CYCLES_S68K_ASD);
244 if (PicoLineHook) PicoLineHook();
246 pevt_log_m68k_o(EVT_NEXT_LINE);
248 lines = scanlines_total;
249 vcnt_wrap = Pico.m.pal ? 0x103 : 0xEB; // based on Gens, TODO: verify
251 for (y++; y < lines; y++)
253 pv->v_counter = Pico.m.scanline = y;
255 pv->v_counter -= Pico.m.pal ? 56 : 6;
256 if ((pv->reg[12]&6) == 6)
257 pv->v_counter = (pv->v_counter << 1) | 1;
258 pv->v_counter &= 0xff;
266 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
267 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_S68K_LINE);
272 if (PicoLineHook) PicoLineHook();
274 pevt_log_m68k_o(EVT_NEXT_LINE);
278 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
279 PicoSyncZ80(Pico.m.pal ? 151809 : 127671); // cycles adjusted for converter
280 if (PsndOut && ym2612.dacen && PsndDacLine <= lines-1)
284 p32x_sync_sh2s(SekCyclesDoneT2());