$TITLE('CONTRAVES ENCODER (YUMA)') DEBUG PAGEWIDTH(80)
$NOSYMBOLS MACROFILE
;
;******************************************************
;
	NAME	JN1478
	PUBLIC	STAK,INTRR,PGMEM,FPSST,LMPAR,LCPAR
	PUBLIC	LP1PAR,YRPAR,XMPAR,LCADR,YRADR,XMADR
	PUBLIC	MTAB,BRTAB,DPART,PARSV,MENULP,CMPAR
	PUBLIC	CMADR,MENUR,XSWST,LDDAY,CTODCT,XPPAR
	PUBLIC	CRPAR,CRADR,DEFLC,IRIGFG,RETFG,XPADR
	PUBLIC	LDXP
	EXTRN	TSTNVM,YEAR,LDLPM,CBYTE,FORCK
	EXTRN	LDCHR,RIFF,IRIGSR,RVSPT,LDSPA
	EXTRN	MENUFG,ANNOR,CKINIT,EXIT,SETCK
	EXTRN	MENU,POSAN,LDCON,RDCLK,CLOCK,CLKST
	EXTRN	IRIGST,XSTAT,B2ACAS,BCDCLK,ASCCLK
	EXTRN	LDASCK,DAY,DMYCV,PDAY,WTPAR,XMCHG,BOX
	EXTRN	LOD,AD,SB,MUL,DIV,TST,CHS,ABS,STR,MOVE
	EXTRN	INIT,INP,OU,BXHAIR,XOUTDR,ABSPOS
	EXTRN	BCDASC,XINIT
;	DATE	15 MAR 84
;
;******************************************************
;
;		EXECUTIVE EQUATES
;
;******************************************************
;
;MEMORY ADDRESSES
;
FXDBF	EQU	3800H		;FIXED DATA BUFFER
ALTPG	EQU	3900H		;PAGE SAVE BUFFER
FPLUT	EQU	3A60H		;F.P. LOOK UP TABLE
STAK	EQU	3E00H		;TOP OF STACK
PGMEM	EQU	3E00H		;PAGE MEMORY
PARIN	EQU	4000H		;PARALLEL INPUT
ENCOD	EQU	4A00H		;ENCODER
;
;I/O PORT ADDRESSES
;
IPB	EQU	5		;IRIG PORT B
ISP	EQU	6		;IRIG STATUS PORT
ICM	EQU	7		;IRIG COMMAND PORT
;
FXDST	EQU	8		;FXD DATA STATUS PORT
FXDAD	EQU	8		;FXD DATA ADDRESS PORT
FXDCM	EQU	9		;FXD DATA COMMAND PORT
FXDIN	EQU	9		;FXD DATA INPUT PORT
FXDHS	EQU	10		;FXD DATA IN W/H'SHAKE
;
STATUS	EQU	47H		;VSP INTR STATUS PORT
FPSIO	EQU	48H		;FRONT PANEL SWITCHES
ENCMD	EQU	4AH		;ENCODER COMMAND PORT
;
;******************************************************
;
;		SYSTEM INITIALIZATION
;
;******************************************************
;
	ORG	0		;RST0 VECTORS HERE
;
START:
	DI			;DISABLE INTERRUPTS
	LXI	SP,STAK		;LOAD STACK POINTER
	CALL	TSTNVM		;MOVE PARAMETERS TO RAM
	LDA	LCPAR		;FETCH LINE COUNT
	LXI	H,PGMEM		;CLEAR PAGE
	CALL	ANNOR
	LXI	H,LCPAR		;LOAD LINE POS MEMORY
	CALL	LDLPM
	LHLD	PONWD		;POWER ON TEST WORD
	LXI	D,55AAH		;POWER ON CONSTANT
	MOV	A,H		;POWER ON INIT?
	CMP	D
	JNZ	INIT05		;YES-AHEAD
	MOV	A,L
	CMP	E
	JZ	INIT40		;NO-AHEAD
INIT05:
	XCHG			;ELSE-STORE CONSTANT
	SHLD	PONWD
	XRA	A		;RESET OTHER TEST BYTES
	STA	CBYTE
	MVI	C,5		;INIT CTR FOR OPT TEST
	CALL	RVSPT		;RESET TIMER
	JMP	INIT10		;AHEAD
	NOP
	NOP
