DataMuseum.dk

Presents historical artifacts from the history of:

RC3500

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about RC3500

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦29ef805a4⟧ Bits:30001846 Debug-source til ROA640, 8-hole paper tape, TextFileEvenParity

    Length: 53590 (0xd156)
    Description: Bits:30001846 Debug-source til ROA640
    Types: 8-hole paper tape, TextFileEvenParity

TextFileEvenParity



; 1981.05.06    RC3502 DEBUGGER.          KNEH.
; LOG: DEBUG 039 - BJ -
; 
;
; DATE: 1981-05-06
;
; LISTING :   RCSL 52-AA 1046
; SOURCE TAPE : RCSL 52-AA 1047
; ROM NO. :     ROA  640
;

; DEBUG CONSOLE PROGRAM TO RC3502 MINICOMPUTER.
; 1981.01.22 KNEH	VER0004.

; DEBUG COMMANDS:
; --------------
; R 		RUN.
; C             INSTRUCTION STEP ON CURRENT LEVEL
; C<ANTAL STEP> 
; S		INSTRUCTION STEP.
; S<ANTAL STEP>	
; L<LEVEL>      MODIFY LEVEL REGISTER.
; M<MODUL><ADDR>MODIFY MEMORY.
; W<REG-ADDR>	MODIFY W-REG.
; Y<ADDR>	MODIFY MICROPROCESSOR RAM
; <ESC>       TERMINATE CURRENT COMMAND.
;
.TITLE DBU35

; DEBUG MODE SWITCH SET TABLE.
; SWITCH STATE
; 0 , 8		300BPS	RUN TEST	LOOP
; 1 , 9		1200BPS	RUN TEST	LOOP
; 2 , A		300BPS	SKIP TEST	
; 3,  B		1200BPS	SKIP TEST	
; 4 , C		300BPS	RUN TEST	NO LOOP
; 5 , D		1200BPS	RUN TEST	NO LOOP
; 6 , E		300BPS	SKIP TEST	
; 7 , F		1200BPS	SKIP TEST	
;
; SWITCH STATE 8-F SAME AS 0-7 BUT WITH BLOCKED
; TERMINAL MODE( BELL WILL NOT SWITCH TO DEBUG ).

; RUN TEST     MEANS THAT THE BUILT-IN TEST ROUTINES AL-
;              WAYS ARE EXECUTED AFTER PUSHING AUTOLOAD.

; SKIP TEST    THE BUILT-IN TEST ROUTINES ARE SKIPPED.

; LOOP         THE BUILT IN TEST FOREVER.

; NO LOOP      EXECUTE 1 PASS.


; TERMINAL MODE:
;	1 START - 8 DATA - NO PARITY - 1 STOP
\f


; OUTPUT INFIRMATION ON THE OPERATOR CONSOLE IF THE
; BUILT-IN TEST DETECT AN ERROR.

;  1  8085 COMMUNICATION TEST.
;     OUTPUT:  ERR 1  <DUMMY>  <DUMMY>
;              Y<5D>  GIVES 6 XMT DATA
;              Y<70>  GIVES 6 BYTES RECEIVED DATA


;  3  COMMUNICATION TEST
;     L REQUEST TO M
;     OBS !!!!! NO CONSOLE OUTPUT
;     ONLY ON LAMPS

;  5  WORKING ADDRESS REGISTER TEST.
;     OUTPUT:  ERR 5  <ADDRESS>  <WANTED DATA>
;              W<ADDRESS> GIVES READ DATA.

;  7  WORKING REGISTER DATA TEST.
;     OUTPUT:  ERR 7  <ADDRESS>  <WANTED DATA>

;  9  MEMORY ADDRESS TEST.
;     OUTPUT:  ERR 9  <OFFSET ADDRESS>  <WANTED DATA>
;              Y<40>  GIVES THE MEMORY MODULE NUMBER.
;              M<MODULE:OFFSET> GIVES READ DATA.

;  B  MEMORY DATA TEST. PATTERN: 5555
;     OUTPUT:  ERR B  <OFFSET ADDRESS>  <WANTED DATA>
;              Y<40>  GIVES THE MEMORY MODULE NUMBER.
;              M<MODULE,OFFSET> GIVES READ DATA.

;  D  MEMORY DATA TEST. PATTERN: AAAA
;     OUTPUT:  ERR D  <OFFSET ADDRESS>  <WANTED DATA>
;              Y<40>  GIVES THE MEMORY MODULE NUMBER.
;              M<MODULE,OFFSET> GIVES READ DATA.

;      RUN CONTROL
;      THE EXECUTION OF THE BUILT-IN TEST IS CONTROLLED 
;      BY THE MODE SWITCH ON THE FRONT PANEL OF CPU201.
;      THE BUILT-IN CAN BE SKIPPED OR EXECUTED ONCE .
;      OR LOOP FOREVER DURING EXECUTION THE "TM" LAMP IS 
;      LIT.
;      THE 4 LAMPS (TM-LP-RP-OP) GIVES THE TEST PROGRAM 
;      NUMBER.
;
\f

;		DEBUG RAM LAYOUT
;
;	00:	RTC ITR-LEVEL
;	01:	TTO/WRITE RAM LEVEL
;	02:	TTI LEVEL
;	03:	TIMER LSB
;	04:	TIMER MSB
;	05:	WATCH DOG LSB
;	06:	WATCH DOG MSB
;	07:	TTI INPUT
;	08:	TTO OUTPUT
;	09:	MICRO PROGRAM VERSION NUMBER
;	0A:	SWITCH MIRROR 0-7
;	0B:	SWITCH MIRROR 8-15
;	0C:	  I/O LEVEL	0-7
;	0D:		"	8-15
;	0E:		"	16-23
;	0F:		"	24-31
;	10:		"	32-39
;	11:		"	40-47
;	12:		"	48-55
;	13:		"	56-63
;	14:		"	64-71
;	15:		"	72-79
;	16:		"	80-87
;	17:		"	88-95
;	18:		"	96-103
;	19:		"	104-111
;	1A:		"	112-119
;	1B:		"	120-127
;	1C:	RAM CONFIGURATION 0-7
;	1D:	 "        "       8-15
;	1E:	PROM      "       0-7
;	1F:	 "        "       8-15
.RDXO 16
.RDX 16
;	M <----> L COMMUNICATIONS CODES

AUCOM= 35	; AUTOLOAD
CONCOM= 10	; SET LEVEL (CONSOLE)
GLCOM= 37	; GET LEVEL
GMCOM= 3B	; GET MEM
GRCOM= 3F	; GET REG
INILA= 37	; INIT LAMDA
PMCOM= 39	; PUT MEM
PRCOM= 3D	; PUT REG
RACOM= 31	; WRITE DATA TO L VIA FIFO
RDCOM= 30	; READ COMM M TO L (FIFO)
ROFF= 34	; REGEISTER OFFSET (TABLE)
RUNB= 80	; CS7 (RUN COMM.)
SECUR= 3C	; SINGLE STEP ON CURR LEVEL
SEXEC= 38	; SINGLE STEP
TIMCM= 20	; SET LEVEL TIMER
TSCOM= 3E	; TEST COMM
TSLEV= 36	; TEST LEVEL COMM.
TTICOM= 0	; CONSOLE ITR
WREQC= 33	; L REQUEST



\f


; MICROPROCESSOR HARDWARE CONFIGURATION.
;
; ADDR. 0-	FFF	PROM MEMORY.
; ADDR. 4000-	40FF	RAM MEMORY.

; I/O DEVICES:
; 40	8155 COMMAND/STATUS.
; 41	8155 A-PORT.
; 42	8155 B-PORT.
; 43	8155 C-PORT.
; 44	8155 LOW ORDER TIMER.
; 45	8155 HIGH ORDER TIMER.
; OUT 0	CLEAR MREQ.
; OUT 10 SET MREQ.
; OUT 30 OUTPUT-REG TO L
; IN  20 INPUT-REG FROM L

RAMB=	4000
COMMX=	40
PORTA=	COMMX+1
PORTB=	COMMX+2
PORTC=	COMMX+3
TIML=	COMMX+4
TIMH=	COMMX+5
CDO=	30
CDI=	20
CREQ=	0
SREQ=	10

SCR=	10
SPINIT=	4100
COMA=	3E	; A=INPUT,B-C=OUTPUT.
TIMLI=	80
TIMHI=	2+0C0
IMASK=	0D8
REGSP=	1
\f

	.LOC	4000
TIMLV:	0		; TIMER LEVEL.
TTOLV:	0
TTILV:	0
TIMOUT:	DWC.	0
WADOG:	DWC.	0	; WATCHDOG. BIT7=0 ENABLE WATCHDOG.
DTIN:	0
DATOUT:	0
VERNO:	0		; MICRO PROGRAM NUMBER
SWITCH:	DWC.	0

	.LOC	403E
TIMCOUMT: DWC.	0	; TIMER COUNT DOWN
RCAB:	0		; MODULE NUMBER UNDER TEST.
BRATE:	0		; BAUD RATE. 0=> 300, 1=> 1200
BCOUNT:	0
	0
COMM:	0		; DEBUG COMMAND.
	DWC.	0	; ADD.
	DWC.	0	; DATA0.
	DWC.	0	; DATA1.
	DWC.	0	; DATA2.
	DWC.	0	; DATA3.
	DWC.	0	; DATA4.
	DWC.	0	; DATA5.
	DWC.	0	; DATA6.
	DWC.	0	; DATA7.
INBUF:	DWC.	0
	DWC.	0
	DWC.	0
MBUF:	DWC.	0
	DWC.	0	; TRANSFER BUFFER TO RC3502.
	DWC.	0
MBASE:	DWC.	0
LSAV:	DWC.	0	; SAVE LEVEL.
POINT:	0
	0
	0
CHSAV:	0
BASA:	DWC.	0
BSAV:	0
ITRCOM:	0		; =1 WANTED 7.5 REQUEST.
SETCOM:	0	; =1 TIMER/CONSOLE LEVEL REQUEST.
ABUF:	DWC.	0
	DWC.	0
	DWC.	0
DBUF:	DWC.	0
FCOM:	0		; TTY INPUT <NEW>
SCOM:	0		; TTY INPUT <OLD>
CSUPD:	0		; SWITCH UPDATE 0 => UPDATE
TIMCX:	0
TSCONT:	DWC.	0	; TEST CONSTANT.
WPATT:	DWC.	0	; WANTED PATTERN.
RPATT:	DWC.	0	; READ PATTERN.
PASSC:	0
UPDAT:	0		; UPDATE MASK.

XOUTDELAY:	0
OUTPASE:	0
INDELAY:	0
INPASE:	0
XOUTCHAR:	0
INCBUF:	0
XINCHAR:	0
CHARRDY:	0
BHALF:	0
DOHALF:	0
ITEST:	0
TTESX:	0
XAUTO:	0

NUMBER:	0
\f

;	CONSTANTS

BELL= 07
BSPACE= 08
CR= 0D
CURR= 20
HOME= 1D
KTS02= 0502
KTS03= 0703
KTS04= 0904
KTS05= 0B05
KTS09= 0D05
LF= 0A
MXLEV= 7F	; MAX LEVEL 127
RAML= 40
ROMCH= 0AA
SSTRT= 80
STOPB= 0C0
STRT= 40
SW0= 10
SW1= 20
TAB= 09
TITRC= 0008	; ITR FREQUENCY APP 20 MS
TSMON= 5555
TSMIN= 0AAAA
US= 1F
XCR= 60
XSPACE= 20
ZEZE= 3030
ESC= 1B	; ESCAPE VALUE.
\f

	.RDX	8
	.LOC	0
	JMP	INIT
