Compucolor.org – Virtual Media

Listing of file='COPY.SRC;01' on disk='vmedia/taylor_7-sector.ccvf'


;	SAMPLE PROGRAM

;	SYSTEM ADDRESSES

CO	EQU	3392H		;SEND CHARACTER TO SCREEN
OS	EQU	33F4H		;SEND STRING ENDING WITH 239

EMESS	EQU	262DH		;FCS ERROR SUBROUTINE
PFSPC	EQU	3077H		;PARSE FILE SPEC
RESET	EQU	26A5H
OPEN	EQU	2DABH		;OPENS A FILE
				;HL=>FPB

RWSEQI	EQU	30C6H		;'REWINDS' A SEQUENTIAL FILE
				;INPUTS:	HL=>FPB
				;OUTPUTS:	A-LOST
				;		BC,DE UNCHANGED
				;		HL=>FPB
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 ERRORS
				;STATUS:	<NC> NO ERRORS
				;		<C> ERROR
				;		B=ERROR CODE
GTBYT	EQU	322CH		;GETS A SINGLE BYTE FROM FILE
				;INPUT HL=>FPB
				;OUTPUTS	A=BYTE
				;		BC,DE UNCHANGED
				;STATUS:	NC=NO ERRORS
				;		C,Z=END OF FILE
				;		C,NZ,M=ERROR

PTBYT	EQU	324AH		;PUTS A BYTE ON A FILE
				;INPUTS HL=>FPB,A=THE BYTE
				;OUTPUTS	A=THE BYTE
				;		BC,DE UNCHANGED
				;STATUS:	SAME AS GTBYT
ADHLA	EQU	3518H		;ADDS A TO HL WITH CARRYS
INPCRT	EQU	81C5H		;JUMP VECTOR NUMBER 31
KBDFL	EQU	81DFH		;HOLDS NUMBER OF JUMP VECTOR

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

;	SPECIAL CONTROL CHARACTERS

CR	EQU	13
LF	EQU	10
FF	EQU	12

;	START OF PROGRAM
	ORG	8200H

START:	LXI	H,0		; SAVE FCS STACK POINTER
	DAD	SP
	SHLD	FCSSP
	LXI	SP,STACK	; SETUP RUNOFF STACK
	MVI	A,31		;SET UP VECTOR
	STA	KBDFL		;TO INPCRT
	MVI	A,0C3H		;LITERALLY JMP
	STA	INPCRT
	LXI	H,CHRINT	;THUS
				;INPCRT:	JMP	CHRINT
	SHLD	INPCRT+1
	LXI	H,INBUF		;POINT TO COUNTER
	MVI	M,0		;CLEAR COUNTER

	LXI	H,MSG00		; PRINT STARTUP MESSAGE
	CALL	OS

	CALL	SETUP		; INITIALIZE FILES

LOOP:	LXI	H,FPB1
	CALL	GTBYT
	JC	LOOPE1
	LXI	H,FPB2
	CALL	PTBYT
	JNC	LOOP

LOOPE2:	JMP	ERROR

LOOPE1:	JZ	EOF		;AT END OF FILE - CLOSE OUTPUT
	JMP	ERROR

SETUP:	LXI	H,MSG01		; DISPLAY PROMPT
	CALL	OS
	CALL	RESET		; RESET DISK IF ERROR
	LXI	H,BUFFER	; POINT AT BUFFER
L02:	CALL	CI		; READ FROM CONSOLE
	CPI	13		; IS IT CR ?
	JZ	X02		; YES, GO PROCESS CR
	CPI	26		; IS IT BS ?
	JZ	G021		; YES, GO PROCESS BACKSPACE
	MOV	M,A		; STORE CHARACTER
	INX	H		; BUMP POINTER
	JMP	L02		; CONTINUE LOOP
G021:	MOV	A,L		; TEST LO BYTE OF POINTER
	ORA	A		; IF ZERO THEN RESTART READ
	JZ	SETUP
	MVI	A,' '		; ELSE SPACE OVER
	CALL	CO
	MVI	A,26		; TYPED DATA
	CALL	CO
	DCX	H
	JMP	L02		; CONTINUE LOOP
X02:	MVI	M,0		; INSERT TERMINATOR
	MVI	A,CR		; PRINT CARRIAGE RETURN
	CALL	CO
	MVI	A,LF		; LINEFEED SEQUENCE
	CALL	CO
	LXI	H,BUFFER	; POINT AT BUFFER
	LXI	D,FPB1		; POINT AT INPUT FPB
	LXI	B,DEFAULT	; POINT AT DEFAULT TYPE
	CALL	PFSPC		; PARSE FILE SPEC
	JC	E02		; IF CARRY THEN ERROR
	MOV	A,M		; TEST FOR END
	MVI	B,9		; SETUP SYNTAX ERROR
	ORA	A
	JNZ	E02
	LXI	H,FPB1		; POINT AT INPUT FPB
	MVI	A,0		; SETUP AS OLD FILE
	MOV	M,A
	CALL	OPEN		; OPEN THE FILE
	JC	E02
	LXI	H,FPB1		; COPY FPB1 TO FPB2
	LXI	D,FPB2
	MVI	B,38
