$	DEBUG XREF GEN NOSYMBOLS PAGEWIDTH(80)
$	ERRORPRINT
;	LEADLESS CONTROL PANEL ROUTINE
;	VERSION	1.4	MAY 19 82	WHH

;	PORT DEFINITIONS

;OUTPUTS	8700W	D0-D7 BAR DATA

;		8701W	D0-INPUT JAM
;			D1-T.S. JAM
;			D2-SORT JAM
;			D3-INPUT JAM
;			D4-STOP
;			D5-OUT OF TEMP
;			D6-TESTING
;			D7-OUTPUT FULL

;		8702W	D0-D3 SWITCH SELECT
;			D4-DEFROST
;			D5-PURGE
;			D6-INITIATE
;			D7-PARITY JAM

;		8703W	D0-D6 ASCII CHARACTER
;			D7-DISPLAY STROBE

;		8704W	D0-D2 BAR SELECT/CLOCK


;INPUTS		8702R	D0-D7 SWITCH DATA


;		SWITCH TABLE
;SEL   DIS  D7   D6   D5   D4   D3   D2   D1   D0
;0  CONT    COLD COLD COLD TEMP PAR  STOP STRT DIS
;1  DBL TST 8    7    6    5    4    3    2    1
;2  DBL TST 16   15   14   13   12   11   10   9
;3  SET PNT CAL  NORM EXER 100'S      TEN'S
;4  STCK CP        TEN'S	 UNIT'S
;5  DIAG SEL       TEN'S	 UNIT'S
;6  SOAK TM        UNITS	 TENTHS
;7  SET PNT        UNITS	 VAR


;		INTERNAL DATA
INTL_DATA	SEGMENT	DATA
		RSEG	INTL_DATA
		DS	16



START_SAVE:	DS	1	;ON OFF TOGGLE
SWITCH_CNTR:	DS 	1	;SWITCH READ CNTR
COLD_LEDS:	DS	1	;OUTPUT LED WORD
BAR_CNTR:	DS	1	;BAR DISPLAY CNTR
TEMP_PNTR:	DS	1	;TEMP ZONE PNTR
CONTROLS:	DS	1	;CONTROL OPERANDS
;				D0-TEMP SEL
;				D1-DISPLAY UPDATE
;				D2-PULSE FLAG
BAR_PNTR:	DS	1	;BAR OUTPUT PNTR
SET_POINT:	DS	1	;SET POINT WORK WRD
SP_VAR:		DS	1	;VARIATION WORK WRD
DISP_PTR:	DS	1	;DISPLAY POINTER
;		UPPER INTERNAL DATA
SWITCH_VALUE:	DS	8
;			0	CONTROL SWITCHES
;			1	DOUBLE TEST
;			2	DOUBLE TEST
;			3	SET POINT
;			4	STICK CAP
;			5	DIAG SEL
;			6	SOAK TIME
;			7	SET POINT
PREV_READ:	DS	8	;SAME AS ABOVE
SWITCH_COUNT:	DS	8	;SAME AS ABOVE
SWITCH_PTR:	DS	1	;SWITCH POINTER
UPDATE_FLGS:	DS	8	;ALTERED SWITCHES
BAR_DATA:	DS	12	;BAR OUTPUT WORDS
;				D0-D3 BAR SELECT
;				D4-D7 GRAPH SELECT
TMDL1:		DS	1	;TIMER COUNTER
P2STORE:	DS	1	;P2 STORAGE WORD
STARTF:		DS	1	;START TEMP CONT
TMDL2:		DS	1	;TIMER 2 SEC CNTR
SWITCH_TIME:	DS	1	;FLAG FROM INT ROUTINE


FLAG_SPACE	SEGMENT	BIT
RSEG	FLAG_SPACE

FLAGS1:	DBIT	1
FLAGS2:	DBIT	1
FLAGS3:	DBIT	1
FLAGS4:	DBIT	1
FLAGS5:	DBIT	1



STACK_START	SEGMENT	DATA	;STACK START ADDR
RSEG		STACK_START	
		DS	16


XSEG	AT	0

DISPLAY_OUT:	DS	8	;SMART DISP ASCII
;				D7-STROBE BIT
ZONE_TEMPS:	DS	12	;CONTROL ZONE TEMPS
JAM_IND:	DS	1	;LED STATUS IND
RATE_VALUE:	DS	6	;BOGUS TEMP RATES


$INCLUDE(COMMAC.SRC)
$INCLUDE(TALK.SRC)
EXTRN NUMBER(?CONTROLSFLAGS)
MY_BOARD	EQU	2
ALIVE_COUNTS	EQU	0FFH
PUBLIC	P2STORE,MY_BOARD,ALIVE_COUNTS,PARAM_UPDATE


