uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit d6e064745fc86ac9e64f49ae94136e8752ba8656
parent 7853a988da736ee220c1bfef87c54903552c25fa
Author: Aleksandr Pasechnik <al@megamicron.net>
Date:   Tue,  1 Jul 2025 19:31:01 -0400

set window title to the rom name if we can

This is my attempt to read metadata and use it to set the title of the window.
I am definitely not experienced in C, so please let me know if there is a
better way to deal with buffers, strings, and the metadata data.

There might be some opportunity to extract more metadata than just the first
line and use that for other parts of the app. If there's a better data
structure that we should use here, let me know!

For example, there may be some way to turn an icon defined in the metadata into
an application icon. Actually making and setting the icon is probably out of
scope (does SDL2 even give us that sort of API?) but we might set ourselves up
for success by reading more of the metadata now.

Diffstat:
Msrc/devices/system.c | 30++++++++++++++++++++++++++++++
Msrc/devices/system.h | 1+
Msrc/uxnemu.c | 8+++++++-
3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/src/devices/system.c b/src/devices/system.c @@ -1,4 +1,5 @@ #include <stdio.h> +#include <string.h> #include "../uxn.h" #include "system.h" @@ -15,6 +16,11 @@ WITH REGARD TO THIS SOFTWARE. */ char *boot_path; +Uint16 metadata_addr; + +#define METADATA_LEN 256 +/* allocate one more to ensure a null terminator */ +char metadata_buffer[METADATA_LEN + 1]; static void system_print(char *name, Stack *s) @@ -98,6 +104,27 @@ system_expansion(const Uint16 exp) fprintf(stderr, "Unknown command: %s\n", &uxn.ram[exp]); } +char *metadata_read_name() { + int i; + + if (metadata_addr == 0) + /* we probably do not have any metadata */ + return metadata_buffer; + + if (uxn.ram[metadata_addr] != 0x00) + /* metadata should start with a 0 */ + return metadata_buffer; + + for (i = 1; i < METADATA_LEN; i++) { + char c = uxn.ram[metadata_addr + i]; + if (c == 0x00 || c == 0x0a) + break; + + metadata_buffer[i-1] = c; + } + return metadata_buffer; +} + /* IO */ Uint8 @@ -124,6 +151,9 @@ system_deo(Uint8 port) case 0x5: uxn.rst.ptr = uxn.dev[5]; break; + case 0x7: + metadata_addr = PEEK2(&uxn.dev[0x6]); + break; case 0xe: system_print("WST", &uxn.wst); system_print("RST", &uxn.rst); diff --git a/src/devices/system.h b/src/devices/system.h @@ -15,6 +15,7 @@ WITH REGARD TO THIS SOFTWARE. int system_error(char *msg, const char *err); int system_boot(Uint8 *ram, char *rom_path, int has_args); int system_reboot(int soft); +char *metadata_read_name(); Uint8 system_dei(Uint8 addr); void system_deo(Uint8 addr); diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -426,7 +426,13 @@ emu_run(char *rom_path) window_created = 1; if(fullscreen) window_flags = window_flags | SDL_WINDOW_FULLSCREEN_DESKTOP; - emu_window = SDL_CreateWindow(rom_path, + + char *window_name = rom_path; + char *rom_name = metadata_read_name(); + if (strlen(rom_name)) + window_name = rom_name; + + emu_window = SDL_CreateWindow(rom_name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, uxn_screen.width * zoom,