changeset 1900:93960907807a

Added UI for selecting configured model
author Michael Pavone <pavone@retrodev.com>
date Sun, 16 Feb 2020 10:33:20 -0800
parents 789746b1a1b3
children 5433252329fb
files build_release config.c config.h default.cfg nuklear_ui/blastem_nuklear.c systems.cfg
diffstat 6 files changed, 160 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/build_release	Sun Feb 02 22:38:49 2020 -0800
+++ b/build_release	Sun Feb 16 10:33:20 2020 -0800
@@ -62,7 +62,7 @@
 echo $dir
 rm -rf "$dir"
 mkdir "$dir"
-cp -r $binaries shaders images default.cfg rom.db gamecontrollerdb.txt "$dir"
+cp -r $binaries shaders images default.cfg rom.db gamecontrollerdb.txt systems.cfg "$dir"
 for file in README COPYING CHANGELOG; do
 	cp "$file" "$dir"/"$file$txt"
 done
--- a/config.c	Sun Feb 02 22:38:49 2020 -0800
+++ b/config.c	Sun Feb 16 10:33:20 2020 -0800
@@ -322,3 +322,18 @@
 	char * lowpass_cutoff_str = tern_find_path(config, "audio\0lowpass_cutoff\0", TVAL_PTR).ptrval;
 	return lowpass_cutoff_str ? atoi(lowpass_cutoff_str) : DEFAULT_LOWPASS_CUTOFF;
 }
+
+tern_node *get_systems_config(void)
+{
+	static tern_node *systems;
+	if (!systems) {
+		systems = parse_bundled_config("systems.cfg");
+	}
+	return systems;
+}
+
+tern_node *get_model(tern_node *config, system_type stype)
+{
+	char *model = tern_find_path_default(config, "system\0model\0", (tern_val){.ptrval = "md1va3"}, TVAL_PTR);
+	return tern_find_node(get_systems_config(), model);
+}
--- a/config.h	Sun Feb 02 22:38:49 2020 -0800
+++ b/config.h	Sun Feb 16 10:33:20 2020 -0800
@@ -6,6 +6,7 @@
 #ifndef CONFIG_H_
 #define CONFIG_H_
 #include "tern.h"
+#include "system.h"
 
 tern_node *parse_config_file(char *config_path);
 tern_node *parse_bundled_config(char *config_name);
@@ -17,6 +18,8 @@
 void persist_config(tern_node *config);
 char **get_extension_list(tern_node *config, uint32_t *num_exts_out);
 uint32_t get_lowpass_cutoff(tern_node *config);
+tern_node *get_systems_config(void);
+tern_node *get_model(tern_node *config, system_type stype);
 
 #endif //CONFIG_H_
 
--- a/default.cfg	Sun Feb 02 22:38:49 2020 -0800
+++ b/default.cfg	Sun Feb 16 10:33:20 2020 -0800
@@ -385,6 +385,8 @@
 	#MegaWiFi allows ROMs to make connections to the internet
 	#so it should only be enabled for ROMs you trust
 	megawifi off
+	#Model of the emulated Gen/MD system, see systems.cfg for a list of options
+	model md1va3
 }
 
 
--- a/nuklear_ui/blastem_nuklear.c	Sun Feb 02 22:38:49 2020 -0800
+++ b/nuklear_ui/blastem_nuklear.c	Sun Feb 16 10:33:20 2020 -0800
@@ -1831,6 +1831,50 @@
 		nk_end(context);
 	}
 }
