This is extremely inspired by the MESS implementation, written by Nathan * Woods and R. Belmont: * https://github.com/mamedev/mame/blob/7914a6083a3b3a8c243ae6c3b8cb50b023f21e0e/src/lib/formats/ap2_dsk.cpp */
| 37 | * https://github.com/mamedev/mame/blob/7914a6083a3b3a8c243ae6c3b8cb50b023f21e0e/src/lib/formats/ap2_dsk.cpp |
| 38 | */ |
| 39 | static Bytes decode_crazy_data(const uint8_t* inp, Sector::Status& status) |
| 40 | { |
| 41 | Bytes output(APPLE2_SECTOR_LENGTH); |
| 42 | |
| 43 | uint8_t checksum = 0; |
| 44 | for (unsigned i = 0; i < APPLE2_ENCODED_SECTOR_LENGTH; i++) |
| 45 | { |
| 46 | checksum ^= decode_data_gcr(*inp++); |
| 47 | |
| 48 | if (i >= 86) |
| 49 | { |
| 50 | /* 6 bit */ |
| 51 | output[i - 86] |= (checksum << 2); |
| 52 | } |
| 53 | else |
| 54 | { |
| 55 | /* 3 * 2 bit */ |
| 56 | output[i + 0] = ((checksum >> 1) & 0x01) | ((checksum << 1) & 0x02); |
| 57 | output[i + 86] = |
| 58 | ((checksum >> 3) & 0x01) | ((checksum >> 1) & 0x02); |
| 59 | if ((i + 172) < APPLE2_SECTOR_LENGTH) |
| 60 | output[i + 172] = |
| 61 | ((checksum >> 5) & 0x01) | ((checksum >> 3) & 0x02); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | checksum &= 0x3f; |
| 66 | uint8_t wantedchecksum = decode_data_gcr(*inp); |
| 67 | status = (checksum == wantedchecksum) ? Sector::OK : Sector::BAD_CHECKSUM; |
| 68 | return output; |
| 69 | } |
| 70 | |
| 71 | static uint8_t combine(uint16_t word) |
| 72 | { |
no test coverage detected