CSEG AT 0
RESTART: JMP	MAIN

CSEG AT 0BH
TMER0:	JMP	TIMER_INT_0

CON_PANEL SEGMENT CODE
RSEG	CON_PANEL

TIMER_INT_0: %SAVE
	%REG_BANK_1
	%ALIVE_TIMER
	MOV	TH0,#0FCH ;RESET TIMER
	MOV	TL0,#6BH
	SETB	TR0
	CLR	TF0

	CALL	BAR_DISP ;DO BAR GRAPHS
	CALL	DISP_OUT ;DO SMART DISP

	INC	TMDL1
	MOV	A,TMDL1
	ANL	A,#3H
	JNZ	TMER1	;JUMP IF NOT 4MSEC
	MOV	SWITCH_TIME,#0FFH	;TIME TO DO SWITCHES
	MOV	A,TMDL1
	JNZ	TMER1	;JUMP IF NOT .25 SEC
	INC	TMDL2
	MOV	A,TMDL2
	ANL	A,#7H	;JUMP IF NOT 2 SEC
	JNZ	TMER1
	CALL	TEMP_EX

TMER1:	%RESTORE
	RETI

MAIN:	MOV	SP,STACK_START-1
	CALL	INITIATE
	CALL	TMR_INITIATE
	CALL	SWITCH_INIT

MAIN1:	%ALIVE_MAIN
	MOV	A,SWITCH_TIME	;CHECK FOR SWITCHES
	JZ	SKIP_SWITCHES
	CALL	SWITCH_READ
	CALL	SWITCH_REPORT
SKIP_SWITCHES:	MOV	SWITCH_TIME,#0
	CALL	JAM_LED ;DO STATUS IND
	CALL	TEMP_CHECK ;DO AMB MODE CHECK
	CALL	SP_UPDATE ;DO SET POINT UPDATE
	CALL	DISP_FORMAT ;DO ASCII FORMAT
	MOV	A,STARTF
	JZ	MAIN1
	CALL	RATE_ADJ ;DO TEMP RATES
	CALL	BAR_FORMAT ;DO BAR DISPLAY FORM
	JMP	MAIN1
PARAM_UPDATE:	RET	;DUMMY FOR COMM PKG


INITIATE: MOV	SWITCH_TIME,#0	;CLEAR TOGGLE
	MOV	START_SAVE,#0	;TURN OFF MACHINE
	MOV	DPTR,#ZONE_TEMPS
	MOV	A,#96
INIT1:	MOVX	@DPTR,A
	INC	DPTR	;SET UP ZONE TEMPS
	INC	A
	INC	A
	CJNE	A,#116,INIT1 ;JUMP IF NOT DONE
	MOV	R0,#SET_POINT
	MOV	@R0,#100 ;SET POINT 100
	INC	R0
	MOV	@R0,#1	;SET POINT VAR=1
	MOV	R0,#BAR_CNTR
	CLR	A	;CLEAR BAR CNTR
	MOV	@R0,A
	MOV	R0,#BAR_PNTR
	MOV	@R0,A	;CLEAR BAR PNTR
	MOV	R0,#TEMP_PNTR
	MOV	@R0,A	;CLEAR TEMP PNTR

	MOV	DPTR,#JAM_IND
	MOV	A,#0FFH ;SET UP STATUS IND
	MOVX	@DPTR,A
	MOV	R0,#COLD_LEDS
	MOV	A,#0F0H	;SET UP COLD LEDS
	MOV	@R0,A
	CLR	A
	MOV	DISP_PTR,A ;CLEAR DISPLAY PNTR
	SETB	FLAGS1	;SET DISPLAY UPDATE
	CLR	FLAGS2	;CLEAR DISP PULSE
	RET


SWITCH_INIT:	MOV	R0,#SWITCH_COUNT;SET SWITCH COUNTS TO 0
	MOV	R1,#8		;SO ALL SWITCHES WILL SHOW
	CLR	A		;NEW VALUES INITIALLY
	CALL	CLRLP	;LOOP LOCATED AT END OF SWITCHREPORT
	CALL	SWITCH_READ	;GET SWITCH VALUES
	MOV	R0,#LOW UPDATE_FLGS
	MOV	R1,#8
	MOV	A,#0FFH
	CALL	CLRLP	;SET ALL UPDATE FLAGS	
	CALL	SWITCH_REPORT
	MOV	START_SAVE,#0	;TURN MACHINE OFF
	RET

