diff --git a/mkninja.sh b/mkninja.sh index a146fc3c..97052897 100644 --- a/mkninja.sh +++ b/mkninja.sh @@ -35,6 +35,10 @@ rule test rule strip command = cp -f \$in \$out && $STRIP \$out description = STRIP \$in + +rule mktable + command = sh scripts/mktable.sh \$kind \$words > \$out + description = MKTABLE \$kind EOF buildlibrary() { @@ -105,8 +109,10 @@ buildproto() { cfiles= for src in "$@"; do local cfile + local hfile cfile="$OBJDIR/proto/${src%%.proto}.pb.cc" - cfiles="$cfiles $cfile" + hfile="$OBJDIR/proto/${src%%.proto}.pb.h" + cfiles="$cfiles $cfile $hfile" done echo build $cfiles $def : proto $@ @@ -197,6 +203,19 @@ buildsimpleprogram() { buildprogram $prog lib$prog.a "$@" } +buildmktable() { + local kind + local out + kind=$1 + out=$2 + shift + shift + + echo "build $out : mktable scripts/mktable.sh" + echo " words=$@" + echo " kind=$kind" +} + runtest() { local prog prog=$1 @@ -303,30 +322,37 @@ buildlibrary libbackend.a \ lib/utils.cc \ lib/writer.cc \ -for pb in \ +READABLES="\ + acornadfs \ acorndfs \ brother \ ibm \ -; do + " + +WRITABLES="\ + brother240 \ + ibm1440 \ + " + +for pb in $READABLES; do buildencodedproto $OBJDIR/proto/libproto.def ConfigProto \ readables_${pb}_pb src/readables/$pb.textpb $OBJDIR/proto/src/readables/$pb.cc done -for pb in \ - brother240 \ - ibm1440 \ -; do +for pb in $WRITABLES; do buildencodedproto $OBJDIR/proto/libproto.def ConfigProto \ writables_${pb}_pb src/writables/$pb.textpb $OBJDIR/proto/src/writables/$pb.cc done +buildmktable readables $OBJDIR/readables.cc $READABLES +buildmktable writables $OBJDIR/writables.cc $WRITABLES + buildlibrary libfrontend.a \ -I$OBJDIR/proto \ - $OBJDIR/proto/src/readables/acorndfs.cc \ - $OBJDIR/proto/src/readables/brother.cc \ - $OBJDIR/proto/src/readables/ibm.cc \ - $OBJDIR/proto/src/writables/brother240.cc \ - $OBJDIR/proto/src/writables/ibm1440.cc \ + $(for a in $READABLES; do echo $OBJDIR/proto/src/readables/$a.cc; done) \ + $(for a in $WRITABLES; do echo $OBJDIR/proto/src/writables/$a.cc; done) \ + $OBJDIR/readables.cc \ + $OBJDIR/writables.cc \ src/fe-analysedriveresponse.cc \ src/fe-analyselayout.cc \ src/fe-cwftoflux.cc \ @@ -347,7 +373,6 @@ buildlibrary libfrontend.a \ src/fe-writeflux.cc \ src/fluxengine.cc \ -# src/fe-readadfs.cc \ # src/fe-readaeslanier.cc \ # src/fe-readamiga.cc \ # src/fe-readampro.cc \ diff --git a/scripts/mktable.sh b/scripts/mktable.sh new file mode 100644 index 00000000..7b251edb --- /dev/null +++ b/scripts/mktable.sh @@ -0,0 +1,19 @@ +#!/bin/sh +echo "#include " +echo "#include " + +word=$1 +shift + +for a in "$@"; do + echo "extern std::string ${word}_${a}_pb();" +done + +echo "extern const std::map ${word};" +echo "const std::map ${word} = {" +for a in "$@"; do + echo " { \"${a}\", ${word}_${a}_pb() }," +done +echo "};" + + diff --git a/src/fe-read.cc b/src/fe-read.cc index 1d97a4b4..749f5846 100644 --- a/src/fe-read.cc +++ b/src/fe-read.cc @@ -19,24 +19,17 @@ static FlagGroup flags { &readerFlags }; -extern std::string readables_acorndfs_pb(); -extern std::string readables_brother_pb(); -extern std::string readables_ibm_pb(); - -static std::map> readables = { - { "acorndfs", readables_acorndfs_pb }, - { "brother", readables_brother_pb }, - { "ibm", readables_ibm_pb }, -}; +extern const std::map readables; int mainRead(int argc, const char* argv[]) { std::vector filenames = flags.parseFlagsWithFilenames(argc, argv); for (const auto& filename : filenames) { - if (readables.find(filename) != readables.end()) + const auto& it = readables.find(filename); + if (it != readables.end()) { - if (!config.ParseFromString(readables[filename]())) + if (!config.ParseFromString(it->second)) Error() << "couldn't load config proto"; } else diff --git a/src/fe-readadfs.cc b/src/fe-readadfs.cc deleted file mode 100644 index 8debc4db..00000000 --- a/src/fe-readadfs.cc +++ /dev/null @@ -1,13 +0,0 @@ -#include "globals.h" -#include "reader.h" -#include "fmt/format.h" -#include "readibm.h" - -int mainReadADFS(int argc, const char* argv[]) -{ - setReaderDefaultSource(":t=0-79:s=0-1"); - setReaderDefaultOutput("adfs.img"); - sectorIdBase.setDefaultValue(0); - return mainReadIBM(argc, argv); -} - diff --git a/src/fe-write.cc b/src/fe-write.cc index 24d6065c..2cdcaa4c 100644 --- a/src/fe-write.cc +++ b/src/fe-write.cc @@ -19,22 +19,17 @@ static FlagGroup flags { &writerFlags }; -extern std::string writables_brother240_pb(); -extern std::string writables_ibm1440_pb(); - -static std::map> writables = { - { "brother240", writables_brother240_pb }, - { "ibm1440", writables_ibm1440_pb }, -}; +extern const std::map writables; int mainWrite(int argc, const char* argv[]) { std::vector filenames = flags.parseFlagsWithFilenames(argc, argv); for (const auto& filename : filenames) { - if (writables.find(filename) != writables.end()) + const auto& it = writables.find(filename); + if (it != writables.end()) { - if (!config.ParseFromString(writables[filename]())) + if (!config.ParseFromString(it->second)) Error() << "couldn't load config proto"; } else diff --git a/src/fluxengine.cc b/src/fluxengine.cc index dd596dfb..7e6009a2 100644 --- a/src/fluxengine.cc +++ b/src/fluxengine.cc @@ -20,7 +20,6 @@ extern command_cb mainTestVoltages; extern command_cb mainUpgradeFluxFile; extern command_cb mainWrite; extern command_cb mainWriteFlux; -extern command_cb mainWriteTestPattern; struct Command { @@ -46,7 +45,6 @@ static std::vector commands = { "upgradefluxfile", mainUpgradeFluxFile, "Upgrades a flux file from a previous version of this software.", }, { "write", mainWrite, "Writes a sector image to a disk.", }, { "writeflux", mainWriteFlux, "Writes a raw flux file. Warning: you can't use this to copy disks.", }, - { "writetestpattern", mainWriteTestPattern, "Writes a machine-generated test pattern to a disk.", }, }; static std::vector readables = diff --git a/src/readables/acornadfs.textpb b/src/readables/acornadfs.textpb new file mode 100644 index 00000000..f1269d1f --- /dev/null +++ b/src/readables/acornadfs.textpb @@ -0,0 +1,29 @@ +input { + disk { + drive {} + } +} + +output { + file { + filename: "acornadfs.img" + img {} + } +} + +decoder { + ibm { + sector_base: 0 + } +} + +cylinders { + start: 0 + end: 79 +} + +heads { + start: 0 + end: 1 +} + diff --git a/src/readables/acorndfs.textpb b/src/readables/acorndfs.textpb index 3b7b07f2..30706c2c 100644 --- a/src/readables/acorndfs.textpb +++ b/src/readables/acorndfs.textpb @@ -6,7 +6,7 @@ input { output { file { - filename: "ibm.img" + filename: "acorndfs.img" img {} } }