return burn;\r
}\r
\r
-static __inline void SekRun(int cyc)\r
+static __inline void SekRunM68k(int cyc)\r
{\r
int cyc_do;\r
SekCycleAim+=cyc;\r
if (CheckIdle()) break;\r
\r
lines += lines_step;\r
- SekRun(cycles_68k_block);\r
+ SekRunM68k(cycles_68k_block);\r
\r
PicoRunZ80Simple(line, lines);\r
line=lines;\r
// a gap between flags set and vint\r
pv->pending_ints|=0x20;\r
pv->status|=8; // go into vblank\r
- SekRun(68+4);\r
+ SekRunM68k(68+4);\r
\r
// ---- V-Blanking period ----\r
// fix line counts\r
while (sects) {\r
lines += lines_step;\r
\r
- SekRun(cycles_68k_vblock);\r
+ SekRunM68k(cycles_68k_vblock);\r
\r
PicoRunZ80Simple(line, lines);\r
line=lines;\r
#define CYCLES_M68K_ASD 148
#define CYCLES_Z80_LINE 228
#define CYCLES_Z80_ASD 69
+#define CYCLES_S68K_LINE 795
+#define CYCLES_S68K_ASD 241
// pad delay (for 6 button pads)
#define PAD_DELAY \
} \
}
+// CPUS_RUN
+#ifndef PICO_CD
+#define CPUS_RUN(m68k_cycles,z80_cycles,s68k_cycles) \
+ SekRunM68k(m68k_cycles); \
+ Z80_RUN(z80_cycles);
+#else
+#define CPUS_RUN(m68k_cycles,z80_cycles,s68k_cycles) \
+{ \
+ if ((PicoOpt & 0x2000) && (Pico_mcd->m.busreq&3) == 1) { \
+ SekRunPS(m68k_cycles, s68k_cycles); /* "better/perfect sync" */ \
+ } else { \
+ SekRunM68k(m68k_cycles); \
+ if ((Pico_mcd->m.busreq&3) == 1) /* no busreq/no reset */ \
+ SekRunS68k(s68k_cycles); \
+ } \
+ Z80_RUN(z80_cycles); \
+}
+#endif
+
// Accurate but slower frame which does hints
static int PicoFrameHints(void)
{
}
SekCyclesReset();
+#ifdef PICO_CD
+ SekCyclesResetS68k();
+#endif
pv->status&=~0x88; // clear V-Int, come out of vblank
//dprintf("-hint: %i", hint);
// This is to make active scan longer (needed for Double Dragon 2, mainly)
- SekRun(CYCLES_M68K_ASD);
- Z80_RUN(CYCLES_Z80_ASD);
+ CPUS_RUN(CYCLES_M68K_ASD, CYCLES_Z80_ASD, CYCLES_S68K_ASD);
for (y=0;y<lines_vis;y++)
{
}
PAD_DELAY
+#ifdef PICO_CD
+ check_cd_dma();
+#endif
// H-Interrupts:
if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
if(PicoOpt&1)
sound_timers_and_dac(y);
+#ifndef PICO_CD
// get samples from sound chips
if(y == 32 && PsndOut)
emustatus &= ~1;
else if((y == 224 || y == line_sample) && PsndOut)
getSamples(y);
+#endif
// Run scanline:
if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
- SekRun(CYCLES_M68K_LINE);
- Z80_RUN(CYCLES_Z80_LINE);
+ CPUS_RUN(CYCLES_M68K_LINE, CYCLES_Z80_LINE, CYCLES_S68K_LINE);
+
+#ifdef PICO_CD
+ update_chips();
+#endif
}
// V-int line (224 or 240)
Pico.video.status|=0x200;
PAD_DELAY
+#ifdef PICO_CD
+ check_cd_dma();
+#endif
// Last H-Int:
if (--hint < 0)
// there must be a delay after vblank bit is set and irq is asserted (Mazin Saga)
// also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants)
// also delay between last H-int and V-int (Golden Axe 3)
- SekRun(CYCLES_M68K_VINT_LAG);
+ SekRunM68k(CYCLES_M68K_VINT_LAG);
if (pv->reg[1]&0x20) {
elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt);
SekInterrupt(6);
sound_timers_and_dac(y);
// get samples from sound chips
- if ((y == 224) && PsndOut)
- getSamples(y);
+#ifndef PICO_CD
+ if (y == 224)
+#endif
+ if (PsndOut)
+ getSamples(y);
// Run scanline:
if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
- SekRun(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD);
- Z80_RUN(CYCLES_Z80_LINE - CYCLES_Z80_ASD);
+ CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD,
+ CYCLES_Z80_LINE - CYCLES_Z80_ASD, CYCLES_S68K_LINE - CYCLES_S68K_ASD);
+
+#ifdef PICO_CD
+ update_chips();
+#endif
// PAL line count might actually be 313 according to Steve Snake, but that would complicate things.
lines = Pico.m.pal ? 312 : 262;
Pico.m.scanline=(short)y;
PAD_DELAY
+#ifdef PICO_CD
+ check_cd_dma();
+#endif
if(PicoOpt&1)
sound_timers_and_dac(y);
// Run scanline:
if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
- SekRun(CYCLES_M68K_LINE);
- Z80_RUN(CYCLES_Z80_LINE);
+ CPUS_RUN(CYCLES_M68K_LINE, CYCLES_Z80_LINE, CYCLES_S68K_LINE);
+
+#ifdef PICO_CD
+ update_chips();
+#endif
}
// draw a frame just after vblank in alternative render mode
#undef PAD_DELAY
#undef Z80_RUN
+#undef CPUS_RUN
extern int SekCycleCntS68k;\r
extern int SekCycleAimS68k;\r
\r
-#define SekCyclesResetS68k() {SekCycleCntS68k=SekCycleAimS68k=0;}\r
+#define SekCyclesResetS68k() { \\r
+ SekCycleCntS68k-=SekCycleAimS68k; \\r
+ SekCycleAimS68k=0; \\r
+}\r
#define SekCyclesDoneS68k() (SekCycleAimS68k-SekCyclesLeftS68k)\r
\r
// debug cyclone\r
}
-static int PicoFrameHintsMCD(void)
+static __inline void getSamples(int y)
{
- struct PicoVideo *pv=&Pico.video;
- int total_z80=0,lines,y,lines_vis = 224,z80CycleAim = 0,line_sample;
- const int cycles_68k=488,cycles_z80=228,cycles_s68k=795; // both PAL and NTSC compile to same values
- int skip=PicoSkipFrame || (PicoOpt&0x10);
- int hint; // Hint counter
-
- if(Pico.m.pal) { //
- //cycles_68k = (int) ((double) OSC_PAL / 7 / 50 / 312 + 0.4); // should compile to a constant (488)
- //cycles_z80 = (int) ((double) OSC_PAL / 15 / 50 / 312 + 0.4); // 228
- lines = 312; // Steve Snake says there are 313 lines, but this seems to also work well
- line_sample = 68;
- if(pv->reg[1]&8) lines_vis = 240;
- } else {
- //cycles_68k = (int) ((double) OSC_NTSC / 7 / 60 / 262 + 0.4); // 488
- //cycles_z80 = (int) ((double) OSC_NTSC / 15 / 60 / 262 + 0.4); // 228
- lines = 262;
- line_sample = 93;
- }
-
- SekCyclesReset();
- SekCyclesResetS68k();
- //z80ExtraCycles = 0;
-
- if(PicoOpt&4)
- z80CycleAim = 0;
-// z80_resetCycles();
-
- pv->status&=~0x88; // clear V-Int, come out of vblank
-
- hint=pv->reg[10]; // Load H-Int counter
- //dprintf("-hint: %i", hint);
-
- for (y=0;y<lines;y++)
- {
- Pico.m.scanline=(short)y;
-
- // pad delay (for 6 button pads)
- if(PicoOpt&0x20) {
- if(Pico.m.padDelay[0]++ > 25) Pico.m.padTHPhase[0]=0;
- if(Pico.m.padDelay[1]++ > 25) Pico.m.padTHPhase[1]=0;
- }
-
- check_cd_dma();
-
- // H-Interrupts:
- if(y <= lines_vis && --hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
- {
- //dprintf("rhint:old @ %06x", SekPc);
- hint=pv->reg[10]; // Reload H-Int counter
- pv->pending_ints|=0x10;
- if (pv->reg[0]&0x10) SekInterrupt(4);
- //dprintf("rhint: %i @ %06x [%i|%i]", hint, SekPc, y, SekCycleCnt);
- //dprintf("hint_routine: %x", (*(unsigned short*)(Pico.ram+0x0B84)<<16)|*(unsigned short*)(Pico.ram+0x0B86));
- }
-
- // V-Interrupt:
- if (y == lines_vis)
- {
- //dprintf("vint: @ %06x [%i|%i]", SekPc, y, SekCycleCnt);
- pv->status|=0x88; // V-Int happened, go into vblank
- SekRunM68k(128); SekCycleAim-=128; // there must be a gap between H and V ints, also after vblank bit set (Mazin Saga, Bram Stoker's Dracula)
- /*if(Pico.m.z80Run && (PicoOpt&4)) {
- z80CycleAim+=cycles_z80/2;
- total_z80+=z80_run(z80CycleAim-total_z80);
- z80CycleAim-=cycles_z80/2;
- }*/
- pv->pending_ints|=0x20;
- if(pv->reg[1]&0x20) SekInterrupt(6);
- if(Pico.m.z80Run && (PicoOpt&4)) // ?
- z80_int();
- //dprintf("zint: [%i|%i] zPC=%04x", Pico.m.scanline, SekCyclesDone(), mz80GetRegisterValue(NULL, 0));
- }
-
- // decide if we draw this line
-#if CAN_HANDLE_240_LINES
- if(!skip && ((!(pv->reg[1]&8) && y<224) || ((pv->reg[1]&8) && y<240)) )
-#else
- if(!skip && y<224)
-#endif
- PicoLine(y);
-
- if(PicoOpt&1)
- sound_timers_and_dac(y);
-
- // get samples from sound chips
- if (y == 224 && PsndOut) {
- int len = sound_render(0, PsndLen);
- if (PicoWriteSound) PicoWriteSound(len);
- // clear sound buffer
- sound_clear();
- }
-
- // Run scanline:
- //dprintf("m68k starting exec @ %06x", SekPc);
- if (Pico.m.dma_xfers) SekCycleCnt+=CheckDMA();
- if ((PicoOpt & 0x2000) && (Pico_mcd->m.busreq&3) == 1) {
- SekRunPS(cycles_68k, cycles_s68k); // "better/perfect sync"
- } else {
- SekRunM68k(cycles_68k);
- if ((Pico_mcd->m.busreq&3) == 1) // no busreq/no reset
- SekRunS68k(cycles_s68k);
- }
-
- if ((PicoOpt&4) && Pico.m.z80Run) {
- if (Pico.m.z80Run & 2) z80CycleAim+=cycles_z80;
- else {
- int cnt = SekCyclesDone() - z80startCycle;
- cnt = (cnt>>1)-(cnt>>5);
- //if (cnt > cycles_z80) printf("FIXME: z80 cycles: %i\n", cnt);
- if (cnt > cycles_z80) cnt = cycles_z80;
- Pico.m.z80Run |= 2;
- z80CycleAim+=cnt;
- }
- total_z80+=z80_run(z80CycleAim-total_z80);
- }
-
- update_chips();
- }
+ int len = sound_render(0, PsndLen);
+ if (PicoWriteSound) PicoWriteSound(len);
+ // clear sound buffer
+ sound_clear();
+}
- // draw a frame just after vblank in alternative render mode
- if (!PicoSkipFrame && (PicoOpt&0x10))
- PicoFrameFull();
- return 0;
-}
+#define PICO_CD
+#include "../PicoFrameHints.c"
PICO_INTERNAL int PicoFrameMCD(void)
if(!(PicoOpt&0x10))
PicoFrameStart();
- PicoFrameHintsMCD();
+ PicoFrameHints();
return 0;
}
int emu_check_save_file(int slot);\r
void emu_set_save_cbs(int gz);\r
void emu_forced_frame(void);\r
-int emu_cd_check(char **bios_file);\r
+int emu_cd_check(int *pregion);\r
int find_bios(int region, char **bios_file);\r
void scaling_update(void);\r
\r
\r
/* checks if romFileName points to valid MegaCD image\r
* if so, checks for suitable BIOS */\r
-int emu_cd_check(char **bios_file)\r
+int emu_cd_check(int *pregion)\r
{\r
unsigned char buf[32];\r
pm_file *cd_f;\r
printf("detected %s Sega/Mega CD image with %s region\n",\r
type == 2 ? "BIN" : "ISO", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
\r
- if (PicoRegionOverride) {\r
- region = PicoRegionOverride;\r
- printf("overrided region to %s\n", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
- }\r
-\r
- if (bios_file == NULL) return type;\r
-\r
- if (find_bios(region, bios_file))\r
- return type; // CD and BIOS detected\r
+ if (pregion != NULL) *pregion = region;\r
\r
- return -1; // CD detected but load failed\r
+ return type;\r
}\r
\r
int emu_ReloadRom(void)\r
char *used_rom_name = romFileName;\r
char ext[5];\r
pm_file *rom;\r
- int ret, cd_state;\r
+ int ret, cd_state, cd_region, cfg_loaded = 0;\r
\r
printf("emu_ReloadRom(%s)\n", romFileName);\r
\r
Stop_CD();\r
\r
// check for MegaCD image\r
- cd_state = emu_cd_check(&used_rom_name);\r
- if (cd_state > 0) {\r
+ cd_state = emu_cd_check(&cd_region);\r
+ if (cd_state > 0)\r
+ {\r
+ // valid CD image, check for BIOS..\r
+\r
+ // we need to have config loaded at this point\r
+ ret = emu_ReadConfig(1, 1);\r
+ if (!ret) emu_ReadConfig(0, 1);\r
+ cfg_loaded = 1;\r
+\r
+ if (PicoRegionOverride) {\r
+ cd_region = PicoRegionOverride;\r
+ printf("overrided region to %s\n", cd_region != 4 ? (cd_region == 8 ? "EU" : "JAP") : "USA");\r
+ }\r
+ if (!find_bios(cd_region, &used_rom_name)) {\r
+ // bios_help() ?\r
+ return 0;\r
+ }\r
+\r
PicoMCD |= 1;\r
get_ext(used_rom_name, ext);\r
- } else if (cd_state == -1) {\r
- // bios_help() ?\r
- return 0;\r
- } else {\r
+ }\r
+ else\r
+ {\r
if (PicoMCD & 1) Stop_CD();\r
PicoMCD &= ~1;\r
}\r
}\r
\r
// load config for this ROM (do this before insert to get correct region)\r
- ret = emu_ReadConfig(1, 1);\r
- if (!ret)\r
- emu_ReadConfig(0, 1);\r
+ if (!cfg_loaded) {\r
+ ret = emu_ReadConfig(1, 1);\r
+ if (!ret) emu_ReadConfig(0, 1);\r
+ }\r
\r
printf("PicoCartInsert(%p, %d);\n", rom_data, rom_size);\r
if(PicoCartInsert(rom_data, rom_size)) {\r
int emu_check_save_file(int slot);\r
void emu_set_save_cbs(int gz);\r
void emu_forced_frame(void);\r
-int emu_cd_check(char **bios_file);\r
+int emu_cd_check(int *pregion);\r
int find_bios(int region, char **bios_file);\r
void scaling_update(void);\r
\r