/*
 * $Header: DH0:src/omti/dist/src/RCS/OmtiInfo.c,v 1.1 92/11/25 02:06:42 Barnard Exp $
 *
 */

/*
 * This program shows some data about the connected drives. This data
 * is derived from Block 0 of the drive.
 *
 *
 * Sorry, I just inserted this comment-lines, the rest is commented in
 * german.
 *
 * This program was written under AmigaOS 1.3. I don't know, whether it will
 * run under AmigaOS 2.04 and above.
 *
 * The TAB-Size use is 4.
 */

#include <exec/types.h>
#include <exec/io.h>

#include "include/omti.h"
#include "include/omtistruct.h"
#include "include/parablock.h"

int	OmtiStep[8]	=
{
		3000,	  10,	  25,	  50,
		 200,	  70,	3000,	3000
};


main(argc,argv)
STRPTR	argv[];
COUNT	argc;
{
SHORT				 OmtiUnit;
struct	MsgPort		*DI_Port;
struct	IOStdReq	*DI_IoReq;
struct	ParaBlock	*ParaStruct;
UBYTE				 ParaBlock[PARABLOCKSIZE];
BYTE				 DI_Error;
ULONG				 Capacity;

	if(argc == 0)
		exit(20);				/* Sorry! No WorkBench! */
	if((argc != 2) || ((argc == 2) && ((*argv[1] == '?') || ((*argv[1] & 0xfe) != '0'))))
	{
		printf("\n%s {0|1} for Unit 0/1\n",argv[0]);
		exit(10);
	}
/* Device oeffnen */

	if(NULL == (DI_Port = (struct MsgPort *)CreatePort("OmtiInfo-Port",NULL)))
	{
		printf("Kein Message-Port!\n");
		exit(20);
	}
	if(NULL == (DI_IoReq = (struct IOStdReq *)CreateExtIO(DI_Port,sizeof(struct IOStdReq))))
	{
		DeletePort(DI_Port);
		printf("Kein IORequest!\n");
		exit(20);
	}
	OmtiUnit	 = *argv[1] - '0';
	if(OpenDevice(OD_NAME,OmtiUnit,DI_IoReq,NULL))
	{
		DeleteExtIO(DI_IoReq);
		DeletePort(DI_Port);
		exit(20);
	}

	DI_IoReq->io_Command	 = CMD_READ;
	DI_IoReq->io_Length		 = PARABLOCKSIZE;
	DI_IoReq->io_Offset		 = 0;			/* Parameterblock beginnt bei 0 */
	DI_IoReq->io_Data		 = ParaBlock;
	if(DI_Error = DoIO(DI_IoReq))
		printf("IO-Fehler: %d\n",DI_Error);
	else
	{
		ParaStruct = (struct ParaBlock *)ParaBlock;
		if(strncmp(&(ParaStruct->pb_paraid),PARAID,strlen(PARAID)))
			printf("\nDrive %d hat keinen Parameter-Block\n",OmtiUnit);
		else
		{
			printf("\nParameter fuer Drive %d:\n",OmtiUnit);
			printf("----------------------\n\n");
			printf("Device-Parameter:\n");
			printf("Hoechster Zylinder:                   %d\n",ParaStruct->pb_hicyl-1);
			printf("Hoechster schreib-/lesbarer Zylinder: %d\n",ParaStruct->pb_wrcyl-1);

			if(ParaStruct->pb_wrpre != 2047)
				printf("Write-Precompensation Zylinder:       %d\n",ParaStruct->pb_wrpre);
			if(ParaStruct->pb_wrcur != 2047)
				printf("Reduce Write Current Zylinder:        %d\n",ParaStruct->pb_wrcur);

			printf("Park-Zylinder:                        %d\n",ParaStruct->pb_parkcyl);
			printf("Koepfe:                               %d\n",ParaStruct->pb_heads);
			printf("Steprate im uSec:                     %d\n",OmtiStep[ParaStruct->pb_step]);

			printf("\nInit-Parameter:\n");
			printf("AutoPark aktiv:                       %s\n",(ParaStruct->pb_autopark ? "JA" : "NEIN"));
			printf("Write-Protect:                        %s\n",(ParaStruct->pb_wrprot   ? "JA" : "NEIN"));

			printf("\nBoot-Parameter:\n");
			printf("Boot-LUN:                             %d\n",ParaStruct->pb_bootlun & 1);
			printf("Startkopf fuer Bootspur:              %d\n",ParaStruct->pb_boothead);
			printf("Startsektor fuer Bootspur:            %d\n",ParaStruct->pb_bootsector);
			printf("Startspur fuer Bootspur:              %d\n",ParaStruct->pb_boottrack);
			printf("Anzahl der geladenen Bloecke:         %d\n",ParaStruct->pb_bootblocks);

			printf("\nFormat-Parameter:\n");
			printf("Verwendeter Interleave:               %d\n",ParaStruct->pb_interleave+1);
			printf("Sektoren pro Spur:                    %d\n",ParaStruct->pb_sectors);

			printf("\nSonstiges:\n");
			Capacity = ParaStruct->pb_sectors * PARABLOCKSIZE * ParaStruct->pb_heads * ParaStruct->pb_hicyl;
			printf("Bruttokapazitaet des Drive: %2.2f MByte = %d KByte = %ld Byte\n",(double)Capacity / (double)(1<<20),(Capacity >> 10),Capacity);
			Capacity = ParaStruct->pb_sectors * PARABLOCKSIZE * ParaStruct->pb_heads * (ParaStruct->pb_wrcyl-1); /* -1 wg. Boottrack */
			printf("Nettokapazitaet des Drive:  %2.2f MByte = %d KByte = %ld Byte\n",(double)Capacity / (double)(1<<20),(Capacity >> 10),Capacity);

			DI_IoReq->io_Command	 = OD_MOTOR;
			DI_IoReq->io_Length		 = 0;
			DoIO(DI_IoReq);			/* Motor wieder ausschalten */

		}
	}
	CloseDevice(DI_IoReq);
	DeleteExtIO(DI_IoReq);
	DeletePort(DI_Port);
	exit(0);
}


