fork/GramFirmware

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

CarVacfix B input change checkab1e4b7

gram
44.2 KiB1050 linesraw
1#include "modes/MeleeLimits.hpp"
2//#include "modes/Fixed.h"
3
4#define HISTORYLEN 5//changes in target stick position
5
6#define ANALOG_STICK_MIN 48
7#define ANALOG_DEAD_MIN (128-22)/*this is in the deadzone*/
8#define ANALOG_STICK_NEUTRAL 128
9#define ANALOG_DEAD_MAX (128+22)/*this is in the deadzone*/
10#define ANALOG_STICK_MAX 208
11#define ANALOG_CROUCH (128-50)/*this y coordinate will hold a crouch*/
12#define ANALOG_TAPJUMP (128+53)/*this Y coordinate will tap jump always (running is less)*/
13#define ANALOG_DASH_LEFT (128-64)/*this x coordinate will dash left*/
14#define ANALOG_DASH_RIGHT (128+64)/*this x coordinate will dash right*/
15#define ANALOG_SDI_LEFT (128-56)/*this x coordinate will sdi left*/
16#define ANALOG_SDI_RIGHT (128+56)/*this x coordinate will sdi right*/
17#define ANALOG_UTILT_LEFT (128-44)/*this y coordinate will never uptilt*/
18#define ANALOG_UTILT_RIGHT (128+44)/*this y coordinate will never uptilt*/
19#define MELEE_SDI_RAD 3136/* if x^2+y^2 >= this, it's diagonal SDI*/
20#define MELEE_RIM_RAD1 6185/*if x^2+y^2 >= this, it's on the rim and 6ms*/
21#define MELEE_RIM_RAD2 6858/*if x^2+y^2 >= this, it's past the rim and 7ms*/
22#define MELEE_RIM_RAD3 8979/*if x^2+y^2 >= this, it's past the rim and 8ms*/
23
24#define TRAVELTIME_EASY1 6//ms
25#define TRAVELTIME_EASY2 7//ms
26#define TRAVELTIME_EASY3 8//ms for 112+cubic it takes 83% to get to dash, for 80+linear it takes 80% to get to dash
27#define TRAVELTIME_CROSS 12//ms to cross gate; unused
28#define TRAVELTIME_INTERNAL 12//ms for "easy" to "internal"; 2/3 frame
29#define TRAVELTIME_SLOW 88//(5.5*16)//ms for tap SDI nerfing, 5.5 frames
30
31#define TIMELIMIT_DOWNUP (16*3*250)//units of 4us; how long after a crouch to upward input should it begin a jump?
32#define JUMP_TIME (16*2*250)//units of 4us; after a recent crouch to upward input, always hold full up for 2 frames
33
34#define TIMELIMIT_FRAME 4167//(16.66...*250)//units of 4us; 1 frame, for reference
35#define TIMELIMIT_HALFFRAME 2083//(8.33...*250)//units of 4us; 1/2 frame
36#define TIMELIMIT_DEBOUNCE 1500//(6*250)//units of 4us; 6ms;
37#define TIMELIMIT_SIMUL 500//(2*250)//units of 4us; 2ms: if the latest inputs are less than 2 ms apart then don't nerf cardiag
38
39#define TIMELIMIT_TAPSHUTOFF 16000//4 frames for tap jump shutoff
40
41//not used #define TIMELIMIT_DASH 60000//(16*15*250)//units of 4us; last dash time prior to a pivot input; 15 frames
42
43//not used #define TIMELIMIT_QCIRC 24000//(16*6*250)//units of 4us; 6 frames
44
45#define TIMELIMIT_TAP 22000//(16*5.5*250)//units of 4us; 5.5 frames
46#define TIMELIMIT_TAP_PLUS 34000//(16*8.5*250)//units of 4us; 3 additional frames
47
48#define TIMELIMIT_CARDIAG 32000//(16*8*250)//units of 4us; 8 frames
49
50#define TIMELIMIT_WANK 22000//(16*5.5*250)//units of 4us; 5.5 frames
51
52#define TIMELIMIT_PIVOTTILT 32000//(16*8*250)//units of 4us; 8 frames
53
54#define TIMELIMIT_SDI_COUNTDOWN 16000//(16*4*250)//units of 4us; 4 frames
55
56enum pivotdir{P_None, P_Leftright, P_Rightleft};
57enum travelType{T_Lin, T_Quad, T_Cubic, T_Quart, T_Delay};
58
59#define ZONE_DIR 0b0000'1111
60#define ZONE_U   0b0000'0001
61#define ZONE_D   0b0000'0010
62#define ZONE_L   0b0000'0100
63#define ZONE_R   0b0000'1000
64
65#define BITS_SDI          0b1111'0000
66#define BITS_SDI_WANK     0b0001'0000
67#define BITS_SDI_TAP_CARD 0b0010'0000
68#define BITS_SDI_TAP_DIAG 0b0100'0000
69#define BITS_SDI_TAP_CRDG 0b1000'0000
70
71typedef struct {
72    uint16_t timestamp;//in samples
73    uint8_t tt;//travel time used in ms
74    uint8_t x;
75    uint8_t y;
76    uint8_t x_start;
77    uint8_t y_start;
78    uint8_t x_end;
79    uint8_t y_end;
80} shortstate;
81
82//for sdi nerfs, we want to record only movement between sdi zones, ignoring movement within zones
83typedef struct {
84    uint16_t timestamp;//in samples
85    uint8_t zone;
86    bool stale;
87} sdizonestate;
88
89//for pivot nerfs, we want to record only movement between dash zones, ignoring movement within zones
90typedef struct {
91    uint16_t timestamp;//in samples
92    uint8_t zone;
93    bool stale;
94} pivotzonestate;
95
96uint8_t isEasy(const uint8_t x, const uint8_t y) {
97    //is it on the rim?
98    const uint8_t xnorm = (x > ANALOG_STICK_NEUTRAL ? (x-ANALOG_STICK_NEUTRAL) : (ANALOG_STICK_NEUTRAL-x));
99    const uint8_t ynorm = (y > ANALOG_STICK_NEUTRAL ? (y-ANALOG_STICK_NEUTRAL) : (ANALOG_STICK_NEUTRAL-y));
100    const uint16_t xsquared = xnorm*xnorm;
101    const uint16_t ysquared = ynorm*ynorm;
102    const uint16_t radSquared = xsquared+ysquared;
103    if((radSquared) >= MELEE_RIM_RAD1) {
104        //is it within 3 units of the diagonal? or is it a cardinal?
105        const uint8_t diagMax = max(xnorm, ynorm);
106        const uint8_t diagMin = min(xnorm, ynorm);
107        const uint8_t diff = diagMax - diagMin;
108        if(diff <= 6 || xnorm == 0 || ynorm == 0) {
109            //if so, yes
110            if(radSquared >= MELEE_RIM_RAD3) {
111                return 3;
112            } else if(radSquared >= MELEE_RIM_RAD2) {
113                return 2;
114            } else {
115                return 1;
116            }
117        } else {
118            return 0;
119        }
120    } else {
121        return 0;
122    }
123}
124
125uint8_t getRandom(uint16_t currentTime) {
126    // Use the time of the first directional input to initialize the LCG
127    static uint16_t random = currentTime;
128    // Constant from https://arxiv.org/pdf/2001.05304.pdf
129    random = 0xD9F5 * random + 1;
130    // XOR all nibbles together, necessary to minimize patterns with a power of 2 LCG
131    uint8_t xor1 = random ^ (random >> 8);
132    uint8_t xor2 = xor1   ^ (xor1   >> 4);
133    return xor2 % 16;
134}
135// 1 2 1 //4
136// 2 4 2 //8
137// 1 2 1 //4
138// totals up to 16
139void randomizeCoord(uint8_t &x, uint8_t &y, uint16_t currentTime) {
140    const uint8_t random = getRandom(currentTime);
141    const uint8_t left = ((random ^ 0b0) & 0b11) == 0;
142    //middle is when random & 0b01 or 0b10
143    const uint8_t right = ((random ^ 0b11) & 0b11) == 0;
144    const uint8_t up = ((random ^ 0b0000) & 0b1100) == 0;
145    //middle is when random & 0b01xx or 0b10xx
146    const uint8_t down = ((random ^ 0b1100) & 0b1100) == 0;
147
148    //don't randomize when x or y are neutral
149    x = (x != ANALOG_STICK_NEUTRAL) ? x - left + right : x;
150    y = (y != ANALOG_STICK_NEUTRAL) ? y - down + up : y;
151}
152
153uint8_t lookback(const uint8_t currentIndex,
154                 const uint8_t samplesBack) {
155    if(samplesBack > currentIndex) {
156        return (HISTORYLEN-samplesBack) + currentIndex;
157    } else {
158        return currentIndex - samplesBack;
159    }
160}
161
162//the output will have the following bits set:
163//0b0000'0001 for up
164//0b0000'0010 for down
165//0b0000'0100 for left
166//0b0000'1000 for right
167//no bits set for neutral
168//thresholds are dash for cardinals, and deadzone for diagonals
169uint8_t sdiZone(const uint8_t x, const uint8_t y) {
170    uint8_t result = 0b0000'0000;
171    const uint8_t xnorm = (x > ANALOG_STICK_NEUTRAL ? (x-ANALOG_STICK_NEUTRAL) : (ANALOG_STICK_NEUTRAL-x));
172    const uint8_t ynorm = (y > ANALOG_STICK_NEUTRAL ? (y-ANALOG_STICK_NEUTRAL) : (ANALOG_STICK_NEUTRAL-y));
173    const uint16_t xsquared = xnorm*xnorm;
174    const uint16_t ysquared = ynorm*ynorm;
175    const uint16_t radSquared = xsquared+ysquared;
176    if(x >= ANALOG_DEAD_MIN && x <= ANALOG_DEAD_MAX) {
177        if(y < ANALOG_SDI_LEFT) {
178            result = result | ZONE_D;
179        } else if(y > ANALOG_SDI_RIGHT) {
180            result = result | ZONE_U;
181        }
182    } else if(x < ANALOG_DEAD_MIN) {
183        if(y < ANALOG_DEAD_MIN && radSquared >= MELEE_SDI_RAD) {
184            result = result | ZONE_D | ZONE_L;
185        } else if(y > ANALOG_DEAD_MAX && radSquared >= MELEE_SDI_RAD) {
186            result = result | ZONE_U | ZONE_L;
187        } else if(x <= ANALOG_SDI_LEFT) {
188            result = result | ZONE_L;
189        }
190    } else /*if(x > ANALOG_DEAD_MAX)*/ {
191        if(y < ANALOG_DEAD_MIN && radSquared >= MELEE_SDI_RAD) {
192            result = result | ZONE_D | ZONE_R;
193        } else if(y > ANALOG_DEAD_MAX && radSquared >= MELEE_SDI_RAD) {
194            result = result | ZONE_U | ZONE_R;
195        } else if(x >= ANALOG_SDI_RIGHT) {
196            result = result | ZONE_R;
197        }
198    }
199    return result;
200}
201
202//the output will have the following bits set:
203//0b0000'0100 for left
204//0b0000'1000 for right
205//no bits set for neutral
206//thresholds are dash for the x-axis
207uint8_t pivotZone(const uint8_t x) {
208    uint8_t result = 0b0000'0000;
209    if(x <= ANALOG_DASH_LEFT) {
210        result = result | ZONE_L;
211    } else if(x >= ANALOG_DASH_RIGHT) {
212        result = result | ZONE_R;
213    }
214    return result;
215}
216
217uint8_t uptiltShutoffZone(const uint8_t y) {
218    uint8_t result = 0b0000'0000;
219    if(y > ANALOG_DEAD_MAX && y < ANALOG_TAPJUMP) {
220        result = result | ZONE_U;
221    }
222    return result;
223}
224
225//not a general purpose popcount, this is specifically for zones
226uint8_t popcount_zone(const uint8_t bitsIn) {
227    uint8_t count = 0;
228    for(uint8_t i = 0; i < 4; i++) {
229        if((bitsIn >> i) & 0b0000'0001) {
230            count++;
231        }
232    }
233    return count;
234}
235
236uint8_t isTapSDI(const sdizonestate zoneHistory[HISTORYLEN],
237                 const uint8_t currentIndex,
238                 const uint16_t currentTime,
239                 const uint16_t sampleSpacing) {
240    uint8_t output = 0;
241
242    //grab the last five zones
243    const uint8_t historyLength = min(5, HISTORYLEN);
244    uint8_t zoneList[historyLength];
245    uint16_t timeList[historyLength];
246    bool staleList[historyLength];
247    for(int i = 0; i < historyLength; i++) {
248        const uint8_t index = lookback(currentIndex, i);
249        zoneList[i] = zoneHistory[index].zone;
250        timeList[i] = zoneHistory[index].timestamp;
251        staleList[i] = zoneHistory[index].stale;
252    }
253    const uint8_t popCur = popcount_zone(zoneList[0]);
254    const uint8_t popOne = popcount_zone(zoneList[1]);
255
256    //detect repeated center-cardinal sequences, or repeated cardinal-diagonal sequences
257    // if we're changing zones back and forth
258    if(zoneList[0] != zoneList[1] && (zoneList[0] == zoneList[2]) && (zoneList[1] == zoneList[3])) {
259        //check the time duration
260        const uint16_t timeDiff0 = (currentTime - timeList[2])*sampleSpacing;//make sure things aren't reliant on long-past inputs
261        const uint16_t timeDiff1 = (timeList[0] - timeList[2])*sampleSpacing;//rising edge to rising edge, or falling edge to falling edge
262        //const uint16_t timeDiff2 = (timeList[0] - timeList[1])*sampleSpacing;//rising to falling, or falling to rising
263        //We want to nerf it if there is more than one press every 6 frames, but not if the previous press or release duration is less than 1 frame
264        if(!staleList[2] && (timeDiff0 < TIMELIMIT_TAP_PLUS && timeDiff1 < TIMELIMIT_TAP && timeDiff0 > TIMELIMIT_DEBOUNCE)) {
265            if((zoneList[0] == 0) || (zoneList[1] == 0)) {//if one of the pairs of zones is zero, it's tapping a cardinal (or tapping a diagonal modifier)
266                output = output | BITS_SDI_TAP_CARD;
267            } else {//if(popCur != 0 && popOne != 0) { //one is cardinal and the other is diagonal
268                output = output | BITS_SDI_TAP_DIAG;
269            }
270        }
271    }
272    //detect:
273    //         center-cardinal-diagonal-center-cardinal (-diagonal)
274    //center-cardinal-diagonal-cardinal-center-cardinal (-diagonal)
275    //where the the diagonals are the same
276    //the cardinals don't have to be the same in case they're inputting 2365 etc
277
278    //simpler: if the last 5 inputs are in the origin, one cardinal, and one diagonal
279    //and that there was a recent return to center
280    //at least one of each zone, and at least two diagonals
281    uint8_t diagZone = 0b1111'1111;
282    uint8_t origCount = 0;
283    uint8_t cardCount = 0;
284    uint8_t diagCount = 0;
285    for(int i = 0; i < historyLength; i++) {
286        const uint8_t popcnt = popcount_zone(zoneList[i]);
287        if(popcnt == 0) {
288            origCount++;
289        } else if(popcnt == 1) {
290            cardCount++;
291        } else {
292            diagCount++;
293            diagZone = diagZone & zoneList[i];//if two of these don't match, it'll have zero or one bits set
294        }
295    }
296    {//to limit scope of these vars
297        //check the bit count of diagonal matching
298        const bool diagMatch = popcount_zone(diagZone) == 2;
299        //check whether it returned to center recently
300        //const bool recentOrig = (zoneList[1] & zoneList[2]) == 0;//may be too lenient in case people throw in modifier taps?
301        //check whether the input was fast enough
302        const bool shortTime = ((timeList[0] - timeList[4])*sampleSpacing < TIMELIMIT_CARDIAG) &&
303                               ((timeList[0] - timeList[1])*sampleSpacing > TIMELIMIT_SIMUL) &&
304                               !staleList[4];
305
306        // if only the same diagonal was pressed
307        //              if the origin, cardinal, and two diagonals were all entered
308        //                                                         within the time limit
309        if(diagMatch && origCount && cardCount && diagCount > 1 && shortTime) {
310            output = output | BITS_SDI_TAP_CRDG;
311        }
312    }
313
314    //3 input sdi
315    //center-cardinal-diagonal-diagonal
316    //center-cardinal-diagonal-same cardinal-diagonal
317    //all directions except center must be the same
318    uint8_t cardZone = 0b1111'1111;
319    diagZone = 0b1111'1111;
320    origCount = 0;
321    cardCount = 0;
322    diagCount = 0;
323    for(int i = 0; i < historyLength; i++) {
324        const uint8_t popcnt = popcount_zone(zoneList[i]);
325        if(popcnt == 0) {
326            origCount++;
327            break;//stop counting once there's an origin
328        } else if(popcnt == 1) {
329            cardCount++;
330            cardZone = cardZone & zoneList[i];//if there are two different cardinals then it won't count
331        } else {
332            diagCount++;
333            diagZone = diagZone & zoneList[i];//if two of these don't match, it'll have zero or one bits set
334        }
335    }
336    {//to limit scope of these vars
337        //check the bit count of diagonal matching
338        const bool adjacentDiag = popcount_zone(diagZone & cardZone) == 1;
339        const bool shortTime = ((timeList[0] - timeList[3])*sampleSpacing < TIMELIMIT_WANK) &&
340                               !staleList[3];
341        //if it hit two different diagonals
342        //                 hit origin, at least one cardinal, and two diagonals
343        //                                                            within the time limit
344        if(adjacentDiag && origCount && cardCount && diagCount > 1 && shortTime) {
345            output = output | BITS_SDI_WANK;
346        }
347    }
348
349    //wank sdi around a diagonal
350    //7 8 9
351    //4 5 6
352    //1 2 3
353    //
354    //this would be 4 7 8 7 type deal
355
356    //first check if another one isn't already triggered
357    if(!output) {
358        //were there two of the same diagonal on alternating inputs?
359        if((zoneList[0] == zoneList[2]) && (popcount_zone(zoneList[0]) == 2)) {
360            //check duration
361            if((timeList[0] - timeList[2])*sampleSpacing < TIMELIMIT_WANK && !staleList[2]) {
362                output = output | BITS_SDI_WANK | BITS_SDI_TAP_CRDG;
363            }
364        }
365    }
366
367    //return the last cardinal in the zone list before the last diagonal, useful for SDI diagonal nerfs.
368    bool lookNow = false;
369    bool alreadyWritten = false;
370    for(int i = 0; i < historyLength; i++) {
371        if((popcount_zone(zoneList[i]) == 2) && !alreadyWritten) {
372            lookNow = true;
373        }
374        if((popcount_zone(zoneList[i]) == 1) && !alreadyWritten && lookNow) {
375            output = output | zoneList[i];
376            alreadyWritten = true;
377        }
378    }
379    return output;
380}
381
382/*
383Fixed88 quadraticEasing(Fixed88 i){
384    Fixed88 x2 = fixedMul(i,i);
385    return x2;
386}
387Fixed88 cubicEasing(Fixed88 i){
388    Fixed88 x2 = fixedMul(i,i);
389    Fixed88 x3 = fixedMul(x2,i);
390    return x3;
391}
392Fixed88 quarticEasing(Fixed88 i){
393    Fixed88 x2 = fixedMul(i,i);
394    Fixed88 x4 = fixedMul(x2,x2);
395    return x4;
396}
397*/
398
399void travelTimeCalc(const uint16_t currentTime,
400                    const uint16_t inputTime,
401                    const uint16_t sampleSpacing,//units of 4us
402                    const uint8_t msTravel,
403                    const uint8_t startX,
404                    const uint8_t startY,
405                    const uint8_t destX,
406                    const uint8_t destY,
407                    const travelType type,
408                    bool &doneTraveling,//apply tt if false; when travel time is done, set it to true
409                    uint8_t &outX,
410                    uint8_t &outY) {
411    const uint16_t samplesElapsed = currentTime - inputTime;
412
413    const uint16_t timeElapsed = samplesElapsed*sampleSpacing;//units of 4 us
414    if(type == T_Lin) {
415        const uint16_t travelTimeElapsed = timeElapsed/msTravel;//250 times the fraction of the travel time elapsed
416
417        //For the following 256s, they used to be 250, but AVR had division issues
418        // and would only be able to reach a value of 6 when returning to neutral,
419        // from the right only.
420        //Switching to 256 fixed it somehow, at the expense of 2.4% greater travel time.
421        const uint16_t cappedTT = min(256, travelTimeElapsed);
422
423        const int16_t dX = ((destX-startX)*cappedTT)/256;
424        const int16_t dY = ((destY-startY)*cappedTT)/256;
425
426        const uint16_t newX = startX+dX;
427        const uint16_t newY = startY+dY;
428
429        outX = (uint8_t) newX;
430        outY = (uint8_t) newY;
431    } else if (type == T_Delay) {
432        if(timeElapsed <= msTravel*250) {
433            outX = startX;
434            outY = startY;
435        } else {
436            outX = destX;
437            outY = destY;
438        }
439//    } else{
440//        uint16_t usTravel4 = msTravel*250;//units of 4 us
441//        const uint16_t clampedElapsed = min(usTravel4, timeElapsed);
442//        if(clampedElapsed == usTravel4) {
443//            doneTraveling = true;
444//        }
445//        const Fixed88 timeElapsedPercent = fastDiv(intToFixed(int8_t(timeElapsed>>6)), intToFixed(int8_t(usTravel4>>6)));
446//
447//        Fixed88 interpolatedTime = max(min(timeElapsedPercent, intToFixed(int8_t(1))), intToFixed(int8_t(0)));
448//
449//        /*if(type == T_Quad) {
450//         * */
451//            interpolatedTime = quadraticEasing(interpolatedTime);
452//            /*
453//        } else if(type == T_Cubic) {
454//            interpolatedTime = cubicEasing(interpolatedTime);
455//        } else {//if(type == T_Quart)
456//            interpolatedTime = quarticEasing(interpolatedTime);
457//        }
458//        */
459//        const Fixed88 x0 = intToFixed(int8_t(startX- 128)) >> 1;
460//        const Fixed88 x1 = intToFixed(int8_t(destX - 128)) >> 1;
461//        const Fixed88 y0 = intToFixed(int8_t(startY- 128)) >> 1;
462//        const Fixed88 y1 = intToFixed(int8_t(destY - 128)) >> 1;
463//        const Fixed88 fixedX = lerp(x0, x1, interpolatedTime) << 1;
464//        const Fixed88 fixedY = lerp(y0, y1, interpolatedTime) << 1;
465//
466//        outX = uint8_t(fixedToInt(fixedX) + 128);
467//        outY = uint8_t(fixedToInt(fixedY) + 128);
468    }
469
470    if(timeElapsed > msTravel*250 && !doneTraveling) {
471        doneTraveling = true;
472    }
473    if(doneTraveling) {
474        outX = destX;
475        outY = destY;
476    }
477}
478
479void limitOutputs(const uint16_t sampleSpacing,//in units of 4us
480                  const abtest whichAB,
481                  const InputState &inputs,
482                  const OutputState &rawOutputIn,
483                  OutputState &finalOutput) {
484    //First, we want to check if the raw output has changed.
485    //If it has changed, then we need to store it with a timestamp in our buffer.
486    //Also check whether it's an "easy" coordinate or not (rim+origin = easy)
487    //Then, we need to parse the buffer and detect whether:
488    //  an empty pivot has likely occurred (0.5 to 1.5 frames?) ============ this depends on our travel time implementation unless we store the analog value history too
489    //    how?
490    //    (make you do a 2f jump input if you input an upward tilt coordinate within 10 frames)
491    //    (lock out the A press if you input a downward tilt coordinate for 3 frames)
492    //  the input is crouching
493    //    (make you do a 2f jump input if you input an upward tilt coordinate within 4 frames)
494    //  rapid quarter circling (wank di)
495    //    lock out second diagonal (opposite axis). May not be important with neutral SOCD.
496    //  rapid tapping (tap di)
497    //    Temporarily increase travel time to... 16 ms? 24ms?
498    //  rapid eighth-circling (cardinal diagonal neutral repeat)
499    //    Increase travel time on cardinal and lock out later diagonals.
500
501    static bool doneTraveling = true;
502
503    static uint16_t currentTime = 0;
504    currentTime++;
505
506    static shortstate aHistory[HISTORYLEN];
507    static sdizonestate sdiZoneHist[HISTORYLEN];
508    static pivotzonestate pivotZoneHist[HISTORYLEN];
509
510    static InputState prevInputs;
511
512    static bool initialized = false;
513    if(!initialized) {
514        for(int i = 0; i<HISTORYLEN; i++) {
515            aHistory[i].timestamp = 0;
516            aHistory[i].tt = 6;
517            aHistory[i].x = ANALOG_STICK_NEUTRAL;
518            aHistory[i].y = ANALOG_STICK_NEUTRAL;
519            aHistory[i].x_start = ANALOG_STICK_NEUTRAL;
520            aHistory[i].y_start = ANALOG_STICK_NEUTRAL;
521            aHistory[i].x_end = ANALOG_STICK_NEUTRAL;
522            aHistory[i].y_end = ANALOG_STICK_NEUTRAL;
523            sdiZoneHist[i].timestamp = 0;
524            sdiZoneHist[i].zone = 0;
525            sdiZoneHist[i].stale = true;
526            pivotZoneHist[i].timestamp = 0;
527            pivotZoneHist[i].zone = 0;
528            pivotZoneHist[i].stale = true;
529        }
530        //track the inputs that can cause changes to coordinates
531        prevInputs.lf3 = inputs.lf3;//left;
532        prevInputs.lf1 = inputs.lf1;//right;
533        prevInputs.lf2 = inputs.lf2;//down;
534        prevInputs.rf4 = inputs.rf4;//up;
535        prevInputs.rt3 = inputs.rt3;//c_left;
536        prevInputs.rt5 = inputs.rt5;//c_right;
537        prevInputs.rt2 = inputs.rt2;//c_down;
538        prevInputs.rt4 = inputs.rt4;//c_up;
539        prevInputs.rf1 = inputs.rf1;//b;
540        prevInputs.lf4 = inputs.lf4;//l;//we don't care about recording these
541        prevInputs.rf5 = inputs.rf5;//r;
542        prevInputs.rf7 = inputs.rf7;//lightshield;
543        prevInputs.rf8 = inputs.rf8;//midshield;
544        prevInputs.lt1 = inputs.lt1;//mod_x;
545        prevInputs.lt2 = inputs.lt2;//mod_y;
546
547        initialized = true;
548    }
549    static uint8_t currentIndexA = 0;
550    static uint8_t currentIndexSDI = 0;
551
552    static travelType delayType = T_Lin;
553
554    //calculate whether to do a airdodge travel adjustment or not
555    //we want to continue the previous travel time, but if it's an airdodge with a prohibited angle destination, we overwrite the angle.
556    //this way the travel itself never skips straight to the destination.
557
558    //if L or R has been pressed
559    // if the coordinates changed
560    //  if they need to be nerfed
561    //   nerf them
562    //  else
563    //   if L or R caused the coordinate change
564    //    set the travel time destination to the new coordinate
565    // if the coordinates are in a nerf region (but haven't been corrected yet)
566    //  nerf them
567    //if L or R has just been released
568    // if it was nerfing them, un-nerf them
569    bool wavedashSkip = false;
570    static bool wavedashWasNerfed = false;
571    if(inputs.lf4/*l*/ || inputs.rf5/*r*/) {
572        //check angles to see if it's in a shallow wavedash region
573        //the trigger was the only input that changed, potentially causing a retargeting without restarting the travel time
574        const uint8_t xIn = rawOutputIn.leftStickX;
575        const uint8_t yIn = rawOutputIn.leftStickY;
576        uint8_t x_end = xIn;
577        uint8_t y_end = yIn;
578
579        //calculate magnitudes
580        const uint16_t xInMag = xIn > ANALOG_STICK_NEUTRAL ? xIn - ANALOG_STICK_NEUTRAL : ANALOG_STICK_NEUTRAL - xIn;
581        const uint16_t yInMag = yIn > ANALOG_STICK_NEUTRAL ? yIn - ANALOG_STICK_NEUTRAL : ANALOG_STICK_NEUTRAL - yIn;
582
583        //calculate radius (squared)
584        const uint16_t xsquared = xInMag*xInMag;
585        const uint16_t ysquared = yInMag*yInMag;
586        const uint16_t radSquared = xsquared+ysquared;
587
588        //if the coordinates changed
589        if(aHistory[currentIndexA].x != rawOutputIn.leftStickX || aHistory[currentIndexA].y != rawOutputIn.leftStickY) {
590            //if the angle moved, check whether the currently requested angle is too shallow
591            //if so, nerf it, regardless of whether it was nerfed before.
592            if(((yInMag * 157 < xInMag * 80) || (xInMag * 157 < yInMag * 80)) && xInMag && yInMag) { //157 and 80 are the closest ratio to 27 degrees (27.0013)
593                //the closest coordinate inside the melee unit circle to 27 degrees is 51 and 26 (27.0127)
594                const uint8_t longCoord  = radSquared > 5625 ? 70 : 51;
595                const uint8_t shortCoord = radSquared > 5625 ? 36 : 26;
596                const uint8_t xWavedash = xInMag > yInMag ? longCoord : shortCoord;
597                const uint8_t yWavedash = yInMag > xInMag ? longCoord : shortCoord;
598                //overwrite with a nerfed angle
599                if(xIn < ANALOG_STICK_NEUTRAL) {
600                    x_end = ANALOG_STICK_NEUTRAL - xWavedash;
601                } else {
602                    x_end = ANALOG_STICK_NEUTRAL + xWavedash;
603                }
604                if(yIn < ANALOG_STICK_NEUTRAL) {
605                    y_end = ANALOG_STICK_NEUTRAL - yWavedash;
606                } else {
607                    y_end = ANALOG_STICK_NEUTRAL + yWavedash;
608                }
609                //fuzz it
610                randomizeCoord(x_end, y_end, currentTime);
611                //write it back
612                aHistory[currentIndexA].x_end = x_end;
613                aHistory[currentIndexA].y_end = y_end;
614                //also record the new requested coordinates
615                aHistory[currentIndexA].x = rawOutputIn.leftStickX;
616                aHistory[currentIndexA].y = rawOutputIn.leftStickY;
617                //mark as having been nerfed so we can undo it later
618                wavedashWasNerfed = true;
619            } else {
620                wavedashWasNerfed = false;
621                //only skip inputs if the L or R press caused the change in coordinates
622                if(!(prevInputs.lf4 /*l*/ || prevInputs.rf5 /*r*/)) {
623                    //check if the L/R press coincides with a change in coordinate, indicating L/R NDM
624                    if(
625                        prevInputs.lf3 == inputs.lf3 /*left*/ &&
626                        prevInputs.lf1 == inputs.lf1 /*right*/ &&
627                        prevInputs.lf2 == inputs.lf2 /*down*/ &&
628                        prevInputs.rf4 == inputs.rf4 /*up*/ &&
629                        prevInputs.rt3 == inputs.rt3 /*c_left*/ &&
630                        prevInputs.rt5 == inputs.rt5 /*c_right*/ &&
631                        prevInputs.rt2 == inputs.rt2 /*c_down*/ &&
632                        prevInputs.rt4 == inputs.rt4 /*c_up*/ &&
633                        prevInputs.rf1 == inputs.rf1 /*b*/ &&
634                        prevInputs.rf7 == inputs.rf7 /*lightshield*/ &&
635                        prevInputs.rf8 == inputs.rf8 /*midshield*/ &&
636                        prevInputs.lt1 == inputs.lt1 /*mod_x*/ &&
637                        prevInputs.lt2 == inputs.lt2 /*mod_y*/
638                    ) {
639                        //then we need to skip to the new coordinate
640                        //fuzz it
641                        randomizeCoord(x_end, y_end, currentTime);
642                        //write it back
643                        aHistory[currentIndexA].x_end = x_end;
644                        aHistory[currentIndexA].y_end = y_end;
645                        //also record the new requested coordinates
646                        aHistory[currentIndexA].x = rawOutputIn.leftStickX;
647                        aHistory[currentIndexA].y = rawOutputIn.leftStickY;
648                        //mark this change as having been skipped so we don't restart travel time later
649                        wavedashSkip = true;
650                    }
651                }
652            }
653        }
654        //even if pressing L or R didn't move the coordinate, but it is now illegal
655        //nerf it
656        if(((yInMag * 157 < xInMag * 80) || (xInMag * 157 < yInMag * 80)) && xInMag && yInMag && !wavedashWasNerfed) { //157 and 80 are the closest ratio to 27 degrees (27.0013)
657            //the closest coordinate inside the melee unit circle to 27 degrees is 51 and 26 (27.0127)
658            const uint8_t xWavedash = xInMag > yInMag ? 51 : 26;
659            const uint8_t yWavedash = yInMag > xInMag ? 51 : 26;
660            //overwrite with a nerfed angle
661            if(xIn < ANALOG_STICK_NEUTRAL) {
662                x_end = ANALOG_STICK_NEUTRAL - xWavedash;
663            } else {
664                x_end = ANALOG_STICK_NEUTRAL + xWavedash;
665            }
666            if(yIn < ANALOG_STICK_NEUTRAL) {
667                y_end = ANALOG_STICK_NEUTRAL - yWavedash;
668            } else {
669                y_end = ANALOG_STICK_NEUTRAL + yWavedash;
670            }
671            //fuzz it
672            randomizeCoord(x_end, y_end, currentTime);
673            //write it back
674            aHistory[currentIndexA].x_end = x_end;
675            aHistory[currentIndexA].y_end = y_end;
676            //mark as having been nerfed so we can undo it later
677            wavedashWasNerfed = true;
678        }
679    } else if(!(inputs.lf4 /*l*/ || inputs.rf5/*r*/) && (prevInputs.lf4 /*l*/ || prevInputs.rf5/*r*/)) {
680        //if nerfed, then de-nerf once L and R are no longer pressed
681        if(wavedashWasNerfed) {
682            const uint8_t xIn = rawOutputIn.leftStickX;
683            const uint8_t yIn = rawOutputIn.leftStickY;
684            uint8_t x_end = xIn;
685            uint8_t y_end = yIn;
686            //fuzz it again
687            randomizeCoord(x_end, y_end, currentTime);
688            //write it back
689            aHistory[currentIndexA].x_end = x_end;
690            aHistory[currentIndexA].y_end = y_end;
691            wavedashWasNerfed = false;
692        }
693    }
694    //record previous inputs
695    prevInputs.lf3 = inputs.lf3;//left;
696    prevInputs.lf1 = inputs.lf1;//right;
697    prevInputs.lf2 = inputs.lf2;//down;
698    prevInputs.rf4 = inputs.rf4;//up;
699    prevInputs.rt3 = inputs.rt3;//c_left;
700    prevInputs.rt5 = inputs.rt5;//c_right;
701    prevInputs.rt2 = inputs.rt2;//c_down;
702    prevInputs.rt4 = inputs.rt4;//c_up;
703    prevInputs.rf1 = inputs.rf1;//b;
704    prevInputs.lf4 = inputs.lf4;//l;//we don't care about recording these
705    prevInputs.rf5 = inputs.rf5;//r;
706    prevInputs.rf7 = inputs.rf7;//lightshield;
707    prevInputs.rf8 = inputs.rf8;//midshield;
708    prevInputs.lt1 = inputs.lt1;//mod_x;
709    prevInputs.lt2 = inputs.lt2;//mod_y;
710
711    //calculate travel from the previous step
712    uint8_t prelimAX = rawOutputIn.leftStickX;
713    uint8_t prelimAY = rawOutputIn.leftStickY;
714    uint8_t prelimCX = rawOutputIn.rightStickX;
715    uint8_t prelimCY = rawOutputIn.rightStickY;
716
717    //test for SDI in the raw inputs
718    const uint8_t tapSDI = isTapSDI(sdiZoneHist, currentIndexSDI, currentTime, sampleSpacing);
719    //if cardinal tap SDI
720    if(tapSDI & BITS_SDI_TAP_CARD) {
721        aHistory[currentIndexA].tt = max(aHistory[currentIndexA].tt, TRAVELTIME_SLOW);
722        delayType = T_Lin;
723    }
724    //if oscillating about a diagonal
725    static uint16_t sdiCountdown = 0;
726    if((tapSDI & BITS_SDI_WANK) && (tapSDI & BITS_SDI_TAP_CRDG)) {
727        //both wank&cardiag indicates that it was oscillating about a diagonal
728        //new destinations will have 5.5 frame travel time for a duration of 4 frames from the last sdi detection event
729        sdiCountdown = TIMELIMIT_SDI_COUNTDOWN;
730        //prelimCX = ANALOG_STICK_NEUTRAL - 50;
731    }
732    if(sdiCountdown > sampleSpacing) {
733        sdiCountdown = sdiCountdown - sampleSpacing;
734        aHistory[currentIndexA].tt = max(aHistory[currentIndexA].tt, TRAVELTIME_SLOW);
735    } else {
736        sdiCountdown = 0;
737    }
738
739    travelTimeCalc(currentTime,
740                   aHistory[currentIndexA].timestamp,
741                   sampleSpacing,
742                   aHistory[currentIndexA].tt,
743                   aHistory[currentIndexA].x_start,
744                   aHistory[currentIndexA].y_start,
745                   aHistory[currentIndexA].x_end,
746                   aHistory[currentIndexA].y_end,
747                   delayType,
748                   doneTraveling,
749                   prelimAX,
750                   prelimAY);
751
752    //detect an input that gives >50% pivot probability given travel time
753    //if we are in a new pivot zone, record the new zone
754    //we're keeping these in sequence so we copy them all
755    if(pivotZoneHist[0].zone != pivotZone(prelimAX)) {
756        for(int i = HISTORYLEN-2; i >= 0; i--) {
757            pivotZoneHist[i+1].timestamp = pivotZoneHist[i].timestamp;
758            pivotZoneHist[i+1].zone = pivotZoneHist[i].zone;
759            pivotZoneHist[i+1].stale = pivotZoneHist[i].stale;
760        }
761
762        pivotZoneHist[0].timestamp = currentTime;
763        pivotZoneHist[0].zone = pivotZone(prelimAX);
764        pivotZoneHist[0].stale = false;
765    }
766    for(int i = 0; i < HISTORYLEN; i++) {
767        if((currentTime-pivotZoneHist[i].timestamp) * (sampleSpacing>>1) > 15*16*125) { //15 frames
768            pivotZoneHist[i].stale = true;
769        }
770    }
771
772    //pivot inputs:
773    //current--------------------past
774    //---neutral ----left ---neutral ---right
775    //---neutral ----left ---right
776    //---neutral ---right ---neutral ---left
777    //---neutral ---right ---left
778    //start time of neutral minus
779    //  start time of ^ between 0.5 and 1.5 frames
780    //current time minus start time of neutral should be used to limit how long the nerf applies for
781    pivotdir direction = P_None;
782    if(pivotZoneHist[0].zone == 0) {
783        if(pivotZoneHist[1].zone == ZONE_L && (pivotZoneHist[2].zone == ZONE_R || pivotZoneHist[3].zone == ZONE_R)) {
784            direction = P_Rightleft;
785        } else if(pivotZoneHist[1].zone == ZONE_R && (pivotZoneHist[2].zone == ZONE_L || pivotZoneHist[3].zone == ZONE_L)) {
786            direction = P_Leftright;
787        }
788    }
789    uint16_t pivotLength = (pivotZoneHist[0].timestamp - pivotZoneHist[1].timestamp)*sampleSpacing;
790    if(pivotLength < TIMELIMIT_HALFFRAME || pivotLength > TIMELIMIT_FRAME+TIMELIMIT_HALFFRAME) {
791        //less than 50% chance it was a successful pivot
792        direction = P_None;
793    }
794    //check for staleness
795    if(pivotZoneHist[3].stale || pivotZoneHist[2].stale || pivotZoneHist[1].stale || pivotZoneHist[0].stale) {
796        //if the previous movement was more than 15 frames earlier
797        direction = P_None;
798    }
799
800    uint16_t pivotAge = (currentTime - pivotZoneHist[0].timestamp)*sampleSpacing;
801    if(pivotAge > TIMELIMIT_PIVOTTILT) {
802        direction = P_None;
803    }
804
805    //tap jump shutoff
806    static uint8_t uptiltSamples = 0;
807    if(prelimAY > ANALOG_DEAD_MAX) {
808        uptiltSamples = min(uptiltSamples+1,254);
809    } else {
810        uptiltSamples = 0;
811    }
812    const uint16_t timeSinceNotUptilt = uptiltSamples*sampleSpacing;
813
814    //actually apply the nerfs
815    //debug c-stick output
816    /*
817    if(direction != P_None) {
818        prelimCY = 255;
819    }
820    */
821    //if it's a downtilt coordinate...
822    bool pivotTilt = false;
823    bool upTilt = false;
824    //if(direction != P_None && prelimAY < ANALOG_DEAD_MIN) {
825    if(direction != P_None && aHistory[currentIndexA].y_end < ANALOG_DEAD_MIN) {
826        pivotTilt = true;
827    }
828    //if it's a uptilt coordinate...
829    //if(direction != P_None && prelimAY > ANALOG_DEAD_MAX) {
830    if(direction != P_None && aHistory[currentIndexA].y_end > ANALOG_DEAD_MAX) {
831        pivotTilt = true;
832        upTilt = true;
833    }
834    if(pivotTilt) {
835        //If there's a pivot tilt, preserve the angle as best as possible but maximize the radius
836        int8_t xCoord = prelimAX - ANALOG_STICK_NEUTRAL;
837        int8_t yCoord = prelimAY - ANALOG_STICK_NEUTRAL;
838        uint8_t xCoordAbs = abs(xCoord);
839        uint8_t yCoordAbs = abs(yCoord);
840
841        if(upTilt && xCoordAbs > yCoordAbs) {
842            //Force all upward angles to a minimum of 45deg to prevent pivot uftilt and ensure tap jump
843            prelimAX = ANALOG_STICK_NEUTRAL + (xCoord >= 0 ? 127 : -127);
844            prelimAY = ANALOG_STICK_NEUTRAL + 127;
845        } else {
846            //Scale magnitude as close as we can get to 127 in increments of 0.5
847            //Quick way to ensure we get above 80 magnitude with minimal rounding errors
848            uint8_t stretchMult = (uint8_t)(127 * 2) / max(xCoordAbs, yCoordAbs);
849            prelimAX = ANALOG_STICK_NEUTRAL + xCoord * stretchMult / 2;
850            prelimAY = ANALOG_STICK_NEUTRAL + yCoord * stretchMult / 2;
851        }
852        if(upTilt && timeSinceNotUptilt > TIMELIMIT_TAPSHUTOFF) {
853            //the x direction got flipped to avoid affecting diagonals
854            if(direction == P_Leftright) {
855                prelimAX = ANALOG_STICK_NEUTRAL + 56;
856            } else if(direction == P_Rightleft) {
857                prelimAX = ANALOG_STICK_NEUTRAL - 56;
858            }
859            prelimAY = ANALOG_STICK_NEUTRAL + 56;
860        }
861    }
862
863    //if it's a crouch to upward coordinate too quickly, make Y jump even if a tilt was desired
864    static uint16_t timeSinceCrouch = 100;//must be < 65535 when multiplied by 500, the longest possible sampleSpacing, but bigger than the (timelimit/250)
865    static bool downUpJumping;
866    static uint16_t timeSinceJump = 100;
867
868    //increment timeSinceCrouch unless you have crouched
869    timeSinceCrouch = min(timeSinceCrouch+1, 100);
870    if(prelimAY < ANALOG_CROUCH) {
871        timeSinceCrouch = 0;
872    }
873
874    //increment timeSinceJump unless you want to trigger a jump
875    timeSinceJump = min(timeSinceJump+1, 100);
876    if(timeSinceCrouch*sampleSpacing < TIMELIMIT_DOWNUP
877        && prelimAY > ANALOG_DEAD_MAX
878        && prelimAY < ANALOG_TAPJUMP
879        && prelimAX > ANALOG_UTILT_LEFT
880        && prelimAX < ANALOG_UTILT_RIGHT
881        && !downUpJumping) {
882        downUpJumping = true;
883        timeSinceJump = 0;
884    }
885
886    if(timeSinceJump*sampleSpacing < JUMP_TIME && downUpJumping) {
887        prelimAY = 255;
888        timeSinceCrouch = 100;//prevent an extra duration jump if the jump ends before the lockout window
889    } else {
890        downUpJumping = false;
891    }
892
893    //if it's wank sdi (TODO) or diagonal tap SDI, lock out the cross axis
894    //we use the sdi variable from earlier
895    static bool sdiIsNerfed = false;//only for lockouts, not travel time
896    if(tapSDI & (BITS_SDI_TAP_DIAG | BITS_SDI_TAP_CRDG | BITS_SDI_WANK)){
897        if(tapSDI & (ZONE_L | ZONE_R)) {
898            //lock the cross axis
899            prelimAY = ANALOG_STICK_NEUTRAL;
900            //make sure future cross axis travel time begins at the origin
901            aHistory[currentIndexA].y_end = prelimAY;
902            //the following is disabled because the sdi threshold is actually 0.7
903            //prevent the cardinal axis from dipping below the sdi threshold by preserving its coordinate
904            //prelimAX = aHistory[currentIndexA].x_start;
905            //make sure that future cardinal travel time begins where it was before
906            //aHistory[currentIndexA].x_end = prelimAX;
907            sdiIsNerfed = true;
908            //prelimCX = ANALOG_STICK_NEUTRAL + 50;
909        } else if(tapSDI & (ZONE_U | ZONE_D)) {
910            //lock the cross axis
911            prelimAX = ANALOG_STICK_NEUTRAL;
912            //make sure future cross axis travel time begins at the origin
913            aHistory[currentIndexA].x_end = prelimAX;
914            //the following is disabled because the sdi threshold is actually 0.7
915            //prevent the cardinal axis from dipping below the sdi threshold by preserving its coordinate
916            //prelimAY = aHistory[currentIndexA].y_start;
917            //make sure that future cardinal travel time begins where it was before
918            //aHistory[currentIndexA].y_end = prelimAY;
919            sdiIsNerfed = true;
920            //prelimCX = ANALOG_STICK_NEUTRAL - 50;
921        }//one or the other should occur
922        //debug to see if SDI was detected
923        /*
924        if(tapSDI & BITS_SDI_TAP_CARD) {
925            prelimCY = ANALOG_STICK_NEUTRAL + 50;
926        }
927        if(tapSDI & BITS_SDI_TAP_CRDG) {
928            prelimCY = ANALOG_STICK_NEUTRAL - 50;
929        }
930        if(tapSDI & BITS_SDI_WANK) {
931            prelimCY = ANALOG_STICK_NEUTRAL + 120;
932        }
933        */
934    } else if(sdiIsNerfed) {
935        aHistory[currentIndexA].x_end = aHistory[currentIndexA].x;
936        aHistory[currentIndexA].y_end = aHistory[currentIndexA].y;
937        if(prelimAX == ANALOG_STICK_NEUTRAL && prelimAY == ANALOG_STICK_NEUTRAL) {
938            sdiIsNerfed = false;
939        }
940    }
941
942    //==================================recording history======================================//
943
944    //if we are in a new SDI zone, record the new zone
945    if(sdiZoneHist[currentIndexSDI].zone != sdiZone(rawOutputIn.leftStickX, rawOutputIn.leftStickY)) {
946        currentIndexSDI = (currentIndexSDI + 1) % HISTORYLEN;
947
948        sdiZoneHist[currentIndexSDI].timestamp = currentTime;
949        sdiZoneHist[currentIndexSDI].zone = sdiZone(rawOutputIn.leftStickX, rawOutputIn.leftStickY);
950        sdiZoneHist[currentIndexSDI].stale = false;
951    }
952    for(int i = 0; i < HISTORYLEN; i++) {
953        if(currentTime-sdiZoneHist[i].timestamp > 8*16*2) {//8 frames * 16 ms * max 2 samples
954            sdiZoneHist[i].stale = true;
955        }
956    }
957
958    //if we have a new coordinate, record the new info, the travel time'd locked out stick coordinate, and set travel time
959    const uint8_t xIn = rawOutputIn.leftStickX;
960    const uint8_t yIn = rawOutputIn.leftStickY;
961    static uint8_t prevX = xIn;
962    static uint8_t prevY = yIn;
963    //prelimAY = 5*currentIndexA;//we found that there are no new inputs causing the jumps
964    //prelimAY = currentTime % 256;//we found that time isn't jumping
965    if(prevX != xIn || prevY != yIn) {
966        //don't update things if this is a wavedash in a banned region
967        if(!wavedashSkip) {
968            doneTraveling = false;
969            const uint8_t oldIndexA = currentIndexA;
970            currentIndexA = (currentIndexA + 1) % HISTORYLEN;
971
972            prevX = xIn;
973            prevY = yIn;
974
975            uint8_t xInRand = xIn;
976            uint8_t yInRand = yIn;
977            randomizeCoord(xInRand, yInRand, currentTime);
978
979            aHistory[currentIndexA].timestamp = currentTime;
980            aHistory[currentIndexA].x = xIn;
981            aHistory[currentIndexA].y = yIn;
982            aHistory[currentIndexA].x_end = xInRand;
983            aHistory[currentIndexA].y_end = yInRand;
984            aHistory[currentIndexA].x_start = prelimAX;
985            aHistory[currentIndexA].y_start = prelimAY;
986
987            //make the initial travel begin instantly 1 unit towards the destination
988            if(prelimAX == prevX) {
989                if(xInRand > prevX) {
990                    aHistory[currentIndexA].x_start++;
991                }
992                if(xInRand < prevX) {
993                    aHistory[currentIndexA].x_start--;
994                }
995            }
996            if(prelimAY == prevY) {
997                if(yInRand > prevY) {
998                    aHistory[currentIndexA].y_start++;
999                }
1000                if(yInRand < prevY) {
1001                    aHistory[currentIndexA].y_start--;
1002                }
1003            }
1004
1005            uint8_t prelimTT = TRAVELTIME_EASY3;
1006            //if the destination is not an "easy" coordinate
1007            const uint8_t easiness = isEasy(xIn, yIn);
1008            if(easiness == 1) {
1009                prelimTT = TRAVELTIME_EASY1;
1010                delayType = T_Lin;
1011            } else if(easiness == 2) {
1012                prelimTT = TRAVELTIME_EASY2;
1013                delayType = T_Lin;
1014            } else if(easiness == 3) {
1015                prelimTT = TRAVELTIME_EASY3;
1016                delayType = T_Lin;
1017            } else {
1018                prelimTT = TRAVELTIME_INTERNAL;
1019                delayType = T_Lin;
1020            }
1021            //prelimTT = TRAVELTIME_SLOW;//========================debug
1022            aHistory[currentIndexA].tt = prelimTT;
1023        }
1024    }
1025
1026    //===============================applying the nerfed coords=================================//
1027    finalOutput.a               = rawOutputIn.a;
1028    finalOutput.b               = rawOutputIn.b;
1029    finalOutput.x               = rawOutputIn.x;
1030    finalOutput.y               = rawOutputIn.y;
1031    finalOutput.buttonL         = rawOutputIn.buttonL;
1032    finalOutput.buttonR         = rawOutputIn.buttonR;
1033    finalOutput.triggerLDigital = rawOutputIn.triggerLDigital;
1034    finalOutput.triggerRDigital = rawOutputIn.triggerRDigital;
1035    finalOutput.start           = rawOutputIn.start;
1036    finalOutput.select          = rawOutputIn.select;
1037    finalOutput.home            = rawOutputIn.home;
1038    finalOutput.dpadUp          = rawOutputIn.dpadUp;
1039    finalOutput.dpadDown        = rawOutputIn.dpadDown;
1040    finalOutput.dpadLeft        = rawOutputIn.dpadLeft;
1041    finalOutput.dpadRight       = rawOutputIn.dpadRight;
1042    finalOutput.leftStickClick  = rawOutputIn.leftStickClick;
1043    finalOutput.rightStickClick = rawOutputIn.rightStickClick;
1044    finalOutput.leftStickX      = prelimAX;
1045    finalOutput.leftStickY      = prelimAY;
1046    finalOutput.rightStickX     = prelimCX;
1047    finalOutput.rightStickY     = prelimCY;
1048    finalOutput.triggerLAnalog  = rawOutputIn.triggerLAnalog;
1049    finalOutput.triggerRAnalog  = rawOutputIn.triggerRAnalog;
1050}