2017-09-06 12:22:23 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
2018-09-15 13:35:59 +00:00
|
|
|
#include <string>
|
2017-09-06 12:22:23 +00:00
|
|
|
|
2018-11-16 23:49:52 +00:00
|
|
|
#include "Chip.h"
|
2017-09-06 12:22:23 +00:00
|
|
|
#include "Signal.h"
|
|
|
|
#include "Register.h"
|
2018-06-10 21:00:52 +00:00
|
|
|
#include "EventArgs.h"
|
2018-12-29 19:17:36 +00:00
|
|
|
#include "Mapper.h"
|
2017-09-06 12:22:23 +00:00
|
|
|
|
|
|
|
namespace EightBit {
|
2018-12-29 19:17:36 +00:00
|
|
|
class Bus : public Mapper {
|
2017-09-06 12:22:23 +00:00
|
|
|
public:
|
2017-11-10 22:41:50 +00:00
|
|
|
virtual ~Bus() = default;
|
2017-09-06 12:22:23 +00:00
|
|
|
|
2018-06-10 21:00:52 +00:00
|
|
|
Signal<EventArgs> WritingByte;
|
|
|
|
Signal<EventArgs> WrittenByte;
|
2018-02-07 23:00:38 +00:00
|
|
|
|
2018-06-10 21:00:52 +00:00
|
|
|
Signal<EventArgs> ReadingByte;
|
|
|
|
Signal<EventArgs> ReadByte;
|
2017-09-06 12:22:23 +00:00
|
|
|
|
2018-11-29 00:09:40 +00:00
|
|
|
[[nodiscard]] auto ADDRESS() const noexcept { return m_address; }
|
|
|
|
[[nodiscard]] auto& ADDRESS() noexcept { return m_address; }
|
2018-08-12 16:08:03 +00:00
|
|
|
|
2018-11-29 00:09:40 +00:00
|
|
|
[[nodiscard]] auto DATA() const noexcept { return m_data; }
|
|
|
|
[[nodiscard]] auto& DATA() noexcept { return m_data; }
|
2017-09-06 12:22:23 +00:00
|
|
|
|
2018-11-29 00:09:40 +00:00
|
|
|
[[nodiscard]] auto peek() { return reference(); }
|
|
|
|
[[nodiscard]] auto peek(const uint16_t address) { return reference(address); }
|
|
|
|
[[nodiscard]] auto peek(const register16_t address) { return reference(address.word); }
|
2018-09-20 23:16:00 +00:00
|
|
|
void poke(const uint8_t value) { reference() = value; }
|
|
|
|
void poke(const uint16_t address, const uint8_t value) { reference(address) = value; }
|
|
|
|
void poke(const register16_t address, const uint8_t value) { reference(address.word) = value; }
|
2017-09-06 12:22:23 +00:00
|
|
|
|
2018-11-29 00:09:40 +00:00
|
|
|
[[nodiscard]] uint8_t read();
|
|
|
|
template<class T> [[nodiscard]] auto read(const T address) {
|
2018-06-15 23:55:32 +00:00
|
|
|
ADDRESS() = address;
|
|
|
|
return read();
|
|
|
|
}
|
2017-09-06 12:22:23 +00:00
|
|
|
|
2018-06-09 23:40:56 +00:00
|
|
|
void write();
|
2017-11-10 22:41:50 +00:00
|
|
|
void write(uint8_t value);
|
2018-06-15 23:55:32 +00:00
|
|
|
template<class T> void write(const T offset, const uint8_t value) {
|
|
|
|
ADDRESS() = offset;
|
|
|
|
write(value);
|
|
|
|
}
|
2017-09-06 12:22:23 +00:00
|
|
|
|
2019-01-14 02:10:17 +00:00
|
|
|
virtual void raisePOWER();
|
|
|
|
virtual void lowerPOWER();
|
2018-11-11 16:48:44 +00:00
|
|
|
|
|
|
|
virtual void initialise() = 0;
|
|
|
|
|
2019-01-14 02:10:17 +00:00
|
|
|
protected:
|
2018-11-29 00:09:40 +00:00
|
|
|
[[nodiscard]] uint8_t& reference(uint16_t address);
|
|
|
|
[[nodiscard]] auto& reference(const register16_t address) { return reference(address.word); }
|
|
|
|
[[nodiscard]] uint8_t& reference() { return reference(ADDRESS()); }
|
2017-09-06 12:22:23 +00:00
|
|
|
|
2018-09-15 13:35:59 +00:00
|
|
|
void loadHexFile(std::string path);
|
|
|
|
|
2017-09-06 12:22:23 +00:00
|
|
|
private:
|
2018-11-16 23:49:52 +00:00
|
|
|
uint8_t m_data = Chip::Mask8;
|
|
|
|
register16_t m_address = Chip::Mask16;
|
2017-09-06 12:22:23 +00:00
|
|
|
};
|
2017-11-30 23:19:17 +00:00
|
|
|
}
|