Re: A86: menu style decimal input
[Prev][Next][Index][Thread]
Re: A86: menu style decimal input
here's a two-step routine that'll input a floating point number in the
small font. i've fixed whatever that bug was in my original atof routine
as well.
;example use:
ld hl,$3a00 ;input on bottom line
ld (_penCol),hl
ld hl,_op3 ;buffer
call vgetd ;get number as string
ld b,c ;get length to b
ld de,_op1 ;store to op1
call atof ;convert string to fp
call _dispop1
ret
;-josh
;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
;get decimal
;enter:
; hl -> buffer
;return:
; hl -> buffer 0 term
; a = return code K_EXIT,K_ENTER,or K_XVAR
; bc = length
vgetd: push hl
push hl
vgetdloop:
ld a,(_penCol)
ld b,a
ld a,$d0 ;cursor
call _vputmap
ld a,b
ld (_penCol),a
vgetdkey:
halt
call GET_KEY
cp K_NOKEY
jr z,vgetdkey
cp K_EXIT
jr z,vgetdexit
cp K_XVAR
jr z,vgetddone
cp K_ENTER
jr z,vgetddone
cp K_DOT
jr z,vgetddot
ld b,10
ld hl,vgetddigit
vgetdcheckd:
cp (hl)
inc hl
jr z,vgetdnumber
djnz vgetdcheckd
jr z,vgetdnumber ;go get d number...
jr vgetdkey
vgetddot:
ld a,'.' ;dot!
vgetdput:
pop hl
ld (hl),a
inc hl
push hl
call _vputmap
jr vgetdloop
vgetdnumber:
ld a,b ;translate number
add $30-1
jr vgetdput
vgetdret:
push de
ld b,a
ld a,(_penCol) ;clear cursor
ld c,a
ld a,$20
call _vputmap
ld a,$20
call _vputmap
ld a,$20
call _vputmap
ld a,c
ld (_penCol),a
ld a,b ;return with key hit
pop bc ;bc=length
ret
vgetdexit:
pop hl
pop hl
ld (hl),'0' ;print string as 0
inc hl
ld (hl),0
dec hl
ld de,0 ;register nothing
jr vgetdret
vgetddone:
pop hl
ld (hl),0
pop de
or a ;clear carry
sbc hl,de ;get length
ex de,hl
jr vgetdret
vgetddigit: .db K_9,K_8,K_7,K_6,K_5,K_4,K_3,K_2,K_1,K_0
On Sat, 24 Apr 1999 06:57:10 -0400 "Jimi Malcolm"
<MalcolmJ1@email.msn.com> writes:
>
>has anyone made a routine for the ti86 that will allow the user to
>input a
>value using the number pad and will store the value into a register?
>i've
>tried a bunch of different ways but i'm stuck.
>
>even if i had to resort to checking for each key (k0 through k9)
>individually, i don't know how to leave the routine with all the
>value
>stored in hl.
>
>the best try yet was when i tried to have the user input it as a
>string
>(which i got working) and then the next routine reads the string and
>subtracts 48 so it's not ascii anymore and then multplies that times
>100,
>the next times 10 and the last times 1 and then adds them all. but
>that
>failed too.
>
>jimi
>
>
>
>
___________________________________________________________________
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: