2 #include <aros/debug.h>
5 #include <devices/ahi.h>
6 #include <libraries/ahi_sub.h>
8 #include "DriverData.h"
11 #define dd ((struct AC97Data *) AudioCtrl->ahiac_DriverData)
13 /******************************************************************************
14 ** The slave process **********************************************************
15 ******************************************************************************/
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
))
39 struct ExecBase
* SysBase
= *((struct ExecBase
**) 4);
45 struct BufferDescriptor
{
51 Slave( struct ExecBase
* SysBase
)
53 struct AHIAudioCtrlDrv
* AudioCtrl
;
54 struct DriverBase
* AHIsubBase
;
55 struct ac97Base
* ac97Base
;
56 BOOL running
, firstTime
= TRUE
;
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
);
83 SetTaskPri(FindTask(NULL
), 127);
85 int tail
= (inb(ac97Base
->dmabase
+ PO_CIV
) + 1) & 0x1f;
89 signals
= SetSignal(0L,0L);
92 if( signals
& ( SIGBREAKF_CTRL_C
| (1L << dd
->slavesignal
) ) )
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 */
106 buff
= (IPTR
)dd
->mixbuffer
;
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 */
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
);
132 outb(0x11, ac97Base
->dmabase
+ PO_CR
);
133 /* Enable busmaster + interrupt on completion */
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
);
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);
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;
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.