Tscope5
system.c
Go to the documentation of this file.
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
99 
100 
101 
102 
103 
104 
105 
106 
107 
108 
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
123 
124 
125 
126 
127 
128 
129 
130 
131 
132 
133 
134 
135 
136 
137 
138 
139 
140 
141 
142 
143 
144 
145 
146 
147 
148 
149 
150 
151 
152 
153 
154 
155 
156 
157 
158 
159 
160 
161 
162 
163 
164 
165 
166 
167 
168 
169 
170 
171 
172 
173 
174 
175 
176 
177 
178 
179 
180 
181 
182 
183 
184 
185 
186 
187 
188 
189 
190 
191 
192 
193 
194 
195 
196 
197 
198 
199 
200 
201 
202 
203 
204 
205 
206 
207 
208 
209 
210 
211 
223 
224 
271 
272 
289 
290 
297 
298 #include "../include/tscope5/system.h"
299 #include "../include/tscope5/display.h"
300 #include "../include/tscope5/system_internal.h"
301 
302 
309 
310 
311 
312 
323 void ts5_log(const unsigned int level, const char *format, ...)
324 {
325  if (!_ts5_is_tscope5_installed) {
326  ts5_install_tscope5("ts5_log");
327  }
328 
329  if (level <= _ts5_status.loglevel) {
330 
331  if (!_ts5_is_textlog_installed) {
332  _ts5_status.textlog = fopen("tscope5.log", "w+");
333  if (!_ts5_status.textlog) {
334  ts5_fatal("ts5_log: could not open log file\n");
335  }
336  _ts5_is_textlog_installed = 1;
337  }
338 
339  char outbuf[TS5_MAX_CHAR];
340  va_list args;
341  va_start(args, format);
342  vsnprintf(outbuf, TS5_MAX_CHAR*sizeof(char), format, args);
343  va_end(args);
344 
345  double logtime = al_get_time();
346  fprintf(stderr, "%8.3f: %s", logtime, outbuf);
347  fprintf(_ts5_status.textlog, "%8.3f: %s", logtime, outbuf);
348  }
349 }
350 
351 
374 int ts5_set_log_level(const unsigned int loglevel)
375 {
376  if (!_ts5_is_tscope5_installed) {
377  ts5_install_tscope5("ts5_set_log_level");
378  }
379 
380  ts5_log(TS5_LOGLEVEL_4, "ts5_set_log_level(%d)\n", loglevel);
381 
382  int retval;
383  retval = _ts5_status.loglevel;
384 
385  if (loglevel <= TS5_LOGLEVEL_6) {
386  _ts5_status.loglevel = loglevel;
387  ts5_log(TS5_LOGLEVEL_4, "ts5_set_log_level: changed loglevel from %d to %d\n",
388  retval, loglevel);
389  }
390  else {
391  ts5_fatal("ts5_log: requested loglevel not supported.");
392  }
393 
394  return retval;
395 }
396 
397 
404 {
405  if (!_ts5_is_tscope5_installed) {
406  ts5_install_tscope5("ts5_get_log_level");
407  }
408 
409  ts5_log(TS5_LOGLEVEL_4, "ts5_get_log_level\n");
410 
411  return _ts5_status.loglevel;
412 }
413 
414 
424 {
425  // display adapters + supported fullscreen modes
426  int i;
427  ts5_log(TS5_LOGLEVEL_0, "\n");
428  ts5_log(TS5_LOGLEVEL_0, "========================================\n");
429  ts5_log(TS5_LOGLEVEL_0, "tscope5 status:\n");
430  ts5_log(TS5_LOGLEVEL_0, "\n");
431 
432  ts5_log(TS5_LOGLEVEL_0, "Loglevel: %d\n", _ts5_status.loglevel);
433  ts5_log(TS5_LOGLEVEL_0, "Number of display adapters: %d\n", _ts5_status.num_display_adapters);
434 
435  for (i = 0; i < _ts5_status.num_display_adapters; i++) {
436 
437  ts5_log(TS5_LOGLEVEL_0, "Display adapter %d: w: %d (%d:%d), h: %d (%d:%d)\n", i+1,
438  _ts5_status.display_adapter_status[i].w,
439  _ts5_status.display_adapter_status[i].x1,
440  _ts5_status.display_adapter_status[i].x2,
441  _ts5_status.display_adapter_status[i].h,
442  _ts5_status.display_adapter_status[i].y1,
443  _ts5_status.display_adapter_status[i].y2);
444  }
445 
446  ts5_log(TS5_LOGLEVEL_0, "\n");
447 
448  int oldadapter = ts5_nextdisplay.adapter;
449  ALLEGRO_DISPLAY_MODE *mode;
450  mode = (ALLEGRO_DISPLAY_MODE *)al_malloc(sizeof(ALLEGRO_DISPLAY_MODE));
451 
452  for (i = 0; i < _ts5_status.num_display_adapters; i++) {
453 
454  al_set_new_display_adapter(i);
455  int oldrate = al_get_new_display_refresh_rate();
456  int oldflags = al_get_new_display_flags();
457  al_set_new_display_refresh_rate(0);
458  al_set_new_display_flags(0);
459 
460  int nmodes = al_get_num_display_modes();
461 
462  int j;
463  for (j=0; j<nmodes; j++) {
464 
465  mode = al_get_display_mode(j, mode);
466  ts5_log(TS5_LOGLEVEL_0, "adapter %d mode %d: w=%d, h=%d, format=%d, rate=%d\n",
467  i+1, j+1, mode->width, mode->height, mode->format, mode->refresh_rate);
468  }
469 
470  al_set_new_display_refresh_rate(oldrate);
471  al_set_new_display_flags(oldflags);
472  }
473 
474  ts5_log(TS5_LOGLEVEL_0, "\n");
475  al_set_new_display_adapter(oldadapter);
476  al_free(mode);
477 
478  // display settings + settings for next display
479  ts5_log(TS5_LOGLEVEL_0, "========================================\n");
480  ts5_log(TS5_LOGLEVEL_0, "Parameters for next display:\n");
481  ts5_log(TS5_LOGLEVEL_0, "\tadapter %d\n", ts5_nextdisplay.adapter+1);
482  ts5_log(TS5_LOGLEVEL_0, "\tw=%d, h=%d\n", ts5_nextdisplay.w, ts5_nextdisplay.h);
483  ts5_log(TS5_LOGLEVEL_0, "\tx=%d, y=%d\n", ts5_nextdisplay.x, ts5_nextdisplay.y);
484  ts5_log(TS5_LOGLEVEL_0, "\trefreshrate=%d\n", ts5_nextdisplay.refreshrate);
485  ts5_log(TS5_LOGLEVEL_0, "\tdisplay mode=%d\n", ts5_nextdisplay.display_mode);
486  ts5_log(TS5_LOGLEVEL_0, "\tvsync mode=%d\n", ts5_nextdisplay.vsync_mode);
487  ts5_log(TS5_LOGLEVEL_0, "\n");
488 
489  ts5_log(TS5_LOGLEVEL_0, "Number of displays: %d\n", _ts5_status.num_displays);
490  ts5_log(TS5_LOGLEVEL_0, "Active display: %d\n", _ts5_status.active_display);
491 
492  for (i = 0; i < _ts5_status.num_displays; i++) {
493 
494  ts5_log(TS5_LOGLEVEL_0,
495  "Display %d: adapter %d, w=%d, h=%d, x=%d, y=%d, rate=%d, display_mode=%d, vsync=%d\n",
496  i+1, _ts5_status.display_status[i].adapter+1,
497  _ts5_status.display_status[i].w, _ts5_status.display_status[i].h,
498  _ts5_status.display_status[i].x, _ts5_status.display_status[i].y,
499  _ts5_status.display_status[i].refreshrate,
500  _ts5_status.display_status[i].display_mode,
501  _ts5_status.display_status[i].vsync_mode);
502  }
503 
504  ts5_log(TS5_LOGLEVEL_0, "\n");
505 
506  // graphics parameters
507  float r, g, b, a;
508  ts5_log(TS5_LOGLEVEL_0, "========================================\n");
509  ts5_log(TS5_LOGLEVEL_0, "Coordinate system: %d\n", _ts5_status.graphics_status.coordinate_system);
510  ts5_log(TS5_LOGLEVEL_0, "Coordinate scale: %d\n", _ts5_status.graphics_status.coordinate_scale);
511  ts5_log(TS5_LOGLEVEL_0, "Target bitmap size: %d x %d\n",
512  _ts5_status.graphics_status.target_width, _ts5_status.graphics_status.target_height);
513 
514  al_unmap_rgba_f(_ts5_status.graphics_status.foreground_color, &r, &g, &b, &a);
515  ts5_log(TS5_LOGLEVEL_0, "Foreground color: r: %f g: %f b: %f alpha: %f\n", r, g, b, a);
516  al_unmap_rgba_f(_ts5_status.graphics_status.background_color, &r, &g, &b, &a);
517  ts5_log(TS5_LOGLEVEL_0, "Background color: r: %f g: %f b: %f alpha: %f\n", r, g, b, a);
518  ts5_log(TS5_LOGLEVEL_0, "Line drawing thickness: %f\n", _ts5_status.graphics_status.drawing_thickness);
519  ts5_log(TS5_LOGLEVEL_0, "Fill mode: %d\n", _ts5_status.graphics_status.fill_mode);
520  ts5_log(TS5_LOGLEVEL_0, "Font type: %d\n", _ts5_status.graphics_status.font_type);
521  ts5_log(TS5_LOGLEVEL_0, "Font style: %d\n", _ts5_status.graphics_status.font_style);
522  ts5_log(TS5_LOGLEVEL_0, "Font size: %d\n", _ts5_status.graphics_status.font_size);
523  ts5_log(TS5_LOGLEVEL_0, "Font number: %d\n", _ts5_status.graphics_status.font_index);
524  ts5_log(TS5_LOGLEVEL_0, "Text alignment: %d\n", _ts5_status.graphics_status.text_alignment);
525  ts5_log(TS5_LOGLEVEL_0, "\n");
526 
527  // response keys
528  ts5_log(TS5_LOGLEVEL_0, "========================================\n");
529  ts5_log(TS5_LOGLEVEL_0, "Number of defined response keys: %d\n",
530  _ts5_status.timer_status.num_defined_buttons);
531 
532  ts5_log(TS5_LOGLEVEL_0, "Number of active response keys: %d\n",
533  _ts5_status.timer_status.num_active_buttons);
534 
535  ts5_log(TS5_LOGLEVEL_0, "Mouse is response device: %d\n",
536  _ts5_status.timer_status.mouse_is_response_device);
537 
538  if (_ts5_status.timer_status.mouse_is_response_device) {
539 
540  for (i=0; i<_ts5_status.timer_status.mouse.num_buttons; i++) {
541 
542  if (_ts5_status.timer_status.mouse.button_press_active[i]!=0) {
543  ts5_log(TS5_LOGLEVEL_0, "Mouse button press %d has response value %d\n",
544  i+1, _ts5_status.timer_status.mouse.button_press_defined[i]);
545  }
546 
547  if (_ts5_status.timer_status.mouse.button_release_active[i]!=0) {
548  ts5_log(TS5_LOGLEVEL_0, "Mouse button release %d has response value %d\n",
549  i+1, _ts5_status.timer_status.mouse.button_release_defined[i]);
550  }
551  }
552  }
553 
554  ts5_log(TS5_LOGLEVEL_0, "Keyboard is response device: %d\n",
555  _ts5_status.timer_status.keyboard_is_response_device);
556 
557  if (_ts5_status.timer_status.keyboard_is_response_device) {
558 
559  for (i=0; i<_ts5_status.timer_status.keyboard.num_buttons; i++) {
560 
561  if (_ts5_status.timer_status.keyboard.button_press_active[i]!=0) {
562  ts5_log(TS5_LOGLEVEL_0, "Keyboard button press %d has response value %d\n",
563  i+1, _ts5_status.timer_status.keyboard.button_press_defined[i]);
564  }
565 
566  if (_ts5_status.timer_status.keyboard.button_release_active[i]!=0) {
567  ts5_log(TS5_LOGLEVEL_0, "Keyboard button release %d has response value %d\n",
568  i+1, _ts5_status.timer_status.keyboard.button_release_defined[i]);
569  }
570  }
571  }
572 
573  ts5_log(TS5_LOGLEVEL_0, "Number of joysticks: %d\n", _ts5_status.timer_status.num_joystick);
574  ts5_log(TS5_LOGLEVEL_0, "Joystick is response device: %d\n",
575  _ts5_status.timer_status.joystick_is_response_device);
576 
577  if (_ts5_status.timer_status.joystick_is_response_device) {
578 
579  for (i=0; i<_ts5_status.timer_status.num_joystick; i++) {
580  int j;
581 
582  for (j=0; j<_ts5_status.timer_status.joystick[i].num_buttons; j++) {
583 
584  if (_ts5_status.timer_status.joystick[i].button_press_active[j]!=0) {
585  ts5_log(TS5_LOGLEVEL_0, "Joystick %d button press %d has response value %d\n",
586  i+1, j+1, _ts5_status.timer_status.joystick[i].button_press_defined[j]);
587  }
588 
589  if (_ts5_status.timer_status.joystick[i].button_release_active[j]!=0) {
590  ts5_log(TS5_LOGLEVEL_0, "Joystick %d button release %d has response value %d\n",
591  i+1, j+1, _ts5_status.timer_status.joystick[i].button_release_defined[j]);
592  }
593  }
594  }
595  }
596 
597  ts5_log(TS5_LOGLEVEL_0, "Number of cedrusboxes: %d\n", _ts5_status.timer_status.num_cedrusbox);
598  ts5_log(TS5_LOGLEVEL_0, "Cedrusbox is response device: %d\n",
599  _ts5_status.timer_status.cedrusbox_is_response_device);
600 
601  if (_ts5_status.timer_status.cedrusbox_is_response_device) {
602 
603  for (i=0; i<_ts5_status.timer_status.num_cedrusbox; i++) {
604 
605  ts5_log(TS5_LOGLEVEL_0, "Cedrusbox %d is mapped to serial device %d\n",
606  i+1, _ts5_status.timer_status.cedrusbox[i].port_num+1);
607 
608  ts5_log(TS5_LOGLEVEL_0, "Cedrusbox %d is type %d\n",
609  i+1, _ts5_status.timer_status.cedrusbox[i].type);
610 
611  int j;
612  for (j=0; j<_ts5_status.timer_status.cedrusbox[i].num_buttons; j++) {
613 
614  if (_ts5_status.timer_status.cedrusbox[i].button_press_active[j]!=0) {
615  ts5_log(TS5_LOGLEVEL_0, "Cedrusbox %d button press %d has response value %d\n",
616  i+1, j+1, _ts5_status.timer_status.cedrusbox[i].button_press_defined[j]);
617  }
618 
619  if (_ts5_status.timer_status.cedrusbox[i].button_release_active[j]!=0) {
620  ts5_log(TS5_LOGLEVEL_0, "Cedrusbox %d button release %d has response value %d\n",
621  i+1, j+1, _ts5_status.timer_status.cedrusbox[i].button_release_defined[j]);
622  }
623  }
624  }
625  }
626 
627  ts5_log(TS5_LOGLEVEL_0, "Number of parallel ports: %d\n", _ts5_status.timer_status.num_parport);
628  ts5_log(TS5_LOGLEVEL_0, "Parallel port is response device: %d\n",
629  _ts5_status.timer_status.parport_is_response_device);
630 
631  if (_ts5_status.timer_status.parport_is_response_device) {
632 
633  for (i=0; i<_ts5_status.timer_status.num_parport; i++) {
634 
635  int j;
636  for (j=0; j<_ts5_status.timer_status.parport[i].num_buttons; j++) {
637 
638  if (_ts5_status.timer_status.parport[i].button_press_active[j]!=0) {
639  ts5_log(TS5_LOGLEVEL_0, "Parport %d button press %d has response value %d\n",
640  i+1, j+1, _ts5_status.timer_status.parport[i].button_press_defined[j]);
641  }
642 
643  if (_ts5_status.timer_status.cedrusbox[i].button_release_active[j]!=0) {
644  ts5_log(TS5_LOGLEVEL_0, "Parport %d button release %d has response value %d\n",
645  i+1, j+1, _ts5_status.timer_status.parport[i].button_release_defined[j]);
646  }
647  }
648  }
649  }
650 
651  ts5_log(TS5_LOGLEVEL_0, "\n");
652 
653 
654  // audio parameters
655  ts5_log(TS5_LOGLEVEL_0, "========================================\n");
656  ts5_log(TS5_LOGLEVEL_0, "Number of audio channels: %d\n", _ts5_status.audio_status.channels);
657  ts5_log(TS5_LOGLEVEL_0, "Sample rate: %d\n", _ts5_status.audio_status.frequency);
658  ts5_log(TS5_LOGLEVEL_0, "Sample format: %d\n", _ts5_status.audio_status.depth);
659  ts5_log(TS5_LOGLEVEL_0, "Gain: %f\n", _ts5_status.audio_status.gain);
660 
661 
662  ts5_log(TS5_LOGLEVEL_0, "\n");
663  ts5_log(TS5_LOGLEVEL_0, "========================================\n");
664 }
665 
666 
668 
669 
670 
671 
679 
680 
681 
682 
694 void ts5_fatal(const char *format, ...)
695 {
696  ts5_log(TS5_LOGLEVEL_1, "ts5_fatal\n");
697 
698  char outbuf[TS5_MAX_CHAR];
699  va_list args;
700  va_start(args, format);
701  vsnprintf(outbuf, TS5_MAX_CHAR*sizeof(char), format, args);
702  va_end(args);
703 
704  fprintf(stderr, "Tscope5 error: %s", outbuf);
705 
706  if (_ts5_status.num_displays>0) {
707 
708  if (_ts5_status.display_status[_ts5_status.active_display].display_mode == TS5_FULLSCREEN_WINDOW) {
709  al_toggle_display_flag(_ts5_status.display[_ts5_status.active_display],
710  ALLEGRO_FULLSCREEN_WINDOW, 0);
711  _ts5_status.display_status[_ts5_status.active_display].display_mode = TS5_WINDOWED;
712  }
713 
714  al_show_native_message_box(_ts5_status.display[_ts5_status.active_display],
715  "Tscope5 error", "Tscope5 error", outbuf, NULL, ALLEGRO_MESSAGEBOX_ERROR);
716  }
717  else {
718  al_show_native_message_box(NULL, "Tscope5 error", "Tscope5 error",
719  outbuf, NULL, ALLEGRO_MESSAGEBOX_ERROR);
720  }
721  exit(1);
722 }
723 
724 
726 
727