Created
February 26, 2018 13:11
-
-
Save pedrovanzella/808ba39310f3b21a7e099b18bf6c1bd5 to your computer and use it in GitHub Desktop.
operator[]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ROM { | |
public: | |
ROM(std::array<uint8_t, 1024> buf) { _buffer = std::move(buf); } | |
const uint16_t operator[](const uint16_t offset) const { | |
if (offset > _buffer.size()) { | |
return 0x0; | |
} | |
// This is a big-endian machine, indexed by 16-bit words | |
return (_buffer[offset] << 8) + (_buffer[offset + 1]); | |
} | |
private: | |
std::array<uint8_t, 1024> _buffer; | |
} | |
class Memory { | |
public: | |
Memory(ROM rom) { | |
_ram.fill(0); | |
_rom = std::move(rom); | |
} | |
// operator[]?? | |
// Say we have an instance called mem | |
// mem[0x200] should return _rom[0x0] and be read-only | |
// mem[0x602] or higher should return _ram[0x602] or higher and be read-write. | |
private: | |
ROM _rom; | |
std::array<uint8_t, 2560> _ram; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment