Browse Source

partially revived platform support for PSP (unfinished) #2

scaling, release generation, fixes
still not planning to make this officially supported.
kub 3 years ago
parent
commit
6c5784f07f

+ 13 - 9
Makefile

@@ -111,12 +111,12 @@ LDFLAGS += -ldl -lbcm_host -L/opt/vc/lib
 ifneq (,$(wildcard /opt/vc/lib/libbrcmGLESv2.so))
 LDFLAGS += -lbrcmEGL -lbrcmGLESv2
 else
-LDFLAGS += -lEGL -lGLESv2
+LDFLAGS += -lEGL -lGLESv2 # on raspi GLESv1_CM is included in GLESv2
 endif
 OBJS += platform/linux/emu.o platform/linux/blit.o # FIXME
 OBJS += platform/common/plat_sdl.o platform/common/input_sdlkbd.o
 OBJS += platform/libpicofe/plat_sdl.o platform/libpicofe/in_sdl.o
-OBJS += platform/libpicofe/plat_dummy.o
+OBJS += platform/libpicofe/plat_dummy.o platform/libpicofe/linux/plat.o
 OBJS += platform/libpicofe/gl.o
 OBJS += platform/libpicofe/gl_platform.o
 USE_FRONTEND = 1
@@ -130,7 +130,7 @@ else
 OBJS += platform/common/plat_sdl.o platform/common/inputmap_kbd.o
 endif
 OBJS += platform/libpicofe/plat_sdl.o platform/libpicofe/in_sdl.o
-OBJS += platform/libpicofe/plat_dummy.o
+OBJS += platform/libpicofe/plat_dummy.o platform/libpicofe/linux/plat.o
 USE_FRONTEND = 1
 endif
 ifeq "$(PLATFORM)" "pandora"
@@ -142,12 +142,14 @@ OBJS += platform/common/arm_utils.o
 OBJS += platform/libpicofe/linux/in_evdev.o
 OBJS += platform/libpicofe/linux/fbdev.o 
 OBJS += platform/libpicofe/linux/xenv.o
+OBJS += platform/libpicofe/linux/plat.o
 OBJS += platform/libpicofe/pandora/plat.o
 USE_FRONTEND = 1
 endif
 ifeq "$(PLATFORM)" "gp2x"
 OBJS += platform/common/arm_utils.o 
 OBJS += platform/libpicofe/linux/in_evdev.o
+OBJS += platform/libpicofe/linux/plat.o
 OBJS += platform/libpicofe/gp2x/in_gp2x.o
 OBJS += platform/libpicofe/gp2x/soc.o 
 OBJS += platform/libpicofe/gp2x/soc_mmsp2.o 
@@ -166,16 +168,16 @@ PLATFORM_ZLIB = 1
 endif
 ifeq "$(PLATFORM)" "psp"
 CFLAGS += -DUSE_BGR565 -DDRAW2_OVERRIDE_LINE_WIDTH=512 -G8 # -DLPRINTF_STDIO -DFW15
+LDFLAGS := $(filter-out -lpsp%, $(LDFLAGS)) # collides with PSP image generation
+LDLIBS += -lpspnet_inet -lpspgu -lpspge -lpsppower -lpspaudio -lpspdisplay
+LDLIBS += -lpspaudiocodec -lpsprtc -lpspctrl -lpspsdk -lpspuser -lpspkernel
 platform/common/main.o: CFLAGS += -Dmain=pico_main
 OBJS += platform/psp/plat.o
 OBJS += platform/psp/emu.o
 OBJS += platform/psp/in_psp.o
 OBJS += platform/psp/psp.o
-#OBJS += platform/psp/menu.o
 OBJS += platform/psp/asm_utils.o
 OBJS += platform/psp/mp3.o
-#OBJS += platform/psp/data/bg32.o
-#OBJS += platform/psp/data/bg40.o
 USE_FRONTEND = 1
 endif
 ifeq "$(PLATFORM)" "libretro"