;
;******************************************************
;
;		INTERRUPT PROCESSING
;
;******************************************************
;
	ORG	38H		;RST7 VECTORS HERE
;
INTR:
	PUSH	PSW		;SAVE REGISTERS
	PUSH	B
	PUSH	D
	PUSH	H
	LXI	H,INTRR		;RET ADDR TO STACK
	PUSH	H
;
;TEST FOR VSP INTERRUPT
;
	IN	STATUS		;FETCH VSP F/F STATUS
	RLC			;SET?
	JNC	INT20		;NO-AHEAD
	LXI	H,ENCOD		;POINT AT ENCODER
;
;BEGIN ENCODER LOADING
;
	MVI	M,0		;STORE NULL BYTE
	INX	H
	MVI	M,10110011B	;STORE SYNC BYTE
	INX	H
	PUSH	H		;SAVE POINTER
	CALL	RDCLK		;READ CLOCK
	POP	H		;RESTORE POINTER
	LXI	D,BCDCLK	;BCD CLOCK DATA
	MVI	C,7		;7 BYTES OF CLOCK
	CALL	LDCHR		;LOAD TIME
	LXI	H,FXDCT		;FIXED DATA COUNT
	MOV	E,M		;COUNT TO DE
	MVI	D,0
	INR	M		;INCREMENT COUNT
	LXI	H,FXDBF		;POINT AT BUFFER
	DAD	D		;ADD COUNT
	MOV	A,M		;FETCH FIXED DATA
	LXI	H,ENCOD+16	;ENCODER FIELD COUNT
	MOV	M,E		;LOAD COUNT
	INX	H
	MOV	M,A		;LOAD FIXED DATA
	INX	H
	MVI	M,0		;LOAD NULL
;
;RESET INTR F/F AND WRITE LINE 1 ANNOTATION
;
	MVI	A,0FFH		;SET FLAG
	STA	VSPFG
	CALL	RIFF		;RESET INTR F/F
	CALL	RDFPS		;READ F.P. SWITCHES
	CALL	LDASCK		;CONV CLK TO ASCII
	LXI	H,PGMEM		;POINT AT PAGE
	CALL	LDDAY		;LOAD DAY
	CALL	CTODCT		;COMPUTE TOD COUNT
	CALL	LDCHR		;LOAD TIME
	LDA	IRIGFG		;IRIG IN SYSTEM?
	ORA	A
	JNZ	$+8		;NO-AHEAD
	LDA	ASCCLK		;ELSE-STORE STATUS
	MOV	M,A
	INX	H
	MVI	M,' '		;SPACE
	INX	H
	SHLD	PGPTR		;SAVE POINTER
;
;READ PARALLEL INPUT AND LOAD ENCODER
;
	LXI	H,AZELBF	;POINT AT BUFFER
	PUSH	H		;SAVE POINTER
	LXI	D,PARIN		;POINT AT PARALLEL IN
	MVI	C,6		;6 BYTES
INT03:
	LDAX	D		;FETCH BYTE
	CMA			;COMPLEMENT
	MOV	M,A		;STORE
	INX	H		;BUMP POINTERS
	INX	D
	DCR	C		;DONE?
	JNZ	INT03		;NO-BACK
	DCX	H		;FETCH EL LSB'S
	MOV	A,M
	ANI	0F8H		;MASK 3 LSB'S
	MOV	M,A		;STORE
	DCX	H		;FETCH AZ LSB'S
	DCX	H
	DCX	H
	MOV	A,M
	ANI	0F8H		;MASK 3 LSB'S
	MOV	M,A		;STORE
	LXI	H,ENCOD+9	;POINT AT ENCODER
	POP	D		;POINT AT BUFFER
	MVI	C,6		;6 BYTES
	CALL	LDCHR		;LOAD ENCODER
	MVI	M,0		;LOAD NULL
	LXI	H,CNVFG		;CONVERT FLAG SET?
	XRA	A
	ORA	M
	JNZ	INT05		;YES-AHEAD
	CMA			;ELSE-SET FLAG
	MOV	M,A
	LXI	H,AEIBF		;LOAD BUFFER
	LXI	D,AZELBF
	CALL	LDCHR
