;****************************************************************
;*								*
;*		Disk Parameter Macros for TurboDOS		*
;*								*
;*	The macro						*
;*	DST	@SIZ,@TRKS,@SEC,@BLKS,@NDIR,@RSVD,@FIXD,@EXM0	*
;*		generates a Drive Specification Table.		*
;*	where @SIZ is the sector size in bytes (128, 256, 512	*
;*	or 1024), @TRKS is the number of tracks on the drive,	*
;*	@SEC is the number of sectors per track, @BLKS is the	*
;*	block size in bytes (1024, 2048, 4096, 8192 or 16384),	*
;*	@NDIR is the number of directory entries, @RSVD is the	*
;*	number of reserved (system) tracks on the disk. @FIXD	*
;*	is an optional parameter that specifies the disk to	*
;*	be fixed. @EXM0 is an optional parameter that forces	*
;*	extents to 16K each.					*
;*								*
;*	The macro						*
;*	SKEW	@SECS,@SKF,@FSC					*
;*		generates a skew table for @SEC sectors,	*
;*	starting at sector @FSC with a skew factor of @SKF.	*
;*								*
;****************************************************************
	.XLIST
@LOG2	MACRO	@N
@X	DEFL	@N
@Y	DEFL	0
	REPT	16
	IF	@X EQ 1
	EXITM
	ENDIF
@X	DEFL	@X/2
@Y	DEFL	@Y + 1
	ENDM
	ENDM

DST	MACRO	@SIZ,@TRKS,@SEC,@BLKS,@NDIR,@RSVD,@FIXD,@EXM0
@DTRKS	DEFL	@TRKS-@RSVD	;no. of data tracks
@SPBLK	DEFL	@BLKS/@SIZ	;no. of sectors/block
@NSECT	DEFL	@DTRKS*@SEC	;no. of sectors on drive
@NMBLK	DEFL	@NSECT/@SPBLK	;no. of blocks
@DRBLK	DEFL	(32*@NDIR)/@BLKS ;no. of directory blocks

	@LOG2	@BLKS
@BLMSK	DEFL	@Y-7		;block size

	IFNB	<@FIXD>
@BLMSK	DEFL	@BLMSK OR 80H	;fixed disk
	ENDIF
	IFNB	<@EXM0>
@BLMSK	DEFL	@BLMSK OR 40H	;force exm=0
	ENDIF

	@LOG2	@SIZ
@SECSZ	DEFL	@Y-7		;sector size

	DB	@BLMSK		;block size
	DW	@NMBLK		;no. of blocks
	DB	@DRBLK		;no. of directory blocks
	DB	@SECSZ		;sector size
	DW	@SEC		;no. of sectors/track
	DW	@TRKS		;total no. of tracks
	DW	@RSVD		;no. of reserved tracks

	ENDM

@GCD	MACRO	@M,@N
@GCDM	DEFL	@M
@GCDN	DEFL	@N
@GCDR	DEFL	0
	REPT	65535
@GCDX	DEFL	@GCDM/@GCDN
@GCDR	DEFL	@GCDM - @GCDX*@GCDN
	IF	@GCDR EQ 0
	EXITM
	ENDIF
@GCDM	DEFL	@GCDN
@GCDN	DEFL	@GCDR
	ENDM
	ENDM

SKEW	MACRO	@SECS,@SKF,@FSC
@NXTSC	DEFL	0
@NXTBS	DEFL	0
	@GCD	%@SECS,@SKF
@NELTT	DEFL	@SECS/@GCDN
@NELTS	DEFL	@NELTT
	REPT	@SECS
	DB	@NXTSC + @FSC
@NXTSC	DEFL	@NXTSC + @SKF
	IF	@NXTSC GE @SECS
@NXTSC	DEFL	@NXTSC - @SECS
	ENDIF
@NELTS	DEFL	@NELTS - 1
	IF	@NELTS EQ 0
@NXTBS	DEFL	@NXTBS + 1
@NXTSC	DEFL	@NXTBS
@NELTS	DEFL	@NELTT
	ENDIF
	ENDM
	ENDM
	.LIST