TTYTXT:	CR	; BUSTIMER
	LF
	"T
	CR
	LF
	0
DBTXT:	CR
	LF
	"D
	0
INITX:	HOME	; RC350
	US
	"R
	"C
	"3
	"5
	"0
	0
INITY:	40	; DEBUG VER0
	"M
	"I
	"C
	"R
	"O
	40
	"V
	"E
	"R
	"0
	0
CRTXT:	CR	; CR
      LF
	0
	.LOC	44
	JMP	TRAP
TXTC:	CR	; *
	LF
	"*
	0
ERRTXT: CR	; ERR
	LF
	"E
	"R
	"R
	0
CONTB:	200
	100
	40
	20
	10
	4
	2
	1
	.LOC	74
	JMP	INT75
\f

; FUNCTION: CI.
; INPUTS: NONE.
; CALLS: FBIT,HBIT.
; DESTROY'S: A,F/F'S.
; DESCRIPTION: CI WAITS UNTIL A CHARACTER HAS BEEN
; ENTERED AT THE DEBUG TERMINAL AND THEN RETURNS THE
; CHARACTER,VIA THE A REGISTER,TO THE CALLING ROUTINE.

CI:	PUSH	H	; SAVE HL.
CI01:	LXI	H,CHARRDY
	MOV	A,M
	ORA	A
	JZ	CI02	; CHARACTER NOT READY.
	MVI	M,0
	DCX	H
	MOV	A,M
	ANI	177
	POP	H
	RET
CI02:	LXI	H,ITEST
	MOV	A,M
	ORA	A
	JNZ	ABORT
	INX	H
	MOV	A,M
	ORA	A
	CZ	ITRBE
	INX	H
	MOV	A,M
	ORA	A
	JNZ	CI01
ABORT:	XRA	A
	POP	H
	RET

ITRBE:	PUSH	HL
	PUSH	DE
	PUSH	BC
	CALL	TIMITR
	POP	BC
	POP	DE
	POP	HL
	RET
\f

; FUNCTION: CO.
; INPUTS: C-CHARACTER TO OUTPUT TO TTY.
; OUTPUTS: C-CHARACTER TO OUTPUT TO TTY.
; CALLS: FBIT.
; DESTROY'S: A,F/F'S.
; DESCRIPTION: CO SEND ITS INPUT ARGUMENT TO THE TTY.


CO:	LDA	TTESX
	ORA	A
	CZ	ITRBE
   	LDA	OUTPASE
	ORA	A
	JNZ	CO	; JUMP IF NOT READY TO SEND.
	MOV	A,C
	ORI	200
	STA	XOUTCHAR
	MVI	A,2
	STA	OUTPASE
	RET

BETJEN:	LDA	XAUTO
	PUSH	B
	PUSH	D
	ORA	A
	CZ	AUTOL
	LDA	TTESX
	ORA	A
	CZ	TIMITR
	LDA	ITEST
	ORA	A
	CNZ	WRREQ
	POP	D
	POP	B
	RET
\f

; FUNCTION: CNVBN.
; INPUTS: C-ASCII CHARACTER '0'-'9','A'-'F'.
; OUTPUTS: A- 0-F.
; DESTROY'S: A,F/F'S.
; DESCRIPTION: CNVBN CONVERTS THE ASCII REPRESENTATION OF
; A HEX NUMBER INTO ITS CORRESPONDING BINARY VALUE.

CNVBN:	MOV	A,C
	SUI	"0	; SUBTRACT "0" FROM ARGUMENT.
	CPI	10.	; TEST RESULT FOR 0-9.
	RM		; IF SO ALL DONE.
	SUI	7
	RET

; FUNCTION: PRVAL.
; INPUTS: A-INTEGER,RANGE 0-F.
; OUTPUTS: A AND C-ASCII CHARACTER.
; DESCRIPTION: PRVAL CONVERTS A NUMBER IN THE RANGE 0-F.
; HEX TO THE CORRESPONDING ASCII CHARACTER,0-9,A-F.
; PRVAL DOES NOT CHECK THE VALIDITY OF ITS INPUT ARGUMENT.

PRVAL:	ANI	17
	CPI	10.	; ARGUMENT IN RANGE 0-9 ?
	JC	LESS	; YES
	SUI	1
	ANI	7
	ADI	100	; ADD ACSII BASE+16.
	MOV	C,A
	RET

LESS:	ADI	60	; ADD ASCII BASE
	MOV	C,A
	RET

; FUNCTION: VALDG.
; INPUTS: C-ASCII CHARACTER.
; OUTPUTS: CARRY-1 IF CHAR REPRESENTS VALID HEX DIGIT.
;               -0 OTHERWISE.
; DESCRIPTION: VALDG RETURNS SUCCESS IF ITS INPUT ARGUMENT
; IS AN ASCII CHARACTER REPRESENTING A VALID HEX 
; DIGIT (0-9,A-F), AND FAILURE OTHERWISE.

VALDG:	MOV	A,C
	CPI	"0	; TEST CHAR AGAINST "0.
	JM	FRET	; IF ASCII CODE LESS,CANNOT BE
			; VALID DIGIT.
	CPI	"9	; ELSE SEE IF IN RANGE "0-"9.
	JM	SRET	; CODE BETWWEEN "0 AND "9.
	JZ	SRET	; CODE EQUALS "9.
	CPI	"A	; TRY "A LETTER.
	JM	FRET	; CODE BETWEEN "9 AND "A.
	CPI	"G
	JM	SRET
FRET:	STC
	CMC		; ZERO TO CARRY
	RET
SRET:	STC		; ONE TO CARRY
	RET
\f

; PROCEDURE TO CALCULATE MICROPROCESSOR RAM ADDRESS.
; INPUT: (COMM-1)= OFFSET
;        (COMM+1)= BASE ADDRESS
; OUTPUT: HL= (OFFSET+BASE ADDRESS)&(3F)+4000.

MRAMC:	LXI	H,COMM-1
	PUSH	D
	PUSH	PSW
	MOV	E,M	; GET OFFSET
	MVI	D,0
	LHLD	COMM+1	; RELATIV ADDR
	DAD	D	; ADD OFFSET
	LXI	D,RAMB	; RAM BASE
	DAD	D	; ADD OFFSET
	POP	PSW
	POP	D
	RET

; ROUTINE TO OUTPUT 2SPACES TO TTY TERMINAL.

DSPACE:	MVI	C,XSPACE
	CALL	CO
	JMP	CO

; ROUTINE TO OUTPUT A SEQUENCE: CR-LF-*.

DCLEAR:	CALL	OTXT
	DWC.	TXTC
	RET

; ROUTINE TO MOVE THE CURSOR RIGHT THE NUMBER OF
; POSITIONS SPECIFIED IN A.

CRIGHT:	PUSH	B
	MOV	B,A	; B=COUNT.
CRLOP:  MVI	C,CURR
	CALL	CO	; OUTPUT CURSOR RIGHT
	DCR	B	; MORE STEPS ?
	JNZ	CRLOP	; YES
	POP	B
	RET
\f


; PROCEDURE TO OUTPUT A STRING OF CHARACTERS.
; CALLED BY CALL OTXT
;                DWC. <STRING ADDRESS>.
; THE TXT STRING SHOULD BE TERMINATED BY 0.

OTXT:	POP	H
	PUSH	H	; HL= TXT ADDRESS
	MOV	E,M
	INX	H
	MOV	D,M
	XCHG
OTX02:	MOV	C,M
	MOV	A,C
	CPI	0	; TEXT FINISH ?
	JZ	OTX01	; YES
	CALL	CO	; NO
	INX	H
	JMP	OTX02

OTX01:	POP	H
	INX	H	; RESTORE STACKP.
	INX	H
	PUSH	H
	RET

; ROUTINE TO OUTPUT CR.

CRCUR:	CALL	OTXT
	DWC.	CRTXT
	RET

; ROUTINE TO CONVERT THE 4 ASCII CHARS IN INBUF
; TO A 16 BITS INTEGER PLACED IN HL.

CINBF:	LXI	H,INBUF	; HL=BUFFER POINTER.
	MOV	C,M
	CALL	SPCONV	; CONVERT 1 TO BINARY.
	MOV	D,A	; SAVE LEFT PART IN D
	INX	H
	MOV	C,M
	CALL	CNVBN	; CONVERT 2 TO BINARY
	ADD	D	; ADD LEFT PART
	MOV	D,A	; SAVE 1-2 DIGIT I D
	INX	H
	MOV	C,M
	CALL	SPCONV	; CONVERT 3 TO BINARY
	MOV	E,A	; SAVE LEFT PART IN E
	INX	H
	MOV	C,M
	CALL	CNVBN	; CONVERT 4 TO BINARY
	ADD	E	; ADD LEFT PART
	MOV	E,A	; SAVE 3-4 DIGIT IN E
	XCHG
	RET
\f

; ROUTINE TO PUT DE INTO DATAX
; USING (COMM-1) AS OFFSET.

SVDE:	LXI	H,COMM+3 ; FIRST DATA.
	LDA	COMM-1
	RAL		; TABLE MODULUS 2
	ANI	376
	MOV	C,A
	MVI	B,0	; BC=OFFSET IN TABLE
	DAD	B
	MOV	M,E	; SAVE LSB
	INX	H
	MOV	M,D	; SAVE MSB
	RET

; ROUTINE TO OUTPUT THE CONTENTS OF DE TO THE TTY.

LOUTDE:	XCHG
OUTDE:	MOV	A,D
	PUSH	B
	CALL	SPRIGHT
	CALL	PRVAL	; HEX TO ASCII.
	CALL	CO	; OUTPUT 1'ST CHAR
	MOV	A,D
	CALL	PRVAL	; HEX TO ASCII
	CALL	CO	; OUTPUT 2'D CHAR
	MOV	A,E
	CALL	SPRIGHT
	CALL	PRVAL	; HEX TO ASCII
	CALL	CO	; OUTPUT 3'TH CHAR
	MOV	A,E
	CALL	PRVAL	; HEX TO ASCII
	CALL	CO	; OUTPUT 4'TH CHAR
	POP	B
	RET
\f

; ROUTINE TO INPUT MAX 4HEX DIGIT TO CURRENT DATX.
; IF INPUT=SPACE THEN TAKE OLD DIGIT IN DATX.
; IF INPUT=BACKSPACE THEN TAKE OLD.
; IF INPUT=(CR,+,-) THEN TERMINATE THE COMMAND.
DATIN:	XRA	A
	STA	INBUF+4	; RESET DIGIT POINTER.
DAT03:	CALL	GETDI	; :C = ASCII DIGIT
	LXI	H,INBUF+4
	MOV	E,M	; DIGIT POINTER
	MVI	D,0
	LXI	H,INBUF
	DAD	D
	MOV	M,C	; STORE ASCII CHAR
	LXI	H,INBUF+4
	INR	M	; IMCR. DIGIT POINTER
	MOV	A,M
	CPI	4	; NEXT GROUP ?
	JNZ	DAT03	; NO
	MVI	A,3
	STA	INBUF+4 ; 3 TO DIGIT POINTER
	LDA	POINT+2
	ORA	A
	JNZ	DAT01
	XRA	A
	STA	INBUF+4
DAT01:	XRA	A
	STA	POINT+2
	CALL	CI	; WAIT TTY INPUT
	MOV	C,A
	CPI	CR
	JZ	CREND	; CR <TERMINATION>
	CPI	"+
	JZ	PLUSE	; + NEXT 8 GROUP
	CPI	"-
	JZ	MINUS	; - PREVIOUS 8 GROUP
	CPI	ESC
	JZ	CANCEL ; BACK SPACE
	CPI	TAB
	JZ	NTAB	; TABULATION
	CPI	XSPACE
	JZ	SPACE	; SPACE
	CALL	VALDG	; TEST FOR HEX DIGIT.
	JNC	DAT01	; NO VALID DIGIT
	CALL	CO	; ECHO DIGIT
	CALL	FUPDAT
