1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-09-30 07:55:01 +00:00

Colocate memory.

This commit is contained in:
Thomas Harte 2023-11-16 15:24:35 -05:00
parent 095359017f
commit 99e7de5a8b

View File

@ -16,6 +16,8 @@
#include "../ScanProducer.hpp" #include "../ScanProducer.hpp"
#include "../TimedMachine.hpp" #include "../TimedMachine.hpp"
#include <array>
namespace PCCompatible { namespace PCCompatible {
struct Registers { struct Registers {
@ -113,15 +115,13 @@ class Segments {
const Registers &registers_; const Registers &registers_;
}; };
// TODO: send writes to the ROM area off to nowhere.
struct Memory { struct Memory {
public: public:
using AccessType = InstructionSet::x86::AccessType; using AccessType = InstructionSet::x86::AccessType;
// Constructor. // Constructor.
Memory(Registers &registers, const Segments &segments) : registers_(registers), segments_(segments) { Memory(Registers &registers, const Segments &segments) : registers_(registers), segments_(segments) {}
memory.resize(1024*1024);
std::fill(memory.begin(), memory.end(), 0xff);
}
// //
// Preauthorisation call-ins. Since only an 8088 is currently modelled, all accesses are implicitly authorised. // Preauthorisation call-ins. Since only an 8088 is currently modelled, all accesses are implicitly authorised.
@ -154,13 +154,6 @@ struct Memory {
// Accesses an address based on physical location. // Accesses an address based on physical location.
template <typename IntT, AccessType type> template <typename IntT, AccessType type>
typename InstructionSet::x86::Accessor<IntT, type>::type access(uint32_t address) { typename InstructionSet::x86::Accessor<IntT, type>::type access(uint32_t address) {
// TODO: send writes to the ROM area off to nowhere.
// if constexpr (is_writeable(type)) {
// if(address >= 0xc'0000) {
//
// }
// }
// Dispense with the single-byte case trivially. // Dispense with the single-byte case trivially.
if constexpr (std::is_same_v<IntT, uint8_t>) { if constexpr (std::is_same_v<IntT, uint8_t>) {
return memory[address]; return memory[address];
@ -229,11 +222,11 @@ struct Memory {
// Population. // Population.
// //
void install(size_t address, const uint8_t *data, size_t length) { void install(size_t address, const uint8_t *data, size_t length) {
std::copy(data, data + length, memory.begin() + address); std::copy(data, data + length, memory.begin() + std::vector<uint8_t>::difference_type(address));
} }
private: private:
std::vector<uint8_t> memory; std::array<uint8_t, 1024*1024> memory{0xff};
Registers &registers_; Registers &registers_;
const Segments &segments_; const Segments &segments_;