Re: A86: Number input


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

Re: A86: Number input




You can use _getkey to do this, you just have to convert the number first.
Sorry, this code is not optimized very well, because I'm too tired to think
about all the shifts and carries.  But you should get the general idea.
Instead of adding 16 bits, you can just shift the lower part and the upper
part separately.  I'll post a better routine tomorow if someone wants it:

read3dignum:		; ***NOT TESTED***
call getdig
ld h,0
ld l,a
add hl,hl		; * 2
add hl,hl		; * 4
ld d,h
ld e,l
add hl,hl		; * 8
add hl,hl		; * 16
add hl,hl		; * 32
ld b,h
ld c,l
add hl,hl		; * 64
add hl,bc		; (* 64 + * 32) = * 96
add hl,de		; (* 96 + * 4) = * 100
ex de,hl
call getdig
sla a			; * 2
ld b,a
sla a			; * 4
sla a			; * 8
add a,b		; (* 8 + * 2) = * 10
ld h,0
ld l,a
add hl,de
call getdig
ld d,0
ld e,a
add hl,de
ret

getdig:		; returns number pressed in A
call _getkey		; read key (if _getkey destroys regs, push 'em)
jr z,getdig		; wait for key
sub k0			; are in order 0-9
cp 10			; should be range 0-9
jr nc,getdig		; wait for number
ret


At 08:14 PM 9/28/98 -0700, you wrote:
>
>I'm sure this is probably a dumb question, but how would you get a three
>digit number input from the user?  
>
>I can easily get it a digit at a time, by _getkey, but that would leave
>me with a three byte number where one byte would suffice.  And I can't
>use it in math functions that way.  What I want is to be able to get a
>three digit input into one register so that I can do stuff to it.
>

--
David Phillips
mailto:electrum@tfs.net
ICQ: 13811951
AOL/AIM: Electrum32