home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 106 / EnigmaAmiga106CD.iso / software / sviluppo / ahisrc / addaudiomodes / addaudiomodes.c next >
Encoding:
C/C++ Source or Header  |  1999-04-22  |  7.4 KB  |  302 lines

  1. /*
  2.      AddAudioModes - Manipulates AHI's audio mode database 
  3.      Copyright (C) 1996-1999 Martin Blom <martin@blom.org>
  4.      
  5.      This program is free software; you can redistribute it and/or
  6.      modify it under the terms of the GNU General Public License
  7.      as published by the Free Software Foundation; either version 2
  8.      of the License, or (at your option) any later version.
  9.      
  10.      This program is distributed in the hope that it will be useful,
  11.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.      GNU General Public License for more details.
  14.      
  15.      You should have received a copy of the GNU General Public License
  16.      along with this program; if not, write to the Free Software
  17.      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19.  
  20. /* $Id: AddAudioModes.c,v 4.6 1999/04/22 19:41:29 lcs Exp $
  21. * $Log: AddAudioModes.c,v $
  22. * Revision 4.6  1999/04/22 19:41:29  lcs
  23. * Removed SAS/C smakefile.
  24. * I had the copyright date screwed up: Changed to 1996-1999 (which is only
  25. * partly correct, but still better than 1997-1999....)
  26. *
  27. * Revision 4.5  1999/03/28 22:31:15  lcs
  28. * AHI is now GPL/LGPL software.
  29. * Make target bindist work correctly when using a separate build directory.
  30. * Small first steps towards a WarpOS PPC version.
  31. *
  32. * Revision 4.4  1999/01/09 23:18:37  lcs
  33. * Bigger, better, and greater?
  34. *
  35. * Revision 4.3  1999/01/08 23:42:55  lcs
  36. * Switched to gcc and GNU make.
  37. * Clean-up in source code.
  38. *
  39. * Revision 4.2  1998/03/11 12:31:57  lcs
  40. * Added hardware-banging code to force VGA mode.
  41. *
  42. * Revision 4.1  1997/04/02 22:44:22  lcs
  43. * Bumped to version 4
  44. *
  45. * Revision 1.5  1997/02/18 22:24:45  lcs
  46. * Better DBLSCAN handling.
  47. * The device is now opened with the AHIDF_NOMODESCAN flag.
  48. *
  49. * Revision 1.2  1997/01/04 00:24:51  lcs
  50. * Added DBLSCAN switch + some other small changes
  51. *
  52. */
  53.  
  54. #include <config.h>
  55.  
  56. #include <devices/ahi.h>
  57. #include <graphics/modeid.h>
  58. #include <graphics/gfxbase.h>
  59. #include <intuition/screens.h>
  60. #include <proto/ahi.h>
  61. #include <proto/dos.h>
  62. #include <proto/exec.h>
  63. #include <proto/graphics.h>
  64. #include <proto/intuition.h>
  65. #include <stdlib.h>
  66.  
  67. #include "version.h"
  68.  
  69. struct Library    *AHIBase   = NULL;
  70. struct MsgPort    *AHImp     = NULL;
  71. struct AHIRequest *AHIio     = NULL;
  72. BYTE               AHIDevice = -1;
  73.  
  74. static const char version[] = "$VER: AddAudioModes " VERS "\n\r";
  75.  
  76. #define AHIVERSION 4
  77. LONG __OSlibversion = 37;
  78.  
  79. #define TEMPLATE "FILES/M,QUIET/S,REFRESH/S,REMOVE/S,DBLSCAN/S"
  80.  
  81. struct {
  82.   STRPTR *files;
  83.   ULONG   quiet;
  84.   ULONG   refresh;
  85.   ULONG   remove;
  86.   ULONG   dblscan;
  87. } args = {NULL, FALSE, FALSE, FALSE, FALSE};
  88.  
  89.  
  90. void
  91. cleanup( int rc )
  92. {
  93.   if( AHIDevice == 0 )
  94.   {
  95.     CloseDevice( (struct IORequest *) AHIio );
  96.   }
  97.  
  98.   DeleteIORequest( (struct IORequest *) AHIio);
  99.   DeleteMsgPort( AHImp );
  100.  
  101.   exit( rc );
  102. }
  103.  
  104.  
  105. void
  106. OpenAHI( void )
  107. {
  108.   if( AHIDevice != 0 )
  109.   {
  110.     AHImp = CreateMsgPort();
  111.  
  112.     if( AHImp != NULL )
  113.     {
  114.       AHIio = (struct AHIRequest *)
  115.                   CreateIORequest( AHImp, sizeof( struct AHIRequest ) );
  116.  
  117.       if( AHIio != NULL )
  118.       {
  119.         AHIio->ahir_Version = AHIVERSION;
  120.  
  121.         AHIDevice = OpenDevice( AHINAME, 
  122.                                 AHI_NO_UNIT,
  123.                                 (struct IORequest *) AHIio,
  124.                                 AHIDF_NOMODESCAN );
  125.       }
  126.     }
  127.  
  128.     if( AHIDevice != 0 )
  129.     {
  130.       Printf( "Unable to open %s version %ld\n", (ULONG) AHINAME, AHIVERSION );
  131.       cleanup( RETURN_FAIL );
  132.     }
  133.  
  134.     AHIBase = (struct Library *) AHIio->ahir_Std.io_Device;
  135.   }
  136. }
  137.  
  138.  
  139. int
  140. main( void )
  141. {
  142.   struct RDArgs *rdargs;
  143.   int            rc = RETURN_OK;
  144.  
  145.   rdargs = ReadArgs( TEMPLATE , (LONG *) &args, NULL );
  146.  
  147.   if( rdargs != NULL )
  148.   {
  149.     /* Refresh database */
  150.  
  151.     if( args.refresh && !args.remove )
  152.     {
  153.       OpenAHI();
  154.       
  155.       if( !AHI_LoadModeFile( "DEVS:AudioModes" ) && !args.quiet )
  156.       {
  157.         PrintFault( IoErr(), "DEVS:AudioModes" );
  158.         rc = RETURN_ERROR;
  159.       }
  160.     }
  161.  
  162.     /* Load mode files */
  163.  
  164.     if( args.files != NULL && !args.remove )
  165.     {
  166.       int i = 0;
  167.  
  168.       OpenAHI();
  169.  
  170.       while( args.files[i] )
  171.       {
  172.         if( !AHI_LoadModeFile( args.files[i] ) && !args.quiet )
  173.         {
  174.           PrintFault( IoErr(), args.files[i] );
  175.           rc = RETURN_ERROR;
  176.         }
  177.         i++;
  178.       }
  179.     }
  180.  
  181.     /* Remove database */
  182.  
  183.     if( args.remove )
  184.     {
  185.       if( args.files || args.refresh )
  186.       {
  187.         PutStr( "The REMOVE switch cannot be used together with FILES or REFRESH.\n" );
  188.         rc = RETURN_FAIL;
  189.       }
  190.       else
  191.       {
  192.         ULONG id;
  193.  
  194.         OpenAHI();
  195.  
  196.         for( id = AHI_NextAudioID( AHI_INVALID_ID );
  197.              id != AHI_INVALID_ID;
  198.              id = AHI_NextAudioID( AHI_INVALID_ID ) )
  199.         {
  200.           AHI_RemoveAudioMode( id );
  201.         }
  202.       }
  203.     }
  204.  
  205.     /* Make display mode doublescan (allowing > 28 kHz sample rates) */
  206.  
  207.     if( args.dblscan )
  208.     {
  209.       ULONG          id;
  210.       ULONG          bestid = INVALID_ID;
  211.       int            minper = MAXINT;
  212.       struct Screen *screen = NULL;
  213.  
  214.       static const struct ColorSpec colorspecs[] =
  215.       {
  216.         { 0, 0, 0, 0 },
  217.         { 1, 0, 0, 0 },
  218.         {-1, 0, 0, 0 }
  219.       };
  220.       
  221.       union {
  222.         struct MonitorInfo mon;
  223.         struct DisplayInfo dis;
  224.       } buffer;
  225.  
  226.       for( id = NextDisplayInfo( INVALID_ID );
  227.            id != (ULONG) INVALID_ID;
  228.            id = NextDisplayInfo( id ) )
  229.       {
  230.         int period;
  231.  
  232.         if( GetDisplayInfoData( NULL, 
  233.                                 (UBYTE*) &buffer.dis, sizeof(buffer.dis),
  234.                                 DTAG_DISP, id ) )
  235.         {
  236.           if( !(buffer.dis.PropertyFlags & (DIPF_IS_ECS | DIPF_IS_AA ) ) )
  237.           {
  238.             continue;
  239.           }
  240.         }
  241.  
  242.         if( GetDisplayInfoData( NULL,
  243.                                 (UBYTE*) &buffer.mon, sizeof(buffer.mon),
  244.                                 DTAG_MNTR, id ) )
  245.         {
  246.           period = buffer.mon.TotalColorClocks * buffer.mon.TotalRows
  247.                    / ( 2 * ( buffer.mon.TotalRows - buffer.mon.MinRow + 1 ) );
  248.  
  249.           if( period < minper )
  250.           {
  251.             minper = period;
  252.             bestid = id;
  253.           }
  254.         }
  255.  
  256.       }
  257.  
  258.       if( bestid != (ULONG) INVALID_ID && minper < 100 )
  259.       {
  260.         screen = OpenScreenTags( NULL,
  261.                                  SA_DisplayID,  bestid,
  262.                                  SA_Colors,    (ULONG) &colorspecs,
  263.                                  TAG_DONE );
  264.       }
  265.       else if( ( GfxBase->ChipRevBits0 & (GFXF_HR_DENISE | GFXF_AA_LISA ) ) != 0 )
  266.       {
  267.         /* No suitable screen mode found, let's bang the hardware...
  268.            Using code from Sebastiano Vigna <vigna@eolo.usr.dsi.unimi.it>. */
  269.  
  270.         extern struct Custom custom;
  271.  
  272.         custom.bplcon0  = 0x8211;
  273.         custom.ddfstrt  = 0x0018;
  274.         custom.ddfstop  = 0x0058;
  275.         custom.hbstrt   = 0x0009;
  276.         custom.hsstop   = 0x0017;
  277.         custom.hbstop   = 0x0021;
  278.         custom.htotal   = 0x0071;
  279.         custom.vbstrt   = 0x0000;
  280.         custom.vsstrt   = 0x0003;
  281.         custom.vsstop   = 0x0005;
  282.         custom.vbstop   = 0x001D;
  283.         custom.vtotal   = 0x020E;
  284.         custom.beamcon0 = 0x0B88;
  285.         custom.bplcon1  = 0x0000;
  286.         custom.bplcon2  = 0x027F;
  287.         custom.bplcon3  = 0x00A3;
  288.         custom.bplcon4  = 0x0011;
  289.       }
  290.  
  291.       if( screen != NULL )
  292.       {
  293.         CloseScreen( screen );
  294.       }
  295.     }
  296.  
  297.     FreeArgs( rdargs );
  298.   }
  299.  
  300.   cleanup( rc );
  301. }
  302.