2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
9 #include <proto/exec.h>
10 #include <proto/dos.h>
12 # include <proto/CamdDriver.h>
14 #include "camd_intern.h"
19 # include <aros/debug.h>
22 BOOL
isPointerInSeglist(APTR pointer
,BPTR seglist
,ULONG minsize
);
24 /*****************************************************************************
28 AROS_LH1(struct MidiDeviceData
*, OpenMidiDevice
,
31 AROS_LHA(UBYTE
*, name
, A0
),
34 struct CamdBase
*, CamdBase
, 34, Camd
)
37 Remind me to fill in things here later.
56 2001-01-12 ksvalast first created
58 *****************************************************************************/
62 struct Drivers
*driver
;
66 struct MidiDeviceData
*mididevicedata
;
72 seg
=seglist
=LoadSeg(name
);
74 if(seglist
==BNULL
) return NULL
;
76 // The code here is partly taken from AROS/rom/dos/lddemon.c - LDInit()
79 addr
=(STRPTR
)(BADDR(seg
)-sizeof(ULONG
));
83 addr
+=sizeof(BPTR
)+sizeof(ULONG
),
84 size
-=sizeof(BPTR
)+sizeof(ULONG
); // Is this a bug? (- -> + ?)
85 size
>=sizeof(struct MidiDeviceData
);
86 size
-=AROS_PTRALIGN
,addr
+=AROS_PTRALIGN
88 mididevicedata
=(struct MidiDeviceData
*)addr
;
91 /* Do some tests to check that we have got a correct mididevicedata.
92 It's not failproof, but the chance for this to fail should be small.
94 mididevicedata
->Magic
==MDD_Magic
&& //Hopefully, this one should only succeed once.
95 mididevicedata
->Name
!=NULL
&&
96 mididevicedata
->Init
!=NULL
&&
97 isPointerInSeglist(mididevicedata
->Init
,seglist
,4) &&
99 (((ULONG
)(mididevicedata
->Init
)&(AROS_PTRALIGN
-1))==0) &&
102 mididevicedata
->Name
,
103 seglist
,mystrlen(findonlyfilename(name
))
106 mystrcmp(findonlyfilename(name
),mididevicedata
->Name
)==TRUE
&&
108 mididevicedata
->Expunge
==NULL
||
110 isPointerInSeglist(mididevicedata
->Expunge
,seglist
,4)
112 && (((ULONG
)(mididevicedata
->Expunge
)&(AROS_PTRALIGN
-1))==0)
118 mididevicedata
->OpenPort
==NULL
||
121 (((ULONG
)(mididevicedata
->OpenPort
)&(AROS_PTRALIGN
-1))==0) &&
123 isPointerInSeglist(mididevicedata
->OpenPort
,seglist
,4)
128 mididevicedata
->ClosePort
==NULL
||
131 (((ULONG
)(mididevicedata
->ClosePort
)&(AROS_PTRALIGN
-1))==0) &&
133 isPointerInSeglist(mididevicedata
->ClosePort
,seglist
,4)
137 mididevicedata
->IDString
!=NULL
&&
138 isPointerInSeglist(mididevicedata
->IDString
,seglist
,4)
143 driver
=AllocMem(sizeof(struct Drivers
),MEMF_ANY
| MEMF_CLEAR
| MEMF_PUBLIC
);
148 driver
->seglist
=seglist
;
149 driver
->mididevicedata
=mididevicedata
;
151 ObtainSemaphore(CB(CamdBase
)->CLSemaphore
);
152 driver
->next
=CB(CamdBase
)->drivers
;
153 CB(CamdBase
)->drivers
=driver
;
154 ReleaseSemaphore(CB(CamdBase
)->CLSemaphore
);
155 return mididevicedata
;
158 seg
=*(BPTR
*)BADDR(seg
);
165 struct CamdDriverIFace
*ICamdDriver
;
166 struct Library
*CamdDriverBase
= (struct CamdDriverLibrary
*) OpenLibrary( name
, 0 );
168 if( CamdDriverBase
== NULL
)
170 // DebugPrintF("Failed to load %s\n", name);
174 if ((ICamdDriver
= (struct CamdDriverIFace
*) GetInterface((struct Library
*) CamdDriverBase
, "main", 1, NULL
)) == NULL
)
176 // DebugPrintF("Failed to load interface for %s\n", name);
177 CloseLibrary(CamdDriverBase
);
182 driver
=AllocMem(sizeof(struct Drivers
),MEMF_ANY
| MEMF_CLEAR
| MEMF_PUBLIC
);
184 CloseLibrary(CamdDriverBase
);
187 driver
->mididevicedata
= AllocMem(sizeof(struct MidiDeviceData
), MEMF_ANY
| MEMF_CLEAR
| MEMF_PUBLIC
);
188 driver
->mididevicedata
->Name
= ICamdDriver
->GetMidiDeviceData()->Name
;
189 driver
->mididevicedata
->IDString
= ICamdDriver
->GetMidiDeviceData()->IDString
;
190 driver
->mididevicedata
->Version
= ICamdDriver
->GetMidiDeviceData()->Version
;
191 driver
->mididevicedata
->Revision
= ICamdDriver
->GetMidiDeviceData()->Revision
;
192 driver
->mididevicedata
->NPorts
= ICamdDriver
->GetMidiDeviceData()->NPorts
;
193 driver
->mididevicedata
->Flags
= ICamdDriver
->GetMidiDeviceData()->Flags
;
194 driver
->mididevicedata
->CamdDriverBase
= CamdDriverBase
;
195 driver
->mididevicedata
->ICamdDriver
= ICamdDriver
;
198 ObtainSemaphore(CB(CamdBase
)->CLSemaphore
);
199 driver
->next
=CB(CamdBase
)->drivers
;
200 CB(CamdBase
)->drivers
=driver
;
201 ReleaseSemaphore(CB(CamdBase
)->CLSemaphore
);
203 return driver
->mididevicedata
;
212 BOOL
isPointerInSeglist(APTR pointer
,BPTR seglist
,ULONG minsize
){
217 addr
=(STRPTR
)(BADDR(seglist
)-sizeof(ULONG
));
219 addr
+=sizeof(BPTR
)+sizeof(ULONG
);
220 size
-=sizeof(BPTR
)+sizeof(ULONG
);
221 if((STRPTR
)pointer
>=addr
&& (STRPTR
)pointer
<=addr
+size
-minsize
){
224 seglist
=*(BPTR
*)BADDR(seglist
);