DAT02:	LXI	H,INBUF+4
	MOV	E,M	; FETCH DIGIT POINTER
	MVI	D,0
	LXI	H,INBUF
	DAD	D	; ADD BASE
	MOV	M,C	; SAVE CHAR.
DAT40:	LXI	H,INBUF+4
	INR	M	; INCR. DIGIT POINTER
	MOV	A,M
	CPI	4	; LAST IN 4 GROUP ?
	JZ	NEND	; YES
	JMP	DAT01
\f


SPACE:	MVI	C,CURR	;
	CALL	CO	; STEP CURSOR RIGHT
	JMP	DAT40
CREND:	POP	H
	LXI	D,2	; INCRM. TO RETURN ADDR LCR
	DAD	D
XEND:	MOV	E,M	; FETCH LSB RETURN ADDR
	INX	H
	MOV	D,M	; FETCH MSB RETURN ADDR
	PUSH	D
	JMP	UPBUF

PLUSE:	POP	H
	LXI	D,4
	DAD	D	; INCRM. TO RETURN ADDR LPLUS
	JMP	XEND
MINUS:	POP	H
	LXI	D,6
	DAD	D	; INCRM. TO RETURN ADDR LMINUS
	JMP	XEND
NEND:	POP	H
	LXI	D,10
	DAD	D	; INCRM. TO RETURN ADDR DSPACE
	PUSH	H
	JMP	UPBUF
\f

; ROUTINE TO GET THE DIGIT INTO C DEFINED BY
; ADDRESS OFFSET IN (COMM-1)
; AND DIGIT POINTER IN (INBUF+4).

GETDI:	LXI	H,COMM-1
	MOV	A,M	; GET ADDRESS OFFSET.
	MVI	D,0
	RAL		; 2 BYTE TABLE SPACE
	ANI	376
	MOV	E,A	; :DE
	LXI	H,COMM+3
	DAD	D	; :HL POINT TO DATA(X).
	LDA	INBUF+4
	MOV	B,A	; SAVE DIGIT POINTER.
	RAR		; 2 BYTE EACH DATA(X)
	XRI	1
	MOV	E,A
	DAD	D	; :HL POINT OUT THE BYTE
	MOV	E,M	; FETCH BYTE (2 CHAR)
	MOV	A,B	; RELOAD DIGIT POINTER
	ANI	1	; IS IT LEFT PART ?
	JZ	LEFT	; YES
	MOV	A,E
RIGHT:	JMP	PRVAL	; HEX TO ASCII

LEFT:	MOV	A,E
	CALL	SPRIGTH
	JMP	PRVAL

; ROUTINE TO UPDATE INBUF AFTER TERMINATION AND STORE
; INBUF INTO DATX.

UPBUF:	   	     
UPYES:	CALL	CINBF	; CONVERT INBUF TO BINARY
	XCHG
	JMP	SVDE	; SAVE IT IN DATA(X)

MCALCA:	PUSH	D
	LHLD	COMM+1	; MEM OFFSET
	LDA	COMM-1
	ADD	A	; MODULUS 2
	MVI	D,0
	MOV	E,A
	DAD	D	; OFFSET (TOTAL)
	POP	D
	RET		; HL= ADDRESS.
\f


; ROUTINE TO SAVE DAT0-7 INTO RC3502/3 MEMORY.

MSTORE:	XRA	A
	STA	COMM-1	; RESET ADDRESS COUNTER.
	MVI	A,8.
	STA	BSAV	; NUMBER OF REG
MM10:	LDA	COMM-1	; ADDRESS COUNT.
	RAL		; TABLE MODULUS 2
	ANI	16
	MVI	D,0
	MOV	E,A
	LXI	H,COMM+3
	DAD	D	; :HL= ADDR IN DATA(X)
	MOV	E,M
	INX	H
	MOV	D,M	; DE=DATA.
	CALL	MCALCA	; HL=ADDRESS.
	SHLD	ABUF+2	; ADDR TO ABUF+2
	XCHG
	SHLD	DBUF	; DATA TO DBUF
	XCHG
	LDA	UPDAT	; FETCH UPDAT
	RAL		; ANY CHANGE ?
	STA	UPDAT
	JNC	ML10	; NO
	CALL	PMEM	; YES - WRITE NEW CONTENTS IN MEM
ML10:	CALL	INCCM
	JNZ	MM10
	RET

; ROUTINE TO OUTPUT THE CONTENTS OF A AS
; TWO HEX DIGITS.

CHEX:	PUSH	PSW
	CALL	SPRIGHT	; FETCH LEFT PART
	CALL	PRVAL	; HEX TO ASCII
	CALL	CO
	POP	PSW
	CALL	PRVAL	; HEX TO ASCII
	JMP	CO
\f

; ROUTINE TO TAKE THE CONTENTS OF
; INBUF,INBUF+1 AND STORE THE VALUE INTO THE
; MICROPROCESSOR RAM.

RCONV:	LDA	INBUF
	MOV	C,A
	CALL	SPCONV	; ASCII TO HEX+SHIFT LEFT <4
	MOV	E,A	; SAVE LEFT PART
	LDA	INBUF+1
	MOV	C,A
	CALL	CNVBN	; ACSII TO HEX
	ANI	17
	ADD	E	; ADD LEFT + RIGHT
	CALL	MRAMC
	MOV	M,A	; STORE RESULT
	RET

; ROUTINE TO STORE INTO MICROPROCESSOR RAM.

NSTORE:	MOV	A,B
	CPI	2	; IS RAM ALREADY STORED ?
	RZ		; YES RETURN
	ORA	A
	JZ	RCONV	; YES STORE LAST GROUP

VAL1:	LDA	INBUF	; FETCH FIRST DIGIT
	MOV	C,A
	CALL	SPCONV	; ASCII TO HEX+SHIFT LEFT <4
	MOV	C,A
	CALL	MRAMC
	MOV	A,M
	ANI	17
	ADD	C	; ADD 2'D DIGIT
	MOV	M,A	; STORE
	RET

; ROUTINE TO CALCULATE ADDRESS AS
; (COMM-1)+(COMM+1)-->HL.

CALCA:	PUSH	D
	LHLD	COMM+1	; HL=ADDRESS BASE.
	LDA	COMM-1	; GET OFFSET.
	MVI	D,0
	MOV	E,A
	DAD	D
	POP	D	; HL=OFFSET + BASE.
	RET

; ROUTINE TO INCREMENT THE CONTENTS OF (COMM-1) AND
; DECREMENT THE CONTENTS OF BSAV.

INCCM:	LXI	H,COMM-1
	INR	M	; INCRM. RELATIV NUMBER
	LXI	H,BSAV
	DCR	M	; DECRM. NUMBER LEFT
	RET
\f

; ROUTINE TO STORE DAT0-7 INTO RC3502/3 W-REG.

LSTORE:	XRA	A
	STA	COMM-1	; RESET W-REG OFFSET.
	MVI	A,8.
	STA	BSAV
LST10:	LDA	COMM-1
	RAL
	ANI	16
	MVI	D,0
	MOV	E,A
	LXI	H,COMM+3 ; BASE ADDR TO BUFFER DATAX
	DAD	D
	MOV	E,M	; 
	INX	H	;
	MOV	D,M	;
	CALL	RALCA	; :HL= :DATA(X)
	SHLD	ABUF	; STORE REG ADDR IN ABUF
	XCHG
	SHLD	DBUF	; STORE DATA IN DBUF
	LDA	UPDAT
	RAL
	STA	UPDAT
	JNC	LSI10
	CALL	PREG	; PUT REG TO L
LSI10:	CALL	INCCM	; INCR. :COMM-1, DECR. :BSAV
	JNZ	LST10
	RET

; UPDATE CURSOR AFTER TERMINATION.

TERMC:	CALL	CRCUR
	MVI	A,4
	JMP	CRIGHT
\f

; READ AND MODIFY MICROPROCESSOR RAM.
; ADDRESS IN MICROPROCESSOR 4000+0 - 4000+3F.

RMICRO:	CALL	DCLEAR	; INIT SCREEN.
	MVI	C,"Y
	CALL	CO	; OUTPUT COMMAND CODE.
	CALL	DSPACE
	MVI	B,2	; NUMBER OF ADDRESS DIGITS.
	LXI	H,ZEZE	; 2 X ZERO TO INBUFF
	SHLD	INBUF
	LXI	D,INBUF+2
RR01:	CALL	CI
	MOV	C,A
	CPI	ESC
	JZ	PCANCEL
	CALL	VALDG	; TEST IF VALID HEX CHAR?
	JNC	RR01
	CALL	CO	; ECHO CHAR.
	MOV	A,C
	STAX	D	; SAVE ADDREESS DIGIT.
	INX	D
	DCR	B
	JNZ	RR01	; GET NEXT ADDRESS DIGIT.
	CALL	CINBF	; HL=ADDRESS
	SHLD	COMM+1
RC01:	XRA	A
	STA	COMM-1	; RESET ADDRESS COUNT.
	MVI	A,8.	; NUMBER OF LISTED LOCATIONS.
	STA	BSAV
RR02:	CALL	CALCA
	CALL	DSPACE
	LXI	D,RAMB	; RAM BASE
	DAD	D	; ADD OFFSET
	MOV	A,M	; FETCH BYTE	
	CALL	CHEX	; SPLIT TO 2 HEX DIGIT AND OUTPUT
	CALL	INCCM	; INCR. ADDR DECR. NUMBER
	JNZ	RR02	; GET NEXT ADDRESS.



\f

; MODIFY MICRORAM. THE CURSOR IS RETURNED 
; TO THE FIRST DIGIT IN FIRST LOCATIONS.

RR20:	CALL	CRCUR
	MVI	A,8.
	CALL	CRIGHT	; MOVE RIGHT CURSOR 7 POSITIONS.
	XRA	A
	STA	COMM-1	; RESET ADDRESS OFFSET.
	MVI	A,8.
	STA	BSAV
RR05:	LXI	D,INBUF
	MVI	B,2
RR03:	CALL	CI	; INPUT CHAR.
	MOV	C,A	; SAVE INPUT
	CPI	CR
	JZ	CRMIC	; CR <TERMINATION>
	CPI	ESC
	JZ	PCANCEL
	CPI	"+
	JZ	NPLUS	; + NEXT 8 LOCATIONS
	CPI	"-
	JZ	NMINUS	; - PREVIOUS 8 LOCATIONS
	CPI	XSPACE
	JZ	NSPACE	; SPACE
	CALL	VALDG
	JNC	RR03	; NO VALID COMMAND/DIGIT
	CALL	CO	; ECHO DIGIT
	MOV	A,C
	STAX	D	; STORE IN BUFFER
RR08:	INX	D
     	DCR	B
	JNZ	RR03	; GET NEXT DIGIT
	CALL	RCONV
	CALL	DSPACE	; OUTPUT SPACE
	CALL	INCCM	; INCR. ADDR DECR. NUMBER
	JNZ	RR05	; JUMP IF NOT LAST GROUP
	MVI	B,2
RR06:	CALL	CI	; INPUT CHAR
	CPI	CR
	JZ	CRMIC	; CR <TERMINATION>
	CPI	ESC
	JZ	PCANCEL
	CPI	"+
	JZ	NPLUS	; + NEXT 8 GROUP
	CPI	"-
	JZ	NMINUS	; - PREVIOUS 8 GROUP
	JMP	RR06	; NO VALID COMMAND