+typedef struct {
+	const char **models;
+	const char **names;
+	uint32_t   num_models;
+	uint32_t   storage;
+} model_foreach_state;
+void model_iter(char *key, tern_val val, uint8_t valtype, void *data)
+{
+	if (valtype != TVAL_NODE) {
+		return;
+	}
+	model_foreach_state *state = data;
+	if (state->num_models == state->storage) {
+		state->storage *= 2;
+		state->models = realloc(state->models, state->storage * sizeof(char *));
+		state->names = realloc(state->names, state->storage * sizeof(char *));
+	}
+	char *def = strdup(key);
+	state->models[state->num_models] = def;
+	state->names[state->num_models++] = tern_find_ptr_default(val.ptrval, "name", def);
+}
+
+typedef struct {
+	const char **models;
+	const char **names;
+} models;
+
+models get_models(uint32_t *num_out)
+{
+	tern_node *systems = get_systems_config();
+	model_foreach_state state = {
+		.models = calloc(4, sizeof(char *)),
+		.names = calloc(4, sizeof(char *)),
+		.num_models = 0,
+		.storage = 4
+	};
+	tern_foreach(systems, model_iter, &state);
+	*num_out = state.num_models;
+	return (models){
+		.models = state.models,
+		.names = state.names
+	};
+}
+
 void view_system_settings(struct nk_context *context)
 {
 	const char *sync_opts[] = {
@@ -1853,12 +1897,25 @@
 	if (selected_region < 0) {
 		selected_region = find_match(region_codes, num_regions, "system\0default_region\0", "U");
 	}
+	static const char **model_opts;
+	static const char **model_names;
+	static uint32_t num_models;
+	if (!model_opts) {
+		models m = get_models(&num_models);
+		model_opts = m.models;
+		model_names = m.names;
+	}
+	static int32_t selected_model = -1;
+	if (selected_model < 0) {
+		selected_model = find_match(model_opts, num_models, "system\0model\0", "md1va3");
+	}
+	
 	const char *formats[] = {
 		"native",
 		"gst"
 	};
 	const uint32_t num_formats = sizeof(formats)/sizeof(*formats);
-	int32_t selected_format = -1;
+	static int32_t selected_format = -1;
 	if (selected_format < 0) {
 		selected_format = find_match(formats, num_formats, "ui\0state_format\0", "native");
 	}
@@ -1908,6 +1965,7 @@
 		settings_toggle(context, "Save config with EXE", "ui\0config_in_exe_dir\0", 0);
 		settings_string(context, "Game Save Path", "ui\0save_path\0", "$USERDATA/blastem/$ROMNAME");
 		selected_region = settings_dropdown_ex(context, "Default Region", region_codes, regions, num_regions, selected_region, "system\0default_region\0");
+		selected_model = settings_dropdown_ex(context, "Model", model_opts, model_names, num_models, selected_model, "system\0model\0");
 		selected_format = settings_dropdown(context, "Save State Format", formats, num_formats, selected_format, "ui\0state_format\0");
 		selected_init = settings_dropdown(context, "Initial RAM Value", ram_inits, num_inits, selected_init, "system\0ram_init\0");
 		selected_io_1 = settings_dropdown_ex(context, "IO Port 1 Device", io_opts_1, device_type_names, num_io, selected_io_1, "io\0devices\0""1\0");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/systems.cfg	Sun Feb 16 10:33:20 2020 -0800
@@ -0,0 +1,80 @@
+md1va0 {
+	name Model 1 VA0
+	vram 64
+	vsram 40
+	zram 8
+	tas broken
+	z80_open_bus float
+	fm discrete 2612
+	tmss off
+}
+md1va3 {
+	name Model 1 VA3
+	vram 64
+	vsram 40
+	zram 8
+	tas broken
+	z80_open_bus FF
+	fm discrete 2612
+	tmss off
+}
+md1va6 {
+	name Model 1 VA6
+	vram 64
+	vsram 40
+	zram 8
+	tas broken
+	z80_open_bus FF
+	fm discrete 2612
+	tmss on
+}
+md2va1 {
+	name Model 2 VA1
+	vram 64
+	vsram 40
+	zram 8
+	tas broken
+	z80_open_bus FF
+	fm integrated 3834
+	tmss on
+}
+md2va2 {
+	name Model 2 VA2
+	vram 64
+	vsram 40
+	zram 8
+	tas broken
+	z80_open_bus FF
+	fm discrete 2612
+	tmss on
+}
+md3va1 {
+	name Model 3 VA1
+	vram 64
+	vsram 64
+	zram 8
+	tas broken
+	z80_open_bus FF
+	fm integrated 3834
+	tmss on
+}
+md3va2 {
+	name Model 3 VA2
+	vram 64
+	vsram 64
+	zram 8
+	tas works
+	z80_open_bus FF
+	fm discrete 2612
+	tmss on
+}
+teradrive {
+	name Teradrive
+	vram 128
+	vsram 40
+	zram 16
+	tas broken
+	z80_open_bus FF
+	fm discrete 3834
+	tmss off
+}
\ No newline at end of file