revert between 56095 -> 55830 in arch
[AROS.git] / workbench / devs / AHI / Device / header.c
blob6fc74b8fddd746131fbd4ab6dd42e84020867f96
1 /*
2 AHI - Hardware independent audio subsystem
3 Copyright (C) 1996-2005 Martin Blom <martin@blom.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library 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 GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, Cambridge,
18 MA 02139, USA.
21 #include <config.h>
23 #include <exec/memory.h>
24 #include <exec/resident.h>
25 #include <exec/alerts.h>
26 #include <exec/execbase.h>
27 #include <proto/dos.h>
28 #include <proto/exec.h>
29 #include <proto/gadtools.h>
30 #include <proto/graphics.h>
31 #include <proto/iffparse.h>
32 #if defined(__AROS__)
33 #include <proto/stdc.h>
34 #endif
36 #include "ahi_def.h"
37 #include "debug.h"
38 #include "header.h"
39 #include "gateway.h"
40 #include "gatestubs.h"
41 #include "localize.h"
42 #include "misc.h"
43 #include "version.h"
45 #ifdef __amithlon__
46 # define RTF_NATIVE (1<<3)
47 # define FUNCARRAY_32BIT_NATIVE 0xfffefffe
48 #endif
50 #if !defined( __AROS__ ) && !defined( __amithlon__ )
51 extern void _etext;
52 #else
53 # define _etext RomTag+1 // Fake it
54 #endif
56 /******************************************************************************
57 ** Function prototypes ********************************************************
58 ******************************************************************************/
60 static BOOL
61 OpenLibs ( void );
63 static void
64 CloseLibs ( void );
66 #define GetSymbol( name ) AHIGetELFSymbol( #name, (void*) &name ## Ptr )
68 #undef Req
69 #define Req( msg ) ReqA( msg, NULL )
71 /******************************************************************************
72 ** Device entry ***************************************************************
73 ******************************************************************************/
75 #if defined( __amithlon__ )
76 __asm( "\n\
77 .text;\n\
78 .byte 0x4e, 0xfa, 0x00, 0x03\n\
79 jmp _start" );
80 #endif
82 int
83 _start( void )
85 return -1;
88 #if defined( __MORPHOS__ )
89 ULONG __abox__=1;
90 ULONG __amigappc__=1; // deprecated, used in MOS 0.4
91 #endif
93 /******************************************************************************
94 ** Device resident structure **************************************************
95 ******************************************************************************/
97 #if defined( __AMIGAOS4__ )
98 static const struct TagItem InitTable[];
99 #else
100 static const APTR InitTable[4];
101 #endif
103 // This structure must reside in the text segment or the read-only
104 // data segment! "const" makes it happen.
105 const struct Resident RomTag __attribute__((used)) =
107 RTC_MATCHWORD,
108 (struct Resident *) &RomTag,
109 (struct Resident *) &_etext,
110 #if defined( __MORPHOS__ )
111 RTF_EXTENDED | RTF_PPC | RTF_AUTOINIT,
112 #elif defined( __AROS__ )
113 RTF_EXTENDED | RTF_AUTOINIT,
114 #elif defined( __amithlon__ )
115 RTF_NATIVE | RTF_AUTOINIT,
116 #elif defined( __AMIGAOS4__ )
117 RTF_NATIVE | RTF_AUTOINIT,
118 #else
119 RTF_AUTOINIT,
120 #endif
121 VERSION,
122 NT_DEVICE,
123 0, /* priority */
124 (BYTE *) &DevName[0],
125 (BYTE *) &IDString[6],
126 (APTR) &InitTable
127 #if defined( __MORPHOS__ ) || defined( __AROS__ )
128 , REVISION, NULL
129 #endif
133 /******************************************************************************
134 ** Globals ********************************************************************
135 ******************************************************************************/
137 const ULONG DriverVersion = 2;
138 const ULONG Version = VERSION;
139 const ULONG Revision = REVISION;
141 const char DevName[] = AHINAME;
142 const char IDString[] = "$VER: " AHINAME " " VERS
143 " ©1994-2005 Martin Blom. " CPU " version.\r\n";
145 struct ExecBase *SysBase = NULL;
146 struct DosLibrary *DOSBase = NULL;
147 struct GfxBase *GfxBase = NULL;
148 struct AHIBase *AHIBase = NULL;
149 struct Library *GadToolsBase = NULL;
150 struct Library *IFFParseBase = NULL;
151 struct IntuitionBase *IntuitionBase = NULL;
152 struct LocaleBase *LocaleBase = NULL;
153 struct Device *TimerBase = NULL;
154 struct UtilityBase *UtilityBase = NULL;
155 #if defined (__AROS__)
156 struct StdCBase *StdCBase = NULL;
157 #endif
159 #if defined( __AMIGAOS4__ )
160 struct ExecIFace *IExec = NULL;
161 struct DOSIFace *IDOS = NULL;
162 struct GadToolsIFace *IGadTools = NULL;
163 struct GraphicsIFace *IGraphics = NULL;
164 struct IFFParseIFace *IIFFParse = NULL;
165 struct IntuitionIFace *IIntuition = NULL;
166 struct LocaleIFace *ILocale = NULL;
167 struct TimerIFace *ITimer = NULL;
168 struct UtilityIFace *IUtility = NULL;
169 #endif
171 struct Resident *MorphOSRes = NULL;
172 static struct timerequest *TimerIO = NULL;
174 #if defined( ENABLE_WARPUP )
175 struct Library *PowerPCBase = NULL;
176 void *PPCObject = NULL;
177 const ULONG __LIB_Version = VERSION;
178 const ULONG __LIB_Revision = REVISION;
179 #endif
181 enum MixBackend_t MixBackend = MB_NATIVE;
183 ADDFUNC* AddByteMonoPtr = AddByteMono;
184 ADDFUNC* AddByteStereoPtr = AddByteStereo;
185 ADDFUNC* AddByte71Ptr = AddByte71;
186 ADDFUNC* AddBytesMonoPtr = AddBytesMono;
187 ADDFUNC* AddBytesStereoPtr = AddBytesStereo;
188 ADDFUNC* AddBytes71Ptr = AddBytes71;
189 ADDFUNC* AddWordMonoPtr = AddWordMono;
190 ADDFUNC* AddWordStereoPtr = AddWordStereo;
191 ADDFUNC* AddWord71Ptr = AddWord71;
192 ADDFUNC* AddWordsMonoPtr = AddWordsMono;
193 ADDFUNC* AddWordsStereoPtr = AddWordsStereo;
194 ADDFUNC* AddWords71Ptr = AddWords71;
195 ADDFUNC* AddLongMonoPtr = AddLongMono;
196 ADDFUNC* AddLongStereoPtr = AddLongStereo;
197 ADDFUNC* AddLong71Ptr = AddLong71;
198 ADDFUNC* AddLongsMonoPtr = AddLongsMono;
199 ADDFUNC* AddLongsStereoPtr = AddLongsStereo;
200 ADDFUNC* Add71MonoPtr = Add71Mono;
201 ADDFUNC* Add71StereoPtr = Add71Stereo;
202 ADDFUNC* AddLongs71Ptr = AddLongs71;
203 ADDFUNC* Add7171Ptr = Add7171;
205 ADDFUNC* AddByteMonoBPtr = AddByteMonoB;
206 ADDFUNC* AddByteStereoBPtr = AddByteStereoB;
207 ADDFUNC* AddByte71BPtr = AddByte71B;
208 ADDFUNC* AddBytesMonoBPtr = AddBytesMonoB;
209 ADDFUNC* AddBytesStereoBPtr = AddBytesStereoB;
210 ADDFUNC* AddBytes71BPtr = AddBytes71B;
211 ADDFUNC* AddWordMonoBPtr = AddWordMonoB;
212 ADDFUNC* AddWordStereoBPtr = AddWordStereoB;
213 ADDFUNC* AddWord71BPtr = AddWord71B;
214 ADDFUNC* AddWordsMonoBPtr = AddWordsMonoB;
215 ADDFUNC* AddWordsStereoBPtr = AddWordsStereoB;
216 ADDFUNC* AddWords71BPtr = AddWords71B;
217 ADDFUNC* AddLongMonoBPtr = AddLongMonoB;
218 ADDFUNC* AddLongStereoBPtr = AddLongStereoB;
219 ADDFUNC* AddLong71BPtr = AddLong71B;
220 ADDFUNC* AddLongsMonoBPtr = AddLongsMonoB;
221 ADDFUNC* AddLongsStereoBPtr = AddLongsStereoB;
222 ADDFUNC* AddLongs71BPtr = AddLongs71B;
223 ADDFUNC* Add71MonoBPtr = Add71MonoB;
224 ADDFUNC* Add71StereoBPtr = Add71StereoB;
225 ADDFUNC* Add7171BPtr = Add7171B;
227 ADDFUNC* AddLofiByteMonoPtr = AddLofiByteMono;
228 ADDFUNC* AddLofiByteStereoPtr = AddLofiByteStereo;
229 ADDFUNC* AddLofiBytesMonoPtr = AddLofiBytesMono;
230 ADDFUNC* AddLofiBytesStereoPtr = AddLofiBytesStereo;
231 ADDFUNC* AddLofiWordMonoPtr = AddLofiWordMono;
232 ADDFUNC* AddLofiWordStereoPtr = AddLofiWordStereo;
233 ADDFUNC* AddLofiWordsMonoPtr = AddLofiWordsMono;
234 ADDFUNC* AddLofiWordsStereoPtr = AddLofiWordsStereo;
235 ADDFUNC* AddLofiLongMonoPtr = AddLofiLongMono;
236 ADDFUNC* AddLofiLongStereoPtr = AddLofiLongStereo;
237 ADDFUNC* AddLofiLongsMonoPtr = AddLofiLongsMono;
238 ADDFUNC* AddLofiLongsStereoPtr = AddLofiLongsStereo;
239 ADDFUNC* AddLofiByteMonoBPtr = AddLofiByteMonoB;
240 ADDFUNC* AddLofiByteStereoBPtr = AddLofiByteStereoB;
241 ADDFUNC* AddLofiBytesMonoBPtr = AddLofiBytesMonoB;
242 ADDFUNC* AddLofiBytesStereoBPtr = AddLofiBytesStereoB;
243 ADDFUNC* AddLofiWordMonoBPtr = AddLofiWordMonoB;
244 ADDFUNC* AddLofiWordStereoBPtr = AddLofiWordStereoB;
245 ADDFUNC* AddLofiWordsMonoBPtr = AddLofiWordsMonoB;
246 ADDFUNC* AddLofiWordsStereoBPtr = AddLofiWordsStereoB;
247 ADDFUNC* AddLofiLongMonoBPtr = AddLofiLongMonoB;
248 ADDFUNC* AddLofiLongStereoBPtr = AddLofiLongStereoB;
249 ADDFUNC* AddLofiLongsMonoBPtr = AddLofiLongsMonoB;
250 ADDFUNC* AddLofiLongsStereoBPtr = AddLofiLongsStereoB;
252 /******************************************************************************
253 ** Device code ****************************************************************
254 ******************************************************************************/
256 #ifndef __AMIGAOS4__
257 static inline void DeleteLibrary(struct Library *base) {
258 FreeMem((APTR)(((char*)base)-base->lib_NegSize),base->lib_NegSize+base->lib_PosSize);
260 #endif
262 struct AHIBase*
263 _DevInit( struct AHIBase* device,
264 APTR seglist,
265 struct ExecBase* sysbase )
267 AHIBase = device;
268 SysBase = sysbase;
270 ahibug("[AHI:Device] %s()\n", __func__);
272 #ifdef __AMIGAOS4__
273 IExec = (struct ExecIFace*) SysBase->MainInterface;
274 #endif
276 device->ahib_Library.lib_Revision = REVISION;
278 device->ahib_SysLib = sysbase;
279 device->ahib_SegList = (BPTR) seglist;
281 #if defined( __mc68000__ )
282 // Make sure we're running on a M68020 or better
284 if( ( sysbase->AttnFlags & AFF_68020 ) == 0 )
286 Alert( ( AN_Unknown | ACPU_InstErr ) & (~AT_DeadEnd) );
287 DeleteLibrary( &device->ahib_Library );
288 return NULL;
290 #endif
292 InitSemaphore( &device->ahib_Lock );
294 if( !OpenLibs() )
296 CloseLibs();
297 DeleteLibrary( &device->ahib_Library );
298 return NULL;
301 return device;
305 BPTR
306 _DevExpunge( struct AHIBase* device )
308 BPTR seglist = 0;
310 ahibug("[AHI:Device] %s()\n", __func__);
312 //DebugPrintF("AHI: _DevExpunge\n");
314 if( device->ahib_Library.lib_OpenCnt == 0)
316 seglist = device->ahib_SegList;
318 Remove( (struct Node *) device );
320 CloseLibs();
322 DeleteLibrary( &device->ahib_Library );
324 else
326 device->ahib_Library.lib_Flags |= LIBF_DELEXP;
329 return seglist;
332 ULONG
333 _DevNull( void ) {
334 return 0;
338 #ifndef __AMIGAOS4__
340 static const APTR FuncTable[] =
342 #if defined( __MORPHOS__ ) || defined( __amithlon__ )
343 (APTR) FUNCARRAY_32BIT_NATIVE,
344 #endif
346 gwDevOpen,
347 gwDevClose,
348 gwDevExpunge,
349 gwDevNull,
351 gwDevBeginIO,
352 gwDevAbortIO,
354 gwAHI_AllocAudioA,
355 gwAHI_FreeAudio,
356 gwAHI_KillAudio,
357 gwAHI_ControlAudioA,
358 gwAHI_SetVol,
359 gwAHI_SetFreq,
360 gwAHI_SetSound,
361 gwAHI_SetEffect,
362 gwAHI_LoadSound,
363 gwAHI_UnloadSound,
364 gwAHI_NextAudioID,
365 gwAHI_GetAudioAttrsA,
366 gwAHI_BestAudioIDA,
367 gwAHI_AllocAudioRequestA,
368 gwAHI_AudioRequestA,
369 gwAHI_FreeAudioRequest,
370 gwAHI_PlayA,
371 gwAHI_SampleFrameSize,
372 gwAHI_AddAudioMode,
373 gwAHI_RemoveAudioMode,
374 gwAHI_LoadModeFile,
376 (APTR) -1
380 static const APTR InitTable[4] =
382 (APTR) sizeof( struct AHIBase ),
383 (APTR) &FuncTable,
384 NULL,
385 #if defined( __MORPHOS__ ) || defined( __amithlon__ )
386 (APTR) _DevInit
387 #else
388 (APTR) gwDevInit
389 #endif
392 #else // __AMIGAOS4__
394 static ULONG generic_Obtain(struct Interface *Self)
396 return Self->Data.RefCount++;
399 static ULONG generic_Release(struct Interface *Self)
401 return Self->Data.RefCount--;
405 static const CONST_APTR DevManagerVectors[] =
407 generic_Obtain,
408 generic_Release,
409 NULL,
410 NULL,
412 gwDevOpen,
413 gwDevClose,
414 gwDevExpunge,
415 NULL,
416 gwDevBeginIO,
417 gwDevAbortIO,
419 (CONST_APTR) -1
422 static const struct TagItem DevManagerTags[] =
424 { MIT_Name, (IPTR) "__device" },
425 { MIT_VectorTable, (IPTR) DevManagerVectors },
426 { MIT_Version, 1 },
427 { TAG_DONE, 0 }
431 static const CONST_APTR MainVectors[] = {
432 generic_Obtain,
433 generic_Release,
434 NULL,
435 NULL,
437 gwAHI_AllocAudioA,
438 gwAHI_AllocAudio,
439 gwAHI_FreeAudio,
440 gwAHI_KillAudio,
441 gwAHI_ControlAudioA,
442 gwAHI_ControlAudio,
443 gwAHI_SetVol,
444 gwAHI_SetFreq,
445 gwAHI_SetSound,
446 gwAHI_SetEffect,
447 gwAHI_LoadSound,
448 gwAHI_UnloadSound,
449 gwAHI_NextAudioID,
450 gwAHI_GetAudioAttrsA,
451 gwAHI_GetAudioAttrs,
452 gwAHI_BestAudioIDA,
453 gwAHI_BestAudioID,
454 gwAHI_AllocAudioRequestA,
455 gwAHI_AllocAudioRequest,
456 gwAHI_AudioRequestA,
457 gwAHI_AudioRequest,
458 gwAHI_FreeAudioRequest,
459 gwAHI_PlayA,
460 gwAHI_Play,
461 gwAHI_SampleFrameSize,
462 gwAHI_AddAudioMode,
463 gwAHI_RemoveAudioMode,
464 gwAHI_LoadModeFile,
466 (CONST_APTR) -1
469 static const struct TagItem MainTags[] =
471 { MIT_Name, (IPTR) "main" },
472 { MIT_VectorTable, (IPTR) MainVectors },
473 { MIT_Version, 1 },
474 { TAG_DONE, 0 }
478 /* MLT_INTERFACES array */
479 static const CONST_APTR Interfaces[] =
481 DevManagerTags,
482 MainTags,
483 NULL
486 /* m68k library vectors */
487 static const CONST_APTR VecTable68K[] = {
488 (CONST_APTR) &m68kgwDevOpen,
489 (CONST_APTR) &m68kgwDevClose,
490 (CONST_APTR) &m68kgwDevExpunge,
491 (CONST_APTR) &m68kgwDevNull,
493 (CONST_APTR) &m68kgwDevBeginIO,
494 (CONST_APTR) &m68kgwDevAbortIO,
495 (CONST_APTR) &m68kgwAHI_AllocAudioA,
496 (CONST_APTR) &m68kgwAHI_FreeAudio,
497 (CONST_APTR) &m68kgwAHI_KillAudio,
498 (CONST_APTR) &m68kgwAHI_ControlAudioA,
499 (CONST_APTR) &m68kgwAHI_SetVol,
500 (CONST_APTR) &m68kgwAHI_SetFreq,
501 (CONST_APTR) &m68kgwAHI_SetSound,
502 (CONST_APTR) &m68kgwAHI_SetEffect,
503 (CONST_APTR) &m68kgwAHI_LoadSound,
504 (CONST_APTR) &m68kgwAHI_UnloadSound,
505 (CONST_APTR) &m68kgwAHI_NextAudioID,
506 (CONST_APTR) &m68kgwAHI_GetAudioAttrsA,
507 (CONST_APTR) &m68kgwAHI_BestAudioIDA,
508 (CONST_APTR) &m68kgwAHI_AllocAudioRequestA,
509 (CONST_APTR) &m68kgwAHI_AudioRequestA,
510 (CONST_APTR) &m68kgwAHI_FreeAudioRequest,
511 (CONST_APTR) &m68kgwAHI_PlayA,
512 (CONST_APTR) &m68kgwAHI_SampleFrameSize,
513 (CONST_APTR) &m68kgwAHI_AddAudioMode,
514 (CONST_APTR) &m68kgwAHI_RemoveAudioMode,
515 (CONST_APTR) &m68kgwAHI_LoadModeFile,
517 (CONST_APTR) -1
520 /* CreateLibrary() tag list */
521 static const struct TagItem InitTable[] =
523 { CLT_DataSize, sizeof(struct AHIBase) },
524 { CLT_Interfaces, (ULONG) Interfaces },
525 { CLT_Vector68K, (ULONG) VecTable68K },
526 { CLT_InitFunc, (ULONG) gwDevInit },
527 { TAG_DONE, 0 }
530 #endif // __AMIGAOS4__
533 /******************************************************************************
534 ** OpenLibs *******************************************************************
535 ******************************************************************************/
537 // This function is called by the device startup code when the device is
538 // first loaded into memory.
540 static BOOL
541 OpenLibs ( void )
543 /* Intuition Library */
545 ahibug("[AHI:Device] %s()\n", __func__);
547 IntuitionBase = (struct IntuitionBase *) OpenLibrary( "intuition.library", 37 );
549 if( IntuitionBase == NULL)
551 Alert(AN_Unknown|AG_OpenLib|AO_Intuition);
552 return FALSE;
555 /* DOS Library */
557 DOSBase = (struct DosLibrary *) OpenLibrary( "dos.library", 37 );
559 if( DOSBase == NULL)
561 Req( "Unable to open 'dos.library'." );
562 return FALSE;
565 /* Graphics Library */
567 GfxBase = (struct GfxBase *) OpenLibrary( "graphics.library", 37 );
569 if( GfxBase == NULL)
571 Req( "Unable to open 'graphics.library'." );
572 return FALSE;
575 /* GadTools Library */
577 GadToolsBase = OpenLibrary( "gadtools.library", 37 );
579 if( GadToolsBase == NULL)
581 Req( "Unable to open 'gadtools.library'." );
582 return FALSE;
585 /* IFFParse Library */
587 IFFParseBase = OpenLibrary( "iffparse.library", 37 );
589 if( IFFParseBase == NULL)
591 Req( "Unable to open 'iffparse.library'." );
592 return FALSE;
595 /* Locale Library */
597 LocaleBase = (struct LocaleBase*) OpenLibrary( "locale.library", 38 );
599 /* Timer Device */
601 TimerIO = (struct timerequest *) AllocMem( sizeof(struct timerequest),
602 MEMF_PUBLIC | MEMF_CLEAR );
604 if( TimerIO == NULL)
606 Req( "Out of memory." );
607 return FALSE;
610 if( OpenDevice( "timer.device",
611 UNIT_VBLANK,
612 (struct IORequest *)
613 TimerIO,
614 0) != 0 )
616 Req( "Unable to open 'timer.device'." );
617 // return FALSE;
619 else
621 TimerBase = (struct Device *) TimerIO->tr_node.io_Device;
624 /* Utility Library */
626 UtilityBase = (struct UtilityBase *) OpenLibrary( "utility.library", 37 );
628 if( UtilityBase == NULL)
630 Req( "Unable to open 'utility.library'." );
631 return FALSE;
634 #if defined(__AROS__)
635 /* StdC library */
637 StdCBase = (struct StdCBase *) OpenLibrary( "stdc.library", 0 );
639 if( StdCBase == NULL)
641 Req( "Unable to open 'stdc.library'." );
642 return FALSE;
644 #endif
646 #ifdef __AMIGAOS4__
647 if ((IIntuition = (struct IntuitionIFace *) GetInterface((struct Library *) IntuitionBase, "main", 1, NULL)) == NULL)
649 Req("Couldn't open IIntuition interface!\n");
650 return FALSE;
653 if ((IDOS = (struct DOSIFace *) GetInterface((struct Library *) DOSBase, "main", 1, NULL)) == NULL)
655 Req("Couldn't open IDOS interface!\n");
656 return FALSE;
659 if ((IGraphics = (struct GraphicsIFace *) GetInterface((struct Library *) GfxBase, "main", 1, NULL)) == NULL)
661 Req("Couldn't open Graphics interface!\n");
662 return FALSE;
665 if ((IGadTools = (struct GadToolsIFace *) GetInterface((struct Library *) GadToolsBase, "main", 1, NULL)) == NULL)
667 Req("Couldn't open IGadTools interface!\n");
668 return FALSE;
671 if ((IIFFParse = (struct IFFParseIFace *) GetInterface((struct Library *) IFFParseBase, "main", 1, NULL)) == NULL)
673 Req("Couldn't open IFFParse interface!\n");
674 return FALSE;
677 if ((ILocale = (struct LocaleIFace *) GetInterface((struct Library *) LocaleBase, "main", 1, NULL)) == NULL)
679 Req("Couldn't open ILocale interface!\n");
680 return FALSE;
683 if ((ITimer = (struct TimerIFace *) GetInterface((struct Library *) TimerBase, "main", 1, NULL)) == NULL)
685 Req("Couldn't open Timer interface!\n");
686 return FALSE;
689 if ((IUtility = (struct UtilityIFace *) GetInterface((struct Library *) UtilityBase, "main", 1, NULL)) == NULL)
691 Req("Couldn't open Utility interface!\n");
692 return FALSE;
695 if ((IAHI = (struct AHIIFace *) GetInterface((struct Library *) AHIBase, "main", 1, NULL)) == NULL)
697 Req("Couldn't open AHI interface!\n");
698 return FALSE;
700 #endif
703 /* MorphOS/PowerUp/WarpOS loading
705 Strategy:
707 1) If MorphOS is running, use it.
708 2) If PowerUp is running, but not WarpUp, use the m68k core
709 3) If neither of them are running, try WarpUp.
713 // Check if MorpOS/PowerUp/WarpUp is running.
715 #if defined( ENABLE_WARPUP )
716 struct Library* ppclib = NULL;
717 struct Library* powerpclib = NULL;
718 #endif
720 Forbid();
721 MorphOSRes = FindResident( "MorphOS" );
723 #if defined( ENABLE_WARPUP )
724 powerpclib = (struct Library *) FindName( &SysBase->LibList,
725 "powerpc.library" );
726 ppclib = (struct Library *) FindName( &SysBase->LibList,
727 "ppc.library" );
728 #endif
730 Permit();
732 #if defined( ENABLE_WARPUP )
733 if( MorphOSRes == NULL && ! ( ppclib != NULL && powerpclib == NULL ) )
735 // Open WarpUp (but not if MorphOS or PowerUp is active)
737 PowerPCBase = OpenLibrary( "powerpc.library", 15 );
739 #endif
742 if( MorphOSRes != NULL )
744 MixBackend = MB_NATIVE;
747 #if defined( ENABLE_WARPUP )
749 else if( PowerPCBase != NULL )
751 MixBackend = MB_WARPUP;
753 /* Load our code to PPC.. */
755 PPCObject = AHILoadObject( "DEVS:ahi.device.elf" );
757 if( PPCObject != NULL )
759 ULONG* version = NULL;
760 ULONG* revision = NULL;
762 int r = ~0;
764 AHIGetELFSymbol( "__LIB_Version", (void*) &version );
765 AHIGetELFSymbol( "__LIB_Revision", (void*) &revision );
767 if( version != NULL && revision != NULL )
769 if( *version == VERSION && *revision == REVISION )
771 r &= GetSymbol( AddByteMono );
772 r &= GetSymbol( AddByteStereo );
773 r &= GetSymbol( AddBytesMono );
774 r &= GetSymbol( AddBytesStereo );
775 r &= GetSymbol( AddWordMono );
776 r &= GetSymbol( AddWordStereo );
777 r &= GetSymbol( AddWordsMono );
778 r &= GetSymbol( AddWordsStereo );
779 r &= GetSymbol( AddLongMono );
780 r &= GetSymbol( AddLongStereo );
781 r &= GetSymbol( AddLongsMono );
782 r &= GetSymbol( AddLongsStereo );
783 r &= GetSymbol( AddByteMonoB );
784 r &= GetSymbol( AddByteStereoB );
785 r &= GetSymbol( AddBytesMonoB );
786 r &= GetSymbol( AddBytesStereoB );
787 r &= GetSymbol( AddWordMonoB );
788 r &= GetSymbol( AddWordStereoB );
789 r &= GetSymbol( AddWordsMonoB );
790 r &= GetSymbol( AddWordsStereoB );
791 r &= GetSymbol( AddLongMonoB );
792 r &= GetSymbol( AddLongStereoB );
793 r &= GetSymbol( AddLongsMonoB );
794 r &= GetSymbol( AddLongsStereoB );
796 r &= GetSymbol( AddLofiByteMono );
797 r &= GetSymbol( AddLofiByteStereo );
798 r &= GetSymbol( AddLofiBytesMono );
799 r &= GetSymbol( AddLofiBytesStereo );
800 r &= GetSymbol( AddLofiWordMono );
801 r &= GetSymbol( AddLofiWordStereo );
802 r &= GetSymbol( AddLofiWordsMono );
803 r &= GetSymbol( AddLofiWordsStereo );
804 r &= GetSymbol( AddLofiLongMono );
805 r &= GetSymbol( AddLofiLongStereo );
806 r &= GetSymbol( AddLofiLongsMono );
807 r &= GetSymbol( AddLofiLongsStereo );
808 r &= GetSymbol( AddLofiByteMonoB );
809 r &= GetSymbol( AddLofiByteStereoB );
810 r &= GetSymbol( AddLofiBytesMonoB );
811 r &= GetSymbol( AddLofiBytesStereoB );
812 r &= GetSymbol( AddLofiWordMonoB );
813 r &= GetSymbol( AddLofiWordStereoB );
814 r &= GetSymbol( AddLofiWordsMonoB );
815 r &= GetSymbol( AddLofiWordsStereoB );
816 r &= GetSymbol( AddLofiLongMonoB );
817 r &= GetSymbol( AddLofiLongStereoB );
818 r &= GetSymbol( AddLofiLongsMonoB );
819 r &= GetSymbol( AddLofiLongsStereoB );
821 if( r != 0 )
823 char buffer[ 2 ] = "0";
825 GetVar( "PowerPC/UseDisable", buffer, sizeof buffer, 0 );
827 if( buffer[ 0 ] == '1' )
829 // OK, then...
831 else
833 Req( "The WarpUp variable 'PowerPC/UseDisable' must be '1'." );
835 AHIUnloadObject( PPCObject );
836 PPCObject = NULL;
837 MixBackend = MB_NATIVE;
840 else
842 Req( "Unable to fetch all symbols from ELF object." );
844 AHIUnloadObject( PPCObject );
845 PPCObject = NULL;
846 MixBackend = MB_NATIVE;
849 else
851 Req( "'ahi.device.elf' version %ld.%ld doesn't match "
852 "'ahi.device' version %ld.%ld.",
853 *version, *revision, VERSION, REVISION );
855 AHIUnloadObject( PPCObject );
856 PPCObject = NULL;
857 MixBackend = MB_NATIVE;
860 else
862 Req( "Unable to fetch version information from 'ahi.device.elf'." );
864 AHIUnloadObject( PPCObject );
865 PPCObject = NULL;
866 MixBackend = MB_NATIVE;
869 else
871 MixBackend = MB_NATIVE;
875 #endif
877 else
879 //MixBackend = MB_NATIVE;
882 OpenahiCatalog(NULL, NULL);
884 return TRUE;
888 /******************************************************************************
889 ** CloseLibs *******************************************************************
890 ******************************************************************************/
892 // This function is called by DevExpunge() when the device is about to be
893 // flushed
895 static void
896 CloseLibs ( void )
898 ahibug("[AHI:Device] %s()\n", __func__);
900 CloseahiCatalog();
902 #if defined( ENABLE_WARPUP )
903 if( PPCObject != NULL )
905 AHIUnloadObject( PPCObject );
908 CloseLibrary( PowerPCBase );
909 #endif
911 #ifdef __AMIGAOS4__
912 DropInterface((struct Interface *) IUtility );
913 DropInterface((struct Interface *) ITimer );
914 DropInterface((struct Interface *) ILocale );
915 DropInterface((struct Interface *) IIFFParse );
916 DropInterface((struct Interface *) IGadTools );
917 DropInterface((struct Interface *) IGraphics );
918 DropInterface((struct Interface *) IDOS );
919 DropInterface((struct Interface *) IIntuition );
920 DropInterface((struct Interface *) IAHI );
921 #endif
923 #if defined(__AROS__)
924 CloseLibrary( (struct Library *) StdCBase );
925 #endif
926 CloseLibrary( (struct Library *) UtilityBase );
928 if( TimerIO != NULL )
930 if( TimerBase != NULL )
932 CloseDevice( (struct IORequest *) TimerIO );
935 FreeMem( TimerIO, sizeof(struct timerequest) );
938 CloseLibrary( (struct Library *) LocaleBase );
939 CloseLibrary( IFFParseBase );
940 CloseLibrary( GadToolsBase );
941 CloseLibrary( (struct Library *) GfxBase );
942 CloseLibrary( (struct Library *) DOSBase );
943 CloseLibrary( (struct Library *) IntuitionBase );