| 1 | #define CYCLES_M68K_LINE 488 // suitable for both PAL/NTSC |
| 2 | #define CYCLES_M68K_VINT_LAG 68 |
| 3 | #define CYCLES_M68K_ASD 148 |
| 4 | #define CYCLES_Z80_LINE 228 |
| 5 | #define CYCLES_Z80_ASD 69 |
| 6 | #define CYCLES_S68K_LINE 795 |
| 7 | #define CYCLES_S68K_ASD 241 |
| 8 | |
| 9 | // pad delay (for 6 button pads) |
| 10 | #define PAD_DELAY \ |
| 11 | if (PicoOpt&0x20) { \ |
| 12 | if(Pico.m.padDelay[0]++ > 25) Pico.m.padTHPhase[0]=0; \ |
| 13 | if(Pico.m.padDelay[1]++ > 25) Pico.m.padTHPhase[1]=0; \ |
| 14 | } |
| 15 | |
| 16 | #define Z80_RUN(z80_cycles) \ |
| 17 | { \ |
| 18 | if ((PicoOpt&4) && Pico.m.z80Run) \ |
| 19 | { \ |
| 20 | int cnt; \ |
| 21 | if (Pico.m.z80Run & 2) z80CycleAim += z80_cycles; \ |
| 22 | else { \ |
| 23 | cnt = SekCyclesDone() - z80startCycle; \ |
| 24 | cnt = (cnt>>1)-(cnt>>5); \ |
| 25 | if (cnt < 0 || cnt > (z80_cycles)) cnt = z80_cycles; \ |
| 26 | Pico.m.z80Run |= 2; \ |
| 27 | z80CycleAim+=cnt; \ |
| 28 | } \ |
| 29 | cnt=z80CycleAim-total_z80; \ |
| 30 | if (cnt > 0) total_z80+=z80_run(cnt); \ |
| 31 | } \ |
| 32 | } |
| 33 | |
| 34 | // CPUS_RUN |
| 35 | #ifndef PICO_CD |
| 36 | #define CPUS_RUN(m68k_cycles,z80_cycles,s68k_cycles) \ |
| 37 | SekRunM68k(m68k_cycles); \ |
| 38 | Z80_RUN(z80_cycles); |
| 39 | #else |
| 40 | #define CPUS_RUN(m68k_cycles,z80_cycles,s68k_cycles) \ |
| 41 | { \ |
| 42 | if ((PicoOpt & 0x2000) && (Pico_mcd->m.busreq&3) == 1) { \ |
| 43 | SekRunPS(m68k_cycles, s68k_cycles); /* "better/perfect sync" */ \ |
| 44 | } else { \ |
| 45 | SekRunM68k(m68k_cycles); \ |
| 46 | if ((Pico_mcd->m.busreq&3) == 1) /* no busreq/no reset */ \ |
| 47 | SekRunS68k(s68k_cycles); \ |
| 48 | } \ |
| 49 | Z80_RUN(z80_cycles); \ |
| 50 | } |
| 51 | #endif |
| 52 | |
| 53 | // Accurate but slower frame which does hints |
| 54 | static int PicoFrameHints(void) |
| 55 | { |
| 56 | struct PicoVideo *pv=&Pico.video; |
| 57 | int lines,y,lines_vis = 224,total_z80 = 0,z80CycleAim = 0,line_sample; |
| 58 | int skip=PicoSkipFrame || (PicoOpt&0x10); |
| 59 | int hint; // Hint counter |
| 60 | |
| 61 | if (Pico.m.pal) { |
| 62 | //cycles_68k = (int) ((double) OSC_PAL / 7 / 50 / 312 + 0.4); // should compile to a constant (488) |
| 63 | //cycles_z80 = (int) ((double) OSC_PAL / 15 / 50 / 312 + 0.4); // 228 |
| 64 | line_sample = 68; |
| 65 | if(pv->reg[1]&8) lines_vis = 240; |
| 66 | } else { |
| 67 | //cycles_68k = (int) ((double) OSC_NTSC / 7 / 60 / 262 + 0.4); // 488 |
| 68 | //cycles_z80 = (int) ((double) OSC_NTSC / 15 / 60 / 262 + 0.4); // 228 |
| 69 | line_sample = 93; |
| 70 | } |
| 71 | |
| 72 | SekCyclesReset(); |
| 73 | #ifdef PICO_CD |
| 74 | SekCyclesResetS68k(); |
| 75 | #endif |
| 76 | |
| 77 | pv->status&=~0x88; // clear V-Int, come out of vblank |
| 78 | |
| 79 | hint=pv->reg[10]; // Load H-Int counter |
| 80 | //dprintf("-hint: %i", hint); |
| 81 | |
| 82 | // This is to make active scan longer (needed for Double Dragon 2, mainly) |
| 83 | // also trying to adjust for z80 overclock here (due to int line cycle counts) |
| 84 | z80CycleAim = Pico.m.pal ? -40 : 7; |
| 85 | CPUS_RUN(CYCLES_M68K_ASD, 0, CYCLES_S68K_ASD); |
| 86 | |
| 87 | for (y=0;y<lines_vis;y++) |
| 88 | { |
| 89 | Pico.m.scanline=(short)y; |
| 90 | |
| 91 | // VDP FIFO |
| 92 | pv->lwrite_cnt -= 12; |
| 93 | if (pv->lwrite_cnt <= 0) { |
| 94 | pv->lwrite_cnt=0; |
| 95 | Pico.video.status|=0x200; |
| 96 | } |
| 97 | |
| 98 | PAD_DELAY |
| 99 | #ifdef PICO_CD |
| 100 | check_cd_dma(); |
| 101 | #endif |
| 102 | |
| 103 | // H-Interrupts: |
| 104 | if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe |
| 105 | { |
| 106 | hint=pv->reg[10]; // Reload H-Int counter |
| 107 | pv->pending_ints|=0x10; |
| 108 | if (pv->reg[0]&0x10) { |
| 109 | elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCycleCnt); |
| 110 | SekInterrupt(4); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | // decide if we draw this line |
| 115 | #if CAN_HANDLE_240_LINES |
| 116 | if(!skip && ((!(pv->reg[1]&8) && y<224) || (pv->reg[1]&8)) ) |
| 117 | #else |
| 118 | if(!skip && y<224) |
| 119 | #endif |
| 120 | PicoLine(y); |
| 121 | |
| 122 | if(PicoOpt&1) |
| 123 | sound_timers_and_dac(y); |
| 124 | |
| 125 | #ifndef PICO_CD |
| 126 | // get samples from sound chips |
| 127 | if(y == 32 && PsndOut) |
| 128 | emustatus &= ~1; |
| 129 | else if((y == 224 || y == line_sample) && PsndOut) |
| 130 | getSamples(y); |
| 131 | #endif |
| 132 | |
| 133 | // Run scanline: |
| 134 | if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA()); |
| 135 | CPUS_RUN(CYCLES_M68K_LINE, CYCLES_Z80_LINE, CYCLES_S68K_LINE); |
| 136 | |
| 137 | #ifdef PICO_CD |
| 138 | update_chips(); |
| 139 | #endif |
| 140 | } |
| 141 | |
| 142 | #ifdef DRAW_FINISH_FUNC |
| 143 | DRAW_FINISH_FUNC(); |
| 144 | #endif |
| 145 | |
| 146 | // V-int line (224 or 240) |
| 147 | Pico.m.scanline=(short)y; |
| 148 | |
| 149 | // VDP FIFO |
| 150 | pv->lwrite_cnt=0; |
| 151 | Pico.video.status|=0x200; |
| 152 | |
| 153 | PAD_DELAY |
| 154 | #ifdef PICO_CD |
| 155 | check_cd_dma(); |
| 156 | #endif |
| 157 | |
| 158 | // Last H-Int: |
| 159 | if (--hint < 0) |
| 160 | { |
| 161 | hint=pv->reg[10]; // Reload H-Int counter |
| 162 | pv->pending_ints|=0x10; |
| 163 | //printf("rhint: %i @ %06x [%i|%i]\n", hint, SekPc, y, SekCycleCnt); |
| 164 | if (pv->reg[0]&0x10) SekInterrupt(4); |
| 165 | } |
| 166 | |
| 167 | // V-Interrupt: |
| 168 | pv->status|=0x08; // go into vblank |
| 169 | pv->pending_ints|=0x20; |
| 170 | |
| 171 | // the following SekRun is there for several reasons: |
| 172 | // there must be a delay after vblank bit is set and irq is asserted (Mazin Saga) |
| 173 | // also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants) |
| 174 | // also delay between last H-int and V-int (Golden Axe 3) |
| 175 | SekRunM68k(CYCLES_M68K_VINT_LAG); |
| 176 | if (pv->reg[1]&0x20) { |
| 177 | elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt); |
| 178 | SekInterrupt(6); |
| 179 | } |
| 180 | if (Pico.m.z80Run && (PicoOpt&4)) |
| 181 | z80_int(); |
| 182 | |
| 183 | if (PicoOpt&1) |
| 184 | sound_timers_and_dac(y); |
| 185 | |
| 186 | // get samples from sound chips |
| 187 | #ifndef PICO_CD |
| 188 | if (y == 224) |
| 189 | #endif |
| 190 | if (PsndOut) |
| 191 | getSamples(y); |
| 192 | |
| 193 | // Run scanline: |
| 194 | if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA()); |
| 195 | CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD, |
| 196 | CYCLES_Z80_LINE - CYCLES_Z80_ASD, CYCLES_S68K_LINE - CYCLES_S68K_ASD); |
| 197 | |
| 198 | #ifdef PICO_CD |
| 199 | update_chips(); |
| 200 | #endif |
| 201 | |
| 202 | // PAL line count might actually be 313 according to Steve Snake, but that would complicate things. |
| 203 | lines = Pico.m.pal ? 312 : 262; |
| 204 | |
| 205 | for (y++;y<lines;y++) |
| 206 | { |
| 207 | Pico.m.scanline=(short)y; |
| 208 | |
| 209 | PAD_DELAY |
| 210 | #ifdef PICO_CD |
| 211 | check_cd_dma(); |
| 212 | #endif |
| 213 | |
| 214 | if(PicoOpt&1) |
| 215 | sound_timers_and_dac(y); |
| 216 | |
| 217 | // Run scanline: |
| 218 | if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA()); |
| 219 | CPUS_RUN(CYCLES_M68K_LINE, CYCLES_Z80_LINE, CYCLES_S68K_LINE); |
| 220 | |
| 221 | #ifdef PICO_CD |
| 222 | update_chips(); |
| 223 | #endif |
| 224 | } |
| 225 | |
| 226 | // draw a frame just after vblank in alternative render mode |
| 227 | if (!PicoSkipFrame && (PicoOpt&0x10)) |
| 228 | PicoFrameFull(); |
| 229 | |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | #undef PAD_DELAY |
| 234 | #undef Z80_RUN |
| 235 | #undef CPUS_RUN |
| 236 | |