8 #include <exec/alerts.h>
9 #include <exec/libraries.h>
10 #include <exec/resident.h>
11 #include <utility/utility.h>
13 #include <clib/alib_protos.h>
14 #include <proto/ahi_sub.h>
15 #include <proto/exec.h>
16 #include <proto/intuition.h>
17 #include <proto/utility.h>
19 #define DRIVER_LIBSTUB
21 #include "gatestubs.h"
24 #include "DriverData.h"
28 #define INTUITIONNAME "intuition.library"
32 # define RTF_NATIVE (1<<3)
33 # define FUNCARRAY_32BIT_NATIVE 0xfffefffe
36 #if !defined( __AROS__ ) && !defined( __amithlon__ )
39 # define _etext RomTag+1 // Fake it
42 /******************************************************************************
43 ** Function prototypes ********************************************************
44 ******************************************************************************/
47 _LibInit( struct DriverBase
* AHIsubBase
,
49 struct ExecBase
* sysbase
);
52 _LibExpunge( struct DriverBase
* AHIsubBase
);
55 _LibOpen( ULONG version
,
56 struct DriverBase
* AHIsubBase
);
59 _LibClose( struct DriverBase
* AHIsubBase
);
62 _LibNull( struct DriverBase
* AHIsubBase
);
65 /******************************************************************************
66 ** Driver entry ***************************************************************
67 ******************************************************************************/
69 #if defined( __amithlon__ )
72 .byte 0x4e, 0xfa, 0x00, 0x03\n\
82 #if defined( __MORPHOS__ )
84 ULONG __amigappc__
=1; // deprecated, used in MOS 0.4
87 /******************************************************************************
88 ** Driver resident structure **************************************************
89 ******************************************************************************/
91 #if defined( __AMIGAOS4__ )
92 static const struct TagItem InitTable
[];
94 static const APTR InitTable
[4];
97 // This structure must reside in the text segment or the read-only
98 // data segment! "const" makes it happen.
99 const struct Resident RomTag
__attribute__((used
)) =
102 (struct Resident
*) &RomTag
,
103 (struct Resident
*) &_etext
,
104 #if defined( __MORPHOS__ )
105 RTF_EXTENDED
| RTF_PPC
| RTF_AUTOINIT
,
106 #elif defined( __AROS__ )
107 RTF_EXTENDED
| RTF_AUTOINIT
,
108 #elif defined( __amithlon__ )
109 RTF_NATIVE
| RTF_AUTOINIT
,
110 #elif defined( __AMIGAOS4__ )
111 RTF_NATIVE
| RTF_AUTOINIT
,
119 (BYTE
*) LibIDString
,
121 #if defined( __MORPHOS__ ) || defined( __AROS__ )
127 /******************************************************************************
128 ** Globals ********************************************************************
129 ******************************************************************************/
131 const char LibName
[] = DRIVER
;
132 const char LibIDString
[] = DRIVER
" " VERS
"\r\n";
133 const UWORD LibVersion
= VERSION
;
134 const UWORD LibRevision
= REVISION
;
137 /******************************************************************************
138 ** Library stuff **************************************************************
139 ******************************************************************************/
143 static const APTR FuncTable
[] =
145 #if defined( __MORPHOS__ ) || defined( __amithlon__ )
146 (APTR
) FUNCARRAY_32BIT_NATIVE
,
166 gwAHIsub_UnloadSound
,
168 gwAHIsub_HardwareControl
,
174 static const APTR InitTable
[4] =
176 (APTR
) DRIVERBASE_SIZEOF
,
179 #if defined( __MORPHOS__ ) || defined( __amithlon__ )
186 #else // __AMIGAOS4__
188 static ULONG
generic_Obtain(struct Interface
*Self
)
190 return Self
->Data
.RefCount
++;
194 static ULONG
generic_Release(struct Interface
*Self
)
196 return Self
->Data
.RefCount
--;
200 static const CONST_APTR LibManagerVectors
[] =
215 static const struct TagItem LibManagerTags
[] =
217 { MIT_Name
, (ULONG
) "__library" },
218 { MIT_VectorTable
, (ULONG
) LibManagerVectors
},
224 static const CONST_APTR MainVectors
[] = {
242 gwAHIsub_UnloadSound
,
244 gwAHIsub_HardwareControl
,
249 static const struct TagItem MainTags
[] =
251 { MIT_Name
, (ULONG
) "main" },
252 { MIT_VectorTable
, (ULONG
) MainVectors
},
258 /* MLT_INTERFACES array */
259 static const CONST_APTR Interfaces
[] =
266 /* m68k library vectors */
267 static const CONST_APTR VecTable68K
[] = {
268 (CONST_APTR
) &m68kgwLibOpen
,
269 (CONST_APTR
) &m68kgwLibClose
,
270 (CONST_APTR
) &m68kgwLibExpunge
,
271 (CONST_APTR
) &m68kgwLibNull
,
273 (CONST_APTR
) &m68kgwAHIsub_AllocAudio
,
274 (CONST_APTR
) &m68kgwAHIsub_FreeAudio
,
275 (CONST_APTR
) &m68kgwAHIsub_Disable
,
276 (CONST_APTR
) &m68kgwAHIsub_Enable
,
277 (CONST_APTR
) &m68kgwAHIsub_Start
,
278 (CONST_APTR
) &m68kgwAHIsub_Update
,
279 (CONST_APTR
) &m68kgwAHIsub_Stop
,
280 (CONST_APTR
) &m68kgwAHIsub_SetVol
,
281 (CONST_APTR
) &m68kgwAHIsub_SetFreq
,
282 (CONST_APTR
) &m68kgwAHIsub_SetSound
,
283 (CONST_APTR
) &m68kgwAHIsub_SetEffect
,
284 (CONST_APTR
) &m68kgwAHIsub_LoadSound
,
285 (CONST_APTR
) &m68kgwAHIsub_UnloadSound
,
286 (CONST_APTR
) &m68kgwAHIsub_GetAttr
,
287 (CONST_APTR
) &m68kgwAHIsub_HardwareControl
,
292 /* CreateLibrary() tag list */
293 static const struct TagItem InitTable
[] =
295 { CLT_DataSize
, DRIVERBASE_SIZEOF
},
296 { CLT_Interfaces
, (ULONG
) Interfaces
},
297 { CLT_Vector68K
, (ULONG
) VecTable68K
},
298 { CLT_InitFunc
, (ULONG
) gwLibInit
},
302 #endif // __AMIGAOS4__
305 /******************************************************************************
306 ** Message requester **********************************************************
307 ******************************************************************************/
310 ReqA( const char* text
,
312 struct DriverBase
* AHIsubBase
)
314 struct IntuitionBase
*IntuitionBase
= AHIsubBase
->intuitionbase
;
315 struct EasyStruct es
=
317 sizeof (struct EasyStruct
),
327 EasyRequestArgs( NULL
, &es
, NULL
, args
);
330 /******************************************************************************
331 ** Serial port debugging ******************************************************
332 ******************************************************************************/
336 #if defined( __AROS__ ) && !defined( __mc68000__ )
338 #include <aros/asmcall.h>
342 AROS_UFHA( UBYTE
, c
, D0
),
343 AROS_UFHA( struct ExecBase
*, sysbase
, A3
) )
347 AROS_LC1NR(void, RawPutChar
, AROS_LCA(UBYTE
, c
, D0
), struct ExecBase
*, sysbase
, 86, Exec
);
354 static const UWORD rawputchar_m68k
[] =
356 0x2C4B, // MOVEA.L A3,A6
357 0x4EAE, 0xFDFC, // JSR -$0204(A6)
364 MyKPrintFArgs( UBYTE
* fmt
,
366 struct DriverBase
* AHIsubBase
)
368 RawDoFmt( fmt
, args
, (void(*)(void)) rawputchar_m68k
, SysBase
);
373 /******************************************************************************
374 ** HookEntry ******************************************************************
375 ******************************************************************************/
377 #if defined( __MORPHOS__ )
379 /* Should be in libamiga, but isn't? */
384 struct Hook
* h
= (struct Hook
*) REG_A0
;
385 void* o
= (void*) REG_A2
;
386 void* msg
= (void*) REG_A1
;
388 return ( ( (ULONG(*)(struct Hook
*, void*, void*)) *h
->h_SubEntry
)( h
, o
, msg
) );
391 struct EmulLibEntry _HookEntry
=
393 TRAP_LIB
, 0, (void (*)(void)) &gw_HookEntry
396 __asm( ".globl HookEntry;HookEntry=_HookEntry" );
400 /******************************************************************************
401 ** Library init ***************************************************************
402 ******************************************************************************/
405 #include <aros/symbolsets.h>
407 THIS_PROGRAM_HANDLES_SYMBOLSET(INIT
)
408 THIS_PROGRAM_HANDLES_SYMBOLSET(EXIT
)
414 _LibInit( struct DriverBase
* AHIsubBase
,
416 struct ExecBase
* sysbase
)
421 if (!set_call_funcs(SETNAME(INIT
), 1, 1))
426 IExec
= (struct ExecIFace
*) SysBase
->MainInterface
;
429 AHIsubBase
->library
.lib_Node
.ln_Type
= NT_LIBRARY
;
430 AHIsubBase
->library
.lib_Node
.ln_Name
= (STRPTR
) LibName
;
431 AHIsubBase
->library
.lib_Flags
= LIBF_SUMUSED
| LIBF_CHANGED
;
432 AHIsubBase
->library
.lib_Version
= VERSION
;
433 AHIsubBase
->library
.lib_Revision
= REVISION
;
434 AHIsubBase
->library
.lib_IdString
= (STRPTR
) LibIDString
;
435 AHIsubBase
->seglist
= seglist
;
437 AHIsubBase
->intuitionbase
= (struct IntuitionBase
*)OpenLibrary( INTUITIONNAME
, 37 );
438 AHIsubBase
->utilitybase
= (struct UtilityBase
*)OpenLibrary( UTILITYNAME
, 37 );
440 if( AHIsubBase
->intuitionbase
== NULL
)
442 Alert( AN_Unknown
|AG_OpenLib
|AO_Intuition
);
447 if ((IIntuition
= (struct IntuitionIFace
*) GetInterface((struct Library
*) AHIsubBase
->intuitionbase
, "main", 1, NULL
)) == NULL
)
449 Alert( AN_Unknown
|AG_OpenLib
|AO_Intuition
);
454 if( AHIsubBase
->utilitybase
== NULL
)
456 Req( "Unable to open 'utility.library' version 37.\n" );
461 if ((IUtility
= (struct UtilityIFace
*) GetInterface((struct Library
*) AHIsubBase
->utilitybase
, "main", 1, NULL
)) == NULL
)
463 Req("Couldn't open IUtility interface!\n");
467 if ((IAHIsub
= (struct AHIsubIFace
*) GetInterface((struct Library
*) AHIsubBase
, "main", 1, NULL
)) == NULL
)
469 Req("Couldn't open IAHIsub interface!\n");
474 if( ! DriverInit( AHIsubBase
) )
482 _LibExpunge( AHIsubBase
);
487 /******************************************************************************
488 ** Library clean-up ***********************************************************
489 ******************************************************************************/
492 # define DeleteLibrary(base) FreeMem((APTR)(((char*) base) - \
493 ((struct Library*) base)->lib_NegSize), \
494 ((struct Library*) base)->lib_NegSize + \
495 ((struct Library*) base)->lib_PosSize)
499 _LibExpunge( struct DriverBase
* AHIsubBase
)
503 if( AHIsubBase
->library
.lib_OpenCnt
== 0 )
505 seglist
= AHIsubBase
->seglist
;
507 /* Since LibInit() calls us on failure, we have to check if we're
508 really added to the library list before removing us. */
510 if( AHIsubBase
->library
.lib_Node
.ln_Succ
!= NULL
)
512 Remove( (struct Node
*) AHIsubBase
);
515 DriverCleanup( AHIsubBase
);
518 DropInterface((struct Interface
*) IAHIsub
);
519 DropInterface((struct Interface
*) IIntuition
);
520 DropInterface((struct Interface
*) IUtility
);
523 /* Close libraries */
524 CloseLibrary(&AHIsubBase
->intuitionbase
->LibNode
);
525 CloseLibrary(&AHIsubBase
->utilitybase
->ub_LibNode
);
528 set_call_funcs(SETNAME(EXIT
), -1, 0);
531 DeleteLibrary(&AHIsubBase
->library
);
535 AHIsubBase
->library
.lib_Flags
|= LIBF_DELEXP
;
542 /******************************************************************************
543 ** Library opening ************************************************************
544 ******************************************************************************/
547 _LibOpen( ULONG version
,
548 struct DriverBase
* AHIsubBase
)
550 AHIsubBase
->library
.lib_Flags
&= ~LIBF_DELEXP
;
551 AHIsubBase
->library
.lib_OpenCnt
++;
557 /******************************************************************************
558 ** Library closing ************************************************************
559 ******************************************************************************/
562 _LibClose( struct DriverBase
* AHIsubBase
)
566 AHIsubBase
->library
.lib_OpenCnt
--;
568 if( AHIsubBase
->library
.lib_OpenCnt
== 0 )
570 if( AHIsubBase
->library
.lib_Flags
& LIBF_DELEXP
)
572 seglist
= _LibExpunge( AHIsubBase
);
580 /******************************************************************************
581 ** Unused function ************************************************************
582 ******************************************************************************/
585 _LibNull( struct DriverBase
* AHIsubBase
)