#ifndef SPIRIT_H
#define SPIRIT_H
//
// $VER: spirit.h 1.5 (23.7.98)
//
// include file for spirit
//
// Copyright (C) 1998 by Sunbeam/DC
//

#ifndef UTILITY_TAGITEM_H
#include <utility/tagitem.h>
#endif

// KeyBase Structure ********************************************************************

struct KeyBase {
       STRPTR   Name;                      // Name:
       STRPTR   Serial;                    // Serial:
       STRPTR   Street;                    // Street:
       STRPTR   City;                      // ZIP/City:
       STRPTR   Country;                   // Country:
       STRPTR   Computer;                  // Computer:
       STRPTR   eMail;                     // eMail:
       STRPTR   Phone;                     // Phone:
       ULONG    SerialHEX;                 // see below
       ULONG    SerialDEC;                 // see below
       STRPTR   KeyBuffer;                 // pointer to the keyfile buffer
       STRPTR   TempBuffer;                // pointer to temp buffer
       APTR     SaveFile;                  // file save function
       STRPTR   Date;                      // current date in format dd.mm.yy
       STRPTR   Time;                      // current system time in format hh:mm:ss
};

// kb_SerialHEX/DEC:
// Here you can find the converted serial number.
// For example the user have keyboarded "12345":
// kb_Serial is the STRPTR, kb_SerialDEC includes 0x12345
// kb_SerialHEX includes 0x3039
// Since V1.4 I abort the serial converter on an overflow.

// Patch File Structure *****************************************************************

struct pchhd {
       ULONG   ph_ID;                      // patch header ID (PH_ID,PH_IDATT)
       ULONG   ph_FileLen;                 // filelength of the compared file
       ULONG   ph_NumPatches;              // number of stored patches
       ULONG   ph_ChkSum1;                 // original file checksum
       ULONG   ph_ChkSum2;                 // patched file checksum
       // pchdat starts here
};

struct pchdat {
       UBYTE   pd_ID;                      // security ID (PD_ID)
       ULONG   pd_Offset;                  // offset in file
       UBYTE   pd_OrigByte;                // original byte
       UBYTE   pd_PatchByte;               // patched byte
};

#define PH_ID           "SPCH"             // normal patch file
#define PH_IDATT        "SPC2"             // +attached file
#define PD_ID           0x44               // pchdat->pd_ID
#define PD_ENDID        0x55               // pchdat->pd_ID (no more entries)

// file structure:
//  struct pchhd
//  struct pchdat*ph_NumPatches
//  pd_ID=PH_ENDID
//  str 'cracker' until 0
//  str 'group' until 0
//  str 'prg' until 0
//  str 'prg_ver' until 0
//  str 'date' until 0
//-end or if PH_IDATT
//  ulong attach len
//  ulong attach sum
//  str 'path+name' until 0
//  attached file

// SPT_Flags Flags **********************************************************************

#define FLGF_HEXSER     (1L<<0)            // allow in serial hex chars. (0-F)
#define FLGF_RNDFILL    (1L<<1)            // fill keyfile with random bytes
#define FLGF_RNDFILLTMP (1L<<2)            // fill tempbuffer with random bytes
#define FLGF_CHECKEMPTY (1L<<3)            // no empty string gadgets, or spaces
#define FLGF_DYNAMIC    (1L<<4)            // keyfile have a dynamic length
#define FLGF_CRYPTED    (1L<<5)            // do not set this!

// KeyModule Tags ***********************************************************************

#define SPT_Name        (TAG_USER+0)       // name of the program
#define SPT_Version     (TAG_USER+1)       // program version
#define SPT_Cracker     (TAG_USER+2)       // name of the cracker
#define SPT_Group       (TAG_USER+3)       // group of the cracker
#define SPT_Date        (TAG_USER+4)       // keymodule creation date (dd.mm.yy)
#define SPT_KeyLength   (TAG_USER+5)       // length of the keyfile buffer (kb_KeyBuffer)
#define SPT_KeyName     (TAG_USER+6)       // keyfile name only. without the path
#define SPT_KeyPath     (TAG_USER+7)       // the complete path to the keyfile dir
#define SPT_Encrypt     (TAG_USER+8)       // pointer to your encrypt routine
#define SPT_TempBuff    (TAG_USER+9)       // length of the temp buffer (kb_TempBuffer)
#define SPT_Flags       (TAG_USER+10)      // see above
#define SPT_Anno        (TAG_USER+11)      // announcement before key saving or for ABORT
#define SPT_NameLen     (TAG_USER+12)      // length of the Name: string gadget
#define SPT_SerialLen   (TAG_USER+13)      // ^^^
#define SPT_StreetLen   (TAG_USER+14)      // ^^^
#define SPT_CityLen     (TAG_USER+15)      // ^^^
#define SPT_CountryLen  (TAG_USER+16)      // ^^^
#define SPT_ComputerLen (TAG_USER+17)      // ^^^
#define SPT_eMailLen    (TAG_USER+18)      // ^^^
#define SPT_PhoneLen    (TAG_USER+19)      // ^^^
#define SPT_EncryptLen  (TAG_USER+20)      // length of your code (for the keymod crypter)
#define SPT_SpiritVer   (TAG_USER+21)      // set SPIRITVERSION
#define SPT_CPU         (TAG_USER+22)      // set the needed CPU type

#define SPIRITVERSION   0x00010005         // actual spirit version (SPT_SpiritVer)

// SPT_CPU Types ************************************************************************

#define CPU_68000       0                  // not really required
#define CPU_68010       1
#define CPU_68020       2
#define CPU_68030       3
#define CPU_68040       4
#define CPU_68060       8

// SPT_Encrypt Return Codes *************************************************************

#define RETURN_NOERR    0                  // keyfile generated
#define RETURN_ERR     -1                  // keyfile not generated
#define RETURN_ABORT   -2                  // aborted (no fail requester but a SPT_Anno)
#define RETURN_SERIAL  -3                  // special for serial#gen

// Misc *********************************************************************************

extern __asm void spreturn(register __d0 long ret,register __d1 long size);
#define keyargs register __a5 struct KeyBase *KeyBase
extern __asm void encrypt(void);
extern __asm BOOL SaveFile(register __d1 char *nme,register __d2 ULONG len,register __d3 APTR buf);

//***************************************************************************************
#endif //SPIRIT_H
