#include "../sound/sound.h"
-extern unsigned char formatted_bram[8*0x10];
+extern unsigned char formatted_bram[4*0x10];
int PicoInitMCD(void)
int PicoResetMCD(int hard)
{
- memset(Pico_mcd->prg_ram, 0, sizeof(Pico_mcd->prg_ram));
- memset(Pico_mcd->word_ram, 0, sizeof(Pico_mcd->word_ram));
- memset(Pico_mcd->pcm_ram, 0, sizeof(Pico_mcd->pcm_ram));
+ memset(Pico_mcd->prg_ram, 0, sizeof(Pico_mcd->prg_ram));
+ memset(Pico_mcd->word_ram2M, 0, sizeof(Pico_mcd->word_ram2M));
+ memset(Pico_mcd->pcm_ram, 0, sizeof(Pico_mcd->pcm_ram));
if (hard) {
+ int fmt_size = sizeof(formatted_bram);
memset(Pico_mcd->bram, 0, sizeof(Pico_mcd->bram));
- memcpy(Pico_mcd->bram + sizeof(Pico_mcd->bram) - 8*0x10, formatted_bram, 8*0x10);
+ memcpy(Pico_mcd->bram + sizeof(Pico_mcd->bram) - fmt_size, formatted_bram, fmt_size);
}
memset(Pico_mcd->s68k_regs, 0, sizeof(Pico_mcd->s68k_regs));
memset(&Pico_mcd->pcm, 0, sizeof(Pico_mcd->pcm));
#endif
}
+#define PS_STEP_M68K ((488<<16)/20) // ~24
+//#define PS_STEP_S68K 13
+
+#ifndef _ASM_CD_PICO_C
+static __inline void SekRunPS(int cyc_m68k, int cyc_s68k)
+{
+ int cycn, cycn_s68k, cyc_do;
+ int d_cm = 0, d_cs = 0, ex;
+ SekCycleAim+=cyc_m68k;
+ SekCycleAimS68k+=cyc_s68k;
+
+// fprintf(stderr, "=== start %3i/%3i [%3i/%3i] {%05i.%i} ===\n", cyc_m68k, cyc_s68k,
+// SekCycleAim-SekCycleCnt, SekCycleAimS68k-SekCycleCntS68k, Pico.m.frame_count, Pico.m.scanline);
+
+ /* loop 488 downto 0 in steps of PS_STEP */
+ for (cycn = (488<<16)-PS_STEP_M68K; cycn >= 0; cycn -= PS_STEP_M68K)
+ {
+ ex = 0;
+ cycn_s68k = (cycn + cycn/2 + cycn/8) >> 16;
+//fprintf(stderr, "%3i/%3i: ", cycn>>16, cycn_s68k);
+ if ((cyc_do = SekCycleAim-SekCycleCnt-(cycn>>16)) > 0) {
+#if defined(EMU_C68K)
+ PicoCpu.cycles = cyc_do;
+ CycloneRun(&PicoCpu);
+ SekCycleCnt += cyc_do - PicoCpu.cycles;
+#elif defined(EMU_M68K)
+ m68k_set_context(&PicoM68kCPU);
+ SekCycleCnt += (ex = m68k_execute(cyc_do));
+#endif
+ }
+//fprintf(stderr, "%3i ", ex); d_cm += ex; ex = 0;
+ if ((cyc_do = SekCycleAimS68k-SekCycleCntS68k-cycn_s68k) > 0) {
+#if defined(EMU_C68K)
+ PicoCpuS68k.cycles = cyc_do;
+ CycloneRun(&PicoCpuS68k);
+ SekCycleCntS68k += cyc_do - PicoCpuS68k.cycles;
+#elif defined(EMU_M68K)
+ m68k_set_context(&PicoS68kCPU);
+ SekCycleCntS68k += (ex = m68k_execute(cyc_do));
+#endif
+ }
+//fprintf(stderr, "%3i\n", ex); d_cs += ex;
+ }
+
+//fprintf(stderr, "== end %3i/%3i ==\n", d_cm, d_cs);
+}
+#else
+void SekRunPS(int cyc_m68k, int cyc_s68k);
+#endif
+
+
static __inline void check_cd_dma(void)
{
int ddx;
gfx_cd_update();
}
-// to be called on 224 or line_sample scanlines only
-static __inline void getSamples(int y)
-{
- if(y == 224) {
- //dprintf("sta%i: %i [%i]", (emustatus & 2), emustatus, y);
- if(emustatus & 2)
- sound_render(PsndLen/2, PsndLen-PsndLen/2);
- else sound_render(0, PsndLen);
- if (emustatus&1) emustatus|=2; else emustatus&=~2;
- if (PicoWriteSound) PicoWriteSound();
- // clear sound buffer
- sound_clear();
- //memset(PsndOut, 0, (PicoOpt & 8) ? (PsndLen<<2) : (PsndLen<<1));
- }
- else if(emustatus & 3) {
- emustatus|= 2;
- emustatus&=~1;
- sound_render(0, PsndLen/2);
- }
-}
-
static int PicoFrameHintsMCD(void)
{
sound_timers_and_dac(y);
// get samples from sound chips
- if(y == 32 && PsndOut)
- emustatus &= ~1;
- else if((y == 224 || y == line_sample) && PsndOut)
- getSamples(y);
+ 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_bytes) SekCycleCnt+=CheckDMA();
- SekRun(cycles_68k);
- if ((Pico_mcd->m.busreq&3) == 1) { // no busreq/no reset
-#if 0
- int i;
- FILE *f = fopen("prg_ram.bin", "wb");
- for (i = 0; i < 0x80000; i+=2)
- {
- int tmp = Pico_mcd->prg_ram[i];
- Pico_mcd->prg_ram[i] = Pico_mcd->prg_ram[i+1];
- Pico_mcd->prg_ram[i+1] = tmp;
- }
- fwrite(Pico_mcd->prg_ram, 1, 0x80000, f);
- fclose(f);
- exit(1);
-#endif
- //dprintf("s68k starting exec @ %06x", SekPcS68k);
- SekRunS68k(cycles_s68k);
+ if((PicoOpt & 0x2000) && (Pico_mcd->m.busreq&3) == 1) {
+ SekRunPS(cycles_68k, cycles_s68k); // "better/perfect sync"
+ } else {
+ SekRun(cycles_68k);
+ if ((Pico_mcd->m.busreq&3) == 1) // no busreq/no reset
+ SekRunS68k(cycles_s68k);
}
if((PicoOpt&4) && Pico.m.z80Run) {