home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol090 / systest1.mac < prev    next >
Encoding:
Text File  |  1984-04-29  |  2.5 KB  |  115 lines

  1. ;
  2. ;  PROGRAM:  SYSTEST1
  3. ;  AUTHOR:  Richard Conn
  4. ;  PURPOSE:  This program creates a file and then accepts lines of text
  5. ;        to input into that file.
  6. ;  NOTE:  This test illustrates the use of the byte-oriented file
  7. ;        output routines and the use of SYSLIB.
  8. ;
  9.  
  10. ;  Define the <CR> and <LF> constants
  11. cr    equ    0dh
  12. lf    equ    0ah
  13.  
  14. ;  External Definitions of Routines to be Used
  15.     ext    fname        ; Convert file name into FCB format
  16.     ext    print        ; Print string
  17.     ext    bbline        ; Input Line Editor
  18.     ext    fo0$open    ; Open File for Output
  19.     ext    fo0$close    ; Close File
  20.     ext    f0$put        ; Write Byte to File
  21.  
  22. ;
  23. ;  This part of the program prompts the user for input and inputs a line
  24. ;
  25.     call    print    ; print prompt to user
  26.     db    'SYSTEST1 - Byte-Oriented File Output Demonstration'
  27.     db    cr,lf,'Name of File to Create? ',0
  28.     xra    a    ; A=0 so BBLINE does not capitalize line
  29.     call    bbline    ; input file name from user
  30.     ora    a    ; check char count for zero
  31.     rz        ; return to CP/M if no line input
  32.  
  33. ;
  34. ;  The file name specified by the user is converted into the FCB format
  35. ;  and stored into an FCB
  36. ;
  37. ;  First char of filename is pointed to by HL, as returned by BBLINE
  38. ;
  39.     lxi    d,fcb    ; load fcb
  40.     call    fname
  41.  
  42. ;
  43. ;  Now we open the file for byte-oriented output; since FNAME does not
  44. ;  affect DE, DE still points to the FCB
  45. ;
  46.     call    fo0$open    ; open file for output
  47.     jz    loop    ; ok to proceed
  48.  
  49. ;
  50. ;  File could not be opened -- print error message and abort
  51. ;
  52.     call    print
  53.     db    cr,lf,'Cannot Open File -- Abort',0
  54.     ret
  55.  
  56. ;
  57. ;  This loop prompts the user for a line and stores it in the file.
  58. ;  If the user types an empty line (just <CR>), we exit and close the
  59. ;  output file.
  60. ;
  61. loop:
  62.     call    print    ; print prompt
  63.     db    cr,lf,'Input Line (<CR>=Done)? ',0
  64.     xra    a    ; A=0 so BBLINE does not capitalize line
  65.     call    bbline    ; get line from user
  66.     ora    a    ; check char count
  67.     jz    done    ; done if no chars
  68.  
  69. ;
  70. ;  This loop writes the string pted to by HL (from BBLINE) to disk.
  71. ;
  72. oloop:
  73.     mov    a,m    ; get char
  74.     ora    a    ; done if zero
  75.     jz    odone
  76.     call    f0$put    ; write to disk
  77.     jnz    derr    ; check for disk error
  78.     inx    h    ; pt to next char to output
  79.     jmp    oloop
  80.  
  81. ;
  82. ;  This routine terminates the string just written to disk with a
  83. ;  <CR> <LF> pair, and the creation of the file is continued.
  84. ;
  85. odone:
  86.     mvi    a,cr    ; new line
  87.     call    f0$put
  88.     mvi    a,lf
  89.     call    f0$put
  90.     jmp    loop
  91.  
  92. ;
  93. ;  The user has typed an empty line (just <CR>), so we close the file
  94. ;  and exit.
  95. ;
  96. done:
  97.     call    fo0$close    ; close file
  98.     ret
  99.  
  100. ;
  101. ;  Error message and abort if error occurs while writing to disk.
  102. ;
  103. derr:
  104.     call    print
  105.     db    cr,lf,'Disk Output Error',0
  106.     ret
  107.  
  108. ;
  109. ;  FCB used by program
  110. ;
  111. fcb:
  112.     ds    36
  113.  
  114.     end
  115.