DataMuseum.dk

Presents historical artifacts from the history of:

Jet Computer Jet80

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Jet Computer Jet80

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦b39413114⟧ TextFile

    Length: 3584 (0xe00)
    Types: TextFile
    Names: »CVTSFP.SRC«

Derivation

└─⟦c9df7130d⟧ Bits:30005915 Pascal MT+ Release 5.2 (Jet-80)
    └─ ⟦this⟧ »CVTSFP.SRC« 

TextFile

; convert a string to a floating point number
;
	NAME CVTSFP
	ENTRY CVTSFP,CVTH,CVTL
	EXT FADD1,FPTTEN,FPERR,FPDTEN
	INCLUDE FPINIT.SRC
	INCLUDE FPMAC.SRC
;
cvtsfp:	lxi	d,0
	mvi	b,7
addzer:	push	d		;add 14 bytes of zeroes to the stack
	djnz	addzer
	push	x		;save ix, iy and hl
	push	y
	push	h
	xchg			;hl <- 0
	dad	s		;hl = sp
	push	h
	pop	x		;ix = sp
	inr	intflg(x)	;set internal operations flag
	xchg			;de = sp
nxtdig:	pop	h		;get next digit
	mov	a,m
	dcx	h		;bump and save pointer
	push	h
	cpi	'.'		;check for a decimal point
	jrz	fractn		;yes, go indicate a fraction
	cpi	'e'		;check for a scale factor
	jrz	scale
	cpi	'E'
	jrz	scale
	cpi	' '		;check for end of number
	jrz	eofpn
	dcr	dc1(x)		;add another notch to the digit counter
	call	fptten		;op1 := op1 * 10
	pop	h		;get digit again
	push	h
	inx	h
	mov	a,m
	sui	'0'		;strip ascii bias
	lxi	h,op2		;make op2 = new digit
	dad	d
	mvi	m,7		;exponent
	dcx	h
	mov	m,a		;high byte of mantissa
	xra	a		;acc <- 0
	dcx	h
	mov	m,a		;store a zero into this byte of mantissa
	dcx	h
	mov	m,a		;store a zero into this byte of mantissa
	dcx	h
	mov	m,a		;store a zero into this byte of mantissa
	normfp	2		;normalize this number, and ....
	call	fadd1		;add
	jr	nxtdig		;do next digit
fractn:	mvi	dc1(x),0	;indicate no decimal digits yet
	mvi	dc2(x),0ffh	;fix mask to allow decimal digits
	jr	nxtdig		;go do next digit
eofpn:	xra	a		;clear acc
	pop	h		;throw away string pointer
	jr	scal6		;and go do some scaling
scale:	pop	h		;get pointer to string
	xra	a		;clear acc
	mov	c,a		;clear c
	mov	a,m		;get first char of scale factor
	cpi	'-'		;check for a leading sign
	jrnz	scal2		;no leading minus sign
	mov	c,a		;set c to indicate a negative exponent
	jr	scal3
scal2:	cpi	'+'		;check for a leading plus sign
	jrnz	scal4		;no, keep processing
scal3:	dcx	h		;skip over sign and keep processing
scal4:	mov	a,m		;get first digit
	sui	'0'		;strip ascii bias
	jc	fperr		;make sure than 0 <= exp <= 9
	cpi	10
	jnc	fperr
	mov	b,a		;save the digit
	dcx	h		;bump the pointer
	mov	a,m		;get next digit
	cpi	' '		;check for end of exponent
	jrz	scal5
	sui	'0'		;strip ascii bias
	jc	fperr
	cpi	10
	jnc	fperr
	push	d		;save stack pointer
	mov	d,a		;save ones digit
	mov	a,b		;get tens digit
	add	a		;x2
	add	a		;x4
	add	b		;x5
	add	a		;x10
	add	d		; + ones digit
	pop	d		;restore stack pointer
	mov	b,a		;save exponent in b
scal5:	mov	a,b		;get exponent
	bit	0,c		;check for negative exponent
	jrz	scal6		;no, don't negate
	neg			;negate acc
scal6:	mov	b,a		;save signed exponent
	mov	a,dc1(x)	;get input bias
	ana	dc2(x)		;...and...
	add	b		;form corrected scale factor
	jm	dcnst		;negative exp requires division
	jrz	cvtdn		;zero -> done
	mov	b,a		;save it
mcnst:	push	b		;save counter
	call	fptten		;multiply by ten
	pop	b		;get counter
	djnz	mcnst		;continue until done
	jr	cvtdn
dcnst:	neg			;make counter positive
	mov	b,a		;save in b
dcnst2:	push	b		;save counter
	call	fpdten		;divide op1 by ten
	pop	b		;get counter
	djnz	dcnst2		;continue until done
cvtdn:	pop	y		;restore y
	pop	x		;restore x
	lxi	h,8		;throw away work space
	dad	s
	sphl
	pop	h		;get op1
	pop	d
	pop	b		;throw away scratch bytes
	xra	a		;clear acc
	ret
cvth	pop	h
	xthl
	call	cvtsfp		;convert to float
	ret			;return with two msb's in de
cvtl	pop	h
	xthl
	call	cvtsfp		;convert to float
	xchg
	ret			;return with two lsb's in de
;
«eof»