Skip to content

Commit

Permalink
minor psp fixes
Browse files Browse the repository at this point in the history
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@297 be3aeb3a-fb24-0410-a615-afba39da0efa
  • Loading branch information
notaz committed Nov 17, 2007
1 parent 81fda4e commit 110df09
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 46 deletions.
2 changes: 1 addition & 1 deletion cpu/fame/famec.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define FAMEC_ROLL_INLINE
//#define FAMEC_EMULATE_TRACE
//#define FAMEC_CHECK_BRANCHES
#define FAMEC_EXTRA_INLINE
//#define FAMEC_EXTRA_INLINE
// #define FAMEC_DEBUG
//#define FAMEC_NO_GOTOS
#define FAMEC_ADR_BITS 24
Expand Down
2 changes: 1 addition & 1 deletion platform/base_readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ Problems / limitations
Credits
-------

This emulator uses code from these people/projects:
This emulator is made of the code from following people/projects:

notaz
GP2X, UIQ, PSP, Gizmondo ports, CPU core hacks,
Expand Down
9 changes: 2 additions & 7 deletions platform/common/lprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
#include <stdio.h>
#define lprintf printf
#elif defined(PSP)
#ifdef LPRINTF_STDIO
#include <stdio.h>
#define lprintf printf
#else
extern void lprintf_f(const char *fmt, ...);
#define lprintf lprintf_f
#endif
extern void lprintf_f(const char *fmt, ...);
#define lprintf lprintf_f
#else
#include "giz.h"
#endif
Expand Down
10 changes: 7 additions & 3 deletions platform/psp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ PSPSDK = $(shell psp-config --pspsdk-path)
amalgamate = 0


CFLAGS += -I../.. -I. -DNO_SYNC -DLPRINTF_STDIO
CFLAGS += -I../.. -I. -DNO_SYNC
CFLAGS += -Wall -Winline -G0
CFLAGS += -DLPRINTF_STDIO
#CFLAGS += -DLPRINTF_STDIO
#CFLAGS += -fprofile-generate
#CFLAGS += -fprofile-use
#CFLAGS += -pg
Expand Down Expand Up @@ -83,6 +83,7 @@ EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = PicoDrive
PSP_EBOOT_ICON = data/icon.png
#PSP_EBOOT_PIC1 = .png
BUILD_PRX = 1

CUSTOM_CLEAN = myclean

Expand Down Expand Up @@ -131,8 +132,11 @@ data/bg40.o: data/bg40.bin
bin2o -i $< $@ bgdatac40

#
ifndef UPDIR
UPDIR = /media/disk/PSP/GAME/PicoDrive/
endif
up: EBOOT.PBP
@cp -v $^ /media/disk/PSP/GAME/PicoDrive/
@cp -v $^ $(UPDIR)


