minor psp fixes

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@297 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2007-11-17 17:57:58 +00:00
parent 81fda4e8d8
commit 110df09c8a
10 changed files with 153 additions and 47 deletions

View file

@ -18,7 +18,7 @@
#define FAMEC_ROLL_INLINE #define FAMEC_ROLL_INLINE
//#define FAMEC_EMULATE_TRACE //#define FAMEC_EMULATE_TRACE
//#define FAMEC_CHECK_BRANCHES //#define FAMEC_CHECK_BRANCHES
#define FAMEC_EXTRA_INLINE //#define FAMEC_EXTRA_INLINE
// #define FAMEC_DEBUG // #define FAMEC_DEBUG
//#define FAMEC_NO_GOTOS //#define FAMEC_NO_GOTOS
#define FAMEC_ADR_BITS 24 #define FAMEC_ADR_BITS 24

View file

@ -542,7 +542,7 @@ Problems / limitations
Credits Credits
------- -------
This emulator uses code from these people/projects: This emulator is made of the code from following people/projects:
notaz notaz
GP2X, UIQ, PSP, Gizmondo ports, CPU core hacks, GP2X, UIQ, PSP, Gizmondo ports, CPU core hacks,

View file

@ -2,13 +2,8 @@
#include <stdio.h> #include <stdio.h>
#define lprintf printf #define lprintf printf
#elif defined(PSP) #elif defined(PSP)
#ifdef LPRINTF_STDIO extern void lprintf_f(const char *fmt, ...);
#include <stdio.h> #define lprintf lprintf_f
#define lprintf printf
#else
extern void lprintf_f(const char *fmt, ...);
#define lprintf lprintf_f
#endif
#else #else
#include "giz.h" #include "giz.h"
#endif #endif

View file

@ -8,9 +8,9 @@ PSPSDK = $(shell psp-config --pspsdk-path)
amalgamate = 0 amalgamate = 0
CFLAGS += -I../.. -I. -DNO_SYNC -DLPRINTF_STDIO CFLAGS += -I../.. -I. -DNO_SYNC
CFLAGS += -Wall -Winline -G0 CFLAGS += -Wall -Winline -G0
CFLAGS += -DLPRINTF_STDIO #CFLAGS += -DLPRINTF_STDIO
#CFLAGS += -fprofile-generate #CFLAGS += -fprofile-generate
#CFLAGS += -fprofile-use #CFLAGS += -fprofile-use
#CFLAGS += -pg #CFLAGS += -pg
@ -83,6 +83,7 @@ EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = PicoDrive PSP_EBOOT_TITLE = PicoDrive
PSP_EBOOT_ICON = data/icon.png PSP_EBOOT_ICON = data/icon.png
#PSP_EBOOT_PIC1 = .png #PSP_EBOOT_PIC1 = .png
BUILD_PRX = 1
CUSTOM_CLEAN = myclean CUSTOM_CLEAN = myclean
@ -131,8 +132,11 @@ data/bg40.o: data/bg40.bin
bin2o -i $< $@ bgdatac40 bin2o -i $< $@ bgdatac40
# #
ifndef UPDIR
UPDIR = /media/disk/PSP/GAME/PicoDrive/
endif
up: EBOOT.PBP up: EBOOT.PBP
@cp -v $^ /media/disk/PSP/GAME/PicoDrive/ @cp -v $^ $(UPDIR)
# cleanup # cleanup

View file

