comparison src/compass.c @ 620:cd986267a5ca

potential compass bug "fixed"
author heinrichsweikamp
date Fri, 22 Feb 2019 16:30:05 +0100
parents ca4556fb60b9
children 1ad0531e9078
comparison
equal deleted inserted replaced
619:e76a87e087ef 620:cd986267a5ca
65 /// represented as 0..32767. 65 /// represented as 0..32767.
66 66
67 Int16 udiv(PARAMETER Int16 a, PARAMETER Int16 b) 67 Int16 udiv(PARAMETER Int16 a, PARAMETER Int16 b)
68 { 68 {
69 OVERLAY Int16 d, r; 69 OVERLAY Int16 d, r;
70 70 OVERLAY char failsafe=250;
71
71 //---- Pre-scale both numerator and denominator -------------------------- 72 //---- Pre-scale both numerator and denominator --------------------------
72 while( (((a>>8) | (b>>8)) & 0xC0) == 0 ) 73 while( (((a>>8) | (b>>8)) & 0xC0) == 0 )
73 { 74 {
75 failsafe--;
76 if (failsafe==0) break;
74 a <<= 1; 77 a <<= 1;
75 b <<= 1; 78 b <<= 1;
76 } 79 }
77 80
78 //---- Make division trials ---------------------------------------------- 81 //---- Make division trials ----------------------------------------------
171 /// 174 ///
172 175
173 void sincos(PARAMETER Int16 x, PARAMETER Int16 y, Int16* sin, Int16* cos) 176 void sincos(PARAMETER Int16 x, PARAMETER Int16 y, Int16* sin, Int16* cos)
174 { 177 {
175 OVERLAY Int16 x2, y2, h2; 178 OVERLAY Int16 x2, y2, h2;
179 OVERLAY char failsafe = 250;
176 180
177 //---- Fold into one quadant --------------------------------------------- 181 //---- Fold into one quadant ---------------------------------------------
178 OVERLAY char neg = 0; 182 OVERLAY char neg = 0;
179 if( x < 0 ) 183 if( x < 0 )
180 { 184 {
188 } 192 }
189 193
190 //---- Pre-scale both numerator and denominator ---------------------- 194 //---- Pre-scale both numerator and denominator ----------------------
191 while( (((x>>8) | (y>>8)) & 0xE0) == 0 ) 195 while( (((x>>8) | (y>>8)) & 0xE0) == 0 )
192 { 196 {
197 failsafe--;
198 if (failsafe == 0) break;
193 x <<= 1; 199 x <<= 1;
194 y <<= 1; 200 y <<= 1;
195 } 201 }
196 202
197 //---- Uses trig() to do the stuff one on quadrant ------------------- 203 //---- Uses trig() to do the stuff one on quadrant -------------------