;
; IEEE TEST PROGRAMM
;
R0 EQU 0000H ; I\O REG
R1 EQU 0001H ; INT1\STAT1
R2 EQU 0002H ; INT2\STAT2
R3 EQU 0003H ; SER.PO\SER.PO
R4 EQU 0004H ; ADDR STA\ADDR.MOD
R5 EQU 0005H ; COM.PA.TH\AUX.MOD
R6 EQU 0006H ; ADDR.0\ADDR.0/1
R7 EQU 0007H ; ADDR.1\EOS
ISL1 EQU 0038H ;INTRF.SELECT
ISL2 EQU 0040H ;INTF.SELECT
MYAD EQU 0008H ;READ MY ADDR.
;
; INITIALZATION
;
ORG 1000H
INIT:CALL ANF
JMP NG
JMP IDLE
ANF:MVI A,02H
OUT ISL1+R5
MVI A,0
OUT ISL1+R1 ;DISABLE INTERR.
OUT ISL1+R2 ;ENABLE DMA1,DISABLE DMA0
MVI A,33H
OUT ISL1+R4 ;SET LISTEN ONLY MODE
MVI A,4BH	;MY LISTENER ADDR.
STA ADFE
OUT ISL1+R6 ;MY ADDR.TO ADDR 0
MVI A,84H
OUT ISL1+R6	;DISABLE ADDR1
MVI A,0AH
OUT ISL1+R7 ;SET EOS CODE
MVI A,26H
OUT ISL1+R5 ;SET CLOCK FREQU.
MVI A,8CH
OUT ISL1+R5 ;SET AUX.MOD A
MVI A,0A4H
OUT ISL1+R5 ;SET AUX.MOD B
MVI A,6AH
OUT ISL1+R5 ;SET AUX.PP MOD.
XRA A ;CLEAR ACCU
STA KBY
STA STFE
OUT ISL1+R5
IN ISL1+R7
RET
JMP IDLE
SERE: MVI A,0
	STA KBY
	CALL DIMA
ERA:	CALL KEY
	LDA KBY
	CPI 03H
	JZ ERA
	JMP IDLE
NOP
;
DIMA:LXI H,SCH
MVI A,00H
OUT 28H
MOV A,L
OUT 20H
MOV A,H
OUT 20H
MVI A,0FFH
OUT 21H
MVI A,00H
OUT 21H
MVI A,0
OUT 2AH
MVI A,44H
OUT 2BH
STA KBY
RET
;
;
KEY:IN 41H ;IN STATUS
RAR
RNC
IN 40H
STA KBY
RET
KBY: DB 0
;
SYST:IN 13H
ANI 40H
CZ RSA
RET
;
;
IDLE:CALL KEY
LDA KBY
CPI 31H
CZ DISP
LDA KBY
CPI 32H
CZ IRT
LDA KBY
CPI 33H
CZ RSA
LDA KBY
CPI 03H
JZ 0000H
LDA KBY
CPI 34H
JZ INIT
LDA KBY
CPI 35H
JZ SERE
JMP IDLE
;
IRT:MVI C,02H
MVI E,1AH
CALL 5
RET
;
IN 13H ;READ SYSTEM STAT.
ANI 40H
JZ IRS
POP H
RET
RSA: PUSH H
IRS: LXI H,MSTA
IN ISL1+R1 ;STAT 1
MOV M,A
ANI 01H
CNZ IDA
INX H
IN ISL1+R2 ;STAT 2
MOV M,A
INX H
IN ISL1+R4 ;ADR STAT
NG: IN ISL1+R4
IN ISL1+R1
IN ISL1+R5
JMP NG
MOV M,A
INX H
IN ISL1+R5 ;COM.PASS.THR.
MOV M,A
INX H
IN ISL1+R6
MOV M,A
POP H
MVI A,00H
STA KBY
RET
VAL:MVI A,07H
OUT ISL1+R5
RET
;
STFE: DW 0
ADFE: DW 0
MSTA: DW 0
      DW 0
      DW 0
