Use nodiscard, where appropriate and try not to inline virtual methods.

Signed-off-by: Adrian Conlon <adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2021-01-02 11:49:34 +00:00
parent 4ec462e79a
commit b4f8c81a94
7 changed files with 68 additions and 59 deletions

View File

@ -16,15 +16,15 @@ namespace EightBit {
protected:
BigEndianProcessor(Bus& memory);
register16_t getWord() override;
[[nodiscard]] register16_t getWord() override;
void setWord(register16_t value) override;
register16_t getWordPaged(uint8_t page, uint8_t offset) override;
[[nodiscard]] register16_t getWordPaged(uint8_t page, uint8_t offset) override;
void setWordPaged(uint8_t page, uint8_t offset, register16_t value) override;
register16_t fetchWord() final;
[[nodiscard]] register16_t fetchWord() final;
void pushWord(register16_t value) final;
register16_t popWord() final;
[[nodiscard]] register16_t popWord() final;
};
}

View File

@ -1,14 +1,14 @@
#pragma once
#include <cstdint>
#include <fstream>
//#include <fstream>
#include <string>
#include <ios>
#include <sstream>
//#include <ios>
//#include <sstream>
#include <map>
#include <optional>
#include <vector>
#include <utility>
//#include <utility>
namespace EightBit {
class IntelHexFile final {
@ -21,7 +21,7 @@ namespace EightBit {
[[nodiscard]] std::optional<std::pair<uint16_t, std::vector<uint8_t>>> parse(std::string line);
[[nodiscard]] std::vector<uint8_t> parseDataRecord(std::string line, uint8_t count);
template <class T> T fromHex(std::string input) {
template <class T> [[nodiscard]] T fromHex(std::string input) {
std::istringstream converter(input);
unsigned output;
converter >> std::hex >> output;

View File

@ -132,47 +132,13 @@ namespace EightBit {
//
virtual void restart(const uint8_t address) {
call(MEMPTR() = { address, 0 });
}
virtual int callConditional(const int condition) {
MEMPTR() = fetchWord();
if (condition)
call(MEMPTR());
return condition;
}
virtual int jumpConditional(const int condition) {
MEMPTR() = fetchWord();
if (condition)
jump(MEMPTR());
return condition;
}
virtual int returnConditional(const int condition) {
if (condition)
ret();
return condition;
}
virtual void jr(const int8_t offset) {
jump(MEMPTR() = PC() + offset);
}
virtual int jrConditional(const int condition) {
const auto offsetAddress = PC()++;
if (condition) {
const auto offset = memoryRead(offsetAddress);
jr(offset);
}
return condition;
}
void ret() override {
Processor::ret();
MEMPTR() = PC();
}
virtual void restart(uint8_t address);
virtual int callConditional(int condition);
virtual int jumpConditional(int condition);
virtual int returnConditional(int condition);
virtual void jr(int8_t offset);
virtual int jrConditional(int condition);
void ret() override;
private:
std::array<opcode_decoded_t, 0x100> m_decodedOpcodes;

View File

@ -16,15 +16,15 @@ namespace EightBit {
protected:
LittleEndianProcessor(Bus& memory);
register16_t getWord() override;
[[nodiscard]] register16_t getWord() override;
void setWord(register16_t value) override;
register16_t getWordPaged(uint8_t page, uint8_t offset) override;
[[nodiscard]] register16_t getWordPaged(uint8_t page, uint8_t offset) override;
void setWordPaged(uint8_t page, uint8_t offset, register16_t value) override;
register16_t fetchWord() final;
[[nodiscard]] register16_t fetchWord() final;
void pushWord(register16_t value) override;
register16_t popWord() override;
[[nodiscard]] register16_t popWord() override;
};
}

View File

@ -88,11 +88,7 @@ namespace EightBit {
PC() = destination;
}
virtual void call(const register16_t destination) {
pushWord(PC());
jump(destination);
}
virtual void call(register16_t destination);
virtual void ret();
private:

View File

@ -40,3 +40,45 @@ void EightBit::IntelProcessor::setWord(const register16_t value) {
LittleEndianProcessor::setWord(value);
MEMPTR() = BUS().ADDRESS();
}
void EightBit::IntelProcessor::restart(const uint8_t address) {
call(MEMPTR() = { address, 0 });
}
int EightBit::IntelProcessor::callConditional(const int condition) {
MEMPTR() = fetchWord();
if (condition)
call(MEMPTR());
return condition;
}
int EightBit::IntelProcessor::jumpConditional(const int condition) {
MEMPTR() = fetchWord();
if (condition)
jump(MEMPTR());
return condition;
}
int EightBit::IntelProcessor::returnConditional(const int condition) {
if (condition)
ret();
return condition;
}
void EightBit::IntelProcessor::jr(const int8_t offset) {
jump(MEMPTR() = PC() + offset);
}
int EightBit::IntelProcessor::jrConditional(const int condition) {
const auto offsetAddress = PC()++;
if (condition) {
const auto offset = memoryRead(offsetAddress);
jr(offset);
}
return condition;
}
void EightBit::IntelProcessor::ret() {
Processor::ret();
MEMPTR() = PC();
}

View File

@ -67,6 +67,11 @@ int8_t EightBit::Processor::signExtend(const int b, uint8_t x) noexcept {
return result;
}
void EightBit::Processor::call(const register16_t destination) {
pushWord(PC());
jump(destination);
}
void EightBit::Processor::ret() {
jump(popWord());
}