SWITCH_REPORT:	MOV	A,UPDATE_FLGS
	ANL	A,#17H	;CHECK DIS,STRT,STOP,TEMP
	JNZ	CONTROL_FORM
	MOV	A,UPDATE_FLGS+3;CHECK CAL,NORM,EXER
	ANL	A,#0E0H
	JNZ	CONTROL_FORM
	JMP	DTFLGS
CONTROL_FORM:	MOV	B,#0;FORM CONTROL WORD
	MOV	A,SWITCH_VALUE
	CPL	A
	JB	ACC.0,CFJMP1
	SETB	B.2
CFJMP1:	JB	ACC.4,CFJMP2
	SETB	B.6
CFJMP2:	JB	ACC.1,NOSTART
	MOV	START_SAVE,#0FFH

NOSTART:	JB	ACC.2,NOSTOP
	MOV	START_SAVE,#0
NOSTOP:	MOV	A,START_SAVE
	CPL	A
	JB	ACC.0,NOSTARTBIT
	SETB	B.0
NOSTARTBIT:	MOV	A,SWITCH_VALUE+3
	ANL	A,#0C0H
	RR	A
	RR	A
	ORL	A,B
%WRITE (?CONTROLSFLAGS)
DTFLGS:	NOP
CLEAR_UPDATE_FLAGS:	MOV	R0,#LOW UPDATE_FLGS
	MOV	R1,#08
	CLR	A
CLRLP:	MOV	@R0,A
	INC	R0
	DJNZ	R1,CLRLP
	RET




	TMR_INITIATE: MOV  TMOD,#1H
	MOV	TH0,#0FCH	;SET TIMER TO 1MSEC
	MOV	TL0,#6BH
	MOV	TCON,#10H
	MOV	IE,#82H
	RET


JAM_LED: MOV	DPTR,#JAM_IND
	MOVX	A,@DPTR	;READ STAT WORD
	MOV	DPTR,#8701H
	MOVX	@DPTR,A	;WRITE TO LEDS
	RET

BAR_FORMAT: MOV	R0,#TEMP_PNTR
	MOV	A,#ZONE_TEMPS
	ADD	A,@R0
	MOV	DPL,A	;LOAD DPTR
	MOV	DPH,#0
	MOVX	A,@DPTR	;READ ZONE TEMP
	CLR	C
	SUBB	A,SET_POINT	;JUMP IF BELOW SET P
	JC	BARFM4

	MOV	B,SP_VAR	;LOAD SP VAR
	DIV	AB
	JZ	BARFM6	;JUMP IF IN TEMP
	ADD	A,#4
	MOV	R2,A	;ADD OFFSET
	ADD	A,#0F7H
	JC	BARFM3	;JUMP IF JUMO IF OVER
BARFM0:	MOV	A,R2
	CALL	CONVERT ;FIND BAR (NORMAL)
	MOV	R3,A
BARFM1:	MOV	A,@R0	;READ TEMP POINTER
	ADD	A,#BAR_DATA
	MOV	R1,A
	MOV	A,R3
	MOV	@R1,A	;WRITE BAR RESULT
	CALL	IN_TEMP_RE
	ORL	A,#3H	;CLEAR IN TEMP BARS
	CALL	IN_TEMP_SE

BARFM1A: MOV	A,@R0
	INC	A
	CJNE	A,#5,BARFM2 ;INCR PNTR
	CLR	A
BARFM2:	MOV	@R0,A
	RET

BARFM3: MOV	R2,#8H	;SET UPPER BAR
	JMP	BARFM0
BARFM4:	MOV	B,SP_VAR	;LOAD VARIATION
	CLR	C
	MOVX	A,@DPTR	;READ TEMP
	MOV	R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H
	MOV	A,BAR_CNTR
	ADD	A,#BAR_DATA
	MOV	R0,A
	MOV	A,@R0
	MOVX	@DPTR,A
	MOV	DPTR,#8704H
	MOV	A,BAR_CNTR
	MOVX	@DPTR,A
	CJNE	A,#6,BRDIS1
	CLR	A
	MOV	BAR_CNTR,A
	RET
BRDIS1: INC	BAR_CNTR
	RET

