aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneonloop2021-08-21 00:10:44 +0000
committerneonloop2021-08-21 00:10:44 +0000
commit41fff233f29b6ee7274f4bf525052dcf0fa56c00 (patch)
treecfcc8fc9ae57b694d353cba8752a1f8fd99dc78e
parentf89bcd0179f4e07fe403894053c624d4983090c3 (diff)
downloadpicoarch-41fff233f29b6ee7274f4bf525052dcf0fa56c00.tar.gz
picoarch-41fff233f29b6ee7274f4bf525052dcf0fa56c00.tar.bz2
picoarch-41fff233f29b6ee7274f4bf525052dcf0fa56c00.zip
Updates message display and adds loading message to pcsx
-rw-r--r--Makefile2
-rw-r--r--config.c1
-rw-r--r--core.c7
-rw-r--r--main.c15
-rw-r--r--main.h13
-rw-r--r--menu.c3
-rw-r--r--options.c39
-rw-r--r--overrides.c2
-rw-r--r--overrides.h6
-rw-r--r--overrides/pcsx_rearmed.h8
-rw-r--r--plat.h4
-rw-r--r--plat_linux.c3
-rw-r--r--plat_sdl.c39
-rw-r--r--plat_trimui.c3
-rw-r--r--unzip.c3
-rw-r--r--util.c29
-rw-r--r--util.h21
17 files changed, 133 insertions, 65 deletions
diff --git a/Makefile b/Makefile
index 5cfb979..9d360c7 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ SYSROOT = $(shell $(CC) --print-sysroot)
PROCS = -j4
-OBJS = libpicofe/input.o libpicofe/in_sdl.o libpicofe/linux/in_evdev.o libpicofe/linux/plat.o libpicofe/fonts.o libpicofe/readpng.o libpicofe/config_file.o config.o core.o menu.o main.o options.o overrides.o scale.o unzip.o
+OBJS = libpicofe/input.o libpicofe/in_sdl.o libpicofe/linux/in_evdev.o libpicofe/linux/plat.o libpicofe/fonts.o libpicofe/readpng.o libpicofe/config_file.o config.o core.o menu.o main.o options.o overrides.o scale.o unzip.o util.o
BIN = picoarch
diff --git a/config.c b/config.c
index c33d5cc..83f8a61 100644
--- a/config.c
+++ b/config.c
@@ -4,6 +4,7 @@
#include "main.h"
#include "options.h"
#include "scale.h"
+#include "util.h"
typedef enum {
CE_TYPE_STR = 0,
diff --git a/core.c b/core.c
index bbc9a58..da5c6a9 100644
--- a/core.c
+++ b/core.c
@@ -13,6 +13,7 @@
#include "overrides.h"
#include "plat.h"
#include "unzip.h"
+#include "util.h"
#define PATH_SEPARATOR_CHAR '/'
@@ -390,9 +391,11 @@ static bool pa_environment(unsigned cmd, void *data) {
break;
}
case RETRO_ENVIRONMENT_SET_MESSAGE: { /* 6 */
- /* Just warn for now. TODO: Display on the screen */
const struct retro_message *message = (const struct retro_message*)data;
- PA_WARN(message->msg);
+ if (message) {
+ PA_INFO("%s\n", message->msg);
+ }
+
break;
}
case RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY: { /* 9 */
diff --git a/main.c b/main.c
index c7b4276..e8e7679 100644
--- a/main.c
+++ b/main.c
@@ -381,7 +381,7 @@ void handle_emu_action(emu_action action)
case EACTION_TOGGLE_FPS:
show_fps = !show_fps;
/* Force the hud to clear */
- plat_video_set_msg(" ");
+ plat_video_set_msg(NULL, 0, 0);
break;
case EACTION_SAVE_STATE:
state_write();
@@ -432,6 +432,13 @@ void pa_log(enum retro_log_level level, const char *fmt, ...) {
}
}
+static void show_startup_message(void) {
+ const struct core_override *override = get_overrides();
+ if (override && override->startup_msg) {
+ plat_video_set_msg(override->startup_msg->msg, 2, override->startup_msg->msec);
+ }
+}
+
void pa_track_render(void) {
renders++;
}
@@ -454,12 +461,13 @@ static void count_fps(void)
vsyncs = 0;
renders = 0;
nextsec = ticks + 1000;
+
+ snprintf(msg, HUD_LEN, "FPS: %.1f (%.0f)", rendersps, vsyncsps);
+ plat_video_set_msg(msg, 1, 1100);
}
}
vsyncs++;
- snprintf(msg, HUD_LEN, "FPS: %.1f (%.0f)", rendersps, vsyncsps);
- plat_video_set_msg(msg);
}
}
@@ -534,6 +542,7 @@ int main(int argc, char **argv) {
}
#endif
+ show_startup_message();
do {
count_fps();
adjust_audio();
diff --git a/main.h b/main.h
index cf6025e..e4e73aa 100644
--- a/main.h
+++ b/main.h
@@ -2,7 +2,6 @@
#define __MAIN_H__
#include <stdbool.h>
-#include <string.h>
#include "options.h"
#include "libretro.h"
@@ -30,18 +29,6 @@ extern void* mmenu;
extern char save_template_path[MAX_PATH];
#endif
-
-#define MAX(a, b) (a) > (b) ? (a) : (b)
-#define MIN(a, b) (a) < (b) ? (a) : (b)
-
-static inline bool has_suffix_i(const char *str, const char *suffix) {
- const char *p = strrchr(str, suffix[0]);
- if (!p) p = str;
- return !strcasecmp(p, suffix);
-}
-
-#define array_size(x) (sizeof(x) / sizeof(x[0]))
-
#ifdef DEBUG_LOGGING
#define PA_DEBUG(...) pa_log(RETRO_LOG_DEBUG, __VA_ARGS__)
#else
diff --git a/menu.c b/menu.c
index f314e43..0310c07 100644
--- a/menu.c
+++ b/menu.c
@@ -6,6 +6,7 @@
#include "overrides.h"
#include "plat.h"
#include "scale.h"
+#include "util.h"
static int drew_alt_bg = 0;
@@ -435,7 +436,7 @@ void menu_loop(void)
;
/* Force the hud to clear */
- plat_video_set_msg(" ");
+ plat_video_set_msg(NULL, 0, 0);
plat_video_menu_leave();
}
diff --git a/options.c b/options.c
index 7f902e3..ebfd538 100644
--- a/options.c
+++ b/options.c
@@ -4,6 +4,7 @@
#include "main.h"
#include "options.h"
#include "overrides.h"
+#include "util.h"
int show_fps;
int limit_frames;
@@ -18,36 +19,6 @@ struct core_options core_options;
#define MAX_LINE_LEN 52
#define MAX_LINES 3
-static void truncate(char *string, size_t max_len) {
- size_t len = strlen(string) + 1;
- if (len <= max_len) return;
-
- strncpy(&string[max_len - 4], "...\0", 4);
-}
-
-static void wrap(char *string, size_t max_len, size_t max_lines) {
- char *line = string;
-
- for (size_t i = 1; i < max_lines; i++) {
- char *p = line;
- char *prev;
- do {
- prev = p;
- p = strchr(prev+1, ' ');
- } while (p && p - line < (int)max_len);
-
- if (!p && strlen(line) < max_len) break;
-
- if (prev && prev != line) {
- line = prev + 1;
- *prev = '\n';
- }
- }
- truncate(line, max_len);
-
- return;
-}
-
static int options_default_index(const struct core_option_entry* entry, const char *default_value) {
const char *value;
if (!default_value)
@@ -123,7 +94,7 @@ void options_init(const struct retro_core_option_definition *defs) {
}
strncpy(entry->desc, desc, len);
- truncate(entry->desc, MAX_DESC_LEN);
+ string_truncate(entry->desc, MAX_DESC_LEN);
if (info) {
len = strlen(info) + 1;
@@ -134,7 +105,7 @@ void options_init(const struct retro_core_option_definition *defs) {
return;
}
strncpy(entry->info, info, len);
- wrap(entry->info, MAX_LINE_LEN, MAX_LINES);
+ string_wrap(entry->info, MAX_LINE_LEN, MAX_LINES);
}
for (j = 0; def->values[j].value; j++)
@@ -240,7 +211,7 @@ void options_init_variables(const struct retro_variable *vars) {
return;
}
strncpy(entry->info, info, len);
- wrap(entry->info, MAX_LINE_LEN, MAX_LINES);
+ string_wrap(entry->info, MAX_LINE_LEN, MAX_LINES);
}
entry->blocked = CORE_OVERRIDE(override, blocked, false);
@@ -264,7 +235,7 @@ void options_init_variables(const struct retro_variable *vars) {
if (p && *(p + 1) == ' ') {
*p = '\0';
entry->desc = value;
- truncate(entry->desc, MAX_DESC_LEN);
+ string_truncate(entry->desc, MAX_DESC_LEN);
p++;
p++;
}
diff --git a/overrides.c b/overrides.c
index d8914ce..998110f 100644
--- a/overrides.c
+++ b/overrides.c
@@ -1,4 +1,3 @@
-#include "main.h"
#include "overrides.h"
#include "overrides/gambatte.h"
#include "overrides/gpsp.h"
@@ -6,6 +5,7 @@
#include "overrides/pcsx_rearmed.h"
#include "overrides/snes9x2002.h"
#include "overrides/snes9x2005.h"
+#include "util.h"
static const struct core_override overrides[] = {
gambatte_overrides,
diff --git a/overrides.h b/overrides.h
index cba4308..0d378af 100644
--- a/overrides.h
+++ b/overrides.h
@@ -21,9 +21,15 @@ struct core_override_fast_forward {
const char *interval_value;
};
+struct core_override_startup_msg {
+ const char *msg;
+ const unsigned msec;
+};
+
struct core_override {
const char *core_name;
const struct core_override_fast_forward *fast_forward;
+ const struct core_override_startup_msg *startup_msg;
me_bind_action* actions;
const size_t action_size;
const struct core_override_option* options;
diff --git a/overrides/pcsx_rearmed.h b/overrides/pcsx_rearmed.h
index 1b463cf..daf0ea6 100644
--- a/overrides/pcsx_rearmed.h
+++ b/overrides/pcsx_rearmed.h
@@ -181,10 +181,16 @@ const struct core_override_fast_forward pcsx_rearmed_fast_forward = {
.interval_key = "pcsx_rearmed_frameskip_interval"
};
+const struct core_override_startup_msg pcsx_rearmed_startup_msg = {
+ .msg = "Loading...",
+ .msec = 3000,
+};
+
#define pcsx_rearmed_overrides { \
.core_name = "pcsx_rearmed", \
.fast_forward = &pcsx_rearmed_fast_forward, \
+ .startup_msg = &pcsx_rearmed_startup_msg, \
.actions = pcsx_rearmed_ctrl_actions, \
.action_size = array_size(pcsx_rearmed_ctrl_actions), \
- .options = pcsx_rearmed_core_option_overrides \
+ .options = pcsx_rearmed_core_option_overrides, \
}
diff --git a/plat.h b/plat.h
index f116d1c..64ffb47 100644
--- a/plat.h
+++ b/plat.h
@@ -8,7 +8,7 @@ struct audio_frame {
int16_t right;
};
-#define HUD_LEN 39
+#define HUD_LEN 41
int plat_init(void);
void plat_finish(void);
@@ -19,7 +19,7 @@ int plat_dump_screen(const char *filename);
int plat_load_screen(const char *filename, void *buf, size_t buf_size, int *w, int *h, int *bpp);
void plat_video_open(void);
-void plat_video_set_msg(const char *new_msg);
+void plat_video_set_msg(const char *new_msg, unsigned priority, unsigned msec);
void plat_video_process(const void *data, unsigned width, unsigned height, size_t pitch);
void plat_video_flip(void);
void plat_video_close(void);
diff --git a/plat_linux.c b/plat_linux.c
index a087ca6..bc57f3c 100644
--- a/plat_linux.c
+++ b/plat_linux.c
@@ -1,9 +1,10 @@
#include <SDL/SDL.h>
-#include "main.h"
#include "libretro.h"
#include "libpicofe/plat.h"
#include "libpicofe/input.h"
#include "libpicofe/in_sdl.h"
+#include "main.h"
+#include "util.h"
#define SAMPLE_RATE 48000
diff --git a/plat_sdl.c b/plat_sdl.c
index 395227a..e4d2c1f 100644
--- a/plat_sdl.c
+++ b/plat_sdl.c
@@ -5,6 +5,7 @@
#include "menu.h"
#include "plat.h"
#include "scale.h"
+#include "util.h"
static SDL_Surface* screen;
@@ -22,6 +23,21 @@ struct audio_state {
struct audio_state audio;
static char msg[HUD_LEN];
+static unsigned msg_priority = 0;
+static unsigned msg_expire = 0;
+
+static void video_expire_msg(void)
+{
+ msg[0] = '\0';
+ msg_priority = 0;
+ msg_expire = 0;
+}
+
+static void video_update_msg(void)
+{
+ if (msg[0] && msg_expire < plat_get_ticks_ms())
+ video_expire_msg();
+}
static void video_clear_msg(uint16_t *dst, uint32_t h, uint32_t pitch)
{
@@ -169,29 +185,42 @@ void plat_video_open(void)
{
}
-void plat_video_set_msg(const char *new_msg)
+void plat_video_set_msg(const char *new_msg, unsigned priority, unsigned msec)
{
- snprintf(msg, HUD_LEN, "%s", new_msg);
+ if (!new_msg) {
+ video_expire_msg();
+ } else if (priority >= msg_priority) {
+ snprintf(msg, HUD_LEN, "%s", new_msg);
+ string_truncate(msg, HUD_LEN - 1);
+ msg_priority = priority;
+ msg_expire = plat_get_ticks_ms() + msec;
+ }
}
void plat_video_process(const void *data, unsigned width, unsigned height, size_t pitch) {
+ static int had_msg = 0;
SDL_LockSurface(screen);
- if (msg[0])
+ if (had_msg) {
video_clear_msg(screen->pixels, screen->h, screen->pitch / SCREEN_BPP);
+ had_msg = 0;
+ }
scale(width, height, pitch, data, screen->pixels);
- if (msg[0])
+ if (msg[0]) {
video_print_msg(screen->pixels, screen->h, screen->pitch / SCREEN_BPP, msg);
+ had_msg = 1;
+ }
SDL_UnlockSurface(screen);
+
+ video_update_msg();
}
void plat_video_flip(void)
{
fb_flip();
- msg[0] = 0;
}
void plat_video_close(void)
diff --git a/plat_trimui.c b/plat_trimui.c
index f50b2ed..eee7c19 100644
--- a/plat_trimui.c
+++ b/plat_trimui.c
@@ -1,9 +1,10 @@
#include <SDL/SDL.h>
-#include "main.h"
#include "libretro.h"
#include "libpicofe/plat.h"
#include "libpicofe/input.h"
#include "libpicofe/in_sdl.h"
+#include "main.h"
+#include "util.h"
#define SAMPLE_RATE 48000
diff --git a/unzip.c b/unzip.c
index 1345ddb..abd0d55 100644
--- a/unzip.c
+++ b/unzip.c
@@ -1,7 +1,10 @@
+#include <stdbool.h>
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "main.h"
#include "unzip.h"
+#include "util.h"
#include "zlib.h"
#define HEADER_SIZE 30
diff --git a/util.c b/util.c
new file mode 100644
index 0000000..ccc8c19
--- /dev/null
+++ b/util.c
@@ -0,0 +1,29 @@
+#include "util.h"
+
+void string_truncate(char *string, size_t max_len) {
+ size_t len = strlen(string) + 1;
+ if (len <= max_len) return;
+
+ strncpy(&string[max_len - 4], "...\0", 4);
+}
+
+void string_wrap(char *string, size_t max_len, size_t max_lines) {
+ char *line = string;
+
+ for (size_t i = 1; i < max_lines; i++) {
+ char *p = line;
+ char *prev;
+ do {
+ prev = p;
+ p = strchr(prev+1, ' ');
+ } while (p && p - line < (int)max_len);
+
+ if (!p && strlen(line) < max_len) break;
+
+ if (prev && prev != line) {
+ line = prev + 1;
+ *prev = '\n';
+ }
+ }
+ string_truncate(line, max_len);
+}
diff --git a/util.h b/util.h
new file mode 100644
index 0000000..641165b
--- /dev/null
+++ b/util.h
@@ -0,0 +1,21 @@
+#ifndef UTIL_H
+#define UTIL_H
+
+#include <stdbool.h>
+#include <string.h>
+
+#define MAX(a, b) (a) > (b) ? (a) : (b)
+#define MIN(a, b) (a) < (b) ? (a) : (b)
+
+#define array_size(x) (sizeof(x) / sizeof(x[0]))
+
+static inline bool has_suffix_i(const char *str, const char *suffix) {
+ const char *p = strrchr(str, suffix[0]);
+ if (!p) p = str;
+ return !strcasecmp(p, suffix);
+}
+
+void string_truncate(char *string, size_t max_len);
+void string_wrap(char *string, size_t max_len, size_t max_lines);
+
+#endif