From 2b02d6e533b114456785f39a356476eb97306fcf Mon Sep 17 00:00:00 2001 From: notaz Date: Fri, 18 Jul 2008 13:04:38 +0000 Subject: [PATCH] uncommited code for 151 release (PSP suspend, file browser, etc) git-svn-id: file:///home/notaz/opt/svn/PicoDrive@554 be3aeb3a-fb24-0410-a615-afba39da0efa --- Pico/Pico.c | 2 +- platform/common/menu.c | 3 ++- platform/gp2x/gp2x.c | 4 +-- platform/psp/emu.c | 25 +++++++++++++++--- platform/psp/emu.h | 4 +-- platform/psp/main.c | 14 ++++++++--- platform/psp/menu.c | 57 +++++++++++++++++++++--------------------- platform/psp/mp3.c | 3 +++ platform/psp/psp.c | 25 +++++++----------- 9 files changed, 79 insertions(+), 58 deletions(-) diff --git a/Pico/Pico.c b/Pico/Pico.c index b5e4e28..6bf28b6 100644 --- a/Pico/Pico.c +++ b/Pico/Pico.c @@ -15,7 +15,7 @@ struct Pico Pico; int PicoOpt = 0; int PicoSkipFrame = 0; // skip rendering frame? int emustatus = 0; // rapid_ym2612, multi_ym_updates -int PicoPad[2]; // Joypads, format is SACB RLDU +int PicoPad[2]; // Joypads, format is MXYZ SACB RLDU int PicoPadInt[2]; // internal copy int PicoAHW = 0; // active addon hardware: scd_active, 32x_active, svp_active, pico_active int PicoRegionOverride = 0; // override the region detection 0: Auto, 1: Japan NTSC, 2: Japan PAL, 4: US, 8: Europe diff --git a/platform/common/menu.c b/platform/common/menu.c index 7a97fc3..00afc34 100644 --- a/platform/common/menu.c +++ b/platform/common/menu.c @@ -421,7 +421,8 @@ void debug_menu_loop(void) case 2: clear_screen(); emu_forcedFrame(0); darken_screen(); - PDebugShowSpriteStats(SCREEN_BUFFER, SCREEN_WIDTH); break; + PDebugShowSpriteStats((unsigned short *)SCREEN_BUFFER + (SCREEN_HEIGHT/2 - 240/2)*SCREEN_WIDTH + + SCREEN_WIDTH/2 - 320/2, SCREEN_WIDTH); break; case 3: clear_screen(); PDebugShowPalette(SCREEN_BUFFER, SCREEN_WIDTH); PDebugShowSprite((unsigned short *)SCREEN_BUFFER + SCREEN_WIDTH*120+SCREEN_WIDTH/2+16, diff --git a/platform/gp2x/gp2x.c b/platform/gp2x/gp2x.c index 80b0486..56fbf5c 100644 --- a/platform/gp2x/gp2x.c +++ b/platform/gp2x/gp2x.c @@ -237,12 +237,12 @@ int gp2x_touchpad_read(int *x, int *y) if (touchdev < 0) return -1; retval = read(touchdev, &event, sizeof(event)); - if (retval < 0) { + if (retval <= 0) { printf("touch read failed %i %i\n", retval, errno); return -1; } // this is to ignore the messed-up 4.1.x driver - if (retval == 0) zero_seen = 1; + if (event.pressure == 0) zero_seen = 1; if (x) *x = (event.x * touchcal[0] + touchcal[2]) >> 16; if (y) *y = (event.y * touchcal[4] + touchcal[5]) >> 16; diff --git a/platform/psp/emu.c b/platform/psp/emu.c index d6bc20c..11b5e3f 100644 --- a/platform/psp/emu.c +++ b/platform/psp/emu.c @@ -22,6 +22,7 @@ #include "../common/config.h" #include "../common/lprintf.h" #include "../../Pico/PicoInt.h" +#include "../../Pico/cd/cue.h" #define OSD_FPS_X 432 @@ -34,7 +35,7 @@ int sceAudioOutput2GetRestSample(); char romFileName[PATH_MAX]; unsigned char *PicoDraw2FB = (unsigned char *)VRAM_CACHED_STUFF + 8; // +8 to be able to skip border with 1 quadword.. -int engineState = PGS_Menu; +int engineState = PGS_Menu, engineStateSuspend; static unsigned int noticeMsgTime = 0; int reset_timing = 0; // do we need this? @@ -1118,15 +1119,31 @@ void emu_HandleResume(void) { if (!(PicoAHW & PAHW_MCD)) return; - // reopen files.. + // reopen first CD track if (Pico_mcd->TOC.Tracks[0].F != NULL) { - lprintf("emu_HandleResume: reopen %s\n", romFileName); + char *fname = romFileName; + int len = strlen(romFileName); + cue_data_t *cue_data = NULL; + + if (len > 4 && strcasecmp(fname + len - 4, ".cue") == 0) + { + cue_data = cue_parse(romFileName); + if (cue_data != NULL) + fname = cue_data->tracks[1].fname; + } + + lprintf("emu_HandleResume: reopen %s\n", fname); pm_close(Pico_mcd->TOC.Tracks[0].F); - Pico_mcd->TOC.Tracks[0].F = pm_open(romFileName); + Pico_mcd->TOC.Tracks[0].F = pm_open(fname); lprintf("reopen %s\n", Pico_mcd->TOC.Tracks[0].F != NULL ? "ok" : "failed"); + + if (cue_data != NULL) cue_destroy(cue_data); } mp3_reopen_file(); + + if (!(Pico_mcd->s68k_regs[0x36] & 1) && (Pico_mcd->scd.Status_CDC & 1)) + cdda_start_play(); } diff --git a/platform/psp/emu.h b/platform/psp/emu.h index 1ef9450..c27c566 100644 --- a/platform/psp/emu.h +++ b/platform/psp/emu.h @@ -15,11 +15,11 @@ enum TPicoGameState { PGS_Menu, PGS_RestartRun, PGS_Suspending, - PGS_SuspendAck, + PGS_SuspendWake, }; extern char romFileName[]; -extern int engineState; +extern int engineState, engineStateSuspend; void emu_Init(void); diff --git a/platform/psp/main.c b/platform/psp/main.c index d970f8a..a2e99aa 100644 --- a/platform/psp/main.c +++ b/platform/psp/main.c @@ -69,11 +69,15 @@ int pico_main(void) break; case PGS_Suspending: - while (engineState == PGS_Suspending || engineState == PGS_SuspendAck) { - if (engineState == PGS_Suspending) - engineState = PGS_SuspendAck; + while (engineState == PGS_Suspending) psp_wait_suspend(); - } + break; + + case PGS_SuspendWake: + psp_unhandled_suspend = 0; + psp_resume_suspend(); + emu_HandleResume(); + engineState = engineStateSuspend; break; case PGS_RestartRun: @@ -81,8 +85,10 @@ int pico_main(void) case PGS_Running: if (psp_unhandled_suspend) { + psp_unhandled_suspend = 0; psp_resume_suspend(); emu_HandleResume(); + break; } emu_Loop(); #ifdef GPROF diff --git a/platform/psp/menu.c b/platform/psp/menu.c index 20c3460..5768a9c 100644 --- a/platform/psp/menu.c +++ b/platform/psp/menu.c @@ -174,13 +174,9 @@ void menu_romload_end(void) // -------------- ROM selector -------------- -// SceIoDirent -#define DT_DIR FIO_SO_IFDIR -#define DT_REG FIO_SO_IFREG - struct my_dirent { - unsigned char d_type; + unsigned int d_type; char d_name[255]; }; @@ -221,7 +217,7 @@ static void draw_dirlist(char *curdir, struct my_dirent **namelist, int n, int s pos = start + i; if (pos < 0) continue; if (pos > 26) break; - if (namelist[i+1]->d_type & DT_DIR) { + if (namelist[i+1]->d_type & FIO_S_IFDIR) { smalltext_out16_lim(14, pos*10, "/", 0xd7ff, 1); smalltext_out16_lim(14+6, pos*10, namelist[i+1]->d_name, 0xd7ff, 80-3); } else { @@ -236,9 +232,10 @@ static void draw_dirlist(char *curdir, struct my_dirent **namelist, int n, int s static int scandir_cmp(const void *p1, const void *p2) { struct my_dirent **d1 = (struct my_dirent **)p1, **d2 = (struct my_dirent **)p2; - if ((*d1)->d_type == (*d2)->d_type) return strcasecmp((*d1)->d_name, (*d2)->d_name); - if ((*d1)->d_type & DT_DIR) return -1; // put before - if ((*d2)->d_type & DT_DIR) return 1; + if ((*d1)->d_type & (*d2)->d_type & FIO_S_IFDIR) + return strcasecmp((*d1)->d_name, (*d2)->d_name); + if ((*d1)->d_type & FIO_S_IFDIR) return -1; // put before + if ((*d2)->d_type & FIO_S_IFDIR) return 1; return strcasecmp((*d1)->d_name, (*d2)->d_name); } @@ -297,7 +294,7 @@ static int my_scandir(const char *dir, struct my_dirent ***namelist_out, { ent = malloc(sizeof(*ent)); if (ent == NULL) { lprintf("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; } - ent->d_type = sce_ent.d_stat.st_attr; + ent->d_type = sce_ent.d_stat.st_mode; strncpy(ent->d_name, sce_ent.d_name, sizeof(ent->d_name)); ent->d_name[sizeof(ent->d_name)-1] = 0; if (filter == NULL || filter(ent)) @@ -350,7 +347,8 @@ static char *romsel_loop(char *curr_path) // is this a dir or a full path? memset(&cpstat, 0, sizeof(cpstat)); iret = sceIoGetstat(curr_path, &cpstat); - if (iret >= 0 && (cpstat.st_attr & FIO_SO_IFREG)) { // file + if (iret >= 0 && (cpstat.st_mode & FIO_S_IFDIR)); // dir + else if (iret >= 0 && (cpstat.st_mode & FIO_S_IFREG)) { // file char *p; for (p = curr_path + strlen(curr_path) - 1; p > curr_path && *p != '/'; p--); if (p > curr_path) { @@ -359,7 +357,6 @@ static char *romsel_loop(char *curr_path) } else strcpy(curr_path, "ms0:/"); } - else if (iret >= 0 && (cpstat.st_attr & FIO_SO_IFDIR)); // dir else strcpy(curr_path, "ms0:/"); // something else n = my_scandir(curr_path, &namelist, scandir_filter, scandir_cmp); @@ -394,14 +391,10 @@ static char *romsel_loop(char *curr_path) if(inp & BTN_L) { sel-=24; if (sel < 0) sel = 0; } if(inp & BTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; } if(inp & BTN_R) { sel+=24; if (sel > n-2) sel = n-2; } - if(inp & BTN_CIRCLE) { // enter dir/select - if (namelist[sel+1]->d_type & DT_REG) { - strcpy(romFileName, curr_path); - strcat(romFileName, "/"); - strcat(romFileName, namelist[sel+1]->d_name); - ret = romFileName; - break; - } else if (namelist[sel+1]->d_type & DT_DIR) { + if(inp & BTN_CIRCLE) // enter dir/select + { + if (namelist[sel+1]->d_type & FIO_S_IFDIR) + { int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2; char *p, *newdir = malloc(newlen); if (strcmp(namelist[sel+1]->d_name, "..") == 0) { @@ -422,6 +415,14 @@ static char *romsel_loop(char *curr_path) free(newdir); break; } + else if (namelist[sel+1]->d_type & FIO_S_IFREG) + { + strcpy(romFileName, curr_path); + strcat(romFileName, "/"); + strcat(romFileName, namelist[sel+1]->d_name); + ret = romFileName; + break; + } } if(inp & BTN_X) break; // cancel } @@ -692,14 +693,14 @@ static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_ text_out16(x, y, "Done"); if (sel < opt_cnt) { - text_out16(80+30, 225, "Press a button to bind/unbind"); - text_out16(80+30, 235, "Use SELECT to clear"); - text_out16(80+30, 245, "To bind UP/DOWN, hold SELECT"); - text_out16(80+30, 255, "Select \"Done\" to exit"); + text_out16(80+30, 220, "Press a button to bind/unbind"); + text_out16(80+30, 230, "Use SELECT to clear"); + text_out16(80+30, 240, "To bind UP/DOWN, hold SELECT"); + text_out16(80+30, 250, "Select \"Done\" to exit"); } else { - text_out16(80+30, 235, "Use Options -> Save cfg"); - text_out16(80+30, 245, "to save controls"); - text_out16(80+30, 255, "Press X or O to exit"); + text_out16(80+30, 230, "Use Options -> Save cfg"); + text_out16(80+30, 240, "to save controls"); + text_out16(80+30, 250, "Press X or O to exit"); } menu_draw_end(); } @@ -787,7 +788,7 @@ me_bind_action emuctrl_actions[] = static void kc_sel_loop(void) { - int menu_sel = 3, menu_sel_max = 3; + int menu_sel = 5, menu_sel_max = 5; unsigned long inp = 0; menu_id selected_id; diff --git a/platform/psp/mp3.c b/platform/psp/mp3.c index 43b449d..19f6ec3 100644 --- a/platform/psp/mp3.c +++ b/platform/psp/mp3.c @@ -373,6 +373,9 @@ void mp3_start_play(FILE *f, int pos) mp3_fname = fname; } + // clear decoder state + sceAudiocodecInit(mp3_codec_struct, 0x1002); + // seek.. mp3_src_pos = (int) (((float)pos / 1023.0f) * (float)mp3_src_size); sceIoLseek32(mp3_handle, mp3_src_pos, PSP_SEEK_SET); diff --git a/platform/psp/psp.c b/platform/psp/psp.c index 4046e29..1b1a1f5 100644 --- a/platform/psp/psp.c +++ b/platform/psp/psp.c @@ -26,14 +26,14 @@ extern int pico_main(void); #ifndef FW15 -PSP_MODULE_INFO("PicoDrive", 0, 1, 50); +PSP_MODULE_INFO("PicoDrive", 0, 1, 51); PSP_HEAP_SIZE_MAX(); int main() { return pico_main(); } /* just a wrapper */ #else -PSP_MODULE_INFO("PicoDrive", 0x1000, 1, 50); +PSP_MODULE_INFO("PicoDrive", 0x1000, 1, 51); PSP_MAIN_THREAD_ATTR(0); int main() @@ -58,10 +58,11 @@ int main() #endif +int psp_unhandled_suspend = 0; + unsigned int __attribute__((aligned(16))) guCmdList[GU_CMDLIST_SIZE]; void *psp_screen = VRAM_FB0; -int psp_unhandled_suspend = 0; static int current_screen = 0; /* front bufer */ @@ -79,26 +80,19 @@ static int exit_callback(int arg1, int arg2, void *common) /* Power Callback */ static int power_callback(int unknown, int pwrflags, void *common) { - static int old_state = PGS_Menu; - int i; - lprintf("power_callback: flags: 0x%08X\n", pwrflags); /* check for power switch and suspending as one is manual and the other automatic */ if (pwrflags & PSP_POWER_CB_POWER_SWITCH || pwrflags & PSP_POWER_CB_SUSPENDING || pwrflags & PSP_POWER_CB_STANDBY) { - if (engineState != PGS_Suspending && engineState != PGS_SuspendAck) { - old_state = engineState; - engineState = PGS_Suspending; - } - for (i = 0; i < 10 && engineState != PGS_SuspendAck; i++) - sceKernelDelayThread(100*1024); - + psp_unhandled_suspend = 1; + if (engineState != PGS_Suspending) + engineStateSuspend = engineState; + sceKernelDelayThread(100000); // ?? } else if (pwrflags & PSP_POWER_CB_RESUME_COMPLETE) { - engineState = old_state; - psp_unhandled_suspend = 1; + engineState = PGS_SuspendWake; } //sceDisplayWaitVblankStart(); @@ -288,7 +282,6 @@ void psp_resume_suspend(void) } if (fd >= 0) sceIoClose(fd); sceDisplayWaitVblankStart(); - psp_unhandled_suspend = 0; if (i < 30) lprintf("io resumed after %i tries\n", i); else { -- 2.39.2