Compucolor.org – Virtual Media

Listing of file='CCIO.MAC;01' on disk='vmedia/tiny_c_v3.0-sector.ccvf'


KBVEC	EQU	81C5H	; KEYBOARD INPUT ROUT. VECTOR
KBDFL	EQU	81DFH	; KEYBOARD INPUT FLAG BYTE
KBSIZE	EQU	32	; LOOKAHEAD SIZE (POWER OF 2)

; PRINT STRING STARTING AT (HL), TERMINATED BY NULL BYTE

	EXTRN	OUTCH

	ENTRY	PS

PS:	MOV	A,M
	ORA	A
	RZ
	CALL	OUTCH
	INX	H
	JMP	PS

; QUIT CATCHES INTERRUPTS (ESC KEY) AT APPL LEVEL.

	KILL	EQU	99

	EXTRN	APPLVL,ESCAPE,ESET

	ENTRY	QUIT

QUIT:	LDA	APPLVL
	ORA	A
	RZ
	CALL	CHRDY
	RZ
	MOV	B,A
	LDA	ESCAPE
	CMP	B
	RNZ
	CALL	INCH
	CALL	ESET
	DB	KILL
	RET

; PRINT (DE) AS SIGNED INTEGER

	ENTRY	PN

PN:	LXI	H,BUFF
	CALL	ITOA
	MVI	M,0
	LXI	H,BUFF
	JMP	PS

BUFF:	DS	40

; CONVERT (DE) TO ASCII SIGNED INTEGER

	EXTRN	DENEG

	ENTRY	ITOA

ITOA:	MOV	A,D
	ORA	A
	JP	NTOA
	CALL	DENEG
	MVI	M,'-'
	INX	H

; CONVERT (DE) TO ASCII UNSIGNED INTEGER

	EXTRN	DDIV

	ENTRY	NTOA

NTOA:	MOV	A,D
	ORA	E
	JNZ	NT2
	MVI	M,'0'
	INX	H
	RET

NT2:	XRA	A
	PUSH	PSW
NT3:	LXI	B,10
	PUSH	H
	CALL	DDIV
	MOV	A,L
	POP	H
	ADI	'0'
	PUSH	PSW
	MOV	A,D
	ORA	E
	JNZ	NT3
NT4:	POP	PSW
	RZ
	MOV	M,A
	INX	H
	JMP	NT4

; PRINT INLINE STRING

	ENTRY	PX

PX:	XTHL		; GET STRING POINTER
	PUSH	PSW	; SAVE REGISTERS
	CALL	PS	; PRINT OUT STRING
	INX	H	; JUMP OVER THE 0
	POP	PSW	; RESTORE REGISTERS
	XTHL
	RET

;	INPUT CHARACTER

	ENTRY	INCH

INCH:	CALL	CHRDY
	JZ	INCH
	PUSH	PSW
	LDA	KBRPTR
	INR	A
	ANI	KBSIZE-1
	STA	KBRPTR
	POP	PSW
	RET

;	TEST FOR CHARACTER

	EXTRN	ADHLA

	ENTRY	CHRDY

CHRDY:	PUSH	H
	LHLD	KBRPTR
	MOV	A,L
	SUB	H
	JZ	CHRDY1
	MOV	A,L
	LXI	H,KBUFF
	CALL	ADHLA
	MOV	A,M
	ORA	A
	JNZ	CHRDY1
	INR	A
CHRDY1:	POP	H
	RET

;	KEYBOARD INTERRUPT ROUTINE

	ENTRY	KBINT

KBINT:	PUSH	H
	PUSH	PSW
	LHLD	KBRPTR
	MOV	A,H
	INR	A
	ANI	KBSIZE-1
	CMP	L
	JZ	KBINT1
	STA	KBWPTR
	MOV	A,H
	LXI	H,KBUFF
	CALL	ADHLA
	MOV	M,E
KBINT1:	POP	PSW
	POP	H
	RET

	PUBLIC	KBRPTR,KBWPTR,KBUFF

KBRPTR:	DB	0	; KEYBOARD READ POINTER
KBWPTR:	DB	0	; KEYBOARD WRITE POINTER
KBUFF:	DS	KBSIZE	; KEYBOARD LOOK AHEAD BUFFER

	END