\f

CRMIC:	CALL	NSTORE	; STORE LAST GROUP IF NECESS.
	LXI	H,RAMB+0
	MOV	A,M	; FETCH TIMER LEVEL
	CALL	READR	; TRANSFER TO L
	LXI	H,TTOLV
	MOV	A,M	; FETCH TTY OUT
	CALL	READR	; TRANSFER TO L
	JMP	FORTOL
NSPACE:	CALL	MRAMC	; CALCULATE RAM ADDR
	MOV	A,B
	CPI	2	; IS CURSOR UNDER FIRST DIGIT ?
	JZ	FIRST	; YES
	MOV	A,M	; NO - UNDER 2'D ?
	CALL	PRVAL	; HEX TO ASCII
	STA	INBUF+1 ; STORE DIGIT IN BUFF
	JMP	ESPACE
FIRST:	MOV	A,M	; FETCH FIRST DIGIT
	CALL	SPRIGHT
	CALL	PRVAL	; HEX TO ASCII
	STA	INBUF
ESPACE:	MVI	C,CURR	; CURSOR RIGHT
	CALL	CO
	JMP	RR08
NPLUS:	CALL	NSTORE	; STORE LAST GROUP IF NECESS.
	LXI	D,8.
	LHLD	COMM+1
	DAD	D	; +8 TO RELATIV ADDR
	SHLD	COMM+1
PLUSX:	PUSH	H
	CALL	TERMC	; CURSOR BACK TO ADDR POSITION
	POP	H
	MOV	A,L
	CALL	CHEX	; OUTPUT NEW ADDR
	JMP	RC01
NMINUS:	CALL	NSTORE	; STORE LAST GROUP IF NECESS.
	LXI	D,-8.
	LHLD	COMM+1
	DAD	D	; -8 FROM RELATIV ADDR
	MVI	H,0
	SHLD	COMM+1	; ZERO TO OFFSET
	JMP	PLUSX

\f

; INITIALIZATION.

INIT:	LXI	SP,SPINIT
	OUT	CREQ	; CLEAR CR F/F
	MVI	A,COMA
	OUT	COMMX	; INIT 8155
	IN	PORTA	; GET MODE SWITCH
	ANI	1
	LXI	H,BHALF
	JNZ	B300
	MVI	M,1.
	INX	H
	MVI	M,3.
	JMP	ENDBR
B300:	MVI	M,7.
	INX	H
	MVI	M,15.
ENDBR:	MVI	A,TIMLI
	OUT	TIML
	MVI	A,TIMHI ; LOAD TIMER
	OUT	TIMH
	MVI	A,COMA+300
	OUT	COMMX	; START TIMER
	MVI	A,INILA ; INIT LAMDA COMM (GET LEVEL)
	OUT	PORTB
	OUT	SREQ	; SET CR F/F
	MVI	A,IMASK
	SIM		; SET 8085 ITR MASK
	LXI	H,0
	SHLD	WADOG	; RESET WATCH DOG
	SHLD	TIMOUT	; RESET TIME OUT
	SHLD	RAMB+28.
	SHLD	RAMB+30.
	SHLD	SWITCH	; ZERO TO SWITCH MIRROR
	SHLD	XOUTDELAY
	SHLD	INDELAY
	SHLD	MBASE	; ZERO TO MODUL BASE
	XRA	A
	STA	ITEST	; RESET 7.5 MARK
	DCR	A	; :A= -1
	STA	XAUTO	; RESET AUTOLOAD MARK
	STA	TTESX
	MVI	B,100
	EI
INI10:	MVI	C,-1.
	CALL	CO
	DCR	B
	JNZ	INI10
	CALL	WAIT	; WAIT UNTILL CR IS CLEARED
	CALL	VERSION ; OUTPUT  CPU VERSION NUMBER
	MVI	A,1
	STA	TIMLV	; SET TIMER LEVEL=1.
	XRA	A
	STA	RAMB+3	; SET CONSOLE LEVEL=0.
	STA	POINT+2
	STA	TIMCX	; RESET AUX TIMER
	CALL	MEMCO	; CONFIGURATE MEM (RAM) 0-15
	CALL	PROCON	; CONFIGURATE MEM (PROM) 0-15
	CALL	IOCON	; CONFIGURATE I/O LEVEL 0-127
	IN	PORTA	; READ MODE SWITCH
	ANI	2	; BUILT-IN TEST WANTED ?
	JZ	TSRET	; NO
	JMP	TS00	; YES
TSRET:	MVI	A,AUCOM
	CALL	XCOM
	MVI	A,-1.
	STA	XAUTO
	LXI	H,TITRC	; INTR INTERVAL FOR TIMER.
	SHLD	TIMOUT	; LOAD TIME CONST.
	SHLD	TIMCOUNT ; LOAD TIME-ITR CONST.
	CALL	RESWH	; UPDATE SWITCHES.
 	CALL	UPCOPY	; UPDATE L'S DEBUG IMAGE
	CALL	DCLEAR	; WRITE * ON THE SCREEN
	XRA	A
	STA	FCOM
	CALL	SLAMP	; SWITCH OFF LAMPS
\f

	LXI	H,300
	SHLD	MBASE	; ZERO TO MODUL-BASE
	CALL	GMEM
 	CALL	SRUN	; SET RUN.
	JMP	MODSH
XFORTOL: CALL	DCLEAR	; WRITE * ON THE SCREEN
XXH:	CALL	CI	; FETCH INPUT CHAR
	ORA	A	; IS IT BREAK ?
	JZ	ZZH	; YES
	CPI	CR	; IS IT CR ?
	JZ	OLDCOM	; YES
	STA	FCOM	; SAVE COMMAND
YYH:	CPI	"Y
	JZ	RMICRO	; MODIFY MICRO RAM
	CPI	"W
	JZ	RLEVEL	; MODIFY LEVEL-REG
	CPI	"L
	JZ	RLEVEL	; MODIFY W-REG
	CPI	"M
	JZ	MMODF	; MODIFY MEM
	CPI	BELL
	JZ	MODSH	; TTY MODE SHIFT
	CPI	"C
	JZ	CSTEP	; SINGLE INSTRUCTION-CURR
	CPI	"S
	JZ	SSTEP	; SINGLE INSTRUCTION.
	CPI	CR
	JZ	OLDCOM	; REPEAT LAST COMMAND
	CPI	"R
	JZ	XSRUN	; RUN
ZZH: 	CALL	RESWH	; UPDATE SWITCHES
	CALL	BETJEN
	JMP	XXH
FORTOL:	LDA	FCOM
	STA	SCOM	; LAST COMM SAVE
	CALL	RESWH	; UPDATE SWITCHES
	JMP	XFORTOL
OLDCOM:	CALL	RESWH	; UPDATE SWITCHES
	LDA	SCOM	; FETCH OLD COMMAND
	CPI	"C	; IS IT "C ?
	JZ	OLDCS	; YES
	CPI	"S	; IS IT "S ?
	JNZ	YYH	; NO
OLDCS:	CALL	STERM	;
	JMP	SST02	;

XSRUN:	CALL	SRUN
	JMP	FORTOL

\f

; 7.5 INTERRUPT.
; WHEN A 7.5 INTERRUPT OCCURS THIS ROUTINE 
; SET (ITEST):=-1.

INT75:	PUSH	H
	PUSH	PSW
	LXI	H,ITEST
	DCR	M	; (ITEST):=-1
	POP	PSW
	POP	H
	EI
	RET

BLSET:	CALL	DSPACE	; SPACE
	MVI	B,2	; NUMBER OF DIGIT IN COMM
	LXI	D,INBUF+2
	JMP	RL30

\f

; MODIFY REGISTER DEBUG COMMAND.
; CALL RWRITE HL= LEVEL,CODE<6+REGISTER NO.; DE=DATA.
; CALL RREAD  HL= LEVEL,CODE<6+REGISTER NO..
; RETURN: DE=DATE.

RLEVEL:	CALL	DCLEAR	; INIT SCREEN FORMAT.
	XRA	A
	STA	UPDAT	; ZERO TO UPDAT
	LDA	FCOM	; FETCH COMM. L OR W
	MOV	C,A	; 
	CALL	CO	; OUTPUT COMMAND.
	CALL	DSPACE
	LDA	FCOM
	CPI	"L	; IS IT LEVEL REG
	JZ	BLSET	; YES
	MVI	C,CURR
	CALL	CO
	MVI	B,3	; MUNBER OF DIGITS IN COMM.
	LXI	D,INBUF+1
RL30:	LXI	H,ZEZE	; 2 ASCII LEADING ZERO
	SHLD	INBUF
RL01:	CALL	CI	; INPUT CHAR.
	MOV	C,A
	CPI	ESC
	JZ	PCANCEL
	CALL	VALDG	; TEST IF VALID HEX
	JNC	RL01
	CALL	CO	; ECHO CHAR.
	MOV	A,C
	STAX	D	; SAVE LEVEL DIGIT.
	INX	D
	DCR	B	
	JNZ	RL01	; GET NEXT DIGIT.
	CALL	CINBF	; HL=LEVEL NO.
	SHLD	LSAV	; SAVE IN LEVEL SAVE
	LDA	FCOM
	CPI	"W	; IS IT A W-COMM. ?
	JZ	RL31	; YES
	MOV	A,L	; MOVE LEVEL NUMBER TO A
	CALL	LCONV	; GET REG-OFFSET FROM L
RL31:	SHLD	COMM+1	; SAVE ANSWER
RL05:	XRA	A
	STA	COMM-1	; RESET W-REG COUNTER.
	MVI	A,8.
	STA	BSAV	; SAVE NUMBER OF W-REG'S.
RL02:	CALL	RALCA	; CALCUL. ABSOLUTE ADDR IN ARRAY
	SHLD	ABUF
	CALL	GREG	; FETCH CONTENTS OF REG
	XCHG
	LHLD	DBUF	; GET RESULT FROM IN BUFF
	XCHG		; RESULT IN DE
	CALL	SVDE	; SAVE ANSWER I DATAX
	CALL	DSPACE	; OUTPUT SPACE
	CALL	OUTDE	; OUTPUT ANSWER
	CALL	INCCM	; INCR. OFFSET,DECR NO. OF W-REG'S.
	JNZ	RL02
	CALL	CRCUR	; CR
	MVI	A,10.
	CALL	CRIGHT	; MOVE CURSOR 8 POS. RIGHT.
	XRA	A
	STA	COMM-1	; RESET W-REG OFFSET.
	MVI	A,8.
	STA	BSAV	; SET W-REG COUNTER.
\f

RL03:	CALL	DATIN	; MODIFY DIGIT.
	DWC.	PCANCEL	; BACK SPACE
   	DWC.	LCR	; CR TERMINATE.
	DWC.	LPLUS	; PLUS TERMINATE.
	DWC.	LMINUS	; MINIUS TERMINATE.
	CALL	DSPACE
	CALL	INCCM
	JNZ	RL03
RL04:	CALL	CI	; INPUT	CHAR.
	CPI	CR
	JZ	LCR	; CR TERMINATE.
	CPI	ESC
	JZ	PCANCEL
	CPI	"+
	JZ	LPLUS	; + TERMINATE.
	CPI	"-
	JZ	LMINUS	; - TERMINATE.
	JMP	RL04
LCR:	CALL	LSTORE	; UPDATE REGISTERS.
	JMP	FORTOL
LPLUS:	CALL	LSTORE	; STORE W-REG IN L
	LDA	FCOM
	CPI	"W	; WAS IT AN W-COMM ?
	JZ	RL32	; YES
	LDA	LSAV
	INR	A	; INCR. LEVEL NUMBER
