summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2019-03-20 22:05:27 -0700
committerMichael Pavone <pavone@retrodev.com>2019-03-20 22:05:27 -0700
commita460f11a88ad30ff938327428e53319518cfdce4 (patch)
treea365deab30cc5903587af0f661470b605fa0fb9a
parentf328cd509d79f1b468b32bab0fbfd214705534d7 (diff)
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
-rw-r--r--gdb_remote.c2
-rw-r--r--io.c10
-rwxr-xr-xrender_sdl.c33
-rw-r--r--romdb.c10
-rw-r--r--util.c23
-rw-r--r--util.h4
6 files changed, 53 insertions, 29 deletions
diff --git a/gdb_remote.c b/gdb_remote.c
index 173e2bc..92fdfcf 100644
--- a/gdb_remote.c
+++ b/gdb_remote.c
@@ -596,5 +596,7 @@ void gdb_remote_init(void)
fatal_error("accept returned an error while listening on GDB remote debugging socket");
}
closesocket(listen_sock);
+#else
+ disable_stdout_messages();
#endif
}
diff --git a/io.c b/io.c
index 2a3a03e..273c50d 100644
--- a/io.c
+++ b/io.c
@@ -335,7 +335,7 @@ void setup_io_devices(tern_node * config, rom_info *rom, sega_io *io)
warning("IO port %s is configured to use the sega parallel board, but no paralell_pipe is set!\n", io_name(i));
ports[i].device_type = IO_NONE;
} else {
- printf("IO port: %s connected to device '%s' with pipe name: %s\n", io_name(i), device_type_names[ports[i].device_type], pipe_name);
+ debug_message("IO port: %s connected to device '%s' with pipe name: %s\n", io_name(i), device_type_names[ports[i].device_type], pipe_name);
if (!strcmp("stdin", pipe_name))
{
ports[i].device.stream.data_fd = STDIN_FILENO;
@@ -361,7 +361,7 @@ void setup_io_devices(tern_node * config, rom_info *rom, sega_io *io)
warning("IO port %s is configured to use generic IO, but no socket is set!\n", io_name(i));
ports[i].device_type = IO_NONE;
} else {
- printf("IO port: %s connected to device '%s' with socket name: %s\n", io_name(i), device_type_names[ports[i].device_type], sock_name);
+ debug_message("IO port: %s connected to device '%s' with socket name: %s\n", io_name(i), device_type_names[ports[i].device_type], sock_name);
ports[i].device.stream.data_fd = -1;
ports[i].device.stream.listen_fd = socket(AF_UNIX, SOCK_STREAM, 0);
size_t pathlen = strlen(sock_name);
@@ -391,9 +391,9 @@ cleanup_sock:
} else
#endif
if (ports[i].device_type == IO_GAMEPAD3 || ports[i].device_type == IO_GAMEPAD6 || ports[i].device_type == IO_GAMEPAD2) {
- printf("IO port %s connected to gamepad #%d with type '%s'\n", io_name(i), ports[i].device.pad.gamepad_num, device_type_names[ports[i].device_type]);
+ debug_message("IO port %s connected to gamepad #%d with type '%s'\n", io_name(i), ports[i].device.pad.gamepad_num, device_type_names[ports[i].device_type]);
} else {
- printf("IO port %s connected to device '%s'\n", io_name(i), device_type_names[ports[i].device_type]);
+ debug_message("IO port %s connected to device '%s'\n", io_name(i), device_type_names[ports[i].device_type]);
}
}
}
@@ -471,7 +471,7 @@ static void wait_for_connection(io_port * port)
{
if (port->device.stream.data_fd == -1)
{
- puts("Waiting for socket connection...");
+ debug_message("Waiting for socket connection...");
port->device.stream.data_fd = accept(port->device.stream.listen_fd, NULL, NULL);
fcntl(port->device.stream.data_fd, F_SETFL, O_NONBLOCK | O_RDWR);
}
diff --git a/render_sdl.c b/render_sdl.c
index 2f5bfcd..30894b1 100755
--- a/render_sdl.c
+++ b/render_sdl.c
@@ -112,13 +112,12 @@ static int32_t mix_s16(audio_source *audio, void *vstream, int len)
}
if (cur != end) {
- printf("Underflow of %d samples, read_start: %d, read_end: %d, mask: %X\n", (int)(end-cur)/2, audio->read_start, audio->read_end, audio->mask);
+ debug_message("Underflow of %d samples, read_start: %d, read_end: %d, mask: %X\n", (int)(end-cur)/2, audio->read_start, audio->read_end, audio->mask);
}
if (!sync_to_audio) {
audio->read_start = i;
}
if (cur != end) {
- //printf("Underflow of %d samples, read_start: %d, read_end: %d, mask: %X\n", (int)(end-cur)/2, audio->read_start, audio->read_end, audio->mask);
return (cur-end)/2;
} else {
return ((i_end - i) & audio->mask) / audio->num_channels;
@@ -158,7 +157,7 @@ static int32_t mix_f32(audio_source *audio, void *vstream, int len)
audio->read_start = i;
}
if (cur != end) {
- printf("Underflow of %d samples, read_start: %d, read_end: %d, mask: %X\n", (int)(end-cur)/2, audio->read_start, audio->read_end, audio->mask);
+ debug_message("Underflow of %d samples, read_start: %d, read_end: %d, mask: %X\n", (int)(end-cur)/2, audio->read_start, audio->read_end, audio->mask);
return (cur-end)/2;
} else {
return ((i_end - i) & audio->mask) / audio->num_channels;
@@ -922,8 +921,8 @@ static int32_t handle_event(SDL_Event *event)
SDL_Joystick * joy = joysticks[index] = SDL_JoystickOpen(event->jdevice.which);
joystick_sdl_index[index] = event->jdevice.which;
if (joy) {
- printf("Joystick %d added: %s\n", index, SDL_JoystickName(joy));
- printf("\tNum Axes: %d\n\tNum Buttons: %d\n\tNum Hats: %d\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy));
+ debug_message("Joystick %d added: %s\n", index, SDL_JoystickName(joy));
+ debug_message("\tNum Axes: %d\n\tNum Buttons: %d\n\tNum Hats: %d\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy));
handle_joy_added(index);
}
}
@@ -934,9 +933,9 @@ static int32_t handle_event(SDL_Event *event)
if (index >= 0) {
SDL_JoystickClose(joysticks[index]);
joysticks[index] = NULL;
- printf("Joystick %d removed\n", index);
+ debug_message("Joystick %d removed\n", index);
} else {
- printf("Failed to find removed joystick with instance ID: %d\n", index);
+ debug_message("Failed to find removed joystick with instance ID: %d\n", index);
}
break;
}
@@ -1033,7 +1032,7 @@ static void init_audio()
if (!samples) {
samples = 512;
}
- printf("config says: %d\n", samples);
+ debug_message("config says: %d\n", samples);
desired.samples = samples*2;
desired.callback = sync_to_audio ? audio_callback : audio_callback_drc;
desired.userdata = NULL;
@@ -1044,15 +1043,15 @@ static void init_audio()
buffer_samples = actual.samples;
sample_rate = actual.freq;
output_channels = actual.channels;
- printf("Initialized audio at frequency %d with a %d sample buffer, ", actual.freq, actual.samples);
+ debug_message("Initialized audio at frequency %d with a %d sample buffer, ", actual.freq, actual.samples);
if (actual.format == AUDIO_S16SYS) {
- puts("signed 16-bit int format");
+ debug_message("signed 16-bit int format");
mix = mix_s16;
} else if (actual.format == AUDIO_F32SYS) {
- puts("32-bit float format");
+ debug_message("32-bit float format");
mix = mix_f32;
} else {
- printf("unsupported format %X\n", actual.format);
+ debug_message("unsupported format %X\n", actual.format);
warning("Unsupported audio sample format: %X\n", actual.format);
mix = mix_null;
}
@@ -1174,7 +1173,7 @@ void window_setup(void)
}
SDL_RendererInfo rinfo;
SDL_GetRendererInfo(main_renderer, &rinfo);
- printf("SDL2 Render Driver: %s\n", rinfo.name);
+ debug_message("SDL2 Render Driver: %s\n", rinfo.name);
main_clip.x = main_clip.y = 0;
main_clip.w = main_width;
main_clip.h = main_height;
@@ -1183,7 +1182,7 @@ void window_setup(void)
#endif
SDL_GetWindowSize(main_window, &main_width, &main_height);
- printf("Window created with size: %d x %d\n", main_width, main_height);
+ debug_message("Window created with size: %d x %d\n", main_width, main_height);
update_aspect();
render_alloc_surfaces();
def.ptrval = "off";
@@ -1200,7 +1199,7 @@ void render_init(int width, int height, char * title, uint8_t fullscreen)
float aspect = config_aspect() > 0.0f ? config_aspect() : 4.0f/3.0f;
height = ((float)width / aspect) + 0.5f;
}
- printf("width: %d, height: %d\n", width, height);
+ debug_message("width: %d, height: %d\n", width, height);
windowed_width = width;
windowed_height = height;
@@ -1233,7 +1232,7 @@ void render_init(int width, int height, char * title, uint8_t fullscreen)
if (db_data) {
int added = SDL_GameControllerAddMappingsFromRW(SDL_RWFromMem(db_data, db_size), 1);
free(db_data);
- printf("Added %d game controller mappings from gamecontrollerdb.txt\n", added);
+ debug_message("Added %d game controller mappings from gamecontrollerdb.txt\n", added);
}
controller_add_mappings();
@@ -1386,7 +1385,7 @@ void render_set_video_standard(vid_std std)
max_repeat++;
min_buffered = (((float)max_repeat * (float)sample_rate/(float)source_hz)/* / (float)buffer_samples*/);// + 0.9999;
//min_buffered *= buffer_samples;
- printf("Min samples buffered before audio start: %d\n", min_buffered);
+ debug_message("Min samples buffered before audio start: %d\n", min_buffered);
max_adjust = BASE_MAX_ADJUST / source_hz;
}
diff --git a/romdb.c b/romdb.c
index 6300f98..b55e560 100644
--- a/romdb.c
+++ b/romdb.c
@@ -560,7 +560,7 @@ void add_eeprom_map(tern_node *node, uint32_t start, uint32_t end, map_iter_stat
if (bits_write) {
tern_foreach(bits_write, eeprom_write_fun, eep_map);
}
- printf("EEPROM address %X: sda read: %X, sda write: %X, scl: %X\n", start, eep_map->sda_read_bit, eep_map->sda_write_mask, eep_map->scl_mask);
+ debug_message("EEPROM address %X: sda read: %X, sda write: %X, scl: %X\n", start, eep_map->sda_read_bit, eep_map->sda_write_mask, eep_map->scl_mask);
state->info->num_eeprom++;
}
@@ -847,18 +847,18 @@ rom_info configure_rom(tern_node *rom_db, void *vrom, uint32_t rom_size, void *l
product_id[i] = rom[GAME_ID_OFF + i];
}
- printf("Product ID: %s\n", product_id);
+ debug_message("Product ID: %s\n", product_id);
uint8_t raw_hash[20];
sha1(vrom, rom_size, raw_hash);
uint8_t hex_hash[41];
bin_to_hex(hex_hash, raw_hash, 20);
- printf("SHA1: %s\n", hex_hash);
+ debug_message("SHA1: %s\n", hex_hash);
tern_node * entry = tern_find_node(rom_db, hex_hash);
if (!entry) {
entry = tern_find_node(rom_db, product_id);
}
if (!entry) {
- puts("Not found in ROM DB, examining header\n");
+ debug_message("Not found in ROM DB, examining header\n");
if (xband_detect(rom, rom_size)) {
return xband_configure_rom(rom_db, rom, rom_size, lock_on, lock_on_size, base_map, base_chunks);
}
@@ -871,7 +871,7 @@ rom_info configure_rom(tern_node *rom_db, void *vrom, uint32_t rom_size, void *l
info.mapper_type = MAPPER_NONE;
info.name = tern_find_ptr(entry, "name");
if (info.name) {
- printf("Found name: %s\n", info.name);
+ debug_message("Found name: %s\n", info.name);
info.name = strdup(info.name);
} else {
info.name = get_header_name(rom);
diff --git a/util.c b/util.c
index 88a6d4f..26dfc9c 100644
--- a/util.c
+++ b/util.c
@@ -477,13 +477,16 @@ void warning(char *format, ...)
va_end(args);
}
+static uint8_t output_enabled = 1;
void info_message(char *format, ...)
{
va_list args;
va_start(args, format);
#ifndef _WIN32
if (headless || (isatty(STDOUT_FILENO) && isatty(STDIN_FILENO))) {
- info_printf(format, args);
+ if (output_enabled) {
+ info_printf(format, args);
+ }
} else {
#endif
int32_t size = strlen(format) * 2;
@@ -503,7 +506,9 @@ void info_message(char *format, ...)
va_start(args, format);
vsnprintf(buf, actual, format, args);
}
- info_puts(buf);
+ if (output_enabled) {
+ info_puts(buf);
+ }
render_infobox("BlastEm Info", buf);
free(buf);
#ifndef _WIN32
@@ -512,6 +517,20 @@ void info_message(char *format, ...)
va_end(args);
}
+void debug_message(char *format, ...)
+{
+ va_list args;
+ va_start(args, format);
+ if (output_enabled) {
+ info_printf(format, args);
+ }
+}
+
+void disable_stdout_messages(void)
+{
+ output_enabled = 0;
+}
+
#ifdef _WIN32
#include <windows.h>
#include <shlobj.h>
diff --git a/util.h b/util.h
index 1b4c600..a32de10 100644
--- a/util.h
+++ b/util.h
@@ -84,5 +84,9 @@ void fatal_error(char *format, ...);
void info_message(char *format, ...);
//Prints an information message to stderr and to a message box if not in headless mode and not attached to a console
void warning(char *format, ...);
+//Prints a debug message to stdout
+void debug_message(char *format, ...);
+//Disables output of info and debug messages to stdout
+void disable_stdout_messages(void);
#endif //UTIL_H_