Split Chip class into Device and Chip.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon
2019-01-10 20:44:16 +00:00
parent 68030610d8
commit 71daf6aa38
6 changed files with 55 additions and 29 deletions
+4 -23
View File
@@ -1,9 +1,10 @@
#pragma once
#include <cstdint>
#include "Device.h"
namespace EightBit {
class Chip {
class Chip : public Device {
public:
enum Bits {
Bit0 = 1,
@@ -44,10 +45,6 @@ namespace EightBit {
Mask16 = Bit16 - 1
};
enum class PinLevel {
Low, High
};
static void clearFlag(uint8_t& f, const int flag) noexcept { f &= ~flag; }
static void setFlag(uint8_t& f, const int flag) noexcept { f |= flag; }
@@ -59,13 +56,6 @@ namespace EightBit {
static void clearFlag(uint8_t& f, const int flag, const uint32_t condition) noexcept { clearFlag(f, flag, !!condition); }
static void clearFlag(uint8_t& f, const int flag, const bool condition) noexcept { setFlag(f, flag, !condition); }
static constexpr auto raised(const PinLevel line) { return line == PinLevel::High; }
static void raise(PinLevel& line) noexcept { line = PinLevel::High; }
static constexpr auto lowered(const PinLevel line) { return line == PinLevel::Low; }
static void lower(PinLevel& line) noexcept { line = PinLevel::Low; }
static void match(PinLevel& line, int value);
static constexpr auto highNibble(const int value) { return value >> 4; }
static constexpr auto lowNibble(const int value) { return value & Mask4; }
@@ -75,18 +65,9 @@ namespace EightBit {
static constexpr auto promoteNibble(const int value) { return value << 4; }
static constexpr auto demoteNibble(const int value) { return highNibble(value); }
virtual ~Chip() {};
[[nodiscard]] auto& POWER() noexcept { return m_powerLine; }
[[nodiscard]] auto powered() noexcept { return raised(POWER()); }
virtual void powerOn();
void powerOff() noexcept { lower(POWER()); }
virtual ~Chip();
protected:
Chip() = default;
private:
PinLevel m_powerLine = PinLevel::Low;
Chip();
};
}
+31
View File
@@ -0,0 +1,31 @@
#pragma once
namespace EightBit {
class Device {
public:
enum class PinLevel {
Low, High
};
static constexpr auto raised(const PinLevel line) { return line == PinLevel::High; }
static void raise(PinLevel& line) noexcept { line = PinLevel::High; }
static constexpr auto lowered(const PinLevel line) { return line == PinLevel::Low; }
static void lower(PinLevel& line) noexcept { line = PinLevel::Low; }
static void match(PinLevel& line, int value);
virtual ~Device() {};
[[nodiscard]] auto& POWER() noexcept { return m_powerLine; }
[[nodiscard]] auto powered() noexcept { return raised(POWER()); }
virtual void powerOn();
virtual void powerOff() { lower(POWER()); }
protected:
Device() {};
private:
PinLevel m_powerLine = PinLevel::Low;
};
}