DISP_FORMAT: MOV	A,UPDATE_FLGS+5
	ANL	A,#0FH
	JZ	DISFM2	;JUMP IF NO MESS
	CLR	A
	MOV	UPDATE_FLGS+5,A ;CLEAR UPDATE
	MOV	A,SWITCH_VALUE+5
	ANL	A,#0FH
	RL	A	;MULT BY 2
	MOV	R3,A	;SAVE
	MOV	DPTR,#DISPLAY_TAB ;MOVE DIAG SW
	MOVC	A,@A+DPTR	;READ MASTER TAB
	MOV	R2,A
	INC	DPTR
	MOV	A,R3
	MOVC	A,@A+DPTR

	MOV	DPH,R2
	MOV	DPL,A	;LOAD MESS TABLE
	CLR	A
	MOV	P2,A
	MOV	P2STORE,A ;SET UP PNTR
	MOV	R0,#DISPLAY_OUT
	MOV	R3,#0

DISFM1:	MOV	A,R3
	MOVC	A,@A+DPTR ;READ TABLE
	MOVX	@R0,A	;WRITE BYTE
	INC	R0
	INC	R3
	MOV	A,R3
	CJNE	A,#8,DISFM1 ;JUMP IF NOT DONE
	SETB	FLAGS1	;SET DISPLAY FLG
DISFM2:	RET


DISPLAY_TAB: DW	MESS1
	DW	MESS2
	DW	MESS3
	DW	MESS4
	DW	MESS5
	DW	MESS6
	DW	MESS7
	DW	MESS8
	DW	MESS9
	DW	MESS10
	DW	MESS11
	DW	MESS12
	DW	MESS13
	DW	MESS14
	DW	MESS15
	DW	MESS16


MESS1:	DB	' A(TIVE '
MESS2:	DB	'L0(-0UT '
MESS3:	DB	'  PA0G  '
MESS4:	DB	' KI AON '
MESS5:	DB	'  0IAG  '
MESS6:	DB	'(AT 1 56'
MESS7:	DB	'(AT 2 12'
MESS8:	DB	'(AT 3  8'
MESS9:	DB	' 5  1550'
MESS10:	DB	'155 1470'
MESS11:	DB	' 80K155K'
MESS12:	DB	' 80G155K'
MESS13:	DB	' 80G155G'
MESS14:	DB	' 85  10 '
MESS15:	DB	'155  12 '
MESS16:	DB	'7256 FE '


DISP_OUT: JB	FLAGS1,DSPOUT1 ;JUMP IF DISPLAY UPDATE
	RET
DSPOUT1: MOV	A,DISP_PTR
	JZ	DSPOUT4
	JNB	FLAGS2,DSPOUT3 ;JUMP IF PULSE NOT SET
	MOV	A,#0FFH	;WRITE PULSE CLEAR
	MOV	DPTR,#8703H
	MOVX	@DPTR,A
	CLR	FLAGS2	;CLEAR PULSE FLG
	INC	DISP_PTR
	MOV	A,DISP_PTR
	CJNE	A,#9,DSPOUT2 ;JUMP IF NOT DONE
	CLR	A
	MOV	DISP_PTR,A ;CLEAR UPDATE FLG
	CLR	FLAGS1
DSPOUT2: RET

DSPOUT3: SETB	FLAGS2
	DEC	A
	ADD	A,#DISPLAY_OUT ;SET UP DATA PTR
	MOV	DPL,A
	MOV	DPH,#0
	MOVX	A,@DPTR	;READ CHAR
	MOV	DPTR,#8703H
	MOVX	@DPTR,A	;WRITE TO DISPLAY
	RET

DSPOUT4: JB	FLAGS2,DSPOUT5
	MOV	A,#0DH
	MOV	DPTR,#8703H ;WRITE CR
	MOVX	@DPTR,A
	SETB	FLAGS2	;SET PULSE
	RET
DSPOUT5: MOV	A,#0FFH
	MOV	DPTR,#8703H
	MOVX	@DPTR,A	;WRITE CLEAR TO DISP
	CLR	FLAGS2	;CLEAR PULSE FLG
	INC	DISP_PTR
	RET


SWITCH_READ: MOV	DPTR,#8702H
	MOV	SWITCH_CNTR,#00H ;CLEAR COUNTER
	MOV	R0,#PREV_READ
	MOV	INTL_DATA+1,#SWITCH_VALUE
	MOV	INTL_DATA+2,#SWITCH_COUNT
	MOV	INTL_DATA+3,#UPDATE_FLGS

SWRD1:	MOV	A,COLD_LEDS	;READ COLD LEDS
	ANL	A,#0F0H	;FORMAT
	ORL	A,SWITCH_CNTR	;OR IN SELECT
	MOVX	@DPTR,A
	CALL	WAIT	;WAIT FOR SWITCH
	MOVX	A,@DPTR ;READ SWITCH
	MOV	INTL_DATA,A	;SAVE
	MOV	A,@R0
	CJNE	A,INTL_DATA,SWRD3 ;JUMP IF SWITCH CHANGED

	MOV	R1,INTL_DATA+2
	MOV	A,@R1
	JNZ	SWRD6	;JUMP IF COUNTER NOT 0
	MOV	R1,INTL_DATA+1
	MOV	A,@R1
	CJNE	A,INTL_DATA,SWRD7 ;JUMP IF NEW NOT VALUE

