Try to remove some casting warnings by redefining ROM size types.

This commit is contained in:
Adrian Conlon 2022-01-03 12:29:32 +00:00
parent 53ef92dbc4
commit 70a785b5c2
7 changed files with 13 additions and 11 deletions

View File

@ -10,7 +10,7 @@ namespace EightBit {
public:
enum class AccessType { Unknown, Reading, Writing };
[[nodiscard]] size_t size() const noexcept override;
[[nodiscard]] uint16_t size() const noexcept override;
[[nodiscard]] uint8_t peek(uint16_t address) const noexcept override;
[[nodiscard]] uint8_t& reference(uint16_t address) noexcept override;

View File

@ -16,7 +16,7 @@ namespace EightBit {
public:
virtual ~Memory() {};
[[nodiscard]] virtual size_t size() const noexcept = 0;
[[nodiscard]] virtual uint16_t size() const noexcept = 0;
[[nodiscard]] virtual uint8_t peek(uint16_t address) const noexcept = 0;
[[nodiscard]] virtual uint8_t& reference(uint16_t) noexcept;

View File

@ -30,7 +30,7 @@ namespace EightBit {
Rom& operator=(const Rom& rhs);
bool operator==(const Rom& rhs) const;
[[nodiscard]] size_t size() const noexcept final;
[[nodiscard]] uint16_t size() const noexcept final;
int load(std::ifstream& file, int writeOffset = 0, int readOffset = 0, int limit = -1) final;
int load(std::string path, int writeOffset = 0, int readOffset = 0, int limit = -1) final;

View File

@ -13,10 +13,10 @@ namespace EightBit {
// is being read.
class UnusedMemory final : public Memory {
public:
UnusedMemory(size_t size, uint8_t value) noexcept;
UnusedMemory(uint16_t size, uint8_t value) noexcept;
~UnusedMemory() = default;
[[nodiscard]] size_t size() const noexcept final;
[[nodiscard]] uint16_t size() const noexcept final;
[[nodiscard]] uint8_t peek(uint16_t address) const noexcept final;
int load(std::ifstream& file, int writeOffset = 0, int readOffset = 0, int limit = -1) final;
@ -27,7 +27,7 @@ namespace EightBit {
void poke(uint16_t address, uint8_t value) noexcept final;
private:
size_t m_size;
uint16_t m_size;
uint8_t m_value;
};
}

View File

@ -6,7 +6,7 @@
#include "../inc/Register.h"
size_t EightBit::InputOutput::size() const noexcept {
uint16_t EightBit::InputOutput::size() const noexcept {
return 0x100;
}

View File

@ -57,8 +57,10 @@ EightBit::Rom& EightBit::Rom::operator=(const Rom& rhs) {
return *this;
}
size_t EightBit::Rom::size() const noexcept {
return m_bytes.size();
uint16_t EightBit::Rom::size() const noexcept {
const auto size = BYTES().size();
assert(size <= 0x10000);
return static_cast<uint16_t>(size);
}
int EightBit::Rom::load(std::ifstream& file, const int writeOffset, const int readOffset, const int limit) {

View File

@ -3,10 +3,10 @@
#include <cassert>
EightBit::UnusedMemory::UnusedMemory(const size_t size, const uint8_t value) noexcept
EightBit::UnusedMemory::UnusedMemory(const uint16_t size, const uint8_t value) noexcept
: m_size(size), m_value(value) {}
size_t EightBit::UnusedMemory::size() const noexcept {
uint16_t EightBit::UnusedMemory::size() const noexcept {
return m_size;
}