;
IDA:PUSH H
IN ISL1+R0
LXI D,RUFF
STAX D
CALL ANZ
POP H
RET
RUFF: DW 2400H
;
; SEND ROUTINE
;
SEND: CALL LIAD
IN ISL1+MYAD
ORI 40H
OUT ISL1+R0 ;SEND MY TALK ADDR.
CALL WAIT
MVI A,78H
OUT ISL1+R2
MVI A,10H ;STAND BY MODE
OUT ISL1+R5
JMP WAIT
;
; RECEIVE ROUTINE
;
RECV:CALL TAAD ;TALKER ADDR.
CALL UNLTN
MVI A,13H ;LTN CODE
OUT ISL1+R5
MVI A,1AH
UNLTN: MVI A,3FH
OUT ISL1+R0 ;UNLISTEN CODE
JMP WAIT
;
IFC: MVI A,1EH ;SET IFC CODE
OUT ISL1+R5
LXI B,0110H ;SET DELAY COUNTER 100 USEC
CALL WAITA
MVI A,16H
OUT ISL1+R5
RET
;
TAAD: MOV A,B ;TALKER ADDR.
ORI 40H ;FORM TALKER
OUT ISL1+R0
JMP WAIT
;
LIAD: MOV A,B ;LISTEN ADDR
ORI 20H ;FORM LISTENER
OUT ISL1+R0
JMP WAIT
;OUT ISL1+R5 ;TAKE COTROL SYNCH. ON END
MVI A,10H
OUT ISL1+R5 ;STANDBY
JMP WAIT
WAITA: DCR C
JNZ WAITA
MVI C,0FFH
DCR B
JNZ WAITA
RET
;
WAIT:IN ISL1+R1
ANI 0FFH ;EVENT 
JNZ WAIT
IN ISL1+R2
ANI 0FFH ;EVENT
JNZ WAIT
RET
;
; DISPLAY STATUS
;
S1CH: DB'CPT APT DET END DEC ERR DO  DI $'
S2CH: DB'INT SRQ LOK REM CO  LOC REC ADS $'
S3CH: DB'CIC ATN SPM LPA TPA LA  TA  MJM $'
S4CH: DB'CP7 CP6 CP5 CP4 CP3 CP2 CP1 CP0 $'
S5CH: DB' X  DTO DLO AD5 AD4 AD3 AD2 AD1 $'
;
DISP:MVI C,02H ;CURS HOME
MVI E,1AH
CALL 0005H
LXI D,S1CH
CALL DIS2
LXI H,MSTA
CALL DIS1
LXI D,S2CH
CALL DIS2
LXI H,MSTA+1
CALL DIS1
LXI D,S3CH
CALL DIS2
LXI H,MSTA+2
CALL DIS1
LXI D,S4CH
CALL DIS2
LXI H,MSTA+3
CALL DIS1
LXI D,S5CH
CALL DIS2
LXI H,MSTA+4
CALL DIS1
XRA A
STA KBY
RET
DIS1: LXI D,SCH
CALL STAT
CALL CRLF
RET
DIS2: CALL ANZ
CALL CRLF
RET
;
SCH: DB'    $'
;
STAT: MVI B,08H
STA1: MOV A,M
RAL
MOV M,A
CC STA2
CNC STA3
CALL ANZ
DCR B
JNZ STA1
RET
STA2: MVI A,31H
STA SCH+1
RET
STA3: MVI A,30H
STA SCH+1
RET
ANZ: PUSH H
PUSH B
PUSH D
MVI C,09H
CALL 0005H
POP D
POP B
POP H
RET
CRLF: MVI C,02H
MVI E,0AH
CALL 0005H
MVI C,02H
MVI E,0DH
CALL 0005H
RET
; END
