Re: A86: numbers


[Prev][Next][Index][Thread]

Re: A86: numbers




i don't know of any for sure, but i'll look.  in the meantime, here's a
routine to do that (with example test program)

-josh


.org $d748

        ld hl,str
        ld b,10
        ld de,$c089
        call atof
        call $515b
        ret

str:    .db "1.2345",$1b,"678"		; $1b=E

;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

.end

On Wed, 16 Jun 1999 23:45:03 -0400 Aaron Curtis <acurti1@umbc.edu>
writes:
>
>Does anyone know of a rom call that will translate ascii numbers 
>(like
>.db "123") into actual numbers?  Or better yet floating point?  I ask
>because that's how numbers are stored in basic programs, and what you
>type on the screen has to go somewhere...
>
>-Aaron Curtis
>

___________________________________________________________________
Get the Internet just the way you want it.
Free software, free e-mail, and free Internet access for a month!
Try Juno Web: http://dl.www.juno.com/dynoget/tagj.