This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's
z80 & ez80 Assembly subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.
Z80 & 68k Assembly =>
z80 & ez80 Assembly
Author |
Message |
|
tbuckne2
Newbie
Joined: 27 May 2010 Posts: 1
|
Posted: 27 May 2010 07:50:38 pm Post subject: |
|
|
Alright, just starting out here with TI assembly. I've done some user input with GetKey and GetCSC but those give me key codes and scan codes. How do I just get a number, like if the user pressed 7, how do I get that (to be stored into A or something)? I can see how I could use GetKey and subtract $8E from the Key Code to give me the number, but what about GetCSC? There's no such pattern and I don't want to fill up space with a look-up table if possible. Using the ports seems to have an even more random pattern. What's a good way to do this if I don't want to use GetKey? Seems like it should be easy, considering some people might use their calculators for MATH (which I hear uses numbers).
Thanks |
|
Back to top |
|
|
FloppusMaximus
Advanced Member
Joined: 22 Aug 2008 Posts: 472
|
Posted: 27 May 2010 08:58:36 pm Post subject: |
|
|
No, there's no easy way out that you've missed. :)
The values returned by GetCSC correspond directly to the keypad hardware, and as you can see, they don't have much of anything to do with the labels on the keys. The GetKey routine has an internal lookup table that it uses to translate these "raw" GetCSC values into more logical key codes, but there's no OS-independent way for assembly programs to use that table. You either need to include your own lookup table, or else come up with a clever trick to avoid it.
Sadly, the cleverest trick I can think of at the moment is 24 bytes:
Code:
; input: A = scan code returned by GetCSC
sub sk0
jr z,number_ok
dec a
ld b,a
and 7
cp 3
jr nc,not_a_number
ld c,a
sub b
rrca
rrca
rrca
cp 3
jr nc,not_a_number
adc a,c
add a,c
add a,c
number_ok:
; A = numeric value 0-9
Whereas the following table-based version is only 21 bytes:
Code:
ld hl,num_key_table
ld bc,10
cpir
jr nz,not_a_number
ld a,c
number_ok:
...
num_key_table: .db sk9, sk8, sk7, sk6, sk5, sk4, sk3, sk2, sk1, sk0
|
|
Back to top |
|
|
calc84maniac
Elite
Joined: 22 Jan 2007 Posts: 770
|
Posted: 29 May 2010 10:03:58 pm Post subject: |
|
|
That look-up table method actually seems pretty clever to me. Nice job. |
|
Back to top |
|
|
|
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.
»
Go to Registration page