Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional unit tests for new code #45

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions chip8/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,30 +867,34 @@ def draw_sprite(self):

if num_bytes == 0:
if self.bitplane == 3:
self.draw_extended(x_pos, y_pos, 1)
self.draw_extended(x_pos, y_pos, 2)
self.draw_extended(x_pos, y_pos, 1, index=self.index)
self.draw_extended(x_pos, y_pos, 2, index=self.index + 32)
else:
self.draw_extended(x_pos, y_pos, self.bitplane)
self.last_op = f"DRAWEX"
else:
if self.bitplane == 3:
self.draw_normal(x_pos, y_pos, num_bytes, 1)
self.draw_normal(x_pos, y_pos, num_bytes, 2)
self.draw_normal(x_pos, y_pos, num_bytes, 1, index=self.index)
self.draw_normal(x_pos, y_pos, num_bytes, 2, index=self.index + num_bytes)
else:
self.draw_normal(x_pos, y_pos, num_bytes, self.bitplane)
self.last_op = f"DRAW V{x_source:01X}, V{y_source:01X}"

def draw_normal(self, x_pos, y_pos, num_bytes, bitplane):
def draw_normal(self, x_pos, y_pos, num_bytes, bitplane, index=None):
"""
Draws a sprite on the screen while in NORMAL mode.

:param x_pos: the X position of the sprite
:param y_pos: the Y position of the sprite
:param num_bytes: the number of bytes to draw
:param bitplane: the bitplane to draw to
:param index: the memory index in memory where byte the pattern is stored
"""
if not index:
index = self.index

for y_index in range(num_bytes):
color_byte = self.memory[self.index + y_index]
color_byte = self.memory[index + y_index]
y_coord = y_pos + y_index
if not self.clip_quirks or (self.clip_quirks and y_coord < self.screen.get_height()):
y_coord = y_coord % self.screen.get_height()
Expand All @@ -906,7 +910,7 @@ def draw_normal(self, x_pos, y_pos, num_bytes, bitplane):
mask = mask >> 1
self.screen.update()

def draw_extended(self, x_pos, y_pos, bitplane):
def draw_extended(self, x_pos, y_pos, bitplane, index=None):
"""
Draws a sprite on the screen while in EXTENDED mode. Sprites in this
mode are assumed to be 16x16 pixels. This means that two bytes will
Expand All @@ -916,10 +920,14 @@ def draw_extended(self, x_pos, y_pos, bitplane):
:param x_pos: the X position of the sprite
:param y_pos: the Y position of the sprite
:param bitplane: the bitplane to draw to
:param index: the memory index in memory where byte the pattern is stored
"""
if not index:
index = self.index

for y_index in range(16):
for x_byte in range(2):
color_byte = self.memory[self.index + (y_index * 2) + x_byte]
color_byte = self.memory[index + (y_index * 2) + x_byte]
y_coord = y_pos + y_index
if y_coord < self.screen.get_height():
y_coord = y_coord % self.screen.get_height()
Expand Down
Loading
Loading