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 / writearb.asm < prev    next >
Assembly Source File  |  1990-01-06  |  2KB  |  70 lines

  1.  
  2. *    WriteArb.asm (of PCQ Pascal runtime library)
  3. *    Copyright (c) 1989 Patrick Quaid
  4.  
  5. *    This just writes some type to a file of that type
  6.  
  7.     INCLUDE    ":runtime/FileRec.i"
  8.  
  9.     SECTION    ONE
  10.  
  11.     XREF    outbuffer
  12.     XREF    _p%FlushBuffer
  13.     XREF    _p%IOResult
  14.  
  15. *    Upon entry to this routine, d3 holds the size of the data to write.
  16. *    If that size is 1, 2 or 4 d0 holds the data itself.  Otherwise d0
  17. *    holds the address of the data.  The file record address is on top
  18. *    of the stack.
  19.  
  20.     XDEF    _p%WriteArb
  21. _p%WriteArb
  22.  
  23.     tst.l    _p%IOResult    ; is IO in good shape?
  24.     bne    9$        ; if not, leave
  25.     move.l    d0,a1        ; set up as if > 4 or = 3
  26.     cmp.l    #4,d3        ; is size > 4 ?
  27.     bgt.s    5$        ; if so, go to write
  28.  
  29. 1$    cmp.l    #3,d3        ; if its three, do the same
  30.     beq.s    5$        ;
  31.  
  32. 2$    move.l    #outbuffer,a1    ; set up for all the others
  33.     cmp.l    #1,d3        ; is it a byte?
  34.     bne.s    3$        ; if not 1 then go around
  35.     move.b    d0,outbuffer    ; move it into outbuffer
  36.     bra.s    5$        ; go write
  37.  
  38. 3$    cmp.l    #2,d3        ; is it two?
  39.     bne.s    4$        ; go around
  40.     move.w    d0,outbuffer    ; store it
  41.     bra.s    5$
  42.  
  43. 4$    move.l    d0,outbuffer    ; store it if it's 4
  44.  
  45. 5$    move.l    a2,-(sp)    ; save a2 for now
  46.     move.l    8(sp),a0    ; get the file record address
  47.     move.l    CURRENT(a0),a2    ; get the current position
  48.     subq.l    #1,d3        ; set up for dbra loop
  49. 6$    move.b    (a1)+,d0    ; get a byte
  50.     move.b    d0,(a2)+    ; copy it
  51.     cmpa.l    MAX(a0),a2    ; are we at end?
  52.     blt.s    7$        ; if not, skip this
  53.     move.l    a2,CURRENT(a0)    ; save ptr
  54.     movem.l    a1/d3,-(sp)    ; save pointers
  55.     jsr    _p%FlushBuffer    ; write the buffer
  56.     movem.l    (sp)+,a1/d3    ; restore the regs
  57.     tst.l    _p%IOResult    ; did it go OK?
  58.     bne    9$
  59.     move.l    CURRENT(a0),a2    ; and retrieve the current ptr
  60. 7$    dbra    d3,6$
  61.     move.l    a2,CURRENT(a0)    ; save final value
  62.     tst.b    INTERACTIVE(a0)    ; is the file interactive?
  63.     beq.s    8$        ; if not, skip this
  64.     jsr    _p%FlushBuffer    ; flush it every time
  65. 8$    move.l    (sp)+,a2
  66. 9$    rts
  67.  
  68.     END
  69.  
  70.