Jump to content

Photo

detecting special keys independently of other keys being pressed?

(Console and T.I. XB only)

8 replies to this topic

#1 ramidavis ONLINE  

ramidavis

    Star Raider

  • 67 posts

Posted Tue Oct 17, 2017 5:54 PM

Is there a good way to detect a special key being pressed?

By special key i mean: ftcn, ctrl, shift, and alpha-lock.

What i want is a way to tell for instance if the user briefly engages the alpha-lock for a second or two and then releases it.

Or, be able to tell if that "any key" i asked them to hit at the title screen just happened to be the fctn or ctrl key, by themselves.

If you can pick up the shift key being pressed and released, is there any way to differentiate between L-shift and R-shift



#2 jedimatt42 OFFLINE  

jedimatt42

    Stargunner

  • 1,260 posts
  • Location:Beaverton, OR

Posted Tue Oct 17, 2017 10:46 PM

http://www.unige.ch/...99/keyboard.htm

Electrically, both shift keys are the same. The link above covers everything you never wanted to know.

TI's BASICS don't support testing for the modifiers alone. But in any other language that gives you access to setting and testing CRU bits you can.

-M@

#3 RXB OFFLINE  

RXB

    River Patroller

  • 2,812 posts
  • Location:Vancouver, Washington, USA

Posted Wed Oct 18, 2017 12:14 AM

RXB on REAL TI99/4A can detect up to 4 keys being pressed if you scan some rows using RXB command CALL IO for CRU reading of each Keyboard line.

 

Of course the Alpha Lock key will kill off the Joystick UP line if depressed as it cuts off the reading of this line from seeing the UP line on Joysticks.

 

Here is a map and using CRU address lines (divided by 2) in RXB allows you to read each line of keys being scaned:



============================================================================================
= .	Column	0	1	2	3	4	5	6	7	A-lock     =
= R12 address	Pin #	12	13	14	15	9	8	J7	J2	6  =
= >0006	5/J4	=	.	,	M	N	/	Fire	Fire               =
= >0008	4/J5	Space	L	K	J	H	;	Left	Left               =
= >000A	1/J9	Enter	O	I	U	Y	P	Right	Right              =
= >000C	2/J8	                                                                           =
= 9	8	7	6	0	Down	Down                                       =
= >000E	7/J3	Fctn	2	3	4	5	1	Up	Up	A-lock     =
= >0010	3	Shift	S	D	F	G	A	                           =
=                                                                                          =
= >0012	10	Ctrl	W	E	R	T	Q	                           =
=                                                                                          =
= >0014	11	                                                                           =
= X	C	V	B	Z	                                                   =
============================================================================================

Example: CALL IO(2,16,3,A,B) 

Would put the key scan line pin values of     =   .    ,   M N /  Fire1 Fire2

The values of                                               12 13 14 15 9 8  J7      J8

 

RXB can do things no other XB can possible do.

 

To read more then one keyboard line at a time just add more variables EXAMPLE: CALL IO(2,16,3,A,B,2,16,4,C,D) 

this would read CRU line 6 and CRU line 8 of the keyboard (CRU value 6 and 8 divided by 2) into variables A & B and C & D


Edited by RXB, Wed Oct 18, 2017 12:19 AM.


#4 mizapf OFFLINE  

mizapf

    River Patroller

  • 2,588 posts
  • Location:Germany

Posted Wed Oct 18, 2017 5:57 AM

If you decided to use assembly language after all, http://atariage.com/...y0ab/?p=3865591shows you a simple tool to query those keys.



#5 Lee Stewart OFFLINE  

Lee Stewart

    River Patroller

  • 3,392 posts
  • Location:Silver Run, Maryland

Posted Thu Oct 19, 2017 10:25 AM

You can do the same as Assembly Language with fbForth CRU words.

 

...lee



#6 TheBF OFFLINE  

TheBF

    Moonsweeper

  • 371 posts
  • Location:The Great White North

Posted Sat Oct 21, 2017 8:24 AM

I too wanted a faster way to catch a keystroke. Mine was to break out of loops without slowing the loop down too much.

 

This is little routine will only detect a control C key press.  But it could be configured to different keys. It is 4 times faster than using KSCAN.

(approx. 250ms vs over 1mS)

 

Here is the matrix I used to understand how to do it.

