*--------------------------------------------------------------------------
*
* $Id: Format.asm,v 1.2 92/05/01 12:52:23 olsen Sta Locker: olsen $
* $Revision: 1.2 $
* $Date: 92/05/01 12:52:23 $
*
* ANSI-`C' style string routines not necessarily to be found in amiga.lib
*
* Copyright © 1990-1992 by Olaf `Olsen' Barthel & MXM
*    All Rights Reserved
* 
*--------------------------------------------------------------------------

CALL	macro
	xref	_LVO\1
	jsr	_LVO\1(a6)
	endm

	csect	text,0,0,1,2

*--------------------------------------------------------------------------

	xdef	_SPrintf
	xdef	_VSPrintf

	xdef	_atol

*--------------------------------------------------------------------------

_SPrintf:
	movem.l	a2/a3/a6,-(sp)		; Save registers

	move.l	 4+12(sp),a3		; Get destination buffer
	move.l	 8+12(sp),a0		; Get format string
	lea	12+12(sp),a1		; Get arguments
	lea	stuffchar(pc),a2	; Get formatting routine

	move.l	4,a6			; Get ExecBase
	CALL	RawDoFmt		; Format the string

	movem.l	(sp)+,a2/a3/a6		; Restore registers

	rts

*--------------------------------------------------------------------------

_VSPrintf:
	movem.l	a2/a3/a6,-(sp)

	move.l	 4+12(sp),a3
	move.l	 8+12(sp),a0
	move.l	12+12(sp),a1
	lea	stuffchar(pc),a2

	move.l	4,a6
	CALL	RawDoFmt

	movem.l	(sp)+,a2/a3/a6

	rts

stuffchar:
	move.b	d0,(a3)+
	rts

*--------------------------------------------------------------------------
*
*	A tiny replacement for atol(), implemented through StrToLong.
*
*--------------------------------------------------------------------------

_atol:	move.l	4(sp),d1	; Save argument

	movem.l	d2/a6,-(sp)	; Save registers

	pea.l	0		; Push a zero on the stack

	lea.l	(sp),a0		; Get a pointer to the value
	move.l	a0,d2		; Get it into a convenient register

	move.l	_DOSBase(a4),a6	; Get DOSBase

	CALL	StrToLong	; Convert the string

	move.l	(sp)+,d0	; Get the conversion result

	movem.l	(sp)+,d2/a6	; Restore registers

	rts

*--------------------------------------------------------------------------
*
*	These two lines are actually to make BLINK believe that some kind
*	of startup code will clear the Data/BSS segment before running the
*	main program. Since this is no longer necessary with Kickstart 2.x
*	these two lines save about 34 KBytes of disk space.
*
*--------------------------------------------------------------------------

	lea	__BSSBAS,a0
	move.l	#__BSSLEN,d0

*--------------------------------------------------------------------------

	csect	__MERGED

	xref	_DOSBase

	xref	__BSSBAS
	xref	__BSSLEN

	end
