/*
//
// Copyright (C) 2006-2026 Jean-François DEL NERO
//
// This file is part of the HxCFloppyEmulator library
//
// HxCFloppyEmulator may be used and distributed without restriction provided
// that this copyright statement is not removed from the file and that any
// derivative work contains the original copyright notice and the associated
// disclaimer.
//
// HxCFloppyEmulator is free software; you can redistribute it
// and/or modify  it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// HxCFloppyEmulator is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//   See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with HxCFloppyEmulator; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
//
*/
///////////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------//
//-----------H----H--X----X-----CCCCC----22222----0000-----0000------11----------//
//----------H----H----X-X-----C--------------2---0----0---0----0--1--1-----------//
//---------HHHHHH-----X------C----------22222---0----0---0----0-----1------------//
//--------H----H----X--X----C----------2-------0----0---0----0-----1-------------//
//-------H----H---X-----X---CCCCC-----222222----0000-----0000----1111------------//
//-------------------------------------------------------------------------------//
//----------------------------------------------------- http://hxc2001.free.fr --//
///////////////////////////////////////////////////////////////////////////////////
// File : h17_format.c
// Contains: Heathkit H17 floppy image format
//
// Written by: Jean-François DEL NERO
//
// Change History (most recent first):
///////////////////////////////////////////////////////////////////////////////////


//The file starts with a 4 byte file tag “H17D”, a 3 byte version number, and a 0xFF byte. Starting at offset 8,
//the remainder of the file consists of blocks of data.

#pragma pack(1)
typedef struct h17_header_
{
	uint8_t  file_tag[4];     // 0x0000 "H17D"
	uint8_t  version[3];      // 0x0004 Version major/minor/point - Ascii : 3.2.1 -> "321"
	uint8_t  check;           // 0x0007 Check Byte (0xFF)
}h17_header;

typedef struct h17_block_
{
	uint32_t id;
	uint32_t lenght;
	uint8_t  data[];
}h17_block;

typedef struct h17_DskF_
{
	uint8_t Sides;
	uint8_t Tracks;
	uint8_t ReadOnly;
}h17_DskF;

typedef struct h17_Parm_
{
	// 0 Status of source disk unknown.
	// 1 Image was created from an original distribution disk.
	// 2 Image was not an original distribution disk.
	// 3 Image was created from a disk, which appears to be a copy of a distribution disk.
	// 4-127  Reserved.
	uint8_t Distribution_Disk;

	// 0 Generated by an H8D to H17Disk conversion utility
	// 1 Created by an emulator
	// 2 Captured on an H8/H89
	// 3 Captured with an FC5025
	// 4 Captured by AppleSauce
	// 5-127 Reserved.
	uint8_t Source_of_Header_Data;
}h17_Parm;

typedef struct h17_sect_metadata_
{
	uint32_t Offset;

	// Sector_Status bits :
	// 0 Missing Header Sync
	// 1 Wrong Track
	// 2 Invalid Sector
	// 3 Invalid Header Checksum
	// 4 Missing Data Sync
	// 5 Invalid Data Checksum
	// 6 Sector was unreadable
	// 7 Reserved
	uint8_t  Sector_Status;

	uint8_t  HSync;
	uint8_t  Volume;
	uint8_t  Track;
	uint8_t  Sector;
	uint8_t  Header_Checksum;
	uint8_t  DSync;
	uint8_t  Data_Checksum;
	uint16_t Valid_Bytes;
	uint16_t Reserved;
}h17_sect_metadata;

#pragma pack()

#define BLKID_DskF 0x466B7344
#define BLKID_Parm 0x6D726150
#define BLKID_Date 0x65746144
#define BLKID_Imgr 0x72676D49
#define BLKID_Prog 0x676F7250
#define BLKID_Padd 0x64646150
#define BLKID_H8DB 0x42443848
#define BLKID_Labl 0x6C62614C
#define BLKID_Comm 0x6D6D6F43
#define BLKID_SecM 0x4D636553
