grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / camd / camd_intern.h
blob65923976bc0147e3b32f014587fef3de28e24d74
1 #ifndef CAMD_INTERN_H
2 #define CAMD_INTERN_H
4 /*
5 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
6 $Id$
8 Desc:
9 Lang: English
12 #ifndef EXEC_TYPES_H
13 # include <exec/types.h>
14 #endif
15 #ifndef EXEC_LIBRARIES_H
16 # include <exec/libraries.h>
17 #endif
19 #ifndef __AROS__
20 # define AROS_LIBFUNC_INIT
21 # define AROS_LIBFUNC_EXIT
22 # ifndef __amigaos4__
23 # define aros_print_not_implemented(a) kprintf("camd.library: "a" is not implemented\n");
24 # else
25 # define aros_print_not_implemented(a) DebugPrintF("camd.library: "a" is not implemented\n");
26 # endif
27 # define AROS_PTRALIGN 2
28 #else
29 # ifndef AROS_LIBCALL_H
30 # include <aros/libcall.h>
31 # endif
32 #endif
34 #ifndef DOS_DOS_H
35 # include <dos/dos.h>
36 #endif
37 #ifndef UTILITY_UTILITY_H
38 # include <utility/utility.h>
39 #endif
41 #ifndef MIDI_CAMD_H
42 # include <midi/camd.h>
43 #endif
45 #ifndef MIDI_CAMDDEVICES_H
46 # include <midi/camddevices.h>
47 #endif
49 #ifndef EXEC_SEMAPHORES_H
50 # include <exec/semaphores.h>
51 #endif
52 #ifndef EXEC_MEMORY_H
53 # include <exec/memory.h>
54 #endif
55 #ifndef DOS_DOSEXTENS_H
56 #include <dos/dosextens.h>
57 #endif
59 #ifdef __AROS__
60 # undef DEBUG
61 # define DEBUG 1
62 # include <aros/debug.h>
63 #endif
66 #ifdef __amigaos4__
67 # include <libcore/base.h>
68 # include <interfaces/camd.h>
69 # define CAMD_LIBBASE_DECL(a,b) a b = (a) ICamd->Data.LibBase;
70 #endif
74 /****************************************************************************************/
76 #define OUTBUFFERSIZE 1025
77 #define OUTBUFFERSIZE_RT 1025
78 #define RECEIVERPROCBUFFERSIZE 1025
79 #define SYSEXRECEIVERPROCBUFFERSIZE 1025
80 #define NUMBEROFSYSEXSTORECEIVE 1025
82 struct MyMidiMessage2{
83 UBYTE status;
84 UBYTE data1;
85 UBYTE data2;
86 UBYTE len;
89 struct MyMidiCluster{
90 struct MidiCluster cluster;
91 struct SignalSemaphore semaphore;
94 struct DriverData{
95 struct Node outnode; // Used for the outcluster's receiverlist
96 struct Node innode; // Used for the incluster's senderlist
98 struct Drivers *driver;
99 struct MyMidiCluster *incluster; // Clusters we belong to.
100 // in = sender cluster
101 // out = receiver cluster
102 struct MyMidiCluster *outcluster;
103 struct MidiPortData *midiportdata;
104 struct MidiDeviceData *mididevicedata;
105 LONG portnum;
107 BOOL isInOpen; // Driver is opened if at least one of these two ones is TRUE
108 BOOL isOutOpen;
110 ULONG *buffer; // Sendbuffer start
111 ULONG *buffercurrsend; // Sendbuffer write
112 ULONG *buffercurr; // Sendbuffer read
113 ULONG *bufferend; // Sendbuffer end
115 int sendpos; // 0,1 or 2. Position in current sendmessage. (Is only 0 at startup, so 1 or 2 are the only used values)
116 int status; // Current send running status
118 int unsent; // Number of messages waiting to be sent
119 int unsent_rt; // Number of realtime messages waiting to be sent
120 int issending_sx; // =1 if a sysex message is currently being sent.
122 int buffercurrsend_sx; // Number of bytes in the current sysex message being sent.
123 UBYTE *buffer_sx; // Pointer to user-suplied sysex message
124 int unsent_sx; // Used by miditodriver_oldformat
126 UBYTE *buffer_rt; // Realtime sendbuffer start
127 UBYTE *buffercurrsend_rt; // Realtime sendbuffer write
128 UBYTE *buffercurr_rt; // Realtime sendbuffer read
129 UBYTE *bufferend_rt; // Realtime sendbuffer end
130 int isnowtransmitting; // Used by mididitodriver_oldformat
132 int realtimesysx; // =1 if the current sysex message being sent is realtime.
134 ULONG (*transmitfunc)( // Virtual function for the transmitter driver-code.
135 struct DriverData *driverdata
138 struct MyMidiMessage2 msg2; // In-message, to be supplied to the midinodes.
140 struct SignalSemaphore sendsemaphore; // Obtained when putting message to driver
141 struct SignalSemaphore sysexsemaphore; // Obtained when putting sysex to driver.
143 void (*Input_Treat)( // Virtual function for the receiver driver-code.
144 struct DriverData *driverdata,
145 UBYTE data
149 // The following datas are for the ReceiverProcess.
151 struct Process *ReceiverProc;
152 ULONG ReceiverSig;
154 UWORD *re_start;
155 UWORD *re_write;
156 UWORD *re_end;
157 int unpicked;
158 UWORD *re_read;
160 // To know the status of a ReceiverProcess. 0=not alive, or not initialized yet. 1=alive and fine. 2=signal failed.
161 LONG isReceiverProcessAlive;
162 // Keep pointer so it can be freed after the process dies.
163 char *ReceiverProcName;
165 // The following is for ParseMidi
166 UBYTE *lastsysex;
169 struct Drivers{
170 struct Drivers *next;
171 ULONG numports;
172 BPTR seglist;
173 struct MidiDeviceData *mididevicedata;
174 struct DriverData **driverdatas;
178 struct MyMidiNode{
179 struct MidiNode midinode;
181 ULONG error;
183 MidiMsg *in_start;
184 MidiMsg *in_curr;
185 MidiMsg *in_end;
187 int unpicked;
189 MidiMsg *in_curr_get;
191 ULONG dummytimestamp; // To avoid reading from NULL if no timestamp was defined.
193 struct SignalSemaphore receiversemaphore;
195 // For sysex receiving. (probably needs some rewriting)
197 struct SignalSemaphore sysexsemaphore;
198 struct SignalSemaphore sysexsemaphore2;
199 UBYTE *sysex_start;
200 UBYTE *sysex_write;
201 UBYTE *sysex_end;
202 UBYTE *sysex_read;
203 UBYTE *sysex_laststart;
204 BOOL sysex_nextis0;
205 UBYTE lastreadstatus;
208 struct CamdBase_intern{
209 #ifndef __amigaos4__
210 struct Library library;
211 #else
212 struct LibHeader lh;
213 #endif
214 struct Drivers *drivers;
215 struct List mymidinodes;
216 struct List midiclusters;
218 struct List clusnotifynodes;
221 /* Lock semaphore. Obtained Shared before reading various lists and
222 obtained exclusive before adding/deleting to/from various lists. */
224 struct SignalSemaphore *CLSemaphore;
228 #ifdef __AMIGAOS__
229 extern void kprintf(char *bla,...);
230 # ifdef DEBUG
231 # ifndef __amigaos4__
232 # define bug kprintf
233 # else
234 # define bug DebugPrintF
235 # endif
236 # define D(a) a
237 # else
238 # define D(a)
239 # endif
240 # ifndef CONST_STRPTR
241 # define CONST_STRPTR const APTR
242 # endif
243 # ifndef VOID_FUNC
244 # define VOID_FUNC APTR // Yeah.
245 # endif
246 # define AROS_DEBUG_H_FILE "camd_intern.h" // DoNothing
247 #else
248 # define AROS_DEBUG_H_FILE <aros/debug.h>
249 #endif
251 /****************************************************************************************/
253 # undef CB
254 # define CB(b) ((struct CamdBase_intern *)b)
256 /****************************************************************************************/
259 #ifndef NEWLIST
260 # define NEWLIST(l) (((struct List *)l)->lh_TailPred = (struct Node *)(l),((struct List *)l)->lh_Tail=0,((struct List *)l)->lh_Head = (struct Node *)&(((struct List *)l)->lh_Tail))
261 #endif
264 #ifndef FUNCTIONTABLE
265 /* Prototypes */
267 struct CamdBase{struct Library library;};
268 BYTE GetMsgLen(LONG msg);
269 void PutMidi2Link(
270 struct MidiLink *midilink,
271 struct MyMidiMessage2 *msg2,
272 ULONG timestamp
274 void UnlinkMidiLink(struct MidiLink *midilink,BOOL unlinkfromnode,struct CamdBase *CamdBase);
275 BOOL Midi2Driver_internal(
276 struct DriverData *driverdata,
277 ULONG msg,
278 ULONG maxbuff
280 BOOL Midi2Driver_internal_oldformat(
281 struct DriverData *driverdata,
282 ULONG msg,
283 ULONG maxbuff
285 #ifndef __amigaos4__
286 ULONG ASM Transmitter(REG(a2) struct DriverData *driverdata);
287 ULONG ASM Transmitter_oldformat(REG(a2) struct DriverData *driverdata);
288 #else
289 ULONG Transmitter(struct DriverData *driverdata);
290 ULONG ASM Transmitter_oldformat(REG(a2, struct DriverData *driverdata));
291 #endif
292 BOOL SysEx2Driver(struct DriverData *driverdata,UBYTE *buffer);
293 BOOL SysEx2Driver_oldformat(struct DriverData *driverdata, UBYTE *buffer);
294 void RemoveCluster(struct MidiCluster *cluster,struct CamdBase *CamdBase);
295 void LinkHasBeenRemovedFromCluster(struct MidiCluster *cluster,struct CamdBase *CamdBase);
296 struct MidiCluster *NewCluster(char *name,struct CamdBase *CamdBase);
297 struct DriverData *FindReceiverDriverInCluster(struct MidiCluster *cluster);
298 struct DriverData *FindSenderDriverInCluster(struct MidiCluster *cluster);
299 BOOL AddClusterReceiver(
300 struct MidiCluster *cluster,
301 struct Node *node,
302 ULONG *ErrorCode,
303 struct CamdBase *CamdBase
305 BOOL AddClusterSender(
306 struct MidiCluster *cluster,
307 struct Node *node,
308 ULONG *ErrorCode,
309 struct CamdBase *CamdBase
311 BOOL SetClusterForLink(
312 struct MidiLink *midilink,
313 char *name,
314 ULONG *ErrorCode,
315 struct CamdBase *CamdBase
318 BOOL CreateReceiverProc(
319 struct DriverData *driverdata,
320 char *name,
321 LONG portnum,
322 ULONG *ErrorCode,
323 struct CamdBase *CamdBase
326 void EndReceiverProc(
327 struct DriverData *driverdata,
328 struct CamdBase *CamdBase
331 void Receiver_SysExSuperTreat(
332 struct DriverData *driverdata,
333 UBYTE data
335 int GetSysXLen(UBYTE *buffer);
336 BOOL PutSysEx2Link(struct MidiLink *midilink,UBYTE data);
337 void Receiver_SetError(
338 struct DriverData *driverdata,
339 ULONG errorcode
341 void Receiver_RealTime(
342 struct DriverData *driverdata,
343 UBYTE status
345 void Receiver_init(
346 struct DriverData *driverdata,
347 UBYTE data
350 void Receiver_first(
351 struct DriverData *driverdata
354 #ifndef __amigaos4__
355 void ASM Receiver(
356 REG(d0) UWORD input,
357 REG(a2) struct DriverData *driverdata
359 #else
360 void ASM Receiver(
361 REG(d0, UWORD input),
362 REG(a2, struct DriverData *driverdata)
364 #endif
366 extern WORD MidiMsgType_status(UBYTE status);
367 extern WORD MidiMsgType_CMB_Ctrl(UBYTE data1);
368 extern WORD MidiMsgType_status_data1(UBYTE status,UBYTE data1);
370 BOOL OpenDriver(struct DriverData *driverdata,ULONG *ErrorCode,struct CamdBase *CamdBase);
371 void CloseDriver(struct DriverData *driverdata,struct CamdBase *CamdBase);
373 void FreeDriverData(struct Drivers *driver,
374 struct CamdBase *CamdBase
376 void LoadDriver(char *name,
377 struct CamdBase *CamdBase
380 struct Drivers *FindPrevDriverForMidiDeviceData(
381 struct MidiDeviceData *mididevicedata,
382 struct CamdBase *CamdBase
385 ULONG mystrlen(char *string);
386 BOOL mystrcmp(char *one,char *two);
387 char *findonlyfilename(char *pathfile);
388 #ifndef __amigaos4__
389 void mysprintf(struct CamdBase *camdbase,char *string,char *fmt,...);
390 #else
391 # define mysprintf(camdbase, string, fmt, ...) SNPrintf(string, 256, fmt, __VA_ARGS__)
392 #endif
393 struct MidiLink *GetMidiLinkFromOwnerNode(struct MinNode *node);
395 void CamdWait(void);
397 #endif
399 BOOL InitCamdTimer(void);
400 void UninitCamdTimer(void);
402 #ifdef __amigaos4__
403 APTR GoodPutMidi ( struct CamdIFace *ICamd, struct MidiLink * midilink, uint32 msg, uint32 maxbuff );
404 #endif
406 #ifdef __amigaos4__
407 BOOL InitCamd(struct CamdIFace *ICamd);
408 void UninitCamd(struct CamdIFace *ICamd);
409 #else
410 BOOL InitCamd(struct CamdBase *CamdBase);
411 void UninitCamd(struct CamdBase *CamdBase);
412 #endif
414 #endif /* CAMD_INTERN_H */