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

  1.     extrn    .getusr, .setusr, .broom, .ldem, .dos
  2.     extrn    .advance, b.cnt, b.eof
  3. ;
  4. @dma    equ    26
  5. @rdseq    equ    20
  6. ;
  7. ; Read into buffer hl^ until less than 128 bytes free or eof
  8. ; Carry for eof or read error.
  9. ; Reset pointers for any extra portion not read
  10. ; Assumes no access via wtptr, i.e. input only buffer
  11. ; This code assumes buffer size to be a multiple of 128 bytes,
  12. ; so that single reads never need to "wrap around" the buffer.
  13. ; a,f
  14. .bload::
  15.     mov    a,m
  16.     ani    b.eof;            check for eof
  17.     stc
  18.     rnz
  19.     call    .getusr
  20.     push    psw
  21.     mov    a,m
  22.     ani    01fh
  23.     call    .setusr
  24.     push b    ! push d ! push h
  25. bload1:    call    .broom
  26.     mov a,c    ! ani 80h ! ora b
  27.     jz    bload3;            < 128 bytes free
  28.     inx h    ! inx h
  29.     mov c,m    ! inx h ! mov b,m;    get size
  30.     inx h    ! call .ldem;        get fcb, point to cnt
  31.     mov a,d    ! ora e ! stc
  32.     jz    bload3;            error, no fcb specified
  33.     push    d;            save fcb, point to cnt
  34.     inx h    ! inx h;        rptr
  35.     inx h    ! inx h;        wptr (to buffer)
  36.     call    .ldem ! dad d;        form access address
  37.     xchg
  38.     mvi    a,@dma
  39.     call    .dos
  40.     pop    d;            get fcb
  41.     mvi    a,@rdseq
  42.     call    .dos
  43.     jnz    bload2;            exit, eof or error
  44.     pop d    ! push d;        else advance pointers
  45.     lxi h,b.cnt ! dad d
  46.     mov a,m    ! adi 128 ! mov m,a
  47.     inx    h
  48.     mov a,m ! aci 0 ! mov m,a;    advance cnt
  49.     inx h    ! inx h ! inx h;    point to wptr
  50.     call    .advance
  51.     pop h    ! push h
  52.     jmp    bload1;            repeat until full/eof
  53. bload2:    pop h    ! push h
  54.     mov a,m    ! ori b.eof ! mov m,a;    mark eof found
  55. bload3:    pop h    ! pop d ! pop b
  56.     xthl;                get entry user to h
  57.     push    psw;            save error flag
  58.     mov    a,h
  59.     call    .setusr;        restore entry user
  60.     pop    psw
  61.     pop    h
  62.     ret
  63.