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, 0.0, TS5_WINDOWED, TS5_VSYNC_ON, TS5_MULTISAMPLING_OFF, 1};
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 
55  // system
57  _ts5_status.loglevel = TS5_LOGLEVEL_3;
58  _ts5_data.textlog = NULL;
59 
60 
61  // randomizer
62  _ts5_data.randomizer = NULL;
63 
64 
65  // allegro
66  if (!al_install_system(ALLEGRO_VERSION_INT, NULL)) {
67  ts5_fatal("%s: could not install Tscope5\n", calling_function);
68  }
69 
70  ts5_log(TS5_LOGLEVEL_1, "%s: Installing Tscope5\n", calling_function);
71  al_inhibit_screensaver(1);
72  al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ALPHA,
73  ALLEGRO_INVERSE_ALPHA, ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
74 
75  al_add_new_bitmap_flag(ALLEGRO_NO_PRESERVE_TEXTURE);
76  al_add_new_bitmap_flag(ALLEGRO_MIN_LINEAR);
77  al_add_new_bitmap_flag(ALLEGRO_MAG_LINEAR);
78 
79  // display adapters
80  _ts5_status.num_display_adapters = al_get_num_video_adapters();
81 
82  _ts5_status.display_adapter =
83  al_malloc(_ts5_status.num_display_adapters
84  * sizeof(TS5_DISPLAY_ADAPTER_STATUS));
85 
86  for (i = 0; i < _ts5_status.num_display_adapters; i++) {
87 
88  ALLEGRO_MONITOR_INFO monitorinfo;
89  al_get_monitor_info(i, &monitorinfo);
90  _ts5_status.display_adapter[i].x1 = monitorinfo.x1;
91  _ts5_status.display_adapter[i].x2 = monitorinfo.x2;
92  _ts5_status.display_adapter[i].y1 = monitorinfo.y1;
93  _ts5_status.display_adapter[i].y2 = monitorinfo.y2;
94  _ts5_status.display_adapter[i].w = monitorinfo.x2 - monitorinfo.x1;
95  _ts5_status.display_adapter[i].h = monitorinfo.y2 - monitorinfo.y1;
96  }
97 
98  ts5_nextdisplay.x = -1;
99  ts5_nextdisplay.y = -1;
100 
101 
102  // displays
103  _ts5_status.num_displays = 0;
104  _ts5_status.active_display = -1;
105  _ts5_status.display = NULL;
106  _ts5_data.display = NULL;
107  _ts5_data.target = NULL;
108 
109 
110  // graphics parameters
111  _ts5_status.graphics.coordinate_system = TS5_CARTESIAN_COORDINATES;
112  _ts5_status.graphics.coordinate_scale = TS5_ABSOLUTE_COORDINATES;
113 
114  _ts5_status.graphics.foreground_color =
115  al_map_rgba_f(1.0, 1.0, 1.0, 1.0);
116 
117  _ts5_status.graphics.background_color =
118  al_map_rgba_f(0.0, 0.0, 0.0, 1.0);
119 
120  _ts5_status.graphics.drawing_thickness = 0.0;
121  _ts5_status.graphics.fill_mode = TS5_FILL_OFF;
122 
123  _ts5_status.graphics.font_type = TS5_COURIER;
124  _ts5_status.graphics.font_style = TS5_BOLD;
125  _ts5_status.graphics.font_size = 20;
126 
127  _ts5_status.graphics.font_index =
128  _ts5_status.graphics.font_type * TS5_FONTSTYLES * TS5_FONTSIZES +
129  _ts5_status.graphics.font_style * TS5_FONTSIZES +
130  _ts5_status.graphics.font_size - 8;
131 
132  _ts5_status.graphics.text_alignment = TS5_ALIGN_CENTER;
133 
134  for (i=0; i<TS5_NFONTS; i++) {
135  _ts5_status.graphics.fonts[i] = NULL;
136  }
137  _ts5_status.graphics.font = NULL;
138 
139 
140  // audio parameters
141  _ts5_status.audio.samplerate = TS5_44100;
142  _ts5_status.audio.channels = TS5_STEREO;
143  _ts5_status.audio.depth = TS5_FLOAT;
144  _ts5_status.audio.gain = 1.0;
145 
146  _ts5_data.audio.voice = NULL;
147  _ts5_data.audio.mixer = NULL;
148 
149 
150  // timer
151  _ts5_status.timer.priority = TS5_NORMAL_PRIORITY;
152  _ts5_status.timer.num_defined_buttons = 0;
153  _ts5_status.timer.num_active_buttons = 0;
154 
155  _ts5_status.timer.voicekey_is_response_device = 0;
156 
157  _ts5_status.timer.mouse_is_response_device = 0;
158 
159  _ts5_status.timer.keyboard_is_response_device = 0;
160 
161  _ts5_status.timer.num_joysticks = 0;
162  _ts5_status.timer.joystick_is_response_device = 0;
163  _ts5_status.timer.joystick = NULL;
164 
165  _ts5_status.timer.num_cedrusboxes = 0;
166  _ts5_status.timer.cedrusbox_is_response_device = 0;
167  _ts5_status.timer.cedrusbox_is_trigger_device = 0;
168  _ts5_status.timer.cedrusbox = NULL;
169  _ts5_data.timer.cedrusbox_thread = NULL;
170 
171  _ts5_status.timer.num_parports = 3;
172  _ts5_status.timer.parport_base_address[0] = TS5_PARPORT_1_BASE;
173  _ts5_status.timer.parport_base_address[1] = TS5_PARPORT_2_BASE;
174  _ts5_status.timer.parport_base_address[2] = TS5_PARPORT_3_BASE;
175 
176  for (i=0; i<_ts5_status.timer.num_parports; i++) {
177 
178  _ts5_status.timer.parport_data_register[i] =
179  _ts5_status.timer.parport_base_address[i];
180 
181  _ts5_status.timer.parport_status_register[i] =
182  _ts5_status.timer.parport_base_address[i]+1;
183 
184  _ts5_status.timer.parport_control_register[i] =
185  _ts5_status.timer.parport_base_address[i]+2;
186  }
187 
188  _ts5_status.timer.parport_is_response_device = 0;
189  _ts5_status.timer.parport_is_trigger_device = 0;
190  _ts5_status.timer.parport = NULL;
191  _ts5_data.timer.parport_thread = NULL;
192 
193  _ts5_status.timer.num_serialports = 0;
194  _ts5_status.timer.serialport_is_trigger_device = 0;
195  _ts5_status.timer.serialport = NULL;
196  _ts5_data.timer.serialport_thread = NULL;
197 
198  _ts5_data.timer.response_queue = NULL;
199  _ts5_data.timer.trigger_queue = NULL;
200  _ts5_data.timer.trigger_log = NULL;
201 
202 
203  atexit(ts5_uninstall_tscope5);
204  }
205 }
206 
207 
208 ////////////////////////////////////////////////////////////////////////////////
209 /// Uninstall Tscope5.
210 ///
211 /// Closes Tscope5, all subsystems and the log window.
212 ///
213 /// This function is called automatically at the end of the program.
214 ////////////////////////////////////////////////////////////////////////////////
216 {
218 
219  ts5_log(TS5_LOGLEVEL_1, "Uninstalling Tscope5\n");
220  al_inhibit_screensaver(0);
221 
223  fflush(_ts5_data.textlog);
224  fclose(_ts5_data.textlog);
226  }
227 
228  al_free(_ts5_status.display_adapter);
229 
230  //al_uninstall_system();
231 
233  }
234 }
235 
int _ts5_is_tscope5_installed
Is Tscope5 installed?
TS5_DISPLAY_STATUS ts5_nextdisplay
Settings for the next display that will be opened.
void ts5_log(const unsigned int level, const char *format,...)
Send info to a logging window.
Definition: system.c:45
void ts5_install_tscope5(char *calling_function)
Install Tscope5.
int _ts5_is_textlog_installed
Is text log installed?
void ts5_fatal(const char *format,...)
Exit safely with an error message.
Definition: system.c:533
void ts5_uninstall_tscope5()
Uninstall Tscope5.