diff --git a/README.md b/README.md index 394bd83..05809df 100644 --- a/README.md +++ b/README.md @@ -217,27 +217,22 @@ customize the operation of the emulator. The Chip 8 has 16 keys: ### Keys The original Chip 8 had a keypad with the numbered keys 0 - 9 and A - F (16 -keys in total). Without any modifications to the emulator, the keys are mapped -as follows: - -| Chip 8 Key | Keyboard Key | -| :--------: | :----------: | -| `1` | `4` | -| `2` | `5` | -| `3` | `6` | -| `4` | `7` | -| `5` | `R` | -| `6` | `T` | -| `7` | `Y` | -| `8` | `U` | -| `9` | `F` | -| `0` | `G` | -| `A` | `H` | -| `B` | `J` | -| `C` | `V` | -| `D` | `B` | -| `E` | `N` | -| `F` | `M` | +keys in total). The original key configuration was as follows: + + +| `1` | `2` | `3` | `C` | +|-----|-----|-----|-----| +| `4` | `5` | `6` | `D` | +| `7` | `8` | `9` | `E` | +| `A` | `0` | `B` | `F` | + +The Chip8 emulator maps them to the following keyboard keys by default: + +| `1` | `2` | `3` | `4` | +|-----|-----|-----|-----| +| `Q` | `W` | `E` | `R` | +| `A` | `S` | `D` | `F` | +| `Z` | `X` | `C` | `V` | If you wish to configure a different key-mapping, simply change the `KEY_MAPPINGS` variable in the configuration file to reflect the mapping that you want. The @@ -249,9 +244,9 @@ list of all the valid constants for keyboard key values. In addition to the key mappings specified in the configuration file, there are additional keys that impact the execution of the emulator. -| Keyboard Key | Effect | -| :----------: | ------ | -| `ESC` | Quits the emulator | +| Keyboard Key | Effect | +| :----------: |--------------------| +| `ESC` | Quits the emulator | ## ROM Compatibility diff --git a/chip8/config.py b/chip8/config.py index 98a1875..1d49afb 100644 --- a/chip8/config.py +++ b/chip8/config.py @@ -21,22 +21,22 @@ # Sets which keys on the keyboard map to the Chip 8 keys KEY_MAPPINGS = { - 0x0: pygame.K_g, - 0x1: pygame.K_4, - 0x2: pygame.K_5, - 0x3: pygame.K_6, - 0x4: pygame.K_7, - 0x5: pygame.K_r, - 0x6: pygame.K_t, - 0x7: pygame.K_y, - 0x8: pygame.K_u, - 0x9: pygame.K_f, - 0xA: pygame.K_h, - 0xB: pygame.K_j, - 0xC: pygame.K_v, - 0xD: pygame.K_b, - 0xE: pygame.K_n, - 0xF: pygame.K_m, + 0x0: pygame.K_x, + 0x1: pygame.K_1, + 0x2: pygame.K_2, + 0x3: pygame.K_3, + 0x4: pygame.K_q, + 0x5: pygame.K_w, + 0x6: pygame.K_e, + 0x7: pygame.K_a, + 0x8: pygame.K_s, + 0x9: pygame.K_d, + 0xA: pygame.K_z, + 0xB: pygame.K_c, + 0xC: pygame.K_4, + 0xD: pygame.K_r, + 0xE: pygame.K_f, + 0xF: pygame.K_v, } # The font file to use diff --git a/chip8/cpu.py b/chip8/cpu.py index 60e7d1a..e795458 100644 --- a/chip8/cpu.py +++ b/chip8/cpu.py @@ -84,7 +84,7 @@ def reset(self): self.rpl = [0] * NUM_REGISTERS -class Chip8CPU(object): +class Chip8CPU: """ A class to emulate a Chip 8 CPU. There are several good resources out on the web that describe the internals of the Chip 8 CPU. For example: diff --git a/test/test_chip8cpu.py b/test/test_chip8cpu.py index e9c1e79..3d9a7ba 100644 --- a/test/test_chip8cpu.py +++ b/test/test_chip8cpu.py @@ -533,7 +533,7 @@ def test_operation_9E_pc_skips_if_key_pressed(self): self.cpu.registers.v[0] = 1 self.cpu.registers.pc = 0 result_table = [False] * 512 - result_table[pygame.K_4] = True + result_table[pygame.K_1] = True with mock.patch("pygame.key.get_pressed", return_value=result_table) as key_mock: self.cpu.keyboard_routines() self.assertTrue(key_mock.asssert_called) @@ -564,7 +564,7 @@ def test_operation_A1_pc_does_not_skip_if_key_pressed(self): self.cpu.registers.v[0] = 1 self.cpu.registers.pc = 0 result_table = [False] * 512 - result_table[pygame.K_4] = True + result_table[pygame.K_1] = True with mock.patch("pygame.key.get_pressed", return_value=result_table) as key_mock: self.cpu.keyboard_routines() self.assertTrue(key_mock.asssert_called) @@ -769,7 +769,7 @@ def test_wait_for_keypress(self): self.cpu.operand = 0x0 with mock.patch("pygame.event.wait", return_value=event_mock): result_table = [False] * 512 - result_table[pygame.K_4] = True + result_table[pygame.K_1] = True with mock.patch("pygame.key.get_pressed", return_value=result_table): self.cpu.wait_for_keypress() self.assertEqual(0x1, self.cpu.registers.v[0])