| 53 | } |
| 54 | |
| 55 | static uint8_t SNESControllerRead() |
| 56 | { |
| 57 | // SNES bits |
| 58 | // 0 - B |
| 59 | // 1 - Y |
| 60 | // 2 - Select |
| 61 | // 3 - Start |
| 62 | // 4 - Up |
| 63 | // 5 - Down |
| 64 | // 6 - Left |
| 65 | // 7 - Right |
| 66 | // 8 - A |
| 67 | // 9 - X |
| 68 | // 10 - L |
| 69 | // 11 - R |
| 70 | |
| 71 | uint8_t state = 0x00; |
| 72 | uint16_t snes_state = 0x0000; |
| 73 | digitalWrite(CONTROLLER_SNES_LATCH, HIGH); |
| 74 | delayMicroseconds(12); |
| 75 | digitalWrite(CONTROLLER_SNES_LATCH, LOW); |
| 76 | delayMicroseconds(6); |
| 77 | |
| 78 | for (int i = 0; i < 12; i++) |
| 79 | { |
| 80 | if (digitalRead(CONTROLLER_SNES_DATA) == LOW) snes_state |= (1 << i); |
| 81 | digitalWrite(CONTROLLER_SNES_CLK, LOW); |
| 82 | delayMicroseconds(6); |
| 83 | digitalWrite(CONTROLLER_SNES_CLK, HIGH); |
| 84 | delayMicroseconds(6); |
| 85 | } |
| 86 | |
| 87 | // NES compatible bits |
| 88 | state |= snes_state & 0xFF; |
| 89 | |
| 90 | // Map extra bits to A and B buttons |
| 91 | if (snes_state & (1 << 8)) state |= (uint8_t)CONTROLLER::A; |
| 92 | if (snes_state & (1 << 9)) state |= (uint8_t)CONTROLLER::B; |
| 93 | if (snes_state & (1 << 10)) state |= (uint8_t)CONTROLLER::B; |
| 94 | if (snes_state & (1 << 11)) state |= (uint8_t)CONTROLLER::A; |
| 95 | |
| 96 | return state; |
| 97 | } |
| 98 | |
| 99 | static uint8_t PSXTransferByte(uint8_t byte) |
| 100 | { |
nothing calls this directly
no outgoing calls
no test coverage detected