diff --git a/Core/debugger.c b/Core/debugger.c index 0f08fb1..2240e0b 100644 --- a/Core/debugger.c +++ b/Core/debugger.c @@ -2175,6 +2175,29 @@ void GB_debugger_add_symbol(GB_gameboy_t *gb, uint16_t bank, uint16_t address, c } } +void GB_debugger_load_symbol_file_from_buffer(GB_gameboy_t *gb, const char *buffer, size_t size) +{ + const char *str_ptr = buffer; + unsigned length = 0; + + while (str_ptr && size--) { + length++; + char c = (char) *str_ptr++; + + if (c == '\n' || size == 0) { + const char *line = str_ptr - length--; + unsigned bank, address; + char symbol[length]; + + if (sscanf(line, "%x:%x %s", &bank, &address, symbol) == 3) { + GB_debugger_add_symbol(gb, bank, address, symbol); + } + + length = 0; + } + } +} + void GB_debugger_load_symbol_file(GB_gameboy_t *gb, const char *path) { FILE *f = fopen(path, "r"); diff --git a/Core/debugger.h b/Core/debugger.h index b6a12d9..645a706 100644 --- a/Core/debugger.h +++ b/Core/debugger.h @@ -35,7 +35,7 @@ void #endif GB_debugger_execute_command(GB_gameboy_t *gb, char *input); /* Destroys input. */ - +void GB_debugger_load_symbol_file_from_buffer(GB_gameboy_t *gb, const char *buffer, size_t size); void GB_debugger_load_symbol_file(GB_gameboy_t *gb, const char *path); const char *GB_debugger_name_for_address(GB_gameboy_t *gb, uint16_t addr); bool GB_debugger_evaluate(GB_gameboy_t *gb, const char *string, uint16_t *result, uint16_t *result_bank); /* result_bank is -1 if unused. */ diff --git a/gtk3/main.c b/gtk3/main.c index 5e0d139..21a9c55 100644 --- a/gtk3/main.c +++ b/gtk3/main.c @@ -7,8 +7,6 @@ #include #include -// TODO: right now we need access to GB_debugger_add_symbol -#define GB_INTERNAL #include #include "settings.h" @@ -1292,35 +1290,13 @@ static void reset(void) { GB_load_battery(&gb, gui_data.battery_save_path); GB_load_cheats(&gb, gui_data.cheats_save_path); - // TODO: Implement without GB_INTERNAL - /* GB_debugger_load_symbol_file */ { - GError *error = NULL; - GInputStream *stream = g_resources_open_stream(RESOURCE_PREFIX "Misc/registers.sym", G_RESOURCE_LOOKUP_FLAGS_NONE, &error); - GDataInputStream *input_stream = g_data_input_stream_new(stream); - - char *line = NULL; - gsize length = 0; - - while ((line = g_data_input_stream_read_line_utf8(input_stream, &length, NULL, &error))) { - // skip comments - for (unsigned i = 0; i < length; i++) { - if (line[i] == ';') { - line[i] = 0; - length = i; - break; - } - } - if (length == 0) continue; - - unsigned bank, address; - char symbol[length]; - - if (sscanf(line, "%x:%x %s", &bank, &address, symbol) == 3) { - GB_debugger_add_symbol(&gb, bank, address, symbol); - } - } - - g_object_unref(stream); + GError *error = NULL; + GBytes *register_sym_f = g_resources_lookup_data(RESOURCE_PREFIX "Misc/registers.sym", G_RESOURCE_LOOKUP_FLAGS_NONE, &error); + if (register_sym_f) { + gsize register_sym_size; + const gchar *register_sym_data = g_bytes_get_data(register_sym_f, ®ister_sym_size); + GB_debugger_load_symbol_file_from_buffer(&gb, register_sym_data, register_sym_size); + g_bytes_unref(register_sym_f); } size_t path_length = strlen(path);