From e40240694fae5c2284627400087a652b61148431 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Sun, 24 Jun 2018 22:33:02 +0100 Subject: [PATCH] More removal of duplicated code. Signed-off-by: Adrian Conlon --- Intel8080/test/Board.cpp | 4 ++-- Intel8080/test/Board.h | 4 ++-- M6502/test/Board.cpp | 4 ++-- M6502/test/Board.h | 4 ++-- Z80/test/Board.cpp | 4 ++-- Z80/test/Board.h | 4 ++-- inc/Bus.h | 12 +++++------- inc/Memory.h | 2 ++ inc/Processor.h | 15 ++------------- inc/Rom.h | 16 +++++++++------- src/Bus.cpp | 20 -------------------- src/EightBit.vcxproj | 1 - src/EightBit.vcxproj.filters | 3 --- 13 files changed, 30 insertions(+), 63 deletions(-) diff --git a/Intel8080/test/Board.cpp b/Intel8080/test/Board.cpp index 8a343c4..b67e757 100644 --- a/Intel8080/test/Board.cpp +++ b/Intel8080/test/Board.cpp @@ -33,7 +33,7 @@ void Board::initialise() { CPU().PC() = m_configuration.getStartAddress(); } -void Board::Cpu_ExecutingInstruction_Cpm(const EightBit::Intel8080& cpu) { +void Board::Cpu_ExecutingInstruction_Cpm(EightBit::Intel8080& cpu) { switch (cpu.PC().word) { case 0x0: // CP/M warm start CPU().powerOff(); @@ -64,7 +64,7 @@ void Board::bdos() { } } -void Board::Cpu_ExecutingInstruction_Profile(const EightBit::Intel8080& cpu) { +void Board::Cpu_ExecutingInstruction_Profile(EightBit::Intel8080& cpu) { const auto pc = cpu.PC(); diff --git a/Intel8080/test/Board.h b/Intel8080/test/Board.h index 7419151..1846b9c 100644 --- a/Intel8080/test/Board.h +++ b/Intel8080/test/Board.h @@ -32,10 +32,10 @@ private: EightBit::Disassembler m_disassembler; EightBit::Profiler m_profiler; - void Cpu_ExecutingInstruction_Cpm(const EightBit::Intel8080& cpu); + void Cpu_ExecutingInstruction_Cpm(EightBit::Intel8080& cpu); void Cpu_ExecutingInstruction_Debug(const EightBit::Intel8080& cpu); - void Cpu_ExecutingInstruction_Profile(const EightBit::Intel8080& cpu); + void Cpu_ExecutingInstruction_Profile(EightBit::Intel8080& cpu); void bdos(); }; diff --git a/M6502/test/Board.cpp b/M6502/test/Board.cpp index 3bcba47..c80c006 100644 --- a/M6502/test/Board.cpp +++ b/M6502/test/Board.cpp @@ -69,7 +69,7 @@ void Board::Cpu_ExecutingInstruction_Profile(const EightBit::MOS6502& cpu) { //m_profiler.addInstruction(m_memory.peek(pc.word)); } -void Board::Cpu_ExecutedInstruction_StopLoop(const EightBit::MOS6502& cpu) { +void Board::Cpu_ExecutedInstruction_StopLoop(EightBit::MOS6502& cpu) { auto pc = cpu.PC().word; if (m_oldPC == pc) { @@ -81,7 +81,7 @@ void Board::Cpu_ExecutedInstruction_StopLoop(const EightBit::MOS6502& cpu) { } } -void Board::Cpu_ExecutingInstruction_Debug(const EightBit::MOS6502& cpu) { +void Board::Cpu_ExecutingInstruction_Debug(EightBit::MOS6502& cpu) { auto address = cpu.PC().word; auto cell = peek(address); diff --git a/M6502/test/Board.h b/M6502/test/Board.h index 75e875f..679e8b1 100644 --- a/M6502/test/Board.h +++ b/M6502/test/Board.h @@ -39,10 +39,10 @@ private: void pollKeyboard(); - void Cpu_ExecutingInstruction_Debug(const EightBit::MOS6502& cpu); + void Cpu_ExecutingInstruction_Debug(EightBit::MOS6502& cpu); void Cpu_ExecutingInstruction_Profile(const EightBit::MOS6502& cpu); - void Cpu_ExecutedInstruction_StopLoop(const EightBit::MOS6502& cpu); + void Cpu_ExecutedInstruction_StopLoop(EightBit::MOS6502& cpu); void Memory_ReadingByte_Input(EightBit::EventArgs); void Memory_WrittenByte_Output(EightBit::EventArgs); diff --git a/Z80/test/Board.cpp b/Z80/test/Board.cpp index 1b680e1..170fc07 100644 --- a/Z80/test/Board.cpp +++ b/Z80/test/Board.cpp @@ -34,7 +34,7 @@ void Board::initialise() { CPU().PC() = m_configuration.getStartAddress(); } -void Board::Cpu_ExecutingInstruction_Cpm(const EightBit::Z80& cpu) { +void Board::Cpu_ExecutingInstruction_Cpm(EightBit::Z80& cpu) { if (UNLIKELY(EightBit::Processor::lowered(cpu.HALT()))) CPU().powerOff(); switch (cpu.PC().word) { @@ -65,7 +65,7 @@ void Board::bdos() { } } -void Board::Cpu_ExecutingInstruction_Profile(const EightBit::Z80& cpu) { +void Board::Cpu_ExecutingInstruction_Profile(EightBit::Z80& cpu) { const auto pc = cpu.PC(); diff --git a/Z80/test/Board.h b/Z80/test/Board.h index e9d9059..a05dee1 100644 --- a/Z80/test/Board.h +++ b/Z80/test/Board.h @@ -34,10 +34,10 @@ private: EightBit::Disassembler m_disassembler; EightBit::Profiler m_profiler; - void Cpu_ExecutingInstruction_Cpm(const EightBit::Z80& cpu); + void Cpu_ExecutingInstruction_Cpm(EightBit::Z80& cpu); void Cpu_ExecutingInstruction_Debug(EightBit::Z80& cpu); - void Cpu_ExecutingInstruction_Profile(const EightBit::Z80& cpu); + void Cpu_ExecutingInstruction_Profile(EightBit::Z80& cpu); void bdos(); }; diff --git a/inc/Bus.h b/inc/Bus.h index c97a8f7..6443955 100644 --- a/inc/Bus.h +++ b/inc/Bus.h @@ -18,14 +18,12 @@ namespace EightBit { Signal ReadByte; register16_t& ADDRESS() { return m_address; } - register16_t ADDRESS() const { return m_address; } uint8_t& DATA() { return m_data; } - uint8_t DATA() const { return m_data; } - uint8_t peek(); - uint8_t peek(uint16_t address); - void poke(uint8_t value); - void poke(uint16_t address, uint8_t value); + uint8_t peek() { return reference(); } + uint8_t peek(uint16_t address) { return reference(address); } + void poke(uint8_t value) { reference() = value; } + void poke(uint16_t address, uint8_t value) { reference(address) = value; } uint16_t peekWord(uint16_t address); @@ -44,7 +42,7 @@ namespace EightBit { protected: virtual uint8_t& reference(uint16_t address) = 0; - uint8_t& reference(); + uint8_t& reference() { return reference(ADDRESS().word); } private: uint8_t m_data = 0xff; diff --git a/inc/Memory.h b/inc/Memory.h index a0bd246..954ef0c 100644 --- a/inc/Memory.h +++ b/inc/Memory.h @@ -48,4 +48,6 @@ namespace EightBit { private: std::vector m_bytes; }; + + typedef Memory Rom; } diff --git a/inc/Processor.h b/inc/Processor.h index 5d3e3ee..bc330a0 100644 --- a/inc/Processor.h +++ b/inc/Processor.h @@ -68,27 +68,16 @@ namespace EightBit { static int demoteNibble(const int value) { return highNibble(value); } Bus& BUS() { return m_bus; } - const Bus& BUS() const { return m_bus; } register16_t& PC() { return m_pc; } - register16_t PC() const { return m_pc; } PinLevel& RESET() { return m_resetLine; } - PinLevel RESET() const { return m_resetLine; } // In - PinLevel& HALT() { return m_haltLine; } - PinLevel HALT() const { return m_haltLine; } // Out - PinLevel& INT() { return m_intLine; } - PinLevel INT() const { return m_intLine; } // In - PinLevel& NMI() { return m_nmiLine; } - PinLevel NMI() const { return m_nmiLine; } // In - PinLevel& POWER() { return m_powerLine; } - PinLevel POWER() const { return m_powerLine; } // In - bool powered() const { return raised(POWER()); } + bool powered() { return raised(POWER()); } virtual void powerOn() { raise(POWER()); raise(HALT()); reset(); } void powerOff() { lower(POWER()); } @@ -115,7 +104,7 @@ namespace EightBit { virtual void reset(); - bool halted() const { return lowered(HALT()); } + bool halted() { return lowered(HALT()); } void halt() { --PC().word; lower(HALT()); } void proceed() { ++PC().word; raise(HALT()); } diff --git a/inc/Rom.h b/inc/Rom.h index d312d44..62b6b99 100644 --- a/inc/Rom.h +++ b/inc/Rom.h @@ -1,13 +1,15 @@ #pragma once -#include +//#include #include "Memory.h" namespace EightBit { - class Rom : public Memory { - public: - Rom(const size_t size = 0) - : Memory(size) { - } - }; + + + //class Rom : public Memory { + //public: + // Rom(const size_t size = 0) + // : Memory(size) { + // } + //}; } diff --git a/src/Bus.cpp b/src/Bus.cpp index 6ad725b..fc2274a 100644 --- a/src/Bus.cpp +++ b/src/Bus.cpp @@ -1,22 +1,6 @@ #include "stdafx.h" #include "Bus.h" -uint8_t EightBit::Bus::peek() { - return reference(); -} - -uint8_t EightBit::Bus::peek(const uint16_t address) { - return reference(address); -} - -void EightBit::Bus::poke(const uint8_t value) { - reference() = value; -} - -void EightBit::Bus::poke(const uint16_t address, const uint8_t value) { - reference(address) = value; -} - uint16_t EightBit::Bus::peekWord(const uint16_t address) { const auto low = peek(address); const auto high = peek(address + 1); @@ -40,7 +24,3 @@ void EightBit::Bus::write(const uint8_t value) { DATA() = value; write(); } - -uint8_t& EightBit::Bus::reference() { - return reference(ADDRESS().word); -} diff --git a/src/EightBit.vcxproj b/src/EightBit.vcxproj index 00cf7c8..35a9425 100644 --- a/src/EightBit.vcxproj +++ b/src/EightBit.vcxproj @@ -145,7 +145,6 @@ - diff --git a/src/EightBit.vcxproj.filters b/src/EightBit.vcxproj.filters index 1f43263..fb893d3 100644 --- a/src/EightBit.vcxproj.filters +++ b/src/EightBit.vcxproj.filters @@ -41,9 +41,6 @@ Header Files - - Header Files - Header Files