Compucolor.org – Virtual Media

Listing of file='DISASM.SRC;02' on disk='vmedia/disasm+mldp+sideA-sector.ccvf'

;^RED>DISASM.SRC;8		1980/09/14 1200
;
;	KNOWN BUGS:
;			DOES NOT ALLOW INITIAL VALUE
;				FOR LABELS
;
;
;
;
; COPYRIGHT 1977	NORDIN ENTERPRISES
;			P.O. BOX 1277
;			CUPERTINO, CA 95014
;
;
;
;	TITLE	'AUTOMATIC DIS-ASSEMBLER PROGRAM'
;
;
; COMPUCOLOR II		32K SYSTEM
;
; ENTER A 'START ADDR','FINISH ADDR','OFFSET'&'PARAM'
; FROM CONSOLE.  PRINT TO THE LIST DEVICE IN
; ASSEMBLER LANGUAGE FORMAT THE FOLLOWING:
;  HEX ADDR---OBJECT CODE---MNEMONIC---OPERAND
;    PRINT LABELS WHERE FOUND
;
LOAD	EQU	0E400H	;64K MACHINE
			;
	ORG	LOAD
			;
			;
	JMP	FIRST	;FIRST DO COMPUCOLOR THINGS
CI:	JMP	CIX	;CONSOLE INPUT
CO:	JMP	COX	;CONSOLE OUTPUT (DATA IN A REG)
LO:	JMP	LOX	;LIST (PRINT) OUTPUT
MNTR:	JMP	EXIT	;RETURN TO MONITOR
WRTV:	JMP	PUNCH	;PUNCH OUTPUT
UPDAT:	JMP	MNTR
STACK:	DW	THESTK	;LOCATION OF THE STACK
SZTBL	EQU	3	;TABLE SIZE IN KILOBYTES
TBLSZ:	DB	SZTBL	;TABLE SIZE IN KILOBYTES
TABLOC	EQU	LOAD-SZTBL*1024
TABLE:	DW	TABLOC	;START LOCATION OF SYMBOL TABLE
			;
			;
START:	DW	0	;START ADDRESS
FINSH:	DW	0	;FINISH ADDRESS
OFSET:	DW	0	;OFFSET VALUE
HERE:	DW	0	;PRESENT ADDRESS VALUE
TINL:	DW	0	;ADDRESS OF SYMBOL TABLE INSERT
TMPST:	DW	0	;SEARCH ADDRESS FOLLOWING JMP , CALL
PSTAT:	DB	0	;PRINT LABEL STATUS
LABV:	DW	0	;LABEL VALUE -- UP TO 12K LABELS
TABL3:	DW	0	;STARTING ADDRESS OF SYMBOL TABLE
COUNT:	DB	0	;PRINT OUT FORMAT CONTROL
;
;
CR	EQU	0DH	;CARRIAGE RETURN
;
;
;
;
;
;
;
;
;
BEGIN:	LHLD	TABLE
	SHLD	TABL3	;SET UP SYMBOL TABLE START
	LXI	H,MSG1
	CALL	MESAG	;PRINT--PUNCH THE SOURCE ?
	CALL	TI
	CPI	'Y'	;YES?
	JZ	BEG0	;JUMP IF YES
	LXI	H,0C900H;NO
	SHLD	WRTV	;PATCH PUNCH WITH RET IF SO
	JMP	BEG1	;SKIP DISK FILE SETUP
BEG0:	CALL	CRLF
	CALL	SETUP	;SETUP DISK FILE
BEG1:	CALL	CRLF
	LXI	H,MSG2
	CALL	MESAG	;PRINT--PRINT ASCII DUMP ?
	CALL	TI
	CPI	'Y'
	JZ	PASCI	;GO PRINT ASCII FIRST
	CALL	CRLF
	CALL	STFIN	;GET THE START-FINISH PARAMETERS
;
; CLEAR THE SYMBOL TABLE
;
BEG2:	LHLD	TABL3
	LDA	TBLSZ
	RLC
	RLC
	MOV	C,A
	XRA	A
	STA	PSTAT
	MOV	B,A
	DCX	H
CLEAR:	MOV	M,A
	INX	H
	INR	B
	JNZ	CLEAR
	DCR	C
	JNZ	CLEAR
	MVI	A,0FFH
	MVI	B,4
CLR1:	MOV	M,A
	DCX	H
	DCR	B
	JNZ	CLR1
	LHLD	START
	SHLD	HERE
;
; FIRST PASS--BUILD A SYMBOL TABLE ( 3 BYTES PER SYMBOL )
;  SEARCH CODE DELIMITED BY 'START' & 'FINISH' FOR
;  ALL JMP'S & CALL'S.  IF THE ADDRESS WHICH FOLLOWS
;  ISN'T FOUND IN THE TABLE AND IS IN THE RANGE
;  OF 'START & FINISH'---
;  THEN INSERT IT IN A NUMERICALLY ASCENDING ORDER.
;  IF IT IS FOUND IN THE TABLE---
;  INCREMENT THAT LABELS 'NUMBER OF CALLS'
;  COUNTER (UP TO 254 POSSIBLE).
;   FORMAT OF TABL3:
;     CNTR0,MS ADDRESS,LS ADDRESS,CNTR1,MS ADDRESS,LS ADDRESS
;       LAST TABLE POSITION IS 0FFH
;
PASS:	LHLD	HERE	;GET PRESENT CODE POINTER
	LDA	FINSH+1
	CMP	H	;ARE WE FINISHED?
	JZ	PASS1	;MAYBE
	JC	PASSE	;YES
	JMP	PASS2
PASS1:	LDA	FINSH
	CMP	L	;FINISHED?
	JC	PASSE	;YES
PASS2:	MOV	A,M	;NO - GET OPCODE BYTE
	INX	H
	SHLD	HERE	;SAVE POINTER TO NEXT BYTE
	LXI	H,TABL1
	ADD	L
	MOV	L,A
	MVI	A,0
	ADC	H
	MOV	H,A
	MOV	A,M	;GET NUMBER OF BYTES/OPCODE COUNTER
	CPI	1	;ONE BYTE OPCODE?
	JZ	PASS	;YES
	CPI	2
	JZ	PASS3	;TWO BYTE OPCODE
	CPI	3
	JZ	PASS4	;THREE BYTES OTHER THAN JMP , CALL
	LHLD	HERE	;THIS IS A JMP OR CALL OPCODE
	MOV	E,M	;GET LS ADDRESS
	INX	H
	MOV	D,M	;GET MS ADDRESS
	INX	H
	SHLD	HERE	;READY FOR NEXT OPCODE
	XCHG
	SHLD	TMPST	;SAVE DE IN RAM
	LHLD	START
	XCHG
	LHLD	OFSET
	DAD	D	;ADD OFFSET TO START ADDRESS
	XCHG
	LHLD	TMPST	;NOW RETRIEVE COMPARE ADDRESS
	MOV	A,H
	CMP	D	;IF COMPARE ADDRESS < START ADDRESS
	JC	PASS	;THEN GO ON TO NEXT OPCODE
	JNZ	PASS0
	MOV	A,L
	CMP	E
	JC	PASS
