;
; routines for PL/I symbolic debugger
; to convert FIXED BIN variables of any precision and scale factor
; to and from character strings
;
; these routines are not reentrant!
;

	.title	cvfxbn

	.psect	CVFXBN

	.globl	.CVI2C, .CVC2I
	.globl	ILNAR$, SAVRG$, .ERROR



;
; CALL CVI2C ( ADDR(num), precision, s, ssize )
;
; where num is a FIXED BIN variable, precision is a word containing the
; precision & scale factor of num (this determines whether num is 1, 2, or 
; 4 bytes long), s is an UNVARYING character string (not VARYING!), and ssize 
; is the size of s (number of characters). The descriptor and string area
; of s must be contiguous (s cant be based or a parameter or in an array
; or structure); if they aren't, ERROR is signaled with an oncode of 126. 
; The descriptor for s is overwritten, so it would be safest not to use it 
; for anything else.
;

	narg	= 16
	icnumad	= narg+2
	icprec	= icnumad+2
	icstr	= icprec+2
	icssiz	= icstr+2

CVI2C::	jsr r0,SAVRG$
	cmp narg(sp),#4
	bne ilnarg
	mov icstr(sp),r0	;addr of string descriptor
	mov 4(r0),r1		;address of string
	sub #6,r1		;less size of descriptor
	cmp r0,r1
	beq 10$			;contiguous, continue
	clr -(sp)		;no qualifier
	mov r5,-(sp)		;location of error
	mov #<0+126.*256.>,-(sp);ERROR condition code is 0, subcode 126
	jsr r5,.ERROR
10$:	sub r4,r0
	mov r0,iczstr
	mov @icprec(sp),iczpq
	mov @icnumad(sp),r0
	mov @icssiz(sp),-(sp)
	jsr r5,.CVI2C
iczpq:	.word 0
iczstr:	.word 0
	rts pc


;
; CALL CVC2I ( str, ADDR(num), precision )
;
; where str is any character string, num is a FIXED BIN variable, and precision
; is a word containing the precision and scale factor of num (this determines
; whether num is 1, 2, or 4 bytes long).
;

	narg	= 16
	cistr	= narg+2
	cinumad	= cistr+2
	ciprec	= cinumad+2

CVC2I::	jsr r0,SAVRG$
	cmp narg(sp),#3
	bne ilnarg
	mov @cinumad(sp),r0
	sub r4,r0
	mov r0,ciznum
	mov @ciprec(sp),cizpq
	mov cistr(sp),r0
	jsr r5,.CVC2I
ciznum:	.word 0
cizpq:	.word 0
	rts pc


ilnarg:	jsr r5,ILNAR$

	.end
