use log2 from stdc
[AROS.git] / workbench / libs / camd / querysysex.c
blob1436696e189c19d0fac8638a2697786e2cd43041
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 #include <proto/exec.h>
11 #include "camd_intern.h"
14 /*****************************************************************************
16 NAME */
18 AROS_LH1(ULONG, QuerySysEx,
20 /* SYNOPSIS */
21 AROS_LHA(struct MidiNode *, midinode, A0),
23 /* LOCATION */
24 struct CamdBase *, CamdBase, 28, Camd)
26 /* FUNCTION
27 Returns the number of bytes remaining in the current sys/ex message.
29 INPUTS
30 midinode - pointer to MidiNode
32 RESULT
33 Remaining bytes in sys/ex message. 0 is returned if the last
34 message read from GetMidi() wasn't a sys/ex message.
36 NOTES
38 EXAMPLE
40 BUGS
41 Tested.
43 SEE ALSO
44 SkipSysEx(), GetSysEx()
46 INTERNALS
48 HISTORY
50 2001-01-12 ksvalast first created
51 2005-06-30 Lyle Hazelwood fixed sum to include EOX byte
52 2006-01-28 fixed wraparound bug (buffer overflow)
54 *****************************************************************************/
56 AROS_LIBFUNC_INIT
58 struct MyMidiNode *mymidinode=(struct MyMidiNode *)midinode;
59 UBYTE *sysex;
60 ULONG numleft=1;
62 if(mymidinode->lastreadstatus!=0xf0) return 0;
64 ObtainSemaphore(&mymidinode->sysexsemaphore2);
66 if(mymidinode->sysex_nextis0==TRUE){
67 ReleaseSemaphore(&mymidinode->sysexsemaphore2);
68 return 0;
71 sysex=mymidinode->sysex_read;
73 while(*sysex!=0xf7){
74 numleft++;
75 sysex++;
76 if(sysex == mymidinode->sysex_end)
77 sysex = mymidinode->sysex_start;
80 ReleaseSemaphore(&mymidinode->sysexsemaphore2);
82 return numleft;
84 AROS_LIBFUNC_EXIT