#include <stdio.h>
#include <fcntl.h>

main()
{
	unsigned char	x [ 16384 ];
	FILE				*fd;

	printf("Patching your ROM image (OS1.2p1.rom) into one that will allow xdfs support...\n");

	if (NULL == (fd = fopen ( "OS1.2p1.rom", "r"))) {
		printf("Um, couldn't find a file called \"OS1.2p1.rom\", sorry\n");
		return 0;
	}
	fread (x, 1, 16384, fd);

	fclose(fd);

	if (NULL == (fd = fopen ( "OS1.2p1.rom", "w"))) {
		printf("Um, couldn't create output file \"OS1.2p1.rom\", sorry\n");
		return 0;
	}

	/*
	 * The OSFILE trap
	 */

	x [ 0x327d ] = 0x22;

	/*
	 * The OSFSC trap
	 */

	x [ 0x31b1 ] = 0x02;

	fseek ( fd, 0, SEEK_SET );
	fwrite (x, 1, 16384, fd);
	fclose ( fd );

	printf("Patch applied successfully. Bye.\n");
}
