add a missing section header table index conversion
[tangerine.git] / workbench / devs / midi / hostmidi.c
blob402fe681a9867801e6722570f1780826676565a1
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
11 /*********************************************************************************
12 Not a very good example at all. But at least it should prove that
13 AROS is able to use camd-drivers. -Kjetil M.
15 Compiling it up is easy. Its just like any other AROS-program, showed
16 by this makefile:
19 debugdriver: debugdriver.o
20 gcc -nostartfiles -nostdlib -Xlinker -i ../../lib/startup.o debugdriver.o -o debugdriver -L../../lib -larossupport -lamiga -larosc -larosm
22 debugdriver.o: debugdriver.c makefile
23 gcc debugdriver.c -c -I../../Include -Wall
26 ***********************************************************************************/
29 #include <exec/types.h>
30 #include <midi/camddevices.h>
31 #include <hidd/unixio.h>
32 #include <proto/exec.h>
33 #include <proto/oop.h>
34 #include <libcore/compiler.h>
36 #define NUMPORTS 1
38 struct ExecBase *SysBase;
39 struct Library *OOPBase;
41 OOP_Object *unixio;
42 int midi_fd;
44 int main(void)
46 /* A camd mididriver is not supposed to be run directly, so we return an error. */
48 return -1;
53 /* Prototypes */
55 extern void kprintf(char *bla,...);
57 BOOL ASM Init(REG(a6) APTR sysbase);
58 void Expunge(void);
59 SAVEDS ASM struct MidiPortData *OpenPort(
60 REG(a3) struct MidiDeviceData *data,
61 REG(d0) LONG portnum,
62 REG(a0) ULONG (* ASM transmitfunc)(APTR REG(a2) userdata),
63 REG(a1) void (* ASM recievefunc)(UWORD REG(d0) input,APTR REG(a2) userdata),
64 REG(a2) APTR userdata
66 ASM void ClosePort(
67 REG(a3) struct MidiDeviceData *data,
68 REG(d0) LONG portnum
71 /* End prototypes */
75 /***********************************************************************
76 The mididevicedata struct.
77 Note. It doesn't have to be declared with the const qualifier, since
78 NPorts may be set at Init. You should set the name-field to the
79 same as the filename, that might be a demand...
80 ***********************************************************************/
81 const struct MidiDeviceData mididevicedata =
83 MDD_Magic,
84 "hostmidi",
85 "HostMidi V41.0 (c) 2001 AROS - The AROS Research OS",
86 41,
88 Init,
89 Expunge,
90 OpenPort,
91 ClosePort,
92 NUMPORTS,
96 /****************************************************************
97 We only store sysbase, thats all we need in this example.
98 Otherwise, you may want to open libraries, set number of
99 ports, obtain interrupts, etc.
100 ***************************************************************/
102 SAVEDS ASM BOOL Init(REG(a6) APTR sysbase)
104 SysBase=sysbase;
106 kprintf("hostmidi_init\n");
107 OOPBase = OpenLibrary("oop.library", 0);
108 if (!OOPBase) return FALSE;
110 unixio = OOP_NewObject(NULL, CLID_Hidd_UnixIO, NULL);
111 if (!unixio)
113 CloseLibrary(OOPBase);
114 return FALSE;
117 midi_fd = Hidd_UnixIO_OpenFile((HIDD *)unixio, "/dev/midi",
118 02, /* O_RDWR */
119 0, /* mode */
120 NULL);
122 if (!midi_fd)
124 OOP_DisposeObject(unixio);
125 CloseLibrary(OOPBase);
127 return FALSE;
131 return TRUE;
134 /****************************************************************
135 Nothing to do here. Normally, you may want to free memory,
136 close some libraries, free some interrupts, etc.
137 *****************************************************************/
138 void Expunge(void)
140 if (midi_fd) Hidd_UnixIO_CloseFile((HIDD *)unixio, midi_fd, NULL);
141 if (unixio) OOP_DisposeObject(unixio);
143 CloseLibrary(OOPBase);
148 ULONG (ASM *TransmitFunc)(REG(a2) APTR userdata);
149 APTR UserData[NUMPORTS];
153 /****************************************************************
154 Normally, you may want to start an interrupt, or signal another task,
155 or send a message to a port, that calls the transmit-function.
156 But for this small example, sending the signal directly via
157 kprintf is excactly what we want to do.
158 ****************************************************************/
160 SAVEDS ASM void ActivateXmit(REG(a2) APTR userdata,ULONG REG(d0) portnum)
162 ULONG data;
164 for(;;)
166 int written, errno;
167 char buf[1];
169 data=(TransmitFunc)(userdata);
171 if(data==0x100) return;
173 buf[0] = data;
175 written = Hidd_UnixIO_WriteFile((HIDD *)unixio, midi_fd, buf, 1, &errno);
179 struct MidiPortData midiportdata=
181 ActivateXmit
185 /****************************************************************
186 This one is called whenever a program that has opened
187 camd.library wants to use your services.
188 ****************************************************************/
189 SAVEDS ASM struct MidiPortData *OpenPort(
190 REG(a3) struct MidiDeviceData *data,
191 REG(d0) LONG portnum,
192 REG(a0) ULONG (* ASM transmitfunc)(APTR REG(a2) userdata),
193 REG(a1) void (* ASM recieverfunc)(UWORD REG(d0) input,APTR REG(a2) userdata),
194 REG(a2) APTR userdata
197 /* We haven't got any receiver function, so we don't bother about storing the receiverfunc variable. */
199 TransmitFunc=transmitfunc;
200 UserData[portnum-1]=userdata;
202 return &midiportdata;
207 /****************************************************************
208 Nothing to do here. Normally, you may want to free memory,
209 mark the port not to be in use anymore, delete a task, etc.
210 *****************************************************************/
211 ASM void ClosePort(
212 REG(a3) struct MidiDeviceData *data,
213 REG(d0) LONG portnum
216 return;