RL34:	ANI	177
	STA	LSAV	; STORE NEW LEVEL NUMBER
	CALL	LCONV	; GET REG-OFFSET FROM L
	SHLD	COMM+1	; SAVE OFFSET
	CALL	TERMC	; MOVE CURSOR >4
	CALL	DSPACE	; OUTPUT SP-SP
	LDA	LSAV
	CALL	CHEX	; OUTPUT NEW LEVEL NUMBER
	JMP	RL05
RL32:	LHLD	COMM+1	; GET CURRENT W-BASE.
	LXI	D,10
	DAD	D	; ADD 8.
RL06:	MOV	A,H
	ANI	7	; MASK FOR MAX REG ADDR
	MOV	H,A
	SHLD	COMM+1	; STORE NEW W-BASE
	CALL	TERMC	; MOVE CURSOR >4
	LHLD	COMM+1
	CALL	LOUTDE	; OUTPUT NEW W-BASE
	JMP	RL05	;
LMINUS:	CALL	LSTORE	; STORE W-REG IN L
	LDA	FCOM
	CPI	"W	; WAS IT AN W-COMM ?
	JZ	RL33	; YES
	LDA	LSAV
	DCR	A	; DECR. LEVEL
	JMP	RL34
RL33:	LHLD	COMM+1
	LXI	D,-8.
	DAD	D	; DECR. W-BASE
	JMP	RL06
\f


; READ AND MODIFY MEMORY COMMAND.
; CALL MREAD HL=ADDRESS, RETURN: DE=DATA.
; CALL MWRITE HL=ADDRESS,DE=DATA.

MMODF:	CALL	DCLEAR	; INIT SCREEN FORMAT.
	XRA	A
	STA	UPDAT
	MVI	C,"M
	CALL	CO	; ECHO COMMAND.
	CALL	DSPACE
	MVI	B,4	; NUMBER OF DIGIT IN BASE
	LXI	D,INBUF
MX10:	CALL	CI
	CPI	":	; : (USE OLD BASE)
	JZ	MM11
	CPI	ESC
	JZ	PCANCEL
	MOV	C,A
	CALL	VALDG	; VALID DIGIT ?
	JNC	MX10	; NO
	CALL	CO	; ECHO DIGIT
	MOV	A,C
	STAX	D
	INX	D
	DCR	B
	JNZ	MX10	; GET NEXT BASE ADDRESS CIFFER.
	CALL	CINBF	; HL= BASE
	SHLD	ABUF
	SHLD	MBASE	; SAVE IN M(EM)BASE
MM11:	CALL	TERMC	; CURSOR BACK TO FIRST POSITION
	LHLD	MBASE
	XCHG
	CALL	OUTDE	; OUTPUT BASE
	MVI	C,":
	CALL	CO	; OUTPUT :
	MVI	B,4	; B=NUMBER OF OFFSET 
	LXI	D,INBUF
MM01:	CALL	CI	; INPUT CHAR.
	MOV	C,A
	CPI	ESC
	JZ	PCANCEL
	CALL	VALDG	; TEST IF HEX?
	JNC	MM01
	CALL	CO	; ECHO CHAR.
	MOV	A,C
	STAX	D
	INX	D
	DCR	B
	JNZ	MM01	; GET NEXT ADDRESS CIFFER.
	CALL	CINBF	; CONVERT OFFSET (HL)
	SHLD	COMM+1
MM05:	XRA	A
	STA	COMM-1	; RESET ADDRESS COUNTER.
	MVI	A,8.	; NUMBER OF MEMORY LOCATIONS.
	STA	BSAV
MM02:	CALL	MCALCA	; :HL OFFSET (TOTAL)
	SHLD	ABUF+2	; SAVE OFFSET
	XCHG
	CALL	GMEM	; GET MEMORY CONTENTS
	XCHG
	LHLD	DBUF
	XCHG
	CALL	SVDE	; SAVE ANSWER IN DATA(X)
	CALL	DSPACE	; SP - SP
	CALL	OUTDE	; OUTPUT CHARACTER
	CALL	INCCM	; INCR. OFFSET, DECR. NO OF MEM LOCA.
	JNZ	MM02	; GET NEXT ADDRESS.
\f


; MODIFY MEMORY. THE CURSOR IS RETURNED TO THE FIRST
; DIGIT IN FIRST ADDRESS.

 	CALL	CRCUR	; CURSOR BACK
	MVI	A,10.+5
	CALL	CRIGHT	; MOVE CURSOR 10 POS RIGHT.
	MVI	A,8.
	STA	BSAV	; +8 TO DISPLAY LOCATIONS
	XRA	A
	STA	COMM-1	; RESET ADDRESS OFFSET.
MM03:	CALL	DATIN	; MODIFY CONTENTS.
	DWC.	PCANCEL	; BACK SPACE
	DWC.	MCR	; CR TERMINATE.
	DWC.	MPLUS	; + TERMINATE.
	DWC.	MMINUS	; - TERMINATE.
	CALL	DSPACE
	CALL	INCCM
	JNZ	MM03
MM04:	CALL	CI	; INPUT CHARACTER
	CPI	CR
	JZ	MCR	; CR TERMINATE.
	CPI	ESC
	JZ	PCANCEL
	CPI	"+
	JZ	MPLUS	; + TERMINATE.
	CPI	"-
	JZ	MMINUS	; MINUS TERMINATE.
	JMP	MM04
MCR:	CALL	MSTORE	; DATA(X) TO MEM IF NECESS.
	JMP	FORTOL
MPLUS:	CALL	MSTORE	; DATA(X) TO MEM IF NECESS.
	LXI	D,16.
	LHLD	COMM+1
	DAD	D	; INCR. OFFSET TO NEXT 8 GROUP
MM06:	SHLD	COMM+1
	CALL	TERMC	; CURSOR BACK
	LHLD	MBASE
	CALL	LOUTDE	; OUTPUT BASE
	MVI	C,":
	CALL	CO	; OUTPUT :
	LHLD	COMM+1
	CALL	LOUTDE	; OUTPUT NEW OFFSET ADDR
	JMP	MM05

MMINUS:	CALL	MSTORE	; DATA(X) TO MEM IF NECESS.
	LXI	D,-16.
	LHLD	COMM+1
	DAD	D	; DECR. OFFSET TO PREVIOUS 8 GR
	JMP	MM06

\f

; PROCEDURE WAIT.
; LOOP UNTILL >CR=1.

WAIT:	PUSH	PSW
WAIT1:	IN	PORTA	; READ CR F/F
	ANI	XCR	;
	CPI	XCR	; IS F/F CLEARED ?
	JNZ	WAIT1	; NO
	POP	PSW
	RET

; PROCEDURE TO SET CS(COMMAND SELECT).
; CALL<SMICC>;A:=CS(6:0);

SMICC:	PUSH	PSW
	PUSH	B
	ANI	177
	MOV	B,A
	IN	PORTB
	ANI	200	; CLEAR ALL EXCEPT RUN
	ADD	B	; ADD COMMAND
	OUT	PORTB
	POP	B
	POP	PSW
	RET

; PROCEDURE TO OUTPUT A NUMBER OF BYTES FROM M(MICRO-
; PROCESSOR) TO L(LAMDA).
; CALL<OUTCHAR>; A(6:0)=NUMBER OF BYTES; HL=BUFFER POINTER;

OUTCHAR: PUSH	PSW
	PUSH	H
	PUSH	B
	MOV	B,A	; B=COUNT.
OUTLP:	MOV	A,M
	OUT	CDI	; PREPARE BYTE FOR L (FIFO)
	MVI	A,RDCOM	; SET READ COMM.
	CALL	XCOM
	INX	H
	DCR	B	; FINISH ?
	JNZ	OUTLP	; NO
	POP	B	; YES
	POP	H
	POP	PSW
	RET

; PROCEDURE TO INPUT A NUMBER OF BYTES FROM L(LAMDA) TO 
; M(MICROPROCESSOR).
; CALL(INCHAR); A=NUMBER OG BYTES;HL=BUFFER START POINTER;

INCHAR:	PUSH	PSW
	PUSH	H
	PUSH	B
	MOV	B,A	; B=COUNT
INTLP:	MVI	A,RDCOM	; READ COMM. TO L
	CALL	XCOM	; WAIT ANSWER
	IN	CDO	; READ ANSWER FROM FIFO
	MOV	M,A	; SAVE IN BUFFER
	INX	H
	DCR	B	; FINISH ?
	JNZ	INTLP	; NO
	POP	B	; YES
	POP	H
	POP	PSW
	RET
\f

; PROCEDURE SEND.
; CALL <SEND>
; DWC. PARAM
; PARAM: 2 BYTES BUFFER POINTER
;        NUMBER OF BYTES.
; DESTROY HL,DE.

SEND:	POP	H	; NEXT ADDRESS.
	MOV	E,M
	INX	H
	MOV	D,M	; DE=PARAM ADDRESS.
	INX	H
	PUSH	H	; RESTORE STACKP.
	LDAX	D
	MOV	L,A
	INX	D
	LDAX	D
	MOV	H,A	; HL=BUFFER POINTER.
	INX	D
	LDAX	D	; NUMBER OF BYTES
	JMP	OUTCHAR	; SEND BLOCK TO L


; PROCEDURE RECEIVE.
; CALL <RECEIVE>
; DWC. PARAM
; PARAM: 2 BYTES BUFFER POINTER
;        NUMBER OF BYTES.

RECEIVE: POP	H
	MOV	E,M
	INX	H
	MOV	D,M	; DE=PARAM ADDRESS.
	INX	H
	PUSH	H	; RESTORE STACKP.
	LDAX	D
	MOV	L,A
	INX	D
	LDAX	D
	MOV	H,A	; :HL BUFFER POINTER
	INX	D
	LDAX	D	; NUMBER OF BYTES
	JMP	INCHAR	; READ CHARACTER
\f

; ADDRESS PARAM BLOCK.
PADDR:	DWC.	ABUF
	4
; DATA PARAM BLOCK.
PDATA:	DWC.	DBUF
	2
; SINGLE PARAM BLOCK.
SDATA:	DWC.	DBUF
	1
AREG:	DWC.	ABUF
	1
RREG:	DWC.	ABUF
	2
TOUT:	DWC.	MBUF
	6
TIND:	DWC.	ABUF
	6

; PROCEDURE "GET MEM".
; TRANSFER A WORD FROM L-MEM TO .
; CALL: ABUF=ADDRESS
; RETURN: DBUF=DATA

GMEM:	LHLD	MBASE	; MEM BASE
	MOV	A,L
	ANI	376
	MOV	L,A
	SHLD	ABUF
	CALL	SEND	; ADDR PARM BLOCK (4) ABUF
	DWC.	PADDR
	MVI	A,GMCOM	; LOAD GET MEM COMM.
	CALL	XCOM
	CALL	RECEIVE ; RECEIVE ANSWER
	DWC.	PDATA
	RET

; PROCEDURE XCOM. SEND COMMAND

XCOM:	CALL	SMICC	; SEND COMM TO L
	OUT	SCR	; ITR TO L
	CALL	WAIT	; WAIT ANSWER
	MVI	A,GLCOM	; LOAD GET LEVEL COMM.
	JMP	SMICC	; SEND COMM TO L

; PROCEDURE "PUT MEM"
; TRANSFER A WORD FROM M TO L-MEM.

PMEM:	LHLD	MBASE
	MOV	A,L
	ANI	376
	MOV	L,A
	SHLD	ABUF
	CALL	SEND	; ADDR PARM BLOCK (4) ABUF
	DWC.	PADDR
	CALL	SEND	; DATA PARM BLOCK (2) DBUF
	DWC.	PDATA
	MVI	A,PMCOM	; LOAD PUT MEM COMM
	JMP	XCOM	; SEND COMM TO L
