/* (c) Copyright 1987 Michael Goetz																				*/
/*																				*/
/*				File:		endtxt											*/
/*				Returns:	  	void											*/
/*				Parameters:													*/
/*																				*/
/*																				*/

#include <stdio.h>

#include "advm.h"
#include "units.h"
#include "txtbuf.h"


void endtxt()

{
	static int pad = 0;

	k1[kptr] = k2[kptr] = -1;
	if (fwrite((char *)k1,1,sizeof(k1),textkeyfi) != sizeof(k1) ||
		 fwrite((char *)k2,1,sizeof(k2),textkeyfi) != sizeof(k2) ||
		 fwrite((char *)krec,1,sizeof(krec),textkeyfi) != sizeof(krec) ||
		 fwrite(kbyte,1,sizeof(kbyte),textkeyfi) != sizeof(kbyte) ||
			/* write out 0x0000 to be compatible with CPM 128 byte sectors */
		 fwrite((char *)&pad,2,1,textkeyfi) != 1 ||
		 (bptr && (fwrite(buff,1,sizeof(buff),textfi) != sizeof(buff))) ||
		 fclose(textkeyfi))
		{
		printf("\n\n****Output error while closing textfile.\n\n");
		exit(1);
		}
	}