# cleanup
Expand Down
24 changes: 18 additions & 6 deletions platform/psp/emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ static int sound_thread(SceSize args, void *argp)
{
if (samples_made - samples_done < samples_block) {
// wait for data (use at least 2 blocks)
lprintf("sthr: wait... (%i)\n", samples_made - samples_done);
//lprintf("sthr: wait... (%i)\n", samples_made - samples_done);
while (samples_made - samples_done <= samples_block*2 && !sound_thread_exit)
ret = sceKernelWaitSema(sound_sem, 1, 0);
if (ret < 0) lprintf("sthr: sceKernelWaitSema: %i\n", ret);
Expand All @@ -523,8 +523,9 @@ static int sound_thread(SceSize args, void *argp)
snd_playptr += samples_block;
if (snd_playptr >= sndBuffer_endptr)
snd_playptr = sndBuffer;
if (ret)
lprintf("sthr: outf: %i; pos %i/%i\n", ret, samples_done, samples_made);
// 1.5 kernel returns 0, newer ones return # of samples queued
if (ret < 0)
lprintf("sthr: sceAudio_E0727056: %08x; pos %i/%i\n", ret, samples_done, samples_made);

// shouln't happen, but just in case
if (samples_made - samples_done >= samples_block*3) {
Expand All @@ -543,6 +544,7 @@ static int sound_thread(SceSize args, void *argp)
static void sound_init(void)
{
SceUID thid;
int ret;

sound_sem = sceKernelCreateSema("sndsem", 0, 0, 1, NULL);
if (sound_sem < 0) lprintf("sceKernelCreateSema() failed: %i\n", sound_sem);
Expand All @@ -553,7 +555,8 @@ static void sound_init(void)
thid = sceKernelCreateThread("sndthread", sound_thread, 0x12, 0x10000, 0, NULL);
if (thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
ret = sceKernelStartThread(thid, 0, 0);
if (ret < 0) lprintf("sound_init: sceKernelStartThread returned %08x\n", ret);
}
else
lprintf("sceKernelCreateThread failed: %i\n", thid);
Expand Down Expand Up @@ -865,6 +868,7 @@ static void simpleWait(unsigned int until)

void emu_Loop(void)
{
static int mp3_init_done = 0;
char fpsbuff[24]; // fps count c string
unsigned int tval, tval_prev = 0, tval_thissec = 0; // timing
int frames_done = 0, frames_shown = 0, oldmodes = 0;
Expand Down Expand Up @@ -894,8 +898,16 @@ void emu_Loop(void)
target_frametime = Pico.m.pal ? (1000000<<8)/50 : (1000000<<8)/60+1;
reset_timing = 1;

// prepare CD buffer
if (PicoMCD & 1) PicoCDBufferInit();
if (PicoMCD & 1) {
// prepare CD buffer
PicoCDBufferInit();
// mp3...
if (!mp3_init_done) {
i = mp3_init();
mp3_init_done = 1;
if (i) { engineState = PGS_Menu; return; }
}
}

// prepare sound stuff
PsndOut = NULL;
Expand Down
41 changes: 36 additions & 5 deletions platform/psp/main.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <string.h>
#include "psp.h"
#include "emu.h"
#include "menu.h"
Expand All @@ -7,17 +8,34 @@
#include "../common/lprintf.h"
#include "version.h"

int main()
#define GPROF 0
#define GCOV 0

#if GPROF
#include <pspprof.h>
#endif

#if GCOV
#include <stdio.h>
#include <stdlib.h>

void dummy(void)
{
int mp3_ret;
engineState = atoi(romFileName);
setbuf(NULL, NULL);
getenv(NULL);
}
#endif

int main()
{
lprintf("\nPicoDrive v" VERSION " " __DATE__ " " __TIME__ "\n");
psp_init();

emu_ReadConfig(0, 0);
emu_Init();
menu_init();
mp3_ret = mp3_init();
// moved to emu_Loop(), after CPU clock change..
//mp3_init();

engineState = PGS_Menu;

Expand All @@ -26,7 +44,12 @@ int main()
switch (engineState)
{
case PGS_Menu:
#if !GPROF
menu_loop();
#else
strcpy(romFileName, currentConfig.lastRomFile);
engineState = PGS_ReloadRom;
#endif
break;

case PGS_ReloadRom:
Expand All @@ -45,6 +68,9 @@ int main()

case PGS_Running:
emu_Loop();
#if GPROF
goto endloop;
#endif
break;

case PGS_Quit:
Expand All @@ -58,9 +84,14 @@ int main()

endloop:

if (mp3_ret == 0) mp3_deinit();
mp3_deinit();
emu_Deinit();
#if GPROF
gprof_cleanup();
#endif
#if !GCOV
psp_finish();
#endif

return 0;
}
Expand Down
5 changes: 3 additions & 2 deletions platform/psp/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ static void cd_menu_loop_options(void)
for (;;)
{
draw_cd_menu_options(menu_sel, &bios_names);
inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_X|BTN_CIRCLE, 0);
inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_X|BTN_CIRCLE|BTN_START, 0);
if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);
Expand All @@ -958,11 +958,12 @@ static void cd_menu_loop_options(void)
}
}
}
if (inp & BTN_CIRCLE) { // toggleable options
if (inp & BTN_CIRCLE) // toggleable options
if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, 1) &&
selected_id == MA_CDOPT_DONE) {
return;
}
if (inp & BTN_START) {
switch (selected_id) { // BIOS testers
case MA_CDOPT_TESTBIOS_USA:
if (emu_findBios(4, &bios)) { // test US
Expand Down
30 changes: 23 additions & 7 deletions platform/psp/mp3.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

int mp3_last_error = 0;

static int initialized = 0;
static SceUID thread_job_sem = -1;
static SceUID thread_busy_sem = -1;
static int thread_exit = 0;
Expand Down Expand Up @@ -96,9 +97,14 @@ static int read_next_frame(int which_buffer)
continue; // bad frame
}

if (bytes_read - frame_offset < frame_size) {
if (bytes_read - frame_offset < frame_size)
{
lprintf("unfit, foffs=%i\n", mp3_src_pos - bytes_read);
mp3_src_pos -= bytes_read - frame_offset;
if (mp3_src_size - mp3_src_pos < frame_size) {
mp3_src_pos = mp3_src_size;
return 0; // EOF
}
sceIoLseek32(mp3_handle, mp3_src_pos, PSP_SEEK_SET);
continue; // didn't fit, re-read..
}
Expand Down Expand Up @@ -195,6 +201,7 @@ int mp3_init(void)
}

mp3_last_error = 0;
initialized = 1;
return 0;

fail3:
Expand All @@ -207,12 +214,15 @@ int mp3_init(void)
sceAudiocodecReleaseEDRAM(mp3_codec_struct);
fail:
mp3_last_error = ret;
initialized = 0;
return 1;
}

void mp3_deinit(void)
{
lprintf("deinit\n");
lprintf("mp3_deinit, initialized=%i\n", initialized);

if (!initialized) return;
thread_exit = 1;
psp_sem_lock(thread_busy_sem);
psp_sem_unlock(thread_busy_sem);
Expand All @@ -229,6 +239,7 @@ void mp3_deinit(void)
sceKernelDeleteSema(thread_job_sem);
thread_job_sem = -1;
sceAudiocodecReleaseEDRAM(mp3_codec_struct);
initialized = 0;
}

// may overflow stack?
Expand Down Expand Up @@ -269,14 +280,16 @@ static int decode_thread(SceSize args, void *argp)
}


