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

  1.     extrn    .nilchk, .sdem, b.cnt
  2. ;
  3. ; .binit, but ensure size is a multiple of 128
  4. ; a,f,c
  5. .bfinit::
  6.     push    psw
  7.     mov    a,c
  8.     ani    080h
  9.     mov    c,a;        round down to 128 byte multiple
  10.     pop    psw
  11. ;    "    "
  12. ; initialize buffer hl^ to empty, size bc, attach file de^
  13. ; set initial flags (lo byte only) to a, clear hi byte.
  14. ; For file reads the initial flag should be 0, for write 1.
  15. ; a,f
  16. .binit::
  17.     call    .nilchk ! rc;    error, no buffer specified
  18.     mov m,a    ! inx h
  19.     mvi m,0    ! dcx h;    set initial flags
  20.     mov a,b    ! ora c
  21.     stc    ! rz;        error, buffer size 0
  22.     push d    ! push h
  23.     inx h    ! inx h
  24.     mov m,c    ! inx h
  25.     mov m,b ! inx h;    set size
  26.     call    .sdem;        save fcb
  27.     pop h    ! pop d
  28. ;    "    "
  29. ; Set pointers back to start for aligned read/writes.
  30. ; Flush any data in buffer. Return a=0 and z flag.
  31. ; a,f
  32. .bflush::
  33.     call    .nilchk ! rc
  34.     push d    ! push h
  35.     lxi d,b.cnt ! dad d;    point to cnt field
  36.     lxi    d,0
  37.     call    .sdem;        zero bytes available
  38.     call    .sdem;        set rd ptr to 1st address
  39.     call    .sdem;        set wrt ptr to 1st address
  40.     pop h    ! pop d
  41.     xra    a;        signal flushed
  42.     ret
  43. $