Git Product home page Git Product logo

chirp8's Introduction

Chirp-8

License: Apache Stability: experimental

A Chip-8 emulator in Nim

Status: most of the instructions are properly emulated. This WIP branch contains hardcoded key presses for two key input instructions: Ex9E (skip next instruction if a key x is pressed) and ExA1 (skip next instruction if key x is not pressed). The instruction F00A is yet to be implemented.

The keybindings are defined in the file. The location of the config file is currently hardcoded and depends on the binary being called from src.

Some example keys for the current keybindings are as follows:

Pong:
    Arrow up: paddle up
    Arrow down: paddle down
Space Invaders:
    Arrow down: ship left
    Arrow right: ship right
Tetris:
    W: move block left
    A: drop block faster
    Arrow down: rotate block
    Arrow right: move block right

As one can see, the keys are somewhat all over the place and in principle need to be set for each game individually.

Some GIFs:

Pong Tetris Space Invaders

Known issues

The emulation seems to be somewhat broken as of now. Collision detection does not really work in some cases, e.g. the ball simply resets before it hits the opposite paddle in pong and the blocks in tetris fall through the floor. There is also quite some flickering happening.

chirp8's People

Contributors

mratsim avatar vindaar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

chirp8's Issues

Implement key presses

Currently there is no keypress support.

The following loop must be modified:

chirp8/src/chirp8.nim

Lines 34 to 44 in ba98bdb

while gameState.running:
while sdl2.pollEvent(gameState.event):
case gameState.event.kind:
of QuitEvent:
gameState.running = false
break
of KeyDown:
gameState.running = false
break
else:
break

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.