| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include "MSXException.hh" |
| 5 |
#include "XSAExtractor.hh" |
| 6 |
|
| 7 |
#include <bit> |
| 8 |
#include <cstdint> |
| 9 |
#include <cstdlib> |
| 10 |
#include <fstream> |
| 11 |
#include <iostream> |
| 12 |
#include <span> |
| 13 |
#include <vector> |
| 14 |
|
| 15 |
int main(int argc, const char** argv) |
| 16 |
{ |
| 17 |
auto arg = std::span(argv, argc); |
| 18 |
if (arg.size() != 3) { |
| 19 |
std::cerr << "Usage: xsa2dsk <xsa-input-file> <dsk-output-file>\n"; |
| 20 |
exit(1); |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
std::ifstream in(arg[1], std::ios::binary); |
| 25 |
if (!in.is_open()) { |
| 26 |
std::cerr << "Failed to open: " << arg[1] << '\n'; |
| 27 |
exit(1); |
| 28 |
} |
| 29 |
std::vector<uint8_t> inBuf(std::istreambuf_iterator<char>{in}, |
| 30 |
std::istreambuf_iterator<char>{}); |
| 31 |
|
| 32 |
|
| 33 |
auto sectors = [&] { |
| 34 |
try { |
| 35 |
openmsx::XSAExtractor extractor(inBuf); |
| 36 |
return std::move(extractor).extractData(); |
| 37 |
} catch (openmsx::MSXException& e) { |
| 38 |
std::cerr << "Failed to parse: " << arg[1] << ": " << e.getMessage() << '\n'; |
| 39 |
exit(1); |
| 40 |
} |
| 41 |
}(); |
| 42 |
const uint8_t* dskData = sectors.data()->raw.data(); |
| 43 |
auto dskSize = sectors.size() * sizeof(openmsx::SectorBuffer); |
| 44 |
|
| 45 |
|
| 46 |
std::ofstream out(arg[2], std::ios::binary); |
| 47 |
if (!out.is_open()) { |
| 48 |
std::cerr << "Failed to open: " << arg[2] << '\n'; |
| 49 |
exit(1); |
| 50 |
} |
| 51 |
out.write(std::bit_cast<const char*>(dskData), dskSize); |
| 52 |
} |