2019-07-24 22:19:43 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
2019-09-05 14:42:19 +02:00
|
|
|
#include "../os.h"
|
2019-07-24 22:19:43 +02:00
|
|
|
|
|
|
|
namespace lightSwitch::loader {
|
|
|
|
class Loader {
|
|
|
|
protected:
|
2019-09-05 14:42:19 +02:00
|
|
|
std::string file_path; //!< The path to the ROM file
|
|
|
|
std::ifstream file; //!< An input stream from the file
|
2019-07-24 22:19:43 +02:00
|
|
|
|
2019-09-05 14:42:19 +02:00
|
|
|
/**
|
|
|
|
* Read the file at a particular offset
|
|
|
|
* @tparam T The type of object to write to
|
|
|
|
* @param output The object to write to
|
|
|
|
* @param offset The offset to read the file at
|
|
|
|
* @param size The amount to read in bytes
|
|
|
|
*/
|
2019-07-24 22:19:43 +02:00
|
|
|
template<typename T>
|
|
|
|
void ReadOffset(T *output, uint32_t offset, size_t size) {
|
|
|
|
file.seekg(offset, std::ios_base::beg);
|
|
|
|
file.read(reinterpret_cast<char *>(output), size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
2019-09-05 14:42:19 +02:00
|
|
|
/**
|
|
|
|
* @param file_path_ The path to the ROM file
|
|
|
|
*/
|
|
|
|
Loader(std::string &file_path) : file_path(file_path), file(file_path, std::ios::binary | std::ios::beg) {}
|
2019-07-24 22:19:43 +02:00
|
|
|
};
|
2019-09-05 14:42:19 +02:00
|
|
|
}
|