home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / misc / insidcpm.lbr / FT.AQM / FT.ASM
Encoding:
Assembly Source File  |  1985-02-09  |  2.4 KB  |  95 lines

  1. ; * * * * *    FT: builds Files by Typing
  2. ;
  3.     MACLIB    CPMEQU    ; include standard names
  4.     MACLIB    PROG    ; prolog, service macros
  5.     MACLIB    COSUB    ; console output routines
  6.     MACLIB    CISUB    ; cisub for cocrlf only
  7. ;
  8. PROLOG2    FT
  9. ;
  10. ; * * * ERROR MESSAGES
  11. ;
  12. CCMSG    DB    'Can''t close the file',cr,lf,'$'
  13. CWMSG    DB    'Error on write',cr,lf,'$'
  14. CMMSG    DB    'Can''t make the file',cr,lf,'$'
  15. FEMSG    DB    'File exists -- you erase it',cr,lf,'$'
  16. ;
  17. INPUT    CIBUFF    128    ; define line input buffer
  18. ;
  19. FT    EQU    $    ; start of program
  20.     LDA    CPMFCB+1
  21.     CPI    BLANK    ; any operand given?
  22.     RZ        ; done if not
  23. ;
  24.     SERVICE    15,CPMFCB ; open file as for input
  25.     INR    A    ; does file exist?
  26.     JZ    FT2    ; no, continue
  27.     LXI    D,FEMSG    ; yes, quit with a message
  28.     JMP    ERROREXIT
  29. ;
  30. FT2    SERVICE    22,CPMFCB ; new file, make it
  31.     INR    A    ; did that work?
  32.     JNZ    FT3    ; yes, continue
  33.     LXI    D,CMMSG    ; no, quit with a message
  34.     JMP    ERROREXIT
  35. ;
  36. FT3    LXI    D,CPMBUFF ; DE indexes disk buffer
  37.     MVI    B,00    ; [B] counts bytes in it
  38. ;
  39. FTOP    EQU    $    ; here for each console line
  40.     CALL    COCRLF    ; cursor to next screen line
  41.     LXI    H,INPUT
  42.     CALL    CILINE    ; service 10 gets input line
  43.     JZ    FTCLOSE    ; all done if null line
  44. ;
  45. FTLOOP    CALL    CIGETC    ; next inbyte
  46.     JZ    FTEOL    ; (end of line)
  47.     CALL    FTPUT    ; got a byte, put it in file
  48.     JMP    FTLOOP    ; ..and get next
  49. ;
  50. FTEOL    MVI    A,CR    ; end of input line, put
  51.     CALL    FTPUT    ; ..CR, LF into
  52.     MVI    A,LF    ; ..the file
  53.     CALL    FTPUT
  54.     JMP    FTOP    ; then get next line
  55. ;
  56. ;  WHEN a null line is received, fill the rest of the
  57. ;  buffer with EOF marks, write it, and close the file
  58. ;
  59. FTCLOSE    MVI    A,EOF    ; fill disk record with SUBs
  60.     STAX    D
  61.     INX    D
  62.     INR    B
  63.     JP    FTCLOSE
  64.     SERVICE    21,CPMFCB ; then write last record
  65.     ORA    A    ; did it work?
  66.     JNZ    CANT$WRITE
  67.     SERVICE    16,CPMFCB ; close the file
  68.     INR    A    ; check success
  69.     RNZ        ; return to EPILOG if ok
  70.     LXI    D,CCMSG
  71.     JMP    ERROREXIT
  72. ;
  73. ;  Subroutine to stow the byte in [A] in the disk buffer.
  74. ;  DE --> BUFFER, BC counts bytes in it.  write the buffer
  75. ;  when it fills up.
  76. ;
  77. FTPUT    STAX    D    ; put byte in buffer,
  78.     INX    D    ; step buffer index,
  79.     INR    B    ; count bytes in this record
  80.     RP        ; return if not up to 128
  81.     LXI    D,CPMBUFF ; reset buffer ptr,
  82.     MVI    B,00    ; ..and byte count
  83.     SERVICE    21,CPMFCB ; then write record
  84.     ORA    A    ; ..and if it worked
  85.     RZ        ; ..continue in program
  86. CANT$WRITE EQU    $
  87.     LXI    D,CWMSG    ; if it did not,
  88.     JMP    ERROREXIT ; ..quit with a message
  89. ;
  90. ;  COMMON SUBROUTINES
  91. ;
  92.     CISUBM
  93.     COSUBM
  94.     END
  95.