;
;OUTPUT FIELD COUNT AND READ FIXED DATA
;
INT05:
	LDA	FXDFG		;FIXED DATA INPUT?
	ORA	A
	RNZ			;NO-RETURN
	IN	FXDST		;FETCH STATUS
	ANI	2		;MASK FOR MODE
	STA	FDMDF		;STORE MODE
	LXI	H,FLDCT		;FETCH FIELD COUNT
	MOV	A,M
	OUT	FXDAD		;OUTPUT COUNT
	MOV	E,A		;SAVE COUNT
	LDA	FDMDF		;HANDSHAKE MODE?
	ORA	A
	RNZ			;YES-RETURN
	INR	M		;ELSE-INCR COUNT
	IN	FXDIN		;INPUT DATA
	MOV	C,A		;SAVE IN C
	JMP	INT25		;STORE AHEAD
;
;TEST FOR INTERFACE INTERRUPT
;
INT20:
	LDA	FXDFG		;FIXED DATA INPUT?
	ORA	A
	JNZ	INT35		;NO-AHEAD
	IN	FXDST		;INTERRUPT?
	ANI	1
	JZ	INT35		;NO-AHEAD
	OUT	FXDCM		;RESET INTERRUPT
	IN	FXDHS		;READ DATA
	MOV	C,A		;SAVE IN C
	LXI	H,FLDCT		;FETCH FIELD COUNT
	MOV	E,M
	INR	M
	LDA	FXDCT		;FETCH FXD DATA CNT
	CMP	M		;COUNTERS EQUAL?
	JZ	INT25		;YES-AHEAD
	ORA	A		;FXDCT=0?
	JNZ	INT25		;NO-AHEAD
	MOV	M,A		;ELSE-SYNC COUNTERS
INT25:
	MOV	A,E		;CHECK COUNT
	CPI	240		;COUNT<240?
	RNC			;NO-IGNOR
	LXI	H,FXDBF		;POINT AT BUFFER
	MVI	D,0		;SET UP OFFSET
	DAD	D		;ADD OFFSET
	MOV	M,C		;STORE DATA
	MOV	A,C		;ASCII CHARACTER?
INT30:
	ORA	A		;NULL?
	RZ			;YES-IGNOR
	CPI	20H		;VALUE <20H?
	JC	$+8		;YES-SPACE AHEAD
	CPI	60H		;VALUE <60H?
	JC	$+5		;YES-VALID
	MVI	A,20H
	LXI	H,PGMEM+64	;POINT AT PAGE
	DAD	D		;ADD OFFSET
	MOV	M,A		;STORE CHARACTER
	RET
;
;TEST FOR IRIG INTERRUPT
;
INT35:
	LDA	IRIGFG		;IRIG IN SYSTEM
	ORA	A
	RNZ			;NO-RETURN
	POP	H		;RESET STACK POINTER
	IN	ISP		;INTERRUPT?
	ANI	8
	JNZ	IRIGSR		;YES-SERVICE INTR
;
;RETURN FROM INTERRUPT
;
INTRR:
	POP	H		;RESTORE REGISTERS
	POP	D
	POP	B
	POP	PSW
	EI			;ENABLE INTERRUPTS
	RET			;RETURN TO PROGRAM
;
;******************************************************
;
;		CONTINUE INITIALIZATION
;
;******************************************************
;
INIT10:
	XRA	A		;TEST FOR RETICLE GEN
	OUT	31H		;OUTPUT ZERO
	IN	STATUS		;TIMEOUT?
	RLC
	JC	INIT15		;YES-AHEAD
	DCR	C		;DONE?
	JNZ	INIT10		;NO-BACK
INIT15:
	MOV	A,C		;SET/RESET PARAMETER
	STA	RETFG		;ZERO=RETICLE GEN
	MVI	C,5		;TEST FOR FIXED
	CALL	RVSPT		; DATA INPUT
INIT30:
	IN	FXDST		;READ PORT
	IN	STATUS		;TIMEOUT?
	RLC
	JC	INIT35		;YES-AHEAD
	DCR	C		;DONE?
	JNZ	INIT30		;NO-BACK
INIT35:
	MOV	A,C		;SET/RESET FLAG
	STA	FXDFG		;ZERO=FIXED DATA INP
	IN	FXDST		;READ STATUS PORT
	OUT	FXDCM		;RESET INTERRUPT
	ANI	2		;MASK FOR MODE
	STA	FDMDF		;STORE AS MODE FLAG
	MVI	A,0C0H		;TEST FOR IRIG
	OUT	ICM		;INIT IRIG 8255
	IN	IPB		;READ B PORT
	STA	IRIGFG		;SET/RESET FLAG
	XRA	A		;RESET MENU FLAG
	STA	MENUFG
	LDA	XMPAR		;INIT RETICLE MODE
	STA	XSWST