PASS0:	LHLD	FINSH
	XCHG
	LHLD	OFSET
	DAD	D	;ADD OFFSET TO FINISH ADDRESS
	XCHG
	LHLD	TMPST
	XCHG
	MOV	A,H
	CMP	D	;IF COMPARE ADDRESS > FINISH ADDRESS
	JC	PASS	;THEN GO ON TO NEXT OPCODE
	JNZ	SERCH
	MOV	A,L
	CMP	E
	JC	PASS
	JMP	SERCH	;COMPARE ADDRESS WAS WITHIN RANGE
PASS3:	LHLD	HERE
	INX	H
	SHLD	HERE
	JMP	PASS
PASS4:	LHLD	HERE
	INX	H
	INX	H
	SHLD	HERE
	JMP	PASS
;
; TABLE SEARCH FOR COMPARE ADDRESS CONTAINED IN DE
;
SERCH:	LHLD	TABL3
SER1:	MOV	A,M	;GET NUMBER OF CALLS COUNTER
	CPI	0FFH	;END OF TABLE?
	JZ	PASS	;YES
	ORA	A
	JZ	INSRT	;THAT WAS END OF TABLE ENTRIES
	INX	H
	MOV	A,D	;GET MS SEARCH VALUE
	CMP	M	;COMPARE TO SYMBOL TABLE VALUE
	JC	SER5	;MS TABLE > MS SEARCH VALUE
	JNZ	SER2	;NOT EQUAL
	INX	H
	MOV	A,E	;GET LS SEARCH VALUE
	CMP	M
	JC	SER4	;LS TABLE > LS SEARCH VALUE
	JNZ	SER3	;NOT EQUAL
	DCX	H	;AHA--THEY ARE EQUAL
	DCX	H
	MOV	A,M	;GET COUNTER
	INR	A
	MOV	M,A
	CPI	0FFH	;REACHED 255 CALLS?
	JNZ	PASS	;NO
	DCR	A	;YES--ONLY ALLOW 254
	MOV	M,A
	JMP	PASS
SER2:	INX	H	;GO TO NEXT TABLE LOCATION
SER3:	INX	H
	JMP	SER1	;AND CONTINUE SEARCH
SER4:	DCX	H	;TABLE VALUE WAS > SEARCH VALUE
SER5:	DCX	H	;SO INSERT SEARCH VALUE IN TABLE
;
; INSERT SEARCH VALUE CONTAINED IN DE INTO SYMBOL TABLE
;
INSRT:	SHLD	TINL	;SAVE PRESENT POSITION IN SYMBOL TABLE
INSR1:	XRA	A
	ORA	M	;END OF TABLE YET?
	JZ	INSR2	;YES
	CPI	0FFH	;MAX END YET?
	JZ	PASS	;YES
	INX	H
	INX	H
	INX	H
	JMP	INSR1	;GO TO NEXT SYMBOL TABLE LOCATION
INSR2:	PUSH	D	;IT IS OK TO INSERT
	INX	H
	INX	H
	XCHG
	LXI	H,3
	DAD	D	;BOTH POINTERS READY
INSR3:	LDAX	D	;GET CHARACTER
	MOV	M,A	;PUT IT IN LOCATION+3 LOCATION
	DCX	H
	DCX	D
	LDA	TINL+1	;HAVE WE REACHED STARTING
	CMP	D	;PLACE IN TABLE?
	JNZ	INSR3	;NO
	LDA	TINL
	CMP	E
	JNZ	INSR3
	LDAX	D
	MOV	M,A
	XCHG
	MVI	M,1	;INITIAL COUNT = 1
	INX	H
	POP	D
	MOV	M,D	;STORE MS ADDRESS VALUE
	INX	H
	MOV	M,E	;STORE LS
	JMP	PASS	;BACK TO NEXT CODE SEARCH
;
; THIS IS BEGINNING OF SECOND PASS
;  WE NOW PRINT OUT THE ASSEMBLY LANGUAGE EQUIVALENT
;  OF THE OPCODES FOUND AND THEIR ARGUMENTS.
;  ALL 3-BYTE CODES FOUND MAKE A SEARCH OF THE
;  SYMBOL TABLE AND COMPARE.  IF THE VALUE IS FOUND
;  IN THE TABLE THEN IT IS REPLACED BY A MANUFACTURED
;  LABEL WHICH RELATES TO ITS POSITION IN THE TABLE.
;
PASSE:	LHLD	START
	SHLD	HERE
AGAIN:	LHLD	HERE
	LDA	FINSH+1
	CMP	H	;EQUAL?
	JZ	AGN1	;YES
	JC	FOUR	;WHOOPS GREATER THAN
	JMP	AGN2
AGN1:	LDA	FINSH
	CMP	L	;GREATER THAN?
	JC	FOUR	;YES
AGN2:	MVI	B,4	;INDENT
	CALL	SPACE	;LISTING FOR 3 HOLE PUNCH
	XCHG
	LHLD	OFSET
	DAD	D	;ADD OFFSET
	CALL	DADR	;PRINT ADDRESS IN HL
	MVI	B,2
	CALL	SPACE
	XCHG
	CALL	FIND	;SEARCH SYMBOL TABLE
	LHLD	HERE
	MOV	A,M	;GET OPCODE BYTE
	PUSH	PSW	;SAVE A COPY
	INX	H
	SHLD	HERE	;SAVE NEXT BYTE ADDRESS
	LXI	H,TABL1	;FORM TABL1 POINTER
	ADD	L
	MOV	L,A
	MVI	A,0
	ADC	H
	MOV	H,A
	MOV	A,M	;GET NUMBER OF BYTES PER OPCODE
	DCR	A
	JZ	ONE	;THAT IS A ONE-BYTE OPCODE
	CPI	1
	JZ	TWO	;THAT IS A TWO-BYTE OPCODE
;
THREE:	POP	PSW	;THIS IS A THREE-BYTE OPCODE
	MOV	E,A	;SAVE OPCODE IN "E"
	CALL	DBYTE	;PRINT IT
	LHLD	HERE
	MOV	A,M	;GET 1ST DATA/ADDRESS BYTE
	PUSH	PSW	;SAVE TO STACK
	CALL	DBYTE	;PRINT IT
	INX	H
	MOV	A,M	;GET 2ND DATA/ADDRESS BYTE
	PUSH	PSW
	CALL	DBYTE
	INX	H
	SHLD	HERE	;SAVE NEXT OPCODE ADDRESS
	MVI	B,2
	CALL	SPACE
	CALL	LABEL	;PRINT LABEL IF APPROPRIATE
	CALL	PRINT
	POP	PSW
	MOV	D,A	;GET MS
	POP	PSW
	MOV	E,A	;GET LS
	CALL	FIND	;IS IT IN SYMBOL TABLE?
	JNC	THRE1	;NO--JUST PRINT THE NUMBER
	CALL	PLAB	;YES--PRINT A LABEL
	JMP	THRE2
THRE1:	XCHG
	CALL	FADR
THRE2:	CALL	FCRLF
	JMP	AGAIN
;
; PRINT THE SYMBOL TABLE WITH NUMBER OF CALLS PER LABEL
;  FORMAT: SMxxx  YY  ADDR
;   WHERE xxx=LABEL NUMBER & YY=NUMBER OF CALLS
;
FOUR:	MVI	B,4
FOUR1:	MVI	A,0AH	;PRINT 4 LINE FEEDS
	CALL	LO
	DCR	B
	JNZ	FOUR1
	LHLD	TABL3
	LXI	D,0
FOUR2:	MVI	A,4
	STA	COUNT
FOUR3:	XRA	A	;GET COUNTER VALUE
	ORA	M	;END OF TABLE ENTRIES?
	JZ	FLOPY	;YES
	CPI	0FFH	;END OF TABLE?
	JZ	FLOPY	;YES
	MOV	A,D	;GET POSITION COUNTER
	STA	LABV+1	;INITIALIZE FOR PRINTING LABEL
	MOV	A,E
	STA	LABV
	CALL	XLAB
	MVI	B,1
	CALL	SPACE
	MOV	A,M	;GET NUMBER OF CALLS COUNTER
	CALL	DBYTE	;PRINT IT
	MVI	B,1
	CALL	SPACE
	INX	H
	MOV	A,M	;GET MS ADDRESS VALUE
	CALL	DBYTE	;PRINT IT
	INX	H
	MOV	A,M	;GET LS ADDRESS VALUE
	CALL	DBYTE	;PRINT IT
	INX	H
	MVI	B,4
	CALL	SPACE
	INX	D	;NO--ADVANCE TABLE POSITION
	LDA	COUNT
	DCR	A
	STA	COUNT
	JNZ	FOUR3	;PRINT 4 GROUPS PER LINE
	CALL	LCRLF	;END OF A LINE
	JMP	FOUR2
;
FLOPY:	MVI	B,8
FLOP1:	CALL	LCRLF
	DCR	B
	JNZ	FLOP1
	MVI	A,FF	;FORM FEED
	CALL	LO
	MVI	A,FF
	CALL	LO
	JMP	UPDAT
;
; ONE BYTE OPCODE PROGRAM PATH
;
ONE:	POP	PSW	;GET OPCODE
	MOV	E,A	;SAVE
	CALL	DBYTE	;PRINT IT
	MVI	B,6
	CALL	SPACE	;PRINT SPACES
	CALL	LABEL
	CALL	PRINT	;PRINT OPCODE MNEMONIC
	JMP	THRE2
;
; TWO BYTE OPCODE PROGRAM PATH
;
TWO:	POP	PSW	;GET OPCODE
	MOV	E,A	;SAVE
	CALL	DBYTE	;PRINT
	LHLD	HERE
	MOV	A,M	;GET DATA BYTE
	PUSH	PSW	;SAVE
	INX	H
	SHLD	HERE	;SAVE NEXT OPCODE ADDRESS
	CALL	DBYTE	;PRINT DATA BYTE
	MVI	B,4
	CALL	SPACE
	CALL	LABEL
	CALL	PRINT
	POP	PSW
	CALL	FBYTE	;GET AND PRINT DATA BYTE
	JMP	THRE2
;
; PRINT A MESSAGE
;  ENTER WITH HL POINTING AT FIRST
;  ASCII DIGIT--WILL PRINT UNTIL A
;  "EOT" (04H) CHARACTER IS FOUND.
;
MESAG:	MOV	A,M	;GET THE CHARACTER
	CPI	4H	;IS IT EOT?
	RZ		;ALL FINISHED
	CALL	CO
	INX	H	;ADVANCE POINTER
	JMP	MESAG
;
FESAG:	MOV	A,M
	CPI	4H
	RZ
	CALL	LO
	CALL	WRTV
	INX	H
	JMP	FESAG
;
; ENTER START, FINISH AND OFFSET
;  PRINTS CR-LF & MESSAGE:
;  "START ADDRESS, FINISH ADDRESS, OFFSET= "
;  ENTRY OF UP TO 4 HEX DIGITS PER VALUE IS
;  EXPECTED.  OFFSET IS SAME VALUE USED IF
;  LOADING A PROGRAM FROM PAPER TAPE OR
;  FLOPPY WITH OFFSET.
;
STFIN:	CALL	CRLF
	LXI	H,MSGST
	CALL	MESAG	;PRINT MESSAGE TO CONSOLE
	MVI	C,3
	CALL	EXPR	;GET 3 PARAMETERS
	POP	H	;GET OFFSET
	XRA	A
	SUB	L	;DO A 2'S COMPLEMENT
	MOV	L,A
	MVI	A,0
	SBB	H
	MOV	H,A
	SHLD	OFSET	;SAVE IT
	POP	H
	SHLD	FINSH
	POP	H
	SHLD	START
	CALL	CRLF
	RET
;
; PRINT NUMBER OF SPACES SPECIFIED IN "B"
;  TO THE LIST DEVICE
;
SPACE:	MVI	A,' '
	CALL	LO	;TO LIST DEVICE
	DCR	B
	JNZ	SPACE
	RET
;
FPACE:	MVI	A,' '
	CALL	LO
	DCR	B
	JNZ	FPACE
	MVI	A,9H	;TAB CHARACTER TO FLOPPY
	CALL	WRTV
	RET
;
; PRINT OPCODE MNEMONIC MESSAGE
;  ENTER WITH OPCODE BYTE IN "E"
;
PRINT:	MVI	D,0
	LXI	H,TABL2
	XCHG
	DAD	H	;DOUBLE OPCODE VALUE
	DAD	D	;NOW ADD TO TABL2 ADDRESS
	MOV	A,M	;GET LS BYTE FROM TABLE2
	INX	H
	MOV	H,M	;GET MS BYTE FROM TABLE
	MOV	L,A
	CALL	FESAG	;NOW PRINT APPROPRIATE MESSAGE
	RET
;
; SEARCH SYMBOL TABLE FOR AN EQUAL COMPARISON
;  WITH THE VALUE IN DE.
; EXIT WITH:  IF FOUND AN EQUAL
;		CY=1,TABLE POSITION IN "LABV"
;	IF NOT FOUND----CY=0
; A,B,H,L,FLAGS USED
;
FIND:	LHLD	TABL3
	LXI	B,0
