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
11 #define CYCLES_M68K_ASD 148
13 // pad delay (for 6 button pads)
14 #define PAD_DELAY() { \
15 if(Pico.m.padDelay[0]++ > 25) Pico.m.padTHPhase[0]=0; \
16 if(Pico.m.padDelay[1]++ > 25) Pico.m.padTHPhase[1]=0; \
21 #define CPUS_RUN(m68k_cycles) \
22 SekRunM68k(m68k_cycles)
25 // sync m68k to SekCycleAim
26 static void SekSyncM68k(void)
30 pevt_log_m68k_o(EVT_RUN_START);
32 while ((cyc_do = SekCycleAim - SekCycleCnt) > 0) {
33 SekCycleCnt += cyc_do;
36 PicoCpuCM68k.cycles = cyc_do;
37 CycloneRun(&PicoCpuCM68k);
38 SekCycleCnt -= PicoCpuCM68k.cycles;
39 #elif defined(EMU_M68K)
40 SekCycleCnt += m68k_execute(cyc_do) - cyc_do;
41 #elif defined(EMU_F68K)
42 SekCycleCnt += fm68k_emulate(cyc_do, 0, 0) - cyc_do;
49 pevt_log_m68k_o(EVT_RUN_END);
53 static inline void SekRunM68k(int cyc)
59 static int PicoFrameHints(void)
61 struct PicoVideo *pv=&Pico.video;
62 int lines, y, lines_vis = 224, line_sample, skip, vcnt_wrap;
64 int hint; // Hint counter
66 pevt_log_m68k_o(EVT_FRAME_START);
67 pv->v_counter = Pico.m.scanline = 0;
69 if ((PicoOpt&POPT_ALT_RENDERER) && !PicoSkipFrame && (pv->reg[1]&0x40)) { // fast rend., display enabled
70 // draw a frame just after vblank in alternative render mode
71 // yes, this will cause 1 frame lag, but this is inaccurate mode anyway.
73 #ifdef DRAW_FINISH_FUNC
78 else skip=PicoSkipFrame;
82 if (pv->reg[1]&8) lines_vis = 240;
91 pv->status&=~0x88; // clear V-Int, come out of vblank
93 hint=pv->reg[10]; // Load H-Int counter
94 //dprintf("-hint: %i", hint);
96 // This is to make active scan longer (needed for Double Dragon 2, mainly)
97 CPUS_RUN(CYCLES_M68K_ASD);
99 for (y = 0; y < lines_vis; y++)
101 pv->v_counter = Pico.m.scanline = y;
102 if ((pv->reg[12]&6) == 6) { // interlace mode 2
104 pv->v_counter |= pv->v_counter >> 8;
105 pv->v_counter &= 0xff;
109 pv->lwrite_cnt -= 12;
110 if (pv->lwrite_cnt <= 0) {
112 Pico.video.status|=0x200;
118 if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
120 hint=pv->reg[10]; // Reload H-Int counter
121 pv->pending_ints|=0x10;
122 if (pv->reg[0]&0x10) {
123 elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCyclesDone());
128 // decide if we draw this line
129 if (!skip && (PicoOpt & POPT_ALT_RENDERER))
131 // find the right moment for frame renderer, when display is no longer blanked
132 if ((pv->reg[1]&0x40) || y > 100) {
134 #ifdef DRAW_FINISH_FUNC
141 // get samples from sound chips
142 if ((y == 224 || y == line_sample) && PsndOut)
144 cycles = SekCyclesDone();
146 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
148 if (ym2612.dacen && PsndDacLine <= y)
151 pcd_sync_s68k(cycles, 0);
154 p32x_sync_sh2s(cycles);
160 line_base_cycles = SekCyclesDone();
161 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
162 CPUS_RUN(CYCLES_M68K_LINE);
164 if (PicoLineHook) PicoLineHook();
165 pevt_log_m68k_o(EVT_NEXT_LINE);
170 if (DrawScanline < y)
171 PicoDrawSync(y - 1, 0);
172 #ifdef DRAW_FINISH_FUNC
177 // V-int line (224 or 240)
179 pv->v_counter = 0xe0; // bad for 240 mode
180 if ((pv->reg[12]&6) == 6) pv->v_counter = 0xc1;
184 Pico.video.status|=0x200;
186 memcpy(PicoPadInt, PicoPad, sizeof(PicoPadInt));
192 hint=pv->reg[10]; // Reload H-Int counter
193 pv->pending_ints|=0x10;
194 //printf("rhint: %i @ %06x [%i|%i]\n", hint, SekPc, y, SekCyclesDone());
195 if (pv->reg[0]&0x10) SekInterrupt(4);
198 pv->status|=0x08; // go into vblank
199 pv->pending_ints|=0x20;
201 // the following SekRun is there for several reasons:
202 // there must be a delay after vblank bit is set and irq is asserted (Mazin Saga)
203 // also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants)
204 // also delay between last H-int and V-int (Golden Axe 3)
205 line_base_cycles = SekCyclesDone();
206 CPUS_RUN(CYCLES_M68K_VINT_LAG);
208 if (pv->reg[1]&0x20) {
209 elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCyclesDone());
213 cycles = SekCyclesDone();
214 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) {
216 elprintf(EL_INTS, "zint");
221 pcd_sync_s68k(cycles, 0);
224 p32x_sync_sh2s(cycles);
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);
240 if (PicoLineHook) PicoLineHook();
241 pevt_log_m68k_o(EVT_NEXT_LINE);
243 lines = scanlines_total;
244 vcnt_wrap = Pico.m.pal ? 0x103 : 0xEB; // based on Gens, TODO: verify
246 for (y++; y < lines; y++)
248 pv->v_counter = Pico.m.scanline = y;
250 pv->v_counter -= Pico.m.pal ? 56 : 6;
251 if ((pv->reg[12]&6) == 6)
252 pv->v_counter = (pv->v_counter << 1) | 1;
253 pv->v_counter &= 0xff;
258 line_base_cycles = SekCyclesDone();
259 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
260 CPUS_RUN(CYCLES_M68K_LINE);
262 if (PicoLineHook) PicoLineHook();
263 pevt_log_m68k_o(EVT_NEXT_LINE);
267 cycles = SekCyclesDone();
268 if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
270 if (PsndOut && ym2612.dacen && PsndDacLine <= lines-1)
274 pcd_sync_s68k(cycles, 0);
277 p32x_sync_sh2s(cycles);
287 // vim:shiftwidth=2:ts=2:expandtab