#include "../common/emu.h"
#include "../common/lprintf.h"
#include "../../Pico/PicoInt.h"
#include "../common/emu.h"
#include "../common/lprintf.h"
#include "../../Pico/PicoInt.h"
// additional pspaudio imports, credits to crazyc
int sceAudio_38553111(unsigned short samples, unsigned short freq, char unknown); // play with conversion?
// additional pspaudio imports, credits to crazyc
int sceAudio_38553111(unsigned short samples, unsigned short freq, char unknown); // play with conversion?
char romFileName[PATH_MAX];
unsigned char *PicoDraw2FB = (unsigned char *)VRAM_CACHED_STUFF + 8; // +8 to be able to skip border with 1 quadword..
char romFileName[PATH_MAX];
unsigned char *PicoDraw2FB = (unsigned char *)VRAM_CACHED_STUFF + 8; // +8 to be able to skip border with 1 quadword..
static int combo_keys = 0, combo_acts = 0; // keys and actions which need button combos
static unsigned int noticeMsgTime = 0;
static int combo_keys = 0, combo_acts = 0; // keys and actions which need button combos
static unsigned int noticeMsgTime = 0;
-static void osd_text(int x, const char *text, int is_active)
+static void osd_text(int x, const char *text, int is_active, int clear_all)
int *p, h;
void *tmp;
for (h = 0; h < 8; h++) {
p = (int *) (screen+x+512*(264+h));
p = (int *) ((int)p & ~3); // align
int *p, h;
void *tmp;
for (h = 0; h < 8; h++) {
p = (int *) (screen+x+512*(264+h));
p = (int *) ((int)p & ~3); // align
}
if (is_active) { tmp = psp_screen; psp_screen = screen; } // nasty pointer tricks
emu_textOut16(x, 264, text);
}
if (is_active) { tmp = psp_screen; psp_screen = screen; } // nasty pointer tricks
emu_textOut16(x, 264, text);
noticeMsgTime = sceKernelGetSystemTimeLow() - 2000000;
/* assumption: emu_msg_cb gets called only when something slow is about to happen */
noticeMsgTime = sceKernelGetSystemTimeLow() - 2000000;
/* assumption: emu_msg_cb gets called only when something slow is about to happen */
{
memset(¤tConfig, 0, sizeof(currentConfig));
currentConfig.lastRomFile[0] = 0;
{
memset(¤tConfig, 0, sizeof(currentConfig));
currentConfig.lastRomFile[0] = 0;
- currentConfig.EmuOpt = 0x1f | 0x680; // | confirm_save, cd_leds, 16bit rend
- currentConfig.PicoOpt = 0x0f | 0xc00; // | cd_pcm, cd_cdda
+ currentConfig.EmuOpt = 0x1d | 0x680; // | confirm_save, cd_leds, acc rend
+ currentConfig.PicoOpt = 0x0f | 0x1c00; // | gfx_cd, cd_pcm, cd_cdda
currentConfig.PsndRate = 22050;
currentConfig.PicoRegion = 0; // auto
currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP
currentConfig.Frameskip = -1; // auto
currentConfig.volume = 50;
currentConfig.PsndRate = 22050;
currentConfig.PicoRegion = 0; // auto
currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP
currentConfig.Frameskip = -1; // auto
currentConfig.volume = 50;
currentConfig.KeyBinds[ 4] = 1<<0; // SACB RLDU
currentConfig.KeyBinds[ 6] = 1<<1;
currentConfig.KeyBinds[ 7] = 1<<2;
currentConfig.KeyBinds[ 4] = 1<<0; // SACB RLDU
currentConfig.KeyBinds[ 6] = 1<<1;
currentConfig.KeyBinds[ 7] = 1<<2;
currentConfig.KeyBinds[13] = 1<<5;
currentConfig.KeyBinds[15] = 1<<6;
currentConfig.KeyBinds[ 3] = 1<<7;
currentConfig.KeyBinds[13] = 1<<5;
currentConfig.KeyBinds[15] = 1<<6;
currentConfig.KeyBinds[ 3] = 1<<7;
- currentConfig.PicoCDBuffers = 0;
- currentConfig.scaling = 1; // bilinear filtering for psp
- currentConfig.scale = currentConfig.hscale32 = currentConfig.hscale40 = 1.0;
+ currentConfig.KeyBinds[28] = 1<<0; // num "buttons"
+ currentConfig.KeyBinds[30] = 1<<1;
+ currentConfig.KeyBinds[31] = 1<<2;
+ currentConfig.KeyBinds[29] = 1<<3;
+ currentConfig.PicoCDBuffers = 64;
+ currentConfig.scaling = 1; // bilinear filtering for psp
+ currentConfig.scale = 1.20; // fullscreen
+ currentConfig.hscale40 = 1.25;
+ currentConfig.hscale32 = 1.56;
- int src_width, fbimg_width, fbimg_height, fbimg_xoffs, fbimg_yoffs;
+ int src_width, fbimg_width, fbimg_height, fbimg_xoffs, fbimg_yoffs, border_hack = 0;
g_vertices[1].y = fbimg_height;
if (fbimg_xoffs < 0) fbimg_xoffs = 0;
if (fbimg_yoffs < 0) fbimg_yoffs = 0;
g_vertices[1].y = fbimg_height;
if (fbimg_xoffs < 0) fbimg_xoffs = 0;
if (fbimg_yoffs < 0) fbimg_yoffs = 0;
lprintf("set_scaling_params:\n");
lprintf("offs: %i, %i\n", fbimg_xoffs, fbimg_yoffs);
lprintf("xy0, xy1: %i, %i; %i, %i\n", g_vertices[0].x, g_vertices[0].y, g_vertices[1].x, g_vertices[1].y);
lprintf("uv0, uv1: %i, %i; %i, %i\n", g_vertices[0].u, g_vertices[0].v, g_vertices[1].u, g_vertices[1].v);
lprintf("set_scaling_params:\n");
lprintf("offs: %i, %i\n", fbimg_xoffs, fbimg_yoffs);
lprintf("xy0, xy1: %i, %i; %i, %i\n", g_vertices[0].x, g_vertices[0].y, g_vertices[1].x, g_vertices[1].y);
lprintf("uv0, uv1: %i, %i; %i, %i\n", g_vertices[0].u, g_vertices[0].v, g_vertices[1].u, g_vertices[1].v);
- for (i = 0x3f/2; i >= 0; i--)
- dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4);
+ //for (i = 0x3f/2; i >= 0; i--)
+ // dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4);
+ do_pal_convert(localPal, Pico.cram, currentConfig.gamma);
sceGuSync(0,0); // sync with prev
sceGuStart(GU_DIRECT, guCmdList);
sceGuDrawBuffer(GU_PSM_5650, (void *)offs, 512); // point to back buffer
sceGuSync(0,0); // sync with prev
sceGuStart(GU_DIRECT, guCmdList);
sceGuDrawBuffer(GU_PSM_5650, (void *)offs, 512); // point to back buffer
- {
- int i, *dpal = (void *)localPal, *spal = (int *)Pico.cram;
- for (i = 0x3f/2; i >= 0; i--)
- dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4);
- localPal[0xe0] = 0;
- Pico.m.dirtyPal = 0;
- need_pal_upload = 1;
- }
+ do_pal_update(0);
+
+ sceKernelDcacheWritebackAll();
- static int old_reg = 0;
- unsigned int col_g, col_r, *p;
+ unsigned int reg, col_g, col_r, *p;
*p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 512/2 - 12/2;
*p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 512/2 - 12/2;
*p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r;
}
*p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 512/2 - 12/2;
*p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 512/2 - 12/2;
*p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r;
}
for (h = 0; h < 8; h++) {
p = (int *) ((unsigned short *) psp_screen+2+512*(256+h));
p = (int *) ((int)p & ~3); // align
for (h = 0; h < 8; h++) {
p = (int *) ((unsigned short *) psp_screen+2+512*(256+h));
p = (int *) ((int)p & ~3); // align
- if (notice) osd_text(4, notice, 0);
- if (emu_opt & 2) osd_text(OSD_FPS_X, fps, 0);
+ if (notice) osd_text(4, notice, 0, 0);
+ if (emu_opt & 2) osd_text(OSD_FPS_X, fps, 0, 0);
memset32(VRAM_CACHED_STUFF, 0xe0e0e0e0, 512*240/4);
memset32((int *)VRAM_CACHED_STUFF+512*240/4, 0, 512*240*2/4);
} else {
void *fb = psp_video_get_active_fb();
memset32(VRAM_CACHED_STUFF, 0xe0e0e0e0, 512*240/4);
memset32((int *)VRAM_CACHED_STUFF+512*240/4, 0, 512*240*2/4);
} else {
void *fb = psp_video_get_active_fb();
- memset32((int *)((char *)psp_screen + 512*264*2), 0, 512*8*2/4);
- memset32((int *)((char *)fb + 512*264*2), 0, 512*8*2/4);
+ memset32_uncached((int *)((char *)psp_screen + 512*264*2), 0, 512*8*2/4);
+ memset32_uncached((int *)((char *)fb + 512*264*2), 0, 512*8*2/4);
-#define SOUND_BLOCK_SIZE_NTSC (2940*2) // 1024 // 1152
-#define SOUND_BLOCK_SIZE_PAL (3528*2)
-#define SOUND_BLOCK_COUNT 4
+#define SOUND_BLOCK_SIZE_NTSC (1470*2) // 1024 // 1152
+#define SOUND_BLOCK_SIZE_PAL (1764*2)
+#define SOUND_BLOCK_COUNT 8
static short __attribute__((aligned(4))) sndBuffer[SOUND_BLOCK_SIZE_PAL*SOUND_BLOCK_COUNT + 44100/50*2];
static short *snd_playptr = NULL, *sndBuffer_endptr = NULL;
static short __attribute__((aligned(4))) sndBuffer[SOUND_BLOCK_SIZE_PAL*SOUND_BLOCK_COUNT + 44100/50*2];
static short *snd_playptr = NULL, *sndBuffer_endptr = NULL;
- // wait for data...
- //lprintf("sthr: wait... (%i/%i)\n", samples_done, samples_made);
- ret = sceKernelWaitSema(sound_sem, 1, 0);
- //lprintf("sthr: sceKernelWaitSema: %i\n", ret);
+ // wait for data (use at least 2 blocks)
+ //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);
- 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) {
+ //lprintf("sthr: block skip (%i)\n", samples_made - samples_done);
+ samples_done += samples_block; // skip
+ snd_playptr += samples_block;
+ }
+
sound_sem = sceKernelCreateSema("sndsem", 0, 0, 1, NULL);
if (sound_sem < 0) lprintf("sceKernelCreateSema() failed: %i\n", sound_sem);
sound_sem = sceKernelCreateSema("sndsem", 0, 0, 1, NULL);
if (sound_sem < 0) lprintf("sceKernelCreateSema() failed: %i\n", sound_sem);
sound_thread_exit = 0;
thid = sceKernelCreateThread("sndthread", sound_thread, 0x12, 0x10000, 0, NULL);
if (thid >= 0)
{
sound_thread_exit = 0;
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);
samples_made = samples_done = 0;
if (PsndRate != PsndRate_old || (PicoOpt&0x0b) != (PicoOpt_old&0x0b) || Pico.m.pal != pal_old) {
samples_made = samples_done = 0;
if (PsndRate != PsndRate_old || (PicoOpt&0x0b) != (PicoOpt_old&0x0b) || Pico.m.pal != pal_old) {
sndBuffer_endptr = &sndBuffer[samples_block*SOUND_BLOCK_COUNT];
lprintf("starting audio: %i, len: %i, stereo: %i, pal: %i, block samples: %i\n",
PsndRate, PsndLen, stereo, Pico.m.pal, samples_block);
sndBuffer_endptr = &sndBuffer[samples_block*SOUND_BLOCK_COUNT];
lprintf("starting audio: %i, len: %i, stereo: %i, pal: %i, block samples: %i\n",
PsndRate, PsndLen, stereo, Pico.m.pal, samples_block);
ret = sceAudio_38553111(samples_block/2, PsndRate, 2); // seems to not need that stupid 64byte alignment
if (ret < 0) {
lprintf("sceAudio_38553111() failed: %i\n", ret);
ret = sceAudio_38553111(samples_block/2, PsndRate, 2); // seems to not need that stupid 64byte alignment
if (ret < 0) {
lprintf("sceAudio_38553111() failed: %i\n", ret);
- while (samples_made - samples_done >= samples_block || sceAudioOutput2GetRestSample() > 0)
+ int i;
+ if (samples_done == 0)
+ {
+ // if no data is written between sceAudio_38553111 and sceAudio_5C37C0AE calls,
+ // we get a deadlock on next sceAudio_38553111 call
+ // so this is yet another workaround:
+ memset32((int *)(void *)sndBuffer, 0, samples_block*4/4);
+ samples_made = samples_block * 3;
+ sceKernelSignalSema(sound_sem, 1);
+ }
+ sceKernelDelayThread(100*1000);
+ samples_made = samples_done = 0;
+ for (i = 0; sceAudioOutput2GetRestSample() > 0 && i < 16; i++)
// lprintf("signal, %i/%i\n", samples_done, samples_made);
ret = sceKernelSignalSema(sound_sem, 1);
// lprintf("signal, %i/%i\n", samples_done, samples_made);
ret = sceKernelSignalSema(sound_sem, 1);
vidResetMode();
memset32(VRAM_CACHED_STUFF, 0xe0e0e0e0, 512*8/4); // borders
memset32((int *)VRAM_CACHED_STUFF + 512*232/4, 0xe0e0e0e0, 512*8/4);
vidResetMode();
memset32(VRAM_CACHED_STUFF, 0xe0e0e0e0, 512*8/4); // borders
memset32((int *)VRAM_CACHED_STUFF + 512*232/4, 0xe0e0e0e0, 512*8/4);
- blit2("", (which & 0x1000) ? "LOAD STATE? (X=yes, O=no)" : "OVERWRITE SAVE? (X=yes, O=no)");
+ sceGuSync(0,0);
+ blit2("", (which & 0x1000) ? "LOAD STATE? (X=yes, O=no)" : "OVERWRITE SAVE? (X=yes, O=no)", 0);
- osd_text(4, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME", 1);
+ osd_text(4, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME", 1, 0);
PicoStateProgressCB = emu_msg_cb;
emu_SaveLoadGame((which & 0x1000) >> 12, 0);
PicoStateProgressCB = NULL;
PicoStateProgressCB = emu_msg_cb;
emu_SaveLoadGame((which & 0x1000) >> 12, 0);
PicoStateProgressCB = NULL;
- if (PicoOpt&0x10) {
- strcpy(noticeMsg, " 8bit fast renderer");
- } else if (currentConfig.EmuOpt&0x80) {
- strcpy(noticeMsg, "16bit accurate renderer");
- } else {
- strcpy(noticeMsg, " 8bit accurate renderer");
- }
+ if (PicoOpt&0x10)
+ strcpy(noticeMsg, "fast renderer");
+ else if (currentConfig.EmuOpt&0x80)
+ strcpy(noticeMsg, "accurate renderer");
+ else
+ {
+ for (u = 0; u < 28; u++)
+ if ((currentConfig.KeyBinds[u] & 0x30000) == 0 && // pl. 1
+ (currentConfig.KeyBinds[u] & (1 << act))) keyc++;
+ for (u = 0; u < 28; u++)
+ if ((currentConfig.KeyBinds[u] & 0x30000) == 1 && // pl. 2
+ (currentConfig.KeyBinds[u] & (1 << act))) keyc2++;
+ }
+ if (keyc > 1 || keyc2 > 1)
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;
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;
+void emu_HandleResume(void)
+{
+ if (!(PicoMCD & 1)) return;
+
+ // reopen files..
+ if (Pico_mcd->TOC.Tracks[0].F != NULL)
+ {
+ lprintf("emu_HandleResume: reopen %s\n", romFileName);
+ pm_close(Pico_mcd->TOC.Tracks[0].F);
+ Pico_mcd->TOC.Tracks[0].F = pm_open(romFileName);
+ lprintf("reopen %s\n", Pico_mcd->TOC.Tracks[0].F != NULL ? "ok" : "failed");
+ }
+
+ mp3_reopen_file();
+}
+