home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff339.lzh / PCQ / Runtime.lzh / Runtime / Writers / writetext.asm < prev   
Assembly Source File  |  1989-11-20  |  1KB  |  54 lines

  1. *
  2. *    WriteText.asm (of the PCQ Pascal runtime library)
  3. *    Copyright (c) 1989 Patrick Quaid
  4. *
  5.  
  6. *    Writes some bytes to a file record's buffer, flushing the
  7. *    buffer if necessary.
  8.  
  9. *    On entry, a0 holds the address of the file record
  10. *          a1 holds the address of the bytes to write
  11. *          d3 holds the number of bytes to write
  12.  
  13.     INCLUDE    ":runtime/FileRec.i"
  14.  
  15.     XREF    _p%FlushBuffer
  16.     XREF    _p%IOResult
  17.  
  18.     SECTION    WriteText,CODE
  19.  
  20.     XDEF    _p%WriteText
  21. _p%WriteText
  22.  
  23.     tst.l    _p%IOResult        ; is IO system OK?
  24.     bne    Leave            ; if not, go
  25.     tst.l    d3
  26.     beq    Leave            ; if nothing to write, leave
  27.     move.l    BUFFER(a0),d0        ; check actual buffer
  28.     bne.s    4$            ; if allocated, it's OK
  29.     move.l    #56,_p%IOResult        ; set Output not open
  30.     rts                ; split
  31. 4$    subq.l    #1,d3            ; for dbra below
  32.     move.l    a2,-(sp)        ; save a2
  33.     move.l    CURRENT(a0),a2        ; get current position
  34. 1$    move.b    (a1)+,d0        ; get byte
  35.     move.b    d0,(a2)+        ; write into buffer
  36.     cmpa.l    MAX(a0),a2        ; are we at MAX ?
  37.     blt.s    2$            ; if not, skip
  38.     move.l    a2,CURRENT(a0)        ; save new current pointer
  39.     movem.l    a1/d3,-(sp)        ; save regs for call
  40.     jsr    _p%FlushBuffer        ; write buffer contents
  41.     movem.l    (sp)+,a1/d3        ; restore regs
  42.     tst.l    _p%IOResult        ; were there errors?
  43.     bne.s    3$            ; if so, leave this loop
  44.     move.l    CURRENT(a0),a2        ; get new CURRENT ptr
  45. 2$    dbra    d3,1$            ; loop
  46.     move.l    a2,CURRENT(a0)        ; save correct value
  47.     tst.b    INTERACTIVE(a0)        ; is it interactive?
  48.     beq.s    3$            ; if not, skip
  49.     jsr    _p%FlushBuffer        ; if so, flush it immediately
  50. 3$    move.l    (sp)+,a2
  51. Leave    rts
  52.  
  53.     END
  54.