fork/GramFirmware
git clone https://git.julia.blue/fork/GramFirmware
818d962
gram
1#include "comms/N64Backend.hpp" 2 3#include <Nintendo.h> 4 5N64Backend ::N64Backend ( 6InputState & inputs , 7InputSource ** input_sources , 8size_t input_source_count , 9int polling_rate , 10int data_pin 11) 12 :CommunicationBackend (inputs ,input_sources ,input_source_count ), 13_n64 (data_pin ) { 14_data = defaultN64Data ; 15 16if (polling_rate > 0 ) { 17// Delay used between input updates to postpone them until right before the 18// next poll, while also leaving time (850us) for processing to finish. 19_delay = (1000000 /polling_rate )- 850 ; 20 }else { 21// If polling rate is set to 0, disable the delay. 22_delay = 0 ; 23 } 24} 25 26CommunicationBackendId N64Backend ::BackendId () { 27return COMMS_BACKEND_N64 ; 28} 29 30void N64Backend ::SendReport () { 31// Update inputs from all sources at once. 32ScanInputs (); 33 34// Run gamemode logic. 35UpdateOutputs (); 36 37// Digital outputs 38_data .report .a = _outputs .a ; 39_data .report .b = _outputs .b ; 40_data .report .z = _outputs .buttonR ; 41_data .report .l = _outputs .triggerLDigital ; 42_data .report .r = _outputs .triggerRDigital ; 43_data .report .start = _outputs .start ; 44_data .report .dleft = _outputs .dpadLeft ; 45_data .report .dright = _outputs .dpadRight ; 46_data .report .ddown = _outputs .dpadDown ; 47_data .report .dup = _outputs .dpadUp ; 48// Somewhat ugly way of mapping right stick to C-Pad 49_data .report .cleft = _outputs .rightStickX < 128 ; 50_data .report .cright = _outputs .rightStickX > 128 ; 51_data .report .cdown = _outputs .rightStickY < 128 ; 52_data .report .cup = _outputs .rightStickY > 128 ; 53 54// Analog outputs - converted from unsigned to signed 8-bit integers 55_data .report .xAxis = _outputs .leftStickX - 128 ; 56_data .report .yAxis = _outputs .leftStickY - 128 ; 57 58// Send outputs to console. 59_n64 -> write (_data ); 60 61delayMicroseconds (_delay ); 62}