fixes for platform support for PSP

This commit is contained in:
kub 2021-02-05 23:10:22 +01:00
parent 4cc0fcaf15
commit bfd6662370
6 changed files with 33 additions and 22 deletions

View file

@ -168,9 +168,8 @@ PLATFORM_ZLIB = 1
endif endif
ifeq "$(PLATFORM)" "psp" ifeq "$(PLATFORM)" "psp"
CFLAGS += -DUSE_BGR565 -G8 # -DLPRINTF_STDIO -DFW15 CFLAGS += -DUSE_BGR565 -G8 # -DLPRINTF_STDIO -DFW15
LDFLAGS := $(filter-out -lpsp%, $(LDFLAGS)) # collides with PSP image generation LDLIBS += -lpspgu -lpspge -lpsppower -lpspaudio -lpspdisplay -lpspaudiocodec
LDLIBS += -lpspnet_inet -lpspgu -lpspge -lpsppower -lpspaudio -lpspdisplay LDLIBS += -lpsprtc -lpspctrl -lpspsdk -lc -lpspnet_inet -lpspuser -lpspkernel
LDLIBS += -lpspaudiocodec -lpsprtc -lpspctrl -lpspsdk -lpspuser -lpspkernel
platform/common/main.o: CFLAGS += -Dmain=pico_main platform/common/main.o: CFLAGS += -Dmain=pico_main
OBJS += platform/psp/plat.o OBJS += platform/psp/plat.o
OBJS += platform/psp/emu.o OBJS += platform/psp/emu.o

4
configure vendored
View file

@ -17,7 +17,7 @@ compile_object()
compile_binary() compile_binary()
{ {
c="$CC $CFLAGS $TMPC -o $TMPB $LDFLAGS $@" c="$CC $CFLAGS $TMPC -o $TMPB $LDFLAGS $@ $SYSLIBS"
echo $c >> config.log echo $c >> config.log
$c >> config.log 2>&1 $c >> config.log 2>&1
} }
@ -116,7 +116,7 @@ set_platform()
;; ;;
psp) psp)
# use newlib # use newlib
LDFLAGS="$LDFLAGS -lc -lpspuser -lpspkernel" SYSLIBS="-lc -lpspuser -lpspkernel"
CFLAGS="$CFLAGS -D__PSP__" CFLAGS="$CFLAGS -D__PSP__"
ARCH=mipsel ARCH=mipsel
;; ;;

View file

