Skip to content

Commit abebcde

Browse files
authored
Merge pull request #10 from craigthomas/code-coverage-increase
Update dependency badge, remove unit test descriptions, add unit tests.
2 parents 7668a06 + 35ccdc6 commit abebcde

File tree

5 files changed

+223
-235
lines changed

5 files changed

+223
-235
lines changed

README.md

Lines changed: 115 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,22 @@
33
[![Build Status](https://travis-ci.org/craigthomas/Chip8Python.svg?branch=master)](https://travis-ci.org/craigthomas/Chip8Python)
44
[![codecov](https://codecov.io/gh/craigthomas/Chip8Python/branch/master/graph/badge.svg)](https://codecov.io/gh/craigthomas/Chip8Python)
55
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/f100b6deb9bf4729a2c55ef12fb695c9)](https://www.codacy.com/app/craig-thomas/Chip8Python?utm_source=github.com&utm_medium=referral&utm_content=craigthomas/Chip8Python&utm_campaign=Badge_Grade)
6-
[![Dependency Status](https://dependencyci.com/github/craigthomas/Chip8Python/badge)](https://dependencyci.com/github/craigthomas/Chip8Python)
6+
[![Dependency Status](https://dependencyci.com/github/craigthomas/Chip8Python/badge?style=flat)](https://dependencyci.com/github/craigthomas/Chip8Python)
7+
8+
9+
## Table of Contents
10+
11+
1. [What is it?](#what-is-it)
12+
2. [License](#license)
13+
3. [Installing](#installing)
14+
1. [Ubuntu Installation](#ubuntu-installation)
15+
2. [Windows Installation](#windows)
16+
4. [Running](#running)
17+
1. [Running a ROM](#running-a-rom)
18+
2. [Screen Scale](#screen-scale)
19+
3. [Execution Delay](#execution-delay)
20+
5. [Customization](#customization)
21+
6. [Further Documentation](#further-documentation)
722

823
## What is it?
924

@@ -38,52 +53,124 @@ I strongly recommend creating a virtual environment using the
3853
With these tools, you can easily create a virtual sandbox to install pygame
3954
and run the emulator in, without touching your master Python environment.
4055

56+
4157
### Ubuntu Installation
4258

4359
The installation under Ubuntu requires several different steps:
4460

45-
1) Install SDL libraries. The SDL (Simple DirectMedia Layer) libraries are
46-
used by PyGame to draw images on the screen. Several other dependencies are
47-
needed by SDL in order to install PyGame. To install the required SDL
48-
libraries (plus dependencies) from the command-line:
61+
1. Install SDL libraries. The SDL (Simple DirectMedia Layer) libraries are used by PyGame to draw
62+
images on the screen. Several other dependencies are needed by SDL in order to install PyGame.
63+
To install the required SDL libraries (plus dependencies) from the command-line:
64+
65+
```
66+
sudo apt-get install libfreetype6-dev libsdl-dev libsdl-image1.2-dev \
67+
libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl-sound1.2-dev \
68+
libportmidi-dev python-dev
69+
```
70+
71+
2. Install PIP. The `pip` package manager is used for managing Python packages. To install `pip`
72+
from the command-line:
73+
74+
```
75+
sudo apt-get install python-pip
76+
```
77+
78+
3. (*Optional*) Install virtual environment support for Python:
79+
80+
1. Install virtual environment support:
81+
82+
```
83+
pip install virtualenv
84+
pip install virtualenvwrapper
85+
```
86+
87+
2. First you must update your `.bashrc` file in the your home directory and add a few lines
88+
to the bottom of that file:
89+
90+
```
91+
cat >> ~/.bashrc << EOF
92+
export WORKON_HOME=$HOME/.virtualenvs
93+
source /usr/local/bin/virtualenvwrapper.sh
94+
EOF
95+
```
96+
97+
3. Next you must source the `.bashrc` file:
98+
99+
```
100+
source ~/.bashrc
101+
```
102+
103+
4. Finally you can create the environment:
49104
50-
sudo apt-get install libfreetype6-dev libsdl-dev libsdl-image1.2-dev \
51-
libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl-sound1.2-dev \
52-
libportmidi-dev python-dev
53-
54-
2) Install Mercurial. The `hg` command-line tool is required when using
55-
`pip` (see next step) to install the requirements for the project. To
56-
install Mercurial from the command-line:
105+
```
106+
mkvirtualenv chip8
107+
```
57108
58-
sudo apt-get install mercurial
59-
60-
3) Install PIP. The `pip` package manager is used for managing Python
61-
packages. To install `pip` from the command-line:
109+
5. Clone (or download) the Chip 8 emulator project:
62110
63-
sudo apt-get install wget
64-
wget https://bootstrap.pypa.io/get-pip.py
65-
sudo python ./get-pip.py
66-
67-
4) Clone (or download) the Chip 8 emulator project:
111+
```
112+
sudo apt-get install git
113+
git clone https://github.com/craigthomas/Chip8Python.git
114+
```
68115
69-
sudo apt-get install git
70-
git clone [email protected]:craigthomas/Chip8Python.git
71-
72-
5) Install the requirements from the project:
116+
6. Install the requirements from the project:
73117
74-
pip install -r requirements.txt
118+
```
119+
pip install -r requirements.txt
120+
```
121+
122+
123+
### Windows Installation
124+
125+
1. Download and install [Python 2.7.15 for Windows](https://www.python.org/downloads/release/python-2715/).
126+
Make sure that `pip` and `Add python.exe to Path` options are checked when performing the installation.
127+
128+
2. (*Optional*) Install virtual environment support for Python. Run the following commands from a command prompt:
129+
130+
1. Install the virtual environment wrapper:
131+
132+
```
133+
pip install virtualenv
134+
pip install virtualenvwrapper-win
135+
```
136+
137+
2. Create a new environment for the Chip 8 emulator:
138+
139+
```
140+
mkvirtualenv chip8
141+
```
142+
143+
4. Install [Git for Windows](https://git-scm.com/download/win).
144+
145+
5. Clone (or download) the source files from GitHub. Run the following commands in a command prompt window:
146+
147+
```
148+
git clone https://github.com/craigthomas/Chip8Python.git
149+
```
150+
151+
6. Install the requirements for the project. Run the following commands in a command prompt window
152+
in the directory where you cloned or downloaded the source files:
153+
154+
```
155+
pip install -r requirements.txt
156+
```
75157
76158
77159
## Running
78160
79161
### Running a ROM
80162
81163
The command-line interface requires a single argument, which is the full
82-
path to a Chip 8 ROM:
164+
path to a Chip 8 ROM. Run the following command in the directory where you
165+
cloned or downloaded the source files:
83166
84167
python chip8/yac8e.py /path/to/rom/filename
85168
86-
This will start the emulator with the specified ROM.
169+
This will start the emulator with the specified ROM. Note that if you created
170+
a virtual environment as detailed above, you will need to `workon` that
171+
environment before starting the emulator:
172+
173+
workon chip8
87174
88175
### Screen Scale
89176

chip8/cpu.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def __init__(self, screen):
140140
self.screen = screen
141141
self.memory = bytearray(MAX_MEMORY)
142142
self.reset()
143+
self.running = True
143144

144145
def __str__(self):
145146
val = 'PC: {:4X} OP: {:4X}\n'.format(
@@ -257,7 +258,7 @@ def clear_return(self):
257258
self.screen.scroll_left()
258259

259260
if operation == 0x00FD:
260-
pass
261+
self.running = False
261262

262263
if operation == 0x00FE:
263264
self.disable_extended_mode()
@@ -667,12 +668,12 @@ def draw_normal(self, x_pos, y_pos, num_bytes):
667668
color_byte = bin(self.memory[self.registers['index'] + y_index])
668669
color_byte = color_byte[2:].zfill(8)
669670
y_coord = y_pos + y_index
670-
y_coord = y_coord % self.screen.height
671+
y_coord = y_coord % self.screen.get_height()
671672

672673
for x_index in xrange(8):
673674

674675
x_coord = x_pos + x_index
675-
x_coord = x_coord % self.screen.width
676+
x_coord = x_coord % self.screen.get_width()
676677

677678
color = int(color_byte[x_index])
678679
current_color = self.screen.get_pixel(x_coord, y_coord)

chip8/yac8e.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,22 @@ def main_loop(args):
5555
cpu.load_rom(FONT_FILE, 0)
5656
cpu.load_rom(args.rom)
5757
pygame.time.set_timer(TIMER, DELAY_INTERVAL)
58-
running = True
5958

60-
while running:
59+
while cpu.running:
6160
pygame.time.wait(args.op_delay)
62-
operand = cpu.execute_instruction()
61+
cpu.execute_instruction()
6362

6463
# Check for events
6564
for event in pygame.event.get():
6665
if event.type == TIMER:
6766
cpu.decrement_timers()
6867
if event.type == pygame.QUIT:
69-
running = False
68+
cpu.running = False
7069
if event.type == pygame.KEYDOWN:
7170
keys_pressed = pygame.key.get_pressed()
7271
if keys_pressed[pygame.K_q]:
73-
running = False
72+
cpu.running = False
7473

75-
# Check to see if CPU is in exit state
76-
if operand == 0x00FD:
77-
running = False
7874

7975
# M A I N #####################################################################
8076

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
hg+http://bitbucket.org/pygame/pygame
1+
pygame
22
coveralls
33
mock

0 commit comments

Comments
 (0)