#include <stream.h>
#include <dos/dos.h>
#include <exec/types.h>
#include <clib/dos_protos.h>
#include <pragma/dos_lib.h>

#ifndef MakeID
#define MakeID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
#endif

#define FORM	MakeID('F', 'O', 'R', 'M')
#define CAT		MakeID('C', 'A', 'T', ' ')
#define SVX8	MakeID('8', 'S', 'V', 'X')

struct Chunk {
	LONG id;
	LONG size;
};

void main() {
	BPTR outfile = NULL;
	BPTR infile = NULL;
	LONG buffer[8];
	char *names[] = {"explode.8svx", "start.8svx", "shoot.8svx"};
	long length;
	
	outfile = Open("Sounds.8SVX", MODE_NEWFILE);
	
	long count;
	
	int i;
	
	for (i=0;i<3;i++) {
		infile = Open(names[i], MODE_OLDFILE);
		count = Read(infile, buffer, 8);
		length += ((struct Chunk *)buffer)->size;
		Close(infile);
	}
	
	length += (3*8);			// for the three headers
	length += 4;				// for the CAT & 8SVX header
	
	LONG val;
	
	val = CAT;
	count = Write(outfile, &val, 4);
	count = Write(outfile, &length, 4);
	val = SVX8;
	count = Write(outfile, &val, 4);
	
	int j;
	ULONG c;
	
	for (i=0;i<3;i++) {
		infile = Open(names[i], MODE_OLDFILE);
		while((c=FGetC(infile))!=-1)
			FPutC(outfile, c);
		Close(infile);
	}

	Close(outfile);
}
