diff --git a/src/devices/system.c b/src/devices/system.c index 9cecf53..ac25b82 100644 --- a/src/devices/system.c +++ b/src/devices/system.c @@ -1,4 +1,5 @@ #include +#include #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 index a5d66be..5793b66 100644 --- 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 index 4a55c18..ca6ae0f 100644 --- 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,