mirror of
https://github.com/TomHarte/CLK.git
synced 2024-08-16 16:28:59 +00:00
Merge pull request #309 from TomHarte/ROMSafety
Ensures all vectors loaded from disk are the expected size.
This commit is contained in:
commit
573a9c6fb2
@ -931,7 +931,8 @@ class ConcreteMachine:
|
||||
|
||||
// See header; provides the system ROMs.
|
||||
void set_rom(ROMType type, const std::vector<uint8_t> &data) {
|
||||
roms_[static_cast<int>(type)] = data;
|
||||
roms_[static_cast<int>(type)] = std::move(data);
|
||||
roms_[static_cast<int>(type)].resize(16384);
|
||||
}
|
||||
|
||||
// Obtains the system ROMs.
|
||||
|
@ -335,8 +335,14 @@ class ConcreteMachine:
|
||||
for(std::size_t index = 0; index < roms.size(); ++index) {
|
||||
auto &data = roms[index];
|
||||
if(!data) return false;
|
||||
if(index < 9) roms_[index] = *data; else basic_rom_ = *data;
|
||||
if(index < 9) roms_[index] = std::move(*data); else basic_rom_ = std::move(*data);
|
||||
}
|
||||
|
||||
// Characters ROMs should be 4kb.
|
||||
for(std::size_t index = 0; index < 4; ++index) roms_[index].resize(4096);
|
||||
// Kernel ROMs and the BASIC ROM should be 8kb.
|
||||
for(std::size_t index = 4; index < roms.size(); ++index) roms_[index].resize(8192);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -204,18 +204,6 @@ class ConcreteMachine:
|
||||
Memory::Fuzz(ram_, sizeof(ram_));
|
||||
}
|
||||
|
||||
void set_rom(ROM rom, const std::vector<uint8_t> &data) {
|
||||
switch(rom) {
|
||||
case BASIC11: basic11_rom_ = std::move(data); break;
|
||||
case BASIC10: basic10_rom_ = std::move(data); break;
|
||||
case Microdisc: microdisc_rom_ = std::move(data); break;
|
||||
case Colour:
|
||||
colour_rom_ = std::move(data);
|
||||
if(video_output_) video_output_->set_colour_rom(colour_rom_);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Obtains the system ROMs.
|
||||
bool set_rom_fetcher(const std::function<std::vector<std::unique_ptr<std::vector<uint8_t>>>(const std::string &machine, const std::vector<std::string> &names)> &roms_with_names) override {
|
||||
auto roms = roms_with_names(
|
||||
@ -226,11 +214,21 @@ class ConcreteMachine:
|
||||
});
|
||||
|
||||
for(std::size_t index = 0; index < roms.size(); ++index) {
|
||||
auto &data = roms[index];
|
||||
if(!data) return false;
|
||||
set_rom(static_cast<ROM>(index), *data);
|
||||
if(!roms[index]) return false;
|
||||
}
|
||||
|
||||
basic10_rom_ = std::move(*roms[0]);
|
||||
basic11_rom_ = std::move(*roms[1]);
|
||||
microdisc_rom_ = std::move(*roms[2]);
|
||||
colour_rom_ = std::move(*roms[3]);
|
||||
|
||||
basic10_rom_.resize(16384);
|
||||
basic11_rom_.resize(16384);
|
||||
microdisc_rom_.resize(8192);
|
||||
colour_rom_.resize(128);
|
||||
|
||||
if(video_output_) video_output_->set_colour_rom(colour_rom_);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -297,13 +297,6 @@ template<bool is_zx81> class ConcreteMachine:
|
||||
Utility::TypeRecipient::set_typer_for_string(string, std::move(mapper));
|
||||
}
|
||||
|
||||
void set_rom(ROMType type, const std::vector<uint8_t> &data) {
|
||||
switch(type) {
|
||||
case ZX80: zx80_rom_ = data; break;
|
||||
case ZX81: zx81_rom_ = data; break;
|
||||
}
|
||||
}
|
||||
|
||||
// Obtains the system ROMs.
|
||||
bool set_rom_fetcher(const std::function<std::vector<std::unique_ptr<std::vector<uint8_t>>>(const std::string &machine, const std::vector<std::string> &names)> &roms_with_names) override {
|
||||
auto roms = roms_with_names(
|
||||
@ -313,11 +306,14 @@ template<bool is_zx81> class ConcreteMachine:
|
||||
});
|
||||
|
||||
for(std::size_t index = 0; index < roms.size(); ++index) {
|
||||
auto &data = roms[index];
|
||||
if(!data) return false;
|
||||
set_rom(static_cast<ROMType>(index), *data);
|
||||
if(!roms[index]) return false;
|
||||
}
|
||||
|
||||
zx80_rom_ = std::move(*roms[0]);
|
||||
zx81_rom_ = std::move(*roms[1]);
|
||||
zx80_rom_.resize(4096);
|
||||
zx81_rom_.resize(8192);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user