kcmpstr.a68
; Copyright (C) 1986 by Manx Software Systems, Inc.
; :ts=8

	public	KCmpStr
	public	_KCmpStr
	public	_cmpstrexec
_cmpstrexec
_KCmpStr
	movem.l	4(sp),a0/a1
KCmpStr
	move.l	#-1,d0
1$
	move.b	(a0)+,d1
	beq	2$
	cmp.b	(a1)+,d1
	dbne	d0,1$
	neg.l	d0
	bra	3$
2$
	cmp.b	(a1)+,d1
	bne	3$
	move.l	#0,d0
3$
	rts

kgetnum.a68
; Copyright (C) 1986 by Manx Software Systems, Inc.
; :ts=8

	public	KPutChar
	public	KGetChar

	public	KGetNum
	public	_KGetNum
	public	_kgetnum
_KGetNum
_kgetnum
KGetNum
	move.l	d4,-(sp)	;save register
1$
	move.l	#0,d2		;init value to 0
	move.l	#0,d3		;init char count to 0
	move.l	#0,d4		;init sign to zero
	jsr	KGetChar	;get first character
	cmp.b	#'-',d0		;check for minus sign
	bne	3$		;no, skip
	jsr	KPutChar	;echo the character
	add.w	#1,d3		;bump character count
	move.l	#-1,d4		;set sign to negative
	bra	3$		;and skip
2$
	jsr	KGetChar	;get the next character
3$
	cmp.b	#8,d0		;is it a backspace?
	bne	4$		;no, skip
	tst.w	d3		;are there any characters?
	beq	1$		;no, so go back to start
	jsr	KPutChar	;back up the cursor
	move.l	#' ',d0		;use space to erase
	jsr	KPutChar	;erase it
	move.l	#8,d0		;need to back up again
	jsr	KPutChar
	sub.w	#1,d3		;decrement character count
	beq	1$		;if at beginning, go to top
	swap	d2		;get hi word for div by 10
	move.l	#0,d1		;preset d1 to zero
	move.w	d2,d1		;copy high word of d2
	divu	#10,d1		;divide by 10
	swap	d1		;get high part
	move.w	d1,d2		;copy back to d2
	swap	d2		;swap it
	divu	#10,d2		;and divide by 10 again
	move.w	d2,d1		;copy low word to d1
	move.l	d1,d2		;and take all d1 as d2
4$
	cmp.b	#'0',d0		;check against 0
	bcs	5$		;if less, skip
	cmp.b	#'9',d0		;check against 9
	bhi	5$		;if more, skip
	move.l	d2,d1		;do multiply by 10
	asl.l	#2,d1
	bvs	2$
	add.l	d2,d1
	bvs	2$
	asl.l	#1,d1
	sub.b	#'0',d0		;convert char to number
	add.l	d0,d1		;add to value
	bcs	2$		;if overflow, ignore
	add.b	#'0',d0		;else convert to char
	move.l	d1,d2		;save new value
	jsr	KPutChar	;echo the char
	add.w	#1,d3		;bump the char counter
5$
	cmp.b	#$d,d0		;check for return
	bne	2$		;no, ignore
	tst.b	d4		;check sign
	beq	7$		;if zero, skip
	neg.l	d2		;else negate value
7$
	move.l	d2,d0		;copy value for return
	move.l	(sp)+,d4	;restore register
	rts			;and return

kputchar.a68
; Copyright (C) 1986 by Manx Software Systems, Inc.
; :ts=8

	public	_kputchar
	public	_KPutChar
	public	KPutChar
	public	_kputc
	public	_kputch
	public	_KPutCh
_kputchar
_KPutChar
_kputc
_kputch
_KPutCh
	if INT32
	move.l	4(sp),d0
	else
	move.l	#0,d0
	move.w	4(sp),d0
	endc
KPutChar
	movem.l	d0/a6,-(sp)
	move.l	4,a6
	jsr	-516(a6)
	movem.l	(sp)+,d0/a6
	rts

	public	_KPutStr
	public	_kputstr
	public	KPutStr
	public	_kputs
	public	_KPutS
_kputstr
_KPutStr
_kputs
_KPutS
	move.l	4(sp),a0
KPutStr
	move.b	(a0)+,d0
	beq	1$
	bsr	KPutChar
	bra	KPutStr
1$
	rts

	public	_kgetchar
	public	_KGetChar
	public	KGetChar
	public	_kgetc
	public	_KGetCh
	public	_kgetch
_kgetchar
_KGetChar
KGetChar
_kgetc
_KGetCh
_kgetch
	bsr	_KMayGetChar
	tst.l	d0
	bmi	_KGetChar
	rts

	public	_KMayGetChar
	public	KMayGetChar
	public	_KMayGetCh
_KMayGetChar
KMayGetChar
_KMayGetCh
	move.l	a6,-(sp)
	move.l	4,a6
	jsr	-510(a6)
	move.l	(sp)+,a6
	rts

	public	_KPutFmt
_KPutFmt
	move.l	8(sp),a1
	bra	putf

	public	_KPrintF
	public	_kprintf
_kprintf
_KPrintF
	lea	8(sp),a1
putf
	move.l	4(sp),a0

	public	KPutFmt
KPutFmt
	move.l	a2,-(sp)
	lea	KPutChar,a2
	bsr	KDoFmt
	move.l	(sp)+,a2
	rts

	public	KDoFmt
KDoFmt
	move.l	a6,-(sp)
	move.l	4,a6
	jsr	-522(a6)
	move.l	(sp)+,a6
	rts

	public	_KDoFmt
_KDoFmt
	movem.l	a2/a3,-(sp)
	movem.l	12(sp),a0/a1/a2/a3
	bsr	KDoFmt
	movem.l	(sp)+,a2/a3
	rts

makebig
.c.l:
	cc +bcd -o $@ $*.c
.c.l32:
	cc +bp -o $@ $*.c
.a68.l:
	as -cd -o $@ $*.a68
.a68.l32:
	as -cd -eINT32 -o $@ $*.a68

C=mprintf.l mprintf.l32
ASM=kcmpstr.l kgetnum.l kputchar.l kputchar.l32

all:	$(ASM) $(C)

makefile
.c.o:
	cc +bcd -o $@ $*.c
.c.o32:
	cc +bp -o $@ $*.c
.a68.o:
	as -cd -o $@ $*.a68
.a68.o32:
	as -cd -eINT32 -o $@ $*.a68

C=mprintf.o mprintf.o32
ASM=kcmpstr.o kgetnum.o kputchar.o kputchar.o32

all:	$(ASM) $(C)

mprintf.c
/* Copyright (C) 1987 by Manx Software Systems */

mprintf(fmt,args)
char *fmt; unsigned args;
{
	int kputchar();

	return format(kputchar,fmt,&args);
}