L03:	MOV	A,M
	STAX	D
	INX	H
	INX	D
	DCR	B
	JNZ	L03
	LXI	H,FPB2+FTYP	; POINT AT OUTPUT TYPE
	MVI	M,'D'		; STORE 'D'
	INX	H
	MVI	M,'O'		; STORE 'O'
	INX	H
	MVI	M,'C'		; STORE 'C'
	LXI	H,FPB2		; POINT AT OUTPUT FILE
	MVI	A,1		; SETUP AS NEW FILE
	MOV	M,A
	CALL	OPEN		; OPEN THE FILE
	JC	E02
	LXI	H,IBUF		; POINT AT INPUT BUFFER
	SHLD	FPB1+FBUF	; SAVE INPUT BUFFER ADDRESS
	LXI	H,OBUF		; POINT AT OUTPUT BUFFER
	SHLD	FPB2+FBUF	; SAVE OUTPUT BUFFER ADDRESS
	LXI	H,1024		; SETUP BUFFER SIZE
	SHLD	FPB1+FXBC	; SAVE INPUT BUFFER SIZE
	SHLD	FPB2+FXBC	; SAVE OUTPUT BUFFER SIZE
	LXI	H,FPB1		; POINT AT INPUT FPB
	CALL	RWSEQI		; REWIND INPUT FILE
	LXI	H,FPB2		; POINT AT OUTPUT FPB
	CALL	INSEQO		; INITIALIZE OUTPUT FILE
	RET			; RETURN

	;COMPUCOLOR DEMO CI ROUTINE
	;THIS SHOWS HOW TO READ A CHARACTER
	;AND ESCAPE FROM A HUNG PROGRAM


	;

CHRINT:	;CHRINT IS CALLED WHENEVER A KEY IS STRUCK
	;THE JUMP IS FROM INPCRT

	PUSH	H	;SAVE REGISTERS
	PUSH	PSW
	LXI	H,INBUF
	MVI	A,30	;LENGTH OF BUFFER
	CMP	M	;SEE IF BUFFER IS FULL
	JC	INTEXT	;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	27	;SEE IF ESCAPE HAS BEEN HIT
	JZ	BREAK	;USER WANTS TO EXIT
	ANI	127	;MAKE SURE ITS ASCII
	MOV	M,A	;STORE IT
INTEXT:	POP	PSW
	POP	H	;RESTORE REGISTERS
	EI		;REENABLE INTERUPT
	RET
BREAK:;	BREAK ALLOWS THE USER TO BRANCH TO A LOCATION WHEN THE
	;ESCAPE KEY IS STRUCK.  IN THIS CASE THE LOCATION IS
	;CALLED BAILOUT

	LXI	H,4	;POINT TO RETURN ADDRESS
	DAD	SP	;NOW H POINTS TO RETURN ADDRESS
	MVI	M,BAILOUT AND 255	;STORE LOW ORDER BYTE
	INX	H
	MVI	M,BAILOUT/256	;STORE HIGH ORDER BYTE
	JMP	INTEXT	;EXIT INTO EXIT

INBUF:	DS	32	;STORAGE  AREA FOR TYPE AHEAD

CI:	;CI READS AND ECHOS ONE CHARACTER FROM THE KEYBOARD

	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 INTERUPTS WHILE PROCESSING
	PUSH	D	;SAVE D
	DCR	M	;REDUCE BUFFER COUNTER
	MOV	D,M
	INX	H	;POINT TO CHARACTER
	MOV	A,M	;READ IT
	CALL	CO	;ECHO IT
	PUSH	PSW	;STACK IT
CI2:	DCR	D	;SHIFT COUNTER
	JM	CI3	;WHEN DONE
	INX	H	;CHARCTER 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 INTERUPTS
	POP	PSW	;THE CHARACTER
	POP	D
	POP	H
	RET
E02:	CALL	EMESS		; EMIT ERROR MESSAGE
	JMP	SETUP		; READ NEW LINE


ERROR:	LXI	H,MSG02		; PRINT ERROR MESSAGE
	CALL	OS
BAILOUT:MVI	B,0		; SETUP NO ERROR
EXIT:	LHLD	FCSSP		; RESTORE FCS STACK
	SPHL
	RET			; AND EXIT TO FCS

EOF:	LXI	H,FPB2		; POINT AT OUTPUT FILE
	CALL	CLSEQO		; CLOSE OUTPUT FILE
	JMP	EXIT

;	MESSAGES

MSG00:	DB	18,11,'COMPUCOLOR ',19,'II '
	DB	21,'COPY ',22,'V9.78',13,10,239
MSG01:	DB	19,11,'COPY>',18,239
MSG02:	DB	17,'HARDWARE ERROR !',13,10,239

DEFAULT:DB	'SRC'

;	DATA AREAS


BUFFER:	DS	256
IBUF:	DS	1024	;INPUT BUFFER
OBUF:	DS	1024	;OUTPUT BUFFER

	DS	100	;STACK AREA
STACK:

FCSSP:	DS	2	;FCS STACK POINTER
FPB1:	DS	38	;INPUT FPB
FPB2:	DS	38	;OUTPUT FPB

	END	START