2 AddAudioModes - Manipulates AHI's audio mode database
3 Copyright (C) 1996-2005 Martin Blom <martin@blom.org>
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.
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.
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.
22 #include <devices/ahi.h>
23 #include <graphics/modeid.h>
24 #include <graphics/gfxbase.h>
25 #include <intuition/screens.h>
26 #include <proto/ahi.h>
27 #include <proto/dos.h>
28 #include <proto/exec.h>
29 #include <proto/graphics.h>
30 #include <proto/intuition.h>
36 struct GfxBase
*GfxBase
= NULL
;
37 struct IntuitionBase
*IntuitionBase
= NULL
;
38 struct Library
*AHIBase
= NULL
;
39 struct MsgPort
*AHImp
= NULL
;
40 struct AHIRequest
*AHIio
= NULL
;
44 struct AHIIFace
*IAHI
= NULL
;
47 const char version
[] = "$VER: AddAudioModes " VERS
"\n\r";
51 #define TEMPLATE "FILES/M,QUIET/S,REFRESH/S,REMOVE/S,DBLSCAN/S"
59 } args
= {NULL
, FALSE
, FALSE
, FALSE
, FALSE
};
71 DropInterface((struct Interface
*) IAHI
);
76 CloseDevice( (struct IORequest
*) AHIio
);
79 DeleteIORequest( (struct IORequest
*) AHIio
);
80 DeleteMsgPort( AHImp
);
82 CloseLibrary( (struct Library
*) IntuitionBase
);
83 CloseLibrary( (struct Library
*) GfxBase
);
92 AHImp
= CreateMsgPort();
96 AHIio
= (struct AHIRequest
*)
97 CreateIORequest( AHImp
, sizeof( struct AHIRequest
) );
101 AHIio
->ahir_Version
= AHIVERSION
;
103 AHIDevice
= OpenDevice( AHINAME
,
105 (struct IORequest
*) AHIio
,
112 Printf( "Unable to open %s version %ld\n", AHINAME
, AHIVERSION
);
117 AHIBase
= (struct Library
*) AHIio
->ahir_Std
.io_Device
;
120 IAHI
= (struct AHIIFace
*) GetInterface(AHIBase
, "main", 1, NULL
);
125 // Disable command line processing
126 const long __nocommandline
=1;
131 struct RDArgs
*rdargs
;
134 GfxBase
= (struct GfxBase
*) OpenLibrary( GRAPHICSNAME
, 37 );
135 IntuitionBase
= (struct IntuitionBase
*) OpenLibrary( "intuition.library", 37 );
137 if( GfxBase
== NULL
)
139 Printf( "Unable to open %s version %ld\n", GRAPHICSNAME
, 37 );
144 if( IntuitionBase
== NULL
)
146 Printf( "Unable to open %s version %ld\n", "intuition.library", 37 );
151 rdargs
= ReadArgs( TEMPLATE
, (SIPTR
*) &args
, NULL
);
155 /* Refresh database */
157 if( args
.refresh
&& !args
.remove
)
163 /* First, empty the database */
165 for( id
= AHI_NextAudioID( AHI_INVALID_ID
);
166 id
!= (ULONG
) AHI_INVALID_ID
;
167 id
= AHI_NextAudioID( AHI_INVALID_ID
) )
169 AHI_RemoveAudioMode( id
);
172 /* Now add all modes */
174 if( !AHI_LoadModeFile( "DEVS:AudioModes" ) )
180 /* Be quiet here. - Piru */
181 APTR
*windowptr
= &((struct Process
*) FindTask(NULL
))->pr_WindowPtr
;
182 APTR oldwindowptr
= *windowptr
;
183 *windowptr
= (APTR
) -1;
184 res
= AHI_LoadModeFile( "MOSSYS:DEVS/AudioModes" );
185 *windowptr
= oldwindowptr
;
191 PrintFault( IoErr(), "AudioModes" );
201 PrintFault( IoErr(), "DEVS:AudioModes" );
209 /* Load mode files */
211 if( args
.files
!= NULL
&& !args
.remove
)
217 while( args
.files
[i
] )
219 if( !AHI_LoadModeFile( args
.files
[i
] ) && !args
.quiet
)
221 PrintFault( IoErr(), args
.files
[i
] );
228 /* Remove database */
232 if( args
.files
|| args
.refresh
)
234 PutStr( "The REMOVE switch cannot be used together with FILES or REFRESH.\n" );
243 for( id
= AHI_NextAudioID( AHI_INVALID_ID
);
244 id
!= (ULONG
) AHI_INVALID_ID
;
245 id
= AHI_NextAudioID( AHI_INVALID_ID
) )
247 AHI_RemoveAudioMode( id
);
252 /* Make display mode doublescan (allowing > 28 kHz sample rates) */
257 ULONG bestid
= INVALID_ID
;
258 int minper
= INT_MAX
;
259 struct Screen
*screen
= NULL
;
261 static const struct ColorSpec colorspecs
[] =
269 struct MonitorInfo mon
;
270 struct DisplayInfo dis
;
273 for( id
= NextDisplayInfo( INVALID_ID
);
274 id
!= (ULONG
) INVALID_ID
;
275 id
= NextDisplayInfo( id
) )
279 if( GetDisplayInfoData( NULL
,
280 (UBYTE
*) &buffer
.dis
, sizeof(buffer
.dis
),
283 if( !(buffer
.dis
.PropertyFlags
& (DIPF_IS_ECS
| DIPF_IS_AA
) ) )
289 if( GetDisplayInfoData( NULL
,
290 (UBYTE
*) &buffer
.mon
, sizeof(buffer
.mon
),
293 period
= buffer
.mon
.TotalColorClocks
* buffer
.mon
.TotalRows
294 / ( 2 * ( buffer
.mon
.TotalRows
- buffer
.mon
.MinRow
+ 1 ) );
296 if( period
< minper
)
305 if( bestid
!= (ULONG
) INVALID_ID
&& minper
< 100 )
307 screen
= OpenScreenTags( NULL
,
308 SA_DisplayID
, bestid
,
309 SA_Colors
, &colorspecs
,
312 else if( ( GfxBase
->ChipRevBits0
& (GFXF_HR_DENISE
| GFXF_AA_LISA
) ) != 0 )
314 /* No suitable screen mode found, let's bang the hardware...
315 Using code from Sebastiano Vigna <vigna@eolo.usr.dsi.unimi.it>. */
317 struct Custom
*custom
= (struct Custom
*) 0xdff000;
319 custom
->bplcon0
= 0x8211;
320 custom
->ddfstrt
= 0x0018;
321 custom
->ddfstop
= 0x0058;
322 custom
->hbstrt
= 0x0009;
323 custom
->hsstop
= 0x0017;
324 custom
->hbstop
= 0x0021;
325 custom
->htotal
= 0x0071;
326 custom
->vbstrt
= 0x0000;
327 custom
->vsstrt
= 0x0003;
328 custom
->vsstop
= 0x0005;
329 custom
->vbstop
= 0x001D;
330 custom
->vtotal
= 0x020E;
331 custom
->beamcon0
= 0x0B88;
332 custom
->bplcon1
= 0x0000;
333 custom
->bplcon2
= 0x027F;
334 custom
->bplcon3
= 0x00A3;
335 custom
->bplcon4
= 0x0011;
340 CloseScreen( screen
);
351 #if defined(__mc68000__) && defined(__libnix__)