;	kprintf.a - KPrintf implementation using ROM routines
;	$VER: kprintf.a 37.1 (11.5.96)
;	Copyright © 1996 Michael Letowski
;
;	37.1 (11.5.96) - initial version

	include	"exec/funcdef.i"
	include	"exec/exec_lib.i"

	xdef	_KPrintf
	xdef	_VKPrintf
	xdef	@VKPrintf

; Some aliases

	xdef	_KPrintF
	xdef	_kprintf
	xdef	_VKPrintF
	xdef	_vkprintf
	xdef	_KPutFmt
	xdef	@VKPrintF
	xdef	KPutFmt
	xdef	KPrintF

	section	text,code


******* debug.lib/VKPrintf **************************************************
*
*   NAME
*       VKPrintf -- print formatted data to the debugging console. (V37)
*
*   SYNOPSIS
*       nextData = VKPrintf(format, data)
*       D0                  A0      A1
*
*       APTR VKPrintf(STRPTR, APTR);
*
*       nextData = KPrintf(buffer, format, ...)
*
*       APTR KPrintf(STRPTR, STRPTR, ...);
*
*   FUNCTION
*       Prints data formatted with C-like string to the debugging console
*       (defaults to the serial port at 9600 baud). The data is formatted
*       using ROM RawDoFmt() function.
*
*   INPUTS
*       format - "C"-language-like NULL terminated format string.
*       data   - stream of data to be interpreted.
*
*   RESULT
*       nextData - pointer to end of the data stream (the next argument that
*                  would have been processed).
*
*   NOTES
*       @VKPrintf, @VKPrintF, KPutFmt, KPrintF are identical assembly
*       interfaces that want the two pointers in registers.
*       _VKPrintf, _VKPrintF, _vkprintf, _KPutFmt are C interfaces that want
*       the two string pointers on stack.
*       _KPrintf, _KPrintF, _kprintf are C interfaces that expect the format
*       string pointer on the stack, and the parameters on the stack above
*       that.
*
*   SEE ALSO
*       KDoFmt(), exec.library/RawDoFmt().
*
*****************************************************************************
*
* _KPrintf(format, ...)
* _VKPrintf(format, data)
* @VKPrintf(R_A0 format, R_A1 data)
*

_KPrintf:
_KPrintF:
_kprintf:
	move.l	1*4(sp),a0
	lea.l	2*4(sp),a1
	bra.b	KPrintF

_VKPrintf:
_VKPrintF:
_vkprintf:
_KPutFmt:
	move.l	1*4(sp),a0
	move.l	2*4(sp),a1

@VKPrintf:
@VKPrintF:
KPutFmt:
KPrintF:
	movem.l	a2-a3/a6,-(sp)		; Save registers
	lea.l	StuffChar(pc),a2	; a2 = put char proc
	move.l	(4).w,a3		; Remember SysBase
	move.l	a3,a6			; Use SysBase
	jsr	_LVORawDoFmt(a6)	; Jump to ROM
	movem.l	(sp)+,a2-a3/a6		; Restore registers
	rts				; Done

StuffChar:
	move.l	a3,a6			; Get SysBase
	jsr	_LVORawPutChar(a6)	; Use serial I/O to stuff chars
	rts

	end
