2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
9 #include <proto/exec.h>
10 #include <proto/dos.h>
11 #include <proto/camd.h>
12 #include <proto/utility.h>
15 # include <proto/CamdDriver.h>
16 # include <exec/emulation.h>
20 #include "camd_intern.h"
24 # include AROS_DEBUG_H_FILE
26 BOOL
OpenDriver(struct DriverData
*driverdata
,ULONG
*ErrorCode
,struct CamdBase
*CamdBase
){
30 driverdata
->mididevicedata
->Name
,
40 driverdata
->midiportdata
=(*driverdata
->mididevicedata
->OpenPort
)(
42 driverdata
->midiportdata
= driverdata
->mididevicedata
->ICamdDriver
->OpenPort(
44 driverdata
->mididevicedata
,
46 (ULONG (* ASM
)(APTR
REG(a2
)))Transmitter
,
47 (void (* ASM
)(UWORD
REG(d0
),APTR
REG(a2
))) Receiver
,
51 if(driverdata
->midiportdata
==NULL
){
52 D(bug("camd.library: drivers.c/OpenDriver. (*OpenPort) failed...\n"));
53 EndReceiverProc(driverdata
,CamdBase
);
55 *ErrorCode
=CME_NoUnit(driverdata
->portnum
);
64 void CloseDriver(struct DriverData
*driverdata
,struct CamdBase
*CamdBase
){
66 (*driverdata
->mididevicedata
->ClosePort
)(
68 driverdata
->mididevicedata
->ICamdDriver
->ClosePort(
70 driverdata
->mididevicedata
,
73 EndReceiverProc(driverdata
,CamdBase
);
77 struct Drivers
*driver
,
78 struct MidiDeviceData
*mididevicedata
,
79 struct CamdBase
*CamdBase
84 struct DriverData
*driverdata
;
86 struct MidiCluster
*cluster
;
89 nports
=driver
->numports
;
91 driver
->driverdatas
=AllocMem((ULONG
)(sizeof(struct DriverData
*)*nports
),MEMF_ANY
|MEMF_CLEAR
|MEMF_PUBLIC
);
92 if(driver
->driverdatas
==NULL
){
96 for(lokke
=0;lokke
<nports
;lokke
++){
97 driverdata
=AllocMem(sizeof(struct DriverData
),MEMF_ANY
| MEMF_CLEAR
| MEMF_PUBLIC
);
101 driver
->driverdatas
[lokke
]=driverdata
;
103 driverdata
->innode
.ln_Type
=NT_USER
-MLTYPE_NTypes
;
104 driverdata
->innode
.ln_Pri
=127; // Should be set lower?
106 driverdata
->outnode
.ln_Type
=NT_USER
-MLTYPE_NTypes
;
107 driverdata
->outnode
.ln_Pri
=127; // Should be set lower?
109 driverdata
->mididevicedata
=mididevicedata
;
111 driverdata
->buffer
=AllocVec(sizeof(ULONG
)*OUTBUFFERSIZE
,MEMF_ANY
|MEMF_PUBLIC
);
112 if(driverdata
->buffer
==NULL
){
116 driverdata
->buffercurrsend
=driverdata
->buffer
;
117 driverdata
->buffercurr
=driverdata
->buffer
;
118 driverdata
->bufferend
=driverdata
->buffer
+OUTBUFFERSIZE
;
119 driverdata
->sendpos
=0;
121 driverdata
->buffer_rt
=AllocVec(sizeof(UBYTE
)*OUTBUFFERSIZE_RT
,MEMF_ANY
|MEMF_PUBLIC
);
122 if(driverdata
->buffer_rt
==NULL
){
125 driverdata
->buffercurrsend_rt
=driverdata
->buffer_rt
;
126 driverdata
->buffercurr_rt
=driverdata
->buffer_rt
;
127 driverdata
->bufferend
=driverdata
->buffer
+OUTBUFFERSIZE_RT
;
130 driverdata
->status
=0;
131 driverdata
->portnum
=lokke
;
133 driverdata
->Input_Treat
=Receiver_init
;
135 driverdata
->re_start
=AllocVec((ULONG
)(sizeof(UWORD
)*RECEIVERPROCBUFFERSIZE
),MEMF_ANY
|MEMF_PUBLIC
);
136 if(driverdata
->re_start
==NULL
){
139 driverdata
->re_write
=driverdata
->re_start
;
140 driverdata
->re_end
=driverdata
->re_start
+RECEIVERPROCBUFFERSIZE
;
141 driverdata
->re_read
=driverdata
->re_start
;
144 mysprintf(CamdBase
,nametemp
,"%s.in.%ld",mididevicedata
->Name
,lokke
);
145 if((cluster
=NewCluster(nametemp
,CamdBase
))==FALSE
){
148 driverdata
->incluster
=(struct MyMidiCluster
*)cluster
;
150 mysprintf(CamdBase
,nametemp
,"%s.out.%ld",mididevicedata
->Name
,lokke
);
151 if((cluster
=NewCluster(nametemp
,CamdBase
))==FALSE
){
154 driverdata
->outcluster
=(struct MyMidiCluster
*)cluster
;
156 InitSemaphore(&driverdata
->sendsemaphore
);
157 InitSemaphore(&driverdata
->sysexsemaphore
);
159 driverdata
->isOutOpen
=FALSE
;
160 driverdata
->isInOpen
=FALSE
;
163 for(lokke
=0;lokke
<nports
;lokke
++){
164 driverdata
=driver
->driverdatas
[lokke
];
165 AddClusterSender(&driverdata
->incluster
->cluster
,&driverdata
->innode
,NULL
,CamdBase
);
166 AddClusterReceiver(&driverdata
->outcluster
->cluster
,&driverdata
->outnode
,NULL
,CamdBase
);
173 void FreeDriverData(struct Drivers
*driver
,
174 struct CamdBase
*CamdBase
176 struct DriverData
*driverdata
;
179 if(driver
->driverdatas
!=NULL
){
180 for(lokke
=0;lokke
<driver
->numports
;lokke
++){
181 driverdata
=driver
->driverdatas
[lokke
];
182 RemoveCluster(&driverdata
->incluster
->cluster
,CamdBase
);
183 RemoveCluster(&driverdata
->outcluster
->cluster
,CamdBase
);
187 if(driver
->driverdatas
!=NULL
){
188 for(lokke
=0;lokke
<driver
->numports
;lokke
++){
189 driverdata
=driver
->driverdatas
[lokke
];
190 if(driverdata
!=NULL
){
191 if(driverdata
->buffer
!=NULL
){
192 FreeVec(driverdata
->buffer
);
194 if(driverdata
->buffer_rt
!=NULL
){
195 FreeVec(driverdata
->buffer_rt
);
197 if(driverdata
->re_start
!=NULL
){
198 FreeVec(driverdata
->re_start
);
202 FreeMem(driver
->driverdatas
,sizeof(struct DriverData
*)*driver
->numports
);
206 struct Drivers
*FindPrevDriverForMidiDeviceData(
207 struct MidiDeviceData
*mididevicedata
,
208 struct CamdBase
*CamdBase
210 struct Drivers
*driver
,*temp
=NULL
;
212 driver
=CB(CamdBase
)->drivers
;
214 while(driver
->mididevicedata
!=mididevicedata
){
223 void LoadDriver(char *name
,
224 struct CamdIFace
*ICamd
226 CAMD_LIBBASE_DECL(struct CamdBase
*,CamdBase
)
228 void LoadDriver(char *name
,
229 struct CamdBase
*CamdBase
232 struct Drivers
*driver
= NULL
;
233 struct MidiDeviceData
*mididevicedata
= NULL
;
235 D(bug("camd.library: drivers.c/LoadDriver - trying to open %s..\n",name
));
237 mididevicedata
=OpenMidiDevice(name
);
238 D(bug("camd.library: drivers.c/LoadDriver - It was%s a success..\n",mididevicedata
==NULL
?" not":""));
240 if(mididevicedata
==NULL
) return;
242 if((mididevicedata
->Flags
&1)==0){
244 D(bug("%s: mididevicedata->Flags&1==0 is not not supported for AROS!\n",name
));
245 CloseMidiDevice(mididevicedata
);
248 D(bug("%s: old camd driver format. (Supported)\n",name
));
253 if((*mididevicedata
->Init
)(SysBase
)==FALSE
){
254 CloseMidiDevice(mididevicedata
);
260 //D(bug("%s %s %u %u\n", mididevicedata->Name, mididevicedata->IDString, mididevicedata->NPorts,mididevicedata->Flags));
262 driver
=FindPrevDriverForMidiDeviceData(mididevicedata
,CamdBase
);
264 driver
=CB(CamdBase
)->drivers
;
269 driver
->numports
=mididevicedata
->NPorts
;
271 if(AllocDriverData(driver
,mididevicedata
,CamdBase
)==FALSE
){
272 FreeDriverData(driver
,CamdBase
);
273 CloseMidiDevice(mididevicedata
);