Skip to content

Commit

Permalink
Merge pull request #33 from craigthomas/default-64k-mem
Browse files Browse the repository at this point in the history
Default the interpreter to set memory size to 64K.
  • Loading branch information
craigthomas authored Jun 23, 2024
2 parents 4cfcee8 + 52925f3 commit dab0e5e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
3. [Jump Quirks](#jump-quirks)
4. [Clip Quirks](#clip-quirks)
5. [Logic Quirks](#logic-quirks)
5. [Memory Size](#memory-size)
5. [Customization](#customization)
1. [Keys](#keys)
2. [Debug Keys](#debug-keys)
Expand Down Expand Up @@ -294,6 +295,15 @@ such as AND, OR, and XOR. By default, F is left undefined following these operat
With the flag turned on, F will always be cleared.
### Memory Size
The original specification of the Chip8 language defined a 4K memory size for the
interpreter. The addition of the XO Chip extensions require a 64K memory size
for the interpreter. By default, the interpreter will start with a 64K memory size,
but this behavior can be controlled with the `--mem_size` flag. Valid options are
`64K` or `4K` for historical purposes.
## Customization
The file `chip8/config.py` contains several variables that can be changed to
Expand Down
4 changes: 1 addition & 3 deletions chip8/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"""
# I M P O R T S ###############################################################

import pygame

from pygame import key
from random import randint

Expand Down Expand Up @@ -69,7 +67,7 @@ def __init__(
jump_quirks=False,
clip_quirks=False,
logic_quirks=False,
mem_size="4K"
mem_size="64K"
):
"""
Initialize the Chip8 CPU. The only required parameter is a screen
Expand Down
4 changes: 3 additions & 1 deletion test/test_chip8cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import mock
import pygame
import unittest
import collections

from mock import patch, call

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

def test_memory_size_default_64k(self):
self.assertEqual(65536, len(self.cpu.memory))

def test_return_from_subroutine(self):
for address in range(0x200, 0xFFFF, 0x10):
self.cpu.memory[self.cpu.sp] = address & 0x00FF
Expand Down
4 changes: 2 additions & 2 deletions yac8e.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def parse_arguments():
action="store_true", dest="logic_quirks"
)
parser.add_argument(
"--mem_size", help="Maximum memory size (4K default)",
dest="mem_size", choices=["4K", "64K"], default="4K"
"--mem_size", help="Maximum memory size (64K default)",
dest="mem_size", choices=["4K", "64K"], default="64K"
)
parser.add_argument(
"--trace", help="print registers and instructions to STDOUT",
Expand Down

0 comments on commit dab0e5e

Please sign in to comment.