Skip to content

Commit dab0e5e

Browse files
authored
Merge pull request #33 from craigthomas/default-64k-mem
Default the interpreter to set memory size to 64K.
2 parents 4cfcee8 + 52925f3 commit dab0e5e

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
3. [Jump Quirks](#jump-quirks)
2525
4. [Clip Quirks](#clip-quirks)
2626
5. [Logic Quirks](#logic-quirks)
27+
5. [Memory Size](#memory-size)
2728
5. [Customization](#customization)
2829
1. [Keys](#keys)
2930
2. [Debug Keys](#debug-keys)
@@ -294,6 +295,15 @@ such as AND, OR, and XOR. By default, F is left undefined following these operat
294295
With the flag turned on, F will always be cleared.
295296
296297
298+
### Memory Size
299+
300+
The original specification of the Chip8 language defined a 4K memory size for the
301+
interpreter. The addition of the XO Chip extensions require a 64K memory size
302+
for the interpreter. By default, the interpreter will start with a 64K memory size,
303+
but this behavior can be controlled with the `--mem_size` flag. Valid options are
304+
`64K` or `4K` for historical purposes.
305+
306+
297307
## Customization
298308
299309
The file `chip8/config.py` contains several variables that can be changed to

chip8/cpu.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
"""
77
# I M P O R T S ###############################################################
88

9-
import pygame
10-
119
from pygame import key
1210
from random import randint
1311

@@ -69,7 +67,7 @@ def __init__(
6967
jump_quirks=False,
7068
clip_quirks=False,
7169
logic_quirks=False,
72-
mem_size="4K"
70+
mem_size="64K"
7371
):
7472
"""
7573
Initialize the Chip8 CPU. The only required parameter is a screen

test/test_chip8cpu.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import mock
1010
import pygame
1111
import unittest
12-
import collections
1312

1413
from mock import patch, call
1514

@@ -35,6 +34,9 @@ def setUp(self):
3534
self.cpu = Chip8CPU(self.screen)
3635
self.cpu_spy = mock.Mock(wraps=self.cpu)
3736

37+
def test_memory_size_default_64k(self):
38+
self.assertEqual(65536, len(self.cpu.memory))
39+
3840
def test_return_from_subroutine(self):
3941
for address in range(0x200, 0xFFFF, 0x10):
4042
self.cpu.memory[self.cpu.sp] = address & 0x00FF

yac8e.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def parse_arguments():
5757
action="store_true", dest="logic_quirks"
5858
)
5959
parser.add_argument(
60-
"--mem_size", help="Maximum memory size (4K default)",
61-
dest="mem_size", choices=["4K", "64K"], default="4K"
60+
"--mem_size", help="Maximum memory size (64K default)",
61+
dest="mem_size", choices=["4K", "64K"], default="64K"
6262
)
6363
parser.add_argument(
6464
"--trace", help="print registers and instructions to STDOUT",

0 commit comments

Comments
 (0)