@ -53,7 +53,7 @@ static int h32_mode = 0;
static int out_x, out_y; static int out_x, out_y;
static int out_w, out_h; static int out_w, out_h;
static const struct in_default_bind in_psp_defbinds[] = static struct in_default_bind in_psp_defbinds[] =
{ {
{ PSP_CTRL_UP, IN_BINDTYPE_PLAYER12, GBTN_UP }, { PSP_CTRL_UP, IN_BINDTYPE_PLAYER12, GBTN_UP },
{ PSP_CTRL_DOWN, IN_BINDTYPE_PLAYER12, GBTN_DOWN }, { PSP_CTRL_DOWN, IN_BINDTYPE_PLAYER12, GBTN_DOWN },
@ -211,6 +211,7 @@ static void do_pal_update(void)
t |= (t >> 2) | ((t >> 4) & 0x08610861); t |= (t >> 2) | ((t >> 4) & 0x08610861);
dpal[i] = t; dpal[i] = t;
} }
Pico.m.dirtyPal = 0;
} else if (PicoIn.opt & POPT_ALT_RENDERER) { } else if (PicoIn.opt & POPT_ALT_RENDERER) {
do_pal_convert(localPal, PicoMem.cram, currentConfig.gamma, currentConfig.gamma2); do_pal_convert(localPal, PicoMem.cram, currentConfig.gamma, currentConfig.gamma2);
Pico.m.dirtyPal = 0; Pico.m.dirtyPal = 0;
@ -263,7 +264,7 @@ static void blitscreen_clut(void)
sceGuTexMode(is_16bit_mode() ? GU_PSM_5650:GU_PSM_T8,0,0,0); sceGuTexMode(is_16bit_mode() ? GU_PSM_5650:GU_PSM_T8,0,0,0);
sceGuTexImage(0,512,512,512,g_screen_ptr); sceGuTexImage(0,512,512,512,g_screen_ptr);
if (Pico.m.dirtyPal) if (!is_16bit_mode() && Pico.m.dirtyPal)
do_pal_update(); do_pal_update();
sceKernelDcacheWritebackAll(); sceKernelDcacheWritebackAll();

View file

@ -36,9 +36,10 @@ static const char *in_psp_keys[IN_PSP_NBUTTONS] = {
}; };
/* credits to https://graphics.stanford.edu/~seander/bithacks.html */ /* calculate bit number from bit mask (logarithm to the basis 2) */
static int lg2(unsigned v) static int lg2(unsigned v)
{ {
/* credits to https://graphics.stanford.edu/~seander/bithacks.html */
int r, s; int r, s;
r = (v > 0xFFFF) << 4; v >>= r; r = (v > 0xFFFF) << 4; v >>= r;
@ -49,9 +50,9 @@ static int lg2(unsigned v)
return r; return r;
} }
static int in_psp_get_bits(void) static unsigned in_psp_get_bits(void)
{ {
return psp_pad_read(0); return psp_pad_read(0) & 0xf000ffff;
} }
static void in_psp_probe(const in_drv_t *drv) static void in_psp_probe(const in_drv_t *drv)
@ -75,7 +76,8 @@ in_psp_get_key_names(const in_drv_t *drv, int *count)
static int in_psp_update(void *drv_data, const int *binds, int *result) static int in_psp_update(void *drv_data, const int *binds, int *result)
{ {
int type_start = 0; int type_start = 0;
int i, t, keys; int i, t;
unsigned keys;
keys = in_psp_get_bits(); keys = in_psp_get_bits();
@ -98,8 +100,8 @@ static int in_psp_update(void *drv_data, const int *binds, int *result)
int in_psp_update_keycode(void *data, int *is_down) int in_psp_update_keycode(void *data, int *is_down)
{ {
static int old_val = 0; static unsigned old_val = 0;
int val, diff, i; unsigned val, diff, i;
val = in_psp_get_bits(); val = in_psp_get_bits();
diff = val ^ old_val; diff = val ^ old_val;
@ -118,9 +120,9 @@ int in_psp_update_keycode(void *data, int *is_down)
return i; return i;
} }
static const struct { static struct {
short key; unsigned key;
short pbtn; int pbtn;
} key_pbtn_map[] = } key_pbtn_map[] =
{ {
{ PSP_CTRL_UP, PBTN_UP }, { PSP_CTRL_UP, PBTN_UP },
@ -147,12 +149,12 @@ static int in_psp_menu_translate(void *drv_data, int keycode, char *charcode)
keycode = -keycode; keycode = -keycode;
for (i = 0; i < KEY_PBTN_MAP_SIZE; i++) for (i = 0; i < KEY_PBTN_MAP_SIZE; i++)
if (key_pbtn_map[i].pbtn == keycode) if (key_pbtn_map[i].pbtn == keycode)
return lg2(key_pbtn_map[i].key); return key_pbtn_map[i].key;
} }
else else
{ {
for (i = 0; i < KEY_PBTN_MAP_SIZE; i++) for (i = 0; i < KEY_PBTN_MAP_SIZE; i++)
if (key_pbtn_map[i].key == 1<<keycode) if (key_pbtn_map[i].key == keycode)
return key_pbtn_map[i].pbtn; return key_pbtn_map[i].pbtn;
} }
@ -191,11 +193,19 @@ static const in_drv_t in_psp_drv = {
.menu_translate = in_psp_menu_translate, .menu_translate = in_psp_menu_translate,
}; };
void in_psp_init(const struct in_default_bind *defbinds) void in_psp_init(struct in_default_bind *defbinds)
{ {
int i;
/* PSP keys have bit masks, Picodrive wants bit numbers */
for (i = 0; defbinds[i].code; i++)
defbinds[i].code = lg2(defbinds[i].code);
for (i = 0; i < KEY_PBTN_MAP_SIZE; i++)
key_pbtn_map[i].key = lg2(key_pbtn_map[i].key);
in_psp_combo_keys = in_psp_combo_acts = 0; in_psp_combo_keys = in_psp_combo_acts = 0;
/* fill keys array, converting key bitmasks to indexes */ /* fill keys array, converting key bitmasks to bit numbers */
in_psp_keys[lg2(PSP_CTRL_UP)] = "Up"; in_psp_keys[lg2(PSP_CTRL_UP)] = "Up";
in_psp_keys[lg2(PSP_CTRL_LEFT)] = "Left"; in_psp_keys[lg2(PSP_CTRL_LEFT)] = "Left";
in_psp_keys[lg2(PSP_CTRL_DOWN)] = "Down"; in_psp_keys[lg2(PSP_CTRL_DOWN)] = "Down";

View file

@ -1,4 +1,4 @@
struct in_default_bind; struct in_default_bind;
void in_psp_init(const struct in_default_bind *defbinds); void in_psp_init(struct in_default_bind *defbinds);

View file

@ -194,8 +194,9 @@ void psp_finish(void)
void psp_video_flip(int wait_vsync) void psp_video_flip(int wait_vsync)
{ {
void *fb = (void *)((unsigned long)psp_screen & ~0x40000000);
if (wait_vsync) sceDisplayWaitVblankStart(); if (wait_vsync) sceDisplayWaitVblankStart();
sceDisplaySetFrameBuf(psp_screen, 512, PSP_DISPLAY_PIXEL_FORMAT_565, sceDisplaySetFrameBuf(fb, 512, PSP_DISPLAY_PIXEL_FORMAT_565,
wait_vsync ? PSP_DISPLAY_SETBUF_IMMEDIATE : PSP_DISPLAY_SETBUF_NEXTFRAME); wait_vsync ? PSP_DISPLAY_SETBUF_IMMEDIATE : PSP_DISPLAY_SETBUF_NEXTFRAME);
current_screen ^= 1; current_screen ^= 1;
psp_screen = current_screen ? VRAM_FB0 : VRAM_FB1; psp_screen = current_screen ? VRAM_FB0 : VRAM_FB1;