merged
This commit is contained in:
parent
18a14d204c
commit
717568b6d0
30 changed files with 4093 additions and 209 deletions
68
simulator_SIC_XE/include/loader.h
Normal file
68
simulator_SIC_XE/include/loader.h
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
#ifndef LOADER_H
|
||||
#define LOADER_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "file_reader.h"
|
||||
#include <stdexcept>
|
||||
|
||||
class Machine;
|
||||
|
||||
using std::shared_ptr;
|
||||
using std::string;
|
||||
|
||||
|
||||
class Loader {
|
||||
public:
|
||||
Loader( shared_ptr<Machine> machine, string filename) : _machine(machine), _filename(filename) {
|
||||
_file_reader = std::make_shared<FileReader>(filename, std::ios::in);
|
||||
if (!_file_reader->good()) {
|
||||
throw std::runtime_error("Loader: failed to open file: " + filename);
|
||||
}
|
||||
}
|
||||
~Loader();
|
||||
|
||||
|
||||
enum class RecordType {
|
||||
HEADER,
|
||||
TEXT,
|
||||
END,
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
struct HeaderMetadata {
|
||||
string program_name;
|
||||
int start_address;
|
||||
int length;
|
||||
};
|
||||
struct TextRecord {
|
||||
int start_address;
|
||||
std::vector<uint8_t> data;
|
||||
};
|
||||
struct EndRecord {
|
||||
int execution_start_address;
|
||||
};
|
||||
|
||||
void load();
|
||||
|
||||
private :
|
||||
|
||||
static RecordType parseRecordType(char c);
|
||||
|
||||
|
||||
shared_ptr<Machine> _machine;
|
||||
string _filename;
|
||||
shared_ptr<FileReader> _file_reader;
|
||||
HeaderMetadata readHeader();
|
||||
TextRecord readTextRecord();
|
||||
EndRecord readEndRecord();
|
||||
bool load_into_memory(int start_address, const std::vector<uint8_t>& data);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // LOADER_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue