revert between 56095 -> 55830 in arch
[AROS.git] / arch / all-unix / devs / midi / hostmidi.c
blobafa3874730d9192365c6ada84d31dc8eb7c16ed9
1 /*
2 Copyright © 1995-2011, 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 D(x)
38 #define NUMPORTS 1
40 struct ExecBase *SysBase;
41 struct Library *OOPBase;
42 struct Library *UnixIOBase;
44 OOP_Object *unixio;
45 int midi_fd;
47 int main(void)
49 /* A camd mididriver is not supposed to be run directly, so we return an error. */
51 return -1;
56 /* Prototypes */
58 static const char version[];
60 extern void kprintf(char *bla,...);
62 BOOL ASM Init(REG(a6) APTR sysbase);
63 void Expunge(void);
64 SAVEDS ASM struct MidiPortData *OpenPort(
65 REG(a3) struct MidiDeviceData *data,
66 REG(d0) LONG portnum,
67 REG(a0) ULONG (* ASM transmitfunc)(APTR REG(a2) userdata),
68 REG(a1) void (* ASM receivefunc)(UWORD REG(d0) input,APTR REG(a2) userdata),
69 REG(a2) APTR userdata
71 ASM void ClosePort(
72 REG(a3) struct MidiDeviceData *data,
73 REG(d0) LONG portnum
76 /* End prototypes */
78 /***********************************************************************
79 The mididevicedata struct.
80 Note. It doesn't have to be declared with the const qualifier, since
81 NPorts may be set at Init. You should set the name-field to the
82 same as the filename, that might be a demand...
83 ***********************************************************************/
84 const struct MidiDeviceData mididevicedata =
86 MDD_Magic,
87 "hostmidi",
88 (char *)&version[6],
89 41,
91 Init,
92 Expunge,
93 OpenPort,
94 ClosePort,
95 NUMPORTS,
99 static const char version[] = "$VER: HostMidi V41.0 (c) 2001 AROS - The AROS Research OS";
101 /****************************************************************
102 We only store sysbase, thats all we need in this example.
103 Otherwise, you may want to open libraries, set number of
104 ports, obtain interrupts, etc.
105 ***************************************************************/
107 SAVEDS ASM BOOL Init(REG(a6) APTR sysbase)
109 SysBase=sysbase;
111 D(kprintf("hostmidi_init\n"));
113 OOPBase = OpenLibrary("oop.library", 0);
114 if (!OOPBase) return FALSE;
116 UnixIOBase = OpenLibrary("unixio.hidd", 0);
117 if (!UnixIOBase)
119 CloseLibrary(OOPBase);
120 return FALSE;
123 unixio = OOP_NewObject(NULL, CLID_Hidd_UnixIO, NULL);
124 if (!unixio)
126 CloseLibrary(UnixIOBase);
127 CloseLibrary(OOPBase);
128 return FALSE;
131 midi_fd = Hidd_UnixIO_OpenFile(unixio, "/dev/midi",
132 02, /* O_RDWR */
133 0, /* mode */
134 NULL);
136 if (!midi_fd)
138 OOP_DisposeObject(unixio);
139 CloseLibrary(UnixIOBase);
140 CloseLibrary(OOPBase);
142 return FALSE;
146 return TRUE;
149 /****************************************************************
150 Nothing to do here. Normally, you may want to free memory,
151 close some libraries, free some interrupts, etc.
152 *****************************************************************/
153 void Expunge(void)
155 if (midi_fd) Hidd_UnixIO_CloseFile(unixio, midi_fd, NULL);
156 if (unixio) OOP_DisposeObject(unixio);
158 CloseLibrary(OOPBase);
163 ULONG (ASM *TransmitFunc)(REG(a2) APTR userdata);
164 APTR UserData[NUMPORTS];
168 /****************************************************************
169 Normally, you may want to start an interrupt, or signal another task,
170 or send a message to a port, that calls the transmit-function.
171 But for this small example, sending the signal directly via
172 kprintf is excactly what we want to do.
173 ****************************************************************/
175 SAVEDS ASM void ActivateXmit(REG(a2) APTR userdata,ULONG REG(d0) portnum)
177 ULONG data;
179 for(;;)
181 int errno;
182 char buf[1];
184 data=(TransmitFunc)(userdata);
186 if(data==0x100) return;
188 buf[0] = data;
190 Hidd_UnixIO_WriteFile(unixio, midi_fd, buf, 1, &errno);
194 struct MidiPortData midiportdata=
196 ActivateXmit
200 /****************************************************************
201 This one is called whenever a program that has opened
202 camd.library wants to use your services.
203 ****************************************************************/
204 SAVEDS ASM struct MidiPortData *OpenPort(
205 REG(a3) struct MidiDeviceData *data,
206 REG(d0) LONG portnum,
207 REG(a0) ULONG (* ASM transmitfunc)(APTR REG(a2) userdata),
208 REG(a1) void (* ASM receiverfunc)(UWORD REG(d0) input,APTR REG(a2) userdata),
209 REG(a2) APTR userdata
212 /* We haven't got any receiver function, so we don't bother about storing the receiverfunc variable. */
214 TransmitFunc=transmitfunc;
215 UserData[portnum-1]=userdata;
217 return &midiportdata;
222 /****************************************************************
223 Nothing to do here. Normally, you may want to free memory,
224 mark the port not to be in use anymore, delete a task, etc.
225 *****************************************************************/
226 ASM void ClosePort(
227 REG(a3) struct MidiDeviceData *data,
228 REG(d0) LONG portnum
231 return;