home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / prog_c / suplib.lzh / SUPLIB / SRC / FHPRINTF.ASM < prev    next >
Assembly Source File  |  1991-08-16  |  2KB  |  62 lines

  1.  
  2. ;FHPRINTF.ASM
  3. ;
  4. ;  Handles formatted printing to Amiga file handles   w/ fhprintf
  5. ;
  6.  
  7.         section CODE
  8.  
  9.         xdef  _fhprintf
  10.         xref  _Write
  11.         xref  _LVORawDoFmt
  12.         xref  _SysBase
  13.  
  14. _fhprintf
  15.         jsr      xformat   ;same thing
  16.         jsr      _Write
  17.         lea.l    268(A7),A7
  18.         rts
  19.  
  20.         ;XFORMAT takes a Xprintf(xx, cs, arg, arg...)  where xx is any
  21.         ;integer and returns (xx, buf, bytes) on the stack suitable for an
  22.         ;immediate call to xwrite() or Write().  The caller must deallocate
  23.         ;268 bytes from the stack when done.
  24.         ;
  25.         ;          (oret)
  26.         ;  A2 A3 A4 A5 A6 RET FI BUF NUM <thebuffer> printfret fi cs args
  27.         ;  ^   ^         ^
  28.         ;  1   2         3
  29.  
  30.  
  31. xformat
  32.         move.l   A7,A0        ;sp now at pos. #3    A0 = pos #3
  33.         sub.l    #268,A7        ;sp now at pos. #2    SP = pos #2
  34.         move.l   (A0),(A7)      ;copy return address
  35.         move.l   8(A0),4(A7)    ;copy fi or fh  to FI
  36.         lea.l    16(A7),A1      ;address of buffer
  37.         move.l   A1,8(A7)       ;place in     BUF
  38.         movem.l  A2-A6,-(A7)    ;save regs   SP = pos #1
  39.         move.l   A1,A3        ;A3 = buffer pointer
  40.         lea.l    16(A0),A1      ;A1 = lea of printf arg list
  41.         move.l   12(A0),A0      ;A0 = control string
  42.         move.l   #_xc,A2        ;A2 = call vector
  43.  
  44.         move.l   _SysBase,A6    ;exec library call
  45.         jsr      _LVORawDoFmt(A6)
  46.  
  47.         move.l   28(A7),A3      ;buffer start
  48. loop        tst.b    (A3)+          ;find end of string
  49.         bne      loop
  50.         sub.l    28(A7),A3      ;get string length
  51.         subq.l   #1,A3
  52.         move.l   A3,32(A7)      ;place in     NUM
  53.         movem.l  (A7)+,A2-A6    ;restore registers used
  54.         rts
  55.  
  56. _xc
  57.         move.b   D0,(A3)+
  58.         rts
  59.  
  60.         END
  61.  
  62.