Missing dependencies added.
[AROS-Contrib.git] / dopus / Program / main7.c
blob84bfec31a3d39a50b09a9cd9964f76e1827e07ba
1 /*
3 Directory Opus 4
4 Original GPL release version 4.12
5 Copyright 1993-2000 Jonathan Potter
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 All users of Directory Opus 4 (including versions distributed
22 under the GPL) are entitled to upgrade to the latest version of
23 Directory Opus version 5 at a reduced price. Please see
24 http://www.gpsoft.com.au for more information.
26 The release of Directory Opus 4 under the GPL in NO WAY affects
27 the existing commercial status of Directory Opus 5.
31 #include "dopus.h"
32 #ifndef __AROS__
33 #include <proto/inovamusic.h>
34 #endif
35 #include <proto/ahi.h>
36 #include <workbench/icon.h>
38 #ifndef SAMPLETYPE_Stereo
39 #define SAMPLETYPE_Stereo SVX_STEREO
40 #endif
42 #define RAWKEY_ESC 0x45
43 #define RAWKEY_Q 0x10
44 #define RAWKEY_X 0x32
46 static struct DOpusRemember *audio_key; /* Memory key for 8SVX player */
48 static struct MsgPort *audio_port[2]; /* 8SVX Sound player Ports */
50 static struct IOAudio *audio_req1[2]; /* Audio IO Request block #1 */
51 static struct IOAudio *audio_req2[2]; /* Audio IO Request block #2 */
53 static UBYTE *audiodata; /* Audio data to play */
54 static ULONG audio_size; /* Size of audio data */
56 struct Library *AHIBase;
57 static struct MsgPort *AHImp;
58 static struct AHIRequest *AHIio;
59 static BYTE AHIDevice = -1;
60 static struct AHIAudioCtrl *actrl;
62 BOOL useAHI = FALSE;
64 int showpic(fullname,np)
65 char *fullname;
66 int np;
68 int res,a;
69 char buf[256];
71 if (checkexec(fullname) && checkisfont(fullname,buf))
72 return((showfont(buf,atoi(BaseName(fullname)),np)));
74 a=strlen(fullname);
75 if (a>5 && Stricmp(&fullname[a-5],".info")==0) {
76 if ((res=readicon(fullname,np))==0) return(1);
77 if (res==-2) {
78 doerror(-1);
79 return(0);
81 if (res==-3) {
82 dostatustext(globstring[STR_NO_CHIP_FOR_ICON]);
83 return(0);
85 return(res);
88 if (!(res=LoadPic(fullname))) doerror(-1);
89 else if (res==IFFERR_NOTILBM) dostatustext(globstring[STR_FILE_NOT_ILBM]);
90 else if (res==IFFERR_BADIFF) dostatustext(globstring[STR_ERROR_IN_IFF]);
91 else if (res==IFFERR_NOMEMORY) dostatustext(globstring[STR_NO_CHIP_FOR_PICTURE]);
92 else if (res==IFFERR_BADMODE) dostatustext(globstring[STR_SCREEN_MODE_UNAVAILABLE]);
93 else if (res==IFFERR_NOSCREEN) dostatustext(globstring[STR_UNABLE_TO_OPEN_WINDOW]);
94 if (res==-1) return(-1);
95 else if (!res || res<-1) return(0);
96 return(1);
99 int checkisfont(pathname,fontname)
100 char *pathname,*fontname;
102 int a;
103 char fontsize[36],fontpath[256],*ptr;
105 strcpy(fontpath,pathname);
106 if ((ptr=BaseName(fontpath))) {
107 strcpy(fontsize,ptr);
108 *(--ptr)=0;
109 if ((ptr=BaseName(fontpath))) {
110 for (a=0;;a++) {
111 if (!(_isdigit(fontsize[a]))) break;
113 if (!fontsize[a]) {
114 strcat(fontpath,".font");
115 if (CheckExist(fontpath,NULL)) {
116 strcpy(fontname,fontpath);
117 return(1);
122 return(0);
125 int readicon(name,np)
126 char *name;
127 int np;
129 struct DiskObject *dobj;
130 struct Gadget *gad;
131 struct Image *icon_image[2];
132 UWORD coltab[256];
133 int fred,ret,width,height,x,y,x1,y1,imagenum,depth;
135 if (!IconBase) return(0);
137 name[(strlen(name)-5)]=0;
138 if (IconBase->lib_Version >= 44) dobj=GetIconTags(name, ICONGETA_Screen, NULL, ICONGETA_GenerateImageMasks, FALSE, TAG_END);
139 else dobj=GetDiskObject(name);
141 if (dobj == NULL) return(-2);
143 gad=&(dobj->do_Gadget);
145 if (IconBase->lib_Version >= 44)
147 icon_image[0]=(struct Image *)1;
148 depth = 8;
150 else
152 icon_image[0]=(struct Image *)gad->GadgetRender;
153 depth=icon_image[0]->Depth;
154 D(bug("icon depth: %ld\n",icon_image[0]->Depth));
155 // if (depth>4) depth=4;
157 if (!icon_image[0] || !(setupfontdisplay(depth,coltab))) {
158 FreeDiskObject(dobj);
159 return(-3);
161 if (IconBase->lib_Version >= 44)
163 // long isPMicon=0;
165 // IconControl(dobj,ICONCTRLA_IsPaletteMapped,&isPMicon,TAG_END);
166 LoadRGB4(&fontscreen->ViewPort,coltab,256);
167 LayoutIconA(dobj,fontscreen,NULL);
168 LoadRGB4(&fontscreen->ViewPort,nullpalette,256);
169 icon_image[0]=(struct Image *)(gad->GadgetRender);
172 if (gad->Flags&GADGHIMAGE) icon_image[1]=(struct Image *)gad->SelectRender;
173 else icon_image[1]=icon_image[0];
175 for (x=0;x<2;x++) icon_image[x]->NextImage=NULL;
177 imagenum=0;
179 ScreenToFront(fontscreen);
180 ActivateWindow(fontwindow);
182 width=fontscreen->Width;
183 height=fontscreen->Height;
185 DrawImage(fontwindow->RPort,icon_image[0],
186 ((width-icon_image[0]->Width)/2),
187 ((height-icon_image[0]->Height)/2));
189 FadeRGB4(fontscreen,coltab,(1<<depth),1,config->fadetime);
190 show_global_icon=dobj;
191 show_global_icon_name=BaseName(name);
193 FOREVER {
194 if ((fred=WaitForMouseClick(2,fontwindow))==-2) {
195 imagenum=1-imagenum;
196 x=(width-icon_image[imagenum]->Width)/2;
197 y=(height-icon_image[imagenum]->Height)/2;
198 x1=x+icon_image[imagenum]->Width;
199 y1=y+icon_image[imagenum]->Height;
200 DrawImage(fontwindow->RPort,icon_image[imagenum],x,y);
201 drawrecaround(fontwindow->RPort,/*0,0,*/x,y,x1,y1,width,height);
203 else {
204 if (fred==0 || fred==-3) ret=TRUE;
205 else ret=-1;
206 break;
209 show_global_icon=NULL;
210 if (fred!=-3) FadeRGB4(fontscreen,coltab,(1<<depth),-1,config->fadetime);
211 //cleanicon: // HUX - this label is unused
212 FreeDiskObject(dobj);
213 cleanup_fontdisplay();
214 return(ret);
217 void drawrecaround(r,/*l,t,*/x,y,x1,y1,width,height)
218 struct RastPort *r;
219 int /*l,t,*/x,y,x1,y1,width,height;
221 UBYTE o;
223 o=GetAPen(r); SetAPen(r,0);
224 if (x>0) RectFill(r,/*l*/0,/*t*/0,/*l+*/x-1,/*t+*/height-1);
225 if (x1 < /*l+*/width) RectFill(r,/*l+*/x1,/*t*/0,/*l+*/width-1,/*t+*/height-1);
226 if (y>0) RectFill(r,/*l*/0,/*t*/0,/*l+*/width-1,/*t+*/y-1);
227 if (y1 < /*t+*/height) RectFill(r,/*l*/0,/*t+*/y1,/*l+*/width-1,/*t+*/height-1);
228 SetAPen(r,o);
231 /******************************************************************************
232 **** OpenAHI ******************************************************************
233 ******************************************************************************/
235 /* Open the device for low-level usage */
237 BOOL OpenAHI(void)
239 if((AHImp = CreateMsgPort())) {
240 if((AHIio = (struct AHIRequest *)CreateIORequest(AHImp,sizeof(struct AHIRequest)))) {
241 AHIio->ahir_Version = 4;
242 if(!(AHIDevice = OpenDevice(AHINAME, AHI_NO_UNIT,(struct IORequest *) AHIio,NULL))) {
243 AHIBase = (struct Library *) AHIio->ahir_Std.io_Device;
244 return TRUE;
248 return FALSE;
252 /******************************************************************************
253 **** CloseAHI *****************************************************************
254 ******************************************************************************/
256 /* Close the device */
258 void CloseAHI(void)
260 AHI_FreeAudio(actrl);
261 actrl = NULL;
262 if(! AHIDevice) CloseDevice((struct IORequest *)AHIio);
263 AHIDevice=-1;
264 DeleteIORequest((struct IORequest *)AHIio);
265 AHIio=NULL;
266 DeleteMsgPort(AHImp);
267 AHImp=NULL;
270 BYTE AHIsignal = -1;
271 static int AHIloops;
273 #ifdef __MORPHOS__
274 ULONG AHISoundFunc(void);
276 struct EmulLibEntry GATE_AHISoundFunc = { TRAP_LIB, 0, (void (*)(void))AHISoundFunc };
278 ULONG AHISoundFunc(void)
280 struct AHIAudioCtrl *actrl = (struct AHIAudioCtrl *)REG_A2;
281 struct AHISoundMessage *smsg = (struct AHISoundMessage *)REG_A1;
282 #else
283 __saveds ULONG AHISoundFunc(
284 register struct AHIAudioCtrl *actrl __asm("a2"),
285 register struct AHISoundMessage *smsg __asm("a1"))
287 #endif
288 if (AHIloops) // Will it work for stereo sounds too?
290 AHI_SetSound(smsg->ahism_Channel,AHI_NOSOUND,0,0,actrl,NULL);
291 Signal(actrl->ahiac_UserData,1L<<AHIsignal);
293 else AHIloops++;
294 //D(bug("AHISoundFunc() called\n"));
295 return 0;
298 static struct Hook AHISoundHook;
300 int doplay8svx(fname,loop)
301 char *fname;
302 int loop;
304 struct VoiceHeader *vhdr=NULL;
305 UBYTE *p8data;
306 ULONG size,class,rsize,chan=0,pan=Unity/2,waitbits,sigs;
307 UWORD code;
308 char *psample,*ry,*compressbuf;
309 ChunkHeader *p8chunk;
310 int a,b,stereo,*vxcheck,finish,playsize;
311 struct IOAudio *audioptr[2];
312 UBYTE *playdata[2];
314 for (a=0;a<2;a++) {
315 audio_port[a]=NULL;
316 audio_req1[a]=audio_req2[a]=NULL;
318 audiodata=NULL;
320 status_flags&=~STATUS_AUDIOLED;
322 if ((a=readfile(fname,(char **)&audiodata,(int *)&audio_size))) {
323 if (a==-1) return(0);
324 return(-2);
326 vxcheck=(int *)audiodata;
327 if (audio_size<12 || vxcheck[0]!=ID_FORM || vxcheck[2]!=ID_8SVX) { // Raw data
328 size=audio_size;
329 psample=p8data=audiodata;
331 else { // 8SVX sample
332 p8data=audiodata+12;
333 size=0;
334 while (p8data<audiodata+vxcheck[1]) {
335 p8chunk=(ChunkHeader *)p8data;
336 p8data+=sizeof(ChunkHeader);
337 switch (p8chunk->ckID) {
338 case ID_VHDR:
339 vhdr=(struct VoiceHeader *)p8data;
340 break;
341 case ID_BODY:
342 psample=p8data;
343 size=p8chunk->ckSize;
344 break;
345 case ID_CHAN:
346 chan = *((ULONG *)p8data);
347 break;
348 case ID_PAN:
349 pan = *((ULONG *)p8data);
350 break;
352 p8data+=p8chunk->ckSize;
353 if (p8chunk->ckSize&1) ++p8data;
357 if (size>vxcheck[1]) {
358 size/=2; chan=0;
361 if (vhdr) {
362 if (vhdr->vh_Compression==CMP_FIBDELTA) {
363 size-=2;
364 if (!(compressbuf=LAllocRemember(&audio_key,size*2,MEMF_ANY))) return(-2);
365 DUnpack(psample+2,size,compressbuf,psample[1]);
366 psample=compressbuf; size*=2;
370 if (chan==SAMPLETYPE_Stereo) {
371 size/=2;
372 stereo=size;
374 else stereo=0;
376 if (useAHI)
378 D(bug("Trying to play through AHI\n"));
379 if (OpenAHI())
381 D(bug("AHI opened\n"));
382 #ifdef __MORPHOS__
383 AHISoundHook.h_Entry = &GATE_AHISoundFunc;
384 #else
385 AHISoundHook.h_Entry = AHISoundFunc;
386 #endif
387 if ((actrl = AHI_AllocAudio(AHIA_AudioID, AHI_DEFAULT_ID,
388 AHIA_MixFreq, AHI_DEFAULT_FREQ,
389 AHIA_Channels, stereo?2:1,
390 AHIA_Sounds, stereo?2:1,
391 loop?TAG_IGNORE:AHIA_SoundFunc, (Tag)&AHISoundHook,
392 AHIA_UserData, (Tag)FindTask(NULL),
393 TAG_DONE)))
395 struct AHISampleInfo sample = { AHIST_M8S, psample, size /*/ AHI_SampleFrameSize(AHIST_M8S)*/ };
396 UWORD snd0,snd1=1;
398 D(bug("AHI_AllocAudio() succeeded\n"));
399 snd0 = AHI_LoadSound(0, AHIST_SAMPLE, &sample, actrl);
400 if (stereo)
402 sample.ahisi_Address = psample+stereo;
403 snd1 = AHI_LoadSound(1, AHIST_SAMPLE, &sample, actrl);
405 D(bug("LoadSound(0)=%ld, LoadSound(1)=%ld\n",snd0,snd1));
406 if ((snd0 != AHI_NOSOUND) && (snd1 != AHI_NOSOUND))
408 if ((AHIsignal=AllocSignal(-1))!=-1)
410 struct TagItem ahitags2[] =
412 { AHIP_BeginChannel, 1 },
413 { AHIP_Freq , vhdr?vhdr->vh_SamplesPerSec:10000 },
414 { AHIP_Vol , vhdr?vhdr->vh_Volume:Unity },
415 { AHIP_Pan , 0L },
416 { AHIP_Sound , 1 },
417 { AHIP_EndChannel , NULL },
418 { TAG_END }
421 AHI_ControlAudio(actrl, AHIC_Play, TRUE, TAG_END);
423 AHI_Play(actrl,
424 AHIP_BeginChannel, 0,
425 AHIP_Freq , vhdr?vhdr->vh_SamplesPerSec:10000,
426 AHIP_Vol , vhdr?vhdr->vh_Volume:Unity,
427 AHIP_Pan , stereo?Unity:pan,
428 AHIP_Sound , 0,
429 AHIP_EndChannel , NULL,
430 stereo?TAG_MORE:TAG_END, (Tag)ahitags2);
431 D(bug("Playing through AHI\n"));
433 else CloseAHI();
435 else CloseAHI();
437 else CloseAHI();
439 else CloseAHI();
441 if (actrl == NULL)
443 static UBYTE audiochannels[2][4]={{8+1,1,8,4},{4+2,2,4,8}};
445 D(bug("Trying to play through audio.device\n"));
446 for (a=0;a<2;a++) {
447 if (!(audio_req1[a]=LAllocRemember(&audio_key,sizeof(struct IOAudio),MEMF_CLEAR)) ||
448 !(audio_req2[a]=LAllocRemember(&audio_key,sizeof(struct IOAudio),MEMF_CLEAR)) ||
449 !(audio_port[a]=LCreatePort(NULL,0))) return(-2);
452 for (a=0;a<2;a++) {
453 audio_req1[a]->ioa_Request.io_Message.mn_ReplyPort=audio_port[a];
454 audio_req1[a]->ioa_Request.io_Message.mn_Node.ln_Pri=75;
455 audio_req1[a]->ioa_Data=audiochannels[a];
456 audio_req1[a]->ioa_Length=sizeof(audiochannels[a]);
457 if (OpenDevice("audio.device",0,(struct IORequest *)audio_req1[a],0)) return(-6);
460 playsize=(size<25600)?size:25600;
461 for (a=0;a<2;a++) {
462 if (!(playdata[a]=LAllocRemember(&audio_key,playsize,MEMF_CHIP)))
463 return(-2);
466 for (a=0;a<2;a++) {
467 audio_req1[a]->ioa_Request.io_Command=CMD_WRITE;
468 audio_req1[a]->ioa_Request.io_Flags=ADIOF_PERVOL;
469 audio_req1[a]->ioa_Volume=64*(a?Unity-pan:pan)/Unity;
470 audio_req1[a]->ioa_Period=data_colorclock/(vhdr?vhdr->vh_SamplesPerSec:10000);
471 audio_req1[a]->ioa_Cycles=1;
472 CopyMem((char *)audio_req1[a],(char *)audio_req2[a],sizeof(struct IOAudio));
473 audio_req1[a]->ioa_Data=(UBYTE *)playdata[a];
474 audio_req2[a]->ioa_Data=(UBYTE *)playdata[a]+playsize/2/*12800*/;
475 audioptr[a]=audio_req2[a];
479 if (config->viewbits&VIEWBITS_FILTEROFF) {
480 if (filteroff()) status_flags|=STATUS_AUDIOLED;
481 else status_flags&=~STATUS_AUDIOLED;
484 waitbits = 1<<Window->UserPort->mp_SigBit;
485 if (actrl == NULL) waitbits |= 1<<audio_port[0]->mp_SigBit | 1<<audio_port[1]->mp_SigBit;
486 else if (!loop) waitbits |= 1<<AHIsignal;
488 if (size<=25600) {
489 for (a=0;a<2;a++) CopyMem(psample+(a*stereo),(char *)playdata[a],playsize);
490 FOREVER {
491 for (b=0;b<2;b++) {
492 audio_req1[b]->ioa_Length=size;
493 BeginIO((struct IORequest *)audio_req1[b]);
495 a=0;
496 FOREVER {
497 Wait(waitbits);
498 while (getintuimsg()) {
499 class=IMsg->Class; code=IMsg->Code;
500 ReplyMsg((struct Message *)IMsg);
501 if (class==IDCMP_MOUSEBUTTONS) {
502 if (code==SELECTDOWN) return(1);
503 else if (code==MENUDOWN) return(-1);
505 else if (class==IDCMP_RAWKEY) {
506 if (code==RAWKEY_ESC) return(-1);
507 else if (code==RAWKEY_Q || code==RAWKEY_X) return(1);
510 for (b=0;b<2;b++) if (GetMsg(audio_port[b])) ++a;
511 if (a>=2) break;
513 if (!loop) return(1);
516 else
519 ry=psample;
520 rsize=size;
521 finish=0;
522 FOREVER {
523 if (actrl == NULL) {
524 size=rsize;
525 psample=ry;
526 for (a=0;a<2;a++) {
527 CopyMem(psample+(a*stereo),(char *)playdata[a],playsize);
528 // CopyMem((char *)audio_req1[a],(char *)audio_req2[a],sizeof(struct IOAudio));
529 // audio_req1[a]->ioa_Data=(UBYTE *)playdata[a];
530 // audio_req2[a]->ioa_Data=(UBYTE *)playdata[a]+12800;
531 audio_req1[a]->ioa_Length=audio_req2[a]->ioa_Length=playsize/2/*12800*/;
532 audioptr[a]=audio_req2[a];
534 psample+=playsize;
535 size-=playsize/*25600*/;
536 for (a=0;a<2;a++) BeginIO((struct IORequest *)audio_req1[a]);
537 for (a=0;a<2;a++) BeginIO((struct IORequest *)audio_req2[a]);
538 a=0;
540 FOREVER {
541 sigs = Wait(waitbits);
542 while (getintuimsg()) {
543 class=IMsg->Class; code=IMsg->Code;
544 ReplyMsg((struct Message *)IMsg);
545 if (class==IDCMP_MOUSEBUTTONS) {
546 if (code==SELECTDOWN) return(1);
547 else if (code==MENUDOWN) return(-1);
549 else if (class==IDCMP_RAWKEY) {
550 if (code==RAWKEY_ESC) return(-1);
551 else if (code==RAWKEY_Q || code==RAWKEY_X) return(1);
554 if (actrl == NULL) {
555 for (b=0;b<2;b++) {
556 if (GetMsg(audio_port[b]) && !(a&(1<<b))) {
557 if (size>0) {
558 if (audioptr[b]==audio_req1[b]) audioptr[b]=audio_req2[b];
559 else audioptr[b]=audio_req1[b];
560 audioptr[b]->ioa_Length=(size<(playsize/2/*12800*/)?size:(playsize/2)/*12800*/);
561 CopyMem(psample+(b*stereo),(char *)audioptr[b]->ioa_Data,audioptr[b]->ioa_Length);
563 a|=1<<b;
566 if (a==3) {
567 if (size<=0) {
568 if (finish) {
569 finish=0;
570 break;
572 finish=1;
574 else {
575 size-=audioptr[0]->ioa_Length;
576 psample+=playsize/2/*12800*/;
577 for (b=0;b<2;b++) BeginIO((struct IORequest *)audioptr[b]);
579 a=0;
582 else if (sigs & (1<<AHIsignal))
584 //D(bug("AHIsignal received\n"));
585 break;
588 if (!loop) return(1);
593 void kill8svx()
595 int a;
597 if (actrl)
599 AHI_ControlAudio(actrl, AHIC_Play, FALSE, TAG_DONE);
600 FreeSignal(AHIsignal);
601 CloseAHI();
603 else
605 for (a=0;a<2;a++) {
606 if (audio_req2[a] && audio_req2[a]->ioa_Request.io_Device) {
607 audio_req2[a]->ioa_Request.io_Command=CMD_FLUSH;
608 DoIO((struct IORequest *)audio_req2[a]);
610 if (audio_req1[a] && audio_req1[a]->ioa_Request.io_Device) {
611 audio_req1[a]->ioa_Request.io_Command=CMD_FLUSH;
612 DoIO((struct IORequest *)audio_req1[a]);
613 CloseDevice((struct IORequest *)audio_req1[a]);
615 audio_req1[a]=NULL;
616 audio_req2[a]=NULL;
618 for (a=0;a<2;a++) {
619 if (audio_port[a]) {
620 while (GetMsg(audio_port[a]));
621 LDeletePort(audio_port[a]);
622 audio_port[a]=NULL;
626 if (audiodata && audio_size) FreeVec(audiodata);
627 LFreeRemember(&audio_key);
628 audiodata=NULL;
629 if (status_flags&STATUS_AUDIOLED) {
630 filteron();
631 status_flags&=~STATUS_AUDIOLED;
635 void handle8svxerror(res)
636 int res;
638 switch (res) {
639 case 0: doerror(-1); break;
640 case -2: doerror(ERROR_NO_FREE_STORE); break;
641 case -3:
642 case -4: dostatustext(globstring[STR_ERROR_IN_IFF]); break;
643 case -6: dostatustext(globstring[STR_CANT_ALLOCATE_AUDIO]); break;
647 void dosound(type)
648 int type;
650 if (type) {
651 struct IOAudio audio;
652 static UBYTE achannels[8]={1+2,1+4,2+8,4+8,1,2,4,8};
653 int a;
655 D(bug("beepwave at %lx\n",beepwave));
656 if (useAHI)
658 D(bug("Trying to play through AHI\n"));
659 if (OpenAHI())
661 D(bug("AHI opened\n"));
662 if ((actrl = AHI_AllocAudio(AHIA_AudioID, AHI_DEFAULT_ID,
663 AHIA_MixFreq, AHI_DEFAULT_FREQ,
664 AHIA_Channels, 1,
665 AHIA_Sounds, 1,
666 TAG_DONE)))
668 struct AHISampleInfo sample = { AHIST_M8S, beepwave, 16 };
670 D(bug("AHI_AllocAudio() succeeded\n"));
671 if (AHI_LoadSound(0, AHIST_SAMPLE, &sample, actrl) != AHI_NOSOUND)
673 D(bug("Playing through AHI\n"));
674 AHI_ControlAudio(actrl, AHIC_Play, TRUE, TAG_END);
676 for (a=0;a<11;a++)
678 AHI_Play(actrl,
679 AHIP_BeginChannel, 0,
680 AHIP_Freq , (a%2)?6000:9000,
681 AHIP_Vol , 0x10000L,
682 AHIP_Pan , 0x8000L,
683 AHIP_Sound , 0,
684 AHIP_EndChannel , NULL,
685 TAG_END);
686 Delay(6);
689 AHI_ControlAudio(actrl, AHIC_Play, FALSE, TAG_DONE);
691 CloseAHI();
693 return;
695 else CloseAHI();
697 else CloseAHI();
699 else CloseAHI();
701 D(bug("Trying to play through audio.device\n"));
702 audio.ioa_Request.io_Message.mn_ReplyPort=general_port;
703 audio.ioa_Request.io_Message.mn_Node.ln_Pri=90;
704 audio.ioa_Data=achannels;
705 audio.ioa_Length=sizeof(achannels);
706 if (OpenDevice("audio.device",0,(struct IORequest *)&audio,0)==0) {
707 audio.ioa_Request.io_Command=CMD_WRITE;
708 audio.ioa_Request.io_Flags=ADIOF_PERVOL;
709 audio.ioa_Volume=64;
710 audio.ioa_Data=(UBYTE *)beepwave;
711 audio.ioa_Length=16;
712 audio.ioa_Cycles=60;
714 for (a=0;a<11;a++) {
715 audio.ioa_Period=(a%2)?600:400;
716 BeginIO((struct IORequest *)&audio);
717 WaitIO((struct IORequest *)&audio);
720 CloseDevice((struct IORequest *)&audio);
722 else dostatustext(globstring[STR_CANT_ALLOCATE_AUDIO]);
724 else DisplayBeep(NULL);
727 int playmod(name)
728 char *name;
730 #ifndef __AROS__
731 int a;
733 if ((a=PlayModule(name,1))) {
734 switch (a) {
735 case ML_NOMEM: doerror(ERROR_NO_FREE_STORE); break;
736 case ML_BADMOD:
737 dostatustext(globstring[STR_NOT_ST_MOD]);
738 break;
739 case ML_NOMOD: doerror(ERROR_OBJECT_NOT_FOUND); break;
741 default:
742 doerror(0);
743 break;
746 FlushModule();
747 return(0);
749 #endif
750 return(1);
753 int check_is_module(name)
754 char *name;
756 #ifndef __AROS__
757 int a;
759 if (MUSICBase) {
760 a=IsModule(name);
761 if (a>0 && a<100) return(1);
763 #endif
764 return(0);
767 static char codetodelta[16]={-34,-21,-13,-8,-5,-3,-2,-1,0,1,2,3,5,8,13,21};
769 char DUnpack(source,n,dest,x)
770 char *source;
771 int n;
772 char *dest,x;
774 unsigned char d;
775 int i,lim;
777 lim=n<<1;
778 for (i=0;i<lim;++i) {
779 d=source[i>>1];
780 if (i&1) d&=0xf;
781 else d>>=4;
782 x+=codetodelta[d];
783 dest[i]=x;
785 return(x);
788 int EnvoyPacket(device,action,action2,data,buffer)
789 char *device;
790 ULONG action,action2;
791 UWORD data;
792 APTR buffer;
794 struct MsgPort *handler;
795 ULONG args[2];
797 if (!(handler=(struct MsgPort *)DeviceProc(device))) return(-1);
799 args[0]=data;
800 args[1]=(ULONG)buffer;
801 if (!(SendPacket(handler,action,args,2))) {
802 if (action2) return(!(SendPacket(handler,action2,args,2)));
803 return(1);
805 return(0);
808 int filteroff(void) //_filteroff: ;int
810 char *filter_register = (char *)0xBFE001L;
812 if( (*filter_register) & 2 ) // btst.b #1,$bfe001
813 // bne alreadyon
814 return(0); //alreadyon:
815 // moveq.l #0,d0
816 // rts
817 (*filter_register) |= 2; // bset.b #1,$bfe001
818 return(1); // moveq.l #1,d0
819 // rts
822 void filteron(void) //_filteron: ;void
824 char *filter_register = (char *)0xBFE001L;
826 (*filter_register) &= (~2); // bclr.b #1,$bfe001
827 // rts