74 lines
1.2 KiB
C++
74 lines
1.2 KiB
C++
#include "foot-emulator.h"
|
|
|
|
#include <fstream>
|
|
#include <iostream>
|
|
|
|
namespace
|
|
{
|
|
|
|
std::vector<uint16_t> read_file(std::istream& stream)
|
|
{
|
|
std::vector<uint16_t> buf;
|
|
|
|
std::streampos pos = stream.tellg();
|
|
stream.seekg(0, std::ios::end);
|
|
pos = stream.tellg() - pos;
|
|
buf.resize(pos / 2);
|
|
stream.seekg(0, std::ios::beg);
|
|
|
|
for (int i = 0; i < buf.size(); i++)
|
|
{
|
|
char value[2] = {0, 0};
|
|
stream.read(value, 2);
|
|
buf[i] = (uint16_t(value[0]) << 8) | (uint16_t(value[1]) & 0xFF);
|
|
}
|
|
|
|
return buf;
|
|
}
|
|
|
|
class PrintDevice : public foot::Device
|
|
{
|
|
public:
|
|
PrintDevice() :
|
|
Device(1)
|
|
{
|
|
}
|
|
|
|
void update() override
|
|
{
|
|
uint16_t& value = memory(0);
|
|
if (value != 0)
|
|
{
|
|
std::cout << char(value);
|
|
value = 0;
|
|
}
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
foot::Emulator emu;
|
|
emu.map_device(std::make_unique<PrintDevice>());
|
|
|
|
if (argc > 1)
|
|
{
|
|
std::ifstream file(argv[1], std::ios::binary);
|
|
|
|
if (!file.is_open())
|
|
{
|
|
std::cerr << "Failed to open file: " << argv[1] << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
emu.run(read_file(file));
|
|
}
|
|
else
|
|
{
|
|
std::cout << "Usage: " << argv[0] << " <filename>" << std::endl;
|
|
}
|
|
|
|
return 1;
|
|
}
|