From 2520834b18e64fb2ecb91c41a6894836b15f46e3 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 24 Nov 2019 01:46:02 +0100 Subject: [PATCH] Add the brother240tool program. --- doc/disk-brother.md | 4 +-- mkninja.sh | 7 ++++++ tools/brother240tool.cc | 56 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 tools/brother240tool.cc diff --git a/doc/disk-brother.md b/doc/disk-brother.md index c0992040..88ebb958 100644 --- a/doc/disk-brother.md +++ b/doc/disk-brother.md @@ -129,8 +129,8 @@ reverse engineered it to find out. Standard Linux mtools will access the filesystem image and allow you to move files in and out. However, you'll need to change the media type bytes at -offsets 0x015 and 0x100 from 0x58 to 0xf0 before mtools will touch it. Once -done, this will work: +offsets 0x015 and 0x100 from 0x58 to 0xf0 before mtools will touch it. The +supplied `brother240tool` will do this. Once done, this will work: ``` mdir -i brother.img diff --git a/mkninja.sh b/mkninja.sh index eec4ecc2..272d2276 100644 --- a/mkninja.sh +++ b/mkninja.sh @@ -233,6 +233,13 @@ buildsimpleprogram brother120tool \ libemu.a \ libfmt.a \ +buildsimpleprogram brother240tool \ + -Idep/emu \ + tools/brother240tool.cc \ + libbackend.a \ + libemu.a \ + libfmt.a \ + runtest bitaccumulator-test tests/bitaccumulator.cc runtest bytes-test tests/bytes.cc runtest compression-test tests/compression.cc diff --git a/tools/brother240tool.cc b/tools/brother240tool.cc new file mode 100644 index 00000000..68ef1e8e --- /dev/null +++ b/tools/brother240tool.cc @@ -0,0 +1,56 @@ +#include "globals.h" +#include "fmt/format.h" +#include + +static std::fstream inputFile; + +void syntax() +{ + std::cout << "Syntax: brother240tool \n" + "The disk image will be flipped from Brother to DOS format and back\n" + "again.\n"; + exit(0); +} + +uint8_t getbyte(uint32_t offset) +{ + inputFile.seekg(offset, std::ifstream::beg); + return inputFile.get(); +} + +void putbyte(uint32_t offset, uint8_t value) +{ + inputFile.seekp(offset, std::ifstream::beg); + inputFile.put(value); +} + +int main(int argc, const char* argv[]) +{ + if (argc < 2) + syntax(); + + inputFile.open(argv[1], std::ios::in | std::ios::out | std::ios::binary); + if (!inputFile.is_open()) + Error() << fmt::format("cannot open input file '{}'", argv[1]); + + uint8_t b1 = getbyte(0x015); + uint8_t b2 = getbyte(0x100); + if ((b1 == 0x58) && (b2 == 0x58)) + { + std::cerr << "Flipping from Brother to DOS.\n"; + putbyte(0x015, 0xf0); + putbyte(0x100, 0xf0); + } + else if ((b1 == 0xf0) && (b2 == 0xf0)) + { + std::cerr << "Flipping from DOS to Brother.\n"; + putbyte(0x015, 0x58); + putbyte(0x100, 0x58); + } + else + Error() << "Unknown image format."; + + inputFile.close(); + return 0; +} +