2017-09-06 13:22:23 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
#include "Signal.h"
|
|
|
|
#include "Register.h"
|
|
|
|
|
|
|
|
namespace EightBit {
|
|
|
|
class Bus {
|
|
|
|
public:
|
2017-11-10 22:41:50 +00:00
|
|
|
virtual ~Bus() = default;
|
2017-09-06 13:22:23 +01:00
|
|
|
|
2017-09-13 23:12:47 +01:00
|
|
|
Signal<uint16_t> WrittenByte;
|
|
|
|
Signal<uint16_t> ReadingByte;
|
2017-09-06 13:22:23 +01:00
|
|
|
|
2017-11-10 22:41:50 +00:00
|
|
|
register16_t& ADDRESS();
|
|
|
|
uint8_t& DATA();
|
2017-09-06 13:22:23 +01:00
|
|
|
|
2017-11-10 22:41:50 +00:00
|
|
|
uint8_t& placeDATA(uint8_t value);
|
|
|
|
uint8_t& referenceDATA(uint8_t& value);
|
2017-09-06 13:22:23 +01:00
|
|
|
|
2017-11-10 22:41:50 +00:00
|
|
|
uint8_t peek(uint16_t address);
|
|
|
|
void poke(uint16_t address, uint8_t value);
|
2017-09-06 13:22:23 +01:00
|
|
|
|
2017-11-10 22:41:50 +00:00
|
|
|
uint16_t peekWord(uint16_t address);
|
2017-09-06 13:22:23 +01:00
|
|
|
|
2017-11-10 22:41:50 +00:00
|
|
|
uint8_t read();
|
|
|
|
uint8_t read(uint16_t offset);
|
|
|
|
uint8_t read(register16_t address);
|
2017-09-06 13:22:23 +01:00
|
|
|
|
2017-11-10 22:41:50 +00:00
|
|
|
void write(uint8_t value);
|
|
|
|
void write(uint16_t offset, uint8_t value);
|
|
|
|
void write(register16_t address, uint8_t value);
|
2017-09-06 13:22:23 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual uint8_t& reference(uint16_t address, bool& rom) = 0;
|
2017-11-10 22:41:50 +00:00
|
|
|
uint8_t& reference();
|
2017-09-06 13:22:23 +01:00
|
|
|
|
|
|
|
private:
|
2017-11-10 22:41:50 +00:00
|
|
|
uint8_t* m_data = nullptr;
|
2017-11-30 16:55:10 +00:00
|
|
|
register16_t m_address{ { 0xff, 0xff } };
|
2017-11-10 22:41:50 +00:00
|
|
|
uint8_t m_temporary = 0xff; // Used to simulate ROM
|
2017-09-06 13:22:23 +01:00
|
|
|
};
|
2017-11-30 23:19:17 +00:00
|
|
|
}
|