Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / camd / sysexdistr.c
blob6ec558a48406347806028460281b4cb95db1a036
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 #include <proto/exec.h>
10 #include <proto/dos.h>
12 #include "camd_intern.h"
15 /* Sysex receiving is a bit of a mess... (and not very much tested either) -ksvalast- */
17 int GetSysXLen(UBYTE *buffer){
18 int lokke=1;
20 while(buffer[lokke]<0x80){ // "!=0xf7" should allso be correct, but this one is perhaps safer.
21 lokke++;
24 return lokke;
27 BOOL PutSysEx2Link(struct MidiLink *midilink,UBYTE data){
28 UBYTE *sysex;
29 struct MyMidiMessage2 msg2;
31 struct MyMidiNode *mymidinode=(struct MyMidiNode *)midilink->ml_MidiNode;
33 if(mymidinode->sysex_laststart==NULL && data!=0xf0){
34 return TRUE; // This midinode was created in the middle of receiving a sysex-string.
37 if(mymidinode->sysex_start!=NULL && (!(mymidinode->error&CMEF_SysExFull))){
38 if(data==0xff){ // Error in sysex-string. Sysex is cancelled.
39 mymidinode->sysex_write=mymidinode->sysex_laststart;
40 ReleaseSemaphore(&mymidinode->sysexsemaphore);
41 return FALSE;
42 }else{
43 if(data==0xf0){
44 ObtainSemaphore(&mymidinode->sysexsemaphore);
45 ObtainSemaphore(&mymidinode->sysexsemaphore2);
46 mymidinode->sysex_laststart=mymidinode->sysex_write;
47 }else{
48 ObtainSemaphore(&mymidinode->sysexsemaphore2);
50 *mymidinode->sysex_write=data;
51 mymidinode->sysex_write++;
52 if(mymidinode->sysex_write==mymidinode->sysex_end){
53 mymidinode->sysex_write=mymidinode->sysex_start;
55 if(mymidinode->sysex_write==mymidinode->sysex_read){
56 mymidinode->error |= CMEF_SysExFull;
57 mymidinode->sysex_write=mymidinode->sysex_laststart;
58 ReleaseSemaphore(&mymidinode->sysexsemaphore2);
59 ReleaseSemaphore(&mymidinode->sysexsemaphore);
60 return FALSE;
62 ReleaseSemaphore(&mymidinode->sysexsemaphore2);
63 if(data==0xf7){
64 sysex=mymidinode->sysex_laststart;
65 msg2.status=sysex[1];
66 msg2.data1=sysex[2];
67 msg2.data2=sysex[3];
68 msg2.len=3;
69 PutMidi2Link(midilink,&msg2,*mymidinode->midinode.mi_TimeStamp);
70 ReleaseSemaphore(&mymidinode->sysexsemaphore);
71 return FALSE;
74 return TRUE;
75 }else{
76 return FALSE;