mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-08-09 00:25:10 +00:00
Correct more analysis problems. No functional changes.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
@@ -365,8 +365,8 @@ namespace EightBit {
|
|||||||
register16_t m_u;
|
register16_t m_u;
|
||||||
register16_t m_s;
|
register16_t m_s;
|
||||||
|
|
||||||
uint8_t m_dp;
|
uint8_t m_dp = 0;
|
||||||
uint8_t m_cc;
|
uint8_t m_cc = 0;
|
||||||
|
|
||||||
PinLevel m_nmiLine = Low;
|
PinLevel m_nmiLine = Low;
|
||||||
PinLevel m_firqLine = Low;
|
PinLevel m_firqLine = Low;
|
||||||
|
@@ -278,36 +278,36 @@ namespace EightBit {
|
|||||||
bool transmitReadyHigh() const { return m_transmitControl == ReadyHighInterruptDisabled; }
|
bool transmitReadyHigh() const { return m_transmitControl == ReadyHighInterruptDisabled; }
|
||||||
bool transmitReadyLow() const { return !transmitReadyHigh(); }
|
bool transmitReadyLow() const { return !transmitReadyHigh(); }
|
||||||
|
|
||||||
PinLevel m_RXDATA;
|
PinLevel m_RXDATA = Low;
|
||||||
PinLevel m_TXDATA;
|
PinLevel m_TXDATA = Low;
|
||||||
|
|
||||||
PinLevel m_RTS;
|
PinLevel m_RTS = Low;
|
||||||
PinLevel m_CTS;
|
PinLevel m_CTS = Low;
|
||||||
PinLevel m_DCD;
|
PinLevel m_DCD = Low;
|
||||||
PinLevel m_oldDCD; // So we can detect low -> high transition
|
PinLevel m_oldDCD = Low; // So we can detect low -> high transition
|
||||||
|
|
||||||
PinLevel m_RXCLK;
|
PinLevel m_RXCLK = Low;
|
||||||
PinLevel m_TXCLK;
|
PinLevel m_TXCLK = Low;
|
||||||
|
|
||||||
PinLevel m_CS0;
|
PinLevel m_CS0 = Low;;
|
||||||
PinLevel m_CS1;
|
PinLevel m_CS1 = Low;;
|
||||||
PinLevel m_CS2;
|
PinLevel m_CS2 = Low;;
|
||||||
|
|
||||||
PinLevel m_RS;
|
PinLevel m_RS = Low;;
|
||||||
PinLevel m_RW;
|
PinLevel m_RW = Low;;
|
||||||
|
|
||||||
PinLevel m_E;
|
PinLevel m_E = Low;;
|
||||||
PinLevel m_IRQ;
|
PinLevel m_IRQ = Low;;
|
||||||
|
|
||||||
uint8_t m_data;
|
uint8_t m_data = 0;
|
||||||
|
|
||||||
bool m_statusRead = false;
|
bool m_statusRead = false;
|
||||||
|
|
||||||
// Control registers
|
// Control registers
|
||||||
CounterDivideSelect m_counterDivide;
|
CounterDivideSelect m_counterDivide = One;
|
||||||
WordSelect m_wordSelect;
|
WordSelect m_wordSelect = SevenEvenTwo;
|
||||||
TransmitterControl m_transmitControl;
|
TransmitterControl m_transmitControl = ReadyLowInterruptDisabled;
|
||||||
ReceiveControl m_receiveControl;
|
ReceiveControl m_receiveControl = ReceiveInterruptDisable;
|
||||||
|
|
||||||
// Status registers
|
// Status registers
|
||||||
bool m_statusRDRF = false;
|
bool m_statusRDRF = false;
|
||||||
@@ -315,8 +315,8 @@ namespace EightBit {
|
|||||||
bool m_statusOVRN = false;
|
bool m_statusOVRN = false;
|
||||||
|
|
||||||
// Data registers
|
// Data registers
|
||||||
uint8_t m_TDR;
|
uint8_t m_TDR = 0;
|
||||||
uint8_t m_RDR;
|
uint8_t m_RDR = 0;
|
||||||
|
|
||||||
bool m_powered = false;
|
bool m_powered = false;
|
||||||
};
|
};
|
||||||
|
@@ -276,7 +276,7 @@ void EightBit::Z80::add(const uint8_t value, const int carry) {
|
|||||||
adjustOverflowAdd(F(), A(), value, result.low);
|
adjustOverflowAdd(F(), A(), value, result.low);
|
||||||
|
|
||||||
clearFlag(F(), NF);
|
clearFlag(F(), NF);
|
||||||
setFlag(F(), CF, result.word & Bit8);
|
setFlag(F(), CF, result.high & CF);
|
||||||
adjustSZXY<Z80>(F(), A() = result.low);
|
adjustSZXY<Z80>(F(), A() = result.low);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,7 +292,7 @@ void EightBit::Z80::subtract(uint8_t& operand, const uint8_t value, const int ca
|
|||||||
adjustOverflowSub(F(), operand, value, result.low);
|
adjustOverflowSub(F(), operand, value, result.low);
|
||||||
|
|
||||||
setFlag(F(), NF);
|
setFlag(F(), NF);
|
||||||
setFlag(F(), CF, result.word & Bit8);
|
setFlag(F(), CF, result.high & CF);
|
||||||
adjustSZ<Z80>(F(), operand = result.low);
|
adjustSZ<Z80>(F(), operand = result.low);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -516,8 +516,8 @@ void EightBit::Z80::blockLoad(const register16_t source, const register16_t dest
|
|||||||
const auto value = BUS().read(source);
|
const auto value = BUS().read(source);
|
||||||
BUS().write(destination, value);
|
BUS().write(destination, value);
|
||||||
const auto xy = A() + value;
|
const auto xy = A() + value;
|
||||||
setFlag(F(), XF, xy & 8);
|
setFlag(F(), XF, xy & Bit3);
|
||||||
setFlag(F(), YF, xy & 2);
|
setFlag(F(), YF, xy & Bit1);
|
||||||
clearFlag(F(), NF | HC);
|
clearFlag(F(), NF | HC);
|
||||||
setFlag(F(), PF, --counter.word);
|
setFlag(F(), PF, --counter.word);
|
||||||
}
|
}
|
||||||
@@ -576,7 +576,7 @@ void EightBit::Z80::blockOut(const register16_t source, register16_t& destinatio
|
|||||||
MEMPTR() = destination;
|
MEMPTR() = destination;
|
||||||
setFlag(F(), NF, value & Bit7);
|
setFlag(F(), NF, value & Bit7);
|
||||||
setFlag(F(), HC | CF, (L() + value) > 0xff);
|
setFlag(F(), HC | CF, (L() + value) > 0xff);
|
||||||
adjustParity<Z80>(F(), ((value + L()) & 7) ^ B());
|
adjustParity<Z80>(F(), ((value + L()) & Mask3) ^ B());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::outi() {
|
void EightBit::Z80::outi() {
|
||||||
|
@@ -22,11 +22,11 @@ namespace EightBit {
|
|||||||
Signal<EventArgs> ReadingByte;
|
Signal<EventArgs> ReadingByte;
|
||||||
Signal<EventArgs> ReadByte;
|
Signal<EventArgs> ReadByte;
|
||||||
|
|
||||||
auto ADDRESS() const { return m_address; }
|
auto ADDRESS() const noexcept { return m_address; }
|
||||||
auto& ADDRESS() { return m_address; }
|
auto& ADDRESS() noexcept { return m_address; }
|
||||||
|
|
||||||
auto DATA() const { return m_data; }
|
auto DATA() const noexcept { return m_data; }
|
||||||
auto& DATA() { return m_data; }
|
auto& DATA() noexcept { return m_data; }
|
||||||
|
|
||||||
auto peek() { return reference(); }
|
auto peek() { return reference(); }
|
||||||
auto peek(const uint16_t address) { return reference(address); }
|
auto peek(const uint16_t address) { return reference(address); }
|
||||||
|
26
inc/Chip.h
26
inc/Chip.h
@@ -48,21 +48,21 @@ namespace EightBit {
|
|||||||
Low, High
|
Low, High
|
||||||
};
|
};
|
||||||
|
|
||||||
static void clearFlag(uint8_t& f, const int flag) { f &= ~flag; }
|
static void clearFlag(uint8_t& f, const int flag) noexcept { f &= ~flag; }
|
||||||
static void setFlag(uint8_t& f, const int flag) { f |= flag; }
|
static void setFlag(uint8_t& f, const int flag) noexcept { f |= flag; }
|
||||||
|
|
||||||
static void setFlag(uint8_t& f, const int flag, const int condition) { setFlag(f, flag, !!condition); }
|
static void setFlag(uint8_t& f, const int flag, const int condition) noexcept { setFlag(f, flag, !!condition); }
|
||||||
static void setFlag(uint8_t& f, const int flag, const uint32_t condition) { setFlag(f, flag, !!condition); }
|
static void setFlag(uint8_t& f, const int flag, const uint32_t condition) noexcept { setFlag(f, flag, !!condition); }
|
||||||
static void setFlag(uint8_t& f, const int flag, const bool condition) { condition ? setFlag(f, flag) : clearFlag(f, flag); }
|
static void setFlag(uint8_t& f, const int flag, const bool condition) noexcept { condition ? setFlag(f, flag) : clearFlag(f, flag); }
|
||||||
|
|
||||||
static void clearFlag(uint8_t& f, const int flag, const int condition) { clearFlag(f, flag, !!condition); }
|
static void clearFlag(uint8_t& f, const int flag, const int condition) noexcept { clearFlag(f, flag, !!condition); }
|
||||||
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 uint32_t condition) noexcept { clearFlag(f, flag, !!condition); }
|
||||||
static void clearFlag(uint8_t& f, const int flag, const bool condition) { setFlag(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 == High; }
|
static constexpr auto raised(const PinLevel line) { return line == High; }
|
||||||
static void raise(PinLevel& line) { line = High; }
|
static void raise(PinLevel& line) noexcept { line = High; }
|
||||||
static constexpr 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 lower(PinLevel& line) noexcept { line = Low; }
|
||||||
|
|
||||||
static void match(PinLevel& line, int value);
|
static void match(PinLevel& line, int value);
|
||||||
|
|
||||||
@@ -77,11 +77,11 @@ namespace EightBit {
|
|||||||
|
|
||||||
virtual ~Chip() {};
|
virtual ~Chip() {};
|
||||||
|
|
||||||
auto& POWER() { return m_powerLine; }
|
auto& POWER() noexcept { return m_powerLine; }
|
||||||
|
|
||||||
auto powered() { return raised(POWER()); }
|
auto powered() noexcept { return raised(POWER()); }
|
||||||
virtual void powerOn();
|
virtual void powerOn();
|
||||||
void powerOff() { lower(POWER()); }
|
void powerOff() noexcept { lower(POWER()); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Chip() = default;
|
Chip() = default;
|
||||||
|
@@ -9,13 +9,13 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace EightBit {
|
namespace EightBit {
|
||||||
int countBits(uint8_t value);
|
int countBits(uint8_t value) noexcept ;
|
||||||
bool oddParity(uint8_t value);
|
bool oddParity(uint8_t value) noexcept ;
|
||||||
int findFirstSet(int value);
|
int findFirstSet(int value) noexcept ;
|
||||||
constexpr void assume(int expression);
|
constexpr void assume(int expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int EightBit::countBits(const uint8_t value) {
|
inline int EightBit::countBits(const uint8_t value) noexcept {
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
return __popcnt(value);
|
return __popcnt(value);
|
||||||
#else
|
#else
|
||||||
@@ -35,11 +35,11 @@ inline int EightBit::countBits(const uint8_t value) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool EightBit::oddParity(const uint8_t value) {
|
inline bool EightBit::oddParity(const uint8_t value) noexcept {
|
||||||
return countBits(value) % 2;
|
return countBits(value) % 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int EightBit::findFirstSet(const int value) {
|
inline int EightBit::findFirstSet(const int value) noexcept {
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
unsigned long index;
|
unsigned long index;
|
||||||
if (_BitScanForward(&index, value))
|
if (_BitScanForward(&index, value))
|
||||||
|
@@ -6,6 +6,6 @@ namespace EightBit {
|
|||||||
static EventArgs m_empty;
|
static EventArgs m_empty;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static auto& empty() { return m_empty; }
|
static auto& empty() noexcept { return m_empty; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -33,13 +33,13 @@ namespace EightBit {
|
|||||||
|
|
||||||
~IntelProcessor() = default;
|
~IntelProcessor() = default;
|
||||||
|
|
||||||
const auto& getDecodedOpcode(const size_t i) const {
|
const auto& getDecodedOpcode(const size_t i) const noexcept {
|
||||||
return m_decodedOpcodes[i];
|
return m_decodedOpcodes[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& MEMPTR() { return m_memptr; }
|
auto& MEMPTR() noexcept { return m_memptr; }
|
||||||
|
|
||||||
auto& SP() { return m_sp; }
|
auto& SP() noexcept { return m_sp; }
|
||||||
|
|
||||||
virtual register16_t& AF() = 0;
|
virtual register16_t& AF() = 0;
|
||||||
auto& A() { return AF().high; }
|
auto& A() { return AF().high; }
|
||||||
@@ -105,13 +105,13 @@ namespace EightBit {
|
|||||||
return ((before & 0x88) >> 1) | ((value & 0x88) >> 2) | ((calculation & 0x88) >> 3);
|
return ((before & 0x88) >> 1) | ((value & 0x88) >> 2) | ((calculation & 0x88) >> 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto calculateHalfCarryAdd(const uint8_t before, const uint8_t value, const int calculation) {
|
static auto calculateHalfCarryAdd(const uint8_t before, const uint8_t value, const int calculation) noexcept {
|
||||||
static std::array<bool, 8> m_halfCarryTableAdd = { { false, false, true, false, true, false, true, true } };
|
static std::array<bool, 8> m_halfCarryTableAdd = { { false, false, true, false, true, false, true, true } };
|
||||||
const auto index = buildHalfCarryIndex(before, value, calculation);
|
const auto index = buildHalfCarryIndex(before, value, calculation);
|
||||||
return m_halfCarryTableAdd[index & Mask3];
|
return m_halfCarryTableAdd[index & Mask3];
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto calculateHalfCarrySub(const uint8_t before, const uint8_t value, const int calculation) {
|
static auto calculateHalfCarrySub(const uint8_t before, const uint8_t value, const int calculation) noexcept {
|
||||||
std::array<bool, 8> m_halfCarryTableSub = { { false, true, true, true, false, false, false, true } };
|
std::array<bool, 8> m_halfCarryTableSub = { { false, true, true, true, false, false, false, true } };
|
||||||
const auto index = buildHalfCarryIndex(before, value, calculation);
|
const auto index = buildHalfCarryIndex(before, value, calculation);
|
||||||
return m_halfCarryTableSub[index & Mask3];
|
return m_halfCarryTableSub[index & Mask3];
|
||||||
|
@@ -17,21 +17,21 @@ namespace EightBit {
|
|||||||
|
|
||||||
~Processor() {};
|
~Processor() {};
|
||||||
|
|
||||||
auto& PC() { return m_pc; }
|
auto& PC() noexcept { return m_pc; }
|
||||||
|
|
||||||
auto& RESET() { return m_resetLine; }
|
auto& RESET() noexcept { return m_resetLine; }
|
||||||
auto& HALT() { return m_haltLine; }
|
auto& HALT() noexcept { return m_haltLine; }
|
||||||
auto& INT() { return m_intLine; }
|
auto& INT() noexcept { return m_intLine; }
|
||||||
auto& IRQ() { return INT(); } // Synonym
|
auto& IRQ() noexcept { return INT(); } // Synonym
|
||||||
|
|
||||||
void powerOn() override;
|
void powerOn() override;
|
||||||
void reset() { lower(RESET()); }
|
void reset() noexcept { lower(RESET()); }
|
||||||
|
|
||||||
int run(int limit);
|
int run(int limit);
|
||||||
virtual int step() = 0;
|
virtual int step() = 0;
|
||||||
virtual int execute(uint8_t opcode) = 0;
|
virtual int execute(uint8_t opcode) = 0;
|
||||||
|
|
||||||
auto cycles() const { return m_cycles; }
|
auto cycles() const noexcept { return m_cycles; }
|
||||||
|
|
||||||
virtual register16_t peekWord(register16_t address) = 0;
|
virtual register16_t peekWord(register16_t address) = 0;
|
||||||
virtual void pokeWord(register16_t address, register16_t value) = 0;
|
virtual void pokeWord(register16_t address, register16_t value) = 0;
|
||||||
@@ -39,11 +39,11 @@ namespace EightBit {
|
|||||||
protected:
|
protected:
|
||||||
Processor(Bus& memory);
|
Processor(Bus& memory);
|
||||||
|
|
||||||
auto& BUS() { return m_bus; }
|
auto& BUS() noexcept { return m_bus; }
|
||||||
|
|
||||||
auto halted() { return lowered(HALT()); }
|
auto halted() noexcept { return lowered(HALT()); }
|
||||||
auto halt() { --PC(); lower(HALT()); }
|
auto halt() noexcept { --PC(); lower(HALT()); }
|
||||||
auto proceed() { ++PC(); raise(HALT()); }
|
auto proceed() noexcept { ++PC(); raise(HALT()); }
|
||||||
|
|
||||||
virtual void handleRESET();
|
virtual void handleRESET();
|
||||||
virtual void handleINT();
|
virtual void handleINT();
|
||||||
@@ -85,7 +85,7 @@ namespace EightBit {
|
|||||||
return setWord(value);
|
return setWord(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void jump(const register16_t destination) {
|
void jump(const register16_t destination) noexcept {
|
||||||
PC() = destination;
|
PC() = destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,9 +96,9 @@ namespace EightBit {
|
|||||||
|
|
||||||
virtual void ret();
|
virtual void ret();
|
||||||
|
|
||||||
void resetCycles() { m_cycles = 0; }
|
void resetCycles() noexcept { m_cycles = 0; }
|
||||||
void addCycles(const int extra) { m_cycles += extra; }
|
void addCycles(const int extra) noexcept { m_cycles += extra; }
|
||||||
void addCycle() { ++m_cycles; }
|
void addCycle() noexcept { ++m_cycles; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Bus& m_bus;
|
Bus& m_bus;
|
||||||
|
@@ -16,8 +16,8 @@ namespace EightBit {
|
|||||||
std::vector<uint8_t> m_bytes;
|
std::vector<uint8_t> m_bytes;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const auto& BYTES() const { return m_bytes; }
|
const auto& BYTES() const noexcept { return m_bytes; }
|
||||||
auto& BYTES() { return m_bytes; }
|
auto& BYTES() noexcept { return m_bytes; }
|
||||||
|
|
||||||
void poke(uint16_t address, uint8_t value) override;
|
void poke(uint16_t address, uint8_t value) override;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user