mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 07:17:45 -04:00
gen/cd frame loops merged
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@250 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
1dceadaee4
commit
bf5fbbb4b9
7 changed files with 109 additions and 165 deletions
|
@ -199,7 +199,7 @@ PICO_INTERNAL int CheckDMA(void)
|
|||
return burn;
|
||||
}
|
||||
|
||||
static __inline void SekRun(int cyc)
|
||||
static __inline void SekRunM68k(int cyc)
|
||||
{
|
||||
int cyc_do;
|
||||
SekCycleAim+=cyc;
|
||||
|
@ -496,7 +496,7 @@ static int PicoFrameSimple(void)
|
|||
if (CheckIdle()) break;
|
||||
|
||||
lines += lines_step;
|
||||
SekRun(cycles_68k_block);
|
||||
SekRunM68k(cycles_68k_block);
|
||||
|
||||
PicoRunZ80Simple(line, lines);
|
||||
line=lines;
|
||||
|
@ -541,7 +541,7 @@ static int PicoFrameSimple(void)
|
|||
// a gap between flags set and vint
|
||||
pv->pending_ints|=0x20;
|
||||
pv->status|=8; // go into vblank
|
||||
SekRun(68+4);
|
||||
SekRunM68k(68+4);
|
||||
|
||||
// ---- V-Blanking period ----
|
||||
// fix line counts
|
||||
|
@ -568,7 +568,7 @@ static int PicoFrameSimple(void)
|
|||
while (sects) {
|
||||
lines += lines_step;
|
||||
|
||||
SekRun(cycles_68k_vblock);
|
||||
SekRunM68k(cycles_68k_vblock);
|
||||
|
||||
PicoRunZ80Simple(line, lines);
|
||||
line=lines;
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#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 \
|
||||
|
@ -27,6 +29,25 @@
|
|||
} \
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
|
@ -47,6 +68,9 @@ static int PicoFrameHints(void)
|
|||
}
|
||||
|
||||
SekCyclesReset();
|
||||
#ifdef PICO_CD
|
||||
SekCyclesResetS68k();
|
||||
#endif
|
||||
|
||||
pv->status&=~0x88; // clear V-Int, come out of vblank
|
||||
|
||||
|
@ -54,8 +78,7 @@ static int PicoFrameHints(void)
|
|||
//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++)
|
||||
{
|
||||
|
@ -69,6 +92,9 @@ static int PicoFrameHints(void)
|
|||
}
|
||||
|
||||
PAD_DELAY
|
||||
#ifdef PICO_CD
|
||||
check_cd_dma();
|
||||
#endif
|
||||
|
||||
// H-Interrupts:
|
||||
if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
|
||||
|
@ -92,16 +118,21 @@ static int PicoFrameHints(void)
|
|||
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)
|
||||
|
@ -112,6 +143,9 @@ static int PicoFrameHints(void)
|
|||
Pico.video.status|=0x200;
|
||||
|
||||
PAD_DELAY
|
||||
#ifdef PICO_CD
|
||||
check_cd_dma();
|
||||
#endif
|
||||
|
||||
// Last H-Int:
|
||||
if (--hint < 0)
|
||||
|
@ -130,7 +164,7 @@ static int PicoFrameHints(void)
|
|||
// 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);
|
||||
|
@ -142,13 +176,20 @@ static int PicoFrameHints(void)
|
|||
sound_timers_and_dac(y);
|
||||
|
||||
// get samples from sound chips
|
||||
if ((y == 224) && PsndOut)
|
||||
#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;
|
||||
|
@ -158,14 +199,20 @@ static int PicoFrameHints(void)
|
|||
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
|
||||
|
@ -177,4 +224,5 @@ static int PicoFrameHints(void)
|
|||
|
||||
#undef PAD_DELAY
|
||||
#undef Z80_RUN
|
||||
#undef CPUS_RUN
|
||||
|
||||
|
|
|
@ -119,7 +119,10 @@ extern unsigned int SekCycleCntT; // total cycle counter, updated once per frame
|
|||
extern int SekCycleCntS68k;
|
||||
extern int SekCycleAimS68k;
|
||||
|
||||
#define SekCyclesResetS68k() {SekCycleCntS68k=SekCycleAimS68k=0;}
|
||||
#define SekCyclesResetS68k() { \
|
||||
SekCycleCntS68k-=SekCycleAimS68k; \
|
||||
SekCycleAimS68k=0; \
|
||||
}
|
||||
#define SekCyclesDoneS68k() (SekCycleAimS68k-SekCyclesLeftS68k)
|
||||
|
||||
// debug cyclone
|
||||
|
|
124
Pico/cd/Pico.c
124
Pico/cd/Pico.c
|
@ -223,133 +223,17 @@ static __inline void update_chips(void)
|
|||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
@ -357,7 +241,7 @@ PICO_INTERNAL int PicoFrameMCD(void)
|
|||
if(!(PicoOpt&0x10))
|
||||
PicoFrameStart();
|
||||
|
||||
PicoFrameHintsMCD();
|
||||
PicoFrameHints();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ char *emu_GetSaveFName(int load, int is_sram, int slot);
|
|||
int emu_check_save_file(int slot);
|
||||
void emu_set_save_cbs(int gz);
|
||||
void emu_forced_frame(void);
|
||||
int emu_cd_check(char **bios_file);
|
||||
int emu_cd_check(int *pregion);
|
||||
int find_bios(int region, char **bios_file);
|
||||
void scaling_update(void);
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ int find_bios(int region, char **bios_file)
|
|||
|
||||
/* checks if romFileName points to valid MegaCD image
|
||||
* if so, checks for suitable BIOS */
|
||||
int emu_cd_check(char **bios_file)
|
||||
int emu_cd_check(int *pregion)
|
||||
{
|
||||
unsigned char buf[32];
|
||||
pm_file *cd_f;
|
||||
|
@ -183,17 +183,9 @@ int emu_cd_check(char **bios_file)
|
|||
printf("detected %s Sega/Mega CD image with %s region\n",
|
||||
type == 2 ? "BIN" : "ISO", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");
|
||||
|
||||
if (PicoRegionOverride) {
|
||||
region = PicoRegionOverride;
|
||||
printf("overrided region to %s\n", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");
|
||||
}
|
||||
if (pregion != NULL) *pregion = region;
|
||||
|
||||
if (bios_file == NULL) return type;
|
||||
|
||||
if (find_bios(region, bios_file))
|
||||
return type; // CD and BIOS detected
|
||||
|
||||
return -1; // CD detected but load failed
|
||||
return type;
|
||||
}
|
||||
|
||||
int emu_ReloadRom(void)
|
||||
|
@ -202,7 +194,7 @@ int emu_ReloadRom(void)
|
|||
char *used_rom_name = romFileName;
|
||||
char ext[5];
|
||||
pm_file *rom;
|
||||
int ret, cd_state;
|
||||
int ret, cd_state, cd_region, cfg_loaded = 0;
|
||||
|
||||
printf("emu_ReloadRom(%s)\n", romFileName);
|
||||
|
||||
|
@ -271,14 +263,30 @@ int emu_ReloadRom(void)
|
|||
Stop_CD();
|
||||
|
||||
// check for MegaCD image
|
||||
cd_state = emu_cd_check(&used_rom_name);
|
||||
if (cd_state > 0) {
|
||||
PicoMCD |= 1;
|
||||
get_ext(used_rom_name, ext);
|
||||
} else if (cd_state == -1) {
|
||||
cd_state = emu_cd_check(&cd_region);
|
||||
if (cd_state > 0)
|
||||
{
|
||||
// valid CD image, check for BIOS..
|
||||
|
||||
// we need to have config loaded at this point
|
||||
ret = emu_ReadConfig(1, 1);
|
||||
if (!ret) emu_ReadConfig(0, 1);
|
||||
cfg_loaded = 1;
|
||||
|
||||
if (PicoRegionOverride) {
|
||||
cd_region = PicoRegionOverride;
|
||||
printf("overrided region to %s\n", cd_region != 4 ? (cd_region == 8 ? "EU" : "JAP") : "USA");
|
||||
}
|
||||
if (!find_bios(cd_region, &used_rom_name)) {
|
||||
// bios_help() ?
|
||||
return 0;
|
||||
} else {
|
||||
}
|
||||
|
||||
PicoMCD |= 1;
|
||||
get_ext(used_rom_name, ext);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (PicoMCD & 1) Stop_CD();
|
||||
PicoMCD &= ~1;
|
||||
}
|
||||
|
@ -317,9 +325,10 @@ int emu_ReloadRom(void)
|
|||
}
|
||||
|
||||
// load config for this ROM (do this before insert to get correct region)
|
||||
if (!cfg_loaded) {
|
||||
ret = emu_ReadConfig(1, 1);
|
||||
if (!ret)
|
||||
emu_ReadConfig(0, 1);
|
||||
if (!ret) emu_ReadConfig(0, 1);
|
||||
}
|
||||
|
||||
printf("PicoCartInsert(%p, %d);\n", rom_data, rom_size);
|
||||
if(PicoCartInsert(rom_data, rom_size)) {
|
||||
|
|
|
@ -53,7 +53,7 @@ char *emu_GetSaveFName(int load, int is_sram, int slot);
|
|||
int emu_check_save_file(int slot);
|
||||
void emu_set_save_cbs(int gz);
|
||||
void emu_forced_frame(void);
|
||||
int emu_cd_check(char **bios_file);
|
||||
int emu_cd_check(int *pregion);
|
||||
int find_bios(int region, char **bios_file);
|
||||
void scaling_update(void);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue