home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / 22rsx / rxmd.ark.2 / RXMD13.MAC < prev    next >
Encoding:
Text File  |  1985-12-07  |  3.3 KB  |  137 lines

  1. ;
  2. ; ---------------------------------------------------
  3. ;       read a record, refill buffer if empty
  4. ;
  5. ; Buffer is empty - read in another block of 16k
  6. ;
  7. rdblock:
  8.     lda    eoflg;        Get 'EOF' flag
  9.     cpi    1;        Is it set?
  10.     stc;            To show 'EOF'
  11.     rz;            Got 'EOF'
  12.     call    rdblk1
  13. ;    "    "
  14. ; Update record read
  15. ;
  16. rdrecd:    lda    recnbf;        See how many records in the buffer
  17.     ora    a
  18.     jz    rdblock;    If none, go get some
  19.     lda    kflg;        Using 1k blocks?
  20.     ora    a
  21.     jz    rdrec1;        If not, exit
  22. ;    "    "
  23. ; Using 1k blocks, switch to 128 if less than 8 records left
  24.     lda    recnbf;        See how many records in buffer
  25.     sui    8
  26.     jnc    rdrec2;        If 8 or more stay in 1k blocks
  27.     xra    a;        Else there are 1-7 records left
  28.     sta    kflg;        Reset the 1k flag for 128
  29. rdrec1:    lda    recnbf;        Get number of records in buffer
  30.     dcr    a;        Decrement it for 128 character blocks
  31. rdrec2:    sta    recnbf;        Store the new value
  32.     ret
  33. ;
  34. ; Read up to 16k from the disk file into the buffer, ready to send
  35. ;
  36. rdblk1:    mvi    c,0;        Records in block
  37.     lxi    d,dbuf;        To disk buffer
  38. rdreclp:
  39.     push    d
  40.     mvi    a,stdma;    Set DMA address
  41.     call    dos
  42.     mvi    a,read
  43.     call    fileop
  44.     pop    d
  45.     ora    a;        Read ok?
  46.     jnz    reof;        If not, error or end of file
  47.     lxi    h,128;        Add length of one record
  48.     dad    d;        To next buffer
  49.     xchg;            Buffer to 'DE'
  50.     inr    c;        More records?
  51.     mov    a,c;        Get count
  52.     cpi    bufsiz*8;    Done?
  53.     jnz    rdreclp;    Read more
  54.     jmp    ioexit;        buffer full or got eof
  55. ;
  56. reof:    dcr    a
  57.     jnz    rderr;        Not 'EOF'
  58.     mvi    a,1
  59.     sta    eoflg;        Set EOF flag
  60.     mov    a,c
  61.     jmp    ioexit
  62. ;
  63. ; Read error
  64. ;
  65. rderr:    call    erxit
  66.  db    '++ File read error ++','$'
  67. ;
  68. ;       end of read record routine
  69. ; -----------------------------------------------
  70. ;
  71. ; Writes the record into a buffer.  If/when 16k has been written,
  72. ; writes the block to disk.
  73. ;
  74. ; Entry point "WRBLOCK" flushes the buffer at EOF
  75. ;
  76. wrrecd:    lhld    recptr;        Get buffer address
  77.     call    grcdsz;        128/1024 on kflg
  78.     dad    d;        To next buffer
  79.     shld    recptr;        Save buffer address
  80.     lda    kflg;        Using 1k blocks?
  81.     ora    a
  82.     jz    wrrec1;        If not, exit
  83.     lda    recnbf;        Get number of records in buffer
  84.     adi    8;        Increment it 8 records for 1k
  85.     jmp    wrrec2
  86. ;
  87. wrrec1:    lda    recnbf;        Get number of records in buffer
  88.     inr    a;        increment it for 1 record
  89. wrrec2:    sta    recnbf;        Store the new value
  90.     cpi    bufsiz*8;    Is the buffer full, yet?
  91.     rnz;            No, return
  92. ;    "    "
  93. ; Writes a block to disk
  94. ;
  95. wrblock:
  96.     lda    recnbf;        Number of records in the buffer
  97.     ora    a;        0 means end of file
  98.     rz;            None to write
  99.     mov    c,a;        Save count
  100.     lxi    d,dbuf;        Point to disk buff
  101. dkwrlp:    push    d
  102.     mvi    a,stdma;    Set DMA
  103.     call    dos;        To buffer
  104.     mvi    a,write
  105.     call    fileop;        then write the block
  106.     pop    d
  107.     ora    a
  108.     jnz    wrerr;        Oops, error
  109.     lxi    h,128;        Length of 1 record
  110.     dad    d;        'HL'= next buff
  111.     xchg;            To 'DE' for setdma
  112.     dcr    c
  113.     jnz    dkwrlp;        More records
  114.     xra    a;        Get a zero
  115. ;    "    "
  116. ; exit from i/o operations
  117. ioexit:    sta    recnbf;        Reset number of records
  118.     lxi    h,dbuf;        Reset buffer buffer
  119.     shld    recptr;        Save buffer address
  120.     call    dskstp;        stop any disks spinning
  121. ;    "    "
  122. rsdma:    lxi    d,tbuf;        Reset DMA address
  123.     mvi    a,stdma
  124.     jmp    dos
  125. ;
  126. wrerr:    call    rsdma;        Reset DMA to normal
  127.     call    send3can;    cancel sender
  128.     call    rcvsabt;    Kill receive file
  129.     call    erxit;        Exit with msg:
  130.  db    '++ Error writing file ++','$'
  131. ;
  132. ; File operation (a) on FCB
  133. ; a,f,d,e
  134. fileop:    lxi    d,fcb
  135.     jmp    dos
  136. ;
  137. ??