2016-08-29 12:48:49 +00:00
|
|
|
//
|
|
|
|
// BinaryDump.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 28/08/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-08-29 12:48:49 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "BinaryDump.hpp"
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
using namespace Storage::Cartridge;
|
|
|
|
|
2018-04-06 21:42:24 +00:00
|
|
|
BinaryDump::BinaryDump(const std::string &file_name) {
|
2016-08-29 12:48:49 +00:00
|
|
|
// the file should be exactly 16 kb
|
|
|
|
struct stat file_stats;
|
2018-04-06 21:42:24 +00:00
|
|
|
stat(file_name.c_str(), &file_stats);
|
2016-08-29 12:48:49 +00:00
|
|
|
|
|
|
|
// grab contents
|
2018-04-06 21:42:24 +00:00
|
|
|
FILE *file = std::fopen(file_name.c_str(), "rb");
|
2016-08-29 12:48:49 +00:00
|
|
|
if(!file) throw ErrorNotAccessible;
|
2017-11-11 20:28:40 +00:00
|
|
|
std::size_t data_length = static_cast<std::size_t>(file_stats.st_size);
|
2016-08-29 12:48:49 +00:00
|
|
|
std::vector<uint8_t> contents(data_length);
|
2017-11-12 22:46:06 +00:00
|
|
|
contents.resize(std::fread(&contents[0], 1, static_cast<std::size_t>(data_length), file));
|
|
|
|
std::fclose(file);
|
2016-08-29 12:48:49 +00:00
|
|
|
|
|
|
|
// enshrine
|
2016-12-03 16:59:28 +00:00
|
|
|
segments_.emplace_back(
|
2016-08-29 12:48:49 +00:00
|
|
|
::Storage::Cartridge::Cartridge::Segment::UnknownAddress,
|
|
|
|
::Storage::Cartridge::Cartridge::Segment::UnknownAddress,
|
|
|
|
std::move(contents));
|
|
|
|
}
|