;format routines
;relies on FDC_code.asm

read "FDC_code.asm"

cmd_format_track	EQU		%01001101

;**********************
;*** FORMAT A TRACK ***
;**********************
;IX points on track structure
;0 = sector counts
;1-X = sectors ID

.FDC_FormatTrack

;db #ED,#FF
	
	ld A,cmd_format_track
	call FDC_send			;command
	
	push BC
	call FDC_GetIdd
	pop BC
	call FDC_send 			;IDD
	
	ld A,2
	call FDC_send			;size 2 = 512 bytes
	
	ld A,(IX+0)
	call FDC_send			;sector count
	
	ld   A,(gap3)
	call FDC_send 			;GAP3
	
	ld A,#E5				;filler , original , isn't it ?
	call FDC_send
	
	ld E,(IX+0)				;sector to process
	inc IX					;point to sector list
	
.FDC_FormatTrackLoop	
	
	ld A,(current_track)			;track/cylinder (C)
	call FDC_send
	
	;ld A,(current_head)
	xor A
	call FDC_send			;head (H)
	
	ld A,(IX+0)
	call FDC_send			;sector (R)
	
	ld A,2
	call FDC_send			;size (N)

	inc IX
	dec E
	jr nz,FDC_FormatTrackLoop 	
	
	call FDC_getresult
	jp FDC_CheckErrors
