| 52 | } |
| 53 | |
| 54 | static std::vector<bool> encode_data(uint8_t input) |
| 55 | { |
| 56 | /* |
| 57 | * Four 8-bit data bytes are converted to four 10-bit GCR bytes at a time by |
| 58 | * the 1541 DOS. RAM is only an 8-bit storage device though. This hardware |
| 59 | * limitation prevents a 10-bit GCR byte from being stored in a single |
| 60 | * memory location. Four 10-bit GCR bytes total 40 bits - a number evenly |
| 61 | * divisible by our overriding 8-bit constraint. Commodore sub- divides the |
| 62 | * 40 GCR bits into five 8-bit bytes to solve this dilemma. This explains |
| 63 | * why four 8-bit data bytes are converted to GCR form at a time. The |
| 64 | * following step by step example demonstrates how this bit manipulation is |
| 65 | * performed by the DOS. |
| 66 | * |
| 67 | * STEP 1. Four 8-bit Data Bytes |
| 68 | * $08 $10 $00 $12 |
| 69 | * |
| 70 | * STEP 2. Hexadecimal to Binary Conversion |
| 71 | * 1. Binary Equivalents |
| 72 | * $08 $10 $00 $12 |
| 73 | * 00001000 00010000 00000000 00010010 |
| 74 | * |
| 75 | * STEP 3. Binary to GCR Conversion |
| 76 | * 1. Four 8-bit Data Bytes |
| 77 | * 00001000 00010000 00000000 00010010 |
| 78 | * 2. High and Low Nybbles |
| 79 | * 0000 1000 0001 0000 0000 0000 0001 0010 |
| 80 | * 3. High and Low Nybble GCR Equivalents |
| 81 | * 01010 01001 01011 01010 01010 01010 01011 10010 |
| 82 | * 4. Four 10-bit GCR Bytes |
| 83 | * 0101001001 0101101010 0101001010 0101110010 |
| 84 | * |
| 85 | * STEP 4. 10-bit GCR to 8-bit GCR Conversion |
| 86 | * 1. Concatenate Four 10-bit GCR Bytes |
| 87 | * 0101001001010110101001010010100101110010 |
| 88 | * 2. Five 8-bit Subdivisions |
| 89 | * 01010010 01010110 10100101 00101001 01110010 |
| 90 | * |
| 91 | * STEP 5. Binary to Hexadecimal Conversion |
| 92 | * 1. Hexadecimal Equivalents |
| 93 | * 01010010 01010110 10100101 00101001 01110010 |
| 94 | * $52 $56 $A5 $29 $72 |
| 95 | * |
| 96 | * STEP 6. Four 8-bit Data Bytes are Recorded as Five 8-bit GCR Bytes |
| 97 | * $08 $10 $00 $12 |
| 98 | * |
| 99 | * are recorded as |
| 100 | * $52 $56 $A5 $29 $72 |
| 101 | */ |
| 102 | |
| 103 | std::vector<bool> output(10, false); |
| 104 | uint8_t hi = 0; |
| 105 | uint8_t lo = 0; |
| 106 | uint8_t lo_GCR = 0; |
| 107 | uint8_t hi_GCR = 0; |
| 108 | |
| 109 | // Convert the byte in high and low nibble |
| 110 | lo = input >> 4; // get the lo nibble shift the bits 4 to the right |
| 111 | hi = input & 15; // get the hi nibble bij masking the lo bits (00001111) |
no test coverage detected