/*
 * BOOT                       Author :  Vincent Hayward
 *                                      School of Electrical Engineering
 *                                      Purdue University
 *      Dir     : boot
 *      File    : mkboot.c
 *      Remarks : Take the output of the code of boot.s piped through od
 *                and writes a shell file using 'echo' for booting
 *      Usage   : make install
 */

#include <stdio.h>

main()
{
	FILE *fb = fdopen(creat("boot", 0755), "w");
	unsigned int ad, code, dum;
	int i;

	while (getchar() != '*')
		;
	scanf("%o", &ad);
	ad -= 020;
	fprintf(fb, "echo RS/ 00000000000340\n");
	fprintf(fb, "echo -n 100/\n");
	fprintf(fb, "echo 102\n");
	fprintf(fb, "echo -n 102/\n");
	fprintf(fb, "echo 2\n");
	fprintf(fb, "trap \"stty -nl -raw; exit\" 1 2 3\n");
	fprintf(fb, "stty nl\n");
	fprintf(fb, "echo -n %o/\n", ad);
	for (i = 1; scanf("%o", &code) == 1; ++i) {
		fprintf(fb, "echo %o\n", code);
		if (i % 8 == 0) {
			scanf("%o", &dum);
		}
	}
	fprintf(fb, "stty -nl\n");
	fprintf(fb, "echo\n");
	fprintf(fb, "echo R6/ 0000000000077000\n");
	fprintf(fb, "echo -n 77000G\n");
	fprintf(fb, "stty raw\n");
	fprintf(fb, "cat $1\n");
	fprintf(fb, "stty -raw\n");
}
