2019-07-06 21:44:42 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
2021-01-06 15:30:26 +00:00
|
|
|
#include <fstream>
|
2019-07-06 21:44:42 +00:00
|
|
|
#include <string>
|
2021-01-06 15:30:26 +00:00
|
|
|
#include <ios>
|
|
|
|
#include <sstream>
|
2019-07-06 21:44:42 +00:00
|
|
|
#include <map>
|
|
|
|
#include <optional>
|
|
|
|
#include <vector>
|
2021-01-06 15:30:26 +00:00
|
|
|
#include <utility>
|
2019-07-06 21:44:42 +00:00
|
|
|
|
|
|
|
namespace EightBit {
|
2020-05-02 10:36:43 +00:00
|
|
|
class IntelHexFile final {
|
2019-07-06 21:44:42 +00:00
|
|
|
public:
|
|
|
|
IntelHexFile(std::string path);
|
|
|
|
|
|
|
|
[[nodiscard]] std::map<uint16_t, std::vector<uint8_t>> parse();
|
|
|
|
|
|
|
|
private:
|
|
|
|
[[nodiscard]] std::optional<std::pair<uint16_t, std::vector<uint8_t>>> parse(std::string line);
|
|
|
|
[[nodiscard]] std::vector<uint8_t> parseDataRecord(std::string line, uint8_t count);
|
|
|
|
|
2021-01-02 11:49:34 +00:00
|
|
|
template <class T> [[nodiscard]] T fromHex(std::string input) {
|
2019-07-06 21:44:42 +00:00
|
|
|
std::istringstream converter(input);
|
|
|
|
unsigned output;
|
|
|
|
converter >> std::hex >> output;
|
|
|
|
return static_cast<T>(output);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ifstream m_file;
|
|
|
|
bool m_eof;
|
|
|
|
};
|
|
|
|
}
|