2 AddAudioModes - Manipulates AHI's audio mode database
3 Copyright (C) 2017 The AROS Dev Team
4 Copyright (C) 1996-2005 Martin Blom <martin@blom.org>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <aros/debug.h>
26 #include <devices/ahi.h>
27 #include <graphics/modeid.h>
28 #include <graphics/gfxbase.h>
29 #include <intuition/screens.h>
30 #include <proto/ahi.h>
31 #include <proto/dos.h>
32 #include <proto/exec.h>
33 #include <proto/graphics.h>
34 #include <proto/intuition.h>
40 struct GfxBase
*GfxBase
= NULL
;
41 struct IntuitionBase
*IntuitionBase
= NULL
;
42 struct Library
*AHIBase
= NULL
;
43 struct MsgPort
*AHImp
= NULL
;
44 struct AHIRequest
*AHIio
= NULL
;
48 struct AHIIFace
*IAHI
= NULL
;
51 const char version
[] = "$VER: AddAudioModes " VERS
"\n\r";
55 #define TEMPLATE "FILES/M,QUIET/S,REFRESH/S,REMOVE/S,DBLSCAN/S"
63 } args
= {NULL
, FALSE
, FALSE
, FALSE
, FALSE
};
74 D(bug("[AddAudioModes] %s()\n", __func__
);)
77 DropInterface((struct Interface
*) IAHI
);
82 CloseDevice( (struct IORequest
*) AHIio
);
85 DeleteIORequest( (struct IORequest
*) AHIio
);
86 DeleteMsgPort( AHImp
);
88 CloseLibrary( (struct Library
*) IntuitionBase
);
89 CloseLibrary( (struct Library
*) GfxBase
);
96 D(bug("[AddAudioModes] %s()\n", __func__
);)
99 AHImp
= CreateMsgPort();
101 D(bug("[AddAudioModes] %s: MsgPort @ 0x%p\n", __func__
, AHImp
);)
105 AHIio
= (struct AHIRequest
*)
106 CreateIORequest( AHImp
, sizeof( struct AHIRequest
) );
110 D(bug("[AddAudioModes] %s: IORequest @ 0x%p\n", __func__
, AHIio
);)
111 AHIio
->ahir_Version
= AHIVERSION
;
113 AHIDevice
= OpenDevice( AHINAME
,
115 (struct IORequest
*) AHIio
,
122 Printf( "Unable to open '%s' version %ld\n", AHINAME
, AHIVERSION
);
127 AHIBase
= (struct Library
*) AHIio
->ahir_Std
.io_Device
;
128 D(bug("[AddAudioModes] %s: AHIBase @ 0x%p\n", __func__
, AHIBase
);)
131 IAHI
= (struct AHIIFace
*) GetInterface(AHIBase
, "main", 1, NULL
);
136 // Disable command line processing
137 const long __nocommandline
=1;
142 struct RDArgs
*rdargs
;
145 D(bug("[AddAudioModes] %s()\n", __func__
);)
147 GfxBase
= (struct GfxBase
*) OpenLibrary( GRAPHICSNAME
, 37 );
148 IntuitionBase
= (struct IntuitionBase
*) OpenLibrary( "intuition.library", 37 );
150 if( GfxBase
== NULL
)
152 Printf( "Unable to open %s version %ld\n", GRAPHICSNAME
, 37 );
157 if( IntuitionBase
== NULL
)
159 Printf( "Unable to open %s version %ld\n", "intuition.library", 37 );
165 bug("[AddAudioModes] %s: GfxBase @ 0x%p\n", __func__
, GfxBase
);
166 bug("[AddAudioModes] %s: IntuitionBase @ 0x%p\n", __func__
, IntuitionBase
);
169 rdargs
= ReadArgs( TEMPLATE
, (SIPTR
*) &args
, NULL
);
173 /* Refresh database */
175 if( args
.refresh
&& !args
.remove
)
181 /* First, empty the database */
183 for( id
= AHI_NextAudioID( AHI_INVALID_ID
);
184 id
!= (IPTR
) AHI_INVALID_ID
;
185 id
= AHI_NextAudioID( AHI_INVALID_ID
) )
187 D(bug("[AddAudioModes] %s: Removing ID %08x\n", __func__
, id
);)
188 AHI_RemoveAudioMode( id
);
191 /* Now add all modes */
193 if( !AHI_LoadModeFile( "DEVS:AudioModes" ) )
199 /* Be quiet here. - Piru */
200 APTR
*windowptr
= &((struct Process
*) FindTask(NULL
))->pr_WindowPtr
;
201 APTR oldwindowptr
= *windowptr
;
202 *windowptr
= (APTR
) -1;
203 res
= AHI_LoadModeFile( "MOSSYS:DEVS/AudioModes" );
204 *windowptr
= oldwindowptr
;
210 PrintFault( IoErr(), "AudioModes" );
220 PrintFault( IoErr(), "DEVS:AudioModes" );
228 /* Load mode files */
230 if( args
.files
!= NULL
&& !args
.remove
)
236 while( args
.files
[i
] )
238 D(bug("[AddAudioModes] %s: Trying to load '%s' ... \n", __func__
, args
.files
[i
]);)
239 if( !AHI_LoadModeFile( args
.files
[i
] ) && !args
.quiet
)
241 D(bug("[AddAudioModes] %s: Failed!\n", __func__
);)
242 PrintFault( IoErr(), args
.files
[i
] );
249 /* Remove database */
253 if( args
.files
|| args
.refresh
)
255 PutStr( "The REMOVE switch cannot be used together with FILES or REFRESH.\n" );
264 for( id
= AHI_NextAudioID( AHI_INVALID_ID
);
265 id
!= (IPTR
) AHI_INVALID_ID
;
266 id
= AHI_NextAudioID( AHI_INVALID_ID
) )
268 D(bug("[AddAudioModes] %s: Removing ID %08x\n", __func__
, id
);)
269 AHI_RemoveAudioMode( id
);
274 /* Make display mode doublescan (allowing > 28 kHz sample rates) */
279 IPTR bestid
= INVALID_ID
;
280 int minper
= INT_MAX
;
281 struct Screen
*screen
= NULL
;
283 static const struct ColorSpec colorspecs
[] =
291 struct MonitorInfo mon
;
292 struct DisplayInfo dis
;
295 for( id
= NextDisplayInfo( INVALID_ID
);
296 id
!= (IPTR
) INVALID_ID
;
297 id
= NextDisplayInfo( id
) )
301 if( GetDisplayInfoData( NULL
,
302 (UBYTE
*) &buffer
.dis
, sizeof(buffer
.dis
),
305 if( !(buffer
.dis
.PropertyFlags
& (DIPF_IS_ECS
| DIPF_IS_AA
) ) )
311 if( GetDisplayInfoData( NULL
,
312 (UBYTE
*) &buffer
.mon
, sizeof(buffer
.mon
),
315 period
= buffer
.mon
.TotalColorClocks
* buffer
.mon
.TotalRows
316 / ( 2 * ( buffer
.mon
.TotalRows
- buffer
.mon
.MinRow
+ 1 ) );
318 if( period
< minper
)
327 if( bestid
!= (IPTR
) INVALID_ID
&& minper
< 100 )
329 screen
= OpenScreenTags( NULL
,
330 SA_DisplayID
, bestid
,
331 SA_Colors
, &colorspecs
,
334 else if( ( GfxBase
->ChipRevBits0
& (GFXF_HR_DENISE
| GFXF_AA_LISA
) ) != 0 )
336 /* No suitable screen mode found, let's bang the hardware...
337 Using code from Sebastiano Vigna <vigna@eolo.usr.dsi.unimi.it>. */
339 struct Custom
*custom
= (struct Custom
*) 0xdff000;
341 custom
->bplcon0
= 0x8211;
342 custom
->ddfstrt
= 0x0018;
343 custom
->ddfstop
= 0x0058;
344 custom
->hbstrt
= 0x0009;
345 custom
->hsstop
= 0x0017;
346 custom
->hbstop
= 0x0021;
347 custom
->htotal
= 0x0071;
348 custom
->vbstrt
= 0x0000;
349 custom
->vsstrt
= 0x0003;
350 custom
->vsstop
= 0x0005;
351 custom
->vbstop
= 0x001D;
352 custom
->vtotal
= 0x020E;
353 custom
->beamcon0
= 0x0B88;
354 custom
->bplcon1
= 0x0000;
355 custom
->bplcon2
= 0x027F;
356 custom
->bplcon3
= 0x00A3;
357 custom
->bplcon4
= 0x0011;
362 CloseScreen( screen
);
373 #if defined(__mc68000__) && defined(__libnix__)