[GTK3] Add GB_debugger_load_symbol_file_from_buffer

Now we don’t have to rely on GB_INTERNAL anymore.
This commit is contained in:
Maximilian Mader 2020-04-30 21:45:46 +02:00
parent 6594edf1bf
commit 4ac7c0dd0d
Signed by: Max
GPG Key ID: F71D56A3151C4FB3
3 changed files with 31 additions and 32 deletions

View File

@ -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) void GB_debugger_load_symbol_file(GB_gameboy_t *gb, const char *path)
{ {
FILE *f = fopen(path, "r"); FILE *f = fopen(path, "r");

View File

@ -35,7 +35,7 @@ void
#endif #endif
GB_debugger_execute_command(GB_gameboy_t *gb, char *input); /* Destroys input. */ 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); 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); 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. */ bool GB_debugger_evaluate(GB_gameboy_t *gb, const char *string, uint16_t *result, uint16_t *result_bank); /* result_bank is -1 if unused. */

View File

@ -7,8 +7,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
// TODO: right now we need access to GB_debugger_add_symbol
#define GB_INTERNAL
#include <Core/gb.h> #include <Core/gb.h>
#include "settings.h" #include "settings.h"
@ -1292,35 +1290,13 @@ static void reset(void) {
GB_load_battery(&gb, gui_data.battery_save_path); GB_load_battery(&gb, gui_data.battery_save_path);
GB_load_cheats(&gb, gui_data.cheats_save_path); GB_load_cheats(&gb, gui_data.cheats_save_path);
// TODO: Implement without GB_INTERNAL GError *error = NULL;
/* GB_debugger_load_symbol_file */ { GBytes *register_sym_f = g_resources_lookup_data(RESOURCE_PREFIX "Misc/registers.sym", G_RESOURCE_LOOKUP_FLAGS_NONE, &error);
GError *error = NULL; if (register_sym_f) {
GInputStream *stream = g_resources_open_stream(RESOURCE_PREFIX "Misc/registers.sym", G_RESOURCE_LOOKUP_FLAGS_NONE, &error); gsize register_sym_size;
GDataInputStream *input_stream = g_data_input_stream_new(stream); const gchar *register_sym_data = g_bytes_get_data(register_sym_f, &register_sym_size);
GB_debugger_load_symbol_file_from_buffer(&gb, register_sym_data, register_sym_size);
char *line = NULL; g_bytes_unref(register_sym_f);
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);
} }
size_t path_length = strlen(path); size_t path_length = strlen(path);