home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / CLISP-1.LHA / CLISP960530-sr.lha / amiga / jchlib / misc / BPTRfprintf.s next >
Encoding:
Text File  |  1996-07-09  |  1.8 KB  |  87 lines

  1. | Tiny GCC Library
  2. | Jörg Höhle, 9-Jul-96
  3.  
  4. |A 254 byte buffer is allocated and chunks max that large written
  5. |Write() results are not checked! We suppose Write() writes all data!
  6.  
  7. |Bugs: (at least in 2.04), RawDoFmt can't output a %lc of '\0', it's
  8. | simply skipped. This is certainly caused by the choice that the PutChProc
  9. | routine is passed a 0 at the end of the format string.
  10.  
  11. .text
  12.     .even
  13. .globl _BPTRfprintf
  14.  
  15. | BPTRfprintf(BPTR, char * C-format, ... C-varargs);
  16.  
  17. _BPTRfprintf:
  18.  
  19. | Buffer size is 254 bytes
  20.  
  21.     link a3,#-260        | a3 serves as PutChData
  22.             | a3@(16) C-varargs
  23.             | a3@(12) C-format
  24.             | a3@( 8) BPTR handle
  25.             | a3@( 4) RTS
  26.             | a3@( 0) a3 orig
  27.             | a3@(-4) total
  28.             | a3@(-6) counter WORD
  29.             | a3@(-260) buffer
  30.     moveml #0x0022,sp@-    | a2/a6
  31.     clrw a3@(-6)
  32.     clrl a3@(-4)
  33.     movel a3@(12),a0    | C-format
  34.     lea a3@(16),a1        | C-varargs
  35.     lea pc@(stuffit),a2    | PutChProc, ATTENTION! old gas needed stuffit+2
  36.                 | PutChData in a3
  37.     movel _SysBase,a6
  38.     jsr a6@(-0x20a)        | RawDoFmt()
  39.  
  40. | flushit call superfluous as end is recognized by 0 char by stuffit
  41. |    movew a3@(-6),d1
  42. |    lea a3@(-260),a0
  43. |    jbsr flushit
  44. |L101:
  45.     movel a3@(-4),d0
  46. |    moveml a3@(-268),#0x4400    | a2/a6
  47.     moveml sp@+,#0x4400        | a2/a6
  48.     unlk a3
  49.     rts
  50.  
  51. stuffit:
  52.     |    d0.b char
  53.     |    a3 remains accross RawDoFmt
  54.     movew a3@(-6),d1
  55.     lea a3@(-260),a0
  56.     tstb d0            | 0 is end
  57.     jeq flushit        | flush (without that 0)
  58.     moveb d0,a0@(d1:w)
  59.     addqw #1,d1
  60.     cmpw #254,d1
  61.     jeq L103
  62.     movew d1,a3@(-6)
  63. L102:
  64.     rts
  65.     
  66. flushit:
  67.     |    d1.w contains counter
  68.     |    a0 contains buffer
  69.     tstw d1
  70.     jeq L102
  71. L103:
  72.     moveml #0x3002,sp@-    | d2-d3/a6
  73.     moveq #0,d3        | necessary?
  74.     movew d1,d3        | length
  75.     movel a0,d2        | buffer
  76.     movel a3@(8),d1        | handle
  77.     movel _DOSBase,a6
  78.     jsr a6@(-0x30)        | Write()
  79.  
  80.     movel d3,d1
  81.     addl d1,a3@(-4)        | total += counter
  82.     moveq #0,d1        | zero counter
  83.     moveml sp@+,#0x400c    | d2-d3/a6
  84.     movew d1,a3@(-6)
  85.     rts
  86.  
  87.