#include "sound/sound.h"\r
#include "sound/ym2612.h"\r
\r
-int PicoVer=0x0080;\r
+int PicoVer=0x0110;\r
struct Pico Pico;\r
int PicoOpt=0; // disable everything by default\r
int PicoSkipFrame=0; // skip rendering frame?\r
int PicoRegionOverride = 0; // override the region detection 0: Auto, 1: Japan NTSC, 2: Japan PAL, 4: US, 8: Europe\r
+int PicoAutoRgnOrder = 0;\r
int emustatus = 0;\r
-void (*PicoWriteSound)(void) = 0; // called once per frame at the best time to send sound buffer (PsndOut) to hardware\r
+void (*PicoWriteSound)(int len) = 0; // called once per frame at the best time to send sound buffer (PsndOut) to hardware\r
\r
struct PicoSRAM SRam;\r
int z80startCycle = 0, z80stopCycle = 0; // in 68k cycles\r
//int z80ExtraCycles = 0;\r
-int PicoPad[2]; // Joypads, format is SACB RLDU\r
-int PicoMCD = 0; // mega CD status\r
+int PicoPad[2]; // Joypads, format is SACB RLDU\r
+int PicoMCD = 0; // mega CD status: scd_started, reset_pending\r
\r
// to be called once on emu init\r
int PicoInit(void)\r
SekInit();\r
z80_init(); // init even if we aren't going to use it\r
\r
- // Setup memory callbacks:\r
- PicoMemInit();\r
-\r
PicoInitMCD();\r
\r
// notaz: sram\r
// to be called once on emu exit\r
void PicoExit(void)\r
{\r
- PicoExitMCD();\r
+ if (PicoMCD&1)\r
+ PicoExitMCD();\r
z80_exit();\r
\r
// notaz: sram\r
\r
if (Pico.romsize<=0) return 1;\r
\r
+ // setup correct memory map\r
+ if (PicoMCD & 1)\r
+ PicoMemSetupCD();\r
+ else PicoMemSetup();\r
PicoMemReset();\r
SekReset();\r
SekCycleCntT=0;\r
// reset VDP state, VRAM and PicoMisc\r
//memset(&Pico.video,0,sizeof(Pico.video));\r
//memset(&Pico.vram,0,sizeof(Pico.vram));\r
+ memset(Pico.ioports,0,sizeof(Pico.ioports)); // needed for MCD to reset properly\r
memset(&Pico.m,0,sizeof(Pico.m));\r
Pico.video.pending_ints=0;\r
emustatus = 0;\r
c=region>>(i<<3); c&=0xff;\r
if (c<=' ') continue;\r
\r
- if (c=='J') support|=1;\r
- else if (c=='U') support|=4;\r
- else if (c=='E') support|=8;\r
+ if (c=='J') support|=1;\r
+ else if (c=='U') support|=4;\r
+ else if (c=='E') support|=8;\r
+ else if (c=='j') {support|=1; break; }\r
+ else if (c=='u') {support|=4; break; }\r
+ else if (c=='e') {support|=8; break; }\r
else\r
{\r
// New style code:\r
}\r
}\r
\r
+ // auto detection order override\r
+ if (PicoAutoRgnOrder) {\r
+ if (((PicoAutoRgnOrder>>0)&0xf) & support) support = (PicoAutoRgnOrder>>0)&0xf;\r
+ else if (((PicoAutoRgnOrder>>4)&0xf) & support) support = (PicoAutoRgnOrder>>4)&0xf;\r
+ else if (((PicoAutoRgnOrder>>8)&0xf) & support) support = (PicoAutoRgnOrder>>8)&0xf;\r
+ }\r
+\r
// Try to pick the best hardware value for English/50hz:\r
if (support&8) { hw=0xc0; pal=1; } // Europe\r
else if (support&4) hw=0x80; // USA\r
{\r
int cyc_do;\r
SekCycleAim+=cyc;\r
-#if 0\r
- if(Pico.m.dma_bytes) {\r
- int burn=0;\r
- if((Pico.video.status&8)||!(Pico.video.reg[1]&0x40)) { // vblank?\r
- if(Pico.m.dma_bytes < 205) {\r
- burn = Pico.m.dma_bytes*(((488<<8)/205))>>8;\r
- Pico.m.dma_bytes = 0;\r
- } else {\r
- burn += 488;\r
- Pico.m.dma_bytes -= 205;\r
- }\r
- } else {\r
- if(Pico.m.dma_bytes < 18) {\r
- burn = Pico.m.dma_bytes*(((488<<8)/18))>>8;\r
- Pico.m.dma_bytes = 0;\r
- } else {\r
- burn += 488;\r
- Pico.m.dma_bytes -= 18;\r
- }\r
- }\r
- SekCycleCnt+=burn;\r
- dprintf("~DmaSlow %i burn=%i do=%i [%i|%i]", Pico.m.dma_bytes, burn, SekCycleAim-SekCycleCnt,\r
- Pico.m.scanline, SekCyclesDone());\r
- }\r
-#endif\r
//dprintf("aim: %i, cnt: %i", SekCycleAim, SekCycleCnt);\r
if((cyc_do=SekCycleAim-SekCycleCnt) <= 0) return;\r
//dprintf("cyc_do: %i", cyc_do);\r
// to be called on 224 or line_sample scanlines only\r
static __inline void getSamples(int y)\r
{\r
+ static int curr_pos = 0;\r
+\r
if(y == 224) {\r
//dprintf("sta%i: %i [%i]", (emustatus & 2), emustatus, y);\r
if(emustatus & 2)\r
- sound_render(PsndLen/2, PsndLen-PsndLen/2);\r
- else sound_render(0, PsndLen);\r
+ curr_pos += sound_render(curr_pos, PsndLen-PsndLen/2);\r
+ else curr_pos = sound_render(0, PsndLen);\r
if (emustatus&1) emustatus|=2; else emustatus&=~2;\r
- if (PicoWriteSound) PicoWriteSound();\r
+ if (PicoWriteSound) PicoWriteSound(curr_pos);\r
// clear sound buffer\r
- memset(PsndOut, 0, (PicoOpt & 8) ? (PsndLen<<2) : (PsndLen<<1));\r
+ sound_clear();\r
}\r
else if(emustatus & 3) {\r
emustatus|= 2;\r
emustatus&=~1;\r
- sound_render(0, PsndLen/2);\r
+ curr_pos = sound_render(0, PsndLen/2);\r
}\r
}\r
\r
\r
// here we render sound if ym2612 is disabled\r
if(!(PicoOpt&1) && PsndOut) {\r
- sound_render(0, PsndLen);\r
- if(PicoWriteSound) PicoWriteSound();\r
+ int len = sound_render(0, PsndLen);\r
+ if(PicoWriteSound) PicoWriteSound(len);\r
// clear sound buffer\r
- memset(PsndOut, 0, (PicoOpt & 8) ? (PsndLen<<2) : (PsndLen<<1));\r
+ sound_clear();\r
}\r
\r
// render screen\r
{\r
int acc;\r
\r
+ Pico.m.frame_count++;\r
+\r
if (PicoMCD & 1) {\r
PicoFrameMCD();\r
return 0;\r
return 0;\r
}\r
\r
-static int DefaultCram(int cram)\r
-{\r
- int high=0x0841;\r
- // Convert 0000bbbb ggggrrrr\r
- // to rrrr1ggg g10bbbb1\r
- high|=(cram&0x00f)<<12; // Red\r
- high|=(cram&0x0f0)<< 3; // Green\r
- high|=(cram&0xf00)>> 7; // Blue\r
- return high;\r
-}\r
-\r
-// Function to convert Megadrive Cram into a native colour:\r
-int (*PicoCram)(int cram)=DefaultCram;\r
+// callback to output message from emu\r
+void (*PicoMessage)(const char *msg)=NULL;\r
\r
#if defined(__DEBUG_PRINT) || defined(WIN32)\r
// tmp debug: dump some stuff\r