Jump to content



0

Pokey Keyboard Codes


6 replies to this topic

#1 peteym5 OFFLINE  

peteym5

    Dragonstomper

  • 769 posts
  • Location:Western New York USA

Posted Sat Sep 24, 2011 2:32 AM

I am trying to add pause and other functions to my games. When I read KBCODE from Pokey, it reads the current or last key pressed. I have custom VBI and not using the system VBI. Is there something there that can set the KBCODE back to 255 when the key is depressed?

#2 Synthpopalooza OFFLINE  

Synthpopalooza

    Moonsweeper

  • 299 posts
  • Location:knoxville, TN

Posted Sat Sep 24, 2011 5:35 AM

I'm not very good at assembler, but I think there is a location (SRTIMR?) at location 555 decimal which may be of use. It reads 0 when no key is pressed, and a nonzero value when you press a key. Maybe using this timer during your VBI can be of use, have it reset KBCODE to 255 if this location equals 0.

When programming BASIC, I use this location (555) when doing a "press any key to continue" wait for keypress, like this:

10 ? "PRESS ANY KEY TO CONTINUE"
20 IF NOT PEEK(555) THEN 20

Hope this helps

#3 Rybags OFFLINE  

Rybags

    Quadrunner

  • 10,313 posts
  • Location:Australia

Posted Sat Sep 24, 2011 6:51 AM

If you don't let the OS run it's Stage 2 VBlank, the keyboard processing gets screwed up a bit.

ie, the auto repeat won't work, and the debounce timer doesn't count down which means you can't have successive presses of the same key.

You could read the keycode direct from Pokey, and use SKSTAT to determine if the key is held down or not. The keycode register on Pokey doesn't get "reset", it will always hold the value of last keypress even if it happened hours ago.

Another option is to just replicate what the OS does in it's VBlank. The debounce portion shouldn't be too long, and you can do away with auto-repeat anyhow in many cases.

Edited by Rybags, Sat Sep 24, 2011 6:52 AM.


#4 Creature XL OFFLINE  

Creature XL

    Moonsweeper

  • 297 posts
  • Location:Hannover.De

Posted Sat Sep 24, 2011 10:08 AM

i am short on time so I just paste key handling code out of my source code.
Hope you understand it. The routine is called every VBI. You need a mykey variable obviously.


;
;
; Check if a key is pressed/released and change note/ envelope
;
checkkey:
  lda mykey
  beq @space
  cmp #255
  beq @nokey
  lda SKSTAT
  and #$04
  bne @up
  rts
@up:
  movei 255,mykey
  jsr sound_keyup
  rts
@nokey:
  lda SKSTAT
  and #$04
  beq @down
  rts
@down:
  ldy KBCODE
  sty mykey
  jsr sound_keydown
@space:
  lda COLOR4
  eor #$f0
  sta COLOR4
  rts


And here are the key-codes ready to include into ca65 (or other assemblers?)

KEY_A  = 63
KEY_S  = 62
KEY_G  = 61
KEY_Cap  = 60
KEY_D  = 58
KEY_H  = 57
KEY_F  = 56
KEY_Great = 55
KEY_Less = 54
KEY_8  = 53
KEY_BSp  = 52
KEY_7  = 51
KEY_0  = 50
KEY_9  = 48
KEY_Q  = 47
KEY_W  = 46
KEY_T  = 45
KEY_Tab  = 44
KEY_Y  = 43
KEY_E  = 42
KEY_R  = 40
KEY_Inv  = 39
KEY_Slash = 38
KEY_M  = 37
KEY_N  = 35
KEY_Dot  = 34
KEY_Spa  = 33
KEY_Comma = 32
KEY_1  = 31
KEY_2  = 30
KEY_5  = 29
KEY_Esc  = 28
KEY_6  = 27
KEY_3  = 26
KEY_4  = 24
KEY_Z  = 23
KEY_X  = 22
KEY_B  = 21
KEY_F4  = 20
KEY_F3  = 19
KEY_C  = 18
KEY_Hlp  = 17
KEY_V  = 16
KEY_Equal = 15
KEY_Minus = 14
KEY_I  = 13
KEY_Ret  = 12
KEY_U  = 11
KEY_P  = 10
KEY_O  = 8
KEY_Aster = 7
KEY_plus = 6
KEY_K  = 5
KEY_F2  = 4
KEY_F1  = 3
KEY_Semi = 2
KEY_J  = 1
KEY_L  = 0


#5 Tezz OFFLINE  

Tezz

    Stargunner

  • 1,799 posts
  • Location:Manchester, England

Posted Sat Sep 24, 2011 11:17 AM

I do it exactly as Rybags describes replicating the os debounce

    mwa #irq $fffe
    mva #0 $d20e         ;(IRQEN) off. Using keybounce instead


irq
    phr
    mva #0 $d20e
    ldy $d209
    lda keycode,y
    sta 764
    cmp #0            ; example space bar
    beq [whatever]
    cmp #$9b        ; example return key
    beq [something else]
    mva #$40 $d20e
    plr
    rti


keycode    .array 255 .byte = $ff

    [63]:[127] = "A"
    [21]:[85]  = "B"
    [18]:[82]  = "C"
    [58]:[122] = "D"
    [42]:[106] = "E"
    [56]:[120] = "F"
    [61]:[125] = "G"
    [57]:[121] = "H"
    [13]:[77]  = "I"
    [1] :[65]  = "J"
    [5] :[69]  = "K"
    [0] :[64]  = "L"
    [37]:[101] = "M"
    [35]:[99]  = "N"
    [8] :[72]  = "O"
    [10]:[74]  = "P"
    [47]:[111] = "Q"
    [40]:[104] = "R"
    [62]:[126] = "S"
    [45]:[109] = "T"
    [11]:[75]  = "U"
    [16]:[80]  = "V"
    [46]:[110] = "W"
    [22]:[86]  = "X"
    [43]:[107] = "Y"
    [23]:[87]  = "Z"
    [33]:[97]  = " "
    [52]:[180] = $7e
    [12]:[76]  = $9b

    .enda

Edited by Tezz, Sat Sep 24, 2011 11:33 AM.


#6 Tezz OFFLINE  

Tezz

    Stargunner

  • 1,799 posts
  • Location:Manchester, England

Posted Sat Sep 24, 2011 11:35 AM

P.S. to Mods:

Editing a post using full editor needs to be looked at :)

#7 phaeron OFFLINE  

phaeron

    Dragonstomper

  • 629 posts
  • Location:USA

Posted Sat Sep 24, 2011 12:25 PM

Yup, the keyboard IRQ (IRQEN/ST bit 6) is the way to go here.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users