From: notaz Date: Thu, 16 Oct 2008 13:32:55 +0000 (+0000) Subject: debug bgm player, sound code refactoring X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=725d7f6c16b396ad3c7f98175cc20289c5241f3a;p=libpicofe.git debug bgm player, sound code refactoring git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@598 be3aeb3a-fb24-0410-a615-afba39da0efa --- diff --git a/common/emu.h b/common/emu.h index 555df3a..e05f365 100644 --- a/common/emu.h +++ b/common/emu.h @@ -69,7 +69,6 @@ void emu_textOut16(int x, int y, const char *text); char *emu_makeRomId(void); void emu_getGameName(char *str150); void emu_findKeyBindCombos(void); -void emu_forcedFrame(int opts); void emu_changeFastForward(int set_on); void emu_RunEventsPico(unsigned int events); void emu_DoTurbo(int *pad, int acts); @@ -77,9 +76,14 @@ void emu_packConfig(void); void emu_unpackConfig(void); void emu_shutdownMCD(void); +/* not in common */ extern const char * const keyNames[]; void emu_prepareDefaultConfig(void); void emu_platformDebugCat(char *str); +void emu_forcedFrame(int opts); +void emu_startSound(void); +void emu_endSound(void); +void emu_waitSound(void); #ifdef __cplusplus } // extern "C" diff --git a/common/menu.c b/common/menu.c index 1becb83..241af9f 100644 --- a/common/menu.c +++ b/common/menu.c @@ -343,6 +343,20 @@ int me_process(menu_entry *entries, int count, menu_id id, int is_next) void SekStepM68k(void); +static void mplayer_loop(void) +{ + emu_startSound(); + + while (1) + { + PDebugZ80Frame(); + if (read_buttons_async(BTN_NORTH)) break; + emu_waitSound(); + } + + emu_endSound(); +} + static void draw_text_debug(const char *str, int skip, int from) { const char *p; @@ -415,7 +429,7 @@ void debug_menu_loop(void) } menu_draw_end(); - inp = read_buttons(BTN_EAST|BTN_SOUTH|BTN_WEST|BTN_L|BTN_R|BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT); + inp = read_buttons(BTN_EAST|BTN_SOUTH|BTN_WEST|BTN_NORTH|BTN_L|BTN_R|BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT); if (inp & BTN_SOUTH) return; if (inp & BTN_L) { mode--; if (mode < 0) mode = 3; } if (inp & BTN_R) { mode++; if (mode > 3) mode = 0; } @@ -423,6 +437,10 @@ void debug_menu_loop(void) { case 0: if (inp & BTN_EAST) SekStepM68k(); + if (inp & BTN_NORTH) { + while (inp & BTN_NORTH) inp = read_buttons_async(BTN_NORTH); + mplayer_loop(); + } if ((inp & (BTN_WEST|BTN_LEFT)) == (BTN_WEST|BTN_LEFT)) { mkdir("dumps", 0777); PDebugDumpMem(); diff --git a/gp2x/emu.c b/gp2x/emu.c index 77bd83e..8e726e3 100644 --- a/gp2x/emu.c +++ b/gp2x/emu.c @@ -665,6 +665,46 @@ static void updateSound(int len) gp2x_sound_write(PsndOut, len<<1); } +void emu_startSound(void) +{ + static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0; + int target_fps = Pico.m.pal ? 50 : 60; + + PsndOut = NULL; + + // prepare sound stuff + if (currentConfig.EmuOpt & 4) + { + int snd_excess_add; + if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old || + ((PicoOpt&0x200) && crashed_940)) { + PsndRerate(Pico.m.frame_count ? 1 : 0); + } + snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps; + printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n", + PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal); + gp2x_start_sound(PsndRate, 16, (PicoOpt&8)>>3); + gp2x_sound_volume(currentConfig.volume, currentConfig.volume); + PicoWriteSound = updateSound; + update_volume(0, 0); + memset(sndBuffer, 0, sizeof(sndBuffer)); + PsndOut = sndBuffer; + PsndRate_old = PsndRate; + PicoOpt_old = PicoOpt; + pal_old = Pico.m.pal; + } +} + +void emu_endSound(void) +{ +} + +/* wait until we can write more sound */ +void emu_waitSound(void) +{ + // don't need to do anything, writes will block by themselves +} + static void SkipFrame(int do_audio) { @@ -776,8 +816,7 @@ static void tga_dump(void) void emu_Loop(void) { - static int gp2x_old_clock = 200; - static int PsndRate_old = 0, PicoOpt_old = 0, EmuOpt_old = 0, pal_old = 0; + static int gp2x_old_clock = 200, EmuOpt_old = 0; char fpsbuff[24]; // fps count c string struct timeval tval; // timing int pframes_done, pframes_shown, pthissec; // "period" frames, used for sync @@ -821,29 +860,7 @@ void emu_Loop(void) target_frametime = 1000000/target_fps; reset_timing = 1; - // prepare sound stuff - if (currentConfig.EmuOpt & 4) - { - int snd_excess_add; - if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old || - ((PicoOpt&0x200) && crashed_940)) { - PsndRerate(Pico.m.frame_count ? 1 : 0); - } - snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps; - printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n", - PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal); - gp2x_start_sound(PsndRate, 16, (PicoOpt&8)>>3); - gp2x_sound_volume(currentConfig.volume, currentConfig.volume); - PicoWriteSound = updateSound; - update_volume(0, 0); - memset(sndBuffer, 0, sizeof(sndBuffer)); - PsndOut = sndBuffer; - PsndRate_old = PsndRate; - PicoOpt_old = PicoOpt; - pal_old = Pico.m.pal; - } else { - PsndOut = NULL; - } + emu_startSound(); // prepare CD buffer if (PicoAHW & PAHW_MCD) PicoCDBufferInit(); diff --git a/gp2x/gp2x.h b/gp2x/gp2x.h index f9aa851..3d0db13 100644 --- a/gp2x/gp2x.h +++ b/gp2x/gp2x.h @@ -24,6 +24,7 @@ void gp2x_pd_clone_buffer2(void); void gp2x_start_sound(int rate, int bits, int stereo); void gp2x_sound_write(void *buff, int len); void gp2x_sound_volume(int l, int r); +void gp2x_sound_sync(void); /* input */ unsigned long gp2x_joystick_read(int allow_usb_joy); diff --git a/psp/emu.c b/psp/emu.c index 91bd563..015c320 100644 --- a/psp/emu.c +++ b/psp/emu.c @@ -609,7 +609,7 @@ static void sound_init(void) lprintf("sceKernelCreateThread failed: %i\n", thid); } -static void sound_prepare(void) +void emu_startSound(void) { static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0; int ret, stereo; @@ -648,7 +648,7 @@ static void sound_prepare(void) } } -static void sound_end(void) +void emu_endSound(void) { int i; if (samples_done == 0) @@ -667,6 +667,14 @@ static void sound_end(void) sceAudio_5C37C0AE(); } +/* wait until we can write more sound */ +void emu_waitSound(void) +{ + // TODO: test this + while (!sound_thread_exit && samples_made - samples_done > samples_block * 4) + psp_msleep(10); +} + static void sound_deinit(void) { sound_thread_exit = 1; @@ -944,7 +952,7 @@ void emu_Loop(void) PsndOut = NULL; if (currentConfig.EmuOpt & 4) { - sound_prepare(); + emu_startSound(); } sceDisplayWaitVblankStart(); @@ -1090,8 +1098,8 @@ void emu_Loop(void) if (PicoAHW & PAHW_MCD) PicoCDBufferFree(); if (PsndOut != NULL) { + emu_endSound(); PsndOut = NULL; - sound_end(); } // save SRAM