@@ -200,7 +202,7 @@ OBJS += platform/common/main.o platform/common/emu.o \
 
 # libpicofe
 OBJS += platform/libpicofe/input.o platform/libpicofe/readpng.o \
-	platform/libpicofe/fonts.o platform/libpicofe/linux/plat.o
+	platform/libpicofe/fonts.o
 
 # libpicofe - sound
 OBJS += platform/libpicofe/sndout.o
@@ -278,11 +280,13 @@ else
 endif
 
 ifeq "$(PLATFORM)" "psp"
-PSPSDK = /home/.build/opt/pspdev/psp/sdk
+PSPSDK ?= $(shell psp-config --pspsdk-path)
+TARGET = PicoDrive
 PSP_EBOOT_TITLE = PicoDrive
+PSP_EBOOT_ICON = platform/psp/data/icon.png
 LIBS += -lpng -lm -lz -lpspgu -lpsppower -lpspaudio -lpsprtc -lpspaudiocodec
 EXTRA_TARGETS = EBOOT.PBP
-include /home/.build/opt/pspdev/psp/sdk/lib/build.mak
+include $(PSPSDK)/lib/build.mak
 # TODO image generation
 endif
 

+ 1 - 0
Makefile.libretro

@@ -190,6 +190,7 @@ else ifeq ($(platform), psp1)
 	STATIC_LINKING = 1
 	NO_MMAP = 1
 
+	ARCH = mipsel
 	asm_render = 1
 
 # PS2

+ 8 - 2
configure

@@ -38,7 +38,7 @@ check_define()
 # setting options to "yes" or "no" will make that choice default,
 # "" means "autodetect".
 
-platform_list="generic pandora gp2x wiz caanoo opendingux gcw0 rg350 rpi1 rpi2"
+platform_list="generic pandora gp2x wiz caanoo opendingux gcw0 rg350 rpi1 rpi2 psp"
 platform="generic"
 sound_driver_list="oss alsa sdl"
 sound_drivers=""
@@ -114,6 +114,12 @@ set_platform()
     CFLAGS="$CFLAGS -D__GP2X__"
     platform="gp2x"
     ;;
+  psp)
+    # use newlib
+    LDFLAGS="$LDFLAGS -lc -lpspuser -lpspkernel"
+    CFLAGS="$CFLAGS -D__PSP__"
+    ARCH=mipsel
+    ;;
   *)
     fail "unsupported platform: $platform"
     ;;
@@ -341,7 +347,7 @@ EOF
   compile_object "$@"
 }
 
-check_zlib -lz &&MAIN_LDLIBS="$MAIN_LDLIBS -lz" || need_zlib="yes"
+check_zlib -lz && MAIN_LDLIBS="$MAIN_LDLIBS -lz" || need_zlib="yes"
 
 MAIN_LDLIBS="-lpng $MAIN_LDLIBS"
 check_libpng || fail "please install libpng (libpng-dev)"

+ 1 - 0
platform/common/emu.c

@@ -1227,6 +1227,7 @@ void emu_cmn_forced_frame(int no_scale, int do_emu)
 		PicoIn.opt |= POPT_EN_SOFTSCALE;
 
 	PicoDrawSetOutFormat(PDF_RGB555, 1);
+	PicoDrawSetOutBuf(g_screen_ptr, g_screen_ppitch * 2);
 	Pico.m.dirtyPal = 1;
 	Pico.est.rendstatus |= PDRAW_DIRTY_SPRITES;
 	if (do_emu)

+ 19 - 5
platform/common/menu_pico.c

@@ -126,6 +126,20 @@ static void make_bg(int no_scale)
 		menu_darken_bg(dst, src, w, 1);
 }
 
