Lots of various changes suggested by the code analysis tools.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon
2018-11-27 22:36:54 +00:00
parent 555423d10a
commit a673a64c3f
14 changed files with 87 additions and 83 deletions
+11 -11
View File
@@ -54,14 +54,14 @@ namespace EightBit {
auto& NMI() { return m_nmiLine; } // In
auto& M1() { return m_m1Line; } // Out
virtual int execute(uint8_t opcode) final;
virtual int step() final;
virtual void powerOn() final;
int execute(uint8_t opcode) final;
int step() final;
void powerOn() final;
virtual register16_t& AF() final;
virtual register16_t& BC() final;
virtual register16_t& DE() final;
virtual register16_t& HL() final;
register16_t& AF() final;
register16_t& BC() final;
register16_t& DE() final;
register16_t& HL() final;
auto& IX() { return m_ix; }
auto& IXH() { return IX().high; }
@@ -86,8 +86,8 @@ namespace EightBit {
}
protected:
virtual void handleRESET() final;
virtual void handleINT() final;
void handleRESET() final;
void handleINT() final;
private:
PinLevel m_nmiLine = Low;
@@ -304,7 +304,7 @@ namespace EightBit {
}
static void adjustOverflowAdd(uint8_t& f, const int beforeNegative, const int valueNegative, const int afterNegative) {
auto overflow = (beforeNegative == valueNegative) && (beforeNegative != afterNegative);
const auto overflow = (beforeNegative == valueNegative) && (beforeNegative != afterNegative);
setFlag(f, VF, overflow);
}
@@ -313,7 +313,7 @@ namespace EightBit {
}
static void adjustOverflowSub(uint8_t& f, const int beforeNegative, const int valueNegative, const int afterNegative) {
auto overflow = (beforeNegative != valueNegative) && (beforeNegative != afterNegative);
const auto overflow = (beforeNegative != valueNegative) && (beforeNegative != afterNegative);
setFlag(f, VF, overflow);
}
+11 -10
View File
@@ -7,22 +7,23 @@
namespace EightBit {
class BigEndianProcessor : public Processor {
public:
virtual register16_t peekWord(register16_t address) final;
virtual void pokeWord(register16_t address, register16_t value) final;
~BigEndianProcessor() {};
register16_t peekWord(register16_t address) final;
void pokeWord(register16_t address, register16_t value) final;
protected:
BigEndianProcessor(Bus& memory);
virtual ~BigEndianProcessor() = default;
virtual register16_t getWord() override;
virtual void setWord(register16_t value) override;
register16_t getWord() override;
void setWord(register16_t value) override;
virtual register16_t getWordPaged(uint8_t page, uint8_t offset) override;
virtual void setWordPaged(uint8_t page, uint8_t offset, register16_t value) override;
register16_t getWordPaged(uint8_t page, uint8_t offset) override;
void setWordPaged(uint8_t page, uint8_t offset, register16_t value) override;
virtual register16_t fetchWord() final;
register16_t fetchWord() final;
virtual void pushWord(register16_t value) final;
virtual register16_t popWord() final;
void pushWord(register16_t value) final;
register16_t popWord() final;
};
}
+10 -9
View File
@@ -59,21 +59,23 @@ namespace EightBit {
static void clearFlag(uint8_t& f, const int flag, const uint32_t condition) { clearFlag(f, flag, !!condition); }
static void clearFlag(uint8_t& f, const int flag, const bool condition) { setFlag(f, flag, !condition); }
static auto raised(const PinLevel line) { return line == High; }
static constexpr auto raised(const PinLevel line) { return line == High; }
static void raise(PinLevel& line) { line = High; }
static auto lowered(const PinLevel line) { return line == Low; }
static constexpr auto lowered(const PinLevel line) { return line == Low; }
static void lower(PinLevel& line) { line = Low; }
static void match(PinLevel& line, int value);
static auto highNibble(const int value) { return value >> 4; }
static auto lowNibble(const int value) { return value & Mask4; }
static constexpr auto highNibble(const int value) { return value >> 4; }
static constexpr auto lowNibble(const int value) { return value & Mask4; }
static auto higherNibble(const int value) { return value & 0xf0; }
static auto lowerNibble(const int value) { return lowNibble(value); }
static constexpr auto higherNibble(const int value) { return value & 0xf0; }
static constexpr auto lowerNibble(const int value) { return lowNibble(value); }
static auto promoteNibble(const int value) { return value << 4; }
static auto demoteNibble(const int value) { return highNibble(value); }
static constexpr auto promoteNibble(const int value) { return value << 4; }
static constexpr auto demoteNibble(const int value) { return highNibble(value); }
virtual ~Chip() {};
auto& POWER() { return m_powerLine; }
@@ -83,7 +85,6 @@ namespace EightBit {
protected:
Chip() = default;
virtual ~Chip() = default;
private:
PinLevel m_powerLine = Low;
+3 -3
View File
@@ -12,7 +12,7 @@ namespace EightBit {
int countBits(uint8_t value);
bool oddParity(uint8_t value);
int findFirstSet(int value);
void assume(int expression);
constexpr void assume(int expression);
}
inline int EightBit::countBits(const uint8_t value) {
@@ -52,7 +52,7 @@ inline int EightBit::findFirstSet(const int value) {
#endif
}
inline void EightBit::assume(const int expression) {
inline constexpr void EightBit::assume(const int expression) {
#ifdef _MSC_VER
__assume(expression);
#elif defined(__GNUG__)
@@ -72,7 +72,7 @@ inline void EightBit::assume(const int expression) {
# define PARITY(x) EightBit::oddParity(x)
# define UNREACHABLE { ASSUME(0); throw new std::exception("unreachable"); }
# define UNREACHABLE { ASSUME(0); throw std::exception("unreachable"); }
#elif defined(__GNUG__)
+2 -2
View File
@@ -14,9 +14,9 @@ namespace EightBit {
void write(const uint8_t port, const uint8_t value) { return writeOutputPort(port, value); }
uint8_t readInputPort(uint8_t port);
void writeInputPort(const uint8_t port, const uint8_t value) { m_input[port] = value; }
void writeInputPort(const uint8_t port, const uint8_t value) noexcept { m_input[port] = value; }
auto readOutputPort(const uint8_t port) { return m_output[port]; }
auto readOutputPort(const uint8_t port) noexcept { return m_output[port]; }
void writeOutputPort(uint8_t port, uint8_t value);
Signal<uint8_t> ReadingPort;
+11 -11
View File
@@ -10,8 +10,7 @@
#include "EightBitCompilerDefinitions.h"
namespace EightBit {
class IntelProcessor : public LittleEndianProcessor
{
class IntelProcessor : public LittleEndianProcessor {
public:
struct opcode_decoded_t {
@@ -21,7 +20,7 @@ namespace EightBit {
int p = 0;
int q = 0;
opcode_decoded_t() noexcept {}
opcode_decoded_t() {}
opcode_decoded_t(const uint8_t opcode) {
x = (opcode & 0b11000000) >> 6; // 0 - 3
@@ -32,6 +31,8 @@ namespace EightBit {
}
};
~IntelProcessor() = default;
const auto& getDecodedOpcode(const size_t i) const {
return m_decodedOpcodes[i];
}
@@ -56,11 +57,10 @@ namespace EightBit {
auto& H() { return HL().high; }
auto& L() { return HL().low; }
virtual void powerOn() override;
void powerOn() override;
protected:
IntelProcessor(Bus& bus);
virtual ~IntelProcessor() = default;
template<class T> static void adjustSign(uint8_t& f, const uint8_t value) {
setFlag(f, T::SF, value & T::SF);
@@ -101,7 +101,7 @@ namespace EightBit {
//
static auto buildHalfCarryIndex(const uint8_t before, const uint8_t value, const int calculation) {
static constexpr auto buildHalfCarryIndex(const uint8_t before, const uint8_t value, const int calculation) {
return ((before & 0x88) >> 1) | ((value & 0x88) >> 2) | ((calculation & 0x88) >> 3);
}
@@ -117,13 +117,13 @@ namespace EightBit {
return m_halfCarryTableSub[index & Mask3];
}
virtual void push(uint8_t value) final;
virtual uint8_t pop() final;
void push(uint8_t value) final;
uint8_t pop() final;
//
virtual register16_t getWord() final;
virtual void setWord(register16_t value) final;
register16_t getWord() final;
void setWord(register16_t value) final;
//
@@ -162,7 +162,7 @@ namespace EightBit {
return !!condition;
}
virtual void ret() final;
void ret() final;
private:
std::array<opcode_decoded_t, 0x100> m_decodedOpcodes;
+11 -10
View File
@@ -7,22 +7,23 @@
namespace EightBit {
class LittleEndianProcessor : public Processor {
public:
virtual register16_t peekWord(register16_t address) final;
virtual void pokeWord(register16_t address, register16_t value) final;
~LittleEndianProcessor() = default;
register16_t peekWord(register16_t address) final;
void pokeWord(register16_t address, register16_t value) final;
protected:
LittleEndianProcessor(Bus& memory);
virtual ~LittleEndianProcessor() = default;
virtual register16_t getWord() override;
virtual void setWord(register16_t value) override;
register16_t getWord() override;
void setWord(register16_t value) override;
virtual register16_t getWordPaged(uint8_t page, uint8_t offset) override;
virtual void setWordPaged(uint8_t page, uint8_t offset, register16_t value) override;
register16_t getWordPaged(uint8_t page, uint8_t offset) override;
void setWordPaged(uint8_t page, uint8_t offset, register16_t value) override;
virtual register16_t fetchWord() final;
register16_t fetchWord() final;
virtual void pushWord(register16_t value) final;
virtual register16_t popWord() final;
void pushWord(register16_t value) final;
register16_t popWord() final;
};
}
+3 -2
View File
@@ -15,6 +15,8 @@ namespace EightBit {
// x: sign extend this b-bit number to r
static int8_t signExtend(int b, uint8_t x);
~Processor() {};
auto& PC() { return m_pc; }
auto& RESET() { return m_resetLine; }
@@ -22,7 +24,7 @@ namespace EightBit {
auto& INT() { return m_intLine; }
auto& IRQ() { return INT(); } // Synonym
virtual void powerOn() override;
void powerOn() override;
void reset() { lower(RESET()); }
int run(int limit);
@@ -36,7 +38,6 @@ namespace EightBit {
protected:
Processor(Bus& memory);
virtual ~Processor() = default;
auto& BUS() { return m_bus; }
+2 -2
View File
@@ -11,7 +11,7 @@ namespace EightBit {
public:
Ram(size_t size = 0) noexcept;
virtual uint8_t& reference(uint16_t address) final;
virtual void poke(uint16_t address, uint8_t value) final;
uint8_t& reference(uint16_t address) final;
void poke(uint16_t address, uint8_t value) final;
};
}
+7 -7
View File
@@ -19,20 +19,20 @@ namespace EightBit {
const auto& BYTES() const { return m_bytes; }
auto& BYTES() { return m_bytes; }
virtual void poke(uint16_t address, uint8_t value) override;
void poke(uint16_t address, uint8_t value) override;
public:
static int load(std::ifstream& file, std::vector<uint8_t>& output, int writeOffset = 0, int readOffset = 0, int limit = -1, int maximumSize = -1);
static int load(const std::string& path, std::vector<uint8_t>& output, int writeOffset = 0, int readOffset = 0, int limit = -1, int maximumSize = -1);
Rom(size_t size = 0) noexcept;
Rom(size_t size = 0);
virtual size_t size() const final;
size_t size() const final;
virtual int load(std::ifstream& file, int writeOffset = 0, int readOffset = 0, int limit = -1) final;
virtual int load(const std::string& path, int writeOffset = 0, int readOffset = 0, int limit = -1) final;
virtual int load(const std::vector<uint8_t>& bytes, int writeOffset = 0, int readOffset = 0, int limit = -1) final;
int load(std::ifstream& file, int writeOffset = 0, int readOffset = 0, int limit = -1) final;
int load(const std::string& path, int writeOffset = 0, int readOffset = 0, int limit = -1) final;
int load(const std::vector<uint8_t>& bytes, int writeOffset = 0, int readOffset = 0, int limit = -1) final;
virtual uint8_t peek(uint16_t address) const final;
uint8_t peek(uint16_t address) const final;
};
}
+7 -7
View File
@@ -14,17 +14,17 @@ namespace EightBit {
class UnusedMemory final : public Memory {
public:
UnusedMemory(size_t size, uint8_t value);
virtual ~UnusedMemory() = default;
~UnusedMemory() {};
virtual size_t size() const final;
virtual uint8_t peek(uint16_t address) const final;
size_t size() const final;
uint8_t peek(uint16_t address) const final;
virtual int load(std::ifstream& file, int writeOffset = 0, int readOffset = 0, int limit = -1) final;
virtual int load(const std::string& path, int writeOffset = 0, int readOffset = 0, int limit = -1) final;
virtual int load(const std::vector<uint8_t>& bytes, int writeOffset = 0, int readOffset = 0, int limit = -1) final;
int load(std::ifstream& file, int writeOffset = 0, int readOffset = 0, int limit = -1) final;
int load(const std::string& path, int writeOffset = 0, int readOffset = 0, int limit = -1) final;
int load(const std::vector<uint8_t>& bytes, int writeOffset = 0, int readOffset = 0, int limit = -1) final;
protected:
virtual void poke(uint16_t address, uint8_t value) final;
void poke(uint16_t address, uint8_t value) final;
private:
size_t m_size;
+1 -1
View File
@@ -4,5 +4,5 @@
#include <stdexcept>
uint8_t& EightBit::Memory::reference(uint16_t) {
throw new std::logic_error("Reference operation not allowed.");
throw std::logic_error("Reference operation not allowed.");
}
+4 -4
View File
@@ -41,7 +41,7 @@ void EightBit::Rom::poke(const uint16_t address, const uint8_t value) {
BYTES()[address] = value;
}
EightBit::Rom::Rom(const size_t size) noexcept
EightBit::Rom::Rom(const size_t size)
: m_bytes(size) {}
size_t EightBit::Rom::size() const {
@@ -49,18 +49,18 @@ size_t EightBit::Rom::size() const {
}
int EightBit::Rom::load(std::ifstream& file, const int writeOffset, const int readOffset, const int limit) {
const auto maximumSize = (int)size() - writeOffset;
const auto maximumSize = size() - writeOffset;
return load(file, m_bytes, writeOffset, readOffset, limit, maximumSize);
}
int EightBit::Rom::load(const std::string& path, const int writeOffset, const int readOffset, const int limit) {
const auto maximumSize = (int)size() - writeOffset;
const auto maximumSize = size() - writeOffset;
return load(path, m_bytes, writeOffset, readOffset, limit, maximumSize);
}
int EightBit::Rom::load(const std::vector<uint8_t>& bytes, const int writeOffset, const int readOffset, int limit) {
if (limit < 0)
limit = (int)bytes.size() - readOffset;
limit = bytes.size() - readOffset;
std::copy(bytes.cbegin() + readOffset, bytes.cbegin() + limit, m_bytes.begin() + writeOffset);
return limit;
}
+4 -4
View File
@@ -13,17 +13,17 @@ uint8_t EightBit::UnusedMemory::peek(uint16_t) const {
}
int EightBit::UnusedMemory::load(std::ifstream&, int, int, int) {
throw new std::logic_error("load operation not allowed.");
throw std::logic_error("load operation not allowed.");
}
int EightBit::UnusedMemory::load(const std::string&, int, int, int) {
throw new std::logic_error("load operation not allowed.");
throw std::logic_error("load operation not allowed.");
}
int EightBit::UnusedMemory::load(const std::vector<uint8_t>&, int, int, int) {
throw new std::logic_error("load operation not allowed.");
throw std::logic_error("load operation not allowed.");
}
void EightBit::UnusedMemory::poke(uint16_t, uint8_t) {
throw new std::logic_error("Poke operation not allowed.");
throw std::logic_error("Poke operation not allowed.");
}