March 22, 2001 Daniel Lidström & Beto danli97@ite.mh.se Reading the keyboard in ml on the HP49G ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ OUT/IN masks ^^^^^^^^^^^^ To read individual keys, you may use the method of reading directly from the OUT register. Below is a table of values of IN and OUT masks for the HP49G keyboard. Observe that you must use CINRTN to execute C=IN because of the well known bug. Example ^^^^^^^ To check if A is pressed: ********************************************************************** * Adown? * Returns carry set if A is down ********************************************************************** Adown? LCHEX 00020 out mask OUT=C GOSBVL =CINRTN LAHEX 00001 in mask C=C&A A ?C#0 A RTNYES return CS if key is down RTN ********************************************************************** * OUT/IN table ********************************************************************** A B C D E F 020/001 020/002 020/004 020/008 020/010 020/020 UpArrow G H I 040/008 020/080 010/080 008/080 LeftArrow RightArrow 040/004 040/001 J K L 004/080 002/080 001/080 DownArrow 040/002 M N O P <- 010/040 008/040 004/040 002/040 001/040 Q R S T U 010/020 008/020 004/020 002/020 001/020 V W X Y Z 010/010 008/010 004/010 002/010 001/010 Alpha 7 8 9 * 080/008 008/008 004/008 002/008 001/008 L-Shift 4 5 6 - 080/004 008/004 004/004 002/004 001/004 R-Shift 1 2 3 + 080/002 008/002 004/002 002/002 001/002 ON 0 . SPC ENTER /8000 008/001 004/001 002/001 001/001 ********************************************************************** Debounce ^^^^^^^^ Another method to read more than one key at a time is to use the ROM routine Debounce (#2678A). This routine scans the keyboard until it has been stable for one timer tick and returns a bitmap of pressed keys in A[W]. After you've called Debounce you may either load a bit mask to see if your key(s) is pressed or generate a number from the bitmap. Observe that more than one key may be down. The bitmap returned in A[W] is shown below: Nibble Bit3 Bit2 Bit1 Bit0 ^^^^^^ ^^^^ ^^^^ ^^^^ ^^^^ 15 [L] [DROP] [U] [Z] 14 [*] [-] [+] [ENTER] 13 [K] [P] [T] [Y] 12 [9] [6] [3] [SPC] 11 [J] [O] [S] [X] 10 [8] [5] [2] [.] 9 [I] [N] [R] [W] 8 [7] [4] [1] [0] 7 [H] [M] [Q] [V] 6 [] [] [] [] 5 [G] [] [F] [E] 4 [D] [C] [B] [A] 3 [] [] [] [] 2 [^] [<-] [v] [->] 1 [] [] [] [] 0 [ALPHA] [<-|] [|->] [ON] As you see, there are a few bits that don't correspond to any keys. To generate a number from the bitmask you can use the following piece of code: ********************************************************************** * KeyNum * Returns number of key pressed in B[B] * A[W] = key bitmap with at least one bit set! ********************************************************************** KeyNum B=0 A - ?A#0 P <---+ GOYES findBit >---+---+ B=B+CON A,4 | | ASR W | v GONC - >---+ | findBit B=B+1 A <---<---+ ASRB.F P | ?A=0 P ^ RTNYES | GONC findBit >--->---+ This subroutine will number [ON]=1, [|->]=2, and so on.