INIT40:
	LDA	MENUFG		;RST0 FROM MENU?
	ORA	A
	JNZ	INIT45		;YES-AHEAD
	LXI	H,FXDBF		;RESET FIXED DATA
	MVI	C,255
	CALL	LDCON
	MOV	M,A		;RESET LAST BYTE
	INX	H		;POINT AT PAGE BUFFER
	LDA	LMPAR		;CLEAR PAGE SAVE BUFFER
	CALL	ANNOR
	LXI	H,ENCOD		;RESET ENCODER
	XRA	A
	MVI	C,31
	CALL	LDCON
INIT45:
	XRA	A		;RESET MENU FLAG
	STA	MENUFG
	LXI	H,ZROST		;RESET FLAGS
	MVI	C,ZROLN
	CALL	LDCON
	LXI	D,ALTPG		;MOVE ANNOTATION
	LXI	H,PGMEM
	LDA	LMPAR
	CALL	MOVE
	MVI	B,0		;B=0
	LDA	IRIGFG		;IRIG IN SYSTEM?
	ORA	A
	JNZ	INIT50		;NO-AHEAD
	MVI	A,0C0H		;INIT IRIG 8255
	OUT	ICM
	LDA	CMPAR		;IRIG MODE?
	CPI	'I'
	JNZ	INIT50		;NO-AHEAD
	INR	B		;B=1
INIT50:
	MOV	A,B		;CLOCK STATUS
	STA	CLKST
	CALL	CKINIT		;INIT CLOCK
	CALL	XINIT		;INIT RETICLE
	CALL	INIT		;INIT F.P. PACKAGE
	XRA	A
	STA	FPCTR2		;RESET COUNTER
	LXI	H,FPLUT		;INIT POINTER
	PUSH	H
	MVI	A,24		;INIT COUNTER
	STA	FPCTR2
	LXI	H,F180		;START WITH 180 DEG
	CALL	LOD
INIT60:
	POP	H		;FETCH POINTER
	CALL	STR		;STORE FP VALUE
	INX	H		;BUMP POINTER
	PUSH	H		;SAVE IT
	LXI	H,FTWO		;DIVIDE BY 2
	CALL	DIV
	LXI	H,FPCTR2	;DONE?
	DCR	M
	JNZ	INIT60		;NO-BACK
	POP	H		;RESET STACK POINTER
INIT65:
	CALL	RIFF		;RESET INTR F/F
	EI			;ENABLE INTERRUPTS
	HLT			;WAIT
;
;******************************************************
;
;		EXECUTIVE LOOP
;
;******************************************************
;
RUN:
	LXI	H,VSPFG		;VSP INTERRUPT?
	XRA	A
	CMP	M
	JZ	RUN10		;NO-AHEAD
	MOV	M,A		;ELSE-RESET FLAG
	LHLD	PGPTR		;FETCH POINTER
	LDA	RETFG		;RETICLE GENERATOR?
	ORA	A
	JNZ	RUN05		;NO-AHEAD
	LXI	D,ABSPOS	;POINT AT POSITION
	PUSH	D		;SAVE DATA POINTER
	PUSH	H		;SAVE PAGE POINTER
	LXI	H,FXDBF+250	;FIXED DATA BUFFER
	MVI	C,6		;6 CHARACTERS
	CALL	LDCHR		;LOAD POSITION
	CALL	XOUTDR		;UPDATE RETICLE
	POP	H		;RESTORE POINTERS
	POP	D
	LDA	XSWST		;RETICLE ON?
	ANI	7
	JZ	RUN05		;NO-AHEAD
	CALL	LDXP		;STORE XHAIR POS
RUN05:
	MVI	A,32		;LAST CHAR IN LINE?
	CMP	L
	JZ	$+9		;YES-AHEAD
	MVI	M,' '		;ELSE-SPACE FILL
	INX	H
	JMP	$-7		;BACK
	LXI	H,PGMEM+304	;POINT AT PAGE
	LXI	D,FXDBF+240	;FIXED DATA
	MVI	C,16		;16 CHARACTERS
	MVI	B,' '		;B=SPACE
