revert between 56095 -> 55830 in arch
[AROS.git] / workbench / devs / AHI / AddAudioModes / AddAudioModes.c
blob5beea7bda600f4d26bc2dcb9d075970f1aa96698
1 /*
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.
21 #define DEBUG 1
22 #include <aros/debug.h>
24 #include <config.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>
35 #include <stdlib.h>
36 #include <limits.h>
38 #include "version.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;
45 BYTE AHIDevice = -1;
47 #ifdef __AMIGAOS4__
48 struct AHIIFace *IAHI = NULL;
49 #endif
51 const char version[] = "$VER: AddAudioModes " VERS "\n\r";
53 #define AHIVERSION 4
55 #define TEMPLATE "FILES/M,QUIET/S,REFRESH/S,REMOVE/S,DBLSCAN/S"
57 struct {
58 STRPTR *files;
59 IPTR quiet;
60 IPTR refresh;
61 IPTR remove;
62 IPTR dblscan;
63 } args = {NULL, FALSE, FALSE, FALSE, FALSE};
65 #ifdef __MORPHOS__
66 #define IS_MORPHOS 1
67 #else
68 #define IS_MORPHOS 0
69 #endif
71 void
72 cleanup( void )
74 D(bug("[AddAudioModes] %s()\n", __func__);)
76 #ifdef __AMIGAOS4__
77 DropInterface((struct Interface*) IAHI);
78 #endif
80 if( AHIDevice == 0 )
82 CloseDevice( (struct IORequest *) AHIio );
85 DeleteIORequest( (struct IORequest *) AHIio);
86 DeleteMsgPort( AHImp );
88 CloseLibrary( (struct Library*) IntuitionBase );
89 CloseLibrary( (struct Library*) GfxBase );
93 void
94 OpenAHI( void )
96 D(bug("[AddAudioModes] %s()\n", __func__);)
97 if( AHIDevice != 0 )
99 AHImp = CreateMsgPort();
101 D(bug("[AddAudioModes] %s: MsgPort @ 0x%p\n", __func__, AHImp);)
103 if( AHImp != NULL )
105 AHIio = (struct AHIRequest *)
106 CreateIORequest( AHImp, sizeof( struct AHIRequest ) );
108 if( AHIio != NULL )
110 D(bug("[AddAudioModes] %s: IORequest @ 0x%p\n", __func__, AHIio);)
111 AHIio->ahir_Version = AHIVERSION;
113 AHIDevice = OpenDevice( AHINAME,
114 AHI_NO_UNIT,
115 (struct IORequest *) AHIio,
116 AHIDF_NOMODESCAN );
120 if( AHIDevice != 0 )
122 Printf( "Unable to open '%s' version %ld\n", AHINAME, AHIVERSION );
123 cleanup();
124 exit( RETURN_FAIL );
127 AHIBase = (struct Library *) AHIio->ahir_Std.io_Device;
128 D(bug("[AddAudioModes] %s: AHIBase @ 0x%p\n", __func__, AHIBase);)
130 #ifdef __AMIGAOS4__
131 IAHI = (struct AHIIFace *) GetInterface(AHIBase, "main", 1, NULL);
132 #endif
136 // Disable command line processing
137 const long __nocommandline=1;
140 main( void )
142 struct RDArgs *rdargs;
143 int rc = RETURN_OK;
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 );
153 cleanup();
154 return RETURN_FAIL;
157 if( IntuitionBase == NULL )
159 Printf( "Unable to open %s version %ld\n", "intuition.library", 37 );
160 cleanup();
161 return RETURN_FAIL;
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 );
171 if( rdargs != NULL )
173 /* Refresh database */
175 if( args.refresh && !args.remove )
177 IPTR id;
179 OpenAHI();
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" ) )
195 if( IS_MORPHOS )
197 IPTR res;
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;
206 if( !res )
208 if( !args.quiet )
210 PrintFault( IoErr(), "AudioModes" );
213 rc = RETURN_ERROR;
216 else
218 if ( !args.quiet )
220 PrintFault( IoErr(), "DEVS:AudioModes" );
223 rc = RETURN_ERROR;
228 /* Load mode files */
230 if( args.files != NULL && !args.remove )
232 int i = 0;
234 OpenAHI();
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] );
243 rc = RETURN_ERROR;
245 i++;
249 /* Remove database */
251 if( args.remove )
253 if( args.files || args.refresh )
255 PutStr( "The REMOVE switch cannot be used together with FILES or REFRESH.\n" );
256 rc = RETURN_FAIL;
258 else
260 IPTR id;
262 OpenAHI();
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) */
276 if( args.dblscan )
278 IPTR id;
279 IPTR bestid = INVALID_ID;
280 int minper = INT_MAX;
281 struct Screen *screen = NULL;
283 static const struct ColorSpec colorspecs[] =
285 { 0, 0, 0, 0 },
286 { 1, 0, 0, 0 },
287 {-1, 0, 0, 0 }
290 union {
291 struct MonitorInfo mon;
292 struct DisplayInfo dis;
293 } buffer;
295 for( id = NextDisplayInfo( INVALID_ID );
296 id != (IPTR) INVALID_ID;
297 id = NextDisplayInfo( id ) )
299 int period;
301 if( GetDisplayInfoData( NULL,
302 (UBYTE*) &buffer.dis, sizeof(buffer.dis),
303 DTAG_DISP, id ) )
305 if( !(buffer.dis.PropertyFlags & (DIPF_IS_ECS | DIPF_IS_AA ) ) )
307 continue;
311 if( GetDisplayInfoData( NULL,
312 (UBYTE*) &buffer.mon, sizeof(buffer.mon),
313 DTAG_MNTR, id ) )
315 period = buffer.mon.TotalColorClocks * buffer.mon.TotalRows
316 / ( 2 * ( buffer.mon.TotalRows - buffer.mon.MinRow + 1 ) );
318 if( period < minper )
320 minper = period;
321 bestid = id;
327 if( bestid != (IPTR) INVALID_ID && minper < 100 )
329 screen = OpenScreenTags( NULL,
330 SA_DisplayID, bestid,
331 SA_Colors, &colorspecs,
332 TAG_DONE );
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;
360 if( screen != NULL )
362 CloseScreen( screen );
366 FreeArgs( rdargs );
369 cleanup();
370 return rc;
373 #if defined(__mc68000__) && defined(__libnix__)
374 void __main(void) {}
375 #endif