mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-12-23 00:29:47 +00:00
Parts of the EightBit library become linux compatible (TBC!)
Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
parent
57cfd79c44
commit
640b2be670
@ -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);
|
||||
|
@ -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<Intel8080>(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
|
||||
|
@ -14,9 +14,3 @@
|
||||
#include <bitset>
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
||||
#if defined(_M_X64) || defined(_M_IX86 )
|
||||
# define HOST_LITTLE_ENDIAN
|
||||
#else
|
||||
# define HOST_BIG_ENDIAN
|
||||
#endif
|
||||
|
15
inc/Memory.h
15
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 {
|
||||
|
@ -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:
|
||||
|
@ -1,9 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <chrono>
|
||||
#include <intrin.h>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef __GNUG__
|
||||
#include <x86intrin.h>
|
||||
#else
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
|
||||
namespace EightBit {
|
||||
template<class ConfigurationT, class BoardT> 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();
|
||||
}
|
||||
};
|
||||
|
@ -8,9 +8,14 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <chrono>
|
||||
#include <intrin.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <vector>
|
||||
|
||||
#ifdef __GNUG__
|
||||
#include <x86intrin.h>
|
||||
#else
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user