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

	.title	cvdec

	.psect	CVDEC

	.globl	.CVP2C, .CVC2P, .STORP
	.globl	ILNAR$, SAVRG$, .ERROR

	pmask = 377  ;mask to get precision from precision & scale ("pq") word



;
; CALL CVD2C ( ADDR(num), precision, s, ssize )
;
; where num is a DECIMAL variable, precision is a word containing the
; precision & scale factor of num (this determines how long num is),
; 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

CVD2C::	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		;offset in dsa
	mov @icprec(sp),iczpq
	mov @icnumad(sp),r0
	mov @icssiz(sp),-(sp)
	jsr r5,.CVP2C
iczpq:	.word 0
iczstr:	.word 0
	rts pc


;
; CALL CVC2D ( str, ADDR(temp), ADDR(num), precision )
;
; where str is any character string, temp is a DECIMAL(15) variable,
; num is a DECIMAL variable, and precision
; is a word containing the precision and scale factor of num (this determines
; how long num is).
;

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

CVC2D::	jsr r0,SAVRG$
	cmp narg(sp),#4
	bne ilnarg
	mov @citmpad(sp),r0
	sub r4,r0
	mov r0,ciztmp		;offset in dsa
	mov @ciprec(sp),r0
	mov r0,cizpq2
	bic #pmask,r0		;temporary always has precision 15 decimal
	add #17,r0
	mov r0,cizpq1	
	mov cistr(sp),r0
	jsr r5,.CVC2P
ciztmp:	.word 0
cizpq1:	.word 0
	mov @cinumad(sp),r1	;destination decimal variable
	jsr r5,.STORP
cizpq2:	.word 0
	rts pc


ilnarg:	jsr r5,ILNAR$

	.end