SWRD2:	INC	R0
	INC	INTL_DATA+1	;SET UP NEXT
	INC	INTL_DATA+2
	INC	INTL_DATA+3
	INC	SWITCH_CNTR
	MOV	A,SWITCH_CNTR
	CJNE	A,#8H,SWRD1 ;JUMP IF NOT DONE
	RET

SWRD3:	MOV	R1,INTL_DATA+2
	MOV	A,SWITCH_CNTR
	JZ	SWRD4	;JUMP IF FAST SWITCH
	MOV	@R1,#0FFH;RESET SLOW COUNTER
	JMP	SWRD5
SWRD4:	MOV	@R1,#5H ;RESET FAST COUNTER
SWRD5:	MOV	A,INTL_DATA
	MOV	@R0,A	;UPDATE PREVIOUS READ
	JMP	SWRD2
SWRD6:	DEC	@R1
	JMP	SWRD2
SWRD7:	MOV	@R1,INTL_DATA	;MOVE READ TO VALUE
	XRL	A,INTL_DATA	;SET UPDATE FLAG
	MOV	R1,INTL_DATA+3
	MOV	@R1,A
	JMP	SWRD2



WAIT:	MOV	R2,#0FFH
WAIT1:	DJNZ	R2,WAIT1
	RET

TEMP_CHECK: MOV	A,SWITCH_VALUE
	JNB	ACC.4,TCHEK1 ;JUMP IF TEMP SEL ON
	CLR	A
	MOV	STARTF,A ;CLEAR START FLAG
	CPL	A
	MOV	BAR_DATA,A
	MOV	BAR_DATA+1,A
	MOV	BAR_DATA+2,A
	MOV	BAR_DATA+3,A
	MOV	BAR_DATA+4,A
	CLR	A
	MOV	BAR_DATA+5,A
	MOV	BAR_DATA+6,A
	MOV	DPTR,#ZONE_TEMPS
	MOV	A,#26
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A	;SET ALL TEMPS TO 26
	RET
TCHEK1:	MOV	A,#1
	MOV	STARTF,A ;SET START FLAG
	RET

SP_UPDATE: MOV A,SWITCH_VALUE+3
	ANL	A,#0FH	;AND OFF SP 10'S
	MOV	B,#10
	MUL	AB	;MULT NUMB BY 10
	MOV	R2,A
	MOV	A,SWITCH_VALUE+3
	JNB	ACC.4,SPUD1 ;JUMP IF 100'S NOT SET
	MOV	A,R2
	ADD	A,#100
	MOV	R2,A
SPUD1:	MOV	A,SWITCH_VALUE+7
	SWAP	A
	ANL	A,#0FH
	ADD	A,R2	;ADD IN UNITS
	MOV	SET_POINT,A
	MOV	A,SWITCH_VALUE+7
	ANL	A,#0FH
	JZ	SPUD2
	MOV	SP_VAR,A ;UPDATE SP VAR
	RET

SPUD2:	MOV	SP_VAR,#1
	RET


RATE_ADJ: MOV	DPTR,#RATE_VALUE
	MOV	R2,#5
RATER1: MOV	B,SWITCH_VALUE+6
	MOV	A,R2
	CALL	RATE_READ
	MUL	AB
	INC	A
	MOVX	@DPTR,A
	INC	DPTR
	DJNZ	R2,RATER1
	RET

RATE_READ: MOVC	A,@A+PC
	RET
	DB	2	;CH 5
	DB	6	;CH 4
	DB	4	;CH 3
	DB	3	;CH 2
	DB	5	;CH 1


TEMP_EX: MOV	R2,#0
	MOV	R5,#ZONE_TEMPS
	MOV	R6,#RATE_VALUE
	MOV	DPH,#0

TEMPX1:	MOV	DPL,R5
	MOVX	A,@DPTR
	MOV	R3,A
	CLR	C
	SUBB	A,SET_POINT
	JC	TEMPX3	;JUMP IF BELOW SP
	MOV	B,A
	MOV	DPL,R6
	MOVX	A,@DPTR	;READ RATE
	XCH	A,B
	DIV	AB
	JZ	TEMPX4	;JUMP IF NEAR SET POINT
	XCH	A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