FIND1:	XRA	A
	ORA	M	;GET TABLE COUNTER VALUE
	JZ	FIND2	;WHOOPS-FOUND END OF ENTRIES
	CPI	0FFH	;AT END OF TABLE?
	JZ	FIND2	;YES-ALL FINISHED
	INX	H
	MOV	A,D	;GET MS TABLE VALUE
	CMP	M
	JC	FIND2	;D > TABLE VALUE
	JNZ	FIND3	;D < TABLE VALUE
	INX	H
	MOV	A,E	;GET LS
	CMP	M
	JC	FIND2	;E > TABLE VALUE
	JNZ	FIND4	;E < TABLE VALUE
	MOV	A,B
	STA	LABV+1	;FOUND EQUAL SO SAVE POSITION COUNT
	MOV	A,C
	STA	LABV
	MVI	A,0FFH
	STA	PSTAT	;SET FOUND STATUS
	STC
	RET
FIND2:	XRA	A
	STA	PSTAT	;NOT FOUND EXIT
	RET
FIND3:	INX	H
FIND4:	INX	H	;ADJUST POINTER
	INX	B	;KEEP TRACK OF TABLE POSITION
	JMP	FIND1
;
; PRINT A LABEL WHOSE VALUE IS FOUND IN "LABV"
;
XLAB:	MVI	A,'S'
	CALL	LO
	MVI	A,'M'
	CALL	LO
	LDA	LABV+1
	CALL	CONV
	CALL	LO
	LDA	LABV
	CALL	DBYTE
	RET
;
;
PLAB:	MVI	A,'S'
	CALL	LO
	CALL	WRTV
	MVI	A,'M'
	CALL	LO
	CALL	WRTV
	LDA	LABV+1
	CALL	CONV
	CALL	LO
	CALL	WRTV
	LDA	LABV
	RRC
	RRC
	RRC
	RRC
	CALL	CONV
	CALL	LO
	CALL	WRTV
	LDA	LABV
	CALL	CONV
	CALL	LO
	CALL	WRTV
	RET
;
; PRINT LABEL PRECEEDING CODE IF PRINT STAT IS ON.
;  OTHERWISE PRINT SPACES.
;
LABEL:	LDA	PSTAT
	ORA	A
	JZ	LAB1
	CALL	PLAB
	MVI	A,':'
	CALL	LO
	CALL	WRTV
	MVI	B,2
	CALL	FPACE
	RET
LAB1:	MVI	B,8
	CALL	FPACE
	RET
;
; PRINT A CR-LF AND SEND TO PUNCH
;
FCRLF:	MVI	A,CR
	CALL	LO
	CALL	WRTV
	MVI	A,LF
	CALL	LO
	CALL	WRTV
	RET
;
CRLF:	MVI	A,CR
	CALL	CO
	MVI	A,LF
	CALL	CO
	RET
;
; PRINT HEX VALUE IN "A" AND SEND TO PUNCH
;  INSERT A LEADING 0 AND APPEND AN "H"
;
FBYTE:	PUSH	PSW
	PUSH	PSW
	MVI	A,'0'
	CALL	LO
	CALL	WRTV
	POP	PSW
	RRC
	RRC
	RRC
	RRC
	CALL	CONV
	CALL	LO
	CALL	WRTV
	POP	PSW
	CALL	CONV
	CALL	LO
	CALL	WRTV
	MVI	A,'H'
	CALL	LO
	CALL	WRTV
	RET
;
; PRINT AN ADDRESS IN HL AND SEND TO PUNCH
;  INSERT A LEADING 0 AND APPEND AN "H"
;
FADR:	MVI	A,'0'
	CALL	LO
	CALL	WRTV
	MOV	A,H
	RRC
	RRC
	RRC
	RRC
	CALL	CONV
	CALL	LO
	CALL	WRTV
	MOV	A,H
	CALL	CONV
	CALL	LO
	CALL	WRTV
	MOV	A,L
	RRC
	RRC
	RRC
	RRC
	CALL	CONV
	CALL	LO
	CALL	WRTV
	MOV	A,L
	CALL	CONV
	CALL	LO
	CALL	WRTV
	MVI	A,'H'
	CALL	LO
	CALL	WRTV
	RET
;
;
GOMON:	CALL	LCRLF
	JMP	MNTR
;
;
TI:	PUSH	B
	CALL	CI
	CALL	UC
	POP	B
	RET
;
;
UC:	CPI	'A'+20H
	RM
	CPI	'Z'+21H
	RP
	ANI	0DFH	;FORCE UPPER CASE
	RET
;
;
LCRLF:	MVI	A,CR
	CALL	LO
	MVI	A,LF
	CALL	LO
	RET
;
;
DADR:	MOV	A,H
	CALL	DBYTE
	MOV	A,L
	CALL	DBYTE
	RET
;
;
DBYTE:	PUSH	PSW
	RRC
	RRC
	RRC
	RRC
	CALL	CONV
	CALL	LO
	POP	PSW
	CALL	CONV
	CALL	LO
	RET
;
;
CONV:	ANI	0FH
	ADI	90H
	DAA
	ACI	40H
	DAA
	RET
;
;
NIBBL:	SUI	'0'
	RC
	ADI	0E9H
	RC
	ADI	6
	JP	NIBB1
	ADI	7
	RC
NIBB1:	ADI	10
	ORA	A
	RET
;
;
HILO:	INX	H
	MOV	A,H
	ORA	L
	STC
	RZ
	MOV	A,E
	SUB	L
	MOV	A,D
	SBB	H	;RETURN WITH CY=1 IF HL > DE
	RET
;
;
EXPR:	CALL	PARAM
	XTHL
	PUSH	H
	DCR	C
	JNC	EXPR1
	JNZ	GOMON
	RET
EXPR1:	JNZ	EXPR
	JMP	GOMON
PARAM:	CALL	PCHK
	JZ	GOMON
	LXI	H,0
PAR1:	MOV	B,A
	CALL	NIBBL
	JC	PAR2
	DAD	H
	DAD	H
	DAD	H
	DAD	H
	ORA	L
	MOV	L,A
	CALL	TI
	JMP	PAR1
PAR2:	MOV	A,B
	CALL	PCHK1
	JNZ	GOMON
	RET
PCHK:	CALL	TI
PCHK1:	CPI	' '
	RZ
	CPI	','
	RZ
	CPI	CR
	STC
	RZ
	CMC
	RET
;
;
; PRINT MEMORY AND LOOK FOR ASCII CHARACTERS
;
PASCI:	LHLD	STACK
	SPHL
	CALL	STFIN
	CALL	LCRLF
	LHLD	FINSH
	XCHG
	LHLD	START
PASC1:	MVI	B,64
	CALL	DADR
	MVI	A,' '
	CALL	LO
PASC2:	MOV	A,M
	CPI	20H
	JC	PASC4
	CPI	5FH
	JNC	PASC4
	MOV	A,M
PASC3:	CALL	LO
	CALL	HILO
	JC	PASC5
	DCR	B
	JNZ	PASC2
	CALL	LCRLF
	JMP	PASC1
PASC4:	MVI	A,'.'
	JMP	PASC3
PASC5:	MVI	B,8
PASC6:	CALL	LCRLF
	DCR	B
	JNZ	PASC6
	JMP	BEG2
