comparison render_sdl.c @ 1102:c15896605bf2

Clean up symbol visiblity and delete a ltitle bit of dead code
author Michael Pavone <pavone@retrodev.com>
date Mon, 28 Nov 2016 22:45:46 -0800
parents 1a66d5165ea7
children 22e87b739ad6
comparison
equal deleted inserted replaced
1101:e2d345e351b5 1102:c15896605bf2
16 #include <GL/glew.h> 16 #include <GL/glew.h>
17 #endif 17 #endif
18 18
19 #define MAX_EVENT_POLL_PER_FRAME 2 19 #define MAX_EVENT_POLL_PER_FRAME 2
20 20
21 SDL_Window *main_window; 21 static SDL_Window *main_window;
22 SDL_Renderer *main_renderer; 22 static SDL_Renderer *main_renderer;
23 SDL_Texture **sdl_textures; 23 static SDL_Texture **sdl_textures;
24 uint8_t num_textures; 24 static uint8_t num_textures;
25 SDL_Rect main_clip; 25 static SDL_Rect main_clip;
26 SDL_GLContext *main_context; 26 static SDL_GLContext *main_context;
27 27
28 int main_width, main_height, is_fullscreen; 28 static int main_width, main_height, is_fullscreen;
29 29
30 uint8_t render_dbg = 0; 30 static uint8_t render_gl = 1;
31 uint8_t debug_pal = 0; 31 static uint8_t scanlines = 0;
32 uint8_t render_gl = 1; 32
33 uint8_t scanlines = 0; 33 static uint32_t last_frame = 0;
34 34
35 uint32_t last_frame = 0; 35 static uint32_t min_delay;
36 36 static uint32_t frame_delay = 1000/60;
37 uint32_t min_delay; 37
38 uint32_t frame_delay = 1000/60; 38 static int16_t * current_psg = NULL;
39 39 static int16_t * current_ym = NULL;
40 int16_t * current_psg = NULL; 40
41 int16_t * current_ym = NULL; 41 static uint32_t buffer_samples, sample_rate;
42 42 static uint32_t missing_count;
43 uint32_t buffer_samples, sample_rate; 43
44 uint32_t missing_count; 44 static SDL_mutex * audio_mutex;
45 45 static SDL_cond * audio_ready;
46 SDL_mutex * audio_mutex; 46 static SDL_cond * psg_cond;
47 SDL_cond * audio_ready; 47 static SDL_cond * ym_cond;
48 SDL_cond * psg_cond; 48 static uint8_t quitting = 0;
49 SDL_cond * ym_cond; 49
50 uint8_t quitting = 0; 50 static void audio_callback(void * userdata, uint8_t *byte_stream, int len)
51
52 void audio_callback(void * userdata, uint8_t *byte_stream, int len)
53 { 51 {
54 //puts("audio_callback"); 52 //puts("audio_callback");
55 int16_t * stream = (int16_t *)byte_stream; 53 int16_t * stream = (int16_t *)byte_stream;
56 int samples = len/(sizeof(int16_t)*2); 54 int samples = len/(sizeof(int16_t)*2);
57 int16_t * psg_buf, * ym_buf; 55 int16_t * psg_buf, * ym_buf;
83 *(stream++) = psg_buf[i] + *(ym_buf++); 81 *(stream++) = psg_buf[i] + *(ym_buf++);
84 } 82 }
85 } 83 }
86 } 84 }
87 85
88 void render_close_audio() 86 static void render_close_audio()
89 { 87 {
90 SDL_LockMutex(audio_mutex); 88 SDL_LockMutex(audio_mutex);
91 quitting = 1; 89 quitting = 1;
92 SDL_CondSignal(audio_ready); 90 SDL_CondSignal(audio_ready);
93 SDL_UnlockMutex(audio_mutex); 91 SDL_UnlockMutex(audio_mutex);
115 { 113 {
116 return 255 << 24 | r << 16 | g << 8 | b; 114 return 255 << 24 | r << 16 | g << 8 | b;
117 } 115 }
118 116
119 #ifndef DISABLE_OPENGL 117 #ifndef DISABLE_OPENGL
120 GLuint textures[3], buffers[2], vshader, fshader, program, un_textures[2], un_width, at_pos; 118 static GLuint textures[3], buffers[2], vshader, fshader, program, un_textures[2], un_width, at_pos;
121 119
122 GLfloat vertex_data[] = { 120 static GLfloat vertex_data[] = {
123 -1.0f, -1.0f, 121 -1.0f, -1.0f,
124 1.0f, -1.0f, 122 1.0f, -1.0f,
125 -1.0f, 1.0f, 123 -1.0f, 1.0f,
126 1.0f, 1.0f 124 1.0f, 1.0f
127 }; 125 };
128 126
129 const GLushort element_data[] = {0, 1, 2, 3}; 127 static const GLushort element_data[] = {0, 1, 2, 3};
130 128
131 GLuint load_shader(char * fname, GLenum shader_type) 129 static GLuint load_shader(char * fname, GLenum shader_type)
132 { 130 {
133 char const * parts[] = {get_home_dir(), "/.config/blastem/shaders/", fname}; 131 char const * parts[] = {get_home_dir(), "/.config/blastem/shaders/", fname};
134 char * shader_path = alloc_concat_m(3, parts); 132 char * shader_path = alloc_concat_m(3, parts);
135 FILE * f = fopen(shader_path, "rb"); 133 FILE * f = fopen(shader_path, "rb");
136 free(shader_path); 134 free(shader_path);
169 } 167 }
170 return ret; 168 return ret;
171 } 169 }
172 #endif 170 #endif
173 171
174 uint32_t texture_buf[512 * 256]; 172 static uint32_t texture_buf[512 * 256];
175 void render_alloc_surfaces() 173 static void render_alloc_surfaces()
176 { 174 {
177 static uint8_t texture_init; 175 static uint8_t texture_init;
178 176
179 if (texture_init) { 177 if (texture_init) {
180 return; 178 return;
231 #ifndef DISABLE_OPENGL 229 #ifndef DISABLE_OPENGL
232 } 230 }
233 #endif 231 #endif
234 } 232 }
235 233
236 char * caption = NULL; 234 static char * caption = NULL;
237 char * fps_caption = NULL; 235 static char * fps_caption = NULL;
238 236
239 static void render_quit() 237 static void render_quit()
240 { 238 {
241 render_close_audio(); 239 render_close_audio();
242 for (int i = 0; i < num_textures; i++) 240 for (int i = 0; i < num_textures; i++)
566 return; 564 return;
567 } 565 }
568 } 566 }
569 } 567 }
570 568
571 void render_debug_mode(uint8_t mode) 569 static int find_joystick_index(SDL_JoystickID instanceID)
572 {
573 if (mode < 4) {
574 render_dbg = mode;
575 }
576 }
577
578 void render_debug_pal(uint8_t pal)
579 {
580 if (pal < 4) {
581 debug_pal = pal;
582 }
583 }
584
585 int find_joystick_index(SDL_JoystickID instanceID)
586 { 570 {
587 for (int i = 0; i < MAX_JOYSTICKS; i++) { 571 for (int i = 0; i < MAX_JOYSTICKS; i++) {
588 if (joysticks[i] && SDL_JoystickInstanceID(joysticks[i]) == instanceID) { 572 if (joysticks[i] && SDL_JoystickInstanceID(joysticks[i]) == instanceID) {
589 return i; 573 return i;
590 } 574 }
591 } 575 }
592 return -1; 576 return -1;
593 } 577 }
594 578
595 int lowest_unused_joystick_index() 579 static int lowest_unused_joystick_index()
596 { 580 {
597 for (int i = 0; i < MAX_JOYSTICKS; i++) { 581 for (int i = 0; i < MAX_JOYSTICKS; i++) {
598 if (!joysticks[i]) { 582 if (!joysticks[i]) {
599 return i; 583 return i;
600 } 584 }
601 } 585 }
602 return -1; 586 return -1;
603 } 587 }
604 588
605 uint8_t scancode_map[SDL_NUM_SCANCODES] = { 589 static uint8_t scancode_map[SDL_NUM_SCANCODES] = {
606 [SDL_SCANCODE_A] = 0x1C, 590 [SDL_SCANCODE_A] = 0x1C,
607 [SDL_SCANCODE_B] = 0x32, 591 [SDL_SCANCODE_B] = 0x32,
608 [SDL_SCANCODE_C] = 0x21, 592 [SDL_SCANCODE_C] = 0x21,
609 [SDL_SCANCODE_D] = 0x23, 593 [SDL_SCANCODE_D] = 0x23,
610 [SDL_SCANCODE_E] = 0x24, 594 [SDL_SCANCODE_E] = 0x24,
704 [SDL_SCANCODE_KP_9] = 0x7D, 688 [SDL_SCANCODE_KP_9] = 0x7D,
705 [SDL_SCANCODE_KP_0] = 0x70, 689 [SDL_SCANCODE_KP_0] = 0x70,
706 [SDL_SCANCODE_KP_PERIOD] = 0x71, 690 [SDL_SCANCODE_KP_PERIOD] = 0x71,
707 }; 691 };
708 692
709 int32_t handle_event(SDL_Event *event) 693 static int32_t handle_event(SDL_Event *event)
710 { 694 {
711 switch (event->type) { 695 switch (event->type) {
712 case SDL_KEYDOWN: 696 case SDL_KEYDOWN:
713 handle_keydown(event->key.keysym.sym, scancode_map[event->key.keysym.scancode]); 697 handle_keydown(event->key.keysym.sym, scancode_map[event->key.keysym.scancode]);
714 break; 698 break;
803 context->back_buffer = current_ym; 787 context->back_buffer = current_ym;
804 SDL_UnlockMutex(audio_mutex); 788 SDL_UnlockMutex(audio_mutex);
805 context->buffer_pos = 0; 789 context->buffer_pos = 0;
806 } 790 }
807 791
808 void render_fps(uint32_t fps)
809 {
810 frame_delay = 1000/fps;
811 }
812
813 uint32_t render_audio_buffer() 792 uint32_t render_audio_buffer()
814 { 793 {
815 return buffer_samples; 794 return buffer_samples;
816 } 795 }
817 796