debug bgm player, sound code refactoring

git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@598 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2008-10-16 13:32:55 +00:00
parent 095a240bd9
commit 725d7f6c16
5 changed files with 79 additions and 31 deletions

View file

@ -69,7 +69,6 @@ void emu_textOut16(int x, int y, const char *text);
char *emu_makeRomId(void); char *emu_makeRomId(void);
void emu_getGameName(char *str150); void emu_getGameName(char *str150);
void emu_findKeyBindCombos(void); void emu_findKeyBindCombos(void);
void emu_forcedFrame(int opts);
void emu_changeFastForward(int set_on); void emu_changeFastForward(int set_on);
void emu_RunEventsPico(unsigned int events); void emu_RunEventsPico(unsigned int events);
void emu_DoTurbo(int *pad, int acts); void emu_DoTurbo(int *pad, int acts);
@ -77,9 +76,14 @@ void emu_packConfig(void);
void emu_unpackConfig(void); void emu_unpackConfig(void);
void emu_shutdownMCD(void); void emu_shutdownMCD(void);
/* not in common */
extern const char * const keyNames[]; extern const char * const keyNames[];
void emu_prepareDefaultConfig(void); void emu_prepareDefaultConfig(void);
void emu_platformDebugCat(char *str); void emu_platformDebugCat(char *str);
void emu_forcedFrame(int opts);
void emu_startSound(void);
void emu_endSound(void);
void emu_waitSound(void);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"

View file

@ -343,6 +343,20 @@ int me_process(menu_entry *entries, int count, menu_id id, int is_next)
void SekStepM68k(void); 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) static void draw_text_debug(const char *str, int skip, int from)
{ {
const char *p; const char *p;
@ -415,7 +429,7 @@ void debug_menu_loop(void)
} }
menu_draw_end(); 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_SOUTH) return;
if (inp & BTN_L) { mode--; if (mode < 0) mode = 3; } if (inp & BTN_L) { mode--; if (mode < 0) mode = 3; }
if (inp & BTN_R) { mode++; if (mode > 3) mode = 0; } if (inp & BTN_R) { mode++; if (mode > 3) mode = 0; }
@ -423,6 +437,10 @@ void debug_menu_loop(void)
{ {
case 0: case 0:
if (inp & BTN_EAST) SekStepM68k(); 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)) { if ((inp & (BTN_WEST|BTN_LEFT)) == (BTN_WEST|BTN_LEFT)) {
mkdir("dumps", 0777); mkdir("dumps", 0777);
PDebugDumpMem(); PDebugDumpMem();

View file

@ -665,6 +665,46 @@ static void updateSound(int len)
gp2x_sound_write(PsndOut, len<<1); 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) static void SkipFrame(int do_audio)
{ {
@ -776,8 +816,7 @@ static void tga_dump(void)
void emu_Loop(void) void emu_Loop(void)
{ {
static int gp2x_old_clock = 200; static int gp2x_old_clock = 200, EmuOpt_old = 0;
static int PsndRate_old = 0, PicoOpt_old = 0, EmuOpt_old = 0, pal_old = 0;
char fpsbuff[24]; // fps count c string char fpsbuff[24]; // fps count c string
struct timeval tval; // timing struct timeval tval; // timing
int pframes_done, pframes_shown, pthissec; // "period" frames, used for sync int pframes_done, pframes_shown, pthissec; // "period" frames, used for sync
@ -821,29 +860,7 @@ void emu_Loop(void)
target_frametime = 1000000/target_fps; target_frametime = 1000000/target_fps;
reset_timing = 1; reset_timing = 1;
// prepare sound stuff emu_startSound();
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;
}
// prepare CD buffer // prepare CD buffer
if (PicoAHW & PAHW_MCD) PicoCDBufferInit(); if (PicoAHW & PAHW_MCD) PicoCDBufferInit();

View file

@ -24,6 +24,7 @@ void gp2x_pd_clone_buffer2(void);
void gp2x_start_sound(int rate, int bits, int stereo); void gp2x_start_sound(int rate, int bits, int stereo);
void gp2x_sound_write(void *buff, int len); void gp2x_sound_write(void *buff, int len);
void gp2x_sound_volume(int l, int r); void gp2x_sound_volume(int l, int r);
void gp2x_sound_sync(void);
/* input */ /* input */
unsigned long gp2x_joystick_read(int allow_usb_joy); unsigned long gp2x_joystick_read(int allow_usb_joy);

View file

@ -609,7 +609,7 @@ static void sound_init(void)
lprintf("sceKernelCreateThread failed: %i\n", thid); 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; static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;
int ret, stereo; int ret, stereo;
@ -648,7 +648,7 @@ static void sound_prepare(void)
} }
} }
static void sound_end(void) void emu_endSound(void)
{ {
int i; int i;
if (samples_done == 0) if (samples_done == 0)
@ -667,6 +667,14 @@ static void sound_end(void)
sceAudio_5C37C0AE(); 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) static void sound_deinit(void)
{ {
sound_thread_exit = 1; sound_thread_exit = 1;
@ -944,7 +952,7 @@ void emu_Loop(void)
PsndOut = NULL; PsndOut = NULL;
if (currentConfig.EmuOpt & 4) if (currentConfig.EmuOpt & 4)
{ {
sound_prepare(); emu_startSound();
} }
sceDisplayWaitVblankStart(); sceDisplayWaitVblankStart();
@ -1090,8 +1098,8 @@ void emu_Loop(void)
if (PicoAHW & PAHW_MCD) PicoCDBufferFree(); if (PicoAHW & PAHW_MCD) PicoCDBufferFree();
if (PsndOut != NULL) { if (PsndOut != NULL) {
emu_endSound();
PsndOut = NULL; PsndOut = NULL;
sound_end();
} }
// save SRAM // save SRAM