From 640b2be670afe2ef84d710bbf7da59b4e60d6b66 Mon Sep 17 00:00:00 2001 From: "Adrian.Conlon" Date: Sun, 3 Sep 2017 12:11:14 +0100 Subject: [PATCH] Parts of the EightBit library become linux compatible (TBC!) Signed-off-by: Adrian.Conlon --- Intel8080/inc/Intel8080.h | 3 +-- Intel8080/src/Intel8080.cpp | 44 ------------------------------------- Intel8080/src/stdafx.h | 6 ----- inc/Memory.h | 15 ++++++++++--- inc/Processor.h | 5 +++++ inc/TestHarness.h | 14 ++++++++---- src/stdafx.h | 9 ++++++-- 7 files changed, 35 insertions(+), 61 deletions(-) diff --git a/Intel8080/inc/Intel8080.h b/Intel8080/inc/Intel8080.h index afe81e2..18986b9 100644 --- a/Intel8080/inc/Intel8080.h +++ b/Intel8080/inc/Intel8080.h @@ -37,6 +37,7 @@ namespace EightBit { virtual register16_t& HL() override { return hl; } private: + bool m_interrupt; InputOutput& m_ports; register16_t af; @@ -44,8 +45,6 @@ namespace EightBit { register16_t de; register16_t hl; - bool m_interrupt; - uint8_t R(int r) { __assume(r < 8); __assume(r >= 0); diff --git a/Intel8080/src/Intel8080.cpp b/Intel8080/src/Intel8080.cpp index 069b862..9047a78 100644 --- a/Intel8080/src/Intel8080.cpp +++ b/Intel8080/src/Intel8080.cpp @@ -1,8 +1,6 @@ #include "stdafx.h" #include "Intel8080.h" -#pragma region Reset and initialisation - EightBit::Intel8080::Intel8080(Memory& memory, InputOutput& ports) : IntelProcessor(memory), m_interrupt(false), @@ -10,10 +8,6 @@ EightBit::Intel8080::Intel8080(Memory& memory, InputOutput& ports) bc.word = de.word = hl.word = Mask16; } -#pragma endregion Reset and initialisation - -#pragma region Interrupt routines - void EightBit::Intel8080::di() { m_interrupt = false; } @@ -34,10 +28,6 @@ bool EightBit::Intel8080::isInterruptable() const { return m_interrupt; } -#pragma endregion Interrupt routines - -#pragma region Flag manipulation helpers - void EightBit::Intel8080::increment(uint8_t& f, uint8_t& operand) { adjustSZP(f, ++operand); clearFlag(f, AC, lowNibble(operand)); @@ -48,10 +38,6 @@ void EightBit::Intel8080::decrement(uint8_t& f, uint8_t& operand) { setFlag(f, AC, lowNibble(operand) != Mask4); } -#pragma endregion Flag manipulation helpers - -#pragma region PC manipulation: call/ret/jp/jr - bool EightBit::Intel8080::jumpConditionalFlag(uint8_t& f, int flag) { switch (flag) { case 0: // NZ @@ -124,20 +110,12 @@ bool EightBit::Intel8080::callConditionalFlag(uint8_t& f, int flag) { throw std::logic_error("Unhandled CALL conditional"); } -#pragma endregion PC manipulation: call/ret/jp/jr - -#pragma region 16-bit arithmetic - void EightBit::Intel8080::add(uint8_t& f, register16_t& operand, register16_t value) { const auto result = operand.word + value.word; setFlag(f, CF, result & Bit16); operand.word = result; } -#pragma endregion 16-bit arithmetic - -#pragma region ALU - void EightBit::Intel8080::add(uint8_t& f, uint8_t& operand, uint8_t value, int carry) { register16_t result; @@ -192,10 +170,6 @@ void EightBit::Intel8080::compare(uint8_t& f, uint8_t check, uint8_t value) { subtract(f, check, value); } -#pragma endregion ALU - -#pragma region Shift and rotate - void EightBit::Intel8080::rlc(uint8_t& f, uint8_t& operand) { auto carry = operand & Bit7; operand = (operand << 1) | (carry >> 7); @@ -220,10 +194,6 @@ void EightBit::Intel8080::rr(uint8_t& f, uint8_t& operand) { operand = (operand >> 1) | (carry << 7); } -#pragma endregion Shift and rotate - -#pragma region Miscellaneous instructions - void EightBit::Intel8080::daa(uint8_t& a, uint8_t& f) { const auto& before = a; auto carry = f & CF; @@ -261,10 +231,6 @@ void EightBit::Intel8080::xhtl() { H() = MEMPTR().high; } -#pragma endregion Miscellaneous instructions - -#pragma region I/O instructions - void EightBit::Intel8080::out() { m_ports.write(fetchByte(), A()); } @@ -273,20 +239,12 @@ void EightBit::Intel8080::in() { A() = m_ports.read(fetchByte()); } -#pragma endregion I/O instructions - -#pragma region Controlled instruction execution - int EightBit::Intel8080::step() { ExecutingInstruction.fire(*this); cycles = 0; return fetchExecute(); } -#pragma endregion Controlled instruction execution - -#pragma region Instruction decode and execution - int EightBit::Intel8080::execute(uint8_t opcode) { const auto& decoded = getDecodedOpcode(opcode); @@ -641,5 +599,3 @@ void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) { break; } } - -#pragma endregion Instruction decode and execution diff --git a/Intel8080/src/stdafx.h b/Intel8080/src/stdafx.h index b22af77..d77c746 100644 --- a/Intel8080/src/stdafx.h +++ b/Intel8080/src/stdafx.h @@ -14,9 +14,3 @@ #include #include - -#if defined(_M_X64) || defined(_M_IX86 ) -# define HOST_LITTLE_ENDIAN -#else -# define HOST_BIG_ENDIAN -#endif diff --git a/inc/Memory.h b/inc/Memory.h index ead19d9..3356889 100644 --- a/inc/Memory.h +++ b/inc/Memory.h @@ -7,10 +7,19 @@ #include "Signal.h" #include "AddressEventArgs.h" -#if defined(_M_X64) || defined(_M_IX86 ) -# define HOST_LITTLE_ENDIAN +#ifdef __BYTE_ORDER__ +# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +# define HOST_LITTLE_ENDIAN +# endif +# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# define HOST_BIG_ENDIAN +# endif #else -# define HOST_BIG_ENDIAN +# if defined(_M_X64) || defined(_M_IX86) +# define HOST_LITTLE_ENDIAN +# else +# define HOST_BIG_ENDIAN +# endif #endif namespace EightBit { diff --git a/inc/Processor.h b/inc/Processor.h index 86fc0e3..163899a 100644 --- a/inc/Processor.h +++ b/inc/Processor.h @@ -4,6 +4,11 @@ #include "Memory.h" +#ifdef __GNUG__ +# define __assume(cond) do { if (!(cond)) __builtin_unreachable(); } while (0) +# define __popcnt __builtin_popcount +#endif + namespace EightBit { class Processor { public: diff --git a/inc/TestHarness.h b/inc/TestHarness.h index 4dfead1..f7e9095 100644 --- a/inc/TestHarness.h +++ b/inc/TestHarness.h @@ -1,9 +1,15 @@ #pragma once +#include #include -#include #include +#ifdef __GNUG__ +#include +#else +#include +#endif + namespace EightBit { template class TestHarness { public: @@ -76,14 +82,14 @@ namespace EightBit { long long m_instructions; std::chrono::steady_clock::time_point m_startTime; std::chrono::steady_clock::time_point m_finishTime; - unsigned __int64 m_startHostCycles; - unsigned __int64 m_finishHostCycles; + uint64_t m_startHostCycles; + uint64_t m_finishHostCycles; static std::chrono::steady_clock::time_point now() { return std::chrono::steady_clock::now(); } - static unsigned __int64 currentHostCycles() { + static uint64_t currentHostCycles() { return __rdtsc(); } }; diff --git a/src/stdafx.h b/src/stdafx.h index e2a615c..9d6547d 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -8,9 +8,14 @@ #include #include #include -#include #include #include #include -#include \ No newline at end of file +#include + +#ifdef __GNUG__ +#include +#else +#include +#endif