I was working on my Zelda App, and while referencing the learnti83plusAsmin28days tutorial about the keygroups I realized a definite reversable relationship between the getcsc codes and the direct input codes.After a lot of toil, i came up with this exceedingly small routine that checks whether or not a particular key is pressed!


Code:
;-----> CheckKeys
;input:a=getcsc keycode
;output:z=is_pressed
CheckKey:
  dec a
  ld b,%00000001
  ld c,%11111110
ck_loop1:
  cp 8
  jr c,ck_loop2
  rlc c
  sub 8
  jr ck_loop1
ck_loop2:
  or a
  jr z,ck_cont
  rl b
  dec a
  jr ck_loop2
ck_cont:
  ld a,0FFh
  out (1),a
  ld a,c
  out (1),a
  in a,(1)
  and b
  ret


I realized that the getcsc key equates shifted through keygroups in decending order and the decending order of the direct keygroups just shifted a zero to the left:

Code:
eg. $FE=%11111110, $FD=%11111101

The getcsc key equates also changed keygroups every 8 numbers. So, instead of using a lookup table, i used this...

Code:
  $FE rlc*(getcsc-key/8)

and then i used then just used another rotation to get the mask.

I've tested it and it works for the most part, but strangely, some key's aren't coming out right.Like if I test-, +, and then Left to see if all three are pressed, the it'll check for Right instead of Left.Yet if I check Enter,2nd, and Left it'll turn out like its supposed to.i can only think i might need a delay for the port, but if you understand this routine and have a solution, tell me.
weird
I seem to recall issues with my implementation. My code for scanning each row has short delays in it before I/O requests:

Code:
ScanNextGroup
   ld a,$FF
   push ix
   pop ix
   out (1),a
   ld a,c
   push ix
   pop ix
   out (1),a
   push ix
   pop ix
   in a,(1)

I also ensure that the calculator is running at 6MHz before polling the keyboard.
benryves wrote:
I seem to recall issues with my implementation. My code for scanning each row has short delays in it before I/O requests:

Code:
ScanNextGroup
   ld a,$FF
   push ix
   pop ix
   out (1),a
   ld a,c
   push ix
   pop ix
   out (1),a
   push ix
   pop ix
   in a,(1)

I also ensure that the calculator is running at 6MHz before polling the keyboard.
In my experiences with Doors CS, both 6MHz and 15MHz calculators happily execute with 8 cycles in between the out and in:


Code:
out (1),a
nop \ nop
in a,(1)
You have 30 cycles in between there, so that will probably work at least as well if not better.
I just realized the error only occurs when I check 2 keys that use the same port, and the a key from a different port.Here's my testing code...


Code:
#define CheckKey(key) ld a,key \ call CheckKey

mainloop:
  CheckKey(GSubtract)
  jr nz,mainloop
  CheckKey(GAdd)    ;same group as above
  jr nz,mainloop
  CheckKey(GLeft)
  jr nz,mainloop
quit:
  appret


just so everyone knows, appret is just short definition for bjump return used in apps.Anyway, after checking the top two, it checks GRight instead of GLeft.

So, outside the errors, what do you think of my approach to converting getcsc key equate to direct input?
Anakclusmos wrote:
I just realized the error only occurs when I check 2 keys that use the same port, and the a key from a different port.Here's my testing code...


Code:
#define CheckKey(key) ld a,key \ call CheckKey

mainloop:
  CheckKey(GSubtract)
  jr nz,mainloop
  CheckKey(GAdd)    ;same group as above
  jr nz,mainloop
  CheckKey(GLeft)
  jr nz,mainloop
quit:
  appret


just so everyone knows, appret is just short definition for bjump return used in apps.Anyway, after checking the top two, it checks GRight instead of GLeft.

So, outside the errors, what do you think of my approach to converting getcsc key equate to direct input?
Since you seem to have completely ignored me, add a nop \ nop in between the following two lines:


Code:
  out (1),a
  in a,(1)
Yes, this is already documented.
no its not, GetCSC checks the keys and outputs a single keycode. My CheckKey routine routine checks if a particular key is pressed, so you can check multiple keys at the same time like:

CheckKey(GLeft)
CheckKey(G2nd)
DrDnar wrote:
Yes, this is already documented.
Yeah, I didn't want to mention that; he seemed proud of his work. Smile
BUT ITS NOT THE SAME!!!

Theirs:
Input: none
Output: a=keycode

Mine:
Input: a=keycode
Output: z=is pressed

big difference! using mine you can check multiple keys, using theirs you can only check 1
Anakclusmos wrote:
BUT ITS NOT THE SAME!!!

Theirs:
Input: none
Output: a=keycode

Mine:
Input: a=keycode
Output: z=is pressed

big difference! using mine you can check multiple keys, using theirs you can only check 1
Wait, from Theirs/Mine, isn't Mine=Theirs + cp a?
No, i you look closer you realize mine takes a getcsc keycode and converts it into both a group and keymask. it then uses the 2 to look up key using direct input allowing you to check any key. The documented one just checks the keypads and outputs the first one it finds.
Anakclusmos wrote:
No, i you look closer you realize mine takes a getcsc keycode and converts it into both a group and keymask. it then uses the 2 to look up key using direct input allowing you to check any key. The documented one just checks the keypads and outputs the first one it finds.
Ahhh, I see the distinction there. Thanks for the clarification. Smile
so NOW is it a breakthrough?
Anakclusmos wrote:
so NOW is it a breakthrough?
I don't know if I would exactly call it a breakthrough, but it's certainly very handy for people who want multiple keypresses without actually doing their own direct input.
Neutral I guess i can settle with 'handy'.'handy' is fine.Especially since no one's done it before. And its a microscopically small routine. And it'll definitely be in EchoOS.

(IN YA FACES!!! ^cabbage patching emoticon here^)
Anakclusmos wrote:
Neutral I guess i can settle with 'handy'.'handy' is fine.Especially since no one's done it before. And its a microscopically small routine. And it'll definitely be in EchoOS.

(IN YA FACES!!! ^cabbage patching emoticon here^)
Oh yeah, EchoOs. That makes four different community OS projects underway that I know of.
EchoOS is a shell to my knowledge, or am I mistaken?
I tried adding the 2 NOP's and it still isn't working when you check 2 key in the same group and then a third from another, like:
GSubtract +GAdd + GLeft
It cancels out the third key.

Oh, and EchoOS is a shell.
I said "already documented" in response to the "definite reversable relationship between the getcsc codes and the direct input codes." I didn't mean to say that his unique take on key input had already been done.
  
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
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement