Compucolor.org – Virtual Media

Listing of file='FMTCD1.SRC;2F' on disk='vmedia/taylor_7-sector.ccvf'

;
; DISK FORMATTING PROGRAM FOR THE COMPUCOLOR II
; AUTHOR -- J. STEPHEN BOUR II          1/27/79
;
;
; SYSTEM CONSTANTS
;
CKWRD	EQU	82H
TBLE	EQU	08460H
LGAP	EQU	0
SGAP	EQU	36
MGAP	EQU	5
;
DSKID	EQU	20H
DSKWTB	EQU	08H
DSKDCM	EQU	4
DSKSBR	EQU	5
DSKSTA	EQU	3
DSKTSM	EQU	6
TBE	EQU	10H
RDA	EQU	8
DSKDTA	EQU	0
DSKCOM	EQU	07H
;
KYTST	EQU	0024H
OSTR	EQU	33F4H
KBCHA	EQU	81FEH
;
; BEGIN OF PROGRAM
;
	ORG	8200H
	LXI	SP,STACK
	LXI	H,PMSG
	CALL	OSTR	; PRINT PROMPT MESSAGE
BCKUP:	LXI	H,PROMP
	CALL	OSTR	; FORMAT MESSAGE
KWT:	CALL	KYTST
	JNZ	KWT
	LDA	KBCHA
	CPI	'E'-40H
	JZ	0000H	; JUST LIKE CPU RESET
	CPI	'F'-40H
	JNZ	KWT
	MVI	A,3
	STA	RTRY
INST:	CALL	RINIT
	LXI	H,FTMES
	CALL	OSTR
	MVI	A,04H
	STA	LASTST
	DI		; DON'T INTERUPT
	MVI	A,DSKID
	OUT	DSKCOM
;
; STEP HEAD OUT 54 TIMES (JUST LIKE THE BIG BOYS)
;
	MVI	B,54
SOAGN:	CALL	STPOUT
	DCR	B
	JNZ	SOAGN
	MVI	C,0
	CALL	DELAY
;
; SET UP FOR HIGH SPEED
;
	MVI	A,011H	; HIGH BAUD, RESET
	OUT	DSKDCM
	MVI	A,0C0H	; 1 STOP BIT, 9600 (*8) BAUD
	OUT	DSKSBR
;
; SET UP POINTER TO EGNIMA TABLE, LOOP PARAMETERS
;
	LXI	D,TBLE
	MVI	B,1
;
; WRITE A TRACK
;
TRKAN:	CALL	STPIN
	MVI	A,DSKWTB
	ADI	DSKID
	OUT	DSKCOM	; SET WRITE MODE
	MVI	C,LGAP
	CALL	DELAY	; WRITE INITIAL LONG GAP
	MVI	C,10	; WRITE 10 SECTORS
	LXI	H,SCTTBL
;
; WRITE A SECTOR
;
SCTAN:	PUSH	B
	MVI	C,SGAP
	CALL	DELAY
	MVI	A,55H
	CALL	DSKWRT
	MOV	A,B
	CALL	DSKWRT	; TRK ID
	MOV	A,M
	INX	H
	CALL	DSKWRT	; SCT ID
	LDAX	D
	INX	D
	CALL	DSKWRT	; BYTE 1, EGNIMA
	LDAX	D
	INX	D
	CALL	DSKWRT	; BYTE 2, EGNIMA
	MVI	C,10
	CALL	DELAY
	MVI	C,3
	MVI	A,0FFH
FFAGN:	CALL	DSKWRT
	DCR	C
	JNZ	FFAGN
	MVI	A,5AH
	CALL	DSKWRT
	MVI	C,80H
	MVI	A,0E5H
E5AGN:	CALL	DSKWRT	; WRITE A SECTOR OF E5'S
	DCR	C
	JNZ	E5AGN
	MVI	A,0AH
	CALL	DSKWRT	; FIRST BYTE OF CRC
	MVI	A,0B7H
	CALL	DSKWRT	; SECOND BYTE OF CRC
	POP	B
	DCR	C
	JNZ	SCTAN
	MVI	C,MGAP
	CALL	DELAY
	MVI	A,0E0H
	CALL	DSKWRT	; END OF TRACK BYTE
	MVI	A,DSKID
	OUT	DSKCOM	; END WRITE MODE
	MOV	A,B
	CPI	40
	JZ	CHKPAS
	INR	B
	JMP	TRKAN
CHKPAS:	CALL	RINIT
	LXI	H,VMES
	CALL	OSTR
	DI
	MVI	B,40
SOGN:	CALL	STPOUT
	DCR	B
	JNZ	SOGN
	MVI	C,0
	CALL	DELAY