// might be called before initialization
int mp3_get_bitrate(FILE *f, int size)
{
int ret, retval = -1, sample_rate, bitrate;
// filenames are stored instead handles in PSP, due to stupid max open file limit
char *fname = (char *)f;

/* make sure thread is not busy.. */
psp_sem_lock(thread_busy_sem);
if (thread_busy_sem >= 0)
psp_sem_lock(thread_busy_sem);

if (mp3_handle >= 0) sceIoClose(mp3_handle);
mp3_handle = sceIoOpen(fname, PSP_O_RDONLY, 0777);
Expand All @@ -288,19 +301,19 @@ int mp3_get_bitrate(FILE *f, int size)
mp3_src_pos = 0;
ret = read_next_frame(0);
if (ret <= 0) {
lprintf("read_next_frame() failed\n");
lprintf("read_next_frame() failed (%s)\n", fname);
goto end;
}
sample_rate = (mp3_src_buffer[0][2] & 0x0c) >> 2;
bitrate = mp3_src_buffer[0][2] >> 4;

if (sample_rate != 0) {
lprintf("unsupported samplerate\n");
lprintf("unsupported samplerate (%s)\n", fname);
goto end; // only 44kHz supported..
}
bitrate = bitrates[bitrate];
if (bitrate == 0) {
lprintf("unsupported bitrate\n");
lprintf("unsupported bitrate (%s)\n", fname);
goto end;
}

Expand All @@ -310,7 +323,8 @@ int mp3_get_bitrate(FILE *f, int size)
if (mp3_handle >= 0) sceIoClose(mp3_handle);
mp3_handle = -1;
mp3_fname = NULL;
psp_sem_unlock(thread_busy_sem);
if (thread_busy_sem >= 0)
psp_sem_unlock(thread_busy_sem);
if (retval < 0) mp3_last_error = -1; // remember we had a problem..
return retval;
}
Expand All @@ -322,6 +336,8 @@ void mp3_start_play(FILE *f, int pos)
{
char *fname = (char *)f;

if (!initialized) return;

lprintf("mp3_start_play(%s) @ %i\n", fname, pos);
psp_sem_lock(thread_busy_sem);

Expand Down
Loading

0 comments on commit 110df09

Please sign in to comment.