Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / AHI / Drivers / ac97 / ac97-playslave.c
blob0a9be14b2cc8b964cf7432f2d037e8d46db0c7b6
1 #define DEBUG 0
2 #include <aros/debug.h>
3 #include <asm/io.h>
5 #include <devices/ahi.h>
6 #include <libraries/ahi_sub.h>
8 #include "DriverData.h"
9 #include "library.h"
11 #define dd ((struct AC97Data *) AudioCtrl->ahiac_DriverData)
13 /******************************************************************************
14 ** The slave process **********************************************************
15 ******************************************************************************/
17 #undef SysBase
19 void Slave( struct ExecBase* SysBase );
21 #if defined( __AROS__ )
23 #include <aros/asmcall.h>
25 AROS_UFH3(void, SlaveEntry,
26 AROS_UFHA(STRPTR, argPtr, A0),
27 AROS_UFHA(ULONG, argSize, D0),
28 AROS_UFHA(struct ExecBase *, SysBase, A6))
30 AROS_USERFUNC_INIT
31 Slave( SysBase );
32 AROS_USERFUNC_EXIT
35 #else
37 void SlaveEntry(void)
39 struct ExecBase* SysBase = *((struct ExecBase**) 4);
41 Slave( SysBase );
43 #endif
45 struct BufferDescriptor {
46 APTR pointer;
47 ULONG length;
50 void
51 Slave( struct ExecBase* SysBase )
53 struct AHIAudioCtrlDrv* AudioCtrl;
54 struct DriverBase* AHIsubBase;
55 struct ac97Base* ac97Base;
56 BOOL running, firstTime = TRUE;
57 ULONG signals;
59 AudioCtrl = (struct AHIAudioCtrlDrv*) FindTask( NULL )->tc_UserData;
60 AHIsubBase = (struct DriverBase*) dd->ahisubbase;
61 ac97Base = (struct ac97Base*) AHIsubBase;
63 dd->slavesignal = AllocSignal( -1 );
66 // outb(0x1e, ac97Base->dmabase + PO_CR);
67 // outl(ac97Base->PCM_out, ac97Base->dmabase + PO_BDBAR);
69 D(bug("SR=%04x CR=%04x CIV=%02x LVI=%02x\n", inw(ac97Base->dmabase + ac97Base->off_po_sr),
70 inw(ac97Base->dmabase + PO_CR),
71 inb(ac97Base->dmabase + PO_CIV),
72 inb(ac97Base->dmabase + PO_LVI)));
74 if( dd->slavesignal != -1 )
76 // Everything set up. Tell Master we're alive and healthy.
78 Signal( (struct Task*) dd->mastertask,
79 1L << dd->mastersignal );
81 running = TRUE;
83 SetTaskPri(FindTask(NULL), 127);
85 int tail = (inb(ac97Base->dmabase + PO_CIV) + 1) & 0x1f;
87 while( running )
89 signals = SetSignal(0L,0L);
92 if( signals & ( SIGBREAKF_CTRL_C | (1L << dd->slavesignal) ) )
94 running = FALSE;
96 else
98 int i,j;
99 IPTR buff;
100 CallHookPkt( AudioCtrl->ahiac_PlayerFunc, AudioCtrl, NULL );
101 CallHookPkt( AudioCtrl->ahiac_MixerFunc, AudioCtrl, dd->mixbuffer );
103 i = AudioCtrl->ahiac_BuffSamples << 1;
104 i <<= ac97Base->size_shift; /* For SIS 7012 size must be in bytes */
105 j = tail;
106 buff = (IPTR)dd->mixbuffer;
108 while (i > 0)
110 ac97Base->PCM_out[j].sample_address = (APTR)buff;
111 ac97Base->PCM_out[j].sample_size = (i > 65532) ? 65532 : i;
113 i -= ac97Base->PCM_out[j].sample_size;
114 buff += ac97Base->PCM_out[j].sample_size
115 << (1 - ac97Base->size_shift); /* SIS 7012: size already in bytes */
116 j++;
117 tail++;
118 tail &= 0x1f;
119 j &= 0x1f;
121 ac97Base->PCM_out[(j-1) & 0x1f].sample_size |= 0x80000000;
123 D(bug("playing audio from %x (size %d, buffer %d)\n",
124 dd->mixbuffer, AudioCtrl->ahiac_BuffSamples, j-1));
126 D(bug("SR=%08x ",inl(ac97Base->dmabase + PO_CIV)));
128 // outw(4, ac97Base->dmabase + ac97Base->off_po_sr);
129 outb((j-1) & 0x1f, ac97Base->dmabase + PO_LVI);
130 if (firstTime)
132 outb(0x11, ac97Base->dmabase + PO_CR);
133 /* Enable busmaster + interrupt on completion */
134 firstTime = FALSE;
137 // outw(0x1c, ac97Base->dmabase + ac97Base->off_po_sr);
138 // D(bug("SR=%04x ",inw(ac97Base->dmabase + ac97Base->off_po_sr)));
139 // while (!(inw(ac97Base->dmabase + ac97Base->off_po_sr) & 8)) {
140 // D(bug("SR=%04x ",inw(ac97Base->dmabase + ac97Base->off_po_sr)));
142 D(bug("Waiting for int..."));
143 Wait(SIGBREAKF_CTRL_E);
144 D(bug("Got it\n"));
146 // }
147 // D(bug("SR=%04x\n",inw(ac97Base->dmabase + ac97Base->off_po_sr)));
148 // outw(inw(ac97Base->dmabase + ac97Base->off_po_sr), ac97Base->dmabase + ac97Base->off_po_sr);
150 // ac97Base->PCM_out
151 // The mixing buffer is now filled with AudioCtrl->ahiac_BuffSamples
152 // of sample frames (type AudioCtrl->ahiac_BuffType). Send them
153 // to the sound card here.
158 outb(0, ac97Base->dmabase + PO_CR);
159 FreeSignal( dd->slavesignal );
160 dd->slavesignal = -1;
162 Forbid();
164 // Tell the Master we're dying
166 Signal( (struct Task*) dd->mastertask,
167 1L << dd->mastersignal );
169 dd->slavetask = NULL;
171 // Multitasking will resume when we are dead.