#include "exec/types.h"
#include "hardware/dmabits.h"
#include "hardware/custom.h"
#include "hardware/cia.h"
#include "hardware/blit.h"
#include "exec/exec.h"
#include "devices/audio.h"
#include "stdio.h"
                
struct CIA         *cia = 0xbfe001;
/* #define custom (*ccustom) */
/* struct Custom      *ccustom = 0xdff000; */
/* these lines only needed if custom is not declared in hardware/custom.h */

LONG i;
SHORT j, k, n;
LONG s1,s2;
int fr;


short *sndbuffer;

main(argc,argv)
int argc;
char *argv[];
{
 if(argc>1)
  fr = atoi(argv[1]);
 else
  fr = 190;

 MakeSound();
}



MakeSound()
{
LoadSound();
Forbid();
PlaySong();
}  

LoadSound()
{
FILE *fopen(), *fp;
SHORT *ptr, *AllocMem();


sndbuffer = AllocMem(60000L,MEMF_CHIP);
ptr = sndbuffer;

custom . dmacon = 0x0003;
fp = fopen("df1:UB40","r");
if (fp == NULL) return(0);

s1 = 0; s2 = 56724;
for (i=0; i<s1; i++)
	getc(fp);

for (i=s1/2; i<s2/2; i++)
	{
	*ptr++ = getc(fp)*256 + getc(fp);
	}

fclose (fp);
}

PlaySong()
{
custom . aud[0].ac_ptr = (UWORD *)sndbuffer;
custom . aud[0].ac_len = s2/2-s1/2;
custom . aud[0].ac_per = fr;
custom . aud[0].ac_vol = 42;

custom . aud[1].ac_ptr = (UWORD *)sndbuffer;
custom . aud[1].ac_len = s2/2-s1/2;
custom . aud[1].ac_per = fr;
custom . aud[1].ac_vol = 42;

custom . dmacon = 0x8203;
}