\f

; PROCEDURE "GET REG"
; TRANSFER A WORD FROM L-REG TO M.

GREG:	CALL	SEND	; ADDR PARAM. BLOCK (2) ABUF
	DWC.	RREG
	MVI	A,GRCOM
	CALL	XCOM	; READ COMMAND TO L
	CALL	RECEIVE
	DWC.	PDATA	; RECEIVE ANSWER IN DBUF
	RET

; PROCEDURE "PUT REG"
; TRANSFER A WORD FROM M TO L-REG.

PREG:	CALL	SEND
	DWC.	RREG
	CALL	SEND
	DWC.	PDATA
	MVI	A,PRCOM
	JMP	XCOM

; PROCEDURE TO TRANSFER A M-RAM ADDR +M:RAM BYTE 
; FROM M TO L.
; CALL: HL=ADDR; A=DATA.

READR:	PUSH	B
	PUSH	PSW
	MOV	A,L
	OUT	CDI	; OUTPUT LSB ADDR
	MVI	A,RDCOM
	CALL	XCOM	; INPUT TO FIFO
	POP	PSW
	OUT	CDI	; OUTPUT DATA
	MVI	A,RDCOM
	CALL	XCOM	; INPUT TO FIFO
	MVI	A,RACOM
	CALL	XCOM	; WRITE INTO L-IMAGE
	POP	B
	RET

; TIMER INTERRUPT.
; COMMAND L TO SET LEVEL SPECIFIED IN MEM(COPY+0).

TIMITR:	MVI	A,TIMCM
	CALL	XCOM	; SEND TIMER ITR TO L
	MVI	A,-1.
	STA	TTESX	; RESET TIMER MARK
	RET
\f

; AUTOLOAD.
; START LEVEL 127 IN FIRST BYTE OF FIRST PROM.

AUTOL:	CALL	SSTOP
	MVI	A,AUCOM
	CALL	XCOM	; SEND AUTOLOAD REQ TO L
	MVI	A,-1.
	STA	XAUTO	; RESET AUTOLOAD MARK
	JMP	SRUN

; REQUEST CODES FROM L TO M.
; FETCH THE REQUEST CODE INITIATED BY A 7.5 INTERRUPT.

WRREQ:	XRA	A
	STA	ITEST	; RESET ITR MARK
	MVI	A,WREQC
	CALL	XCOM	; SEND ITR ACKN.
	IN	CDO	; READ COMM FROM L
	MOV	B,A	; SAVE COMM IN B
	ANI	300
	CPI	200	; IS IT WRITE COMM ?
	JZ	WRBYTE	; YES
	CPI	100	; IS IT READ COMM ?
	JZ	XMRR	; YES
	RET
XMRR:	MOV	A,B
	ANI	77	; IS IT ERROR ?
	JZ	UPCOPY	; NO
	JMP	MEMERR



.DO	.PASS
.MSG	I'M RUNNING APP. 4 MIN LEFT
.ENDC
\f

; WRITE BYTE. L REQUESTS M TO WRITE A BYTE IN RAM
; :CS2-7 = ADDR.   FIFO = DATA.

WRBYTE:	MOV	A,B	; FETCH SAVED BYTE
	ANI	77	; MASK COMMAND AWAY
	MOV	L,A	; RELATIV ADDR
	MVI	H,0
	LXI	D,RAMB
	DAD	D	; ADD RAM BASE
	MVI	A,RDCOM
	CALL	XCOM
	IN	CDO	; READ DATA (FIFO)
	MOV	M,A	; STORE BYTE IN RAM
	MOV	A,L
	CPI	8.	; WAS IT RAM CELL 8. ?
	JNZ	CONITR	; NO 
	MOV	C,M	; FETCH CHARACTER
	CALL	CO	; OUTPUT CHARACTER
CONITR:	MVI	A,CONCOM
	JMP	XCOM	; SEND CONSOLE ITR

; UPDATE COPY.

UPCOPY:	MVI	B,RAML	; NUMBER OF BYTES TO L
	LXI	H,RAMB
NUPA:	MOV	A,M
	CALL	READR	; MOVE BYTE TO L
	INX	H
	DCR	B	; FINISH ?
	JNZ	NUPA	; NO
	RET		; YES

RALCA:	PUSH	D
	LHLD	COMM+1	; LOAD RELATIV REG NUMBER
	LXI	D,REGSP ; REG SPACE IN ARRAY
	LDA	COMM-1	; OFFSET IN BUFFER
	ORA	A	; FIRST ?
	JZ	RALED	; YES
RALCP:	DAD	D	; ADD BASE + X TIMES OFFSET
	DCR	A
	JNZ	RALCP
RALED:	POP	D
	RET
\f


; ROUTINE TO GET CURRENT LEVEL
; AND PRINT W0-W7 BELONGING TO THIS LEVEL.

RCURR:	CALL	SSTOP	; STOP CPU
	PUSH	PSW	; SAVE LEVEL
	MVI	H,0
	MOV	L,A
	SHLD	ABUF	; STORE LEVEL IN ABUF
	CALL	LOUTDE	; OUTPUT LEVEL NUMBER
	MVI	A,8.
	STA	BSAV
	POP	PSW
	PUSH	PSW
	CALL	LCONV	; GET OFFSET FROM TABLE
	SHLD	ABUF
XEG01:	CALL	DSPACE
	CALL	GREG	; GET REGISTER
	LHLD	DBUF
	CALL	LOUTDE	; OUTPUT CONTENTS
	LXI	D,REGSP
	LHLD	ABUF
	DAD	D	; ADD LEVEL+OFFSET
	SHLD	ABUF	; NEW BASE
	LXI	H,BSAV
	DCR	M	; DECR. DISPLAYED NUMBER
	JNZ	XEG01	; FINISH
	POP	PSW
	RET

; ROUTINE TO SET RUN MODE.
SRUN:	MVI	A,RUNB+GLCOM
	OUT	PORTB	; RUN + GET LEVEL COMM
	LDA	CHSAV
	ORI	8.
	CALL	SLAMP	; SWITCH ON RUN-LAMP
	OUT	SCR	; REQUEST L
	CALL	WAIT	; WAIT ACCEPT ON STARTED
	MVI	C,"R
	JMP	CO	; WRITE "R" ON THE SCREEN

; ROUTINE TO SET STOP MODE.
SSTOP:	MVI	A,GLCOM ; REMOVE RUN CONDITION
	OUT	PORTB
	LDA	CHSAV
	ANI	27
	CALL	SLAMP	; SWITCH OFF RUN LAMP
	OUT	SCR	; REQUEST L
	CALL	WAIT	; WAIT ACCEPT ON STOPPED
	IN	CDO	; READ LEVEL
	RET

STERM:	LDA	POINT
	MOV	C,A
	CALL	CO	; OUTPUT BUFF CHAR.
	JMP	DSPACE	; OUTPUT SP-SP
\f

; EXECUTE SINGLE INSTRUCTION.

SSTEP:	MVI	A,"S
	STA	POINT	; "S TO OUTPUT BUFF
	MVI	A,SEXEC
SST03:	STA	POINT+1 ; SINGLE STEP COMM
	CALL	STERM	; OUTPUT "S OR "C + SP-SP
	CALL	GVALU	; GET NUMBER OF STEPS (OPERATOR)
     	SHLD	MBUF
SST02:	LDA	POINT+1
	CALL	XCOM	; SEND COMMAND TO L
	CALL	RCURR
	LHLD	MBUF	; NUMBER OF STEPS
	MOV	A,H
	ORA	L	; FINISH
	JZ	FORTOL
	DCX	H	; DECR. NUMBER OF STEPS
	SHLD	MBUF
	CALL	DCLEAR
	CALL	STERM	; OUTPUT "S OR "C + SP-SP
	JMP	SST02

; EXECUTE ON CURRENT LEVEL.

CSTEP:	MVI	A,"C
	STA	POINT	; "C TO OUTPUT BUFF
	MVI	A,SECUR ; CURRENT STEP COMM	
	JMP	SST03

SUBSW:	MOV	C,A
	ANI	17
	MOV	D,A	; :D = 2-1-8-4
	ANI	3
	RLC
	RLC
	MOV	E,A
	MOV	A,D
	RRC
	RRC
	ADD	E	; :A = 8-4-2-1
	CALL	SPCO1
	MOV	H,A	; SAVE LEFT PART
	MOV	A,C
	CALL	SPRIGHT
	MOV	D,A	; :D = 1-8-2-4
	RAR
	MOV	C,A
	RAR
	MOV	E,A
	ANI	1
	MOV	B,A	; :B = *-*-*-8
	MOV	A,D
	RAR
	MOV	A,B
	RAL
\f

	MOV	B,A	; :B = *-*-8-4
	MOV	A,C
	RAR
	MOV	A,B
	RAL
	MOV	B,A	; :B = *-8-4-2
	MOV	A,E
	RAR
	RAR
	MOV	A,B
	RAL		; :A = 8-4-2-1
	ADD	H	; ADD LEFT PART
	MOV	D,A	; RESULT I D
	RET

; ROUTINE TO READ SWITCHES 0-3
; IF ANY CHANGE IN RELATION TO LAST READ
; THE MEW SWITCH PICTURE IS SEND TO L

RESWH:	IN	SW0	; READ SWITCH 0 AND 1
	CALL	SUBSW	; CONVERT SWITCH
	LDA	SWITCH
	CMP	D
	MVI	A,0
	STA	CSUPD	; ZERO TO SW UPDATE
	JZ	NEXTW	; NO UPDATE
	MVI	A,-1.
	STA	CSUPD	; ALL ONES TO SW CHANGE
	MOV	A,D
	STA	SWITCH	; STORE NEW SWITCH P.
NEXTW:	IN	SW1	; READ SWITCH 2 AND 3
	CALL	SUBSW	; CONVERT SWITCH
	LDA	SWITCH+1
	CMP	D
	JZ	SWDATE	; NO CHANGE
	MVI	A,-1.
	STA	CSUPD	; ALL ONES TO SW UPDATE
	MOV	A,D
	STA	SWITCH+1 ; STORE NEW SWITCH P.
SWDATE:	LDA	CSUPD	; FETCH SW UPDATE
	CPI	0	; ANY CHANGE AT ALL ?
	RZ		; NO
	LXI	H,SWITCH
	MOV	A,M
	CALL	READR	; UPDATE L IMAGE
	INX	H
	MOV	A,M
	JMP	READR	; UPDATE L IMAGE
\f

;	TRAP INTERRUPT.

TRAP:	PUSH	H
	PUSH	PSW
	LXI	H,XOUTDELAY
	MOV	A,M
	ORA	A
	JZ	OTABEL
	DCR	M
	INX	H
INTEST:	INX	H
	MOV	A,M
	ORA	A
	JZ	ITABEL
	DCR	M	
XYTEST:
ROTIM:	LXI	H,TIMCX	; *5 COUNTER.
	DCR	M
	MOV	A,M
	CPI	6
	JZ	XRTRAP
	CPI	0
	JNZ	RTRAP	; NO
	MVI	M,12.	; YES
	LHLD	TIMCOUNT
	MOV	A,L
	ORA	H	; IS TIMER STOPPED ?
	JZ	GOAG1	; YES
	DCX	H
	SHLD	TIMCOUNT
	MOV	A,L
	ORA	H	; IS IT ZERO NOW ?
	JNZ	RTRAP	; NO
	STA	TTESX	; SET TIMER ITR
