fork/GramFirmware

git clone https://git.julia.blue/fork/GramFirmware

Jonathan HaylettMake select/home = dpad left/right in GamecubeBackend instead of just in Melee modefb5ac91

v0.1.2
2.1 KiB73 linesraw
1#include "comms/GamecubeBackend.hpp"
2
3#include "core/InputSource.hpp"
4
5#include <GamecubeConsole.hpp>
6#include <hardware/pio.h>
7#include <hardware/timer.h>
8
9GamecubeBackend::GamecubeBackend(
10    InputSource **input_sources,
11    size_t input_source_count,
12    uint data_pin,
13    PIO pio,
14    int sm,
15    int offset
16)
17    : CommunicationBackend(input_sources, input_source_count) {
18    _gamecube = new GamecubeConsole(data_pin, pio, sm, offset);
19    _report = default_gc_report;
20}
21
22GamecubeBackend::~GamecubeBackend() {
23    delete _gamecube;
24}
25
26void GamecubeBackend::SendReport() {
27    // Update slower inputs before we start waiting for poll.
28    ScanInputs(InputScanSpeed::SLOW);
29    ScanInputs(InputScanSpeed::MEDIUM);
30
31    // Read inputs
32    _gamecube->WaitForPollStart();
33
34    // Update fast inputs in response to poll.
35    // But wait 40us first so that we read inputs at the start of the 3rd byte of the poll command
36    // not the second, so inputs are maximum 40us old by the time we start sending the report.
37    busy_wait_us(40);
38    ScanInputs(InputScanSpeed::FAST);
39
40    // Run gamemode logic.
41    UpdateOutputs();
42
43    // Digital outputs
44    _report.a = _outputs.a;
45    _report.b = _outputs.b;
46    _report.x = _outputs.x;
47    _report.y = _outputs.y;
48    _report.z = _outputs.buttonR;
49    _report.l = _outputs.triggerLDigital;
50    _report.r = _outputs.triggerRDigital;
51    _report.start = _outputs.start;
52    _report.dpad_left = _outputs.dpadLeft | _outputs.select;
53    _report.dpad_right = _outputs.dpadRight | _outputs.home;
54    _report.dpad_down = _outputs.dpadDown;
55    _report.dpad_up = _outputs.dpadUp;
56
57    // Analog outputs
58    _report.stick_x = _outputs.leftStickX;
59    _report.stick_y = _outputs.leftStickY;
60    _report.cstick_x = _outputs.rightStickX;
61    _report.cstick_y = _outputs.rightStickY;
62    _report.l_analog = _outputs.triggerLAnalog;
63    _report.r_analog = _outputs.triggerRAnalog;
64
65    // Send outputs to console unless poll command is invalid.
66    if (_gamecube->WaitForPollEnd() != PollStatus::ERROR) {
67        _gamecube->SendReport(&_report);
68    }
69}
70
71int GamecubeBackend::GetOffset() {
72    return _gamecube->GetOffset();
73}