Turns a legal mode into an index into the BlockDesc table. Illegal or reserved modes return -1.
| 592 | // Turns a legal mode into an index into the BlockDesc table. |
| 593 | // Illegal or reserved modes return -1. |
| 594 | static int modeToIndex(uint8_t mode) { |
| 595 | if (mode <= 3) { |
| 596 | return mode; |
| 597 | } else if ((mode & 0x2) != 0) { |
| 598 | if (mode <= 18) { |
| 599 | // Turns 6 into 4, 7 into 5, 10 into 6, etc. |
| 600 | return (mode / 2) + 1 + (mode & 0x1); |
| 601 | } else if (mode == 22 || mode == 26 || mode == 30) { |
| 602 | // Turns 22 into 11, 26 into 12, etc. |
| 603 | return mode / 4 + 6; |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | return -1; |
| 608 | } |
| 609 | |
| 610 | // Returns a description of the bitfields for each mode from the LSB |
| 611 | // to the MSB before the index data starts. |