Hello,
how can you get the key that is pressed right now in axe or assembly?
Muessigb wrote:
Hello,
how can you get the key that is pressed right now in axe or assembly?


Axe:

Code:
getKey

Z80 Assembly (TI-83 Plus):

Code:
bcall(_getCSC)

Z80 Assembly (getCSC scancode reimplentation with extra goodies):

Code:

getKBD:  ;destroys registers AF and BC
 xor a
 call getKBDSC.1
 xor $FF
 ret z
 ld bc,$7F00
getKBDSC.2:
 rlc b
 ld a,b
 bit 7,a
 jr z,getKBDSC.E
 call getKBDSC.1
 cp $FF
 jr nz,getKBDSC.3
 ld a,8
 add a,c
 ld c,a
 jr getKBDSC.2
getKBDSC.3:
 bit 0,b
 jr z,getKBDSC.6   ;autotest for multiple arrow keypress
 inc c
 rrca
 jr c,$-2
 set 7,a
 cp $FF
 jr nz,getKBDSC.E  ;Checking all keys in this group.
getKBDSC.4:        ;Checking all other groups for keypress.
 rlc b
 ld a,b
 jr nc,getKBDSC.5
 call getKBDSC.1
 cp $FF
 jr nz,getKBDSC.E
 jr getKBDSC.4
getKBDSC.5
 ld a,c
 ret
getKBDSC.E:
 xor a
 scf
 ret
getKBDSC.1:
 out (1),a
 push af   ;delay for keyboard to respond
 pop af
 in a,(1)
 push af
  ld a,$FF
  out (1),a
 pop af
 ret
getKBDSC.6:
 push hl
  cpl
  and $0F
  ld l,a
  ld h,0
  ld bc,getKBDSC.7
  add hl,bc
  ld a,(hl)
 pop hl
 ret
getKBDSC.7:
;down--------\
;left-------\|
;right-----\||
;up-------\|||
.db  00  ;0000 0
.db  01  ;0001 1
.db  02  ;0010 2
.db  05  ;0011 3
.db  03  ;0100 4
.db  06  ;0101 5
.db  57  ;0110 6
.db  58  ;0111 7
.db  04  ;1000 8
.db  59  ;1001 9
.db  07  ;1010 A
.db  60  ;1011 B
.db  08  ;1100 C
.db  61  ;1101 D
.db  62  ;1110 E
.db  63  ;1111 F
;For additional keycodes,
;$96=150d
;150 = left/right
;151 = left/right/down
;152 = up/down
;153 = up/left/down
;154 = up/right/down
;155 = up/right/left
;156 = all keys mashed
  
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 1
» 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