CLRTRK

.Page
;++
;	Sync20 will clear a track partially bny writing 20 usec 'FF's to
;	the disk.  Sync20 will use theh values in the "y" reg as the number
;	of sets of sync nibbles to write to the disk.
;
;	INPUT
;		Y = number to write
;		A = Addr/Data Mark flag -->0 0 == Data & 1 == Addr
;
;	OUTPUT
;		X = Destroyed
;		Y = 'FF'
;		A = Unknown
;	  "Counter" = 'FF'
;--

BsTbl	.Equ *				; 5 20 usec bytes coded in the following 6 bytes
	.Byte	0FF, 0FC, 0F3, 0CF, 03F, 0FF
Sync20	.Equ *				; Entry point
	Sty	Counter
	Sta	Temp1
	Lda	#0FF			;
	Sta	Q7H			;		Change from SENSE to WRITE LOAD
$05	Ldy	#05			; 2		Transfer 6 bytes, zero based
$07	Lda	BsTbl,y			; 4
$10	Ldx	Q6L			; 4		Sense line encoded in Bit &
	Bpl	$10			; 2,3		Wait for Bit 7 to become a '1'
	Sta	Q6H			; 4

	Dey				; 2
	Bpl	$07			; 2,3
	Dec	Counter			; 5
	Bne	$05			; 2,3

$20	Ldx	Q6L			; 4
	Bpl	$20			; 2,3
	Sta	Q6H			; 4
	Lda	Temp1			; 3
	Bne	$50			; 2,3		if !=0 then use address mark values
	Lda	DatMk1			; 3	12	First data field mark
	Jsr	WrNib1			; 6	14/6
	Lda	DatMk2			; 3	9	second data field mark
	Jmp	WrNib1			; 3	12	Rts to caller from WrNib1

$50	Lda	AdrMk1			; 3	12	first address field mark
	Jsr	WrNib1			; 6	14/6
	Lda	AdrMk2			; 3	9	second address field mark
	Jmp	WrNib1			; 3	12	Rts to caller from WrNib1