298 #include "../include/tscope5/system.h"
299 #include "../include/tscope5/display.h"
300 #include "../include/tscope5/system_internal.h"
323 void ts5_log(
const unsigned int level,
const char *format, ...)
325 if (!_ts5_is_tscope5_installed) {
326 ts5_install_tscope5(
"ts5_log");
329 if (level <= _ts5_status.loglevel) {
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");
336 _ts5_is_textlog_installed = 1;
339 char outbuf[TS5_MAX_CHAR];
341 va_start(args, format);
342 vsnprintf(outbuf, TS5_MAX_CHAR*
sizeof(
char), format, args);
345 double logtime = al_get_time();
346 fprintf(stderr,
"%8.3f: %s", logtime, outbuf);
347 fprintf(_ts5_status.textlog,
"%8.3f: %s", logtime, outbuf);
376 if (!_ts5_is_tscope5_installed) {
377 ts5_install_tscope5(
"ts5_set_log_level");
380 ts5_log(TS5_LOGLEVEL_4,
"ts5_set_log_level(%d)\n", loglevel);
383 retval = _ts5_status.loglevel;
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",
391 ts5_fatal(
"ts5_log: requested loglevel not supported.");
405 if (!_ts5_is_tscope5_installed) {
406 ts5_install_tscope5(
"ts5_get_log_level");
409 ts5_log(TS5_LOGLEVEL_4,
"ts5_get_log_level\n");
411 return _ts5_status.loglevel;
428 ts5_log(TS5_LOGLEVEL_0,
"========================================\n");
429 ts5_log(TS5_LOGLEVEL_0,
"tscope5 status:\n");
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);
435 for (i = 0; i < _ts5_status.num_display_adapters; i++) {
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);
448 int oldadapter = ts5_nextdisplay.adapter;
449 ALLEGRO_DISPLAY_MODE *mode;
450 mode = (ALLEGRO_DISPLAY_MODE *)al_malloc(
sizeof(ALLEGRO_DISPLAY_MODE));
452 for (i = 0; i < _ts5_status.num_display_adapters; i++) {
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);
460 int nmodes = al_get_num_display_modes();
463 for (j=0; j<nmodes; j++) {
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);
470 al_set_new_display_refresh_rate(oldrate);
471 al_set_new_display_flags(oldflags);
475 al_set_new_display_adapter(oldadapter);
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);
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);
492 for (i = 0; i < _ts5_status.num_displays; i++) {
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);
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);
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);
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);
532 ts5_log(TS5_LOGLEVEL_0,
"Number of active response keys: %d\n",
533 _ts5_status.timer_status.num_active_buttons);
535 ts5_log(TS5_LOGLEVEL_0,
"Mouse is response device: %d\n",
536 _ts5_status.timer_status.mouse_is_response_device);
538 if (_ts5_status.timer_status.mouse_is_response_device) {
540 for (i=0; i<_ts5_status.timer_status.mouse.num_buttons; i++) {
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]);
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]);
554 ts5_log(TS5_LOGLEVEL_0,
"Keyboard is response device: %d\n",
555 _ts5_status.timer_status.keyboard_is_response_device);
557 if (_ts5_status.timer_status.keyboard_is_response_device) {
559 for (i=0; i<_ts5_status.timer_status.keyboard.num_buttons; i++) {
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]);
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]);
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);
577 if (_ts5_status.timer_status.joystick_is_response_device) {
579 for (i=0; i<_ts5_status.timer_status.num_joystick; i++) {
582 for (j=0; j<_ts5_status.timer_status.joystick[i].num_buttons; j++) {
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]);
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]);
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);
601 if (_ts5_status.timer_status.cedrusbox_is_response_device) {
603 for (i=0; i<_ts5_status.timer_status.num_cedrusbox; i++) {
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);
608 ts5_log(TS5_LOGLEVEL_0,
"Cedrusbox %d is type %d\n",
609 i+1, _ts5_status.timer_status.cedrusbox[i].type);
612 for (j=0; j<_ts5_status.timer_status.cedrusbox[i].num_buttons; j++) {
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]);
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]);
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);
631 if (_ts5_status.timer_status.parport_is_response_device) {
633 for (i=0; i<_ts5_status.timer_status.num_parport; i++) {
636 for (j=0; j<_ts5_status.timer_status.parport[i].num_buttons; j++) {
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]);
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]);
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);
663 ts5_log(TS5_LOGLEVEL_0,
"========================================\n");
696 ts5_log(TS5_LOGLEVEL_1,
"ts5_fatal\n");
698 char outbuf[TS5_MAX_CHAR];
700 va_start(args, format);
701 vsnprintf(outbuf, TS5_MAX_CHAR*
sizeof(
char), format, args);
704 fprintf(stderr,
"Tscope5 error: %s", outbuf);
706 if (_ts5_status.num_displays>0) {
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;
714 al_show_native_message_box(_ts5_status.display[_ts5_status.active_display],
715 "Tscope5 error",
"Tscope5 error", outbuf, NULL, ALLEGRO_MESSAGEBOX_ERROR);
718 al_show_native_message_box(NULL,
"Tscope5 error",
"Tscope5 error",
719 outbuf, NULL, ALLEGRO_MESSAGEBOX_ERROR);