home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
CPM
/
MISC
/
INSIDCPM.LBR
/
CISUB.LQB
/
CISUB.LIB
Wrap
Text File
|
2000-06-30
|
2KB
|
83 lines
; * * * * * CISUB.LIB : Console Input Aids
;
; MACRO to create a line buffer with one additional
; byte used by the CIGETC subroutine
;
CIBUFF MACRO ?SIZE
DB 0 ; index for CIGETC
DB ?SIZE ; buffer size for BDOS
DB 0 ; returned length of data
DS ?SIZE ; space for the data
ENDM
;
; MACRO to test if a key has been pressed at the
; terminal. Operand is the label of a termination
; or user-communication routine.
;
CITEST MACRO ?CALL
SERVICE 11
ORA A ; has a key been hit?
CNZ ?CALL ; if so, call given routine
ENDM
;
; SET of subroutines for console line input
;
CISUBM MACRO
;
; CILINE: READ a line of input to a line buffer (declared with
; the CIBUFF macro)
; INPUT: HL --> the line buffer (preserved)
; OUTPUT: BUFFER filled. A = number of bytes, Z-flag set if
; the input was a null line.
;
CILINE EQU $
PUSH H ; save BUFFER address
MVI M,00 ; zero index byte for CIGETC
INX H ; HL --> buffer for BDOS
XCHG ; put in DE for BDOS,
SERVICE 10 ; .. fill the BUFFER
XCHG ; recover caller's DE
INX H ; HL --> length of data
MOV A,M ; .. put in A
ORA A ; set Z-flag from length
POP H ; restore HL --> BUFFER
RET
;
; CIGETC: GET next byte from a line buffer
; INPUT: HL --> the line BUFFER (preserved)
; OUTPUT: A = next byte. If there is none, A = CR and
; the Z-flag is set.
;
CIGETC EQU $
PUSH B ; save a work register
PUSH H ; and the buffer address
MOV A,M ; copy index byte,
INR M ; .. and step it for next time
INX H ! INX H ; HL --> length of data
CMP M ; index < length?
JC CIGETC2 ; yes (data remains)
MVI A,CR ; no, return a CR
JMP CIGETC3
CIGETC2 MOV C,A ; compute offset to data from HL:
MVI B,0 ; (HL+1) --> first byte in buffer
INX B
DAD B ; HL --> wanted byte
MOV A,M ; pick it up
CIGETC3 CPI CR ; set Z-flag for end of line
POP H ! POP B ; recover registers
RET
;
; CIGETNB: GET next non-blank from a line buffer
; INPUT: HL --> BUFFER (preserved)
; OUTPUT: as for CIGETC, but never a blank.
;
CIGETNB EQU $
CALL CIGETC ; get a byte
RZ ; .. exit if end of line
CPI BLANK ; if it isn't blank,
RNZ ; .. return
JMP CIGETNB
;
; * * * * * END OF CISUB.LIB
ENDM