home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / buffers.lbr / TEST3.MZC / TEST3.MAC
Encoding:
Text File  |  1987-01-14  |  3.3 KB  |  128 lines

  1. ; test buffers module. Copy file 1 to file 2
  2. ; This illustrates use of the .BFSWAP routine for single
  3. ; buffering, and fast file to file copying.
  4. ;
  5. ;   d>TEST3 [d[u]:]filename.typ [d[u]:]outname.typ
  6. ;        copies filename.typ to outname.typ
  7. ;        (with full du addressing, across users, drives)
  8. ; SEE BUFFERS.DOC for linking instructions
  9. ;
  10. boot    equ    0
  11. tfcb    equ    boot+05ch
  12. defdma    equ    boot+080h
  13. ;
  14.     extrn    .dos, b.wflg
  15.     extrn    .bload, .bdump, .bfswap
  16.     extrn    .bfropen, .fopnw, .bfclose
  17.     extrn    .pfnmdu, .xltusr, .initfcb
  18. ;
  19. begin:    lhld    6;        set stack at top of memory
  20.     mvi    l,0
  21.     sphl
  22. ;    "    "
  23. ; apportion memory to two file buffers
  24.     lxi    d,-buffer-128;    128 byte stack/b.ohead allowance
  25.     dad    d;        form size of memory available
  26.     mov b,h    ! mov c,l;    will be rounded down to 128 byte unit
  27.     push    b;        save buffer size
  28. ;    "    "
  29. ; initialize fcbs
  30.     lxi    h,fcbin
  31.     call    .initfcb
  32.     lxi    h,fcbout
  33.     call    .initfcb
  34. ;    "    "
  35. ; mark end of command line, just in case.
  36. ; Done by most CCPs, but undocumented.  CCPLUS is documented
  37.     lxi    h,defdma
  38.     mov    a,m;        line length
  39.     inx    h
  40.     add    l
  41.     mov    l,a
  42.     adc    h
  43.     sub    l
  44.     mov    h,a
  45.     mvi    m,0;        mark eol
  46. ;    "    "
  47. ; parse the file names
  48.     lxi    d,defdma+1;    set command scanning pointer
  49.     lxi    h,fcbin
  50.     call    .pfnmdu;    will parse an empty line into
  51.     lda    fcbin+1;    a blank FCB.
  52.     cpi    ' ';        could use the open error instead, but
  53.     jz    nofile;          CPM can create a blank named file
  54.     mov    a,b;        designated user
  55.     call    .xltusr;    convert 0 into current, etc
  56.     sta    inuser
  57.     mov    a,b;        but bfropen needs original form
  58.     pop    b;        get buffer size back
  59.     push    d;        save input scan pointer
  60.     lxi    d,fcbin
  61.     lxi    h,buffer
  62.     call    .bfropen;    open buffered file for read
  63.     jc    error;        can't find it, abort
  64.     pop    d;        restore input scan pointer
  65.     lxi    h,fcbout
  66.     call    .pfnmdu
  67.     lda    fcbout+1
  68.     cpi    ' '
  69.     jz    noutfile
  70.     mov    a,b;        designated user
  71.     call    .xltusr;    convert to standard form
  72.     ori    b.wflg;        essential to flag correctly ** <<< **
  73.     sta    outuser;    save for future
  74.     lxi    d,fcbout
  75.     call    .fopnw;        open file for write
  76.     jc    createrr;    can't create file
  77. ;    "    "
  78. ; All files open, and buffers assigned.
  79. ; Copy fcbin to fcbout in largest possible blocks
  80. copy:    lxi    h,buffer
  81.     call    .bload;        fill the buffer
  82.     push    psw;        save carry for eof
  83.     lda    outuser
  84.     lxi    d,fcbout
  85.     call    .bfswap;    change to write
  86.     sta    inuser
  87.     call    .bdump;        write the buffer out
  88.     jc    outerr;        error occured
  89.     pop    psw;        saved eof above
  90.     jc    done
  91.     lda    inuser;        saved above
  92.     lxi    d,fcbin
  93.     call    .bfswap;    return to loading
  94.     sta    outuser;    save for next switch
  95.     jmp    copy;        not complete
  96. ;
  97. ; done, close output file. No need to fill, using full recds.
  98. done:    call    .bfclose
  99.     jnc    boot;        no close error
  100. ;    "    "
  101. ; all the errors simplified to one message
  102. outerr:
  103. createrr:
  104. error
  105. noutfile:
  106. nofile:    lxi    d,errmsg
  107.     mvi    a,9
  108.     call    .dos
  109.     jmp    boot
  110. ;
  111. errmsg:    db    'Some sort of error occured$'
  112. ;
  113. ;    ---------    Data Segment    --------
  114. ;    Link this AFTER all the code segments
  115. ;
  116.     dseg
  117. inuser:        ds    1;    user # for input file
  118. fcbin:        ds    36;    input file fcb
  119. outuser:    ds    1;    user # for output file
  120. fcbout:        ds    36;    output file fcb
  121. ;
  122. ; This must be the last program storage, see linking above.
  123. ; An alternative is to use a separate dseg file.
  124. buffer:        ds    0;    actually rest of memory
  125. ;
  126.     end
  127. √