+static void copy_bg(int dir)
+{
+	unsigned short *bg = (void *)g_menubg_ptr;
+	unsigned short *sc = (void *)g_menuscreen_ptr;
+	int h = g_menuscreen_h;
+
+	for (; h > 0; sc += g_menuscreen_pp, bg += g_menuscreen_w, h--) {
+		if (dir)
+			memcpy(bg, sc, g_menuscreen_w * 2);
+		else
+			memcpy(sc, bg, g_menuscreen_w * 2);
+	}
+}
+
 static void menu_enter(int is_rom_loaded)
 {
 	if (is_rom_loaded)
@@ -182,7 +196,7 @@ static void load_progress_cb(int percent)
 		len = g_menuscreen_w;
 
 	menu_draw_begin(0, 1);
-	memcpy(g_menuscreen_ptr, g_menubg_ptr, g_menuscreen_w * g_menuscreen_h * 2);
+	copy_bg(0);
 	dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_pp * me_sfont_h * 2;
 	for (ln = me_sfont_h - 2; ln > 0; ln--, dst += g_menuscreen_pp)
 		memset(dst, 0xff, len * 2);
@@ -197,7 +211,7 @@ static void cdload_progress_cb(const char *fname, int percent)
 	menu_draw_begin(0, 1);
 	dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_pp * me_sfont_h * 2;
 
-	memcpy(g_menuscreen_ptr, g_menubg_ptr, g_menuscreen_w * g_menuscreen_h * 2);
+	copy_bg(0);
 	menuscreen_memset_lines(dst, 0xff, me_sfont_h - 2);
 
 	smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff);
@@ -224,8 +238,8 @@ void menu_romload_prepare(const char *rom_name)
 	menu_draw_begin(1, 1);
 	smalltext_out16(1, 1, "Loading", 0xffff);
 	smalltext_out16(1, me_sfont_h, p, 0xffff);
-	/* background screen for callbacks */
-	memcpy(g_menubg_ptr, g_menuscreen_ptr, g_menuscreen_w * g_menuscreen_h * 2);
+	/* copy menu to bg for callbacks. OK since we are not in menu_loop here */
+	copy_bg(1);
 	menu_draw_end();
 
 	PicoCartLoadProgressCB = load_progress_cb;
@@ -239,7 +253,7 @@ void menu_romload_end(void)
 	PicoCDLoadProgressCB = NULL;
 
 	menu_draw_begin(0, 1);
-	memcpy(g_menuscreen_ptr, g_menubg_ptr, g_menuscreen_w * g_menuscreen_h * 2);
+	copy_bg(0);
 	smalltext_out16(1, (cdload_called ? 6 : 3) * me_sfont_h,
 		"Starting emulation...", 0xffff);
 	menu_draw_end();

+ 1 - 0
platform/common/menu_pico.h

@@ -66,6 +66,7 @@ typedef enum
 	MA_OPT3_SCALE,		/* psp (all OPT3) */
 	MA_OPT3_HSCALE32,
 	MA_OPT3_HSCALE40,
+	MA_OPT3_GAMMAA,
 	MA_OPT3_PRES_NOSCALE,
 	MA_OPT3_PRES_SCALE43,
 	MA_OPT3_PRES_FULLSCR,

+ 0 - 5
platform/gp2x/emu.c

@@ -98,10 +98,6 @@ static void change_renderer(int diff)
 		r = &currentConfig.renderer;
 	*r += diff;
 
-	// 8bpp fast is not there (yet?)
-	if ((PicoIn.AHW & PAHW_SMS) && *r == RT_8BIT_FAST)
-		(*r)++;
-
 	if      (*r >= RT_COUNT)
 		*r = 0;
 	else if (*r < 0)