@ -508,7 +508,7 @@ static int sound_thread(SceSize args, void *argp)
{ {
if (samples_made - samples_done < samples_block) { if (samples_made - samples_done < samples_block) {
// wait for data (use at least 2 blocks) // 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) while (samples_made - samples_done <= samples_block*2 && !sound_thread_exit)
ret = sceKernelWaitSema(sound_sem, 1, 0); ret = sceKernelWaitSema(sound_sem, 1, 0);
if (ret < 0) lprintf("sthr: sceKernelWaitSema: %i\n", ret); if (ret < 0) lprintf("sthr: sceKernelWaitSema: %i\n", ret);
@ -523,8 +523,9 @@ static int sound_thread(SceSize args, void *argp)
snd_playptr += samples_block; snd_playptr += samples_block;
if (snd_playptr >= sndBuffer_endptr) if (snd_playptr >= sndBuffer_endptr)
snd_playptr = sndBuffer; snd_playptr = sndBuffer;
if (ret) // 1.5 kernel returns 0, newer ones return # of samples queued
lprintf("sthr: outf: %i; pos %i/%i\n", ret, samples_done, samples_made); if (ret < 0)
lprintf("sthr: sceAudio_E0727056: %08x; pos %i/%i\n", ret, samples_done, samples_made);
// shouln't happen, but just in case // shouln't happen, but just in case
if (samples_made - samples_done >= samples_block*3) { if (samples_made - samples_done >= samples_block*3) {
@ -543,6 +544,7 @@ static int sound_thread(SceSize args, void *argp)
static void sound_init(void) static void sound_init(void)
{ {
SceUID thid; SceUID thid;
int ret;
sound_sem = sceKernelCreateSema("sndsem", 0, 0, 1, NULL); sound_sem = sceKernelCreateSema("sndsem", 0, 0, 1, NULL);
if (sound_sem < 0) lprintf("sceKernelCreateSema() failed: %i\n", sound_sem); if (sound_sem < 0) lprintf("sceKernelCreateSema() failed: %i\n", sound_sem);
@ -553,7 +555,8 @@ static void sound_init(void)
thid = sceKernelCreateThread("sndthread", sound_thread, 0x12, 0x10000, 0, NULL); thid = sceKernelCreateThread("sndthread", sound_thread, 0x12, 0x10000, 0, NULL);
if (thid >= 0) if (thid >= 0)
{ {
sceKernelStartThread(thid, 0, 0); ret = sceKernelStartThread(thid, 0, 0);
if (ret < 0) lprintf("sound_init: sceKernelStartThread returned %08x\n", ret);
} }
else else
lprintf("sceKernelCreateThread failed: %i\n", thid); lprintf("sceKernelCreateThread failed: %i\n", thid);
@ -865,6 +868,7 @@ static void simpleWait(unsigned int until)
void emu_Loop(void) void emu_Loop(void)
{ {
static int mp3_init_done = 0;
char fpsbuff[24]; // fps count c string char fpsbuff[24]; // fps count c string
unsigned int tval, tval_prev = 0, tval_thissec = 0; // timing unsigned int tval, tval_prev = 0, tval_thissec = 0; // timing
int frames_done = 0, frames_shown = 0, oldmodes = 0; int frames_done = 0, frames_shown = 0, oldmodes = 0;
@ -894,8 +898,16 @@ void emu_Loop(void)
target_frametime = Pico.m.pal ? (1000000<<8)/50 : (1000000<<8)/60+1; target_frametime = Pico.m.pal ? (1000000<<8)/50 : (1000000<<8)/60+1;
reset_timing = 1; reset_timing = 1;
// prepare CD buffer if (PicoMCD & 1) {
if (PicoMCD & 1) PicoCDBufferInit(); // 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 // prepare sound stuff
PsndOut = NULL; PsndOut = NULL;

View file

@ -1,3 +1,4 @@
#include <string.h>
#include "psp.h" #include "psp.h"
#include "emu.h" #include "emu.h"
#include "menu.h" #include "menu.h"
@ -7,17 +8,34 @@
#include "../common/lprintf.h" #include "../common/lprintf.h"
#include "version.h" #include "version.h"
#define GPROF 0
#define GCOV 0
#if GPROF
#include <pspprof.h>
#endif
#if GCOV
#include <stdio.h>
#include <stdlib.h>
void dummy(void)
{
engineState = atoi(romFileName);
setbuf(NULL, NULL);
getenv(NULL);
}
#endif
int main() int main()
{ {
int mp3_ret;
lprintf("\nPicoDrive v" VERSION " " __DATE__ " " __TIME__ "\n"); lprintf("\nPicoDrive v" VERSION " " __DATE__ " " __TIME__ "\n");
psp_init(); psp_init();
emu_ReadConfig(0, 0); emu_ReadConfig(0, 0);
emu_Init(); emu_Init();
menu_init(); menu_init();
mp3_ret = mp3_init(); // moved to emu_Loop(), after CPU clock change..
//mp3_init();
engineState = PGS_Menu; engineState = PGS_Menu;
@ -26,7 +44,12 @@ int main()
switch (engineState) switch (engineState)
{ {
case PGS_Menu: case PGS_Menu:
#if !GPROF
menu_loop(); menu_loop();
#else
strcpy(romFileName, currentConfig.lastRomFile);
engineState = PGS_ReloadRom;
#endif
break; break;
case PGS_ReloadRom: case PGS_ReloadRom:
@ -45,6 +68,9 @@ int main()
case PGS_Running: case PGS_Running:
emu_Loop(); emu_Loop();
#if GPROF
goto endloop;
#endif
break; break;
case PGS_Quit: case PGS_Quit:
@ -58,9 +84,14 @@ int main()
endloop: endloop:
if (mp3_ret == 0) mp3_deinit(); mp3_deinit();
emu_Deinit(); emu_Deinit();
#if GPROF
gprof_cleanup();
#endif
#if !GCOV
psp_finish(); psp_finish();
#endif
return 0; return 0;
} }

View file

@ -941,7 +941,7 @@ static void cd_menu_loop_options(void)
for (;;) for (;;)
{ {
draw_cd_menu_options(menu_sel, &bios_names); 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_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; } 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); selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);
@ -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) && if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, 1) &&
selected_id == MA_CDOPT_DONE) { selected_id == MA_CDOPT_DONE) {
return; return;
} }
if (inp & BTN_START) {
switch (selected_id) { // BIOS testers switch (selected_id) { // BIOS testers
case MA_CDOPT_TESTBIOS_USA: case MA_CDOPT_TESTBIOS_USA:
if (emu_findBios(4, &bios)) { // test US if (emu_findBios(4, &bios)) { // test US

View file

@ -11,6 +11,7 @@
int mp3_last_error = 0; int mp3_last_error = 0;
static int initialized = 0;
static SceUID thread_job_sem = -1; static SceUID thread_job_sem = -1;
static SceUID thread_busy_sem = -1; static SceUID thread_busy_sem = -1;
static int thread_exit = 0; static int thread_exit = 0;
@ -96,9 +97,14 @@ static int read_next_frame(int which_buffer)
continue; // bad frame 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); lprintf("unfit, foffs=%i\n", mp3_src_pos - bytes_read);
mp3_src_pos -= bytes_read - frame_offset; 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); sceIoLseek32(mp3_handle, mp3_src_pos, PSP_SEEK_SET);
continue; // didn't fit, re-read.. continue; // didn't fit, re-read..
} }
@ -195,6 +201,7 @@ int mp3_init(void)
} }
mp3_last_error = 0; mp3_last_error = 0;
initialized = 1;
return 0; return 0;
fail3: fail3:
@ -207,12 +214,15 @@ fail1:
sceAudiocodecReleaseEDRAM(mp3_codec_struct); sceAudiocodecReleaseEDRAM(mp3_codec_struct);
fail: fail:
mp3_last_error = ret; mp3_last_error = ret;
initialized = 0;
return 1; return 1;
} }
void mp3_deinit(void) void mp3_deinit(void)
{ {
lprintf("deinit\n"); lprintf("mp3_deinit, initialized=%i\n", initialized);
if (!initialized) return;
thread_exit = 1; thread_exit = 1;
psp_sem_lock(thread_busy_sem); psp_sem_lock(thread_busy_sem);
psp_sem_unlock(thread_busy_sem); psp_sem_unlock(thread_busy_sem);
@ -229,6 +239,7 @@ void mp3_deinit(void)
sceKernelDeleteSema(thread_job_sem); sceKernelDeleteSema(thread_job_sem);
thread_job_sem = -1; thread_job_sem = -1;
sceAudiocodecReleaseEDRAM(mp3_codec_struct); sceAudiocodecReleaseEDRAM(mp3_codec_struct);
initialized = 0;
} }
// may overflow stack? // may overflow stack?
@ -269,6 +280,7 @@ static int decode_thread(SceSize args, void *argp)
} }
// might be called before initialization
int mp3_get_bitrate(FILE *f, int size) int mp3_get_bitrate(FILE *f, int size)
{ {
int ret, retval = -1, sample_rate, bitrate; int ret, retval = -1, sample_rate, bitrate;
@ -276,7 +288,8 @@ int mp3_get_bitrate(FILE *f, int size)
char *fname = (char *)f; char *fname = (char *)f;
/* make sure thread is not busy.. */ /* 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); if (mp3_handle >= 0) sceIoClose(mp3_handle);
mp3_handle = sceIoOpen(fname, PSP_O_RDONLY, 0777); mp3_handle = sceIoOpen(fname, PSP_O_RDONLY, 0777);
@ -288,19 +301,19 @@ int mp3_get_bitrate(FILE *f, int size)
mp3_src_pos = 0; mp3_src_pos = 0;
ret = read_next_frame(0); ret = read_next_frame(0);
if (ret <= 0) { if (ret <= 0) {
lprintf("read_next_frame() failed\n"); lprintf("read_next_frame() failed (%s)\n", fname);
goto end; goto end;
} }
sample_rate = (mp3_src_buffer[0][2] & 0x0c) >> 2; sample_rate = (mp3_src_buffer[0][2] & 0x0c) >> 2;
bitrate = mp3_src_buffer[0][2] >> 4; bitrate = mp3_src_buffer[0][2] >> 4;
if (sample_rate != 0) { if (sample_rate != 0) {
lprintf("unsupported samplerate\n"); lprintf("unsupported samplerate (%s)\n", fname);
goto end; // only 44kHz supported.. goto end; // only 44kHz supported..
} }
bitrate = bitrates[bitrate]; bitrate = bitrates[bitrate];
if (bitrate == 0) { if (bitrate == 0) {
lprintf("unsupported bitrate\n"); lprintf("unsupported bitrate (%s)\n", fname);
goto end; goto end;
} }
@ -310,7 +323,8 @@ end:
if (mp3_handle >= 0) sceIoClose(mp3_handle); if (mp3_handle >= 0) sceIoClose(mp3_handle);
mp3_handle = -1; mp3_handle = -1;
mp3_fname = NULL; 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.. if (retval < 0) mp3_last_error = -1; // remember we had a problem..
return retval; return retval;
} }
@ -322,6 +336,8 @@ void mp3_start_play(FILE *f, int pos)
{ {
char *fname = (char *)f; char *fname = (char *)f;
if (!initialized) return;
lprintf("mp3_start_play(%s) @ %i\n", fname, pos); lprintf("mp3_start_play(%s) @ %i\n", fname, pos);
psp_sem_lock(thread_busy_sem); psp_sem_lock(thread_busy_sem);

View file

@ -1,4 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
@ -14,12 +15,15 @@
#include "../common/lprintf.h" #include "../common/lprintf.h"
PSP_MODULE_INFO("PicoDrive", 0, 1, 34); PSP_MODULE_INFO("PicoDrive", 0, 1, 34);
PSP_HEAP_SIZE_MAX();
unsigned int __attribute__((aligned(16))) guCmdList[GU_CMDLIST_SIZE]; unsigned int __attribute__((aligned(16))) guCmdList[GU_CMDLIST_SIZE];
void *psp_screen = VRAM_FB0; void *psp_screen = VRAM_FB0;
static int current_screen = 0; /* front bufer */ static int current_screen = 0; /* front bufer */
static SceUID main_thread_id = -1;
#define ANALOG_DEADZONE 80 #define ANALOG_DEADZONE 80
/* Exit callback */ /* Exit callback */
@ -64,8 +68,10 @@ void psp_init(void)
{ {
SceUID thid; SceUID thid;
lprintf("running in %08x kernel\n", sceKernelDevkitVersion()), main_thread_id = sceKernelGetThreadId();
lprintf("entered psp_init, threadId %08x, priority %i\n", sceKernelGetThreadId(),
lprintf("running on %08x kernel\n", sceKernelDevkitVersion()),
lprintf("entered psp_init, threadId %08x, priority %i\n", main_thread_id,
sceKernelGetThreadCurrentPriority()); sceKernelGetThreadCurrentPriority());
thid = sceKernelCreateThread("update_thread", callback_thread, 0x11, 0xFA0, 0, 0); thid = sceKernelCreateThread("update_thread", callback_thread, 0x11, 0xFA0, 0, 0);
@ -198,35 +204,75 @@ char *psp_get_status_line(void)
} }
/* alt logging */ /* alt logging */
#define LOG_FILE "log.log" #define LOG_FILE "log.txt"
static SceUID logfd = -1; typedef struct _log_entry
{
char buff[256];
struct _log_entry *next;
} log_entry;
static log_entry *le_root = NULL;
void lprintf_f(const char *fmt, ...) void lprintf_f(const char *fmt, ...)
{ {
va_list vl; va_list vl;
#ifdef LPRINTF_STDIO
va_start(vl, fmt);
vprintf(fmt, vl);
va_end(vl);
#else
static SceUID logfd = -1;
char buff[256]; char buff[256];
log_entry *le, *le1;
if (logfd == -2) return; // disabled if (logfd == -2) return; // disabled
if (logfd < 0)
{
logfd = sceIoOpen(LOG_FILE, PSP_O_WRONLY|PSP_O_APPEND, 0777);
if (logfd < 0) {
logfd = -2;
return;
}
}
va_start(vl, fmt); va_start(vl, fmt);
vsnprintf(buff, sizeof(buff), fmt, vl); vsnprintf(buff, sizeof(buff), fmt, vl);
va_end(vl); va_end(vl);
// note: this is still unsafe code
if (main_thread_id != sceKernelGetThreadId())
{
le = malloc(sizeof(*le));
if (le == NULL) return;
le->next = NULL;
strcpy(le->buff, buff);
if (le_root == NULL) le_root = le;
else {
for (le1 = le_root; le1->next != NULL; le1 = le1->next);
le1->next = le;
}
return;
}
logfd = sceIoOpen(LOG_FILE, PSP_O_WRONLY|PSP_O_APPEND, 0777);
if (logfd < 0) {
logfd = -2;
return;
}
if (le_root != NULL)
{
le1 = le_root;
le_root = NULL;
sceKernelDelayThread(1000);
while (le1 != NULL) {
le = le1;
le1 = le->next;
sceIoWrite(logfd, le->buff, strlen(le->buff));
free(le);
}
}
sceIoWrite(logfd, buff, strlen(buff)); sceIoWrite(logfd, buff, strlen(buff));
// make sure it gets flushed // make sure it gets flushed
sceIoClose(logfd); sceIoClose(logfd);
logfd = -1; logfd = -1;
#endif
} }

View file

@ -35,6 +35,7 @@ static int is_good_path(char *path)
fclose(f); fclose(f);
return 1; return 1;
} }
printf("not good path: %s\n", path);
return 0; return 0;
} }
@ -68,7 +69,7 @@ readnext:
{ {
pos1 = search_gcda(buff + pos, l - pos); pos1 = search_gcda(buff + pos, l - pos);
if (pos1 < 0) { if (pos1 < 0) {
fseek(f, -5, SEEK_CUR); fseek(f, -6, SEEK_CUR);
goto readnext; goto readnext;
} }
pos += pos1; pos += pos1;
@ -76,7 +77,7 @@ readnext:
while (pos > 0 && is_good_char(buff[pos-1])) pos--; while (pos > 0 && is_good_char(buff[pos-1])) pos--;
if (pos == 0) { if (pos == 0) {
fseek(f, -16, SEEK_CUR); fseek(f, -(sizeof(buff) + 16), SEEK_CUR);
goto readnext; goto readnext;
} }