From: notaz Date: Sun, 11 Nov 2007 15:38:27 +0000 (+0000) Subject: dualcore integration in famc, bram cart C code, psp bugfixes X-Git-Tag: v1.85~624 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8022f53da61b8e70420a3bac97250119bbe26457;p=picodrive.git dualcore integration in famc, bram cart C code, psp bugfixes git-svn-id: file:///home/notaz/opt/svn/PicoDrive@294 be3aeb3a-fb24-0410-a615-afba39da0efa --- diff --git a/Pico/Debug.c b/Pico/Debug.c index 8c9db8d5..d46f08d4 100644 --- a/Pico/Debug.c +++ b/Pico/Debug.c @@ -41,7 +41,7 @@ static int otherRun(void) CycloneRun(&PicoCpuCM68k); return 1-PicoCpuCM68k.cycles; #elif defined(EMU_F68K) - return fm68k_emulate(1); + return fm68k_emulate(1, 0); #endif } diff --git a/Pico/Pico.c b/Pico/Pico.c index aec354d2..bc764b6b 100644 --- a/Pico/Pico.c +++ b/Pico/Pico.c @@ -213,7 +213,7 @@ static __inline void SekRunM68k(int cyc) #elif defined(EMU_M68K) SekCycleCnt+=m68k_execute(cyc_do); #elif defined(EMU_F68K) - SekCycleCnt+=fm68k_emulate(cyc_do+1); + SekCycleCnt+=fm68k_emulate(cyc_do+1, 0); #endif } @@ -230,7 +230,7 @@ static __inline void SekStep(void) #elif defined(EMU_M68K) SekCycleCnt+=m68k_execute(1); #elif defined(EMU_F68K) - SekCycleCnt+=fm68k_emulate(1); + SekCycleCnt+=fm68k_emulate(1, 0); #endif SekCycleAim=realaim; } diff --git a/Pico/cd/Memory.c b/Pico/cd/Memory.c index 360c0cf5..8053185f 100644 --- a/Pico/cd/Memory.c +++ b/Pico/cd/Memory.c @@ -392,6 +392,24 @@ static u32 OtherRead16End(u32 a, int realsize) goto end; } + if (a==0x400000) { + if (SRam.data != NULL) d=3; // 64k cart + goto end; + } + + if ((a&0xfe0000)==0x600000) { + if (SRam.data != NULL) { + d=SRam.data[((a>>1)&0xffff)+0x2000]; + if (realsize == 8) d|=d<<8; + } + goto end; + } + + if (a==0x7ffffe) { + d=Pico_mcd->m.bcram_reg; + goto end; + } + dprintf("m68k FIXME: unusual r%i: %06x @%06x", realsize&~1, (a&0xfffffe)+(realsize&1), SekPc); end: @@ -403,6 +421,19 @@ static void OtherWrite8End(u32 a, u32 d, int realsize) { if ((a&0xffffc0)==0xa12000) { m68k_reg_write8(a, d); return; } + if ((a&0xfe0000)==0x600000) { + if (SRam.data != NULL && (Pico_mcd->m.bcram_reg&1)) { + SRam.data[((a>>1)&0xffff)+0x2000]=d; + SRam.changed = 1; + } + return; + } + + if (a==0x7fffff) { + Pico_mcd->m.bcram_reg=d; + return; + } + dprintf("m68k FIXME: strange w%i: [%06x], %08x @%06x", realsize, a&0xffffff, d, SekPc); } diff --git a/Pico/cd/Memory.s b/Pico/cd/Memory.s index 3b49cacd..f73f7746 100644 --- a/Pico/cd/Memory.s +++ b/Pico/cd/Memory.s @@ -381,7 +381,7 @@ PicoWriteS68k32: @ u32 a, u32 d add r2, r2, #0x110000 add r2, r2, #0x002200 .if \is_read - ldrb r0, [r2, #0x18] + ldrb r0, [r2, #0x18] @ Pico_mcd->m.bcram_reg .else strb r1, [r2, #0x18] .endif diff --git a/Pico/cd/Pico.c b/Pico/cd/Pico.c index 6db7e6ae..a97e325d 100644 --- a/Pico/cd/Pico.c +++ b/Pico/cd/Pico.c @@ -99,7 +99,7 @@ static __inline void SekRunM68k(int cyc) SekCycleCnt+=m68k_execute(cyc_do); #elif defined(EMU_F68K) g_m68kcontext=&PicoCpuFM68k; - SekCycleCnt+=fm68k_emulate(cyc_do); + SekCycleCnt+=fm68k_emulate(cyc_do, 0); #endif } @@ -119,15 +119,22 @@ static __inline void SekRunS68k(int cyc) SekCycleCntS68k+=m68k_execute(cyc_do); #elif defined(EMU_F68K) g_m68kcontext=&PicoCpuFS68k; - SekCycleCntS68k+=fm68k_emulate(cyc_do); + SekCycleCntS68k+=fm68k_emulate(cyc_do, 0); #endif } #define PS_STEP_M68K ((488<<16)/20) // ~24 //#define PS_STEP_S68K 13 -#ifdef _ASM_CD_PICO_C -void SekRunPS(int cyc_m68k, int cyc_s68k); +#if defined(_ASM_CD_PICO_C) +extern void SekRunPS(int cyc_m68k, int cyc_s68k); +#elif defined(EMU_F68K) +static __inline void SekRunPS(int cyc_m68k, int cyc_s68k) +{ + SekCycleAim+=cyc_m68k; + SekCycleAimS68k+=cyc_s68k; + fm68k_emulate(0, 1); +} #else static __inline void SekRunPS(int cyc_m68k, int cyc_s68k) { @@ -152,7 +159,7 @@ static __inline void SekRunPS(int cyc_m68k, int cyc_s68k) SekCycleCnt += m68k_execute(cyc_do); #elif defined(EMU_F68K) g_m68kcontext = &PicoCpuFM68k; - SekCycleCnt += fm68k_emulate(cyc_do); + SekCycleCnt += fm68k_emulate(cyc_do, 0); #endif } if ((cyc_do = SekCycleAimS68k-SekCycleCntS68k-cycn_s68k) > 0) { @@ -165,7 +172,7 @@ static __inline void SekRunPS(int cyc_m68k, int cyc_s68k) SekCycleCntS68k += m68k_execute(cyc_do); #elif defined(EMU_F68K) g_m68kcontext = &PicoCpuFS68k; - SekCycleCntS68k += fm68k_emulate(cyc_do); + SekCycleCntS68k += fm68k_emulate(cyc_do, 0); #endif } } diff --git a/Pico/cd/buffering.c b/Pico/cd/buffering.c index 15b3a86f..82876189 100644 --- a/Pico/cd/buffering.c +++ b/Pico/cd/buffering.c @@ -3,8 +3,6 @@ #include "../PicoInt.h" -//#include - int PicoCDBuffers = 0; static unsigned char *cd_buffer = NULL; static int prev_lba = 0x80000000; @@ -27,7 +25,7 @@ void PicoCDBufferInit(void) /* try alloc'ing until we succeed */ while (PicoCDBuffers > 0) { - tmp = realloc(cd_buffer, PicoCDBuffers * 2048); + tmp = realloc(cd_buffer, PicoCDBuffers * 2048 + 304); if (tmp != NULL) break; PicoCDBuffers >>= 1; } @@ -104,11 +102,18 @@ PICO_INTERNAL void PicoCDBufferRead(void *dest, int lba) if (is_bin) { - int i; - for (i = 0; i < read_len; i++) + int i = 0; +#if REDUCE_IO_CALLS + int bufs = (read_len*2048+304) / (2048+304); + pm_read(cd_buffer, bufs*(2048+304), Pico_mcd->TOC.Tracks[0].F); + for (i = 1; i < bufs; i++) + // should really use memmove here, but my memcpy32 implementation is also suitable here + memcpy32((int *)(cd_buffer + i*2048), (int *)(cd_buffer + i*(2048+304)), 2048/4); +#endif + for (; i < read_len; i++) { - pm_read(cd_buffer + i*2048, 2048, Pico_mcd->TOC.Tracks[0].F); - pm_seek(Pico_mcd->TOC.Tracks[0].F, 304, SEEK_CUR); + pm_read(cd_buffer + i*2048, 2048 + 304, Pico_mcd->TOC.Tracks[0].F); + // pm_seek(Pico_mcd->TOC.Tracks[0].F, 304, SEEK_CUR); // seeking is slower, in PSP case even more } } else diff --git a/cpu/fame/fame.h b/cpu/fame/fame.h index f8902aa3..f2c61f71 100644 --- a/cpu/fame/fame.h +++ b/cpu/fame/fame.h @@ -134,7 +134,7 @@ extern M68K_CONTEXT *g_m68kcontext; /* General purpose functions */ void fm68k_init(void); int fm68k_reset(void); -int fm68k_emulate(int n); +int fm68k_emulate(int n, int dualcore); int fm68k_would_interrupt(void); // to be called from fm68k_emulate() unsigned fm68k_get_pc(M68K_CONTEXT *context); diff --git a/cpu/fame/famec.c b/cpu/fame/famec.c index 041413f2..6b147b28 100644 --- a/cpu/fame/famec.c +++ b/cpu/fame/famec.c @@ -20,7 +20,7 @@ #define FAMEC_CHECK_BRANCHES #define FAMEC_EXTRA_INLINE // #define FAMEC_DEBUG -#define FAMEC_NO_GOTOS +//#define FAMEC_NO_GOTOS #define FAMEC_ADR_BITS 24 // #define FAMEC_FETCHBITS 8 #define FAMEC_DATABITS 8 @@ -523,7 +523,7 @@ static u32 flag_I; static u32 initialised = 0; #ifdef PICODRIVE_HACK -extern M68K_CONTEXT PicoCpuFS68k; +extern M68K_CONTEXT PicoCpuFM68k, PicoCpuFS68k; #endif /* Custom function handler */ @@ -624,7 +624,7 @@ void fm68k_init(void) #endif if (!initialised) - fm68k_emulate(0); + fm68k_emulate(0, 0); #ifdef FAMEC_DEBUG puts("FAME initialized."); @@ -643,7 +643,7 @@ void fm68k_init(void) int fm68k_reset(void) { if (!initialised) - fm68k_emulate(0); + fm68k_emulate(0, 0); // Si la CPU esta en ejecucion, salir con M68K_RUNNING if (m68kcontext.execinfo & M68K_RUNNING) @@ -771,7 +771,7 @@ static void setup_jumptable(void); // main exec function ////////////////////// -int fm68k_emulate(s32 cycles) +int fm68k_emulate(s32 cycles, int dualcore) { #ifndef FAMEC_NO_GOTOS u32 Opcode; @@ -795,6 +795,11 @@ int fm68k_emulate(s32 cycles) #endif } +#ifdef PICODRIVE_HACK + if (dualcore) goto dualcore_mode; +famec_restart: +#endif + // won't emulate double fault // if (m68kcontext.execinfo & M68K_FAULTED) return -1; @@ -935,7 +940,60 @@ famec_End: printf("pc: 0x%08x\n",m68kcontext.pc); #endif - return cycles - m68kcontext.io_cycle_counter; +#ifdef PICODRIVE_HACK + if (!dualcore) +#endif + return cycles - m68kcontext.io_cycle_counter; + +#ifdef PICODRIVE_HACK +dualcore_mode: + + { + extern int SekCycleAim, SekCycleCnt, SekCycleAimS68k, SekCycleCntS68k; + #define PS_STEP_M68K ((488<<16)/20) // ~24 + if (dualcore == 1) + { + dualcore = (488<<16); // ~ cycn in Pico.c + // adjust for first iteration + g_m68kcontext = &PicoCpuFS68k; + cycles = m68kcontext.io_cycle_counter = 0; + } + if (g_m68kcontext == &PicoCpuFS68k) + { + SekCycleCntS68k += cycles - m68kcontext.io_cycle_counter; + // end? + dualcore -= PS_STEP_M68K; + if (dualcore < 0) return 0; + // become main 68k + g_m68kcontext = &PicoCpuFM68k; + if ((cycles = SekCycleAim-SekCycleCnt-(dualcore>>16)) > 0) + { + if ((m68kcontext.execinfo & FM68K_HALTED) && m68kcontext.interrupts[0] <= (M68K_PPL)) + SekCycleCnt += cycles; // halted + else goto famec_restart; + //else { printf("go main %i\n", cycles); goto famec_restart; } + } + cycles = m68kcontext.io_cycle_counter = 0; + } + if (g_m68kcontext == &PicoCpuFM68k) + { + int cycn_s68k = (dualcore + dualcore/2 + dualcore/8) >> 16; + SekCycleCnt += cycles - m68kcontext.io_cycle_counter; + // become sub 68k + g_m68kcontext = &PicoCpuFS68k; + if ((cycles = SekCycleAimS68k-SekCycleCntS68k-cycn_s68k) > 0) + { + if ((m68kcontext.execinfo & FM68K_HALTED) && m68kcontext.interrupts[0] <= (M68K_PPL)) + SekCycleCntS68k += cycles; // halted + else goto famec_restart; + } + cycles = m68kcontext.io_cycle_counter = 0; + } + goto dualcore_mode; + } +#endif + + #ifdef FAMEC_NO_GOTOS } diff --git a/platform/gizmondo/port_config.h b/platform/gizmondo/port_config.h index 01840326..13e46406 100644 --- a/platform/gizmondo/port_config.h +++ b/platform/gizmondo/port_config.h @@ -5,6 +5,7 @@ #define CASE_SENSITIVE_FS 0 #define DONT_OPEN_MANY_FILES 0 +#define REDUCE_IO_CALLS 0 // draw.c #define OVERRIDE_HIGHCOL 1 diff --git a/platform/gp2x/Makefile b/platform/gp2x/Makefile index 0e2ffe41..dcd45312 100644 --- a/platform/gp2x/Makefile +++ b/platform/gp2x/Makefile @@ -217,9 +217,9 @@ readme.txt: ../../tools/textfilter ../base_readme.txt # cleanup clean: tidy - @$(RM) PicoDrive.gpe + $(RM) PicoDrive.gpe tidy: - @$(RM) $(OBJS) + $(RM) $(OBJS) # @make -C ../../cpu/Cyclone/proj -f Makefile.linux clean diff --git a/platform/gp2x/port_config.h b/platform/gp2x/port_config.h index 19840c8b..5d9bf048 100644 --- a/platform/gp2x/port_config.h +++ b/platform/gp2x/port_config.h @@ -5,6 +5,7 @@ #define CASE_SENSITIVE_FS 1 // CS filesystem #define DONT_OPEN_MANY_FILES 0 +#define REDUCE_IO_CALLS 0 // draw.c #define OVERRIDE_HIGHCOL 0 diff --git a/platform/psp/emu.c b/platform/psp/emu.c index 51db24ae..b7d6baea 100644 --- a/platform/psp/emu.c +++ b/platform/psp/emu.c @@ -48,10 +48,10 @@ void emu_getMainDir(char *dst, int len) if (len > 0) *dst = 0; } -static void osd_text(int x, const char *text, int is_active) +static void osd_text(int x, const char *text, int is_active, int clear_all) { unsigned short *screen = is_active ? psp_video_get_active_fb() : psp_screen; - int len = strlen(text) * 8 / 2; + int len = clear_all ? (480 / 2) : (strlen(text) * 8 / 2); int *p, h; void *tmp; for (h = 0; h < 8; h++) { @@ -66,7 +66,7 @@ static void osd_text(int x, const char *text, int is_active) void emu_msg_cb(const char *msg) { - osd_text(4, msg, 1); + osd_text(4, msg, 1, 1); noticeMsgTime = sceKernelGetSystemTimeLow() - 2000000; /* assumption: emu_msg_cb gets called only when something slow is about to happen */ @@ -149,7 +149,7 @@ void emu_setDefaultConfig(void) currentConfig.KeyBinds[30] = 1<<1; currentConfig.KeyBinds[31] = 1<<2; currentConfig.KeyBinds[29] = 1<<3; - currentConfig.PicoCDBuffers = 0; + currentConfig.PicoCDBuffers = 64; currentConfig.scaling = 1; // bilinear filtering for psp currentConfig.scale = 1.20; // fullscreen currentConfig.hscale40 = 1.25; @@ -411,8 +411,8 @@ static void blit2(const char *fps, const char *notice, int lagging_behind) int vsync = 0, emu_opt = currentConfig.EmuOpt; if (notice || (emu_opt & 2)) { - if (notice) osd_text(4, notice, 0); - if (emu_opt & 2) osd_text(OSD_FPS_X, fps, 0); + if (notice) osd_text(4, notice, 0, 0); + if (emu_opt & 2) osd_text(OSD_FPS_X, fps, 0, 0); } dbg_text(); @@ -567,8 +567,8 @@ static void sound_prepare(void) lprintf("starting audio: %i, len: %i, stereo: %i, pal: %i, block samples: %i\n", PsndRate, PsndLen, stereo, Pico.m.pal, samples_block); - while (sceAudioOutput2GetRestSample() > 0) psp_msleep(100); - sceAudio_5C37C0AE(); + // while (sceAudioOutput2GetRestSample() > 0) psp_msleep(100); + // sceAudio_5C37C0AE(); ret = sceAudio_38553111(samples_block/2, PsndRate, 2); // seems to not need that stupid 64byte alignment if (ret < 0) { lprintf("sceAudio_38553111() failed: %i\n", ret); @@ -589,8 +589,19 @@ static void sound_prepare(void) static void sound_end(void) { + int i; + if (samples_done == 0) + { + // if no data is written between sceAudio_38553111 and sceAudio_5C37C0AE calls, + // we get a deadlock on next sceAudio_38553111 call + // so this is yet another workaround: + memset32((int *)(void *)sndBuffer, 0, samples_block*4/4); + samples_made = samples_block * 3; + sceKernelSignalSema(sound_sem, 1); + } + sceKernelDelayThread(100*1000); samples_made = samples_done = 0; - while (sceAudioOutput2GetRestSample() > 0) + for (i = 0; sceAudioOutput2GetRestSample() > 0 && i < 16; i++) psp_msleep(100); sceAudio_5C37C0AE(); } @@ -685,7 +696,7 @@ static void RunEvents(unsigned int which) if (do_it) { - osd_text(4, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME", 1); + osd_text(4, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME", 1, 0); PicoStateProgressCB = emu_msg_cb; emu_SaveLoadGame((which & 0x1000) >> 12, 0); PicoStateProgressCB = NULL; diff --git a/platform/psp/menu.c b/platform/psp/menu.c index 53d7c25c..86628ca0 100644 --- a/platform/psp/menu.c +++ b/platform/psp/menu.c @@ -917,17 +917,20 @@ static void cd_menu_loop_options(void) char *bios, *p; if (emu_findBios(4, &bios)) { // US - for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++; + for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); + if (*p == '/') p++; strncpy(bios_names.us, p, sizeof(bios_names.us)); bios_names.us[sizeof(bios_names.us)-1] = 0; } else strcpy(bios_names.us, "NOT FOUND"); if (emu_findBios(8, &bios)) { // EU - for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++; + for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); + if (*p == '/') p++; strncpy(bios_names.eu, p, sizeof(bios_names.eu)); bios_names.eu[sizeof(bios_names.eu)-1] = 0; } else strcpy(bios_names.eu, "NOT FOUND"); if (emu_findBios(1, &bios)) { // JP - for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++; + for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); + if (*p == '/') p++; strncpy(bios_names.jp, p, sizeof(bios_names.jp)); bios_names.jp[sizeof(bios_names.jp)-1] = 0; } else strcpy(bios_names.jp, "NOT FOUND"); diff --git a/platform/psp/mp3.c b/platform/psp/mp3.c index f0cfe8f9..f3abc2fa 100644 --- a/platform/psp/mp3.c +++ b/platform/psp/mp3.c @@ -104,7 +104,7 @@ static int read_next_frame(int which_buffer) } if (frame_offset) { - lprintf("unaligned, foffs=%i, offs=%i\n", mp3_src_pos - bytes_read, frame_offset); + //lprintf("unaligned, foffs=%i, offs=%i\n", mp3_src_pos - bytes_read, frame_offset); memmove(mp3_src_buffer[which_buffer], mp3_src_buffer[which_buffer] + frame_offset, frame_size); } @@ -327,7 +327,7 @@ void mp3_start_play(FILE *f, int pos) lprintf("mp3_start_play(%s) @ %i\n", fname, pos); psp_sem_lock(thread_busy_sem); - if (mp3_fname != fname) + if (mp3_fname != fname || mp3_handle < 0) { if (mp3_handle >= 0) sceIoClose(mp3_handle); mp3_handle = sceIoOpen(fname, PSP_O_RDONLY, 0777); diff --git a/platform/psp/port_config.h b/platform/psp/port_config.h index f5336330..231db72b 100644 --- a/platform/psp/port_config.h +++ b/platform/psp/port_config.h @@ -4,7 +4,8 @@ #define PORT_CONFIG_H #define CASE_SENSITIVE_FS 0 -#define DONT_OPEN_MANY_FILES 1 // work around the stupid PSP 10 open file limit +#define DONT_OPEN_MANY_FILES 1 // work around the stupid PSP ~10 open file limit +#define REDUCE_IO_CALLS 1 // another workaround // draw.c #define USE_BGR555 1