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