2017-06-04 21:38:34 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
2017-09-01 16:41:50 +01:00
|
|
|
#include <array>
|
|
|
|
|
2020-02-09 11:51:58 +00:00
|
|
|
#include "Memory.h"
|
|
|
|
#include "Ram.h"
|
2017-06-04 21:38:34 +01:00
|
|
|
|
|
|
|
namespace EightBit {
|
2020-02-09 11:51:58 +00:00
|
|
|
class InputOutput final : public Memory {
|
2017-06-04 21:38:34 +01:00
|
|
|
public:
|
2020-02-09 11:51:58 +00:00
|
|
|
enum class AccessType { Unknown, Reading, Writing };
|
|
|
|
|
2020-04-06 23:11:21 +01:00
|
|
|
[[nodiscard]] size_t size() const noexcept override;
|
2020-02-09 11:51:58 +00:00
|
|
|
[[nodiscard]] uint8_t peek(uint16_t address) const override;
|
2017-06-04 21:38:34 +01:00
|
|
|
|
2020-02-09 11:51:58 +00:00
|
|
|
[[nodiscard]] uint8_t& reference(uint16_t address) override;
|
2017-06-04 21:38:34 +01:00
|
|
|
|
2020-02-09 11:51:58 +00:00
|
|
|
int load(std::ifstream& file, int writeOffset = 0, int readOffset = 0, int limit = -1) override;
|
|
|
|
int load(const std::string& path, int writeOffset = 0, int readOffset = 0, int limit = -1) override;
|
|
|
|
int load(const std::vector<uint8_t>& bytes, int writeOffset = 0, int readOffset = 0, int limit = -1) override;
|
2017-06-04 21:38:34 +01:00
|
|
|
|
2020-02-09 11:51:58 +00:00
|
|
|
AccessType getAccessType() const noexcept { return m_access; }
|
|
|
|
void setAccessType(AccessType value) noexcept { m_access = value; }
|
2017-06-04 21:38:34 +01:00
|
|
|
|
2020-02-09 11:51:58 +00:00
|
|
|
auto readPort(uint8_t port, AccessType access) {
|
|
|
|
setAccessType(access);
|
|
|
|
return reference(port);
|
|
|
|
}
|
2017-06-04 21:38:34 +01:00
|
|
|
|
2020-02-09 11:51:58 +00:00
|
|
|
auto readInputPort(uint8_t port) { return readPort(port, AccessType::Reading); }
|
|
|
|
auto readOutputPort(uint8_t port) { return readPort(port, AccessType::Writing); }
|
|
|
|
|
|
|
|
void writePort(uint8_t port, uint8_t value, AccessType access) {
|
|
|
|
setAccessType(access);
|
|
|
|
reference(port) = value;
|
|
|
|
}
|
2017-06-04 21:38:34 +01:00
|
|
|
|
2020-02-09 11:51:58 +00:00
|
|
|
auto writeInputPort(uint8_t port, uint8_t value) { return writePort(port, value, AccessType::Reading); }
|
|
|
|
auto writeOutputPort(uint8_t port, uint8_t value) { return writePort(port, value, AccessType::Writing); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void poke(uint16_t address, uint8_t value) override;
|
2017-06-04 21:38:34 +01:00
|
|
|
|
|
|
|
private:
|
2020-02-09 11:51:58 +00:00
|
|
|
Ram m_input = 0x100;
|
|
|
|
Ram m_output = 0x100;
|
|
|
|
|
|
|
|
AccessType m_access = AccessType::Unknown;
|
2017-06-04 21:38:34 +01:00
|
|
|
};
|
2017-11-30 23:19:17 +00:00
|
|
|
}
|