Re: A86: 3 questions
[Prev][Next][Index][Thread]
Re: A86: 3 questions
On Wed, 6 Jan 1999 12:30:22 +0100 "Keith Batten" <kbatten@usa.net>
writes:
>
>1) Is there any way for me to have the calculator evalute an
>equation from assembler? maybe like a rom call or an exec_pg?
probably. i don't know where, but... :)
>2) Is there an easy way to convert a string to a real? a rom call?
there might be a rom call, but there's also a routine i wrote. it's up
on ticalc, but i think i missed a bug in that, so here it is again (at
end of message)
>3) also one more question, I have a question about the Floating
>Point Stack. How do I know when the FPS is empty?
the floating point stack starts at $8000 (i think) and works up, so if
_FPS=$8000 then it's empty.
>thanks in advance for any answers.
>
>Keith Batten
>kbatten@usa.net
example:
ld hl,str
ld b,10
ld de,_OP1
call atof
call _disp_op1
ret
str: .db "1.2345",$1b,"678" ;$1b = little E symbol
;convert string (hl) length b to fp (de)
; by Joshua Seagoe
atof: push de
push hl
call $41b7 ;0->(de)
pop hl
pop de
inc de
ld (atofexp),de ;->exponent
inc de ;skip exponent for now
inc de
ld c,0 ;c=number of digits parsed
atofloop:
ld a,(hl) ;load a char
inc hl
cp '0' ;make sure it's a number
jr c,atofnan
cp '9'+1
ret nc ;nothing >9 is used
and $0f ;get the number
bit 0,c ;shift to upper bits
call z,$438b ;if it should be there
ex de,hl
add a,(hl) ;add to what's there
ex de,hl
ld (de),a ;store it
bit 0,c ;go to next byte
jr z,atofnoskip
inc de ;if we should
atofnoskip:
inc c ;register another digit
djnz atofloop ;get the rest
jr atofdoexp ;done!
atofnan: ;it's not a number
cp '.' ;is it a dp?
jr z,atofdp
cp $1b ;is it the exp symbol?
jr z,atofex
jr atofdoexp ;give up
atofdp: ;decimal point!
call atofdoexp
djnz atofloop ;get the rest
ret
atofdoexp:
push de ;save dest
push hl ;save source
push bc ;save length
ld b,0 ;bc=digit count
ld de,$fbff ;hl=$fbff
ex de,hl
add hl,bc
ex de,hl
ld hl,(atofexp) ;find exponent
ld a,h
cp l
jr z,atofalready
ld (hl),e ;write exponent
inc hl
ld (hl),d
ld hl,0
ld (atofexp),hl
atofalready:
pop bc
pop hl
pop de
ret
atofex: ;exponent
ld de,0 ;now contains exponent
dec b ;count off exp char
atofeloop:
ld a,(hl)
inc hl
cp '0' ;only numbers in exponent
ret c
cp '9'+1
ret nc
and $0f ;get actual number
push hl
ld l,e ;de=de*10+a
ld h,d
add hl,hl ;*2
add hl,hl ;*4
add hl,de ;*5
add hl,hl ;*10
ld e,a
ld d,0
add hl,de ;+a
pop de ;restore de
ex de,hl ;they go the other way...
djnz atofeloop
ld hl,(atofexp) ;(hl)->old exp
call $5928 ;ld hl,(hl)
add hl,de ;hl=new exp
ld de,(atofexp)
ex de,hl
ld (hl),e ;store new exp
inc hl
ld (hl),d
dec hl ;restore hl->answer
dec hl
ret
atofexp: .dw 0
___________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com/getjuno.html
or call Juno at (800) 654-JUNO [654-5866]
Follow-Ups: