home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / util / cli / monitorinfo / monitorinfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-09  |  6.5 KB  |  181 lines

  1. /*-------------------------------------------------------------------------
  2. --
  3. -- MonitorInfo.C
  4. --
  5. -- A small program to display a monitor's properties 
  6. --
  7. -- author: Gregor S. M. Kuhlmann
  8. -- version: 37.4
  9. -- created: 1994-Apr-01
  10. --
  11. -- revision history:
  12. -- 1994-Apr-01    37.0  created
  13. -- 1994-Apr-02    37.1  added analogsignal period output in microseconds
  14. -- 1994-Apr-03    37.2  added ms_Flags interpretation
  15. -- 1994-Apr-04    37.3  added LIST option
  16. -- 1994-Apr-09    37.4  added RAW option
  17. --
  18. -------------------------------------------------------------------------*/
  19.  
  20. #define __USE_SYSBASE
  21.  
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <math.h>
  25. #include <exec/types.h>
  26. #include <exec/execbase.h>
  27. #include <graphics/monitor.h>
  28. #include <graphics/gfxbase.h>
  29. #include <proto/dos.h>
  30. #include <proto/exec.h>
  31. #include <proto/graphics.h>
  32.  
  33. #define BOLD_ON         "\x1b[1m"
  34. #define BOLD_OFF        "\x1b[22m"
  35. #define UNDERLINE_ON    "\x1b[4m"
  36. #define UNDERLINE_OFF   "\x1b[24m"
  37.  
  38. extern long __oslibversion = 37;
  39.  
  40. static char version[] = "$VER: MonitorInfo V37.4 (1994-04-09)";
  41.  
  42. static char *beamcon0defs[16] =
  43. {
  44.    "HSYNCTRUE   - horizontal sync true",
  45.    "VSYNCTRUE   - vertical sync true",
  46.    "CSYNCTRUE   - composite sync true",
  47.    "CSBLANK     - composite blank out to /CSY pin (ECS), unused (AA)",
  48.    "VARCSYNC    - variable composite sync enabled",
  49.    "DISPLAYPAL  - uses PAL color encoding",
  50.    "DISPLAYDUAL - uses both UHRES and standard pointers",
  51.    "VARBEAM     - variable beam counter enabled",
  52.    "VARHSYNC    - variable horizontal sync enabled",
  53.    "VARVSYNC    - variable vertical sync enabled",
  54.    "CSCBLANKEN  - redirect composite sync",
  55.    "LOLDIS      - long display lines disabled",
  56.    "VARVBLANK   - variable vertical blank enabled",
  57.    "LPENDIS     - disable lightpen position latch",
  58.    "HARDDIS     - disable hardwired display window limits",
  59.    NULL
  60. };
  61.  
  62. void main(void)
  63. {
  64.    struct MonitorSpec *mspec;
  65.    struct SpecialMonitor *sm;
  66.    float base_frequency, v_freq;
  67.    float ratioh, ratiov;
  68.    float color_clock;
  69.    UWORD i,j;
  70.    char **monitorName;
  71.    int numMonitors = 0;
  72.    BOOL rawmode = FALSE;
  73.    static char template[] = "MONITORS/M,LIST/S,RAW/S";
  74.    LONG values[3] = {0,0,0};
  75.    struct RDArgs *ra;
  76.    long rc = RETURN_OK;
  77.    
  78.    printf("\n" BOLD_ON "%s" BOLD_OFF "   by Gregor S. M. Kuhlmann\n\n",&version[6]);
  79.    
  80.    if (ra=ReadArgs(template,values,0))
  81.    {   
  82.       if ((values[1]) || (values[0]==NULL))
  83.       {   
  84.          ObtainSemaphoreShared(GfxBase->MonitorListSemaphore);
  85.          printf(BOLD_ON UNDERLINE_ON "Currently installed monitors:" BOLD_OFF UNDERLINE_OFF "\n");
  86.          mspec = (struct MonitorSpec *)GfxBase->MonitorList.lh_Head;
  87.          while (mspec->ms_Node.xln_Succ)
  88.          {
  89.             numMonitors++;
  90.             printf("%s\n",mspec->ms_Node.xln_Name);
  91.             mspec=(struct MonitorSpec *)mspec->ms_Node.xln_Succ;
  92.          }
  93.          if (numMonitors==0)
  94.          {
  95.             printf("< NONE >\n");
  96.          }
  97.          printf("\n");
  98.          ReleaseSemaphore(GfxBase->MonitorListSemaphore);
  99.       }
  100.       else 
  101.       {  
  102.          if (values[2])
  103.          {
  104.             rawmode=TRUE;
  105.          }
  106.          monitorName=(char**)values[0];
  107.          while(*monitorName)
  108.          {
  109.             if (mspec=OpenMonitor(*monitorName,0L))
  110.             {
  111.                printf(BOLD_ON UNDERLINE_ON "Information for '%s':" BOLD_OFF UNDERLINE_OFF "\n\n",*monitorName);
  112. /*--- determine color clock period display mode ---*/
  113.                color_clock = 1.0 / (5 * SysBase->ex_EClockFrequency);
  114. /*--- print scan rates ---*/
  115.                printf(BOLD_ON "Display scan rates:" BOLD_OFF "\n");
  116.                base_frequency = 1.0 / (mspec->total_colorclocks * color_clock);
  117.                ratioh=mspec->ratioh/16.0;
  118.                ratiov=mspec->ratiov/16.0;
  119.                v_freq = base_frequency / mspec->total_rows;
  120.                printf("horizontal sweep rate = %.2f kHz (scanline period = %.2f µs)\n",
  121.                      base_frequency / 1000.0, (1.0 / base_frequency) * 1e6);
  122.                printf("vertical sweep rate = %.2f Hz\n",v_freq);
  123.                printf("lores pixel aspect ratio (w/h) = %.3f\n\n",ratiov/ratioh);
  124. /*--- print analogsignal properties ---*/
  125.                if (sm=mspec->ms_Special)
  126.                {
  127.                   if (rawmode)
  128.                   {
  129.                      printf(BOLD_ON "hardware sync/blank values:" BOLD_OFF "\n");
  130.                      printf("HBSTRT=%d, HSSTRT=%d, HSSTOP=%d, HBSTOP=%d\n",
  131.                      sm->hblank.asi_Start,sm->hsync.asi_Start,sm->hsync.asi_Stop,sm->hblank.asi_Stop);
  132.                      printf("VBSTRT=%d, VSSTRT=%d, VSSTOP=%d, VBSTOP=%d\n\n",
  133.                      sm->vblank.asi_Start,sm->vsync.asi_Start,sm->vsync.asi_Stop,sm->vblank.asi_Stop);
  134.                   }     
  135.                   else
  136.                   {
  137.                      printf(BOLD_ON "special signal timing info:" BOLD_OFF "\n");
  138.                      printf("horizontal blanking period: %.2f µs\n",
  139.                         (sm->hblank.asi_Stop-sm->hblank.asi_Start) * color_clock * 1e6);
  140.                      printf("horizontal sync period: %.2f µs (delay = %.2f µs)\n",
  141.                         (sm->hsync.asi_Stop-sm->hsync.asi_Start) * color_clock * 1e6,
  142.                         (sm->hsync.asi_Start - sm->hblank.asi_Start) * color_clock * 1e6);
  143.                      printf("vertical blanking period: %.2f µs\n", 
  144.                         (sm->vblank.asi_Stop-sm->vblank.asi_Start) * color_clock * 1e6);
  145.                      printf("vertical sync period: %.2f µs (delay = %.2f µs)\n\n",
  146.                         (sm->vsync.asi_Stop-sm->vsync.asi_Start ) * color_clock * 1e6,
  147.                         (sm->vsync.asi_Start - sm->vblank.asi_Start) * color_clock * 1e6);
  148.                   }
  149.                }
  150. /*--- print beamcon properties ---*/               
  151.                printf(BOLD_ON "signal properties" BOLD_OFF " (0x%0.4x):\n",mspec->BeamCon0);
  152.                for (i=0;i<16;i++)
  153.                {
  154.                   if (mspec->BeamCon0 & (1<<i))
  155.                   {
  156.                      if (beamcon0defs[i])
  157.                         printf("%s\n",beamcon0defs[i]);
  158.                      else
  159.                         printf("(#%d)\n",i);
  160.                   }
  161.                }
  162.                printf("\n");
  163.                CloseMonitor(mspec);
  164.             }
  165.             else
  166.             {
  167.                printf("ERROR: Couldn't open monitor '%s'\n",*monitorName);
  168.                break;
  169.             }
  170.             monitorName++;
  171.          }
  172.       }
  173.    }
  174.    else
  175.    {
  176.       printf("ERROR: Arguments not suitable for template:\n%s\n",template);
  177.       rc=RETURN_ERROR;
  178.    }
  179.    exit(rc);
  180. }
  181.