This is extremely inspired by the MESS implementation, written by Nathan * Woods and R. Belmont: * https://github.com/mamedev/mame/blob/4263a71e64377db11392c458b580c5ae83556bc7/src/lib/formats/ap_dsk35.cpp */
| 35 | * https://github.com/mamedev/mame/blob/4263a71e64377db11392c458b580c5ae83556bc7/src/lib/formats/ap_dsk35.cpp |
| 36 | */ |
| 37 | static Bytes decode_crazy_data(const Bytes& input, Sector::Status& status) |
| 38 | { |
| 39 | Bytes output; |
| 40 | ByteWriter bw(output); |
| 41 | ByteReader br(input); |
| 42 | |
| 43 | static const int LOOKUP_LEN = MAC_SECTOR_LENGTH / 3; |
| 44 | |
| 45 | uint8_t b1[LOOKUP_LEN + 1]; |
| 46 | uint8_t b2[LOOKUP_LEN + 1]; |
| 47 | uint8_t b3[LOOKUP_LEN + 1]; |
| 48 | |
| 49 | for (int i = 0; i <= LOOKUP_LEN; i++) |
| 50 | { |
| 51 | uint8_t w4 = br.read_8(); |
| 52 | uint8_t w1 = br.read_8(); |
| 53 | uint8_t w2 = br.read_8(); |
| 54 | uint8_t w3 = (i != 174) ? br.read_8() : 0; |
| 55 | |
| 56 | b1[i] = (w1 & 0x3F) | ((w4 << 2) & 0xC0); |
| 57 | b2[i] = (w2 & 0x3F) | ((w4 << 4) & 0xC0); |
| 58 | b3[i] = (w3 & 0x3F) | ((w4 << 6) & 0xC0); |
| 59 | } |
| 60 | |
| 61 | /* Copy from the user's buffer to our buffer, while computing |
| 62 | * the three-byte data checksum. */ |
| 63 | |
| 64 | uint32_t c1 = 0; |
| 65 | uint32_t c2 = 0; |
| 66 | uint32_t c3 = 0; |
| 67 | unsigned count = 0; |
| 68 | for (;;) |
| 69 | { |
| 70 | c1 = (c1 & 0xFF) << 1; |
| 71 | if (c1 & 0x0100) |
| 72 | c1++; |
| 73 | |
| 74 | uint8_t val = b1[count] ^ c1; |
| 75 | c3 += val; |
| 76 | if (c1 & 0x0100) |
| 77 | { |
| 78 | c3++; |
| 79 | c1 &= 0xFF; |
| 80 | } |
| 81 | bw.write_8(val); |
| 82 | |
| 83 | val = b2[count] ^ c3; |
| 84 | c2 += val; |
| 85 | if (c3 > 0xFF) |
| 86 | { |
| 87 | c2++; |
| 88 | c3 &= 0xFF; |
| 89 | } |
| 90 | bw.write_8(val); |
| 91 | |
| 92 | if (output.size() == 524) |
| 93 | break; |
| 94 |
no test coverage detected