GOAG1:	LHLD	TIMOUT
	SHLD	TIMCOUNT ; RELOAD
	POP	PSW
	POP	H
	EI
	RET
XRTRAP:	LHLD	WADOG
	MOV	A,L
	ORA	H	; IS WATCH DOG ALIVE ?
	JZ	RTRAP	; NO
	DCX	H	; DECREMENT
	SHLD	WADOG
	MOV	A,L
	ORA	H	; IS THE DOG BARKING ?
	JNZ	RTRAP	; NO
	STA	XAUTO	; SET AUTOLOAD MARK
RTRAP:	POP	PSW	;
	POP	H
	EI
	RET
\f

CANCEL:	POP	H
PCANCEL:	CALL	OTXT
		DWC.	PCTXT
		JMP	FORTOL
PCTXT:	"<
	"E
	"S
	"C
	">
	0
\f

; ROUTINE TO INPUT A RIGHT JUSTIFIED
; 4 DIGIT VALUE FOR <STEP) IN THE S AND C COMMAND.
; RETURN: HL=VALUE.

GVALU:	LXI	D,INBUF
	MVI	B,4
S20:	CALL	CI
	MOV	C,A
	CPI	ESC
	JZ	PCANCEL
	CPI	CR	; IS IT CR <TERMINATION> ?
	JZ	SSEXD	; YES
	CALL	VALDG	; VALID DIGIT ?
	JNC	S20	; NO
	CALL	CO	; YES - ECHO DIGIT
	MOV	A,C
	STAX	D	; STORE DIGIT IN BUFF.
	INX	D
	DCR	B	; FINISH
	JNZ	S20	; NO - GET NEXT DIGIT
	CALL	DCLEAR
	CALL	STERM
	CALL	CINBF	; CONVERT TO 4 HEX IN HL
	RET
SSEXD:	LXI	H,0	; ZERO TO HL SINGLE STEP
	RET

; TABULATION ROUTINE.

NTAB:	POP	H
	LXI	D,10
	DAD	D
	PUSH	H
XUPBUF:	LDA	INBUF+4
	CPI	4
	JZ	UPYES
	MVI	C,CURR
	CALL	CO
	LXI	H,INBUF+4
	INR	M
	JMP	XUPBUF

; ROUTINE TO GET LEVEL ARRAY START ADDRESS
; IN THE WORKING REGISTER ARRAY (TABLE)
; WHEN CALLED: A=LEVEL.
; RETURN: HL=WORKING REGISTER ADDRESS.

LCONV:	OUT	CDI
	MVI	A,ROFF	; REG OFFSET COMM.
	CALL	XCOM
	CALL	RECEIVE ; GET ANSWER
	DWC.	PDATA
	LHLD	DBUF	; :HL ANSWER
	RET
\f

; ROUTINE TO OUTPUT ERROR MESSAGE 
; AND THE CONTENTS OF MBUF.

OUTERR:	CALL	OTXT	; OUTPUT "ERR"
	DWC.	ERRTXT
	LDA	CHSAV	; FETCH ERROR NUMBER
	CALL	CHEX	; OUTPUT ERROR NUMBER
	CALL	DSPACE	; SPACE
	LHLD	MBUF+1
	CALL	LOUTDE	; OUTPUT 1'ST PARM PART
	CALL	DSPACE	; SPACE
	LHLD	MBUF+3
	CALL	LOUTDE	; OUTPUT 2'D PARM PART
	CALL	DSPACE	; SPACE
	LDA	MBUF
	CALL	CHEX	; OUTPUT 3'TH PARM PART
	XRA	A
	STA	ITEST
	IN	PORTA
	CMA
	ANI	4
	JZ	TS00
	JMP	XFORTOL

; DECODING OF COMMANDS IN CONSOLE MODE.
; WAIT INPUT CHAR;IF CHAR=BELL THEN SHIFT TO DEBUG MODE
; ELSE SEND CHAR TO MICROPROGRAM.

MODSH:	CALL	OTXT	; OUTPUT T MODE TEXT
	DWC.	TTYTXT
MODS1:	CALL	CI	; WAIT INPUT CHAR.
	MOV	C,A
	ORA	A
	JZ	SPTES
	CPI	BELL	; IS IT MODE SHIFT
	JZ	SPT1	; YES
NOSHIFT:	LXI	H,DTIN
	MOV	M,C
	CALL	READR	; UPDATE DATIN.
TTIITR: MVI	A,TTICOM
	CALL	XCOM	; CONSOLE ITR TO L
SWTES:	CALL	RESWH	; TEST SWITCHES.
	JMP	MODS1	; RETURN.
SPTES:	CALL	BETJEN
	JMP	SWTES
SPT1:	IN	PORTA
	CMA
	ANI	8.
	JNZ	NOSHIFT
     	CALL	OTXT	; OUTPUT D MODE TEXT
	DWC.	DBTXT
	JMP	XFORTOL

SPCONV:	CALL	CNVBN	; CONVERT TO HEX
SPCO1:	RAL
	RAL
	RAL
	RAL
	ANI	360	; SHIFT TO LEFT
	RET
SPRIGHT: RAR		; SHIFT TO RIGHT
	RAR
	RAR
	RAR
	ANI	17
	RET
\f

; FUNCTION: SLAMP- SET LAMPS.
; DESCRIPTION: SET THE LAMPS ON THE FRONT PANEL
; OF CPU201 IN ACCORDANCE TO THE CONTENTS OF "CHSAV".

SLAMP:	PUSH	B	; TM= 1
 	STA	CHSAV	; RP= 2
	MOV	B,A	; LP= 4
	ANI	5	; OP= 8
	MOV	C,A
	MOV	A,B
	ANI	2
	JNZ	SLAM1
SLAM3:	MOV	A,B
	ANI	8.
	JNZ	SLAM2
SLAM4:	MOV	A,C
	CMA
	RAL
	RAL
	OUT	PORTC
	POP	B
	RET
SLAM1:	MOV	A,C
	ADI	8.
	MOV	C,A
	JMP	SLAM3
SLAM2:	MOV	A,C
	ADI	2
	MOV	C,A
	JMP	SLAM4

; DISPLAY THE PARITY ERROR.

MEMERR:	CALL	SSTOP

METEX:	MOV	A,B
	ANI	6	; MASK PARITY LAMPS
	CALL	SLAMP	; SET LP/RP LAMP(S)
	CALL	RECEIVE ; FETCH ERROR BUFFER
	DWC.	TOUT
	MVI	C,"P
	CALL	CO	; OUTPUT "P"
	CALL	DSPACE	; OUTPUT SP-SP
	LHLD	MBUF
	CALL	LOUTDE	; OUTPUT BASE
	MVI	C,":
	CALL	CO	; OUTPUT ":"
	LHLD	MBUF+2
	CALL	LOUTDE	; OUTPUT ADDR.
\f

	CALL	DSPACE	;
	LDA	CHSAV	; FETCH ERROR
	RRC		;
	CPI	3	; BOTH L AND R ERROR ?
	JZ	MTEX1	; YES
	CPI	1	; R ERROR
	JZ	MTEX2	; YES
	MVI	C,"L	;
	CALL	CO	; OUTPUT L
	JMP	DCLEAR

MTEX1:	MVI	C,"L	;
	CALL	CO	; OUTPUT L
MTEX2:	MVI	C,"R	;
	CALL	CO	; OUTPUT R
	JMP	DCLEAR

; UPDATE FLAG ADMINISTRATION.

FUPDAT:	PUSH	PSW
	PUSH	B
	PUSH	H
	LDA	COMM-1
	MOV	C,A
	CALL	BITCO
	LXI	H,UPDAT
	ORA	M
	MOV	M,A	; UPDATE BIT IN FUPDAT
	POP	H
	POP	B
	POP	PSW
	RET

; CONFIGURATION TABLE.
; ROUTINE TO CONVERT A BINARY NUMBER(0-7)
; IN C TO A BIT MASK.

BITCO:	PUSH	H
	PUSH	B
	LXI	H,CONTB	; BASE TO MASK TABLE
	MVI	B,0
	DAD	B	; ADD OFFSET
	MOV	A,M	; GET MASK BIT
	POP	B
	POP	H
	RET



\f

; MEMORY CONFIGURATION.
; WHEN CALLED :
; MBUF= INDIRECT CONFI ADDRESS
; HL=   START ADDRESS.

RAMCO:	SHLD	MBASE
	MVI	B,10
REPEAT:	LXI	H,100000
	MVI	A,20
RA22:	SHLD	ABUF+2
	STA	NUMBER
	CALL	GMEM
	MOV	A,L
	MOV	L,H
	MOV	H,A
	LDA	NUMBER
	DCR	A
	JNZ	RA22
RA20:	LXI	H,TSMON ; TEST PATTERN
	SHLD	DBUF
	CALL	PMEM	; STORE PATTERN
	CALL	GMEM	; RE-READ PATTERN
	LHLD	DBUF
	MOV	A,L
	ANA	H	; 
	CPI	125	; EXIST MEM ?
	JZ	EXIST	; YES
RA21:	LHLD	MBASE	; NO
	INX	H
	INX	H
	SHLD	MBASE	; NEXT MEM	
	DCR	B	; FINISH WITH 8 BLOCK ?
	JNZ	REPEAT	; NO
	RET		; YES
EXIST:	LHLD	ABUF	; FETCH MEM BASE
	MOV	A,L
	RAR
	ANI	7
	MOV	C,A
	CALL	BITCO	; CONVERT TO BIT MASK
	LHLD	MBUF
	ADD	M
	MOV	M,A	; ADD BIT TO MASK
	JMP	RA21

; MEMORY CONFIGU.

MEMCO:	LXI	H,RAMB+28.
	SHLD	MBUF
	LXI	H,300
	CALL	RAMCO	; CONFIGURATE 0-7
	LXI	H,MBUF
	INR	M
	LXI	H,320
	JMP	RAMCO	; CONFIGURATE 8-15

\f

; ROUTINE TO OUTPUT CPU NO. AND MICROPROGRAM
; VERSION NUMBER.

VERSION: MVI	A,RDCOM ; TRANF A BYTE TO M
	CALL	XCOM
	IN	CDO	; READ ANSWER "CPU"-"MIC"
	PUSH	PSW
	CALL	OTXT	; SEND OUTPUT "RC 350"
	DWC.	INITX
	POP	PSW	; FETCH BYTE FROM L
	PUSH	PSW
	CALL	SPRIGHT
	CALL	PRVAL	; CONVER TO ASCII
	CALL	CO	; OUTPUT CPU NUMBER
	CALL	OTXT	; OUTPUT CPU NUMBER
	DWC.	INITY
	POP	PSW	; FETCH BYTE FROM L
	ANI	17
	STA	VERNO	; SAVE VER. NO IN RAM
	CALL	PRVAL	; CONVERT TO ASCII
	CALL	CO	; OUTPUT MICROPROGRAM VERSION
	CALL	DCLEAR
	CALL	OTXT
	DWC.	TEC70
	RET
TEC70:	40
	"D
	"E
	"B
	"U
	"G
	40
	"V
	"E
	"R
	"0
	"2
	0

\f

; 8085 MICROPROGRAM COMMUNICATION TEST.
; TEST OF COMMUNICATION FIFO.

TS00:	MVI	A,1
	CALL	SLAMP
	MVI	A,-1.
	LXI	H,MBUF	; START PATTERN GEN
TSB01:	MVI	B,6
TS001:	MOV	M,A
	INX	H
	DCR	A
	DCR	B
	JNZ	TS001
	CALL	SEND	; SEND BLOCK TO L
	DWC.	TOUT
	CALL	RECEIVE ; GET ANSWER
	DWC.	TIND
	LXI	H,MBUF
	LXI	B,ABUF
	MVI	D,6
