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);
82 if ((PicoOpt&POPT_ALT_RENDERER) && !PicoSkipFrame && (pv->reg[1]&0x40)) { // fast rend., display enabled
83 // draw a frame just after vblank in alternative render mode
84 // yes, this will cause 1 frame lag, but this is inaccurate mode anyway.
86 #ifdef DRAW_FINISH_FUNC
91 else skip=PicoSkipFrame;
93 timing.m68c_frame_start = SekCyclesDone();
94 pv->v_counter = Pico.m.scanline = 0;
99 hint = (pv->status & PVS_ACTIVE) ? pv->hint_cnt : pv->reg[10];
101 pv->status |= PVS_ACTIVE;
105 pv->v_counter = Pico.m.scanline = y;
106 if ((pv->reg[12]&6) == 6) { // interlace mode 2
108 pv->v_counter |= pv->v_counter >> 8;
109 pv->v_counter &= 0xff;
112 if ((y == 224 && !(pv->reg[1] & 8)) || y == 240)
116 pv->lwrite_cnt -= 12;
117 if (pv->lwrite_cnt <= 0) {
119 Pico.video.status |= SR_EMPT;
127 hint = pv->reg[10]; // Reload H-Int counter
131 // decide if we draw this line
132 if (!skip && (PicoOpt & POPT_ALT_RENDERER))
134 // find the right moment for frame renderer, when display is no longer blanked
135 if ((pv->reg[1]&0x40) || y > 100) {
137 #ifdef DRAW_FINISH_FUNC
144 // get samples from sound chips
145 if ((y == 224 || y == line_sample) && PsndOut)
147 cycles = SekCyclesDone();
149 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
152 if (PicoAHW & PAHW_MCD)
153 pcd_sync_s68k(cycles, 0);
156 p32x_sync_sh2s(cycles);
162 line_base_cycles = SekCyclesDone();
163 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
164 CPUS_RUN(CYCLES_M68K_LINE);
166 if (PicoLineHook) PicoLineHook();
167 pevt_log_m68k_o(EVT_NEXT_LINE);
170 lines_vis = (pv->reg[1] & 8) ? 240 : 224;
172 pv->status &= ~PVS_ACTIVE;
176 if (Pico.est.DrawScanline < y)
177 PicoDrawSync(y - 1, 0);
178 #ifdef DRAW_FINISH_FUNC
185 Pico.video.status |= SR_EMPT;
187 memcpy(PicoPadInt, PicoPad, sizeof(PicoPadInt));
190 // Last H-Int (normally):
193 hint = pv->reg[10]; // Reload H-Int counter
197 pv->status |= SR_VB; // go into vblank
198 pv->pending_ints |= 0x20;
200 // the following SekRun is there for several reasons:
201 // there must be a delay after vblank bit is set and irq is asserted (Mazin Saga)
202 // also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants)
203 // also delay between last H-int and V-int (Golden Axe 3)
204 line_base_cycles = SekCyclesDone();
205 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
206 CPUS_RUN(CYCLES_M68K_VINT_LAG);
208 if (pv->reg[1] & 0x20) {
209 elprintf(EL_INTS, "vint: @ %06x [%u]", SekPc, SekCyclesDone());
213 cycles = SekCyclesDone();
214 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) {
216 elprintf(EL_INTS, "zint");
221 if (PicoAHW & PAHW_MCD)
222 pcd_sync_s68k(cycles, 0);
225 p32x_sync_sh2s(cycles);
229 // get samples from sound chips
230 if (y == 224 && PsndOut)
234 CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG);
236 if (PicoLineHook) PicoLineHook();
237 pevt_log_m68k_o(EVT_NEXT_LINE);
250 for (y++; y < lines - 1; y++)
252 pv->v_counter = Pico.m.scanline = y;
254 pv->v_counter -= vcnt_adj;
255 if ((pv->reg[12]&6) == 6)
256 pv->v_counter = (pv->v_counter << 1) | 1;
257 pv->v_counter &= 0xff;
261 if ((pv->status & PVS_ACTIVE) && --hint < 0)
263 hint = pv->reg[10]; // Reload H-Int counter
268 line_base_cycles = SekCyclesDone();
269 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
270 CPUS_RUN(CYCLES_M68K_LINE);
272 if (PicoLineHook) PicoLineHook();
273 pevt_log_m68k_o(EVT_NEXT_LINE);
276 pv->status &= ~SR_VB;
280 pv->v_counter = 0xff;
284 if ((pv->status & PVS_ACTIVE) && --hint < 0)
286 hint = pv->reg[10]; // Reload H-Int counter
291 line_base_cycles = SekCyclesDone();
292 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
293 CPUS_RUN(CYCLES_M68K_LINE);
295 if (PicoLineHook) PicoLineHook();
296 pevt_log_m68k_o(EVT_NEXT_LINE);
299 cycles = SekCyclesDone();
300 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
302 if (PsndOut && ym2612.dacen && PsndDacLine < lines)
303 PsndDoDAC(lines - 1);
304 if (PsndOut && PsndPsgLine < lines)
305 PsndDoPSG(lines - 1);
308 if (PicoAHW & PAHW_MCD)
309 pcd_sync_s68k(cycles, 0);
312 p32x_sync_sh2s(cycles);
324 // vim:shiftwidth=2:ts=2:expandtab