home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / CD32 / CD32_Support / examples / SA_Examples / cd / CDTest / bsprintf.a < prev    next >
Encoding:
Text File  |  1996-03-17  |  2.0 KB  |  55 lines

  1. *
  2. *
  3. * Bryce SPrintF() function.  Lifted from doc/exec.doc.
  4. * This thing (a) ought to work, and (b) should be assembled with CAPE.
  5. *
  6. * ANOTHER WARNING:  This does NO LENGTH CHECKING.
  7. *                   Make very sure that you don't exceed the size of
  8. *                   your target buffer!
  9. *
  10. *        ;
  11. *        ; Simple version of the C "sprintf" function.  Assumes C-style
  12. *        ; stack-based function conventions.
  13. *        ;
  14. *        ;   long eyecount;
  15. *        ;   eyecount=2;
  16. *        ;   sprintf(string,"%s have %ld eyes.","Fish",eyecount);
  17. *        ;
  18. *        ; would produce "Fish have 2 eyes." in the string buffer.
  19. *        ;
  20.  
  21.     section    text,code
  22.  
  23.                 XDEF _bsprintf
  24. _LVORawDoFmt     EQU     -$020A          ; bleargh, but it beats linking with amiga.lib
  25.                                          ; for residentable code...
  26.  
  27.         _bsprintf:       ; ( ostring, format, {values} )
  28.                 movem.l a2/a3/a6,-(sp)   ; Save old registers
  29.  
  30.                 move.l  4*4(sp),a3       ; Get the output string pointer
  31.                 move.l  5*4(sp),a0       ; Get the FormatString pointer
  32.                 lea.l   6*4(sp),a1       ; Get the pointer to the DataStream
  33.                 lea.l   stuffChar(pc),a2 ; stuff the character in the output stream
  34.                 move.l  (4),a6           ; get ready for Exec call
  35.                 jsr     _LVORawDoFmt(a6) ; actually call RawDoFmt()
  36.  
  37.                 movem.l (sp)+,a2/a3/a6   ; restore registers
  38.                 rts                      ; we're outta here
  39.  
  40.         ;------ PutChProc function used by RawDoFmt -----------
  41.         stuffChar:
  42.                 move.b  d0,(a3)+        ;Put data to output string
  43.                 rts
  44.  
  45. *   WARNING
  46. *        This Amiga ROM function formats word values in the data stream.  If
  47. *        your compiler defaults to longs, you must add an "l" to your
  48. *        % specifications.  This can get strange for characters, which might
  49. *        look like "%lc".
  50. *
  51. *   SEE ALSO
  52. *        amiga.lib/printf()
  53.  
  54.     end
  55.