clang-format off * IMAGE FILE FORMAT * The overall layout of an ImageDisk .IMD image file is: * IMD v.vv: dd/mm/yyyy hh:mm:ss * Comment (ASCII only - unlimited size) * 1A byte - ASCII EOF character * - For each track on the disk: * 1 byte Mode value (0-5) see getModulationspeed for definition * 1 byte Cylinder (0-n) * 1 byte Head (0-1)
| 138 | */ |
| 139 | // clang-format on |
| 140 | std::unique_ptr<Image> readImage() override |
| 141 | { |
| 142 | // Read File |
| 143 | std::ifstream inputFile( |
| 144 | _config.filename(), std::ios::in | std::ios::binary); |
| 145 | if (!inputFile.is_open()) |
| 146 | error("IMD: cannot open input file"); |
| 147 | // define some variables |
| 148 | bool fm = false; // define coding just to show in comment for setting |
| 149 | // the right write parameters |
| 150 | inputFile.seekg(0, inputFile.end); |
| 151 | int inputFileSize = inputFile.tellg(); // determine filesize |
| 152 | inputFile.seekg(0, inputFile.beg); |
| 153 | Bytes data; |
| 154 | data.writer() += inputFile; |
| 155 | ByteReader br(data); |
| 156 | std::unique_ptr<Image> image(new Image); |
| 157 | TrackHeader header = {0, 0, 0, 0, 0}; |
| 158 | TrackHeader previousheader = {0, 0, 0, 0, 0}; |
| 159 | |
| 160 | auto layout = _extraConfig.mutable_layout(); |
| 161 | |
| 162 | unsigned n = 0; |
| 163 | unsigned headerPtr = 0; |
| 164 | unsigned Modulation_Speed = 0; |
| 165 | unsigned sectorSize = 0; |
| 166 | std::string sector_skew; |
| 167 | |
| 168 | int b; |
| 169 | std::string comment; |
| 170 | bool blnOptionalCylinderMap = false; |
| 171 | bool blnOptionalHeadMap = false; |
| 172 | int trackSectorSize = -1; |
| 173 | // Read comment |
| 174 | comment.clear(); |
| 175 | while ((b = br.read_8()) != EOF && b != END_OF_FILE) |
| 176 | { |
| 177 | comment.push_back(b); |
| 178 | n++; |
| 179 | } |
| 180 | headerPtr = n; // set pointer to after comment |
| 181 | log("Comment in IMD file: {}", comment); |
| 182 | |
| 183 | for (;;) |
| 184 | { |
| 185 | if (headerPtr >= inputFileSize - 1) |
| 186 | { |
| 187 | break; |
| 188 | } |
| 189 | // first read header |
| 190 | header.ModeValue = br.read_8(); |
| 191 | headerPtr++; |
| 192 | Modulation_Speed = getModulationandSpeed(header.ModeValue, &fm); |
| 193 | header.track = br.read_8(); |
| 194 | headerPtr++; |
| 195 | header.Head = br.read_8(); |
| 196 | headerPtr++; |
| 197 | header.numSectors = br.read_8(); |
nothing calls this directly
no test coverage detected