;
;
;
MSG1:	DB	'PUNCH THE SOURCE ? ( Y OR ANY CHARACTER ) ',4
MSG2:	DB	'PRINT ASCII DUMP ? ( Y OR ANY CHARACTER ) ',4
MSGST:	DB	'START ADDRESS , FINISH ADDRESS , OFFSET = ',4
;
;
;
TABL1:	DB	1,4,1,1,1,1,2,1,1,1,1,1,1,1,2,1	;00-0F
	DB	1,4,1,1,1,1,2,1,1,1,1,1,1,1,2,1	;10-1F
	DB	1,4,4,1,1,1,2,1,1,1,4,1,1,1,2,1	;20-2F
	DB	1,4,4,1,1,1,2,1,1,1,4,1,1,1,2,1	;30-3F
	DB	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1	;40-4F
	DB	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1	;50-5F
	DB	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1	;60-6F
	DB	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1	;70-7F
	DB	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1	;80-8F
	DB	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1	;90-9F
	DB	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1	;A0-AF
	DB	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1	;B0-BF
	DB	1,1,4,4,4,1,2,1,1,1,4,1,4,4,2,1	;C0-CF
	DB	1,1,4,2,4,1,2,1,1,1,4,2,4,1,2,1	;D0-DF
	DB	1,1,4,1,4,1,2,1,1,1,4,1,4,1,2,1	;E0-EF
	DB	1,1,4,1,4,1,2,1,1,1,4,1,4,1,2,1	;F0-FF
;
; START ADDRESS TABLE FOR MNEMONIC MESSAGE PRINTING
;
TABL2:	DW	P00,P01,P02,P03,P04,P05,P06,P07
	DW	P08,P09,P0A,P0B,P0C,P0D,P0E,P0F
	DW	P10,P11,P12,P13,P14,P15,P16,P17
	DW	P18,P19,P1A,P1B,P1C,P1D,P1E,P1F
	DW	P20,P21,P22,P23,P24,P25,P26,P27
	DW	P28,P29,P2A,P2B,P2C,P2D,P2E,P2F
	DW	P30,P31,P32,P33,P34,P35,P36,P37
	DW	P38,P39,P3A,P3B,P3C,P3D,P3E,P3F
	DW	P40,P41,P42,P43,P44,P45,P46,P47
	DW	P48,P49,P4A,P4B,P4C,P4D,P4E,P4F
	DW	P50,P51,P52,P53,P54,P55,P56,P57
	DW	P58,P59,P5A,P5B,P5C,P5D,P5E,P5F
	DW	P60,P61,P62,P63,P64,P65,P66,P67
	DW	P68,P69,P6A,P6B,P6C,P6D,P6E,P6F
	DW	P70,P71,P72,P73,P74,P75,P76,P77
	DW	P78,P79,P7A,P7B,P7C,P7D,P7E,P7F
	DW	P80,P81,P82,P83,P84,P85,P86,P87
	DW	P88,P89,P8A,P8B,P8C,P8D,P8E,P8F
	DW	P90,P91,P92,P93,P94,P95,P96,P97
	DW	P98,P99,P9A,P9B,P9C,P9D,P9E,P9F
	DW	PA0,PA1,PA2,PA3,PA4,PA5,PA6,PA7
	DW	PA8,PA9,PAA,PAB,PAC,PAD,PAE,PAF
	DW	PB0,PB1,PB2,PB3,PB4,PB5,PB6,PB7
	DW	PB8,PB9,PBA,PBB,PBC,PBD,PBE,PBF
	DW	PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7
	DW	PC8,PC9,PCA,PCB,PCC,PCD,PCE,PCF
	DW	PD0,PD1,PD2,PD3,PD4,PD5,PD6,PD7
	DW	PD8,PD9,PDA,PDB,PDC,PDD,PDE,PDF
	DW	PE0,PE1,PE2,PE3,PE4,PE5,PE6,PE7
	DW	PE8,PE9,PEA,PEB,PEC,PED,PEE,PEF
	DW	PF0,PF1,PF2,PF3,PF4,PF5,PF6,PF7
	DW	PF8,PF9,PFA,PFB,PFC,PFD,PFE,PFF
