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