;
; AGAIN, SET UP FOR HIGH-SPEED OPERATION
;
	MVI	A,11H
	OUT	DSKDCM
	MVI	A,0C0H
	OUT	DSKSBR
;
; READ 40 TRACKS OF DATA
;
	MVI	B,1	; TRACK ID
;
; READ AN ENTIRE TRACK
;
; CHECKSUM IN C
;
	MVI	C,0
CHKTRK:	LXI	D,1391	; NUMBER OF BYTES ON A TRACK
	CALL	STPIN
RDLOOP:	CALL	RDBYT
	ADD	C
	MOV	C,A

	DCX	D
	MOV	A,D
	ORA	E
	JNZ	RDLOOP
;
; CHECK FOR LAST TRACK
;
	MOV	A,B
	CPI	40
	JZ	FIN	; WAS LAST TRACK, CHECK CHECKSUM
	INR	B
	JMP	CHKTRK
;
; FINISHED -- DO WE DO IT AGAIN?
;
FIN:	MOV	A,C
	CPI	CKWRD
	JZ	OKFIN
	LDA	RTRY	; TRY 3 TIMES, THEN GIVE UP
	DCR	A
	STA	RTRY
	JNZ	INST
NOKFIN:	CALL	RINIT
	LXI	H,FAMES
	CALL	OSTR
	JMP	BCKUP
OKFIN:	CALL	RINIT
	LXI	H,SMES
	CALL	OSTR
	JMP	BCKUP
;
; STEP HEAD IN ONE TRACK
;
STPIN:	LDA	LASTST
	RLC
	ANI	07H
	JNZ	SIR
	MVI	A,01H
SIR:	STA	LASTST
	ADI	DSKID
	OUT	DSKCOM
	PUSH	B
	MVI	C,0
	MVI	B,4
WGN:	CALL	DELAY
	DCR	B
	JNZ	WGN
	POP	B
	MVI	A,DSKID
	OUT	DSKCOM
	PUSH	B
	MVI	C,0
	MVI	B,17
WGNA:	CALL	DELAY
	DCR	B
	JNZ	WGNA
	POP	B
	RET
;
; STEP HEAD OUT ONE TRACK
;
STPOUT:	LDA	LASTST
	RRC
	ANI	07H
	JNZ	SOR
	MVI	A,04H
SOR:	STA	LASTST
	ADI	DSKID
	OUT	DSKCOM
	MVI	C,0
	CALL	DELAY
	MVI	A,DSKID
	OUT	DSKCOM
	RET
;
; RE-INITIALIZE KEYBOARD INTERRUPT-DRIVEN I/O
; (DON'T ASK ME HOW IT WORKS; IT JUST DOES!)
;
RINIT:	MVI	A,3
	OUT	4
	MVI	A,80H
	OUT	7
	IN	1
	ANI	30H
	POP	H
	JMP	37ABH
;
; DELAY ROUTINE -- USED TO CREATE SUITABLE DELAYS
; BETWEEN SECTOR WRITES AND HEAD STEPPING
; DELAY FORMULA IS APROXIMATELY
;
;       TIME = 27.5 + (FACTOR * 41), OR
;
;       FACTOR = (TIME - 27.5) / 41
;
; WHERE FACTOR IS THE ARGUMENT GIVEN THE SUBROUTINE
; BY THE CALL SEQUENCE      (UNITS ARE MICROSECONDS)
;
;	MVI	C,FACTOR
;	CALL	DELAY
;
DELAY:	PUSH	B
OLP:	MVI	B,04
ILP:	DCR	B
	JNZ	ILP
	DCR	C
	JNZ	OLP
	POP	B
	RET
;
; READ A BYTE FROM THE DISK UNIT
;
RDBYT:	IN	DSKSTA
	ANI	RDA
	JZ	RDBYT
	IN	DSKDTA
	RET
;
; WRITE A BYTE TO THE DISK UNIT
;
DSKWRT:	PUSH	PSW
WRTWT:	IN	DSKSTA
	ANI	TBE
	JZ	WRTWT
	POP	PSW
	OUT	DSKTSM
	RET
;
; LAST MINUTE DATA BYTES
;
RTRY:	DB	3
PMSG:	DB	0CH,'CPU DISK FORMATTER VER 1.0',239
PROMP:	DB	0DH,0AH,'FORMAT>',239
FTMES:	DB	'FORMAT',239
VMES:	DB	'VERIFY',239
SMES:	DB	'VERIFY OK',239
FAMES:	DB	'FAILED TO FORMAT',239
LASTST:	DB	04
SCTTBL:	DB	0,5,1,6,2,7,3,8,4,9
	DS	64
STACK	EQU	$
;
; END OF THE PROGRAM
;
	END