.globl	fpsim, fpsr, m.ext, m.lngi
/
/

/ io6 --  input conversions

/.globl	aicv
/.globl	gicv
/
/.globl	ilval
/.globl	width
/.globl	ilen
/.globl	fgetc
/.globl	itype
/.globl	nlflg
/.globl	gcflg

aicv:
	mov	ilval,r1
	movb	width,r2
	movb	ilen,r0
	mov	r0,-(sp)
1:
	cmp	r2,(sp)
	ble	1f
	jsr	r5,fgetc
	dec	r2
	br	1b
1:
	tst	r2
	ble	1f
	jsr	r5,fgetc
	movb	r0,(r1)+
	dec	r2
	dec	(sp)
	br	1b
1:
	tst	(sp)
	ble	1f
	movb	$' ,(r1)+
	dec	(sp)
	br	1b
1:
	tst	(sp)+
	rts	r5

licv:
	mov	width,twidth
bis	$m.ext, fpsr
bic	$m.lngi, fpsr
jsr	pc, fpsim
	clrf	fr0
1:
	jsr	r5,fgetcn
	cmp	r0,$'t
	beq	2f
	cmp	r0,$'T
	beq	2f
	cmp	r0,$'1
	beq	2f
	cmp	r0,$',
	beq	1f
	br	1b
2:
jsr	pc, fpsim
	movif	$1,fr0
	br	1b
1:
	br	storin

iicv:
	clr	ndig

ficv:
eicv:
dicv:
	mov	width,twidth
	br	1f

gicv:
	mov	$16383.,twidth
	clr	ndig
	mov	pc,gcflg
	br	2f
1:
	clr	gcflg
2:
	jsr	r5,gatof
storin:
	cmpb	itype,$'r
	beq	1f
	cmpb	ilen,$1
	beq	3f
	cmpb	ilen,$4
	bne	2f
bis	$m.lngi, fpsr
2:
jsr	pc, fpsim
	movfi	fr0,*ilval
	rts	r5
3:
jsr	pc, fpsim
	movfi	fr0,r0
	movb	r0,*ilval
	rts	r5
1:
	cmpb	ilen,$8.
	beq	2f
bic	$m.ext, fpsr
2:
jsr	pc, fpsim
	movf	fr0,*ilval
	rts	r5

gatof:
bis	$m.ext, fpsr
bic	$m.lngi, fpsr
jsr	pc, fpsim
	movif	$10.,fr3
	clr	r2
jsr	pc, fpsim
	clrf	fr0
	clr	-(sp)
1:
	jsr	r5,fgetcn
	cmp	$' ,r0
	bne	1f
	tst	nlflg
	beq	1b
	tst	(sp)+
	rts	r5
1:
	cmp	r0,$'+
	beq	1f
	cmp	r0,$'-
	bne	2f
	inc	(sp)
1:
	jsr	r5,fgetcn
2:
	cmp	$' ,r0
	bne	3f
	tst	gcflg
	bne	3f
	mov	$'0,r0
3:
	sub	$'0,r0
	cmp	r0,$9.
	bhi	2f
jsr	pc, fpsim
	mulf	fr3,fr0
	movif	r0,fr1
	addf	fr1,fr0
	dec	r1
	br	1b
2:
	add	$'0,r0
	cmp	r0,$'.
	bne	1f
	inc	r2
	clr	r1
	br	1b
1:
	mov	r3,-(sp)
	clr	r3
	cmp	r0,$'d
	beq	3f
	cmp	r0,$'+
	beq	3f
	cmp	r0,$'-
	beq	3f
	cmp	r0,$'e
	bne	2f
3:
	jsr	r5,atoi
2:
	tst	r2
	bne	1f
	mov	ndig,r1
	neg	r1
1:
jsr	pc, fpsim
	movf	fr3,fr2
	add	r3,r1
	mov	(sp)+,r3
	tst	r1
	beq	1f
	bpl	3f
	neg	r1
	mov	pc,-(sp)
	br	2f
3:
	clr	-(sp)
2:
	dec	r1
	ble	2f
jsr	pc, fpsim
	mulf	fr3,fr2
	br	2b
2:
	tst	(sp)+
	bne	2f
jsr	pc, fpsim
	mulf	fr2,fr0
	br	1f
2:
jsr	pc, fpsim
	divf	fr2,fr0
1:
	tst	(sp)+
	beq	1f
jsr	pc, fpsim
	negf	r0
1:
	cmp	r0,$',
	beq	1f
	cmp	$' ,r0
	beq	1f
	jsr	r5,rerr; 110.
1:
	rts	r5

atoi:
	clr	-(sp)
	cmp	r0,$'+
	beq	1f
	cmp	r0,$'-
	beq	3f
	jsr	r5,fgetcn
	cmp	r0,$'+
	beq	1f
	cmp	r0,$'-
	bne	2f
3:
	inc	(sp)
1:
	jsr	r5,fgetcn
2:
	sub	$'0,r0
	cmp	r0,$'9.
	bhi	2f
	mpy	$10.,r3
	add	r0,r3
	br	1b
2:
	add	$'0,r0
	tst	(sp)+
	beq	1f
	neg	r3
1:
	rts	r5

fgetcn:
	tst	twidth
	bgt	1f
	mov	$',,r0
	rts	r5
1:
	jsr	r5,fgetc
	dec	twidth
	rts	r5

