Example #1
0
struct WCSScreenMode *ModeList_New(void)
{
struct NameInfo ModeName;
struct DisplayInfo Properties;
struct DimensionInfo Sizes;
struct WCSScreenMode *ModeList, *ThisMode, *Sort, DummyFirst;
ULONG DInfoID;
int Order;

DummyFirst.Next = NULL;

ThisMode = NULL;
ModeList = &DummyFirst;
DInfoID = INVALID_ID;
DInfoID = NextDisplayInfo(DInfoID);
while (DInfoID != INVALID_ID)
 {
 if(!(ModeNotAvailable(DInfoID)))
  {
  if(GetDisplayInfoData(NULL, (UBYTE *)&ModeName, sizeof(ModeName),
   DTAG_NAME, DInfoID))
   {
   if(GetDisplayInfoData(NULL, (UBYTE *)&Sizes, sizeof(Sizes),
    DTAG_DIMS, DInfoID))
    {
    if((Sizes.StdOScan.MaxX - Sizes.StdOScan.MinX + 1 >= 500) &&
     (Sizes.StdOScan.MaxY - Sizes.StdOScan.MinY + 1 >= 300) && (Sizes.MaxDepth >= 4))
     {
     if(ThisMode = get_Memory(sizeof(struct WCSScreenMode), MEMF_CLEAR))
      {
      ThisMode->ModeID = DInfoID;
      strcpy(ThisMode->ModeName, ModeName.Name);
      ThisMode->X  = ThisMode->UX = ThisMode->OX =Sizes.Nominal.MaxX - Sizes.Nominal.MinX + 1;
      ThisMode->Y  = ThisMode->UY = ThisMode->OY =Sizes.Nominal.MaxY - Sizes.Nominal.MinY + 1;
      ThisMode->OScans[0].x = Sizes.TxtOScan.MaxX - Sizes.TxtOScan.MinX + 1;
      ThisMode->OScans[0].y = Sizes.TxtOScan.MaxY - Sizes.TxtOScan.MinY + 1;
      ThisMode->OScans[1].x = Sizes.StdOScan.MaxX - Sizes.StdOScan.MinX + 1;
      ThisMode->OScans[1].y = Sizes.StdOScan.MaxY - Sizes.StdOScan.MinY + 1;
      ThisMode->OScans[2].x = Sizes.MaxOScan.MaxX - Sizes.MaxOScan.MinX + 1;
      ThisMode->OScans[2].y = Sizes.MaxOScan.MaxY - Sizes.MaxOScan.MinY + 1;
      ThisMode->OScans[3].x = Sizes.VideoOScan.MaxX - Sizes.VideoOScan.MinX + 1;
      ThisMode->OScans[3].y = Sizes.VideoOScan.MaxY - Sizes.VideoOScan.MinY + 1;
      ThisMode->MaxX = Sizes.MaxRasterWidth;
      ThisMode->MaxY = Sizes.MaxRasterHeight;
      if(GetDisplayInfoData(NULL, (UBYTE *)&Properties, sizeof(Properties),
       DTAG_DISP, DInfoID))
       {
       ThisMode->PropertyFlags = Properties.PropertyFlags;
       ThisMode->PixelSpeed = Properties.PixelSpeed;
       } /* if */
      for(Sort = ModeList; Sort;)
       {
       if(Sort->Next)
        {
        Order = stricmp(Sort->Next->ModeName, ThisMode->ModeName);
        if (Order > 0)
         {
         ThisMode->Next = Sort->Next;
         Sort->Next = ThisMode;
         Sort = NULL; /* We're done. */
         } /* else */
        else if (Order == 0)
         {
         /* We already have an entry by that name, don't
         ** bother adding a new one. Break out. */
         free_Memory(ThisMode, sizeof(struct WCSScreenMode));
         Sort = NULL;
         } /* else */ 
        } /* if */
       else
        {
/*        ThisMode->Next = NULL; */ /* Unnecessary: MEMF_CLEAR */
        Sort->Next = ThisMode;
        Sort = NULL; /* break out */
        } /* else */
       if(Sort) /* prevent many fine enforcer hits */
        {
        Sort = Sort->Next;
        } /* if */
       } /* for */
      } /* if */
     } /* if */
    } /* if */
   } /* if */
  } /* if */
 
 DInfoID = NextDisplayInfo(DInfoID);
 } /* while */

ModeList = ModeList->Next; /* Pull off DummyFirst */
    
return(ModeList);
} /* ModeList_New() */
int
main( void )
{
  struct RDArgs *rdargs;
  int            rc = RETURN_OK;

  GfxBase       = (struct GfxBase *) OpenLibrary( GRAPHICSNAME, 37 );
  IntuitionBase = (struct IntuitionBase *) OpenLibrary( "intuition.library", 37 );
  
  if( GfxBase == NULL )
  {
    Printf( "Unable to open %s version %ld\n", (ULONG) GRAPHICSNAME, 37 );
    cleanup();
    return RETURN_FAIL;
  }

  if( IntuitionBase == NULL )
  {
    Printf( "Unable to open %s version %ld\n", (ULONG) "intuition.library", 37 );
    cleanup();
    return RETURN_FAIL;
  }

  rdargs = ReadArgs( TEMPLATE , (LONG *) &args, NULL );

  if( rdargs != NULL )
  {
    /* Refresh database */

    if( args.refresh && !args.remove )
    {
      ULONG id;

      OpenAHI();

      /* First, empty the database */
      
      for( id = AHI_NextAudioID( AHI_INVALID_ID );
           id != (ULONG) AHI_INVALID_ID;
           id = AHI_NextAudioID( AHI_INVALID_ID ) )
      {
        AHI_RemoveAudioMode( id );
      }

      /* Now add all modes */

      if( !AHI_LoadModeFile( "DEVS:AudioModes" ) )
      {
        if( IS_MORPHOS )
        {
          ULONG res;

          /* Be quiet here. - Piru */
          APTR *windowptr = &((struct Process *) FindTask(NULL))->pr_WindowPtr;
          APTR oldwindowptr = *windowptr;
          *windowptr = (APTR) -1;
          res = AHI_LoadModeFile( "MOSSYS:DEVS/AudioModes" );
          *windowptr = oldwindowptr;

          if( !res )
          {
            if( !args.quiet )
            {
              PrintFault( IoErr(), "AudioModes" );
            }

            rc = RETURN_ERROR;
          }
        }
        else
        {
          if ( !args.quiet )
          {
            PrintFault( IoErr(), "DEVS:AudioModes" );
          }

          rc = RETURN_ERROR;
        }
      }
    }

    /* Load mode files */

    if( args.files != NULL && !args.remove )
    {
      int i = 0;

      OpenAHI();

      while( args.files[i] )
      {
        if( !AHI_LoadModeFile( args.files[i] ) && !args.quiet )
        {
          PrintFault( IoErr(), args.files[i] );
          rc = RETURN_ERROR;
        }
        i++;
      }
    }

    /* Remove database */

    if( args.remove )
    {
      if( args.files || args.refresh )
      {
        PutStr( "The REMOVE switch cannot be used together with FILES or REFRESH.\n" );
        rc = RETURN_FAIL;
      }
      else
      {
        ULONG id;

        OpenAHI();

        for( id = AHI_NextAudioID( AHI_INVALID_ID );
             id != (ULONG) AHI_INVALID_ID;
             id = AHI_NextAudioID( AHI_INVALID_ID ) )
        {
          AHI_RemoveAudioMode( id );
        }
      }
    }

    /* Make display mode doublescan (allowing > 28 kHz sample rates) */

    if( args.dblscan )
    {
      ULONG          id;
      ULONG          bestid = INVALID_ID;
      int            minper = INT_MAX;
      struct Screen *screen = NULL;

      static const struct ColorSpec colorspecs[] =
      {
        { 0, 0, 0, 0 },
        { 1, 0, 0, 0 },
        {-1, 0, 0, 0 }
      };
      
      union {
        struct MonitorInfo mon;
        struct DisplayInfo dis;
      } buffer;

      for( id = NextDisplayInfo( INVALID_ID );
           id != (ULONG) INVALID_ID;
           id = NextDisplayInfo( id ) )
      {
        int period;

        if( GetDisplayInfoData( NULL, 
                                (UBYTE*) &buffer.dis, sizeof(buffer.dis),
                                DTAG_DISP, id ) )
        {
          if( !(buffer.dis.PropertyFlags & (DIPF_IS_ECS | DIPF_IS_AA ) ) )
          {
            continue;
          }
        }

        if( GetDisplayInfoData( NULL,
                                (UBYTE*) &buffer.mon, sizeof(buffer.mon),
                                DTAG_MNTR, id ) )
        {
          period = buffer.mon.TotalColorClocks * buffer.mon.TotalRows
                   / ( 2 * ( buffer.mon.TotalRows - buffer.mon.MinRow + 1 ) );

          if( period < minper )
          {
            minper = period;
            bestid = id;
          }
        }

      }

      if( bestid != (ULONG) INVALID_ID && minper < 100 )
      {
        screen = OpenScreenTags( NULL,
                                 SA_DisplayID,  bestid,
                                 SA_Colors,    (ULONG) &colorspecs,
                                 TAG_DONE );
      }
      else if( ( GfxBase->ChipRevBits0 & (GFXF_HR_DENISE | GFXF_AA_LISA ) ) != 0 )
      {
        /* No suitable screen mode found, let's bang the hardware...
           Using code from Sebastiano Vigna <*****@*****.**>. */

        struct Custom *custom = (struct Custom *) 0xdff000;

        custom->bplcon0  = 0x8211;
        custom->ddfstrt  = 0x0018;
        custom->ddfstop  = 0x0058;
        custom->hbstrt   = 0x0009;
        custom->hsstop   = 0x0017;
        custom->hbstop   = 0x0021;
        custom->htotal   = 0x0071;
        custom->vbstrt   = 0x0000;
        custom->vsstrt   = 0x0003;
        custom->vsstop   = 0x0005;
        custom->vbstop   = 0x001D;
        custom->vtotal   = 0x020E;
        custom->beamcon0 = 0x0B88;
        custom->bplcon1  = 0x0000;
        custom->bplcon2  = 0x027F;
        custom->bplcon3  = 0x00A3;
        custom->bplcon4  = 0x0011;
      }

      if( screen != NULL )
      {
        CloseScreen( screen );
      }
    }

    FreeArgs( rdargs );
  }

  cleanup();
  return rc;
}
int
main( void )
{
  struct RDArgs *rdargs;
  int            rc = RETURN_OK;

  rdargs = ReadArgs( TEMPLATE , (LONG *) &args, NULL );

  if( rdargs != NULL )
  {
    /* Refresh database */

    if( args.refresh && !args.remove )
    {
      OpenAHI();
      
      if( !AHI_LoadModeFile( "DEVS:AudioModes" ) && !args.quiet )
      {
        PrintFault( IoErr(), "DEVS:AudioModes" );
        rc = RETURN_ERROR;
      }
    }

    /* Load mode files */

    if( args.files != NULL && !args.remove )
    {
      int i = 0;

      OpenAHI();

      while( args.files[i] )
      {
        if( !AHI_LoadModeFile( args.files[i] ) && !args.quiet )
        {
          PrintFault( IoErr(), args.files[i] );
          rc = RETURN_ERROR;
        }
        i++;
      }
    }

    /* Remove database */

    if( args.remove )
    {
      if( args.files || args.refresh )
      {
        PutStr( "The REMOVE switch cannot be used together with FILES or REFRESH.\n" );
        rc = RETURN_FAIL;
      }
      else
      {
        ULONG id;

        OpenAHI();

        for( id = AHI_NextAudioID( AHI_INVALID_ID );
             id != AHI_INVALID_ID;
             id = AHI_NextAudioID( AHI_INVALID_ID ) )
        {
          AHI_RemoveAudioMode( id );
        }
      }
    }

    /* Make display mode doublescan (allowing > 28 kHz sample rates) */

    if( args.dblscan )
    {
      ULONG          id;
      ULONG          bestid = INVALID_ID;
      int            minper = MAXINT;
      struct Screen *screen = NULL;

      static const struct ColorSpec colorspecs[] =
      {
        { 0, 0, 0, 0 },
        { 1, 0, 0, 0 },
        {-1, 0, 0, 0 }
      };
      
      union {
        struct MonitorInfo mon;
        struct DisplayInfo dis;
      } buffer;

      for( id = NextDisplayInfo( INVALID_ID );
           id != (ULONG) INVALID_ID;
           id = NextDisplayInfo( id ) )
      {
        int period;

        if( GetDisplayInfoData( NULL, 
                                (UBYTE*) &buffer.dis, sizeof(buffer.dis),
                                DTAG_DISP, id ) )
        {
          if( !(buffer.dis.PropertyFlags & (DIPF_IS_ECS | DIPF_IS_AA ) ) )
          {
            continue;
          }
        }

        if( GetDisplayInfoData( NULL,
                                (UBYTE*) &buffer.mon, sizeof(buffer.mon),
                                DTAG_MNTR, id ) )
        {
          period = buffer.mon.TotalColorClocks * buffer.mon.TotalRows
                   / ( 2 * ( buffer.mon.TotalRows - buffer.mon.MinRow + 1 ) );

          if( period < minper )
          {
            minper = period;
            bestid = id;
          }
        }

      }

      if( bestid != (ULONG) INVALID_ID && minper < 100 )
      {
        screen = OpenScreenTags( NULL,
                                 SA_DisplayID,  bestid,
                                 SA_Colors,    (ULONG) &colorspecs,
                                 TAG_DONE );
      }
      else if( ( GfxBase->ChipRevBits0 & (GFXF_HR_DENISE | GFXF_AA_LISA ) ) != 0 )
      {
        /* No suitable screen mode found, let's bang the hardware...
           Using code from Sebastiano Vigna <*****@*****.**>. */

        extern struct Custom custom;

        custom.bplcon0  = 0x8211;
        custom.ddfstrt  = 0x0018;
        custom.ddfstop  = 0x0058;
        custom.hbstrt   = 0x0009;
        custom.hsstop   = 0x0017;
        custom.hbstop   = 0x0021;
        custom.htotal   = 0x0071;
        custom.vbstrt   = 0x0000;
        custom.vsstrt   = 0x0003;
        custom.vsstop   = 0x0005;
        custom.vbstop   = 0x001D;
        custom.vtotal   = 0x020E;
        custom.beamcon0 = 0x0B88;
        custom.bplcon1  = 0x0000;
        custom.bplcon2  = 0x027F;
        custom.bplcon3  = 0x00A3;
        custom.bplcon4  = 0x0011;
      }

      if( screen != NULL )
      {
        CloseScreen( screen );
      }
    }

    FreeArgs( rdargs );
  }

  cleanup( rc );
}
int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
{
    ULONG modeID;
    int   w, h, r, g, b, bpp, m1, m2, i, j, count;

    count  = 0;
    modeID = INVALID_ID;
    do
    {
        // Enumarate all ModeIDs with NextDisplayInfo
        modeID = NextDisplayInfo( modeID );
        if( modeID != INVALID_ID )
        {
            // Get related video mode information
            _glfwGetModeIDInfo( modeID, &w, &h, &r, &g, &b, NULL );

            // Convert RGB to BPP
            bpp = r + g + b;

            // We only support true-color modes, which means at least 15
            // bits per pixel (reasonable?) - Sorry, AGA users!
            if( bpp >= 15 )
            {
                // Mode "code" for this mode
                m1 = (bpp << 25) | (w*h);

                // Insert mode in list (sorted), and avoid duplicates
                for( i = 0; i < count; i ++ )
                {
                    // Mode "code" for already listed mode
                    bpp = list[i].RedBits + list[i].GreenBits +
                          list[i].BlueBits;
                    m2 = (bpp << 25) | (list[i].Width * list[i].Height);
                    if( m1 <= m2 )
                    {
                        break;
                    }
                }

                // New entry at the end of the list?
                if( i >= count )
                {
                    list[count].Width     = w;
                    list[count].Height    = h;
                    list[count].RedBits   = r;
                    list[count].GreenBits = g;
                    list[count].BlueBits  = b;
                    count ++;
                }
                // Insert new entry in the list?
                else if( m1 < m2 )
                {
                    for( j = count; j > i; j -- )
                    {
                        list[j] = list[j-1];
                    }
                    list[i].Width     = w;
                    list[i].Height    = h;
                    list[i].RedBits   = r;
                    list[i].GreenBits = g;
                    list[i].BlueBits  = b;
                    count ++;
                }
            }
        }
    }
    while( modeID != INVALID_ID && count < maxcount );

    return count;
}