RUN08:
	LDAX	D		;FETCH CHARACTER
	CPI	20H		;VALID ASCII?
	JC	$+8		;NO-SPACE AHEAD
	CPI	60H
	JC	$+4		;YES-STORE AHEAD
	MOV	A,B		;ELSE SPACE
	MOV	M,A
	INX	D		;BUMP POINTERS
	INX	H
	DCR	C		;DONE?
	JNZ	RUN08		;NO-BACK
RUN10:
	LDA	CNVFG		;CONVERT FLAG SET?
	ORA	A
	JZ	RUN20		;NO-AHEAD
	CALL	FMTL2		;STORE LABELS
	LXI	H,FXDBF+242	;FIXED DATA BUFFER
	MVI	M,'B'		;INDICATE BINARY
	LXI	H,AEIBF		;POINT AT AZIMUTH
	CALL	AB2ASC		;CONVERT TO ASCII
	LXI	H,PGMEM+35	;POINT AT ANNOTATION
	MVI	C,8		;8 CHARACTERS
	CALL	LDCHR		;STORE AZIMUTH
	LXI	H,AEIBF+3	;POINT AT ELEVATION
	CALL	AB2ASC		;CONVERT TO ASCII
	LXI	H,PGMEM+47	;STORE ELEVATION
	MVI	C,8
	CALL	LDCHR
	XRA	A		;RESET FLAG
	STA	CNVFG
	STA	VSPFG		;RESET FLAG
	HLT			;WAIT FOR INTERRUPT
RUN20:
	JMP	RUN		;LOOP BACK
;
;******************************************************
;
;		EXECUTIVE SUBROUTINES
;
;******************************************************
;
;READ FRONT PANEL SWITCHES
;
RDFPS:
	LXI	H,FPSST		;POINT AT SWITCH STATUS
	IN	FPSIO		;READ SWITCHES
	ANI	1FH		;ALL OFF?
	JNZ	RDS05		;NO-AHEAD
	MOV	M,A		;ELSE-RESET STATUS
	RET
RDS05:
	CMP	M		;CHANGE?
	RZ			;NO-IGNOR
	MOV	M,A		;STORE NEW STATUS
	RRC			;MENU?
	JNC	RDS10		;NO-AHEAD
	LXI	H,ALTPG+64	;PAGE SAVE BUFFER
	LXI	D,PGMEM+64	;PAGE MEMORY
	MVI	A,8		;8 LINES
	CALL	MOVE		;SAVE ANNOTATION
	JMP	MENU		;GO DO MENU
RDS10:
	MVI	A,1CH		;BOX,B/W OR HI/LO?
	ANA	M
	LXI	H,XSWST		;RETICLE SWITCH STATUS
	JZ	RDS15		;NO-AHEAD
	XRA	M		;ELSE-COMPLEMENT
	MOV	M,A		; STATUS BIT
	JMP	XINIT		;REINIT RETICLE
RDS15:
	MOV	A,M		;FETCH STATUS
	ANI	1CH		;SAVE BOX,B/W,HI/LO STAT
	MOV	B,A
	MOV	A,M		;INCR CROSS STATUS
	INR	A
	ANI	3		;MASK
	ORA	B		;COMBINE STATUS
	MOV	M,A
	JMP	XINIT
;
;******************************************************
;
;LOAD RETICLE POSITION SUBROUTINE
;
LDXP:
	MVI	M,'X'		;STORE "X:"
	INX	H
	MVI	M,':'
	INX	H
	MVI	C,3
	CALL	LDCHR		;STORE X POSITION
	MVI	M,' '		;SPACE
	INX	H
	MVI	M,'Y'		;STORE "Y:"
	INX	H
	MVI	M,':'
	INX	H
	JMP	LDCHR		;STORE Y POSITION
;
;******************************************************
;
;ANGULAR BINARY TO ASCII CONVERSION SUBROUTINE
;
AB2ASC:
	PUSH	H		;SAVE POINTER
	XRA	A		;ZERO F.P. BUFFER
	STA	FPBUF
	STA	FPCTR2		;RESET BYTE COUNTER
	LXI	H,0308H		;INIT LOOP COUNTERS
	SHLD	FPCTR1