;
; PRINT MESSAGE LIST
;
P00:	DB	'NOP',4
P01:	DB	'LXI   B,',4
P02:	DB	'STAX  B',4
P03:	DB	'INX   B',4
P04:	DB	'INR   B',4
P05:	DB	'DCR   B',4
P06:	DB	'MVI   B,',4
P07:	DB	'RLC',4
P08:	DB	'DB	08H',4
P09:	DB	'DAD   B',4
P0A:	DB	'LDAX  B',4
P0B:	DB	'DCX   B',4
P0C:	DB	'INR   C',4
P0D:	DB	'DCR   C',4
P0E:	DB	'MVI   C,',4
P0F:	DB	'RRC',4
P10:	DB	'DB	10H',4
P11:	DB	'LXI   D,',4
P12:	DB	'STAX  D',4
P13:	DB	'INX   D',4
P14:	DB	'INR   D',4
P15:	DB	'DCR   D',4
P16:	DB	'MVI   D,',4
P17:	DB	'RAL',4
P18:	DB	'DB	18H',4
P19:	DB	'DAD   D',4
P1A:	DB	'LDAX  D',4
P1B:	DB	'DCX   D',4
P1C:	DB	'INR   E',4
P1D:	DB	'DCR   E',4
P1E:	DB	'MVI   E,',4
P1F:	DB	'RAR',4
P20:	DB	'RIM',4		;8085 ENHANCEMENT
P21:	DB	'LXI   H,',4
P22:	DB	'SHLD  ',4
P23:	DB	'INX   H',4
P24:	DB	'INR   H',4
P25:	DB	'DCR   H',4
P26:	DB	'MVI   H,',4
P27:	DB	'DAA',4
P28:	DB	'DB	28H',4
P29:	DB	'DAD   H',4
P2A:	DB	'LHLD  ',4
P2B:	DB	'DCX   H',4
P2C:	DB	'INR   L',4
P2D:	DB	'DCR   L',4
P2E:	DB	'MVI   L,',4
P2F:	DB	'CMA',4
P30:	DB	'RIM',4		;8085 ENHANCEMENT
P31:	DB	'LXI   SP,',4
P32:	DB	'STA   ',4
P33:	DB	'INX   SP',4
P34:	DB	'INR   M',4
P35:	DB	'DCR   M',4
P36:	DB	'MVI   M,',4
P37:	DB	'STC',4
P38:	DB	'DB	38H',4
P39:	DB	'DAD   SP',4
P3A:	DB	'LDA   ',4
P3B:	DB	'DCX   SP',4
P3C:	DB	'INR   A',4
P3D:	DB	'DCR   A',4
P3E:	DB	'MVI   A,',4
P3F:	DB	'CMC',4
P40:	DB	'MOV   B,B',4
P41:	DB	'MOV   B,C',4
P42:	DB	'MOV   B,D',4
P43:	DB	'MOV   B,E',4
P44:	DB	'MOV   B,H',4
P45:	DB	'MOV   B,L',4
P46:	DB	'MOV   B,M',4
P47:	DB	'MOV   B,A',4
P48:	DB	'MOV   C,B',4
P49:	DB	'MOV   C,C',4
P4A:	DB	'MOV   C,D',4
P4B:	DB	'MOV   C,E',4
P4C:	DB	'MOV   C,H',4
P4D:	DB	'MOV   C,L',4
P4E:	DB	'MOV   C,M',4
P4F:	DB	'MOV   C,A',4
P50:	DB	'MOV   D,B',4
P51:	DB	'MOV   D,C',4
P52:	DB	'MOV   D,D',4
P53:	DB	'MOV   D,E',4
P54:	DB	'MOV   D,H',4
P55:	DB	'MOV   D,L',4
P56:	DB	'MOV   D,M',4
P57:	DB	'MOV   D,A',4
P58:	DB	'MOV   E,B',4
P59:	DB	'MOV   E,C',4
P5A:	DB	'MOV   E,D',4
P5B:	DB	'MOV   E,E',4
P5C:	DB	'MOV   E,H',4
P5D:	DB	'MOV   E,L',4
P5E:	DB	'MOV   E,M',4
P5F:	DB	'MOV   E,A',4
P60:	DB	'MOV   H,B',4
P61:	DB	'MOV   H,C',4
P62:	DB	'MOV   H,D',4
P63:	DB	'MOV   H,E',4
P64:	DB	'MOV   H,H',4
P65:	DB	'MOV   H,L',4
P66:	DB	'MOV   H,M',4
P67:	DB	'MOV   H,A',4
P68:	DB	'MOV   L,B',4
P69:	DB	'MOV   L,C',4
P6A:	DB	'MOV   L,D',4
P6B:	DB	'MOV   L,E',4
P6C:	DB	'MOV   L,H',4
P6D:	DB	'MOV   L,L',4
P6E:	DB	'MOV   L,M',4
P6F:	DB	'MOV   L,A',4
P70:	DB	'MOV   M,B',4
P71:	DB	'MOV   M,C',4
P72:	DB	'MOV   M,D',4
P73:	DB	'MOV   M,E',4
P74:	DB	'MOV   M,H',4
P75:	DB	'MOV   M,L',4
P76:	DB	'HLT',4
P77:	DB	'MOV   M,A',4
P78:	DB	'MOV   A,B',4
P79:	DB	'MOV   A,C',4
P7A:	DB	'MOV   A,D',4
P7B:	DB	'MOV   A,E',4
P7C:	DB	'MOV   A,H',4
P7D:	DB	'MOV   A,L',4
P7E:	DB	'MOV   A,M',4
P7F:	DB	'MOV   A,A',4
P80:	DB	'ADD   B',4
P81:	DB	'ADD   C',4
P82:	DB	'ADD   D',4
P83:	DB	'ADD   E',4
P84:	DB	'ADD   H',4
P85:	DB	'ADD   L',4
P86:	DB	'ADD   M',4
P87:	DB	'ADD   A',4
P88:	DB	'ADC   B',4
P89:	DB	'ADC   C',4
P8A:	DB	'ADC   D',4
P8B:	DB	'ADC   E',4
P8C:	DB	'ADC   H',4
P8D:	DB	'ADC   L',4
P8E:	DB	'ADC   M',4
P8F:	DB	'ADC   A',4
P90:	DB	'SUB   B',4
P91:	DB	'SUB   C',4
P92:	DB	'SUB   D',4
P93:	DB	'SUB   E',4
P94:	DB	'SUB   H',4
P95:	DB	'SUB   L',4
P96:	DB	'SUB   M',4
P97:	DB	'SUB   A',4
P98:	DB	'SBB   B',4
P99:	DB	'SBB   C',4
P9A:	DB	'SBB   D',4
P9B:	DB	'SBB   E',4
P9C:	DB	'SBB   H',4
P9D:	DB	'SBB   L',4
P9E:	DB	'SBB   M',4
P9F:	DB	'SBB   A',4
PA0:	DB	'ANA   B',4
PA1:	DB	'ANA   C',4
PA2:	DB	'ANA   D',4
PA3:	DB	'ANA   E',4
PA4:	DB	'ANA   H',4
PA5:	DB	'ANA   L',4
PA6:	DB	'ANA   M',4
PA7:	DB	'ANA   A',4
PA8:	DB	'XRA   B',4
PA9:	DB	'XRA   C',4
PAA:	DB	'XRA   D',4
PAB:	DB	'XRA   E',4
PAC:	DB	'XRA   H',4
PAD:	DB	'XRA   L',4
PAE:	DB	'XRA   M',4
PAF:	DB	'XRA   A',4
PB0:	DB	'ORA   B',4
PB1:	DB	'ORA   C',4
PB2:	DB	'ORA   D',4
PB3:	DB	'ORA   E',4
PB4:	DB	'ORA   H',4
PB5:	DB	'ORA   L',4
PB6:	DB	'ORA   M',4
PB7:	DB	'ORA   A',4
PB8:	DB	'CMP   B',4
PB9:	DB	'CMP   C',4
PBA:	DB	'CMP   D',4
PBB:	DB	'CMP   E',4
PBC:	DB	'CMP   H',4
PBD:	DB	'CMP   L',4
PBE:	DB	'CMP   M',4
PBF:	DB	'CMP   A',4
PC0:	DB	'RNZ',4
PC1:	DB	'POP   B',4
PC2:	DB	'JNZ   ',4
PC3:	DB	'JMP        ',4
PC4:	DB	'CNZ   ',4
PC5:	DB	'PUSH  B',4
PC6:	DB	'ADI   ',4
PC7:	DB	'RST   0',4
PC8:	DB	'RZ',4
PC9:	DB	'RET',4
PCA:	DB	'JZ    ',4
PCB:	DB	'DB	0CBH',4
PCC:	DB	'CZ    ',4
PCD:	DB	'CALL  ',4
PCE:	DB	'ACI   ',4
PCF:	DB	'RST   1',4
PD0:	DB	'RNC',4
PD1:	DB	'POP   D',4
PD2:	DB	'JNC   ',4
PD3:	DB	'OUT   ',4
PD4:	DB	'CNC   ',4
PD5:	DB	'PUSH  D',4
PD6:	DB	'SUI   ',4
PD7:	DB	'RST   2',4
PD8:	DB	'RC',4
PD9:	DB	'DB	0D9H',4
PDA:	DB	'JC    ',4
PDB:	DB	'IN    ',4
PDC:	DB	'CC    ',4
PDD:	DB	'DB	0DDH',4
PDE:	DB	'SBI   ',4
PDF:	DB	'RST   3',4
PE0:	DB	'RPO',4
PE1:	DB	'POP   H',4
PE2:	DB	'JPO   ',4
PE3:	DB	'XHTL',4
PE4:	DB	'CPO   ',4
PE5:	DB	'PUSH  H',4
PE6:	DB	'ANI   ',4
PE7:	DB	'RST   4',4
PE8:	DB	'RPE',4
PE9:	DB	'PCHL',4
PEA:	DB	'JPE   ',4
PEB:	DB	'XCHG',4
PEC:	DB	'CPE   ',4
PED:	DB	'DB	0EDH',4
PEE:	DB	'XRI   ',4
PEF:	DB	'RST   5',4
PF0:	DB	'RP',4
PF1:	DB	'POP   PSW',4
PF2:	DB	'JP    ',4
PF3:	DB	'DI',4
PF4:	DB	'CP    ',4
PF5:	DB	'PUSH  PSW',4
PF6:	DB	'ORI   ',4
PF7:	DB	'RST   6',4
PF8:	DB	'RM',4
PF9:	DB	'SPHL',4
PFA:	DB	'JM    ',4
PFB:	DB	'EI',4
PFC:	DB	'CM    ',4
PFD:	DB	'DB	0FDH',4
PFE:	DB	'CPI   ',4
PFF:	DB	'RST   7',4
;
;
;
;
;	THIS IS THE STACK
;
;	IT RUNS FROM THE END OF THE TABLES TO
;	THE START OF THE CODE ADDED FOR THE COMPUCOLOR II
;
	ORG	LOAD+13FFH
