Add the concept of a clocked chip

This commit is contained in:
Adrian Conlon 2019-01-10 22:23:51 +00:00
parent 71daf6aa38
commit 9755a5fcd2
8 changed files with 44 additions and 20 deletions

View File

@ -2,7 +2,7 @@
#include <cstdint>
#include <Chip.h>
#include <ClockedChip.h>
/*
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;

View File

@ -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;
}

View File

@ -2,12 +2,14 @@
#include <cstdint>
#include <Chip.h>
#include <ClockedChip.h>
#include <Signal.h>
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;
};
}

Binary file not shown.

24
inc/ClockedChip.h Normal file
View File

@ -0,0 +1,24 @@
#pragma once
#include "Chip.h"
#include "EventArgs.h"
#include "Signal.h"
namespace EightBit {
class ClockedChip : public Chip {
public:
~ClockedChip() {};
Signal<EventArgs> 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;
};
}

View File

@ -2,15 +2,14 @@
#include <cstdint>
#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<EventArgs> 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;

View File

@ -145,6 +145,7 @@
<ClInclude Include="..\inc\BigEndianProcessor.h" />
<ClInclude Include="..\inc\Bus.h" />
<ClInclude Include="..\inc\Chip.h" />
<ClInclude Include="..\inc\ClockedChip.h" />
<ClInclude Include="..\inc\Device.h" />
<ClInclude Include="..\inc\EightBitCompilerDefinitions.h" />
<ClInclude Include="..\inc\EventArgs.h" />

View File

@ -71,6 +71,9 @@
<ClInclude Include="..\inc\Mapper.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\inc\ClockedChip.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">