X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2Fcd%2FPico.c;h=5669238ffa39c811f43c89eddbc9d8f8eeb009d6;hb=83c093a48ab58670ea82d0ec81658daa9f9b950a;hp=0759acb4157cd19333057add11c4262ab9085eb0;hpb=d9153729685381acb0559d8a4fdca47cb839427a;p=picodrive.git diff --git a/Pico/cd/Pico.c b/Pico/cd/Pico.c index 0759acb..5669238 100644 --- a/Pico/cd/Pico.c +++ b/Pico/cd/Pico.c @@ -1,19 +1,14 @@ -// This is part of Pico Library - -// (c) Copyright 2004 Dave, 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 "../PicoInt.h" -#include "../sound/sound.h" extern unsigned char formatted_bram[4*0x10]; extern unsigned int s68k_poll_adclk; +void (*PicoMCDopenTray)(void) = NULL; +int (*PicoMCDcloseTray)(void) = NULL; #define dump_ram(ram,fname) \ { \ @@ -36,7 +31,7 @@ extern unsigned int s68k_poll_adclk; } -int PicoInitMCD(void) +PICO_INTERNAL int PicoInitMCD(void) { SekInitS68k(); Init_CD_Driver(); @@ -45,7 +40,7 @@ int PicoInitMCD(void) } -void PicoExitMCD(void) +PICO_INTERNAL void PicoExitMCD(void) { End_CD_Driver(); @@ -53,7 +48,7 @@ void PicoExitMCD(void) //dump_ram(Pico.ram, "ram.bin"); } -int PicoResetMCD(int hard) +PICO_INTERNAL int PicoResetMCD(int hard) { if (hard) { int fmt_size = sizeof(formatted_bram); @@ -79,10 +74,16 @@ int PicoResetMCD(int hard) //PicoMemResetCDdecode(1); // don't have to call this in 2M mode #endif + // use SRam.data for RAM cart + if (SRam.data) free(SRam.data); + SRam.data = NULL; + if (PicoOpt&0x8000) + SRam.data = calloc(1, 0x12000); + return 0; } -static __inline void SekRun(int cyc) +static __inline void SekRunM68k(int cyc) { int cyc_do; SekCycleAim+=cyc; @@ -121,7 +122,7 @@ void SekRunPS(int cyc_m68k, int cyc_s68k); static __inline void SekRunPS(int cyc_m68k, int cyc_s68k) { int cycn, cycn_s68k, cyc_do; - int d_cm = 0, d_cs = 0, ex; + int ex; SekCycleAim+=cyc_m68k; SekCycleAimS68k+=cyc_s68k; @@ -133,7 +134,6 @@ static __inline void SekRunPS(int cyc_m68k, int cyc_s68k) { 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; @@ -144,7 +144,6 @@ static __inline void SekRunPS(int cyc_m68k, int cyc_s68k) 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; @@ -155,10 +154,7 @@ static __inline void SekRunPS(int cyc_m68k, int cyc_s68k) 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); } #endif @@ -214,13 +210,15 @@ static __inline void update_chips(void) // delayed setting of DMNA bit (needed for Silpheed) if (Pico_mcd->m.state_flags & 2) { Pico_mcd->m.state_flags &= ~2; - Pico_mcd->s68k_regs[3] |= 2; - Pico_mcd->s68k_regs[3] &= ~1; + if (!(Pico_mcd->s68k_regs[3] & 4)) { + Pico_mcd->s68k_regs[3] |= 2; + Pico_mcd->s68k_regs[3] &= ~1; #ifdef USE_POLL_DETECT - if ((s68k_poll_adclk&0xfe) == 2) { - SekSetStopS68k(0); s68k_poll_adclk = 0; - } + if ((s68k_poll_adclk&0xfe) == 2) { + SekSetStopS68k(0); s68k_poll_adclk = 0; + } #endif + } } } @@ -287,7 +285,7 @@ static int PicoFrameHintsMCD(void) { //dprintf("vint: @ %06x [%i|%i]", SekPc, y, SekCycleCnt); pv->status|=0x88; // V-Int happened, go into vblank - SekRun(128); SekCycleAim-=128; // there must be a gap between H and V ints, also after vblank bit set (Mazin Saga, Bram Stoker's Dracula) + 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); @@ -325,7 +323,7 @@ static int PicoFrameHintsMCD(void) if ((PicoOpt & 0x2000) && (Pico_mcd->m.busreq&3) == 1) { SekRunPS(cycles_68k, cycles_s68k); // "better/perfect sync" } else { - SekRun(cycles_68k); + SekRunM68k(cycles_68k); if ((Pico_mcd->m.busreq&3) == 1) // no busreq/no reset SekRunS68k(cycles_s68k); } @@ -354,7 +352,7 @@ static int PicoFrameHintsMCD(void) } -int PicoFrameMCD(void) +PICO_INTERNAL int PicoFrameMCD(void) { if(!(PicoOpt&0x10)) PicoFrameStart();