TS002:	LDAX	B
	CMP	M	; ERROR ?
	JNZ	OUTERR	; YES
	INX	H
	INX	B
	DCR	D	; FINISH ?
	JNZ	TS002	; NO
	LXI	H,MBUF
	MOV	A,M
	ORA	A	; IS ALL PATTERN TESTED ?
	JZ	TS01	; YES
	STC
	CMC
	RAL
	JMP	TSB01
\f

; TEST THAT THE MICROPROGRAM CAN INTERRUPT THE 8085.

TS01:	MVI	A,3
	CALL	SLAMP	; 3 TO LAMP
	XRA	A
	STA	ITEST
	MVI	A,1
	OUT	CDI	; OUTPUT TEST NUMBER
	MVI	A,RDCOM
	CALL	XCOM	; INPUT TO FIFO
	MVI	A,TSCOM ; SEND TEST COMM.
	CALL	XCOM
TS010:	LDA	ITEST
	ORA	A	; L-ITR MARK?
	JZ	TS010	; NO
	XRA	A
	STA	ITEST	; RESET REQ MARK
	JMP	TS02

; TEST PROCEDURE.
; WHEN CALLED : H=LAMP NO. AND L=TEST NO.

TPROC:	MOV	A,H
	CALL	SLAMP	; TESTNUMBER TO LAMP
	MOV	A,L
	OUT	CDI	; OUTPUT TEST NUMBER
	MVI	A,RDCOM
	CALL	XCOM	; INPUT TO FIFO
	MVI	A,TSCOM ; SEND TEST COMM. TO L
	CALL	XCOM
	CALL	RECEIVE ; GET ANSWER
	DWC.	TOUT
	RET

; WORKING ADDRESS REGISTER TEST.

TS02:	LXI	H,KTS02
	CALL	TPROC	; START TEST IN L
	LXI	H,MBUF
	MOV	A,M	; READ ANSWER
	ORA	A	; ERROR ?
	JZ	TS03	; NO
	JMP	OUTERR

; WORKING REGISTER DATA TEST.

TS03:	LXI	H,TSMON
	SHLD	ABUF	; STORE TESTPATTERN
	CALL	SEND
	DWC.	RREG
	LXI	H,KTS03
	CALL	TPROC	; START TEST IN L
	LXI	H,MBUF
	MOV	A,M	; READ ANSWER
	ORA	A	; ERROR ?
	JZ	TS04	; NO
	JMP	OUTERR

\f

; WORKING REGISTER DATA TEST.
; PATTERN: 125252.

TS04:	LXI	H,TSMIN
	SHLD	ABUF	; STORE TESTPATTERN
	CALL	SEND
	DWC.	RREG
	LXI	H,KTS03
	CALL	TPROC	; START TEST IN L
	LXI	H,MBUF	;
	MOV	A,M	; READ ANSWER
	ORA	A	; ERROR ?
	JZ	TS05	; NO
	JMP	OUTERR

; ROUTINE TO GET NEXT MEMORY MODUL.
; CALL: PASSC= MASK AND RCAB=LAST MODUL NO.
; RETURN: C=1 IF FINISH ELSE C=0.
; NAME: "GMODU".

GMODU:	LDA	PASSC	; GET MASK
	ORA	A
	JNZ	NMODL	; GET NEXT
	STC
	RET		; RETURN C=1
NMODL:	LXI	H,RCAB
	LDA	PASSC
	STC
	CMC
	RAL
	STA	PASSC
	INR	M
	INR	M
	JNC	GMODU
	STC
	CMC
	RET		; RETURN C=0.
\f

; MEMORY ADDRESS TEST.
; ALL MODULE POINTED OUT IN "RAMB+28." AND
; "RAMB+29" IS TESTED.

TS05:	MVI	A,276	;
	STA	RCAB	;
	LDA	RAMB+28. ;
	CALL	TS06	;
	MVI	A,316	;
	STA	RCAB	;
	LDA	RAMB+29. ;
	CALL	TS06	;
	JMP	TS07	;
TS06:	STA	PASSC	; SAVE LAST MODUL TESTED
TS05X:	CALL	GMODU
	RC		; FINISH
	MVI	H,0
	LDA	RCAB
	MOV	L,A
	SHLD	ABUF
	CALL	SEND
	DWC.	RREG
	LXI	H,KTS04
	CALL	TPROC
	LXI	H,MBUF
	MOV	A,M
	ORA	A
	JNZ	POUTERR
	LDA	ITEST
	ORA	A
	CNZ	WRREQ
	JMP	TS05X

\f

; MEMORY DATA TEST MODULE: "RAMB+28." AND "RAMB+29."
; PATTERN: 52525

TS07:	MVI	A,276	;
	STA	RCAB	;
	LDA	RAMB+28. ;
	CALL	TS08	;
	MVI	A,316	;
	STA	RCAB	;
	LDA	RAMB+29. ;
	CALL	TS08	;
	JMP	TS09	;
TS08:	STA	PASSC	;
TS07X:	CALL	GMODU
	RC
	LXI	H,TSMON
	SHLD	ABUF
	MVI	H,0
	LDA	RCAB
	MOV	L,A
	SHLD	ABUF+2
	CALL	SEND
	DWC.	PADDR
	LXI	H,KTS05
	CALL	TPROC
	LXI	H,MBUF
	MOV	A,M
	ORA	A
	JNZ	POUTERR
	LDA	ITEST
	ORA	A
	CNZ	WRREQ
	JMP	TS07X

; MEMORY DATA TEST.
; TEST MODULES SELECTED IN RAMB+28. AND RAMB+29.
; PATTERN: 125252.

TS09:	MVI	A,276	;
	STA	RCAB	;
	LDA	RAMB+28. ;
	CALL	TS10	;
	MVI	A,316	;
	STA	RCAB	;
	LDA	RAMB+29. ;
	CALL	TS10	;
	JMP	TS11	;
TS10:	STA	PASSC	;
TS09X:	CALL	GMODU
	RC
	LXI	H,TSMIN
	SHLD	ABUF
	MVI	H,0
	LDA	RCAB
	MOV	L,A
	SHLD	ABUF+2
	CALL	SEND
	DWC.	PADDR
	LXI	H,KTS09
	CALL	TPROC
	LXI	H,MBUF
	MOV	A,M
	ORA	A
	JNZ	POUTERR
	LDA	ITEST
	ORA	A
	CNZ	WRREQ
	JMP	TS09X

POUTERR:	POP	H
	JMP	OUTERR

\f

; RETURN FROM BUILT-IN TEST.
; IF MODE SWITCH 4=0 THEN LOOP ELSE STOP.

TS11:	IN	PORTA	; READ MODE SWITCH
	CMA
	ANI	4	; LOOP ?
	JZ	TS00	; YES
	XRA	A
	CALL	SLAMP	; SWITCH OFF THE LAMPS
	JMP	TSRET

; ROUTINE TO SET I/O CONFIGURATION MAP.
; FROM "RAMB+12." TO "RAMB+27."

IOCONF:	MVI	A,127.
	STA	PASSC
IONEX:	LDA	PASSC
	CPI	-1.
	RZ
	OUT	CDI	; SEND I/O NUMBER TO L
	MVI	A,TSLEV
	CALL	XCOM	; SEND WAIT ANSWER
	IN	CDO	; READ ANSWER
	ORA	A	; EXIST LEVEL ?
	JZ	NEXIST	; NO
	LXI	H,RAMB+12.
	LDA	PASSC
	CALL	SPRIGHT+1
	MOV	C,A
	MVI	B,0
	DAD	B	; CALCULATE REL ADDR
	MOV	A,M
	STC		; 1 TO BIT MASK
IOREP:	RAR
	MOV	M,A
	LXI	H,PASSC
	DCR	M
	JMP	IONEX
NEXIST:	LXI	H,RAMB+12.
	LDA	PASSC
	CALL	SPRIGHT+1
	MOV	C,A
	MVI	B,0
	DAD	B	; CALCULATE REL. ADDR.
	MOV	A,M
	STC
	CMC		; 0 TO BIT MASK
	JMP	IOREP
\f

; PROM CONFIGURATION. PATTERN IN FIRST ADDRESS:AAAA.

PROCON:	LXI	H,376	; LAST PROM.
	SHLD	MBASE
PRONEX:	LDA	MBASE
	CPI	336
	RZ
	LXI	H,0
	SHLD	ABUF+2
	CALL	GMEM	; READ FROM PROM.
	LXI	H,RAMB+28.
	LDA	MBASE
	RAR
	RAR
	RAR
	RAR
	ANI	3
	MOV	C,A
	MVI	B,0	; CALCULATE OFFSET IN TABLE
	DAD	B
	LDA	DBUF
	CPI	ROMCH	; CHECK PATTERN
	JZ	PEXIST
	STC
	CMC		; 0 TO BIT MASK
PROREP:	MOV	A,M
	RAR
	MOV	M,A
	LXI	H,MBASE
	DCR	M
	DCR	M
	JMP	PRONEX	; TEST NEXT.
PEXIST:	STC		; 1 TO BIT MASK
	JMP	PROREP

\f



	.RDX	16
	.LOC	0F26
	.RDX	8
OUTTAB:	DWC.	ODUMMY
	DWC.	OSTART
	DWC.	ODATA
	DWC.	ODATA
	DWC.	ODATA
	DWC.	ODATA
	DWC.	ODATA
	DWC.	ODATA
	DWC.	ODATA
	DWC.	ODATA
	DWC.	OSTOP
	DWC.	XOSTOP

OSTART:	MVI	A,STRT
	JMP	OTXEND
ODATA:	LDA	XOUTCHAR
	RAR
	STA	XOUTCHAR
	MVI	A,SSTRT
	RAR
OTXEND:	SIM
	LXI	H,OUTPASE
	INR	M
	INR	M
	JMP	INTEST
OSTOP:	MVI	A,STOPB
	JMP	OTXEND
XOSTOP:	MVI	A,STOPB
	SIM
	LXI	H,OUTPASE
	MVI	M,0
ODUMMY:	LXI	H,OUTPASE
	JMP	INTEST
\f


OTABEL:	LDA	DOHALF
	MOV	M,A
	INX	H
	MOV	A,M
	LXI	H,OUTTAB
	ADD	L
	MOV	L,A
	MOV	L,M
	PCHL

ITABEL:	INX	H
	MOV	A,M
	LXI	H,INTAB
	ADD	L
	MOV	L,A
	MOV	L,M
	PCHL
\f


INTAB:	DWC.	WSTART
	DWC.	WHALF
	DWC.	IDATA
	DWC.	IDATA
	DWC.	IDATA
	DWC.	IDATA
	DWC.	IDATA
	DWC.	IDATA
	DWC.	IDATA
	DWC.	IDATA
	DWC.	WFULL
	DWC.	IEND

WSTART:	RIM
	RAL
	JC	XYTEST
BSTART:	LDA	BHALF
	STA	INDELAY
	JMP	INXEND
WHALF:	LDA	DOHALF
	STA	INDELAY
	JMP	INXEND
IDATA:	RIM
	RAL
	LDA	INCBUF
	RAR
	STA	INCBUF
INYEND:	LDA	DOHALF
	STA	INDELAY
INXEND:	LXI	H,INPASE
	INR	M
	INR	M
	JMP	XYTEST
WFULL:	LDA	INCBUF
	STA	XINCHAR
	MVI	A,1
	STA	CHARRDY
	JMP	INYEND
IEND:	LDA	DOHALF
	STA	INDELAY
	XRA	A
	STA	INPASE
	JMP	XYTEST
\f

\f