mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-12-22 09:30:32 +00:00
Ensure virtual methods are no longer defined inline.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
85bc2aab12
commit
887b89308a
@ -162,10 +162,7 @@ namespace EightBit {
|
||||
return !!condition;
|
||||
}
|
||||
|
||||
virtual void ret() final {
|
||||
Processor::ret();
|
||||
MEMPTR() = PC();
|
||||
}
|
||||
virtual void ret() final;
|
||||
|
||||
private:
|
||||
std::array<opcode_decoded_t, 0x100> m_decodedOpcodes;
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -20,9 +19,7 @@ namespace EightBit {
|
||||
virtual size_t size() const = 0;
|
||||
virtual uint8_t peek(uint16_t address) const = 0;
|
||||
|
||||
virtual uint8_t& reference(uint16_t) {
|
||||
throw new std::logic_error("Reference operation not allowed.");
|
||||
}
|
||||
virtual uint8_t& reference(uint16_t);
|
||||
|
||||
virtual int load(std::ifstream& file, int writeOffset = 0, int readOffset = 0, int limit = -1) = 0;
|
||||
virtual int load(const std::string& path, int writeOffset = 0, int readOffset = 0, int limit = -1) = 0;
|
||||
|
@ -71,7 +71,7 @@ namespace EightBit {
|
||||
virtual void push(uint8_t value) = 0;
|
||||
virtual uint8_t pop() = 0;
|
||||
|
||||
virtual void pushWord(const register16_t value) = 0;
|
||||
virtual void pushWord(register16_t value) = 0;
|
||||
virtual register16_t popWord() = 0;
|
||||
|
||||
auto getWord(const register16_t address) {
|
||||
@ -93,9 +93,7 @@ namespace EightBit {
|
||||
jump(destination);
|
||||
}
|
||||
|
||||
virtual void ret() {
|
||||
jump(popWord());
|
||||
}
|
||||
virtual void ret();
|
||||
|
||||
void resetCycles() { m_cycles = 0; }
|
||||
void addCycles(const int extra) { m_cycles += extra; }
|
||||
|
13
inc/Ram.h
13
inc/Ram.h
@ -9,16 +9,9 @@ namespace EightBit {
|
||||
// it's externally 'reference'able and 'poke'able.
|
||||
class Ram : public Rom {
|
||||
public:
|
||||
Ram(const size_t size = 0) noexcept
|
||||
: Rom(size) {
|
||||
}
|
||||
Ram(size_t size = 0) noexcept;
|
||||
|
||||
virtual uint8_t& reference(const uint16_t address) final {
|
||||
return BYTES()[address];
|
||||
}
|
||||
|
||||
virtual void poke(const uint16_t address, const uint8_t value) final {
|
||||
Rom::poke(address, value);
|
||||
}
|
||||
virtual uint8_t& reference(uint16_t address) final;
|
||||
virtual void poke(uint16_t address, uint8_t value) final;
|
||||
};
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
#endif
|
||||
|
||||
namespace EightBit {
|
||||
union register16_t {
|
||||
union register16_t final {
|
||||
struct {
|
||||
#ifdef HOST_LITTLE_ENDIAN
|
||||
uint8_t low;
|
||||
|
33
inc/Rom.h
33
inc/Rom.h
@ -19,39 +19,20 @@ namespace EightBit {
|
||||
const auto& BYTES() const { return m_bytes; }
|
||||
auto& BYTES() { return m_bytes; }
|
||||
|
||||
virtual void poke(const uint16_t address, const uint8_t value) override {
|
||||
BYTES()[address] = value;
|
||||
}
|
||||
virtual 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(const size_t size = 0) noexcept
|
||||
: m_bytes(size) {
|
||||
}
|
||||
Rom(size_t size = 0) noexcept;
|
||||
|
||||
virtual size_t size() const final { return m_bytes.size(); }
|
||||
virtual size_t size() const final;
|
||||
|
||||
virtual int load(std::ifstream& file, const int writeOffset = 0, const int readOffset = 0, const int limit = -1) final {
|
||||
const auto maximumSize = (int)size() - writeOffset;
|
||||
return load(file, m_bytes, writeOffset, readOffset, limit, maximumSize);
|
||||
}
|
||||
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;
|
||||
|
||||
virtual int load(const std::string& path, const int writeOffset = 0, const int readOffset = 0, const int limit = -1) final {
|
||||
const auto maximumSize = (int)size() - writeOffset;
|
||||
return load(path, m_bytes, writeOffset, readOffset, limit, maximumSize);
|
||||
}
|
||||
|
||||
virtual int load(const std::vector<uint8_t>& bytes, const int writeOffset = 0, const int readOffset = 0, int limit = -1) final {
|
||||
if (limit < 0)
|
||||
limit = (int)bytes.size() - readOffset;
|
||||
std::copy(bytes.cbegin() + readOffset, bytes.cbegin() + limit, m_bytes.begin() + writeOffset);
|
||||
return limit;
|
||||
}
|
||||
|
||||
virtual uint8_t peek(const uint16_t address) const final {
|
||||
return BYTES()[address];
|
||||
}
|
||||
virtual uint8_t peek(uint16_t address) const final;
|
||||
};
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Memory.h"
|
||||
|
||||
namespace EightBit {
|
||||
@ -8,29 +13,18 @@ namespace EightBit {
|
||||
// is being read.
|
||||
class UnusedMemory final : public Memory {
|
||||
public:
|
||||
UnusedMemory(const size_t size, const uint8_t value)
|
||||
: m_size(size), m_value(value) {}
|
||||
UnusedMemory(size_t size, uint8_t value);
|
||||
virtual ~UnusedMemory() = default;
|
||||
|
||||
virtual size_t size() const final { return m_size; }
|
||||
virtual uint8_t peek(uint16_t address) const final { return m_value; }
|
||||
virtual size_t size() const final;
|
||||
virtual uint8_t peek(uint16_t address) const final;
|
||||
|
||||
virtual int load(std::ifstream& file, int writeOffset = 0, int readOffset = 0, int limit = -1) final {
|
||||
throw new std::logic_error("load operation not allowed.");
|
||||
}
|
||||
|
||||
virtual int load(const std::string& path, int writeOffset = 0, int readOffset = 0, int limit = -1) final {
|
||||
throw new std::logic_error("load operation not allowed.");
|
||||
}
|
||||
|
||||
virtual int load(const std::vector<uint8_t>& bytes, int writeOffset = 0, int readOffset = 0, int limit = -1) final {
|
||||
throw new std::logic_error("load operation not allowed.");
|
||||
}
|
||||
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;
|
||||
|
||||
protected:
|
||||
virtual void poke(uint16_t address, uint8_t value) {
|
||||
throw new std::logic_error("Poke operation not allowed.");
|
||||
}
|
||||
virtual void poke(uint16_t address, uint8_t value) final;
|
||||
|
||||
private:
|
||||
size_t m_size;
|
||||
|
@ -30,3 +30,8 @@ void EightBit::IntelProcessor::setWord(const register16_t value) {
|
||||
LittleEndianProcessor::setWord(value);
|
||||
MEMPTR() = BUS().ADDRESS();
|
||||
}
|
||||
|
||||
void EightBit::IntelProcessor::ret() {
|
||||
Processor::ret();
|
||||
MEMPTR() = PC();
|
||||
}
|
||||
|
8
src/Memory.cpp
Normal file
8
src/Memory.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include "stdafx.h"
|
||||
#include "Memory.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
uint8_t& EightBit::Memory::reference(uint16_t) {
|
||||
throw new std::logic_error("Reference operation not allowed.");
|
||||
}
|
@ -39,3 +39,7 @@ int8_t EightBit::Processor::signExtend(const int b, uint8_t x) {
|
||||
const auto result = (x ^ m) - m;
|
||||
return result;
|
||||
}
|
||||
|
||||
void EightBit::Processor::ret() {
|
||||
jump(popWord());
|
||||
}
|
||||
|
13
src/Ram.cpp
Normal file
13
src/Ram.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include "stdafx.h"
|
||||
#include "Ram.h"
|
||||
|
||||
EightBit::Ram::Ram(const size_t size) noexcept
|
||||
: Rom(size) {}
|
||||
|
||||
uint8_t& EightBit::Ram::reference(const uint16_t address) {
|
||||
return BYTES()[address];
|
||||
}
|
||||
|
||||
void EightBit::Ram::poke(const uint16_t address, const uint8_t value) {
|
||||
Rom::poke(address, value);
|
||||
}
|
32
src/Rom.cpp
32
src/Rom.cpp
@ -36,3 +36,35 @@ int EightBit::Rom::load(const std::string& path, std::vector<uint8_t>& output, c
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
void EightBit::Rom::poke(const uint16_t address, const uint8_t value) {
|
||||
BYTES()[address] = value;
|
||||
}
|
||||
|
||||
EightBit::Rom::Rom(const size_t size) noexcept
|
||||
: m_bytes(size) {}
|
||||
|
||||
size_t EightBit::Rom::size() const {
|
||||
return m_bytes.size();
|
||||
}
|
||||
|
||||
int EightBit::Rom::load(std::ifstream& file, const int writeOffset, const int readOffset, const int limit) {
|
||||
const auto maximumSize = (int)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;
|
||||
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;
|
||||
std::copy(bytes.cbegin() + readOffset, bytes.cbegin() + limit, m_bytes.begin() + writeOffset);
|
||||
return limit;
|
||||
}
|
||||
|
||||
uint8_t EightBit::Rom::peek(const uint16_t address) const {
|
||||
return BYTES()[address];
|
||||
}
|
||||
|
29
src/UnusedMemory.cpp
Normal file
29
src/UnusedMemory.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include "stdafx.h"
|
||||
#include "UnusedMemory.h"
|
||||
|
||||
EightBit::UnusedMemory::UnusedMemory(const size_t size, const uint8_t value)
|
||||
: m_size(size), m_value(value) {}
|
||||
|
||||
size_t EightBit::UnusedMemory::size() const {
|
||||
return m_size;
|
||||
}
|
||||
|
||||
uint8_t EightBit::UnusedMemory::peek(uint16_t) const {
|
||||
return m_value;
|
||||
}
|
||||
|
||||
int EightBit::UnusedMemory::load(std::ifstream&, int, int, int) {
|
||||
throw new 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.");
|
||||
}
|
||||
|
||||
int EightBit::UnusedMemory::load(const std::vector<uint8_t>&, int, int, int) {
|
||||
throw new std::logic_error("load operation not allowed.");
|
||||
}
|
||||
|
||||
void EightBit::UnusedMemory::poke(uint16_t, uint8_t) {
|
||||
throw new std::logic_error("Poke operation not allowed.");
|
||||
}
|
Loading…
Reference in New Issue
Block a user