mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-04-10 23:41:09 +00:00
Split Chip class into Device and Chip.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
68030610d8
commit
71daf6aa38
27
inc/Chip.h
27
inc/Chip.h
@ -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
inc/Device.h
Normal file
31
inc/Device.h
Normal 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;
|
||||
};
|
||||
}
|
@ -1,10 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
#include "Chip.h"
|
||||
|
||||
void EightBit::Chip::powerOn() {
|
||||
raise(POWER());
|
||||
}
|
||||
EightBit::Chip::Chip() {}
|
||||
|
||||
void EightBit::Chip::match(PinLevel& line, int value) {
|
||||
value ? raise(line) : lower(line);
|
||||
}
|
||||
EightBit::Chip::~Chip() {}
|
||||
|
10
src/Device.cpp
Normal file
10
src/Device.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "stdafx.h"
|
||||
#include "Device.h"
|
||||
|
||||
void EightBit::Device::powerOn() {
|
||||
raise(POWER());
|
||||
}
|
||||
|
||||
void EightBit::Device::match(PinLevel& line, int value) {
|
||||
value ? raise(line) : lower(line);
|
||||
}
|
@ -145,6 +145,7 @@
|
||||
<ClInclude Include="..\inc\BigEndianProcessor.h" />
|
||||
<ClInclude Include="..\inc\Bus.h" />
|
||||
<ClInclude Include="..\inc\Chip.h" />
|
||||
<ClInclude Include="..\inc\Device.h" />
|
||||
<ClInclude Include="..\inc\EightBitCompilerDefinitions.h" />
|
||||
<ClInclude Include="..\inc\EventArgs.h" />
|
||||
<ClInclude Include="..\inc\InputOutput.h" />
|
||||
@ -166,6 +167,7 @@
|
||||
<ClCompile Include="BigEndianProcessor.cpp" />
|
||||
<ClCompile Include="Bus.cpp" />
|
||||
<ClCompile Include="Chip.cpp" />
|
||||
<ClCompile Include="Device.cpp" />
|
||||
<ClCompile Include="EventArgs.cpp" />
|
||||
<ClCompile Include="InputOutput.cpp" />
|
||||
<ClCompile Include="IntelProcessor.cpp" />
|
||||
|
@ -65,6 +65,9 @@
|
||||
<ClInclude Include="..\inc\Memory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\inc\Device.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\inc\Mapper.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -109,5 +112,8 @@
|
||||
<ClCompile Include="Memory.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Device.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user