2017-06-04 20:38:34 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
2017-09-01 15:41:50 +00:00
|
|
|
|
2020-02-09 11:51:58 +00:00
|
|
|
#include "Memory.h"
|
|
|
|
#include "Ram.h"
|
2017-06-04 20:38:34 +00:00
|
|
|
|
|
|
|
namespace EightBit {
|
2020-02-09 11:51:58 +00:00
|
|
|
class InputOutput final : public Memory {
|
2017-06-04 20:38:34 +00:00
|
|
|
public:
|
2020-02-09 11:51:58 +00:00
|
|
|
enum class AccessType { Unknown, Reading, Writing };
|
|
|
|
|
2022-01-03 12:29:32 +00:00
|
|
|
[[nodiscard]] uint16_t size() const noexcept override;
|
2021-07-18 13:28:40 +00:00
|
|
|
[[nodiscard]] uint8_t peek(uint16_t address) const noexcept override;
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2021-07-18 13:28:40 +00:00
|
|
|
[[nodiscard]] uint8_t& reference(uint16_t address) noexcept override;
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2020-02-09 11:51:58 +00:00
|
|
|
int load(std::ifstream& file, int writeOffset = 0, int readOffset = 0, int limit = -1) override;
|
2020-11-07 09:41:12 +00:00
|
|
|
int load(std::string path, int writeOffset = 0, int readOffset = 0, int limit = -1) override;
|
2020-02-09 11:51:58 +00:00
|
|
|
int load(const std::vector<uint8_t>& bytes, int writeOffset = 0, int readOffset = 0, int limit = -1) override;
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2021-07-18 13:28:40 +00:00
|
|
|
[[nodiscard]] constexpr const auto& accessType() const noexcept { return m_access; }
|
|
|
|
[[nodiscard]] constexpr auto& accessType() noexcept { return m_access; }
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2021-07-18 13:28:40 +00:00
|
|
|
[[nodiscard]] auto readPort(uint8_t port, AccessType access) noexcept {
|
2020-12-27 15:46:05 +00:00
|
|
|
accessType() = access;
|
2020-02-09 11:51:58 +00:00
|
|
|
return reference(port);
|
|
|
|
}
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2021-07-18 13:28:40 +00:00
|
|
|
[[nodiscard]] auto readInputPort(uint8_t port) noexcept { return readPort(port, AccessType::Reading); }
|
|
|
|
[[nodiscard]] auto readOutputPort(uint8_t port) noexcept { return readPort(port, AccessType::Writing); }
|
2020-02-09 11:51:58 +00:00
|
|
|
|
2021-07-18 13:28:40 +00:00
|
|
|
void writePort(uint8_t port, uint8_t value, AccessType access) noexcept {
|
2020-12-27 15:46:05 +00:00
|
|
|
accessType() = access;
|
2020-02-09 11:51:58 +00:00
|
|
|
reference(port) = value;
|
|
|
|
}
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2021-07-18 13:28:40 +00:00
|
|
|
void writeInputPort(uint8_t port, uint8_t value) noexcept { writePort(port, value, AccessType::Reading); }
|
|
|
|
void writeOutputPort(uint8_t port, uint8_t value) noexcept { writePort(port, value, AccessType::Writing); }
|
2020-02-09 11:51:58 +00:00
|
|
|
|
|
|
|
protected:
|
2021-07-18 13:28:40 +00:00
|
|
|
void poke(uint16_t address, uint8_t value) noexcept override;
|
2017-06-04 20:38:34 +00:00
|
|
|
|
|
|
|
private:
|
2020-02-09 11:51:58 +00:00
|
|
|
Ram m_input = 0x100;
|
|
|
|
Ram m_output = 0x100;
|
2021-07-18 13:28:40 +00:00
|
|
|
uint8_t m_delivered = 0xff;
|
2020-02-09 11:51:58 +00:00
|
|
|
|
|
|
|
AccessType m_access = AccessType::Unknown;
|
2017-06-04 20:38:34 +00:00
|
|
|
};
|
2017-11-30 23:19:17 +00:00
|
|
|
}
|