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