Re: A83: ION Numerical Input
[Prev][Next][Index][Thread]
Re: A83: ION Numerical Input
see if you guys can't find any problems with this
routine. it usually works to get 1 number but then it
spits out junk.
--- num.txt ----
;Input: a = max number of digits (up to 14)
;Output: op1 = number, a = # digits entered
data =saferam1+1
numeric:
ld (data),a ; max number of digits
bcall(_getk) ; reset
ld hl,imathptr1 ; -store a routine-
ld a,$E1 ; pop hl
ld (hl),a
inc hl
ld a,$E5 ; push hl
ld (hl),a
inc hl
ld a,$C9 ; ret
ld (hl),a ; -----
call imathptr1
num_address:
ld de,numstr-num_address
add hl,de
ld b,14
xor a
clear_loop:
ld (hl),a
inc hl
djnz clear_loop
ld de,14
sbc hl,de
ld a,(data)
ld (data),hl
ld ix,(data) ; put the address in ix
ld (data),a
xor a
ld (data+1),a
ld b,a
num_loop:
push bc
bcall(_getk)
pop bc
or a
jr z,num_loop
cp 56
jr z,backup ; [DEL] pressed
cp 9
jr z,nums_entered ; [ENTER] pressed
ld c,a
sub 16
jr c,num_loop
sub 5
jr z,num_loop
sub 4
jr c,num_loop
sub 4
jr z,num_loop
sub 4
jr c,num_loop
sub 4
jr z,num_loop
sub 50
jr c,num_loop
ld a,(data) ; max length
cp b
jr z,num_loop
call imathptr1
char_address:
ld de,char_numtable-char_address-10
add hl,de
ld e,c
ld d,0
add hl,de
ld a,(hl)
bcall(_putc) ; display number
sub 48
ld (ix),a ; store "real" #
inc b
inc ix
jr num_loop
backup:
xor a
cp b
jr z,num_loop
dec b
dec ix
ld (ix),0
ld hl,curcol
ld a,(hl)
or a
jr z,newrow2
dec (hl)
ld a,32
bcall(_putc)
dec (hl)
jr num_loop
newrow2:
ld hl,currow
dec (hl) ; go up a row
inc hl
ld (hl),15 ; go to column 15
ld a,32
bcall(_putc)
ld hl,currow
dec (hl)
inc hl
ld (hl),15
jr num_loop
nums_entered: ; no more input
bcall(_op1set0)
ld a,b
ld d,a
ld e,a
ld (data+1),a
or a
ret z
nums_entered_loop:
dec ix
ld a,(ix)
cp $2e-48d
jr z,decimal_found
after_decimal:
djnz nums_entered_loop
ld b,e
ld c,$7f
nums_dec_loop:
inc c
djnz nums_dec_loop
ld b,d
ld hl,op1
ld a,(ix)
cp $2d-48d
jr z,negate_found
after_negate:
inc hl
ld (hl),c
copy_loop:
inc hl
ld a,(ix)
cp $2e-48d
jr nz,copy_loop_cont
inc ix
dec b
jr z,ending
ld a,(ix)
copy_loop_cont:
sla a
sla a
sla a
sla a ; rotate left 4 digits
ld c,a
dec b
jr z,nums_finished
inc ix
ld a,(ix)
cp $2e-48d
jr nz,copy_loop_cont2
inc ix
dec b
jr z,ending
ld a,(ix)
copy_loop_cont2:
or c
ld (hl),a
inc ix
djnz copy_loop
ld a,(data+1)
ret
nums_finished:
xor a
or c
ld (hl),a
ending:
ld a,(data+1)
ret
decimal_found:
ld e,b
dec e
jr after_decimal
negate_found:
ld a,$80
ld (hl),a
inc ix
dec b
dec c
jr after_negate
numstr: .db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
char_numtable:
.db ">>>>>>"
.db ">-369>>>>.258>>>" ; number table
.db ">0147"
--- end of file---
=====
Get free DSL access at http://dslfree.cjb.net__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com