chirp8 icon indicating copy to clipboard operation
chirp8 copied to clipboard

Implement key presses

Open mratsim opened this issue 7 years ago • 1 comments

Currently there is no keypress support.

The following loop must be modified:

https://github.com/mratsim/chirp8/blob/ba98bdbd09166958df6aea19b135659fe1e2a17a/src/chirp8.nim#L34-L44

KeyDOWN matches pressing KeyUp matches release

So something like that can be done

 while gameState.running: 
   while sdl2.pollEvent(gameState.event): 
     case gameState.event.kind: 
     of QuitEvent: 
       gameState.running = false 
       break 
     of KeyDown: 
       case event.key.keysym.sym:
       of K_KP0: foo(key0)
       of K_KP1: foo(key1)
       ...
     else: 
       break 

Keycodes are available here: https://github.com/nim-lang/sdl2/blob/master/src/sdl2/private/keycodes.nim

A new "key" array should be added to store the key states (up or down)

Layout

The original key layout is this:

2018-03-31_11-28-02

with 2-4-6-8 corresponding to up left right down.

Ideally Chirp-8 should read mapping from a .cfg to so that people can customize their keyboard mapping:

  • laptops without a keypad
  • non-QWERTY keyboard
  • ...

cc @Vindaar

mratsim avatar Mar 31 '18 09:03 mratsim

With commits https://github.com/mratsim/chirp8/commit/fa809d48a56567169f92cd434b17b9f7053dcd6f and https://github.com/mratsim/chirp8/commit/1c0d7481c13390b3dc6ab445d72d885c31656db7 basic key input is in place now, including custom keybindings set in config/keybindings.cfg.

The F00A instruction is the only one still missing.

Vindaar avatar Apr 02 '18 13:04 Vindaar