Skip to content

Commit

Permalink
Implements controls.
Browse files Browse the repository at this point in the history
Implements rest of the 0x8XXX range opcodes.
  • Loading branch information
danmrichards committed Nov 14, 2018
1 parent 888d584 commit fcfa0af
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 44 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ Usage of chip8:
Path to the ROM file to load
```

## Controls
The Chip8 has a 16 key hex keyboard. For the purposes of this emulator it has
been implemented like so:
```
+---+---+---+---+
| 1 | 2 | 3 | 4 |
+---+---+---+---+
| Q | W | E | R |
+---+---+---+---+
| A | S | D | F |
+---+---+---+---+
| Z | X | C | V |
+---+---+---+---+
```
> Note: Which of these keys are actually used will differ from ROM to ROM.
## References
As this was a learning exercise I had to seek a lot of help from the interwebs:
* [https://medium.com/average-coder/exploring-emulation-in-go-chip-8-636f99683f2a][3]
Expand Down
21 changes: 19 additions & 2 deletions cmd/chip8/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ var (
vm *chip8.VM
window *pixelgl.Window

// TODO: Abstract this.
keys = map[uint16]pixelgl.Button{
0x1: pixelgl.Key1, 0x2: pixelgl.Key2, 0x3: pixelgl.Key3, 0xC: pixelgl.Key4,
0x4: pixelgl.KeyQ, 0x5: pixelgl.KeyW, 0x6: pixelgl.KeyE, 0xD: pixelgl.KeyR,
0x7: pixelgl.KeyA, 0x8: pixelgl.KeyS, 0x9: pixelgl.KeyD, 0xE: pixelgl.KeyF,
0xA: pixelgl.KeyZ, 0x0: pixelgl.KeyX, 0xB: pixelgl.KeyC, 0xF: pixelgl.KeyV,
}

rom string
debug bool
)
Expand Down Expand Up @@ -94,11 +102,11 @@ func run() {
log.Fatal(err)
}

inputHandler()

// A bit dirty, but block the next cycle until a tick. This prevents
// the emulator from running too quickly.
<-tick.C

// TODO: Store the key press state.
}
}

Expand All @@ -116,6 +124,7 @@ func eventHandler() {
}
}

// TODO: Abstract this.
func drawScreen() {
window.Clear(colornames.Black)

Expand Down Expand Up @@ -147,3 +156,11 @@ func drawScreen() {
imd.Draw(window)
window.Update()
}

func inputHandler() {
for i, key := range keys {
if window.Pressed(key) {
vm.KeyDown(i)
}
}
}
Loading

0 comments on commit fcfa0af

Please sign in to comment.