1 // common code for Pico.c and cd/Pico.c
2 // (c) Copyright 2007,2008 Grazvydas "notaz" Ignotas
4 #define CYCLES_M68K_LINE 488 // suitable for both PAL/NTSC
5 #define CYCLES_M68K_VINT_LAG 68
6 #define CYCLES_M68K_ASD 148
7 #define CYCLES_Z80_LINE 228
8 #define CYCLES_Z80_ASD 69
9 #define CYCLES_S68K_LINE 795
10 #define CYCLES_S68K_ASD 241
12 // pad delay (for 6 button pads)
14 if (PicoOpt&POPT_6BTN_PAD) { \
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,z80_cycles,s68k_cycles) \
22 SekRunM68k(m68k_cycles);
24 #define CPUS_RUN(m68k_cycles,z80_cycles,s68k_cycles) \
26 if ((PicoOpt&POPT_EN_MCD_PSYNC) && (Pico_mcd->m.busreq&3) == 1) { \
27 SekRunPS(m68k_cycles, s68k_cycles); /* "better/perfect sync" */ \
29 SekRunM68k(m68k_cycles); \
30 if ((Pico_mcd->m.busreq&3) == 1) /* no busreq/no reset */ \
31 SekRunS68k(s68k_cycles); \
36 // Accurate but slower frame which does hints
37 static int PicoFrameHints(void)
39 struct PicoVideo *pv=&Pico.video;
40 int lines, y, lines_vis = 224, line_sample, skip;
41 int hint; // Hint counter
43 if ((PicoOpt&POPT_ALT_RENDERER) && !PicoSkipFrame && (pv->reg[1]&0x40)) { // fast rend., display enabled
44 // draw a frame just after vblank in alternative render mode
45 // yes, this will cause 1 frame lag, but this is inaccurate mode anyway.
47 #ifdef DRAW_FINISH_FUNC
52 else skip=PicoSkipFrame;
56 if(pv->reg[1]&8) lines_vis = 240;
69 pv->status&=~0x88; // clear V-Int, come out of vblank
71 hint=pv->reg[10]; // Load H-Int counter
72 //dprintf("-hint: %i", hint);
74 // This is to make active scan longer (needed for Double Dragon 2, mainly)
75 CPUS_RUN(CYCLES_M68K_ASD, 0, CYCLES_S68K_ASD);
77 for (y=0;y<lines_vis;y++)
79 Pico.m.scanline=(short)y;
83 if (pv->lwrite_cnt <= 0) {
85 Pico.video.status|=0x200;
94 if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
96 hint=pv->reg[10]; // Reload H-Int counter
97 pv->pending_ints|=0x10;
98 if (pv->reg[0]&0x10) {
99 elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCycleCnt);
104 // decide if we draw this line
107 if (PicoOpt&POPT_ALT_RENDERER) {
108 // find the right moment for fast renderer, when display is no longer blanked
109 if ((pv->reg[1]&0x40) || y > 100) {
111 #ifdef DRAW_FINISH_FUNC
119 #if CAN_HANDLE_240_LINES
120 if (((!(pv->reg[1]&8) && y < 224) || (pv->reg[1]&8)) )
129 // get samples from sound chips
130 if (y == 32 && PsndOut)
132 else if ((y == 224 || y == line_sample) && PsndOut)
134 if (Pico.m.z80Run && (PicoOpt&POPT_EN_Z80))
135 PicoSyncZ80(SekCycleCnt);
136 if (ym2612.dacen && PsndDacLine <= y)
143 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
144 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_Z80_LINE, CYCLES_S68K_LINE);
149 if (PicoLineHook) PicoLineHook(1);
153 #ifdef DRAW_FINISH_FUNC
158 // V-int line (224 or 240)
159 Pico.m.scanline=(short)y;
163 Pico.video.status|=0x200;
173 hint=pv->reg[10]; // Reload H-Int counter
174 pv->pending_ints|=0x10;
175 //printf("rhint: %i @ %06x [%i|%i]\n", hint, SekPc, y, SekCycleCnt);
176 if (pv->reg[0]&0x10) SekInterrupt(4);
180 pv->status|=0x08; // go into vblank
181 pv->pending_ints|=0x20;
183 // the following SekRun is there for several reasons:
184 // there must be a delay after vblank bit is set and irq is asserted (Mazin Saga)
185 // also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants)
186 // also delay between last H-int and V-int (Golden Axe 3)
187 SekRunM68k(CYCLES_M68K_VINT_LAG);
189 if (pv->reg[1]&0x20) {
190 elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt);
193 if (Pico.m.z80Run && (PicoOpt&POPT_EN_Z80)) {
194 PicoSyncZ80(SekCycleCnt);
195 elprintf(EL_INTS, "zint");
199 // get samples from sound chips
205 if (ym2612.dacen && PsndDacLine <= y)
211 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
212 CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD,
213 CYCLES_Z80_LINE - CYCLES_Z80_ASD, CYCLES_S68K_LINE - CYCLES_S68K_ASD);
218 if (PicoLineHook) PicoLineHook(1);
221 // PAL line count might actually be 313 according to Steve Snake, but that would complicate things.
222 lines = Pico.m.pal ? 312 : 262;
224 for (y++;y<lines;y++)
226 Pico.m.scanline=(short)y;
234 if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
235 CPUS_RUN(CYCLES_M68K_LINE, CYCLES_Z80_LINE, CYCLES_S68K_LINE);
240 if (PicoLineHook) PicoLineHook(1);
245 if (Pico.m.z80Run && (PicoOpt&POPT_EN_Z80))
246 PicoSyncZ80(SekCycleCnt);
247 if (PsndOut && ym2612.dacen && PsndDacLine <= lines-1)