/*
 * BOOT                       Author :  Vincent Hayward
 *                                      School of Electrical Engineering
 *                                      Purdue University
 *      Dir     : boot
 *      File    : mkabo.c
 *      Remarks : Read the stripped a.out file from the lsi11 loader and make
 *                it downloadable, compute word count and checksum
 *      Usage   : cc mkabo.c -o mybindir/mkabo
 */

#include <stdio.h>

unsigned short header[8];

char buffer[28000];

main()
{
	short wc, *p;
	short chks = 0;
	register int bc;

	read(0, header, sizeof(header));
	if(header[0] != 0407 || !header[7]) {
		fprintf(stderr,"mkabo : bad input\n");
		exit(1);
	}
	bc = read(0, buffer, 28000);
	wc = bc / 2;
	write(1, &wc, 2);
	write(1, buffer, bc);
	p = (short *)buffer;
	while(wc--) {
		chks += *p++;
	}
	write(1, &chks, 2);
	fprintf(stderr, "size = %d (oct 0%o), chks 0%o\n", bc, bc, chks & 0xffff);
	exit(0);
}