\  R1     TB 0    TB 1    TB 2    TB 3    TB 4    TB 5    TB 6    TB 7
\ ---------------------------------------------------------------------
\ 0000    =       space   enter           fctn    shift   ctrl
\ 0100    .       L       O       9       2       S       W       X
\ 0200    ,       K       I       8       3       D       E       C
\ 0300    M       J       U       7       4       F       R       V
\ 0400    N       H       Y       6       5       G       T       B
\ 0500    /       ;       P       0       1       A       Q       Z
\ 0600    Fire1   Left1   Right1  Down1   Up1
\ 0700    Fire2   Left2   Right2  Down2   Up2
\ ---------------------------------------------------------------------

Written in reverse assembler.  (put the instruction on the other side for conventional assembler)

 

Weirdness:

TOS is just a renamed R4.

PUSH is a macro that moves the stack pointer.   (SP DECT)  and moves  a register ( MOV R4,*SP)

 

The method is I collect bits in R4, while looping through the keyboard rows (Register 1)

 

When R4 = C000  I have a ctrl C pressed.  

 

So by changing that value you could detect any key.

 

I took this code from a more general routine and I am sure it can be improved.

As I look at It, I see it does not need to look at row 0100 at all  for a control C.  Duh!

So I can speed it up more in the future.

CODE: ^C? ( -- ?) \ fast check if ctrl C key pressed
           TOS        PUSH,     \ make room in TOS register
           TOS        CLR,      \ TOS will accumulate keyboard bits
           R1         CLR,      \ R1 is column to read. starts at 0
@@1:       R12  0024  LI,       \ set CRU address for column select chip
           R1   3     LDCR,     \ Set 3 bits of column
           R2         SETO,     \ R2 gets the bits. set all bits to 1
           R12  0006  LI,       \ R12-address to read rows
           R2   8     STCR,     \ store 8 column values (bits)->R2
           R2         INV,      \ outputs are low active so flip bits
           R2  TOS    ADD,      \ collect all the bits in TOS (R4)
           R1 0100    ADDI,     \ advance to next row
           R1 0300    CMPI,     \ are we at row 3?
           @@1        JNE,      \ if not jump back
           SCRTO @@   CLR,      \ Reset TI system screen timeout counter
           TOS C000   CMPI,     \ look for ctrl 'C'. (2 bits set)
           @@2        JEQ,      \ ^C was pressed
           TOS        CLR,      \ no ^C, clear TOS, return to forth
           NEXT,

@@2:       TOS        SETO,     \ set TOS to -1 (Forth true flag)
           NEXT,                \ return to Forth
           END-CODE


#7 Lee Stewart OFFLINE  

Lee Stewart

    River Patroller

  • 3,392 posts
  • Location:Silver Run, Maryland

Posted Sun Oct 22, 2017 12:39 PM

I don't mean to get in the way here, but I am used to seeing this in columns and rows opposite to your presentation as follows:
\ +-----+-----------------------------------------------------------------+------------+
\ |     |<------------------------- COLUMN ------------------------------>|            |
\ +-----+-------+-------+-------+-------+-------+-------+--------+--------+------------+
\ | ROW |   0   |   1   |   2   |   3   |   4   |   5   |   6    |   7    | alpha-lock |
\ +-----+-------+-------+-------+-------+-------+-------+--------+--------+------------+
\ |  0  |   =   |   .   |   ,   |   M   |   N   |   /   | fire1  | fire2  |            |
\ +-----+-------+-------+-------+-------+-------+-------+--------+--------+------------+
\ |  1  | space |   L   |   K   |   J   |   H   |   ;   | left1  | left2  |            |
\ +-----+-------+-------+-------+-------+-------+-------+--------+--------+------------+
\ |  2  | enter |   O   |   I   |   U   |   Y   |   P   | right1 | right2 |            |
\ +-----+-------+-------+-------+-------+-------+-------+--------+--------+------------+
\ |  3  |       |   9   |   8   |   7   |   6   |   0   | down1  | down2  |            |
\ +-----+-------+-------+-------+-------+-------+-------+--------+--------+------------+
\ |  4  | fctn  |   2   |   3   |   4   |   5   |   1   |  up1   |  up2   | alpha-lock |
\ +-----+-------+-------+-------+-------+-------+-------+--------+--------+------------+
\ |  5  | shift |   S   |   D   |   F   |   G   |   A   |        |        |            |
\ +-----+-------+-------+-------+-------+-------+-------+--------+--------+------------+
\ |  6  | ctrl  |   W   |   E   |   R   |   T   |   Q   |        |        |            | 
\ +-----+-------+-------+-------+-------+-------+-------+--------+--------+------------+
\ |  7  |       |   X   |   C   |   V   |   B   |   Z   |        |        |            | 
\ +-----+-------+-------+-------+-------+-------+-------+--------+--------+------------+
Then it is a little less confusing (to me, at least) to change a few of your comments (not your code!) to
 