;
THESTK:			;THE STACK IS DECREMENTED FROM HERE
;
;
;
LF	EQU	10	;LINE FEED
FF	EQU	12	;FORM FEED
BS	EQU	26	;LEFT CURSOR (BACKSPACE)
ESC	EQU	27	;ESCAPE
RATE	EQU	88H	;PRINTER BAUD RATE 88H = 1200 BAUD
EMESS	EQU	262DH	;FCS ERROR SUBROUTINE
RESET	EQU	26A5H	;RESET DISK ON ERROR
OPEN	EQU	2DABH	;OPENS A FILE
			;HL->FPB
PFSPC	EQU	3077H	;PARSE FILE SPECIFICATION
INSEQO	EQU	30E7H	;INITIALIZES A SEQUENTIAL OUTPUT FILE
			;INPUTS:	HL->	FPB
			;OUTPUTS:	A	LOST
			;		BC,DE	UNCHANGED
			;		HL->	FPB
CLSEQO	EQU	3136H	;CLOSES A NEWLY CREATED SEQUENTIAL FILE
			;INPUTS:	HL->	FPB
			;OUTPUTS:	A	LOST
			;		BC,DE	LOST
			;		HL->	FPB IF NO ERROR
			;STATUS:	<NC>	NO ERRORS
			;		<C>	ERROR
			;		B=	ERROR CODE
PTBYT	EQU	324AH	;PUTS A BYTE ON A FILE
			;INPUTS:	HL->	FPB
			;		A=	THE BYTE
			;OUTPUTS:	A=	THE BYTE
			;		BC,DE	UNCHANGED
			;STATUS:	<NC>	NO ERRORS
			;		<C,Z>	END OF FILE
			;		<C,NZ>	M=ERROR
;
ADHLA	EQU	3518H	;ADDS A TO HL WITH CARRYS
SAVE	EQU	3FD0H	;SAVES REGISTERS
;
;	DEFINITION OF OFFSETS
;
FOPT	EQU	0
FATR	EQU	1
FNAM	EQU	2
FTYP	EQU	8
FVER	EQU	11
FSBK	EQU	12
FSIZ	EQU	14
FLBC	EQU	16
FLAD	EQU	17
FSAD	EQU	19
FSPR	EQU	21
FDBK	EQU	22
FDEN	EQU	23
FAUX	EQU	24
FHAN	EQU	26
FFCN	EQU	28
FDRV	EQU	29
FBLK	EQU	30
FBUF	EQU	32
FXBC	EQU	34
FPTR	EQU	36
;
CCIICO	EQU	3392H	;SEND CHARACTER TO SCREEN
OS	EQU	33F4H	;SEND STRING TO SCREEN (239=END)
INPCRT	EQU	81C5H	;JUMP VECTOR NUMBER 31
KBDFL	EQU	81DFH	;HOLDS NUMBER OF JUMP VECTOR
BRATE	EQU	81E2H	;CURRENT BAUD RATE
KBCHA	EQU	81FEH	;KEYBOARD CHARACTER
READY	EQU	81FFH	;KEYBOARD READY FLAG
;
;
;
;
;
;
;
FIRST:	LXI	H,0	;SAVE FCS STACK POINTER
	DAD	SP
	SHLD	FCSSP
	LXI	SP,THESTK;SETUP THE STACK
			;
	MVI	A,RATE	;GET THE BAUD RATE
	OUT	5	;TELL 5501
	STA	BRATE	;TELL FCS
			;
	MVI	A,31	;SET UP VECTOR
	STA	KBDFL	;TO INPCRT
	MVI	A,0C3H	;LITERALLY JMP
	STA	INPCRT
	LXI	H,CHRINT;THUS
	SHLD	INPCRT+1;INPCRT: JMP	CHRINT
	LXI	H,INBUF	;POINT TO COUNTER
	MVI	M,0	;CLEAR COUNTER
	LXI	H,FPBO	;POINT TO OUTPUT FBP
	MVI	M,0	;INDICATE FILE NOT IN USE
			;
	LXI	H,MSG0	;PROGRAM IDENTIFICATION
	CALL	OS	;OUTPUT STRING TO SCREEN
	JMP	BEGIN	;GO TO ORIGINAL DISASSEMBLER
;
;
;	THIS ROUTINE ASKS FOR THE DISK FILE NAME
;	OF THE SOURCE OUTPUT
;
;
SETUP:	LXI	H,MSGFN	;PUNCH FILE NAME PROMPT
	CALL	OS
	CALL	RESET	;RESET DISK IF ERROR
	LXI	H,BUFFER;POINT AT BUFFER
SET01:	CALL	CI	;READ FROM CONSOLE
	CPI	CR	;IS IT CARRIAGE RETURN ?
	JZ	SET03	;YES GO PROCESS CR
	CPI	BS	;IS IT BS ?
	JZ	SET02	;YES GO PROCESS BACKSPACE
	MOV	M,A	;STORE CHARACTER
	INX	H	;BUMP POINTER
	JMP	SET01	;CONTINUE LOOP
SET02:	MOV	A,L	;TEST LO BYTE OF POINTER
	ORA	A	;IF ZERO THEN RESTART READ
	JZ	SETUP
	MVI	A,' '	;ELSE SPACE OVER
	CALL	CCIICO
	MVI	A,BS	;PRINT BACKSPACE
	CALL	CCIICO
	DCX	H
	JMP	SET01	;CONTINUE LOOP
