Mercurial > repos > blastem
comparison render_sdl.c @ 1792:52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 20 Mar 2019 22:05:27 -0700 |
parents | ba3fb7a3be6b |
children | 51417bb557b6 |
comparison
equal
deleted
inserted
replaced
1791:1843823f1e9b | 1792:52a47611a273 |
---|---|
110 i &= audio->mask; | 110 i &= audio->mask; |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 if (cur != end) { | 114 if (cur != end) { |
115 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); | 115 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); |
116 } | 116 } |
117 if (!sync_to_audio) { | 117 if (!sync_to_audio) { |
118 audio->read_start = i; | 118 audio->read_start = i; |
119 } | 119 } |
120 if (cur != end) { | 120 if (cur != end) { |
121 //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); | |
122 return (cur-end)/2; | 121 return (cur-end)/2; |
123 } else { | 122 } else { |
124 return ((i_end - i) & audio->mask) / audio->num_channels; | 123 return ((i_end - i) & audio->mask) / audio->num_channels; |
125 } | 124 } |
126 } | 125 } |
156 } | 155 } |
157 if (!sync_to_audio) { | 156 if (!sync_to_audio) { |
158 audio->read_start = i; | 157 audio->read_start = i; |
159 } | 158 } |
160 if (cur != end) { | 159 if (cur != end) { |
161 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); | 160 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); |
162 return (cur-end)/2; | 161 return (cur-end)/2; |
163 } else { | 162 } else { |
164 return ((i_end - i) & audio->mask) / audio->num_channels; | 163 return ((i_end - i) & audio->mask) / audio->num_channels; |
165 } | 164 } |
166 } | 165 } |
920 int index = lowest_unused_joystick_index(); | 919 int index = lowest_unused_joystick_index(); |
921 if (index >= 0) { | 920 if (index >= 0) { |
922 SDL_Joystick * joy = joysticks[index] = SDL_JoystickOpen(event->jdevice.which); | 921 SDL_Joystick * joy = joysticks[index] = SDL_JoystickOpen(event->jdevice.which); |
923 joystick_sdl_index[index] = event->jdevice.which; | 922 joystick_sdl_index[index] = event->jdevice.which; |
924 if (joy) { | 923 if (joy) { |
925 printf("Joystick %d added: %s\n", index, SDL_JoystickName(joy)); | 924 debug_message("Joystick %d added: %s\n", index, SDL_JoystickName(joy)); |
926 printf("\tNum Axes: %d\n\tNum Buttons: %d\n\tNum Hats: %d\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy)); | 925 debug_message("\tNum Axes: %d\n\tNum Buttons: %d\n\tNum Hats: %d\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy)); |
927 handle_joy_added(index); | 926 handle_joy_added(index); |
928 } | 927 } |
929 } | 928 } |
930 } | 929 } |
931 break; | 930 break; |
932 case SDL_JOYDEVICEREMOVED: { | 931 case SDL_JOYDEVICEREMOVED: { |
933 int index = find_joystick_index(event->jdevice.which); | 932 int index = find_joystick_index(event->jdevice.which); |
934 if (index >= 0) { | 933 if (index >= 0) { |
935 SDL_JoystickClose(joysticks[index]); | 934 SDL_JoystickClose(joysticks[index]); |
936 joysticks[index] = NULL; | 935 joysticks[index] = NULL; |
937 printf("Joystick %d removed\n", index); | 936 debug_message("Joystick %d removed\n", index); |
938 } else { | 937 } else { |
939 printf("Failed to find removed joystick with instance ID: %d\n", index); | 938 debug_message("Failed to find removed joystick with instance ID: %d\n", index); |
940 } | 939 } |
941 break; | 940 break; |
942 } | 941 } |
943 case SDL_MOUSEMOTION: | 942 case SDL_MOUSEMOTION: |
944 handle_mouse_moved(event->motion.which, event->motion.x, event->motion.y + overscan_top[video_standard], event->motion.xrel, event->motion.yrel); | 943 handle_mouse_moved(event->motion.which, event->motion.x, event->motion.y + overscan_top[video_standard], event->motion.xrel, event->motion.yrel); |
1031 char * samples_str = tern_find_path(config, "audio\0buffer\0", TVAL_PTR).ptrval; | 1030 char * samples_str = tern_find_path(config, "audio\0buffer\0", TVAL_PTR).ptrval; |
1032 int samples = samples_str ? atoi(samples_str) : 0; | 1031 int samples = samples_str ? atoi(samples_str) : 0; |
1033 if (!samples) { | 1032 if (!samples) { |
1034 samples = 512; | 1033 samples = 512; |
1035 } | 1034 } |
1036 printf("config says: %d\n", samples); | 1035 debug_message("config says: %d\n", samples); |
1037 desired.samples = samples*2; | 1036 desired.samples = samples*2; |
1038 desired.callback = sync_to_audio ? audio_callback : audio_callback_drc; | 1037 desired.callback = sync_to_audio ? audio_callback : audio_callback_drc; |
1039 desired.userdata = NULL; | 1038 desired.userdata = NULL; |
1040 | 1039 |
1041 if (SDL_OpenAudio(&desired, &actual) < 0) { | 1040 if (SDL_OpenAudio(&desired, &actual) < 0) { |
1042 fatal_error("Unable to open SDL audio: %s\n", SDL_GetError()); | 1041 fatal_error("Unable to open SDL audio: %s\n", SDL_GetError()); |
1043 } | 1042 } |
1044 buffer_samples = actual.samples; | 1043 buffer_samples = actual.samples; |
1045 sample_rate = actual.freq; | 1044 sample_rate = actual.freq; |
1046 output_channels = actual.channels; | 1045 output_channels = actual.channels; |
1047 printf("Initialized audio at frequency %d with a %d sample buffer, ", actual.freq, actual.samples); | 1046 debug_message("Initialized audio at frequency %d with a %d sample buffer, ", actual.freq, actual.samples); |
1048 if (actual.format == AUDIO_S16SYS) { | 1047 if (actual.format == AUDIO_S16SYS) { |
1049 puts("signed 16-bit int format"); | 1048 debug_message("signed 16-bit int format"); |
1050 mix = mix_s16; | 1049 mix = mix_s16; |
1051 } else if (actual.format == AUDIO_F32SYS) { | 1050 } else if (actual.format == AUDIO_F32SYS) { |
1052 puts("32-bit float format"); | 1051 debug_message("32-bit float format"); |
1053 mix = mix_f32; | 1052 mix = mix_f32; |
1054 } else { | 1053 } else { |
1055 printf("unsupported format %X\n", actual.format); | 1054 debug_message("unsupported format %X\n", actual.format); |
1056 warning("Unsupported audio sample format: %X\n", actual.format); | 1055 warning("Unsupported audio sample format: %X\n", actual.format); |
1057 mix = mix_null; | 1056 mix = mix_null; |
1058 } | 1057 } |
1059 } | 1058 } |
1060 | 1059 |
1172 if (!main_renderer) { | 1171 if (!main_renderer) { |
1173 fatal_error("unable to create SDL renderer: %s\n", SDL_GetError()); | 1172 fatal_error("unable to create SDL renderer: %s\n", SDL_GetError()); |
1174 } | 1173 } |
1175 SDL_RendererInfo rinfo; | 1174 SDL_RendererInfo rinfo; |
1176 SDL_GetRendererInfo(main_renderer, &rinfo); | 1175 SDL_GetRendererInfo(main_renderer, &rinfo); |
1177 printf("SDL2 Render Driver: %s\n", rinfo.name); | 1176 debug_message("SDL2 Render Driver: %s\n", rinfo.name); |
1178 main_clip.x = main_clip.y = 0; | 1177 main_clip.x = main_clip.y = 0; |
1179 main_clip.w = main_width; | 1178 main_clip.w = main_width; |
1180 main_clip.h = main_height; | 1179 main_clip.h = main_height; |
1181 #ifndef DISABLE_OPENGL | 1180 #ifndef DISABLE_OPENGL |
1182 } | 1181 } |
1183 #endif | 1182 #endif |
1184 | 1183 |
1185 SDL_GetWindowSize(main_window, &main_width, &main_height); | 1184 SDL_GetWindowSize(main_window, &main_width, &main_height); |
1186 printf("Window created with size: %d x %d\n", main_width, main_height); | 1185 debug_message("Window created with size: %d x %d\n", main_width, main_height); |
1187 update_aspect(); | 1186 update_aspect(); |
1188 render_alloc_surfaces(); | 1187 render_alloc_surfaces(); |
1189 def.ptrval = "off"; | 1188 def.ptrval = "off"; |
1190 scanlines = !strcmp(tern_find_path_default(config, "video\0scanlines\0", def, TVAL_PTR).ptrval, "on"); | 1189 scanlines = !strcmp(tern_find_path_default(config, "video\0scanlines\0", def, TVAL_PTR).ptrval, "on"); |
1191 } | 1190 } |
1198 atexit(SDL_Quit); | 1197 atexit(SDL_Quit); |
1199 if (height <= 0) { | 1198 if (height <= 0) { |
1200 float aspect = config_aspect() > 0.0f ? config_aspect() : 4.0f/3.0f; | 1199 float aspect = config_aspect() > 0.0f ? config_aspect() : 4.0f/3.0f; |
1201 height = ((float)width / aspect) + 0.5f; | 1200 height = ((float)width / aspect) + 0.5f; |
1202 } | 1201 } |
1203 printf("width: %d, height: %d\n", width, height); | 1202 debug_message("width: %d, height: %d\n", width, height); |
1204 windowed_width = width; | 1203 windowed_width = width; |
1205 windowed_height = height; | 1204 windowed_height = height; |
1206 | 1205 |
1207 SDL_DisplayMode mode; | 1206 SDL_DisplayMode mode; |
1208 //TODO: Explicit multiple monitor support | 1207 //TODO: Explicit multiple monitor support |
1231 uint32_t db_size; | 1230 uint32_t db_size; |
1232 char *db_data = read_bundled_file("gamecontrollerdb.txt", &db_size); | 1231 char *db_data = read_bundled_file("gamecontrollerdb.txt", &db_size); |
1233 if (db_data) { | 1232 if (db_data) { |
1234 int added = SDL_GameControllerAddMappingsFromRW(SDL_RWFromMem(db_data, db_size), 1); | 1233 int added = SDL_GameControllerAddMappingsFromRW(SDL_RWFromMem(db_data, db_size), 1); |
1235 free(db_data); | 1234 free(db_data); |
1236 printf("Added %d game controller mappings from gamecontrollerdb.txt\n", added); | 1235 debug_message("Added %d game controller mappings from gamecontrollerdb.txt\n", added); |
1237 } | 1236 } |
1238 | 1237 |
1239 controller_add_mappings(); | 1238 controller_add_mappings(); |
1240 | 1239 |
1241 SDL_JoystickEventState(SDL_ENABLE); | 1240 SDL_JoystickEventState(SDL_ENABLE); |
1384 //sync samples with audio thread approximately every 8 lines | 1383 //sync samples with audio thread approximately every 8 lines |
1385 sync_samples = sync_to_audio ? buffer_samples : 8 * sample_rate / (source_hz * (std == VID_PAL ? 313 : 262)); | 1384 sync_samples = sync_to_audio ? buffer_samples : 8 * sample_rate / (source_hz * (std == VID_PAL ? 313 : 262)); |
1386 max_repeat++; | 1385 max_repeat++; |
1387 min_buffered = (((float)max_repeat * (float)sample_rate/(float)source_hz)/* / (float)buffer_samples*/);// + 0.9999; | 1386 min_buffered = (((float)max_repeat * (float)sample_rate/(float)source_hz)/* / (float)buffer_samples*/);// + 0.9999; |
1388 //min_buffered *= buffer_samples; | 1387 //min_buffered *= buffer_samples; |
1389 printf("Min samples buffered before audio start: %d\n", min_buffered); | 1388 debug_message("Min samples buffered before audio start: %d\n", min_buffered); |
1390 max_adjust = BASE_MAX_ADJUST / source_hz; | 1389 max_adjust = BASE_MAX_ADJUST / source_hz; |
1391 } | 1390 } |
1392 | 1391 |
1393 void render_update_caption(char *title) | 1392 void render_update_caption(char *title) |
1394 { | 1393 { |