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
Text File  |  2000-06-30  |  2KB  |  83 lines

  1. ; * * * * *    CISUB.LIB : Console Input Aids
  2. ;
  3. ;    MACRO to create a line buffer with one additional
  4. ;    byte used by the CIGETC subroutine
  5. ;
  6. CIBUFF    MACRO    ?SIZE
  7.     DB    0    ; index for CIGETC
  8.     DB    ?SIZE    ; buffer size for BDOS
  9.     DB    0    ; returned length of data
  10.     DS    ?SIZE    ; space for the data
  11.     ENDM
  12. ;
  13. ;    MACRO to test if a key has been pressed at the
  14. ;    terminal. Operand is the label of a termination
  15. ;    or user-communication routine.
  16. ;
  17. CITEST    MACRO    ?CALL
  18.     SERVICE    11
  19.     ORA    A    ; has a key been hit?
  20.     CNZ    ?CALL    ; if so, call given routine
  21.     ENDM
  22. ;
  23. ;    SET of subroutines for console line input
  24. ;
  25. CISUBM    MACRO
  26. ;
  27. ; CILINE:  READ a line of input to a line buffer (declared with
  28. ;        the CIBUFF macro)
  29. ; INPUT:   HL --> the line buffer (preserved)
  30. ; OUTPUT:  BUFFER filled. A = number of bytes, Z-flag set if
  31. ;        the input was a null line.
  32. ;
  33. CILINE    EQU    $
  34.     PUSH    H    ; save BUFFER address
  35.     MVI    M,00    ; zero index byte for CIGETC
  36.     INX    H    ; HL --> buffer for BDOS
  37.     XCHG        ; put in DE for BDOS,
  38.     SERVICE    10    ; .. fill the BUFFER
  39.     XCHG        ; recover caller's DE
  40.     INX    H    ; HL --> length of data
  41.     MOV    A,M    ; .. put in A
  42.     ORA    A    ; set Z-flag from length
  43.     POP    H    ; restore HL --> BUFFER
  44.     RET
  45. ;
  46. ; CIGETC: GET next byte from a line buffer
  47. ; INPUT:  HL --> the line BUFFER (preserved)
  48. ; OUTPUT: A = next byte. If there is none, A = CR and
  49. ;        the Z-flag is set.
  50. ;
  51. CIGETC    EQU    $
  52.     PUSH    B    ; save a work register
  53.     PUSH    H    ; and the buffer address
  54.     MOV    A,M    ; copy index byte,
  55.     INR    M    ; .. and step it for next time
  56.     INX H ! INX H    ; HL --> length of data
  57.     CMP    M    ; index < length?
  58.     JC    CIGETC2    ; yes (data remains)
  59.     MVI    A,CR    ; no, return a CR
  60.     JMP    CIGETC3
  61. CIGETC2    MOV    C,A    ; compute offset to data from HL:
  62.     MVI    B,0    ;  (HL+1) --> first byte in buffer
  63.     INX    B
  64.     DAD    B    ; HL --> wanted byte
  65.     MOV    A,M    ; pick it up
  66. CIGETC3    CPI    CR    ; set Z-flag for end of line
  67.     POP H ! POP B    ; recover registers
  68.     RET
  69. ;
  70. ; CIGETNB: GET next non-blank from a line buffer
  71. ; INPUT:   HL --> BUFFER (preserved)
  72. ; OUTPUT:  as for CIGETC, but never a blank.
  73. ;
  74. CIGETNB    EQU    $
  75.     CALL    CIGETC    ; get a byte
  76.            RZ        ; .. exit if end of line
  77.     CPI    BLANK    ; if it isn't blank,
  78.     RNZ        ; .. return
  79.     JMP    CIGETNB
  80. ;
  81. ; * * * * *    END OF CISUB.LIB
  82.     ENDM
  83.