// This is part of Pico Library
// (c) Copyright 2004 Dave, All rights reserved.
-// (c) Copyright 2006 notaz, All rights reserved.
+// (c) Copyright 2007 notaz, All rights reserved.
// Free for non-commercial use.
// For commercial use, separate licencing terms must be obtained.
#include "../sound/sound.h"
-int counter75hz = 0;
+extern unsigned char formatted_bram[8*0x10];
int PicoInitMCD(void)
int PicoResetMCD(int hard)
{
- // clear everything except BIOS
- memset(Pico_mcd->prg_ram, 0, sizeof(mcd_state) - sizeof(Pico_mcd->bios));
- PicoMCD |= 2; // s68k reset pending
- counter75hz = 0;
+ memset(Pico_mcd->prg_ram, 0, sizeof(Pico_mcd->prg_ram));
+ memset(Pico_mcd->word_ram, 0, sizeof(Pico_mcd->word_ram));
+ if (hard) {
+ memset(Pico_mcd->bram, 0, sizeof(Pico_mcd->bram));
+ memcpy(Pico_mcd->bram + sizeof(Pico_mcd->bram) - 8*0x10, formatted_bram, 8*0x10);
+ }
+ memset(Pico_mcd->s68k_regs, 0, sizeof(Pico_mcd->s68k_regs));
+
+ *(unsigned int *)(Pico_mcd->bios + 0x70) = 0xffffffff; // reset hint vector (simplest way to implement reg6)
+ Pico_mcd->m.state_flags |= 2; // s68k reset pending
+ Pico_mcd->s68k_regs[3] = 1; // 2M word RAM mode with m68k access after reset
+ Pico_mcd->m.counter75hz = 0;
LC89510_Reset();
Reset_CD();
+ gfx_cd_reset();
return 0;
}
int cyc_do;
SekCycleAim+=cyc;
if((cyc_do=SekCycleAim-SekCycleCnt) < 0) return;
-#if defined(EMU_M68K)
+#if defined(EMU_C68K)
+ PicoCpu.cycles=cyc_do;
+ CycloneRun(&PicoCpu);
+ SekCycleCnt+=cyc_do-PicoCpu.cycles;
+#elif defined(EMU_M68K)
m68k_set_context(&PicoM68kCPU);
SekCycleCnt+=m68k_execute(cyc_do);
#endif
int cyc_do;
SekCycleAimS68k+=cyc;
if((cyc_do=SekCycleAimS68k-SekCycleCntS68k) < 0) return;
-#if defined(EMU_M68K)
+#if defined(EMU_C68K)
+ PicoCpuS68k.cycles=cyc_do;
+ CycloneRun(&PicoCpuS68k);
+ SekCycleCntS68k+=cyc_do-PicoCpuS68k.cycles;
+#elif defined(EMU_M68K)
m68k_set_context(&PicoS68kCPU);
SekCycleCntS68k+=m68k_execute(cyc_do);
#endif
}
-// TODO: tidy
-extern unsigned char m68k_regs[0x40];
-extern unsigned char s68k_regs[0x200];
+static __inline void check_cd_dma(void)
+{
+ int ddx;
+
+ if (!(Pico_mcd->scd.Status_CDC & 0x08)) return;
+
+ ddx = Pico_mcd->s68k_regs[4] & 7;
+ if (ddx < 2) return; // invalid
+ if (ddx < 4) {
+ Pico_mcd->s68k_regs[4] |= 0x40; // Data set ready in host port
+ return;
+ }
+ if (ddx == 6) return; // invalid
+
+ Update_CDC_TRansfer(ddx); // now go and do the actual transfer
+}
+
+// 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
+ memset(PsndOut, 0, (PicoOpt & 8) ? (PsndLen<<2) : (PsndLen<<1));
+ }
+ else if(emustatus & 3) {
+ emustatus|= 2;
+ emustatus&=~1;
+ sound_render(0, PsndLen/2);
+ }
+}
+
+
// Accurate but slower frame which does hints
static int PicoFrameHintsMCD(void)
{
struct PicoVideo *pv=&Pico.video;
- int total_z80=0,lines,y,lines_vis = 224,z80CycleAim = 0,line_sample;
+ int total_z80=0,lines,y,lines_vis = 224,z80CycleAim = 0,line_sample,counter75hz_lim;
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
//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;
+ counter75hz_lim = 2080;
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;
+ counter75hz_lim = 2096;
line_sample = 93;
}
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
{
if(y == 32 && PsndOut)
emustatus &= ~1;
else if((y == 224 || y == line_sample) && PsndOut)
- ;//getSamples(y);
+ getSamples(y);
// Run scanline:
//dprintf("m68k starting exec @ %06x", SekPc);
+ if(Pico.m.dma_bytes) SekCycleCnt+=CheckDMA();
SekRun(cycles_68k);
- if ((Pico_mcd->m68k_regs[1]&3) == 1) { // no busreq/no reset
+ if ((Pico_mcd->m.busreq&3) == 1) { // no busreq/no reset
#if 0
int i;
FILE *f = fopen("prg_ram.bin", "wb");
total_z80+=z80_run(z80CycleAim-total_z80);
}
- // if cdd is on, counter elapsed and irq4 is not masked, do irq4
- if ((Pico_mcd->s68k_regs[0x37]&4) && ++counter75hz > 209 && (Pico_mcd->s68k_regs[0x33]&(1<<4))) {
- counter75hz = 0;
+ if ((Pico_mcd->m.counter75hz+=10) >= counter75hz_lim) {
+ Pico_mcd->m.counter75hz -= counter75hz_lim;
Check_CD_Command();
}
+
+ if (Pico_mcd->rot_comp.Reg_58 & 0x8000)
+ gfx_cd_update();
}
// draw a frame just after vblank in alternative render mode