home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / asmutl / buffers.lbr / TEST2.MZC / TEST2.MAC
Encoding:
Text File  |  1987-01-15  |  3.0 KB  |  132 lines

  1. ; test buffers module. Copy file 1 to file 2
  2. ; This does a totally unnecessary double buffering, in order
  3. ; to illustrate use of the package and linking methods to
  4. ; keep a maximum memory area available.
  5. ;
  6. ;   d>TEST2 [d[u]:]filename.typ [d[u]:]outname.typ
  7. ;        copies filename.typ to outname.typ
  8. ;        (with full du addressing, across users, drives)
  9. ; SEE BUFFERS.DOC for linking instructions
  10. ;
  11. boot    equ    0
  12. tfcb    equ    boot+05ch
  13. defdma    equ    boot+080h
  14. ;
  15.     extrn    .dos, b.ohead
  16.     extrn    .bfgetc, .bfputc
  17.     extrn    .bfropen, .bfwopen, .bfclose
  18.     extrn    .pfnmdu, .initfcb
  19. ;
  20. begin:    lhld    6;        set stack at top of memory
  21.     mvi    l,0
  22.     sphl
  23. ;    "    "
  24. ; apportion memory to two file buffers
  25.     lxi    d,-inbuff-128;    128 byte stack/b.ohead allowance
  26.     dad    d;        form size of memory available
  27.     mov    a,h
  28.     ora    a
  29.     rar
  30.     mov    b,a;        1/2 space to buffers size
  31.     mov    a,l;        will be rounded down
  32.     rar
  33.     mov    c,a;        1/2 space to buffer size
  34.     lxi    h,inbuff
  35.     shld    @inbuff
  36.     dad    b
  37.     lxi    d,b.ohead;    input space + 12
  38.     dad    d
  39.     shld    @outbuff;    form outbuffer pointer
  40.     push    b;        save buffer size
  41. ;    "    "
  42. ; initialize fcbs
  43.     lxi    h,fcbin
  44.     call    .initfcb
  45.     lxi    h,fcbout
  46.     call    .initfcb
  47. ;    "    "
  48. ; mark end of command line, just in case.
  49. ; Done by most CCPs, but undocumented.  CCPLUS is documented
  50.     lxi    h,defdma
  51.     mov    a,m;        line length
  52.     inx    h
  53.     add    l
  54.     mov    l,a
  55.     adc    h
  56.     sub    l
  57.     mov    h,a
  58.     mvi    m,0;        mark eol
  59. ;    "    "
  60. ; parse the file names
  61.     lxi    d,defdma+1;    set command scanning pointer
  62.     lxi    h,fcbin
  63.     call    .pfnmdu;    will parse an empty line into
  64.     lda    fcbin+1;    a blank FCB.
  65.     cpi    ' '
  66.     jz    nofile
  67.     mov    a,b;        designated user
  68.     pop    b;        get buffer size back
  69.     push    b;        re-save buffer size
  70.     push    d;        save input scan pointer
  71.     lxi    d,fcbin
  72.     lhld    @inbuff
  73.     call    .bfropen;    open buffered file for read
  74.     jc    error;        can't find it, abort
  75.     pop    d;        restore input scan pointer
  76.     push    b;        save size again
  77.     lxi    h,fcbout
  78.     call    .pfnmdu
  79.     lda    fcbout+1
  80.     cpi    ' '
  81.     jz    noutfile
  82.     mov    a,b;        designated user
  83.     pop    b
  84.     lxi    d,fcbout
  85.     lhld    @outbuff
  86.     call    .bfwopen;    open buffered file for write
  87.     jc    createrr;    can't create file
  88. ;    "    "
  89. ; All files open, and buffers assigned.
  90. ; Copy fcbin to fcbout byte by byte.
  91. copy:    lhld    @inbuff
  92.     call    .bfgetc;    get a byte
  93.     jc    done;        eof
  94.     mov    c,a
  95.     lhld    @outbuff;    Every byte passes thru here, so
  96.     call    .bfputc;    that any desired filters can be
  97.     jc    outerr;        implemented here.
  98.     jmp    copy
  99. ;
  100. ; done, close output file
  101. done:    lhld    @outbuff
  102.     call    .bfclose
  103.     jnc    boot;        no close error
  104. ;    "    "
  105. ; all the errors simplified to one message
  106. outerr:
  107. createrr:
  108. error
  109. noutfile:
  110. nofile:    lxi    d,errmsg
  111.     mvi    a,9
  112.     call    .dos
  113.     jmp    boot
  114. ;
  115. errmsg:    db    'Some sort of error occured$'
  116. ;
  117. ;    ---------    Data Segment    --------
  118. ;    Link this AFTER all the code segments
  119. ;
  120.     dseg
  121. fcbin:        ds    36;    input file fcb
  122. fcbout:        ds    36;    output file fcb
  123. @inbuff:    ds    2;    pointer to input buffer
  124. @outbuff:    ds    2;    pointer to output buffer
  125. ;
  126. ; This must be the last program storage, see linking above.
  127. ; An alternative is to use a separate dseg file.
  128. inbuff:        ds    0;    actually 1/2 of remainder
  129. ;
  130.     end
  131. ε