2 * common code for base/cd/32x
3 * (C) notaz, 2007-2009,2013
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
12 // pad delay (for 6 button pads)
13 #define PAD_DELAY() { \
14 if(Pico.m.padDelay[0]++ > 25) Pico.m.padTHPhase[0]=0; \
15 if(Pico.m.padDelay[1]++ > 25) Pico.m.padTHPhase[1]=0; \
20 #define CPUS_RUN(m68k_cycles) \
21 SekRunM68k(m68k_cycles)
24 // sync m68k to SekCycleAim
25 static void SekSyncM68k(void)
29 pevt_log_m68k_o(EVT_RUN_START);
31 while ((cyc_do = SekCycleAim - SekCycleCnt) > 0) {
32 SekCycleCnt += cyc_do;
35 PicoCpuCM68k.cycles = cyc_do;
36 CycloneRun(&PicoCpuCM68k);
37 SekCycleCnt -= PicoCpuCM68k.cycles;
38 #elif defined(EMU_M68K)
39 SekCycleCnt += m68k_execute(cyc_do) - cyc_do;
40 #elif defined(EMU_F68K)
41 SekCycleCnt += fm68k_emulate(cyc_do, 0) - cyc_do;
48 pevt_log_m68k_o(EVT_RUN_END);
52 static inline void SekRunM68k(int cyc)
55 cyc = SekCycleAim - SekCycleCnt;
58 SekCycleCnt += cyc >> 6; // refresh slowdowns
62 static void do_hint(struct PicoVideo *pv)
64 pv->pending_ints |= 0x10;
65 if (pv->reg[0] & 0x10) {
66 elprintf(EL_INTS, "hint: @ %06x [%u]", SekPc, SekCyclesDone());
71 static int PicoFrameHints(void)
73 struct PicoVideo *pv = &Pico.video;
74 int line_sample = Pico.m.pal ? 68 : 93;
75 int lines, y, lines_vis, skip;
76 int vcnt_wrap, vcnt_adj;
78 int hint; // Hint counter
80 pevt_log_m68k_o(EVT_FRAME_START);
81 pv->v_counter = Pico.m.scanline = 0;
83 if ((PicoOpt&POPT_ALT_RENDERER) && !PicoSkipFrame && (pv->reg[1]&0x40)) { // fast rend., display enabled
84 // draw a frame just after vblank in alternative render mode
85 // yes, this will cause 1 frame lag, but this is inaccurate mode anyway.
87 #ifdef DRAW_FINISH_FUNC
92 else skip=PicoSkipFrame;
98 hint = (pv->status & PVS_ACTIVE) ? pv->hint_cnt : pv->reg[10];
100 pv->status |= PVS_ACTIVE;
104 pv->v_counter = Pico.m.scanline = y;
105 if ((pv->reg[12]&6) == 6) { // interlace mode 2
107 pv->v_counter |= pv->v_counter >> 8;
108 pv->v_counter &= 0xff;
111 if ((y == 224 && !(pv->reg[1] & 8)) || y == 240)
115 pv->lwrite_cnt -= 12;
116 if (pv->lwrite_cnt <= 0) {
118 Pico.video.status |= SR_EMPT;
126 hint = pv->reg[10]; // Reload H-Int counter
130 // decide if we draw this line
131 if (!skip && (PicoOpt & POPT_ALT_RENDERER))
133 // find the right moment for frame renderer, when display is no longer blanked
134 if ((pv->reg[1]&0x40) || y > 100) {
136 #ifdef DRAW_FINISH_FUNC
143 // get samples from sound chips
144 if ((y == 224 || y == line_sample) && PsndOut)
146 cycles = SekCyclesDone();
148 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
151 if (PicoAHW & PAHW_MCD)
152 pcd_sync_s68k(cycles, 0);
155 p32x_sync_sh2s(cycles);
161 line_base_cycles = SekCyclesDone();
162 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
163 CPUS_RUN(CYCLES_M68K_LINE);
165 if (PicoLineHook) PicoLineHook();
166 pevt_log_m68k_o(EVT_NEXT_LINE);
169 lines_vis = (pv->reg[1] & 8) ? 240 : 224;
171 pv->status &= ~PVS_ACTIVE;
175 if (Pico.est.DrawScanline < y)
176 PicoDrawSync(y - 1, 0);
177 #ifdef DRAW_FINISH_FUNC
184 Pico.video.status |= SR_EMPT;
186 memcpy(PicoPadInt, PicoPad, sizeof(PicoPadInt));
189 // Last H-Int (normally):
192 hint = pv->reg[10]; // Reload H-Int counter
196 pv->status |= SR_VB; // 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 line_base_cycles = SekCyclesDone();
204 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
205 CPUS_RUN(CYCLES_M68K_VINT_LAG);
207 if (pv->reg[1] & 0x20) {
208 elprintf(EL_INTS, "vint: @ %06x [%u]", SekPc, SekCyclesDone());
212 cycles = SekCyclesDone();
213 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) {
215 elprintf(EL_INTS, "zint");
220 if (PicoAHW & PAHW_MCD)
221 pcd_sync_s68k(cycles, 0);
224 p32x_sync_sh2s(cycles);
228 // get samples from sound chips
229 if (y == 224 && PsndOut)
233 CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG);
235 if (PicoLineHook) PicoLineHook();
236 pevt_log_m68k_o(EVT_NEXT_LINE);
249 for (y++; y < lines - 1; y++)
251 pv->v_counter = Pico.m.scanline = y;
253 pv->v_counter -= vcnt_adj;
254 if ((pv->reg[12]&6) == 6)
255 pv->v_counter = (pv->v_counter << 1) | 1;
256 pv->v_counter &= 0xff;
260 if ((pv->status & PVS_ACTIVE) && --hint < 0)
262 hint = pv->reg[10]; // Reload H-Int counter
267 line_base_cycles = SekCyclesDone();
268 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
269 CPUS_RUN(CYCLES_M68K_LINE);
271 if (PicoLineHook) PicoLineHook();
272 pevt_log_m68k_o(EVT_NEXT_LINE);
275 pv->status &= ~SR_VB;
279 pv->v_counter = 0xff;
283 if ((pv->status & PVS_ACTIVE) && --hint < 0)
285 hint = pv->reg[10]; // Reload H-Int counter
290 line_base_cycles = SekCyclesDone();
291 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
292 CPUS_RUN(CYCLES_M68K_LINE);
294 if (PicoLineHook) PicoLineHook();
295 pevt_log_m68k_o(EVT_NEXT_LINE);
298 cycles = SekCyclesDone();
299 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
301 if (PsndOut && ym2612.dacen && PsndDacLine < lines)
302 PsndDoDAC(lines - 1);
303 if (PsndOut && PsndPsgLine < lines)
304 PsndDoPSG(lines - 1);
307 if (PicoAHW & PAHW_MCD)
308 pcd_sync_s68k(cycles, 0);
311 p32x_sync_sh2s(cycles);
323 // vim:shiftwidth=2:ts=2:expandtab