ABA05:
	POP	H		;FETCH POINTER
	MOV	A,M		;FETCH DATA
	RAL			;SHIFT LEFT
	MOV	M,A		;STORE SHIFTED DATA
	PUSH	H		;SAVE POINTER
	JNC	ABA10		;IF BIT=0
	LXI	H,FPLUT		;POINT AT TABLE
	LDA	FPCTR2		;FETCH COUNT
	ADD	A		;COUNT*4
	ADD	A
	MOV	E,A		;COUNT*4=OFFSET
	MVI	D,0		;TO DE
	DAD	D		;FORM POINTER
	CALL	LOD		;LOAD FROM TABLE
	LXI	H,FPBUF		;ADD TO BUFFER
	PUSH	H
	CALL	AD
	POP	H		;STORE RESULT
	CALL	STR
ABA10:
	LXI	H,FPCTR2	;BUMP BYTE COUNTER
	INR	M
	LXI	H,FPCTR1	;BYTE DONE?
	DCR	M
	JNZ	ABA05		;NO-BACK
	MVI	M,8		;ELSE-REINIT COUNT
	INX	H		;CONVERSION DONE?
	DCR	M
	JZ	ABA15		;YES-AHEAD
	POP	H		;ADJUST POINTER
	INX	H
	PUSH	H
	JMP	ABA05		;BACK
ABA15:
	POP	H		;RESET SP
	LXI	H,FPBUF		;LOAD RESULT
	CALL	LOD
	LXI	H,ARG		;CONVERT TO ASCII
	CALL	OU
	LXI	H,ARG
	MVI	C,13		;13 BYTES
ABA20:
	MOV	A,M		;FETCH BYTE
	ADI	30H		;ADD BIAS
	MOV	M,A		;STORE ASCII
	INX	H		;BUMP POINTER
	DCR	C		;DONE?
	JNZ	ABA20		;NO-BACK
	LDA	ARG+9		;EXPONENT?
	CPI	'E'
	JNZ	ABA30		;NO-AHEAD
	LDA	ARG+12		;FETCH EXPONENT
	LXI	D,ZROMG		;POINT AT ZEROS
	LXI	H,AEOBF		;POINT AT BUFFER
	PUSH	H
	SUI	2DH		;TOTAL ZEROS
	MOV	C,A
	CALL	LDCHR		;STORE LEADING ZEROS
	MVI	A,8		;MAX COUNT
	SUB	C		;CHARS REMAINING
	JZ	ABA25		;IF DONE
	MOV	C,A
	LXI	D,ARG+1		;POINT AT DATA
	LDAX	D		;FETCH 1ST CHAR
	MOV	M,A		;STORE
	DCR	C		;DONE?
	JZ	ABA25		;YES-AHEAD
	INX	H		;BUMP POINTERS
	INX	D
	INX	D
	CALL	LDCHR		;COMPLETE
ABA25:
	POP	D		;RESTORE POINTER
	RET
ABA30:
	LXI	D,ARG+4		;POINT AT DATA
	LXI	H,AEOBF		;POINT AT BUFFER
	PUSH	H
	MVI	C,8		;8 CHARACTERS
	LDAX	D		;FETCH 4TH CHARACTER
	CPI	'.'		;DECIMAL
	JZ	ABA35		;YES-AHEAD
	MVI	M,' '		;ELSE-SPACE
	INX	H
	DCX	D
	DCR	C
	LDAX	D		;FETCH 3RD CHARACTER
	CPI	'.'		;DECIMAL
	JZ	ABA35		;YES-AHEAD
	MVI	M,' '		;ELSE-SPACE
	INX	H
	DCR	C
	DCX	D
	LDAX	D		;FETCH 2ND CHARACTER
	CPI	'.'		;DECIMAL?
	JZ	ABA35		;YES-AHEAD
	MVI	M,'0'		;ELSE-ZERO
	INX	H
	DCR	C
ABA35:
	LXI	D,ARG+1		;POINT AT DATA
	CALL	LDCHR		;STORE IN BUFFER
	POP	D		;RESTORE POINTER
	RET
;
ZROMG:	DB	'  0.0000'
;
	ORG	($+3) AND 0FFFCH
;
F180:	DB	88H,33H,0FFH,0FFH
FTWO:	DB	82H,00H,00H,00H
;
;******************************************************
;
;FORMAT LINE 2 SUBROUTINE
;
FMTL2:
	LXI	H,PGMEM+32	;POINT AT PAGE
	LXI	D,LN2MG		;POINT AT MESSAGE
	MVI	C,3
	CALL	LDCHR		;STORE "AZ:"
	LXI	H,PGMEM+43	;STORE "EL:"
	INR	C
	CALL	LDCHR
	LXI	H,PGMEM+55
	MVI	C,9		;SPACE FILL
	JMP	LDSPA
