NEW
  AUTO 3,1
*--------------------------------------
X.TRKFMT.VolNum		.EQ X.TRKFMT.Z
X.TRKFMT.TrkNum		.EQ X.TRKFMT.Z+1
X.TRKFMT.SectNum	.EQ X.TRKFMT.Z+2
X.TRKFMT.CheckSum	.EQ X.TRKFMT.Z+3
*--------------------------------------
X.TRKFMT		lda #$ff

				sta IO.D2.WriteMode,x	goto write mode
				ora IO.D2.WShift,x		(4)

				jsr X.TRKFMT.W14		(14)

				lda #0					(2)
				sta X.TRKFMT.SectNum	(3)

				ldy #0					(2) 256 SyncBytes

				jsr X.TRKFMT.SyncBytes	(15..15)

				nop						(2)
				nop						(2)
				nop						(2)
				nop						(2)

.1				jsr X.TRKFMT.AddrField	(17..15)

				ldy #6					(2)

				jsr X.TRKFMT.SyncBytes	(15..15)

				jsr X.TRKFMT.W14		(14)

				ldy #2					(2)

.2				lda X.TRKFMT.DATA,y		(4)
				sta IO.D2.WLoad,x		(5)
				ora IO.D2.WShift,x		(4)
				dey						(2)
				bmi .22					(3-)

				jsr X.TRKFMT.W12		(12)
				bra .2					(3)

.22				jsr X.TRKFMT.W14		(14)

				ldy #86					(2) 256+86...
				lda #$96				(2)

				sta IO.D2.WLoad,x		(5) ...+1
				ora IO.D2.WShift,x		(4)

				nop						(2)
				bra .3					(3)

.3				jsr X.TRKFMT.W14		(14)

				nop						(2)

				lda #$96				(2)
				sta IO.D2.WLoad,x		(5)
				ora IO.D2.WShift,x		(4)

				dey						(2)
				bne .3					(3)-

				bra .5					(3)

.4				nop						(2)

.5				jsr X.TRKFMT.W14		(14)

				lda #$96				(2)
				sta IO.D2.WLoad,x		(5)
				ora IO.D2.WShift,x		(4)

				dey						(2)
				bne .4					(3)-

				inc X.TRKFMT.SectNum	(5)

				jsr X.TRKFMT.EndMark	(19..15)

				ldy #16					(2)

				jsr X.TRKFMT.SyncBytes	(15..15)

				lda X.TRKFMT.SectNum	(3)
				cmp #16					(2)
				bne .1					(3-)

				lda IO.D2.ReadMode,x	(4) out of write mode
				lda IO.D2.WShift,x		(4) to read mode.

				rts
*--------------------------------------
X.TRKFMT.SyncBytes	
				nop						(2)

				lda #$ff				(2)
			
.1				sta IO.D2.WLoad,x		(5)
				ora IO.D2.WShift,x		(4)
				dey						(2)
				beq .8					(3-)

				jsr X.TRKFMT.W12		(12)
				jsr X.TRKFMT.W12		(12)

				bra .1					(3)

.8				rts						(6)
*--------------------------------------
X.TRKFMT.AddrField
				ldy #2					(2)

.1				lda X.TRKFMT.ADDR,y		(4)
				sta IO.D2.WLoad,x		(5)
				ora IO.D2.WShift,x		(4)
				dey						(2)
				bmi .2					(3-)

				lda X.TRKFMT.VolNum		(3)
				eor X.TRKFMT.TrkNum		(3)
				eor X.TRKFMT.SectNum	(3)
				sta X.TRKFMT.Checksum	(3)
				bra .1					(3)

.2				lda X.TRKFMT.VolNum		(3)
				lda X.TRKFMT.VolNum		(3)
				jsr X.TRKFMT.W4x4		(17..12)

				lda X.TRKFMT.TrkNum		(3)
				jsr X.TRKFMT.W4x4		(17..12)

				lda X.TRKFMT.SectNum	(3)
				jsr X.TRKFMT.W4x4		(17..12)

				lda X.TRKFMT.Checksum	(3)
				jsr X.TRKFMT.W4x4		(17..12)

				pha						(3)
				pla						(4)
*--------------------------------------
X.TRKFMT.EndMark
				ldy #2					(2)

				nop						(2)

.1				lda X.TRKFMT.END,y		(4)
				sta IO.D2.WLoad,x		(5)
				ora IO.D2.WShift,x		(4)
				dey						(2)
				bmi .8					(3-)

				jsr X.TRKFMT.W12		(12)
				bra .1					(3)

.8				rts						(6)
*--------------------------------------
X.TRKFMT.W4x4	tay						(2)
				lsr						(2)
				ora #$AA				(2)
				sta IO.D2.WLoad,x		(5)
				ora IO.D2.WShift,x		(4)

				jsr X.TRKFMT.W12		(12)

				pha						(3)
				pla						(4)

				tya						(2)
				ora #$AA				(2)

				sta IO.D2.WLoad,x		(5)
				ora IO.D2.WShift,x		(4)

X.TRKFMT.W14	nop						(2)

X.TRKFMT.W12	rts						(6)
*--------------------------------------
				.LIST ON
X.TRKFMT.ADDR	.HS 96AAD5
X.TRKFMT.DATA	.HS ADAAD5
X.TRKFMT.END	.HS EBAADE
				.LIST OFF
*--------------------------------------
MAN
SAVE usr/src/shared/x.trkfmt.s
LOAD usr/src/basic.fx/basic.s
ASM
