Skip to content

Commit

Permalink
Simplify the chip8 interpreter. No functional changes.
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
  • Loading branch information
MoleskiCoder committed Aug 7, 2018
1 parent eb7d707 commit 1ced923
Show file tree
Hide file tree
Showing 16 changed files with 484 additions and 582 deletions.
65 changes: 27 additions & 38 deletions src/libs/libchip8/BitmappedGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,88 +11,77 @@ void BitmappedGraphics::initialise() {
setHighResolution(false);
}

int BitmappedGraphics::draw(const Memory& memory, int address, int drawX, int drawY, int width, int height) {
auto bytesPerRow = width / 8;
int BitmappedGraphics::draw(const Memory& memory, int address, const int drawX, const int drawY, const int width, const int height) {
const auto bytesPerRow = width / 8;
size_t hits = 0;
for (int plane = 0; plane < getNumberOfPlanes(); ++plane) {
if (isPlaneSelected(plane)) {
hits += m_planes[plane].draw(memory, address, drawX, drawY, width, height);
address += height * bytesPerRow;
}
}
setDirty(true);
setDirty();
if (!m_countRowHits)
hits = hits > 0 ? 1 : 0;
return (int)hits;
}

void BitmappedGraphics::scrollDown(int count) {
for (int plane = 0; plane < getNumberOfPlanes(); ++plane) {
void BitmappedGraphics::scrollDown(const int count) {
for (int plane = 0; plane < getNumberOfPlanes(); ++plane)
maybeScrollDown(plane, count);
}
setDirty(true);
setDirty();
}

void BitmappedGraphics::scrollUp(int count) {
for (int plane = 0; plane < getNumberOfPlanes(); ++plane) {
for (int plane = 0; plane < getNumberOfPlanes(); ++plane)
maybeScrollUp(plane, count);
}
setDirty(true);
setDirty();
}

void BitmappedGraphics::scrollLeft() {
for (int plane = 0; plane < getNumberOfPlanes(); ++plane) {
for (int plane = 0; plane < getNumberOfPlanes(); ++plane)
maybeScrollLeft(plane);
}
setDirty(true);
setDirty();
}

void BitmappedGraphics::scrollRight() {
for (int plane = 0; plane < getNumberOfPlanes(); ++plane) {
for (int plane = 0; plane < getNumberOfPlanes(); ++plane)
maybeScrollRight(plane);
}
setDirty(true);
setDirty();
}

void BitmappedGraphics::clear() {
for (int plane = 0; plane < getNumberOfPlanes(); ++plane) {
for (int plane = 0; plane < getNumberOfPlanes(); ++plane)
maybeClear(plane);
}
setDirty(true);
setDirty();
}

bool BitmappedGraphics::isPlaneSelected(int plane) const {
auto mask = 1 << plane;
auto selected = (getPlaneMask() & mask) != 0;
return selected;
bool BitmappedGraphics::isPlaneSelected(const int plane) const {
const auto mask = 1 << plane;
return (getPlaneMask() & mask) != 0;
}

void BitmappedGraphics::maybeScrollDown(int plane, int count) {
if (isPlaneSelected(plane)) {
void BitmappedGraphics::maybeScrollDown(const int plane, const int count) {
if (isPlaneSelected(plane))
m_planes[plane].scrollDown(count);
}
}

void BitmappedGraphics::maybeScrollUp(int plane, int count) {
if (isPlaneSelected(plane)) {
void BitmappedGraphics::maybeScrollUp(const int plane, const int count) {
if (isPlaneSelected(plane))
m_planes[plane].scrollUp(count);
}
}

void BitmappedGraphics::maybeScrollLeft(int plane) {
if (isPlaneSelected(plane)) {
void BitmappedGraphics::maybeScrollLeft(const int plane) {
if (isPlaneSelected(plane))
m_planes[plane].scrollLeft();
}
}

void BitmappedGraphics::maybeScrollRight(int plane) {
if (isPlaneSelected(plane)) {
void BitmappedGraphics::maybeScrollRight(const int plane) {
if (isPlaneSelected(plane))
m_planes[plane].scrollRight();
}
}

void BitmappedGraphics::maybeClear(int plane) {
if (isPlaneSelected(plane)) {
void BitmappedGraphics::maybeClear(const int plane) {
if (isPlaneSelected(plane))
m_planes[plane].clear();
}
}
15 changes: 7 additions & 8 deletions src/libs/libchip8/BitmappedGraphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,22 @@ class BitmappedGraphics final {
return 1 << getNumberOfPlanes();
}

const std::vector<GraphicsPlane>& getPlanes() const {
const std::vector<GraphicsPlane>& planes() const {
return m_planes;
}

std::vector<GraphicsPlane>& getPlanesMutable() {
std::vector<GraphicsPlane>& planes() {
return m_planes;
}

bool getHighResolution() const {
return m_highResolution;
}

void setHighResolution(bool value) {
void setHighResolution(const bool value) {
m_highResolution = value;
for (int plane = 0; plane < getNumberOfPlanes(); ++plane) {
m_planes[plane].setHighResolution(value);
}
for (auto& plane : m_planes)
plane.setHighResolution(value);
}

bool getLowResolution() const {
Expand All @@ -62,15 +61,15 @@ class BitmappedGraphics final {
return m_planeMask;
}

void setPlaneMask(int value) {
void setPlaneMask(const int value) {
m_planeMask = value;
}

bool getDirty() const {
return m_dirty;
}

void setDirty(bool value) {
void setDirty(const bool value = true) {
m_dirty = value;
}

Expand Down
Loading

0 comments on commit 1ced923

Please sign in to comment.