/*
** $VER: FSCode.h (22.5.95) by Flavio Stanchina
*/

#ifndef FSCODE_H
#define FSCODE_H

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

/***** Strings *****/
GLOBAL TEXT StartFmt[];
GLOBAL TEXT MultiFmt[];
GLOBAL TEXT   EndFmt[];
GLOBAL TEXT  NameFmt[];

#define START_SKIP 7

/***** Structures *****/
#define FSD_BUFSIZ 16384

struct FSData
{
	/* Command line parameters */
	STRPTR  File;
	STRPTR  To;
	LONG    Encode;
	LONG    Multi;
	LONG  *pLines;

	/* Libraries */
	struct Library    *UtilityBase;
	struct DosLibrary *DOSBase;

	/* Files */
	BPTR StdErr;
	BPTR In, Out;
	LONG close_out;
	TEXT Name[256]; // name of file to (en/de)code

	/* Some data */
	ULONG Size, RealSize;
	ULONG CRC,  RealCRC;

	/* Multi (en/de)code */
	ULONG NumFound; // [decode] number of encoded files found so far
	ULONG PhysPart; // [decode] physical part
	ULONG Part, Parts; // logical part/parts
	ULONG Line, Lines; // [encode] current line and number of lines per part

	/* Buffers */
	UBYTE  Buffer[FSD_BUFSIZ];
	UBYTE *BufPtr; // ptr to current position in output buffer
	ULONG  BufCnt; // bytes available/placed in the buffer

	UBYTE Temp[256]; // small buffer for whatever
	ULONG TempCnt;
};

#define UtilityBase (fsd->UtilityBase)
#define DOSBase     (fsd->DOSBase)

/***** Prototypes *****/
LONG FileSizeFH  (struct FSData *, BPTR);
VOID MyPrintFault(struct FSData *, LONG, STRPTR);
BOOL MyClose     (struct FSData *, BPTR);

LONG GetDec  (STRPTR *);
LONG GetHex  (STRPTR *);
VOID TrimLine(STRPTR *);

LONG Encode(struct FSData *);
LONG Decode(struct FSData *);

BPTR  OpenPart(struct FSData *);
LONG ClosePart(struct FSData *, LONG c);
LONG FlushPart(struct FSData *);

__asm void stuff(void); // required by RawDoFmt() - parameters don't matter

#define VSPrintf(buf, fmt, args) RawDoFmt(fmt, args, stuff, buf);
VOID SPrintf(STRPTR buf, STRPTR fmt, ...);

#endif
