Tscope5
system_internal.c
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // __ ______
4 // / /_______________ ____ ___ / ____/
5 // / __/ ___/ ___/ __ \/ __ \/ _ \ /___ )
6 // / /_(__ ) /__/ /_/ / /_/ / __/ ____/ /
7 // \__/____/\___/\____/ .___/\___/ /_____/
8 // /_/
9 //
10 /// \file system_internal.c
11 /// Definitions of internal system functions
12 ////////////////////////////////////////////////////////////////////////////////
13 
14 #include "../include/tscope5/system.h"
15 #include "../include/tscope5/system_internal.h"
16 
17 /// Is Tscope5 installed?
19 
20 /// Is text log installed?
22 
23 /// Settings for the next display that will be opened.
24 TS5_DISPLAY_STATUS ts5_nextdisplay =
25  { 0, 640, 360, 0, 0, 60, TS5_WINDOWED, TS5_VSYNC_ON };
26 
27 
28 ////////////////////////////////////////////////////////////////////////////////
29 /// Install Tscope5.
30 ///
31 /// \param calling_function Name the function that calls
32 /// for this check or installation.
33 ///
34 /// Gathers information about the display adapter(s) of the
35 /// computer and sets the default parameters for displays, graphics and audio.
36 ///
37 /// This function is called automatically if necessary.
38 ///
39 /// If Tscope5 can't be installed the program is aborted.
40 ///
41 /// This function does not open a display,
42 /// that is done by ts5_install_display().
43 ////////////////////////////////////////////////////////////////////////////////
44 void ts5_install_tscope5(char *calling_function)
45 {
46  int i;
47 
49 
50  #ifdef TS5_WINDOWS
51  setvbuf(stdout, 0, _IONBF, 0);
52 
53  #endif
54 
56  _ts5_status.loglevel = TS5_LOGLEVEL_3;
57  _ts5_data.textlog = NULL;
58 
59  if (!al_install_system(ALLEGRO_VERSION_INT, NULL)) {
60  ts5_fatal("%s: could not install Tscope5\n", calling_function);
61  }
62 
63  ts5_log(TS5_LOGLEVEL_1, "%s: Installing Tscope5\n", calling_function);
64  al_inhibit_screensaver(1);
65  al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ALPHA,
66  ALLEGRO_INVERSE_ALPHA, ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
67 
68  al_add_new_bitmap_flag(ALLEGRO_NO_PRESERVE_TEXTURE);
69 // al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_REQUIRE);
70 // al_set_new_display_option(ALLEGRO_SAMPLES, 4, ALLEGRO_SUGGEST);
71 
72  // display adapters
73  _ts5_status.num_display_adapters = al_get_num_video_adapters();
74 
75  _ts5_status.display_adapter =
76  al_malloc(_ts5_status.num_display_adapters
77  * sizeof(TS5_DISPLAY_ADAPTER_STATUS));
78 
79  for (i = 0; i < _ts5_status.num_display_adapters; i++) {
80 
81  ALLEGRO_MONITOR_INFO monitorinfo;
82  al_get_monitor_info(i, &monitorinfo);
83  _ts5_status.display_adapter[i].x1 = monitorinfo.x1;
84  _ts5_status.display_adapter[i].x2 = monitorinfo.x2;
85  _ts5_status.display_adapter[i].y1 = monitorinfo.y1;
86  _ts5_status.display_adapter[i].y2 = monitorinfo.y2;
87  _ts5_status.display_adapter[i].w = monitorinfo.x2 - monitorinfo.x1;
88  _ts5_status.display_adapter[i].h = monitorinfo.y2 - monitorinfo.y1;
89  }
90 
91  ts5_nextdisplay.x = -1;
92  ts5_nextdisplay.y = -1;
93 
94  // displays
95  _ts5_status.num_displays = 0;
96  _ts5_status.active_display = -1;
97  _ts5_status.display = NULL;
98  _ts5_data.display = NULL;
99  _ts5_data.target = NULL;
100 
101  // graphics parameters
102  _ts5_status.graphics.coordinate_system = TS5_CARTESIAN_COORDINATES;
103  _ts5_status.graphics.coordinate_scale = TS5_ABSOLUTE_COORDINATES;
104 
105  _ts5_status.graphics.foreground_color =
106  al_map_rgba_f(1.0, 1.0, 1.0, 1.0);
107 
108  _ts5_status.graphics.background_color =
109  al_map_rgba_f(0.0, 0.0, 0.0, 1.0);
110 
111  _ts5_status.graphics.drawing_thickness = 0.0;
112  _ts5_status.graphics.fill_mode = TS5_FILL_OFF;
113 
114  _ts5_status.graphics.font_type = TS5_COURIER;
115  _ts5_status.graphics.font_style = TS5_BOLD;
116  _ts5_status.graphics.font_size = 20;
117 
118  _ts5_status.graphics.font_index =
119  _ts5_status.graphics.font_type * TS5_FONTSTYLES * TS5_FONTSIZES +
120  _ts5_status.graphics.font_style * TS5_FONTSIZES +
121  _ts5_status.graphics.font_size - 8;
122 
123  _ts5_status.graphics.text_alignment = TS5_ALIGN_CENTER;
124 
125 
126  for (i=0; i<TS5_NFONTS; i++) {
127  _ts5_status.graphics.fonts[i] = NULL;
128  }
129  _ts5_status.graphics.font = NULL;
130 
131  // randomizer
132  _ts5_data.randomizer = NULL;
133 
134  // timer
135  _ts5_status.timer.priority = TS5_NORMAL_PRIORITY;
136  _ts5_status.timer.num_defined_buttons = 0;
137  _ts5_status.timer.num_active_buttons = 0;
138 
139  _ts5_status.timer.mouse_is_response_device = 0;
140 
141  _ts5_status.timer.keyboard_is_response_device = 0;
142 
143  _ts5_status.timer.num_joysticks = 0;
144  _ts5_status.timer.joystick_is_response_device = 0;
145  _ts5_status.timer.joystick = NULL;
146 
147  _ts5_status.timer.num_cedrusboxes = 0;
148  _ts5_status.timer.cedrusbox_is_response_device = 0;
149  _ts5_status.timer.cedrusbox = NULL;
150  _ts5_data.timer.cedrusbox_thread = NULL;
151  _ts5_data.timer.cedrusbox_thread_is_paused = 1;
152 
153  _ts5_status.timer.num_parports = 0;
154  _ts5_status.timer.parport_is_response_device = 0;
155  _ts5_status.timer.parport = NULL;
156  _ts5_data.timer.parport_thread = NULL;
157 
158  _ts5_status.timer.num_serialports = 0;
159  _ts5_status.timer.serialport_is_trigger_device = 0;
160  _ts5_status.timer.serialport = NULL;
161  _ts5_data.timer.serialport_thread = NULL;
162 
163  _ts5_data.timer.response_queue = NULL;
164  _ts5_data.timer.trigger_queue = NULL;
165  _ts5_data.timer.trigger_log = NULL;
166 
167  // audio parameters
168  _ts5_status.audio.frequency = TS5_44100;
169  _ts5_status.audio.channels = TS5_STEREO;
170  _ts5_status.audio.depth = TS5_FLOAT;
171  _ts5_status.audio.gain = 1.0;
172 
173  _ts5_data.audio.voice = NULL;
174  _ts5_data.audio.mixer = NULL;
175 
176  atexit(ts5_uninstall_tscope5);
177  }
178 }
179 
180 
181 ////////////////////////////////////////////////////////////////////////////////
182 /// Uninstall Tscope5.
183 ///
184 /// Closes Tscope5, all subsystems and the log window.
185 ///
186 /// This function is called automatically at the end of the program.
187 ////////////////////////////////////////////////////////////////////////////////
189 {
191 
192  ts5_log(TS5_LOGLEVEL_1, "Uninstalling Tscope5\n");
193  al_inhibit_screensaver(0);
194 
196  fflush(_ts5_data.textlog);
197  fclose(_ts5_data.textlog);
199  }
200 
201  al_free(_ts5_status.display_adapter);
202 
203  #ifdef TS5_MACOSX
204  al_uninstall_system();
205 
206  #endif
207 
209  }
210 }
211