|
| 1 | +#include "comms/N64Backend.hpp" |
| 2 | + |
| 3 | +#include "core/InputSource.hpp" |
| 4 | + |
| 5 | +#include <N64Console.hpp> |
| 6 | +#include <hardware/pio.h> |
| 7 | + |
| 8 | +N64Backend::N64Backend( |
| 9 | + InputSource **input_sources, |
| 10 | + size_t input_source_count, |
| 11 | + uint data_pin, |
| 12 | + PIO pio, |
| 13 | + int sm, |
| 14 | + int offset |
| 15 | +) |
| 16 | + : CommunicationBackend(input_sources, input_source_count) { |
| 17 | + _n64 = new N64Console(data_pin, pio, sm, offset); |
| 18 | + _report = default_n64_report; |
| 19 | +} |
| 20 | + |
| 21 | +N64Backend::~N64Backend() { |
| 22 | + delete _n64; |
| 23 | +} |
| 24 | + |
| 25 | +void N64Backend::SendReport() { |
| 26 | + // Update slower inputs before we start waiting for poll. |
| 27 | + ScanInputs(InputScanSpeed::SLOW); |
| 28 | + ScanInputs(InputScanSpeed::MEDIUM); |
| 29 | + |
| 30 | + // Read inputs |
| 31 | + _n64->WaitForPoll(); |
| 32 | + |
| 33 | + // Update fast inputs in response to poll. |
| 34 | + ScanInputs(InputScanSpeed::FAST); |
| 35 | + |
| 36 | + // Run gamemode logic. |
| 37 | + UpdateOutputs(); |
| 38 | + |
| 39 | + // Digital outputs |
| 40 | + _report.a = _outputs.a; |
| 41 | + _report.b = _outputs.b; |
| 42 | + _report.z = _outputs.buttonR; |
| 43 | + _report.l = _outputs.triggerLDigital; |
| 44 | + _report.r = _outputs.triggerRDigital; |
| 45 | + _report.start = _outputs.start; |
| 46 | + _report.dpad_left = _outputs.dpadLeft; |
| 47 | + _report.dpad_right = _outputs.dpadRight; |
| 48 | + _report.dpad_down = _outputs.dpadDown; |
| 49 | + _report.dpad_up = _outputs.dpadUp; |
| 50 | + // Somewhat ugly way of mapping right stick to C-Pad |
| 51 | + _report.c_left = _outputs.rightStickX < 128; |
| 52 | + _report.c_right = _outputs.rightStickX > 128; |
| 53 | + _report.c_down = _outputs.rightStickY < 128; |
| 54 | + _report.c_up = _outputs.rightStickY > 128; |
| 55 | + |
| 56 | + // Analog outputs |
| 57 | + _report.stick_x = _outputs.leftStickX - 128; |
| 58 | + _report.stick_y = _outputs.leftStickY - 128; |
| 59 | + |
| 60 | + // Send outputs to console. |
| 61 | + _n64->SendReport(&_report); |
| 62 | +} |
| 63 | + |
| 64 | +int N64Backend::GetOffset() { |
| 65 | + return _n64->GetOffset(); |
| 66 | +} |
0 commit comments