// Copyright (c) 2004 Alkonost Software.

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>

#include "affxlib.c"

//
// -------------------------------------------------------------------------
//
// Main
//
void main(int ac, char* av[])
{
	DWORD FloppyType;
	int Res, i;
	DWORD ErrNo;
	DWORD DriveByte;
	BOOL dllLoadOk;
	char *Errs;
	char *Cap = "Old capacity:";

	
	printf("Please wait...\r");
	dllLoadOk = LoadDll();

	if (dllLoadOk)	
	{
		DriveByte = 0; //Drive A:
		FloppyType = GetFloppyType(DriveByte, &ErrNo);
		
		switch (FloppyType)
		{
			case 1: printf("%s 360KB.\n", Cap); break;
			case 2: printf("%s 1.2MB.\n", Cap); break;
			case 3: printf("%s 720KB.\n", Cap); break;
			case 4: printf("%s 1.44MB.\n", Cap); break;
			case 5: printf("%s 1.72MB.\n", Cap); break;
			case 6: printf("%s DMF1.\n", Cap); break;
			case 7: printf("%s DMF2.\n", Cap); break;
			default: printf("%s Unknown.\n", Cap);
		}
		
		switch (ErrNo)
		{
			case 0: printf("Disk is empty.\n"); break;
			case 1: printf("Disk is NOT empty.\n"); break; 
			case 2: printf("No disk in the drive OR disk is not formatted.\n"); break; 
			case 3: printf("No disk in the drive.\n"); 
		}

		if (ErrNo != 3) {
    //   FloppyType = (FUnknown,NotSupp,F1200,F720,F1440,NotSupp,FDMF1,FDMF2);
    //                 0        1       2     3    4     5       6     7
			FloppyType = 4; // 1.44MB
			
			Res = DiskOpInit(
				DriveByte,     // 0: Drive A:...
				FloppyType,     // 4: 1.44MB;  6: DMF1;  7: DMF2
				"FFORMX_DEMO", // Disk Volume Label
				FALSE,         // if FALSE: need not verify
				&LibId);
			
			printf("\n== Formatting 1.44MB ==\n");
			if (Res==0)
			{
				Res = FormatCylinder(0); // try to format cylinder 0
				switch (Res)
				{
					case 1: Errs = "The drive is not ready"; break;
					case 2: Errs = "No disk in the drive"; break;
					case 3: Errs = "The disk is write protected"; break;
					case 0:
						for (i = 1; i < 80; i++)
						{
							Res = FormatCylinder(i);
							if (Res != 0) break;
							printf("Cylinder %d\r", i);
						};
						if (Res == 0)
							Errs = "Result: Ok";
						else
							Errs = "Result:  Unknown error";

				}
			}
			
			DiskCompletion(TRUE, LibId);
			
			printf("\n%s.\n\n", Errs);
		}
		
		
		FreeDll();
	}
	
	printf("Press a key to exit...\n\a"); _getch();
}







