Re: A86: Number input


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

Re: A86: Number input




Cassady Roop wrote:
> I'm sure this is probably a dumb question, but how would you get a three
> digit number input from the user?

Converting it from three ascii numbers to one hex is pretty easy, actually. 
First, you'll either have to use _getkey or use some kind of table to convert
the GET_KEY codes, because they won'r work the way they are.  Do the following:

GetHund:
 call _getkey
 cp $30              ;Zero
 jr c,GetHund
 cp $3A              ;Nine + 1
 jr nc,GetHund
 sub $30             ;a = #
 add a,a             ;a = # * 2
 ld c,a              ;c = # * 2
 add a,a             ;a = # * 4
 add a,a             ;a = # * 8
 add a,c             ;a = # * 10
 ld b,a
GetTen:
 call _getkey
 cp $30
 jr c,GetTen
 cp $3A
 jr nc,GetTen
 add a,b             ;a = # + (10 * old#)
 add a,a             ;a = # * 2
 ld c,a              ;c = # * 2
 add a,a             ;a = # * 4
 add a,a             ;a = # * 8
 add a,c             ;a = # * 10
 ld b,a
GetOne:
 call _getkey
 cp $30
 jr c,GetOne
 cp $3A
 jr nc,GetOne
 sub $30
 add a,b

Now a is the three-digit number they entered (if it's less than 255 - if it's
over, it's the number they entered modulo 256).
-- 
Dark Ryder
ICQ#:     8189903
E-Mail:   DarkRyder@cyberdude.com

Happiness is inversely proportional to how much you want to upgrade your
computer.

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS/CC/ED/IT/M/MU/P/S/O/AT (!)d-? s++(+):+(++) a?--- C++++$
UB>L+++ P L>+++ E- W+++$ !N o? K- w(---)$ !O M(+)(-) V?
PS+(+++) PE-- Y PGP t*+(+++) 5++ X+ R*+++ tv b+++ DI++++
D++ G++>++++ e*>+++++ h!>++ r-(+) y**++
------END GEEK CODE BLOCK------


References: