grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / usb / classes / camdmidi / poseidonusb.asm
blobac2735bedc12e86da26c6c30e3f7c4820342a5b5
2 * CAMD Driver for Poseidon USB camdusbmidi.class
4 * Copyright 2006 Chris Hodges
6 ************************************************************************
7 * Date | Change
8 *-----------------------------------------------------------------------
9 * 04-Feb-2006 : Initial
10 ************************************************************************
12 ;output DEVS:midi/poseidonusb
14 include "AmigaLVOs.s"
15 include "Macros.lnk"
17 include "exec/types.i"
18 include "exec/execbase.i" ; for FlushDevice()
19 include "exec/macros.i"
20 include "exec/ports.i"
21 include "utility/hooks.i"
22 include "midi/camddevices.i"
24 _LVOusbCAMDOpenPort equ -108
25 _LVOusbCAMDClosePort equ -114
27 Version equ 1
28 Revision equ 2
29 Ports equ 16
31 DEBUG_DETAIL set 0
33 STRUCTURE CAMDAdapter,0
34 APTR ca_ActivateFunc
35 BOOL ca_IsOpen
36 STRUCT ca_CAMDRXFunc,h_SIZEOF
37 STRUCT ca_CAMDTXFunc,IS_SIZE
38 ULONG ca_PortNum
39 APTR ca_TXFunc
40 APTR ca_RXFunc
41 APTR ca_UserData
42 APTR ca_TXBuffer
43 ULONG ca_TXBufSize
44 ULONG ca_TXWritePos
45 ULONG ca_TXReadPos
46 APTR ca_MsgPort
47 LABEL CAMDAdapter_SIZE
49 ****************************************************************
51 * Standard MIDI Device driver header
53 ****************************************************************
55 ; code at start of file in case anyone tries to execute us as a program
57 FalseStart
58 moveq #-1,d0
59 rts
61 MDD ; struct MidiDeviceData
62 dc.l MDD_Magic ; mdd_Magic
63 dc.l Name ; mdd_Name
64 dc.l IDString ; mdd_IDString
65 dc.w Version ; mdd_Version
66 dc.w Revision ; mdd_Revision
67 dc.l Init ; mdd_Init
68 dc.l Expunge ; mdd_Expunge
69 dc.l OpenPort ; mdd_OpenPort
70 dc.l ClosePort ; mdd_ClosePort
71 dc.b Ports ; mdd_NPorts
72 dc.b 0 ; mdd_Flags
74 ; 123456789012
75 Name dc.b 'poseidonusb',0
76 dc.b '3456789012345678901',0 ; 32 bytes
78 IDString
79 dc.b '$VER: Poseidon USB camdusbmidi.class driver 1.1 (21-Feb-06)',0
80 dc.b 'Copyright 2006 Chris Hodges',0
81 even
83 ****************************************************************
85 * MidiDeviceData Functions
87 ****************************************************************
89 ****************************************************************
91 * Init
93 * FUNCTION
94 * Gets called by CAMD after being LoadSeg'ed.
96 * INPUTS
97 * None
99 * RESULTS
100 * TRUE if successful, FALSE on failure.
102 ****************************************************************
104 Init
105 PUTMSG 10,<"Init!">
106 PUSHM a6/a0/a1/d1
107 move.l 4.w,a6
108 move.l a6,SysBase
109 lea .classname(pc),a1
110 moveq.l #0,d0
111 CALL OpenLibrary
112 move.l d0,USBClsBase
113 bne.s .good
114 lea .classname2(pc),a1
115 moveq.l #0,d0
116 CALL OpenLibrary
117 move.l d0,USBClsBase
118 .good POPM
120 .classname2
121 dc.b 'USB/'
122 .classname
123 dc.b 'camdusbmidi.class',0
125 even
127 ****************************************************************
129 * Expunge
131 * FUNCTION
132 * Gets called by CAMD immediately before being
133 * UnLoadSeg'ed.
135 * INPUTS
136 * None
138 * RESULTS
139 * None
141 ****************************************************************
143 Expunge
144 PUTMSG 10,<"Expunge!">
145 PUSHM a6/a1/d0/d1
146 move.l SysBase(pc),a6
147 move.l USBClsBase(pc),a1
148 CALL CloseLibrary
149 clr.l USBClsBase
150 POPM
154 ****************************************************************
156 * SendToCAMD
158 * Called by CallHookA() from camdusbmidi.class with Buffer address in a2
159 * and size in a1.
161 ****************************************************************
163 SendToCAMD
164 PUTMSG 10,<"SendToCAMD %08lx, buf=%08lx">,a0,a2
165 PUSHM a2-a4/d2
166 moveq.l #0,d2
167 move.l a2,a3 ; object
168 move.l h_Data(a0),a0
169 move.b (a3)+,d2
170 PUTMSG 10,<"size=%08ld">,d2
171 move.l ca_UserData(a0),a2
172 move.l ca_RXFunc(a0),a4
173 .loop moveq.l #0,d0
174 move.b (a3)+,d0
175 jsr (a4)
176 subq.l #1,d2
177 bgt.s .loop
178 POPM
179 PUTMSG 10,<"done">
182 ****************************************************************
184 * GetFromCAMD
186 * Called by Cause() from ActivateXmit.
188 ****************************************************************
190 GetFromCAMD
191 PUTMSG 10,<"GetFromCAMD %08lx">,a1
192 PUSHM a2-a6/d2/d3
193 move.l a1,a3
194 move.l ca_UserData(a3),a2
195 move.l ca_TXBuffer(a3),a5
196 move.l ca_TXFunc(a3),a4
197 move.l ca_TXBufSize(a3),d3
198 move.l ca_TXWritePos(a3),d2
199 subq.l #1,d3
200 .loop jsr (a4)
201 PUTMSG 10,<"Byte... %lx %ld">,d0,d1
202 move.b d0,(a5,d2.l)
203 addq.l #1,d2
204 and.l d3,d2
205 cmp.l ca_TXReadPos(a3),d2
206 beq.s .oops ; this will lose data!
207 move.l d2,ca_TXWritePos(a3)
208 tst.b d1
209 beq.s .loop
210 .oops
211 move.l ca_MsgPort(a3),d0 ; now inform usb driver
212 beq.s .noport
213 move.l d0,a0
214 move.l MP_SIGTASK(a0),a1
215 moveq.l #1,d0
216 moveq.l #0,d1
217 move.b MP_SIGBIT(a0),d1
218 lsl.l d1,d0
219 move.l SysBase(pc),a6
220 CALL Signal
222 .noport POPM
223 PUTMSG 10,<"Done">
226 ****************************************************************
228 * OpenPort
230 * FUNCTION
231 * Open a MIDI port.
233 * INPUTS
234 * D0.b - Port number (should always be 0 for this driver)
235 * A0 - Xmit function
236 * A1 - Recv function
237 * A2 - Data
239 * RESULT
240 * D0 - pointer to MidiPortData structure.
242 ****************************************************************
244 OpenPort
245 PUTMSG 10,<"OpenPort %ld, Xmit=%08lx,Recv=%08lx,Data=%08lx">,d0,a0,a1,a2
246 PUSHM a6/a0-a3/d1/d2
247 move.l USBClsBase(pc),a6
248 moveq.l #0,d2
249 move.b d0,d2
250 move.l d2,d0
251 lea Name(pc),a3
252 CALL usbCAMDOpenPort
253 lea CAMDPortBases(pc),a0
254 move.l d0,(a0,d2.l*4)
255 beq.s .toobad
256 move.l d0,a0
257 lea ActivateXmit0(pc,d2.l*4),a1
258 move.l a1,ca_ActivateFunc(a0)
260 move.l d0,ca_CAMDRXFunc+h_Data(a0)
261 lea SendToCAMD(pc),a1
262 move.l a1,ca_CAMDRXFunc+h_Entry(a0)
264 move.b #NT_INTERRUPT,ca_CAMDTXFunc+LN_TYPE(a0)
265 clr.b ca_CAMDTXFunc+LN_PRI(a0)
266 move.l d0,ca_CAMDTXFunc+IS_DATA(a0)
267 lea GetFromCAMD(pc),a1
268 move.l a1,ca_CAMDTXFunc+IS_CODE(a0)
269 st ca_IsOpen(a0)
270 .toobad PUTMSG 10,<"Result=%08lx">,d0
271 POPM
275 ****************************************************************
277 * ClosePort
279 * FUNCTION
280 * Close a MIDI port.
282 * INPUTS
283 * D0.b - Port number (always 0 for this driver).
284 * A1 - USBID
286 * RESULT
287 * None
289 ****************************************************************
291 ClosePort
292 PUSHM a6/a0/a1/d1
293 move.l USBClsBase(pc),a6
294 and.l #$ff,d0
295 lea Name(pc),a1
296 CALL usbCAMDClosePort
297 POPM
300 IFNE DEBUG_DETAIL
301 kprintf PUSHM a2-a3/a6
302 lea .putchr(pc),a2
303 move.l 4.w,a6
304 move.l a6,a3
305 CALL RawDoFmt
306 POPM
308 .putchr dc.w $CD4B,$4EAE,$FDFC,$CD4B,$4E75
309 ENDC
311 ****************************************************************
313 * ActivateXmit
315 * Called by CAMD with Midi Data in a0 (or a2?)
316 * BUG: Actually, the Midi Data is not in any register. This sucks
318 ****************************************************************
320 ActivateXmit0
321 moveq.l #0,d0
322 bra.s ActivateXmit
323 moveq.l #1,d0
324 bra.s ActivateXmit
325 moveq.l #2,d0
326 bra.s ActivateXmit
327 moveq.l #3,d0
328 bra.s ActivateXmit
329 moveq.l #4,d0
330 bra.s ActivateXmit
331 moveq.l #5,d0
332 bra.s ActivateXmit
333 moveq.l #6,d0
334 bra.s ActivateXmit
335 moveq.l #7,d0
336 bra.s ActivateXmit
337 moveq.l #8,d0
338 bra.s ActivateXmit
339 moveq.l #9,d0
340 bra.s ActivateXmit
341 moveq.l #10,d0
342 bra.s ActivateXmit
343 moveq.l #11,d0
344 bra.s ActivateXmit
345 moveq.l #12,d0
346 bra.s ActivateXmit
347 moveq.l #13,d0
348 bra.s ActivateXmit
349 moveq.l #14,d0
350 bra.s ActivateXmit
351 moveq.l #15,d0
352 ; bra.s ActivateXmit
354 ActivateXmit
355 PUTMSG 10,<"ActivateXmit Port %ld">,d0
356 PUSHM a6
357 move.l SysBase(pc),a6
358 move.l CAMDPortBases(pc,d0.l*4),a0
359 lea ca_CAMDTXFunc(a0),a1
360 CALL Cause
361 POPM
364 USBClsBase
365 ds.l 1
366 SysBase ds.l 1
368 CAMDPortBases
369 ds.l 16