@@ -723,7 +719,6 @@ void pemu_sound_stop(void)
 void pemu_forced_frame(int no_scale, int do_emu)
 {
 	doing_bg_frame = 1;
-	PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
 	PicoDrawSetCallbacks(NULL, NULL);
 	Pico.m.dirtyPal = 1;
 

+ 0 - 1
platform/linux/emu.c

@@ -155,7 +155,6 @@ void plat_update_volume(int has_changed, int is_up)
 void pemu_forced_frame(int no_scale, int do_emu)
 {
 	PicoIn.opt &= ~POPT_DIS_32C_BORDER;
-	PicoDrawSetOutBuf(g_screen_ptr, g_screen_ppitch * 2);
 	PicoDrawSetCallbacks(NULL, NULL);
 	Pico.m.dirtyPal = 1;
 

+ 2 - 1
platform/psp/Makefile

@@ -23,7 +23,7 @@ ifeq "$(for_15fw)" "1"
 CFLAGS += -DFW15
 endif
 
-
+ifneq "$(BUILD)" ""
 # frontend and stuff
 OBJS += main.o emu.o mp3.o menu.o psp.o asm_utils.o
 
@@ -172,6 +172,7 @@ myclean:
 clean_prof:
 	find ../.. -name '*.gcno' -delete
 	find ../.. -name '*.gcda' -delete
+endif
 
 # ----------- release -----------
 ifneq ($(findstring rel,$(MAKECMDGOALS)),)

+ 13 - 2
platform/psp/emu.c

@@ -312,7 +312,7 @@ static void cd_leds(void)
 
 static void draw_pico_ptr(void)
 {
-	unsigned char *p = (unsigned char *)VRAM_CACHED_STUFF + 8;
+	unsigned char *p = (unsigned char *)g_screen_ptr + 8;
 
 	// only if pen enabled and for 8bit mode
 	if (pico_inp_mode == 0 || is_16bit_mode()) return;
@@ -571,6 +571,18 @@ void pemu_finalize_frame(const char *fps, const char *notice)
 {
 	int emu_opt = currentConfig.EmuOpt;
 
+	if (PicoIn.opt&POPT_ALT_RENDERER)
+	{
+		int i;
+		unsigned char *pd;
+
+		// clear top and bottom trash
+		for (pd = Pico.est.Draw2FB, i = 8; i > 0; i--, pd += 512)
+			memset32((int *)pd, 0xe0e0e0e0, 320/4);
+		for (pd = Pico.est.Draw2FB+512*232, i = 8; i > 0; i--, pd += 512)
+			memset32((int *)pd, 0xe0e0e0e0, 320/4);
+	}
+
 	if (PicoIn.AHW & PAHW_PICO)
 		draw_pico_ptr();
 
@@ -644,7 +656,6 @@ void emu_video_mode_change(int start_line, int line_count, int is_32cols)
 void pemu_forced_frame(int no_scale, int do_emu)
 {
 	PicoIn.opt &= ~POPT_DIS_32C_BORDER;
-	PicoDrawSetOutBuf(g_screen_ptr, g_screen_ppitch * 2);
 	Pico.m.dirtyPal = 1;
 
 	if (!no_scale)

+ 4 - 0
platform/psp/in_psp.c

@@ -208,6 +208,10 @@ void in_psp_init(const struct in_default_bind *defbinds)
 	in_psp_keys[lg2(PSP_CTRL_CIRCLE)] = "Circle";
 	in_psp_keys[lg2(PSP_CTRL_CROSS)] = "Cross";
 	in_psp_keys[lg2(PSP_CTRL_SQUARE)] = "Square";
+	in_psp_keys[lg2(PSP_NUB_UP)] = "Analog up";
+	in_psp_keys[lg2(PSP_NUB_LEFT)] = "Analog left";
+	in_psp_keys[lg2(PSP_NUB_DOWN)] = "Analog down";
+	in_psp_keys[lg2(PSP_NUB_RIGHT)] = "Analog right";
 
 	in_register_driver(&in_psp_drv, defbinds, NULL);
 }

+ 54 - 58
platform/psp/menu.c

@@ -1,68 +1,64 @@
 
-// TODO scaling configuration non-functional ATM
-
-static const char *men_scaler[] = { "unscaled", "4:3", "fullscreen", NULL };
-#if 0
-static const char h_cscaler40[]   = "Configures the custom scaler for wide resolution";
-static const char h_cscaler32[]   = "Configures the custom scaler for narrow resolution";
-
-static int menu_loop_cscaler(int id, int keys)
-{
-	unsigned int inp;
-
-	currentConfig.scaling = SCALE_CUSTOM;
-
-	pnd_setup_layer(1, g_layer_cx, g_layer_cy, g_layer_cw, g_layer_ch);
-	pnd_restore_layer_data();
+#define MENU_OPTIONS_GFX \
+	mee_cust("Scale factor",                    MA_OPT3_SCALE,    mh_scale, ms_scale), \
+	mee_cust("Hor. scale (for low res. games)", MA_OPT3_HSCALE32, mh_scale, ms_scale), \
+	mee_cust("Hor. scale (for hi res. games)",  MA_OPT3_HSCALE40, mh_scale, ms_scale), \
+	mee_onoff("Bilinear filtering",             MA_OPT3_FILTERING, currentConfig.scaling, 1), \
+	mee_range("Gamma adjustment",               MA_OPT3_GAMMAA,    currentConfig.gamma, -4, 16), \
+	mee_range("Black level",                    MA_OPT3_BLACKLVL,  currentConfig.gamma2,  0,  2), \
+	mee_onoff("wait for vsync",                 MA_OPT3_VSYNC,     currentConfig.EmuOpt, EOPT_VSYNC), \
+	mee_cust_nosave("Set to unscaled centered", MA_OPT3_PRES_NOSCALE, mh_preset_scale, NULL), \
+	mee_cust_nosave("Set to 4:3 scaled",        MA_OPT3_PRES_SCALE43, mh_preset_scale, NULL), \
+	mee_cust_nosave("Set to fullscreen",        MA_OPT3_PRES_FULLSCR, mh_preset_scale, NULL), \
 
-	for (;;)
-	{
-		menu_draw_begin(0, 1);
-		menuscreen_memset_lines(g_menuscreen_ptr, 0, g_menuscreen_h);
-		text_out16(2, 480 - 18, "%dx%d | d-pad to resize, R+d-pad to move", g_layer_cw, g_layer_ch);
-		menu_draw_end();
+#define MENU_OPTIONS_ADV
 
-		inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT
-				   |PBTN_R|PBTN_MOK|PBTN_MBACK, NULL, 40);
-		if (inp & PBTN_UP)    g_layer_cy--;
-		if (inp & PBTN_DOWN)  g_layer_cy++;
-		if (inp & PBTN_LEFT)  g_layer_cx--;
-		if (inp & PBTN_RIGHT) g_layer_cx++;
-		if (!(inp & PBTN_R)) {
-			if (inp & PBTN_UP)    g_layer_ch += 2;
-			if (inp & PBTN_DOWN)  g_layer_ch -= 2;
-			if (inp & PBTN_LEFT)  g_layer_cw += 2;
-			if (inp & PBTN_RIGHT) g_layer_cw -= 2;
-		}
-		if (inp & (PBTN_MOK|PBTN_MBACK))
-			break;
 
-		if (inp & (PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT)) {
-			if (g_layer_cx < 0)   g_layer_cx = 0;
-			if (g_layer_cx > 640) g_layer_cx = 640;
-			if (g_layer_cy < 0)   g_layer_cy = 0;
-			if (g_layer_cy > 420) g_layer_cy = 420;
-			if (g_layer_cw < 160) g_layer_cw = 160;
-			if (g_layer_ch < 60)  g_layer_ch = 60;
-			if (g_layer_cx + g_layer_cw > 800)
-				g_layer_cw = 800 - g_layer_cx;
-			if (g_layer_cy + g_layer_ch > 480)
-				g_layer_ch = 480 - g_layer_cy;
-			pnd_setup_layer(1, g_layer_cx, g_layer_cy, g_layer_cw, g_layer_ch);
-		}
+static const char *ms_scale(int id, int *offs)
+{
+	float val = 0;
+	switch (id) {
+	case MA_OPT3_SCALE:	val = currentConfig.scale; break;
+	case MA_OPT3_HSCALE32:	val = currentConfig.hscale32; break;
+	case MA_OPT3_HSCALE40:	val = currentConfig.hscale40; break;
 	}
+	sprintf(static_buff, "%.2f", val);
+	return static_buff;
+}
 
-	pnd_setup_layer(0, g_layer_cx, g_layer_cy, g_layer_cw, g_layer_ch);
-
+static int mh_scale(int id, int keys)
+{
+	float *val = NULL;
+	switch (id) {
+	case MA_OPT3_SCALE:	val = &currentConfig.scale; break;
+	case MA_OPT3_HSCALE32:	val = &currentConfig.hscale32; break;
+	case MA_OPT3_HSCALE40:	val = &currentConfig.hscale40; break;
+	}
+	if (keys & PBTN_LEFT)	*val += -0.01;
+	if (keys & PBTN_RIGHT)	*val += +0.01;
+	if (*val <= 0)		*val  = +0.01;
 	return 0;
 }
-#endif
 
-#define MENU_OPTIONS_GFX \
-	mee_enum      ("Scaler",                   MA_OPT_SCALING,        currentConfig.scaling, \
-	                                                                  men_scaler), \
-	mee_onoff     ("Vsync",                    MA_OPT3_VSYNC,         currentConfig.EmuOpt, EOPT_VSYNC), \
-	/* mee_cust_h    ("Setup custom scaler",      MA_NONE,               menu_loop_cscaler, NULL, h_cscaler), \*/
-
-#define MENU_OPTIONS_ADV
 
+static int mh_preset_scale(int id, int keys)
+{
+	switch (id) {
+	case MA_OPT3_PRES_NOSCALE:
+		currentConfig.scale = 1.0;
+		currentConfig.hscale32 = 1.0;
+		currentConfig.hscale40 = 1.0;
+		break;
+	case MA_OPT3_PRES_SCALE43:
+		currentConfig.scale = 1.2;
+		currentConfig.hscale32 = 1.25;
+		currentConfig.hscale40 = 1.0;
+		break;
+	case MA_OPT3_PRES_FULLSCR:
+		currentConfig.scale = 1.2;
+		currentConfig.hscale32 = 1.56;
+		currentConfig.hscale40 = 1.25;
+		break;
+	}
+	return 0;
+}

+ 8 - 5
platform/psp/plat.c

@@ -110,7 +110,9 @@ void plat_early_init(void)
 /* base directory for configuration and save files */
 int plat_get_root_dir(char *dst, int len)
 {
-	if (len > 0) *dst = 0;
+ 	*dst = 0;
+	if (len > 4)
+		strcpy(dst, "ms0:/");
 	return 0;
 }
 
@@ -264,8 +266,8 @@ int scandir(const char *dir, struct dirent ***namelist_out,
 	{
 		ent = malloc(sizeof(*ent));
 		if (ent == NULL) { lprintf("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; }
-	ent->d_stat = sce_ent.d_stat;
-	ent->d_stat.st_attr &= FIO_SO_IFMT; // serves as d_type
+		ent->d_stat = sce_ent.d_stat;
+		ent->d_stat.st_attr &= FIO_SO_IFMT; // serves as d_type
 		strncpy(ent->d_name, sce_ent.d_name, sizeof(ent->d_name));
 		ent->d_name[sizeof(ent->d_name)-1] = 0;
 		if (filter == NULL || filter(ent))
@@ -308,7 +310,8 @@ end:
 
 int _flush_cache (char *addr, const int size, const int op)
 {
-	sceKernelDcacheWritebackRange(addr, size);
-	sceKernelIcacheInvalidateRange(addr, size);
+	sceKernelDcacheWritebackAll();
+	//sceKernelDcacheWritebackRange(addr, size);
+	//sceKernelIcacheInvalidateRange(addr, size);
 	return 0;
 }