CODE: ^C? ( -- ?) \ fast check if ctrl C key pressed
           TOS        PUSH,     \ make room in TOS register
           TOS        CLR,      \ TOS will accumulate keyboard bits
           R1         CLR,      \ R1 is column to read. starts at 0
@@1:       R12  0024  LI,       \ set CRU address for column select chip
           R1   3     LDCR,     \ Set 3 bits of column
           R2         SETO,     \ R2 gets the bits. set all bits to 1
           R12  0006  LI,       \ R12-address to read rows
           R2   8     STCR,     \ store 8 row values of current column (bits)->R2 ***
           R2         INV,      \ outputs are low active so flip bits
           R2  TOS    ADD,      \ collect all the bits in TOS (R4)
           R1 0100    ADDI,     \ advance to next column                          ***
           R1 0300    CMPI,     \ are we at column 3?                             ***
           @@1        JNE,      \ if not jump back
           SCRTO @@   CLR,      \ Reset TI system screen timeout counter
           TOS C000   CMPI,     \ look for ctrl 'C'. (2 bits set)
           @@2        JEQ,      \ ^C was pressed
           TOS        CLR,      \ no ^C, clear TOS, return to forth
           NEXT,

@@2:       TOS        SETO,     \ set TOS to -1 (Forth true flag)
           NEXT,                \ return to Forth
           END-CODE

...lee



#8 TheBF OFFLINE  

TheBF

    Moonsweeper

  • 371 posts
  • Location:The Great White North

Posted Sun Oct 22, 2017 8:43 PM

Thanks for the corrections Lee, I will update my source code file.

 

I don't remember where I found the table.  But I know I didn't derive it all by myself.

 

Yours appears to align with the Thierry Nouspikel Web site.

 

So I will avail myself of yours in my source as well with credit to you as it makes more sense.



#9 TheBF OFFLINE  

TheBF

    Moonsweeper

  • 371 posts
  • Location:The Great White North

Posted Sun Oct 22, 2017 9:26 PM

Since I was looking at the code I re-wrote it so it does not look at column 1 by factoring the hardware reading code as a sub-routine.

This further improved the speed from 336uS in the old verison to 273uS but cost 4 bytes of space. The screen capture shows the test results 

using the 9901 timer word 'TMR@"  versus calling KSCAN (ASM word KEY? in Forth)

 

This ctrl C reader is over 4X faster than calling KSCAN

 

Here is the new version in case anybody finds it useful.

To use this concept in TI ASM just remember that TOS is just a re-name for R4.

\ sub routine to read key matrix. Set R1 to the column to read
L: _RKEYS  R12  0024  LI,       \ set CRU address for column select chip
           R1   3     LDCR,     \ Set 3 bits of column
           R2         SETO,     \ R2 gets the bits. set all bits to 1
           R12  0006  LI,       \ R12-address to read rows
           R2   8     STCR,     \ store 8 row values of current column (bits)->R2 ***
           R2         INV,      \ outputs are low active so flip bits
           R2  TOS    ADD,      \ collect all the bits in TOS (R4)
                      RT,

CODE: ^C? ( -- ?) \ fast check if ctrl C key pressed
           TOS        PUSH,     \ make room in TOS register
           TOS        CLR,      \ TOS will accumulate keyboard bits
           R1         CLR,      \ R1 is column to read. starts at 0
          _RKEYS  @@  BL,       \ read keys in column 0
           R1   0200  LI,       \ set column to 2
          _RKEYS  @@  BL,       \ read keys in column 0
           SCRTO  @@  CLR,      \ Reset TI system screen timeout counter
           TOS C000   CMPI,     \ look for ctrl 'C'. (2 bits set)
           @@2        JEQ,      \ ^C was pressed
           TOS        CLR,      \ no ^C, clear TOS, return to forth
           NEXT,

@@2:       TOS        SETO,     \ set TOS to -1 (Forth true flag)
           NEXT,                \ return to Forth
           END-CODE

Attached Files






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users