;
LN2MG:	DB	'AZ: EL:'
;
;******************************************************
;
;COMPUTE TIME OF DAY COUNT SUBROUTINE
;
CTODCT:
	MVI	C,5		;INITIAL COUNT=5
	LDA	CRPAR		;FETCH PARAMETER
	ANI	7FH		;MASK MSB
	MOV	B,A		;SAVE IN B
	CPI	0		;RESOLUTION TO MINUTES?
	RZ			;YES-RETURN
	MVI	C,8		;SET COUNT=8
	CPI	1		;RESOLUTION TO SECONDS?
	RZ			;YES
	LDA	MENUFG		;CALLED FROM MENU?
	ORA	A
	JNZ	CTC05		;YES-AHEAD
	LDA	XSWST		;RETICLE ON?
	ANI	7
	JZ	CTC05		;NO-AHEAD
	LDA	CRPAR		;JULIAN DISPLAY?
	RLC
	JNC	CTC05		;YES-AHEAD
	MOV	A,B		;COMPUTE COUNT
	ADD	C
	CPI	12		;COUNT<12?
	JC	$+5		;YES-AHEAD
	MVI	A,11		;MAX COUNT=11
	MOV	C,A
	RET
CTC05:
	MOV	A,B		;FETCH PARAMETER
	ADD	C		;COMPUTE FOR FRAC SEC
	MOV	C,A		;COUNT TO C
	RET
;
;******************************************************
;
;LOAD DAY OF YEAR SUBROUTINE
;
LDDAY:
	LDA	CRPAR		;JULIAN DISPLAY?
	RLC
	JC	LDY05		;NO-AHEAD
	LXI	D,ASCCLK+1	;POINT AT DAY
	MVI	C,5		;5 CHARACTERS
	JMP	LDCHR		;LOAD JULIAN DAY
LDY05:
	PUSH	H		;SAVE POINTER
	LXI	H,DAYSV		;DAY CHANGE?
	LDA	DAY
	CMP	M
	JZ	LDY10		;NO-AHEAD
	MOV	M,A		;SAVE NEW DAY
	CALL	DMYCV		;UPDATE D-M-Y
LDY10:
	POP	H		;RESTORE POINTER
	LXI	D,PDAY		;POINT AT PRESET DAY
	CALL	B2ACAS		;CONVERT & STORE DAY
	MVI	C,3		;STORE MONTH
	CALL	LDCHR
	CALL	B2ACAS		;CONVERT & STORE YEAR
	MVI	M,' '
	INX	H
	LXI	D,ASCCLK+6	;POINT AT HOUR
	RET
;
;******************************************************
;
;MENU RESET SUBROUTINE
;
MENUR:
	LDA	RETFG		;RETICLE GENERATOR?
	ORA	A
	RNZ			;NO-RETURN
	CMA			;ELSE-DISABLE RETICLE
	OUT	31H
	RET
;
;******************************************************
;
;BORESIGHT RETICLE MENU BRANCH ROUTINE
;
POSRET:
	LXI	H,BXHAIR	;POS RETICLE BRANCH
	JMP	BX05		;AHEAD
CHGBOX:
	LXI	H,BOX		;CHANGE BOX BRANCH
	JMP	BX05
DEFRET:
	LXI	H,XMCHG		;DEF RETICLE BRANCH
BX05:
	LDA	RETFG		;RETICLE IN SYSTEM?
	ORA	A
	JNZ	MENU		;NO-BACK TO MENU
	PCHL			;ELSE-BRANCH
;
;******************************************************
;
;		EXECUTIVE TABLES
;
;******************************************************
;
;DEFAULT PARAMETERS TABLE
;
DPART:
NOPAR:	DB	25		;NUMBER OF PARAMETERS
TSTBT:	DB	78H		;TEST BYTE
DEFLM:	DB	10		;MAXIMUM # LINES
DEFLC:	DB	10		;DEFAULT # LINES
DEFLP1:	DB	10,25,40,120,135;DEFAULT LINE POSITIONS
	DB	150,165,180,195,210
DEFCMD:	DB	'M'		;DEFAULT CLOCK MODE
DEFYR:	DB	84H		;DEFAULT YEAR
DEFCR:	DB	3		;DEFAULT RESOLUTION
DEFXMD:	DB	15H		;DEFAULT RETICLE
DEFXP:	DW	500,120		;DEFAULT RETICLE POS
DEFBX:	DW	12,4		;DEFAULT BOX SIZE
;
;PARAMETER ADDRESS TABLE
;
TBADR:	DB	0		;TEST BYTE
LCADR:	DB	2		;LINE COUNT
CMADR:	DB	13		;CLOCK MODE
YRADR:	DB	14		;YEAR
CRADR:	DB	15		;RESOLUTION
XMADR:	DB	16		;RETICLE MODE
XPADR:	DB	17		;RETICLE POSITION
XBADR:	DB	21		;BOX SIZE
;
;MENU LINE POSITION TABLE
;
MENULP:
	DB	8		;NUMBER OF ENTRIES
	DB	20,40,60,80,100
	DB	120,140,160,180
;
;MENU ENTRY TABLE
;
MTAB:
	DB	8		;NUMBER OF ENTRIES
	DB	'EXIT MENU',0DH
	DB	'SET CLOCK',0DH
	DB	'FORMAT CLOCK',0DH
	DB	'POSITION TEXT',0DH
	DB	'POSITION RETICLE',0DH
	DB	'CHANGE BOX SIZE',0DH
	DB	'DEFINE RETICLE',0DH
;
;MENU BRANCH TABLE
;
BRTAB:
	DW	EXIT
	DW	SETCK
	DW	FORCK
	DW	POSAN
	DW	POSRET
	DW	CHGBOX
	DW	DEFRET
;
;******************************************************
;
;		EXECUTIVE DEFINED MEMORY
;
;******************************************************
;
	DSEG			;DATA SEGMENT
;
;FLOATING POINT STORAGE
;
FPBUF:	DS	4		;F.P. BUFFER
ABBUF:	DS	4		;CONVERSION BUFFER
ARG:	DS	13		;F.P. I/O BUFFER
;
;FLAGS ETC. RESET DURING INITIALIZATION
;
ZROST	EQU	$		;START OF BUFFER
VSPFG:	DS	1		;VSP INTERRUPT FLAG
NAEFG:	DS	1		;NEW AZ/EL DATA FLAG
NFDFG:	DS	1		;NEW FIXED DATA FLAG
FLDCT:	DS	1		;FIELD COUNTER
FXDCT:	DS	1		;FIXED DATA COUNTER
FDMDF:	DS	1		;FIXED DATA MODE FLAG
MINSV:	DS	1		;MINUTE SAVE CELL
CNVFG:	DS	1		;CONVERT FLAG
ZROLN	EQU	$-ZROST		;BUFFER LENGTH
;
;OPTION FLAGS
;
RETFG:	DS	1		;RETICLE FLAG
ENCFG:	DS	1		;ENCODER FLAG
IRIGFG:	DS	1		;IRIG FLAG
INTFG:	DS	1		;INTERFACE FLAG
FXDFG:	DS	1		;FXD DATA INPUT FLAG
;
;PARAMETER BUFFER
;
PARSV:
LMPAR:	DS	1		;MAXIMUN # LINES
LCPAR:	DS	1		;ACTUAL # LINES
LP1PAR:	DS	10		;LINE POSITIONS
CMPAR:	DS	1		;CLOCK MODE
YRPAR:	DS	1		;YEAR
CRPAR:	DS	1		;RESOLUTION
XMPAR:	DS	1		;RETICLE MODE
XPPAR:	DS	4		;RETICLE POSITION
XBPAR:	DS	4		;BOX SIZE
;
;EXECUTIVE STORAGE
;
PONWD:	DS	2		;POWER ON TEST WORD
XSWST:	DS	1		;RETICLE SWITCH STATUS
FPSST:	DS	1		;FRONT PANEL SW STATUS
DAYSV:	DS	1		;DAY SAVE CELL
PGPTR:	DS	2		;PAGE POINTER
AZELBF:	DS	6		;AZ/EL INPUT BUFFER
;
;ANGULAR BINARY TO ASCII CONVERSION STORAGE
;
FPCTR1:	DS	2		;LOOP COUNTERS
FPCTR2:	DS	1		;BYTE COUNTER
AEIBF:	DS	6		;INPUT BUFFER
AEOBF:	DS	8		;OUTPUT BUFFER
;
;******************************************************
;
	END
