home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d110 / pdc.lha / Pdc / lib / xprintf.asm < prev   
Assembly Source File  |  1987-10-28  |  2KB  |  63 lines

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