diff --git a/M6532/inc/M6532.h b/M6532/inc/M6532.h index 50a32e8..26c8c59 100644 --- a/M6532/inc/M6532.h +++ b/M6532/inc/M6532.h @@ -2,7 +2,7 @@ #include -#include +#include /* PIA 6532 combined timer, IO and 128 bytes RAM @@ -177,7 +177,7 @@ namespace EightBit { - class M6532 final : public Chip { + class M6532 final : public ClockedChip { public: M6532() noexcept; virtual ~M6532() = default; diff --git a/MC6809/test/Board.cpp b/MC6809/test/Board.cpp index c925554..8b86e34 100644 --- a/MC6809/test/Board.cpp +++ b/MC6809/test/Board.cpp @@ -118,7 +118,9 @@ void Board::updateAciaPins(const EightBit::Chip::PinLevel rw) { bool Board::accessAcia() { ACIA().raise(ACIA().E()); - const bool accessed = ACIA().tick(); + const bool activated = ACIA().activated(); + if (activated) + ACIA().step(); ACIA().lower(ACIA().E()); - return accessed; + return activated; } diff --git a/MC6850/inc/MC6850.h b/MC6850/inc/MC6850.h index 0bae324..2447e17 100644 --- a/MC6850/inc/MC6850.h +++ b/MC6850/inc/MC6850.h @@ -2,12 +2,14 @@ #include -#include +#include #include namespace EightBit { - class mc6850 : public Chip { + class mc6850 final : public ClockedChip { public: + void powerOn() final; + // +--------+----------------------------------------------------------------------------------+ // | | Buffer address | // | +------------------+------------------+--------------------+-----------------------+ @@ -242,8 +244,9 @@ namespace EightBit { // Receive data register; auto& RDR() { return m_RDR; } - bool tick(); + void step(); + bool activated() { return powered() && raised(E()) && selected(); } bool selected(); void markTransmitComplete(); @@ -318,6 +321,7 @@ namespace EightBit { uint8_t m_TDR = 0; uint8_t m_RDR = 0; - bool m_powered = false; + enum StartupCondition { ColdStart, WarmStart, Unknown }; + StartupCondition m_startup = WarmStart; }; } diff --git a/MC6850/src/MC6850.cpp b/MC6850/src/MC6850.cpp index b9b7c6c..2fa2e81 100644 Binary files a/MC6850/src/MC6850.cpp and b/MC6850/src/MC6850.cpp differ diff --git a/inc/ClockedChip.h b/inc/ClockedChip.h new file mode 100644 index 0000000..564f733 --- /dev/null +++ b/inc/ClockedChip.h @@ -0,0 +1,24 @@ +#pragma once + +#include "Chip.h" +#include "EventArgs.h" +#include "Signal.h" + +namespace EightBit { + class ClockedChip : public Chip { + public: + ~ClockedChip() {}; + + Signal Ticked; + + [[nodiscard]] auto cycles() const noexcept { return m_cycles; } + + protected: + void resetCycles() noexcept { m_cycles = 0; } + void tick(const int extra) { for (int i = 0; i < extra; ++i) tick(); } + void tick() { ++m_cycles; Ticked.fire(EventArgs::empty()); } + + private: + int m_cycles = 0; + }; +} diff --git a/inc/Processor.h b/inc/Processor.h index fdd2628..7db829e 100644 --- a/inc/Processor.h +++ b/inc/Processor.h @@ -2,15 +2,14 @@ #include -#include "Chip.h" +#include "ClockedChip.h" #include "Bus.h" #include "Register.h" -#include "Signal.h" #include "EightBitCompilerDefinitions.h" namespace EightBit { - class Processor : public Chip { + class Processor : public ClockedChip { public: // b: number of bits representing the number in x // x: sign extend this b-bit number to r @@ -18,8 +17,6 @@ namespace EightBit { ~Processor() {}; - Signal Ticked; - [[nodiscard]] auto& PC() noexcept { return m_pc; } [[nodiscard]] auto& RESET() noexcept { return m_resetLine; } @@ -35,8 +32,6 @@ namespace EightBit { virtual int execute() = 0; int execute(uint8_t value); - [[nodiscard]] auto cycles() const noexcept { return m_cycles; } - [[nodiscard]] virtual register16_t peekWord(register16_t address) = 0; virtual void pokeWord(register16_t address, register16_t value) = 0; @@ -108,14 +103,9 @@ namespace EightBit { virtual void ret(); - void resetCycles() noexcept { m_cycles = 0; } - void tick(const int extra) { for (int i = 0; i < extra; ++i) tick(); } - void tick() { ++m_cycles; Ticked.fire(EventArgs::empty()); } - private: Bus& m_bus; uint8_t m_opcode = Mask8; - int m_cycles = 0; register16_t m_pc; PinLevel m_intLine = PinLevel::Low; diff --git a/src/EightBit.vcxproj b/src/EightBit.vcxproj index 0030416..01ac42a 100644 --- a/src/EightBit.vcxproj +++ b/src/EightBit.vcxproj @@ -145,6 +145,7 @@ + diff --git a/src/EightBit.vcxproj.filters b/src/EightBit.vcxproj.filters index 0641168..e32659c 100644 --- a/src/EightBit.vcxproj.filters +++ b/src/EightBit.vcxproj.filters @@ -71,6 +71,9 @@ Header Files + + Header Files +