SET03:	MVI	M,0	;INSERT TERMINATOR
	MVI	A,CR	;PRINT CARRIAGE RETURN
	CALL	CCIICO
	MVI	A,LF	;PRINT LINEFEED
	CALL	CCIICO
	LXI	H,BUFFER;POINT AT BUFFER
	LXI	D,FPBO	;POINT AT OUTPUT FPB
	LXI	B,DEFLT	;POINT AT DEFAULT FILE TYPE
	CALL	PFSPC	;PARSE FILE SPEC
	JC	SET04	;IF CARRY THEN ERROR
	MOV	A,M	;TEST FOR END
	MVI	B,9	;SETUP FOR SYNTAX ERROR
	ORA	A
	JNZ	SET04
	LXI	H,FPBO	;POINT AT OUTPUT FILE
	MVI	A,1	;SETUP AS NEW FILE
	MOV	M,A
	CALL	OPEN	;OPEN THE FILE
	JC	SET04
	LXI	H,BUFFER;POINT AT OUTPUT BUFFER
	SHLD	FPBO+FBUF;SAVE OUTPUT BUFFER ADDRESS
	LXI	H,512	;SETUP BUFFER SIZE
	SHLD	FPBO+FXBC;SAVE OUTPUT BUFFER SIZE
	LXI	H,FPBO	;POINT AT OUTPUT BUFFER
	CALL	INSEQO	;INITIALIZE OUTPUT FILE
	RET
SET04:	CALL	EMESS	;REPORT FCS ERROR
	JMP	SETUP	;KEEP TRYING
;
;
;	COMPUCOLOR DEMO CI ROUTINE
;	THIS SHOWS HOW TO READ A CHARACTER
;	AND ESCAPE FROM A HUNG PROGRAM
;
;	CHRINT IS CALLED WHENEVER A KEY IS STRUCK
;	THE JMP IS FROM INPCRT
;
;
CHRINT:	CALL	SAVE	;SAVE REGISTERS
	LXI	H,INBUF
	MVI	A,30	;LENGTH OF BUFFER
	CMP	M	;SEE IF BUFFER IS FULL
	RC		;IF IT IS IGNORE CHARACTER
	INR	M	;INCREMENT COUNTER
	MOV	A,M	;PUT COUNT IN A
	CALL	ADHLA	;ADD COUNTER TO BEGINNING OF BUFFER
	MOV	A,E	;CHARACTER IS IN E
	CPI	ESC	;SEE IF ESCAPE HAS BEEN HIT
	JZ	BREAK	;USER WANTS TO EXIT
	ANI	127	;MAKE SURE ITS ASCII
	MOV	M,A	;STORE IT
	RET
;
;
;	BREAK ALLOWS THE USER TO BRANCH TO A LOCATION
;	WHEN THE ESCAPE KEY IS STRUCK.  IN THIS CASE
;	THE LOCATION IS CALLED BAILOUT.
;
;
BREAK:	JMP	BAILOUT	;NO FURTHER PROCESSING REQUIRED
;

;
INBUF:	DS	32	;STORAGE AREA FOR TYPE AHEAD
;
;
;
;
;	CI READS AND ECHOS ONE CHARACTER FROM THE KEYBOARD
;

CIX:	PUSH	H	;SAVE H
	LXI	H,INBUF
CI1:	MOV	A,M	;READ COUNTER
	ANA	A	;SEE IF ZERO
	JZ	CI1	;LOOK AND WAIT IF ZERO
	DI		;HOLD OFF INTERRUPTS WHILE PROCESSING
	PUSH	D	;SAVE D
	DCR	M	;REDUCE BUFFER COUNTER
	MOV	D,M
	INX	H	;POINT TO CHARACTER
	MOV	A,M	;READ IT
	PUSH	PSW	;STACK IT
CI2:	DCR	D	;SHIFT COUNTER
	JM	CI3	;WHEN DONE
	INX	H	;CHARACTER TO BE SHIFTED
	MOV	A,M
	DCX	H	;POINT TO NEW HOME
	MOV	M,A	;NEW HOME
	INX	H
	JMP	CI2	;LOOP UNTIL DONE
CI3:	EI		;ENABLE INTERRUPTS
	POP	PSW	;THE CHARACTER
	PUSH	PSW	;SAVED AGAIN
	CALL	CCIICO	;ECHO IT
	POP	PSW	;THE CHARACTER
	POP	D	;<DE> AND <HL>
	POP	H	;UNCHANGED
	RET
;
;
;	COMPUCOLOR CONSOLE OUTPUT ROUTINE
;
;
COX:	JMP	CCIICO	;ROM ROUTINE TO DISPLAY CHARACTER IN A
;
;
;	COMPUCOLOR PRINT ROUTINE
;
;
LOX:	PUSH	D	;SAVE <DE>
	MOV	E,A	;CHARACTER TO BE PRINTED
LOX1:	IN	03H	;EXACT COPY OF ROM ROUTINE
	ANI	10H	;SHOWS CLEAR-TO-SEND HANDSHAKE
	JZ	LOX1	;JUMP IF XMT BUFFER NOT EMPTY
	IN	01H	;CLEAR-TO-SEND OK?
	ANI	80H	;
	JZ	LOX1	;NO
	MOV	A,E	;GET CHARACTER
	OUT	06H	;SEND IT
	CALL	CCIICO	;DISPLAY IT ON THE SCREEN TOO!
	POP	D	;RESTORE <DE>
	RET
;
;
;	COMPUCOLOR PUNCH ROUTINE
;
;
PUNCH:	PUSH	H	;SAVE <HL>
	LXI	H,FPBO	;POINT TO FPB
	CALL	PTBYT	;PUT A BYTE TO DISK
	POP	H	;RESTORE <HL>
	RNC		;RETURN IF NO ERROR
ERROR:	LXI	H,ERMSG	;PRINT ERROR MESSAGE
	CALL	OS
;
;
			;HERE ON FCS ERROR
BAILOUT:		;HERE ON USER REQUEST
EXIT:			;HERE WHEN DONE
;
;
	LXI	H,FPBO	;POINT AT OUTPUT FILE
	MOV	A,M	;GET FILE IN USE INDICATOR
	MVI	B,0	;SET NO ERROR FOR FCS IF NO FILE IN USE
	JZ	NOFILE	;JUMP IF FILE NOT IN USE
	CALL	CLSEQO	;CLOSE OUTPUT FILE
NOFILE:	LHLD	FCSSP	;RESTORE FCS STACK
	SPHL
	RET		;GO BACK TO FCS
;
;
MSG0:	DB	12,18,11,'COMPUCOLOR ',19,'II '
	DB	21,'DIS-ASSEMBLER ',22,'13 SEP 80',CR,LF,239
MSGFN:	DB	19,11,'DISK OUTPUT FILE> ',18,239
ERMSG:	DB	17,'HARDWARE ERROR !',CR,LF,239
;
DEFLT:	DB	'DIS'	;DEFAULT FILE TYPE FOR DIS-ASSEMBLER
;
FCSSP:	DW	0	;THE STACK POINTER USED BY THE FCS
;
FPBO:	DS	38	;OUTPUT FILE PARAMETER BLOCK
BUFFER:	DS	512	;CHARACTER INPUT BUFFER
;
;
;
	END	LOAD