Rev Author Line No. Line
1045 jacho 1 CCS PCM C Compiler, Version 4.106, 47914 05-5-13 12:54
2  
3 Filename: C:\Users\Honza\Documents\pic\azimut\main.lst
4  
5 ROM used: 4548 words (56%)
6 Largest free fragment is 2048
7 RAM used: 32 (9%) at main() level
8 97 (26%) worst case
9 Stack: 4 locations
10  
11 *
12 0000: MOVLW 10
13 0001: MOVWF 0A
14 0002: GOTO 0AD
15 0003: NOP
16 .................... #include "C:\Users\Honza\Documents\pic\azimut\main.h"
17 .................... #include <16F887.h>
18 .................... //////// Standard Header file for the PIC16F887 device ////////////////
19 .................... #device PIC16F887
20 .................... #list
21 ....................
22 .................... #device adc=8
23 ....................
24 .................... #FUSES NOWDT //No Watch Dog Timer
25 .................... #FUSES INTRC //Internal RC Osc
26 .................... #FUSES NOPUT //No Power Up Timer
27 .................... #FUSES MCLR //Master Clear pin enabled
28 .................... #FUSES NOPROTECT //Code not protected from reading
29 .................... #FUSES NOCPD //No EE protection
30 .................... #FUSES NOBROWNOUT //No brownout reset
31 .................... #FUSES IESO //Internal External Switch Over mode enabled
32 .................... #FUSES FCMEN //Fail-safe clock monitor enabled
33 .................... #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
34 .................... #FUSES NODEBUG //No Debug mode for ICD
35 .................... #FUSES NOWRT //Program memory not write protected
36 .................... #FUSES BORV40 //Brownout reset at 4.0V
37 ....................
38 .................... #use delay(clock=8000000)
39 *
40 015D: MOVLW 4F
41 015E: MOVWF 04
42 015F: BCF 03.7
43 0160: MOVF 00,W
44 0161: BTFSC 03.2
45 0162: GOTO 170
46 0163: MOVLW 02
47 0164: MOVWF 78
48 0165: CLRF 77
49 0166: DECFSZ 77,F
50 0167: GOTO 166
51 0168: DECFSZ 78,F
52 0169: GOTO 165
53 016A: MOVLW 97
54 016B: MOVWF 77
55 016C: DECFSZ 77,F
56 016D: GOTO 16C
57 016E: DECFSZ 00,F
58 016F: GOTO 163
59 0170: RETURN
60 ....................
61 ....................
62 ....................
63 .................... #define PIN_SDA PIN_C4
64 .................... #define PIN_SCL PIN_C3
65 .................... #use i2c(master, sda=PIN_SDA, scl=PIN_SCL)
66 *
67 00D8: MOVLW 08
68 00D9: MOVWF 78
69 00DA: NOP
70 00DB: BCF 07.3
71 00DC: BCF 20.3
72 00DD: MOVF 20,W
73 00DE: BSF 03.5
74 00DF: MOVWF 07
75 00E0: NOP
76 00E1: BCF 03.5
77 00E2: RLF 5D,F
78 00E3: BCF 07.4
79 00E4: BTFSS 03.0
80 00E5: GOTO 0EC
81 00E6: BSF 20.4
82 00E7: MOVF 20,W
83 00E8: BSF 03.5
84 00E9: MOVWF 07
85 00EA: GOTO 0F0
86 00EB: BCF 03.5
87 00EC: BCF 20.4
88 00ED: MOVF 20,W
89 00EE: BSF 03.5
90 00EF: MOVWF 07
91 00F0: NOP
92 00F1: BCF 03.5
93 00F2: BSF 20.3
94 00F3: MOVF 20,W
95 00F4: BSF 03.5
96 00F5: MOVWF 07
97 00F6: BCF 03.5
98 00F7: BTFSS 07.3
99 00F8: GOTO 0F7
100 00F9: DECFSZ 78,F
101 00FA: GOTO 0DA
102 00FB: NOP
103 00FC: BCF 07.3
104 00FD: BCF 20.3
105 00FE: MOVF 20,W
106 00FF: BSF 03.5
107 0100: MOVWF 07
108 0101: NOP
109 0102: BCF 03.5
110 0103: BSF 20.4
111 0104: MOVF 20,W
112 0105: BSF 03.5
113 0106: MOVWF 07
114 0107: NOP
115 0108: NOP
116 0109: BCF 03.5
117 010A: BSF 20.3
118 010B: MOVF 20,W
119 010C: BSF 03.5
120 010D: MOVWF 07
121 010E: BCF 03.5
122 010F: BTFSS 07.3
123 0110: GOTO 10F
124 0111: CLRF 78
125 0112: NOP
126 0113: BTFSC 07.4
127 0114: BSF 78.0
128 0115: BCF 07.3
129 0116: BCF 20.3
130 0117: MOVF 20,W
131 0118: BSF 03.5
132 0119: MOVWF 07
133 011A: BCF 03.5
134 011B: BCF 07.4
135 011C: BCF 20.4
136 011D: MOVF 20,W
137 011E: BSF 03.5
138 011F: MOVWF 07
139 0120: BCF 03.5
140 0121: RETURN
141 *
142 038F: MOVLW 08
143 0390: MOVWF 5E
144 0391: MOVF 77,W
145 0392: MOVWF 5F
146 0393: BSF 20.4
147 0394: MOVF 20,W
148 0395: BSF 03.5
149 0396: MOVWF 07
150 0397: NOP
151 0398: BCF 03.5
152 0399: BSF 20.3
153 039A: MOVF 20,W
154 039B: BSF 03.5
155 039C: MOVWF 07
156 039D: BCF 03.5
157 039E: BTFSS 07.3
158 039F: GOTO 39E
159 03A0: BTFSC 07.4
160 03A1: BSF 03.0
161 03A2: BTFSS 07.4
162 03A3: BCF 03.0
163 03A4: RLF 78,F
164 03A5: NOP
165 03A6: BCF 20.3
166 03A7: MOVF 20,W
167 03A8: BSF 03.5
168 03A9: MOVWF 07
169 03AA: BCF 03.5
170 03AB: BCF 07.3
171 03AC: DECFSZ 5E,F
172 03AD: GOTO 393
173 03AE: BSF 20.4
174 03AF: MOVF 20,W
175 03B0: BSF 03.5
176 03B1: MOVWF 07
177 03B2: NOP
178 03B3: BCF 03.5
179 03B4: BCF 07.4
180 03B5: MOVF 5F,W
181 03B6: BTFSC 03.2
182 03B7: GOTO 3BD
183 03B8: BCF 20.4
184 03B9: MOVF 20,W
185 03BA: BSF 03.5
186 03BB: MOVWF 07
187 03BC: BCF 03.5
188 03BD: NOP
189 03BE: BSF 20.3
190 03BF: MOVF 20,W
191 03C0: BSF 03.5
192 03C1: MOVWF 07
193 03C2: BCF 03.5
194 03C3: BTFSS 07.3
195 03C4: GOTO 3C3
196 03C5: NOP
197 03C6: BCF 07.3
198 03C7: BCF 20.3
199 03C8: MOVF 20,W
200 03C9: BSF 03.5
201 03CA: MOVWF 07
202 03CB: NOP
203 03CC: BCF 03.5
204 03CD: BCF 07.4
205 03CE: BCF 20.4
206 03CF: MOVF 20,W
207 03D0: BSF 03.5
208 03D1: MOVWF 07
209 03D2: BCF 03.5
210 03D3: RETURN
211 .................... #use rs232(baud=9600,parity=N,xmit=PIN_C7,rcv=PIN_C6,bits=8) //rcv TXD xmit RXD
212 *
213 0222: BCF 20.7
214 0223: MOVF 20,W
215 0224: BSF 03.5
216 0225: MOVWF 07
217 0226: BCF 03.5
218 0227: BCF 07.7
219 0228: MOVLW 08
220 0229: MOVWF 78
221 022A: GOTO 22B
222 022B: NOP
223 022C: BSF 78.7
224 022D: GOTO 23C
225 022E: BCF 78.7
226 022F: RRF 59,F
227 0230: BTFSC 03.0
228 0231: BSF 07.7
229 0232: BTFSS 03.0
230 0233: BCF 07.7
231 0234: BSF 78.6
232 0235: GOTO 23C
233 0236: BCF 78.6
234 0237: DECFSZ 78,F
235 0238: GOTO 22F
236 0239: GOTO 23A
237 023A: NOP
238 023B: BSF 07.7
239 023C: MOVLW 3F
240 023D: MOVWF 04
241 023E: DECFSZ 04,F
242 023F: GOTO 23E
243 0240: NOP
244 0241: BTFSC 78.7
245 0242: GOTO 22E
246 0243: BTFSC 78.6
247 0244: GOTO 236
248 0245: RETURN
249 *
250 028E: BSF 20.6
251 028F: MOVF 20,W
252 0290: BSF 03.5
253 0291: MOVWF 07
254 0292: BCF 03.5
255 0293: BTFSC 07.6
256 0294: GOTO 293
257 0295: MOVLW 08
258 0296: MOVWF 77
259 0297: CLRF 49
260 0298: BSF 77.7
261 0299: GOTO 2A8
262 029A: BCF 77.7
263 029B: GOTO 2A8
264 029C: BCF 03.0
265 029D: BTFSC 07.6
266 029E: BSF 03.0
267 029F: RRF 49,F
268 02A0: BSF 77.6
269 02A1: GOTO 2A8
270 02A2: BCF 77.6
271 02A3: DECFSZ 77,F
272 02A4: GOTO 29C
273 02A5: MOVF 49,W
274 02A6: MOVWF 78
275 02A7: GOTO 2B3
276 02A8: MOVLW 3F
277 02A9: BTFSC 77.7
278 02AA: MOVLW 11
279 02AB: MOVWF 78
280 02AC: DECFSZ 78,F
281 02AD: GOTO 2AC
282 02AE: BTFSC 77.7
283 02AF: GOTO 29A
284 02B0: BTFSC 77.6
285 02B1: GOTO 2A2
286 02B2: GOTO 29C
287 02B3: RETURN
288 .................... #include <math.h>
289 .................... ////////////////////////////////////////////////////////////////////////////
290 .................... //// (C) Copyright 1996,2008 Custom Computer Services ////
291 .................... //// This source code may only be used by licensed users of the CCS C ////
292 .................... //// compiler. This source code may only be distributed to other ////
293 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
294 .................... //// or distribution is permitted without written permission. ////
295 .................... //// Derivative programs created using this software in object code ////
296 .................... //// form are not restricted in any way. ////
297 .................... ////////////////////////////////////////////////////////////////////////////
298 .................... //// ////
299 .................... //// History: ////
300 .................... //// * 9/20/2001 : Improvments are made to sin/cos code. ////
301 .................... //// The code now is small, much faster, ////
302 .................... //// and more accurate. ////
303 .................... //// * 2/21/2007 : Compiler handles & operator differently and does
304 .................... //// not return generic (int8 *) so type cast is done ////
305 .................... //// ////
306 .................... ////////////////////////////////////////////////////////////////////////////
307 ....................
308 .................... #ifndef MATH_H
309 .................... #define MATH_H
310 ....................
311 .................... #ifdef PI
312 .................... #undef PI
313 .................... #endif
314 .................... #define PI 3.1415926535897932
315 ....................
316 ....................
317 .................... #define SQRT2 1.4142135623730950
318 ....................
319 .................... //float const ps[4] = {5.9304945, 21.125224, 8.9403076, 0.29730279};
320 .................... //float const qs[4] = {1.0000000, 15.035723, 17.764134, 2.4934718};
321 ....................
322 .................... ///////////////////////////// Round Functions //////////////////////////////
323 ....................
324 .................... float32 CEIL_FLOOR(float32 x, unsigned int8 n)
325 .................... {
326 .................... float32 y, res;
327 .................... unsigned int16 l;
328 .................... int1 s;
329 ....................
330 .................... s = 0;
331 .................... y = x;
332 ....................
333 .................... if (x < 0)
334 .................... {
335 .................... s = 1;
336 .................... y = -y;
337 .................... }
338 ....................
339 .................... if (y <= 32768.0)
340 .................... res = (float32)(unsigned int16)y;
341 ....................
342 .................... else if (y < 10000000.0)
343 .................... {
344 .................... l = (unsigned int16)(y/32768.0);
345 .................... y = 32768.0*(y/32768.0 - (float32)l);
346 .................... res = 32768.0*(float32)l;
347 .................... res += (float32)(unsigned int16)y;
348 .................... }
349 ....................
350 .................... else
351 .................... res = y;
352 ....................
353 .................... y = y - (float32)(unsigned int16)y;
354 ....................
355 .................... if (s)
356 .................... res = -res;
357 ....................
358 .................... if (y != 0)
359 .................... {
360 .................... if (s == 1 && n == 0)
361 .................... res -= 1.0;
362 ....................
363 .................... if (s == 0 && n == 1)
364 .................... res += 1.0;
365 .................... }
366 .................... if (x == 0)
367 .................... res = 0;
368 ....................
369 .................... return (res);
370 .................... }
371 ....................
372 .................... // Overloaded Functions to take care for new Data types in PCD
373 .................... // Overloaded function CEIL_FLOOR() for data type - Float48
374 .................... #if defined(__PCD__)
375 .................... float48 CEIL_FLOOR(float48 x, unsigned int8 n)
376 .................... {
377 .................... float48 y, res;
378 .................... unsigned int16 l;
379 .................... int1 s;
380 ....................
381 .................... s = 0;
382 .................... y = x;
383 ....................
384 .................... if (x < 0)
385 .................... {
386 .................... s = 1;
387 .................... y = -y;
388 .................... }
389 ....................
390 .................... if (y <= 32768.0)
391 .................... res = (float48)(unsigned int16)y;
392 ....................
393 .................... else if (y < 10000000.0)
394 .................... {
395 .................... l = (unsigned int16)(y/32768.0);
396 .................... y = 32768.0*(y/32768.0 - (float48)l);
397 .................... res = 32768.0*(float32)l;
398 .................... res += (float48)(unsigned int16)y;
399 .................... }
400 ....................
401 .................... else
402 .................... res = y;
403 ....................
404 .................... y = y - (float48)(unsigned int16)y;
405 ....................
406 .................... if (s)
407 .................... res = -res;
408 ....................
409 .................... if (y != 0)
410 .................... {
411 .................... if (s == 1 && n == 0)
412 .................... res -= 1.0;
413 ....................
414 .................... if (s == 0 && n == 1)
415 .................... res += 1.0;
416 .................... }
417 .................... if (x == 0)
418 .................... res = 0;
419 ....................
420 .................... return (res);
421 .................... }
422 ....................
423 ....................
424 .................... // Overloaded function CEIL_FLOOR() for data type - Float64
425 .................... float64 CEIL_FLOOR(float64 x, unsigned int8 n)
426 .................... {
427 .................... float64 y, res;
428 .................... unsigned int16 l;
429 .................... int1 s;
430 ....................
431 .................... s = 0;
432 .................... y = x;
433 ....................
434 .................... if (x < 0)
435 .................... {
436 .................... s = 1;
437 .................... y = -y;
438 .................... }
439 ....................
440 .................... if (y <= 32768.0)
441 .................... res = (float64)(unsigned int16)y;
442 ....................
443 .................... else if (y < 10000000.0)
444 .................... {
445 .................... l = (unsigned int16)(y/32768.0);
446 .................... y = 32768.0*(y/32768.0 - (float64)l);
447 .................... res = 32768.0*(float64)l;
448 .................... res += (float64)(unsigned int16)y;
449 .................... }
450 ....................
451 .................... else
452 .................... res = y;
453 ....................
454 .................... y = y - (float64)(unsigned int16)y;
455 ....................
456 .................... if (s)
457 .................... res = -res;
458 ....................
459 .................... if (y != 0)
460 .................... {
461 .................... if (s == 1 && n == 0)
462 .................... res -= 1.0;
463 ....................
464 .................... if (s == 0 && n == 1)
465 .................... res += 1.0;
466 .................... }
467 .................... if (x == 0)
468 .................... res = 0;
469 ....................
470 .................... return (res);
471 .................... }
472 .................... #endif
473 ....................
474 .................... ////////////////////////////////////////////////////////////////////////////
475 .................... // float floor(float x)
476 .................... ////////////////////////////////////////////////////////////////////////////
477 .................... // Description : rounds down the number x.
478 .................... // Date : N/A
479 .................... //
480 .................... float32 floor(float32 x)
481 .................... {
482 .................... return CEIL_FLOOR(x, 0);
483 .................... }
484 .................... // Following 2 functions are overloaded functions of floor() for PCD
485 .................... // Overloaded function floor() for data type - Float48
486 .................... #if defined(__PCD__)
487 .................... float48 floor(float48 x)
488 .................... {
489 .................... return CEIL_FLOOR(x, 0);
490 .................... }
491 ....................
492 .................... // Overloaded function floor() for data type - Float64
493 .................... float64 floor(float64 x)
494 .................... {
495 .................... return CEIL_FLOOR(x, 0);
496 .................... }
497 .................... #endif
498 ....................
499 ....................
500 .................... ////////////////////////////////////////////////////////////////////////////
501 .................... // float ceil(float x)
502 .................... ////////////////////////////////////////////////////////////////////////////
503 .................... // Description : rounds up the number x.
504 .................... // Date : N/A
505 .................... //
506 .................... float32 ceil(float32 x)
507 .................... {
508 .................... return CEIL_FLOOR(x, 1);
509 .................... }
510 .................... // Following 2 functions are overloaded functions of ceil() for PCD
511 .................... // Overloaded function ceil() for data type - Float48
512 .................... #if defined(__PCD__)
513 .................... float48 ceil(float48 x)
514 .................... {
515 .................... return CEIL_FLOOR(x, 1);
516 .................... }
517 ....................
518 .................... // Overloaded function ceil() for data type - Float64
519 .................... float64 ceil(float64 x)
520 .................... {
521 .................... return CEIL_FLOOR(x, 1);
522 .................... }
523 .................... #endif
524 ....................
525 .................... ////////////////////////////////////////////////////////////////////////////
526 .................... // float fabs(float x)
527 .................... ////////////////////////////////////////////////////////////////////////////
528 .................... // Description : Computes the absolute value of floating point number x
529 .................... // Returns : returns the absolute value of x
530 .................... // Date : N/A
531 .................... //
532 .................... #define fabs abs
533 ....................
534 .................... ////////////////////////////////////////////////////////////////////////////
535 .................... // float fmod(float x)
536 .................... ////////////////////////////////////////////////////////////////////////////
537 .................... // Description : Computes the floating point remainder of x/y
538 .................... // Returns : returns the value of x= i*y, for some integer i such that, if y
539 .................... // is non zero, the result has the same isgn of x na dmagnitude less than the
540 .................... // magnitude of y. If y is zero then a domain error occurs.
541 .................... // Date : N/A
542 .................... //
543 ....................
544 .................... float fmod(float32 x,float32 y)
545 .................... {
546 .................... float32 i;
547 .................... if (y!=0.0)
548 .................... {
549 .................... i=(x/y < 0.0)? ceil(x/y): floor(x/y);
550 .................... return(x-(i*y));
551 .................... }
552 .................... else
553 .................... {
554 .................... #ifdef _ERRNO
555 .................... {
556 .................... errno=EDOM;
557 .................... }
558 .................... #endif
559 .................... }
560 .................... }
561 .................... //Overloaded function for fmod() for PCD
562 .................... // Overloaded function fmod() for data type - Float48
563 .................... #if defined(__PCD__)
564 .................... float48 fmod(float48 x,float48 y)
565 .................... {
566 .................... float48 i;
567 .................... if (y!=0.0)
568 .................... {
569 .................... i=(x/y < 0.0)? ceil(x/y): floor(x/y);
570 .................... return(x-(i*y));
571 .................... }
572 .................... else
573 .................... {
574 .................... #ifdef _ERRNO
575 .................... {
576 .................... errno=EDOM;
577 .................... }
578 .................... #endif
579 .................... }
580 .................... }
581 .................... // Overloaded function fmod() for data type - Float64
582 .................... float64 fmod(float64 x,float64 y)
583 .................... {
584 .................... float64 i;
585 .................... if (y!=0.0)
586 .................... {
587 .................... i=(x/y < 0.0)? ceil(x/y): floor(x/y);
588 .................... return(x-(i*y));
589 .................... }
590 .................... else
591 .................... {
592 .................... #ifdef _ERRNO
593 .................... {
594 .................... errno=EDOM;
595 .................... }
596 .................... #endif
597 .................... }
598 .................... }
599 .................... #endif
600 .................... //////////////////// Exponential and logarithmic functions ////////////////////
601 .................... ////////////////////////////////////////////////////////////////////////////
602 .................... // float exp(float x)
603 .................... ////////////////////////////////////////////////////////////////////////////
604 .................... // Description : returns the value (e^x)
605 .................... // Date : N/A
606 .................... //
607 .................... #define LN2 0.6931471805599453
608 ....................
609 .................... float const pe[6] = {0.000207455774, 0.00127100575, 0.00965065093,
610 .................... 0.0554965651, 0.240227138, 0.693147172};
611 ....................
612 ....................
613 .................... float32 exp(float32 x)
614 .................... {
615 .................... float32 y, res, r;
616 .................... #if defined(__PCD__)
617 .................... int8 data1;
618 .................... #endif
619 .................... signed int8 n;
620 .................... int1 s;
621 .................... #ifdef _ERRNO
622 .................... if(x > 88.722838)
623 .................... {
624 .................... errno=ERANGE;
625 .................... return(0);
626 .................... }
627 .................... #endif
628 .................... n = (signed int16)(x/LN2);
629 .................... s = 0;
630 .................... y = x;
631 ....................
632 .................... if (x < 0)
633 .................... {
634 .................... s = 1;
635 .................... n = -n;
636 .................... y = -y;
637 .................... }
638 ....................
639 .................... res = 0.0;
640 .................... #if !defined(__PCD__)
641 .................... *((unsigned int8 *)(&res)) = n + 0x7F;
642 .................... #endif
643 ....................
644 .................... #if defined(__PCD__) // Takes care of IEEE format for PCD
645 .................... data1 = n+0x7F;
646 .................... if(bit_test(data1,0))
647 .................... bit_set(*(((unsigned int8 *)(&res)+2)),7);
648 .................... rotate_right(&data1,1);
649 .................... bit_clear(data1,7);
650 .................... *(((unsigned int8 *)(&res)+3)) = data1;
651 .................... #endif
652 ....................
653 .................... y = y/LN2 - (float32)n;
654 ....................
655 .................... r = pe[0]*y + pe[1];
656 .................... r = r*y + pe[2];
657 .................... r = r*y + pe[3];
658 .................... r = r*y + pe[4];
659 .................... r = r*y + pe[5];
660 ....................
661 .................... res = res*(1.0 + y*r);
662 ....................
663 .................... if (s)
664 .................... res = 1.0/res;
665 .................... return(res);
666 .................... }
667 ....................
668 ....................
669 .................... //Overloaded function for exp() for PCD
670 .................... // Overloaded function exp() for data type - Float48
671 .................... #if defined(__PCD__)
672 .................... float48 exp(float48 x)
673 .................... {
674 .................... float48 y, res, r;
675 .................... int8 data1;
676 .................... signed int8 n;
677 .................... int1 s;
678 .................... #ifdef _ERRNO
679 .................... if(x > 88.722838)
680 .................... {
681 .................... errno=ERANGE;
682 .................... return(0);
683 .................... }
684 .................... #endif
685 .................... n = (signed int16)(x/LN2);
686 .................... s = 0;
687 .................... y = x;
688 ....................
689 .................... if (x < 0)
690 .................... {
691 .................... s = 1;
692 .................... n = -n;
693 .................... y = -y;
694 .................... }
695 ....................
696 .................... res = 0.0;
697 ....................
698 .................... data1 = n+0x7F;
699 .................... if(bit_test(data1,0))
700 .................... bit_set(*(((unsigned int8 *)(&res)+4)),7);
701 .................... rotate_right(&data1,1);
702 .................... bit_clear(data1,7);
703 .................... *(((unsigned int8 *)(&res)+5)) = data1;
704 ....................
705 .................... y = y/LN2 - (float48)n;
706 ....................
707 .................... r = pe[0]*y + pe[1];
708 .................... r = r*y + pe[2];
709 .................... r = r*y + pe[3];
710 .................... r = r*y + pe[4];
711 .................... r = r*y + pe[5];
712 ....................
713 .................... res = res*(1.0 + y*r);
714 ....................
715 .................... if (s)
716 .................... res = 1.0/res;
717 .................... return(res);
718 .................... }
719 ....................
720 .................... // Overloaded function exp() for data type - Float64
721 .................... float64 exp(float64 x)
722 .................... {
723 .................... float64 y, res, r;
724 .................... unsigned int16 data1, data2;
725 .................... unsigned int16 *p;
726 .................... signed int16 n;
727 .................... int1 s;
728 .................... #ifdef _ERRNO
729 .................... if(x > 709.7827128)
730 .................... {
731 .................... errno=ERANGE;
732 .................... return(0);
733 .................... }
734 .................... #endif
735 .................... n = (signed int16)(x/LN2);
736 .................... s = 0;
737 .................... y = x;
738 ....................
739 .................... if (x < 0)
740 .................... {
741 .................... s = 1;
742 .................... n = -n;
743 .................... y = -y;
744 .................... }
745 ....................
746 .................... res = 0.0;
747 ....................
748 .................... #if !defined(__PCD__)
749 .................... *((unsigned int16 *)(&res)) = n + 0x7F;
750 .................... #endif
751 .................... p= (((unsigned int16 *)(&res))+3);
752 .................... data1 = *p;
753 .................... data2 = *p;
754 .................... data1 = n + 0x3FF;
755 .................... data1 = data1 <<4;
756 .................... if(bit_test(data2,15))
757 .................... bit_set(data1,15);
758 .................... data2 = data2 & 0x000F;
759 .................... data1 ^= data2;
760 ....................
761 .................... *(((unsigned int16 *)(&res)+3)) = data1;
762 ....................
763 ....................
764 .................... y = y/LN2 - (float64)n;
765 ....................
766 .................... r = pe[0]*y + pe[1];
767 .................... r = r*y + pe[2];
768 .................... r = r*y + pe[3];
769 .................... r = r*y + pe[4];
770 .................... r = r*y + pe[5];
771 ....................
772 .................... res = res*(1.0 + y*r);
773 ....................
774 .................... if (s)
775 .................... res = 1.0/res;
776 .................... return(res);
777 .................... }
778 ....................
779 .................... #ENDIF
780 ....................
781 ....................
782 .................... /************************************************************/
783 ....................
784 .................... float32 const pl[4] = {0.45145214, -9.0558803, 26.940971, -19.860189};
785 .................... float32 const ql[4] = {1.0000000, -8.1354259, 16.780517, -9.9300943};
786 ....................
787 .................... ////////////////////////////////////////////////////////////////////////////
788 .................... // float log(float x)
789 .................... ////////////////////////////////////////////////////////////////////////////
790 .................... // Description : returns the the natural log of x
791 .................... // Date : N/A
792 .................... //
793 .................... float32 log(float32 x)
794 .................... {
795 .................... float32 y, res, r, y2;
796 .................... #if defined(__PCD__)
797 .................... unsigned int8 data1,data2;
798 .................... #endif
799 .................... signed int8 n;
800 .................... #ifdef _ERRNO
801 .................... if(x <0)
802 .................... {
803 .................... errno=EDOM;
804 .................... }
805 .................... if(x ==0)
806 .................... {
807 .................... errno=ERANGE;
808 .................... return(0);
809 .................... }
810 .................... #endif
811 .................... y = x;
812 ....................
813 .................... if (y != 1.0)
814 .................... {
815 .................... #if !defined(__PCD__)
816 .................... *((unsigned int8 *)(&y)) = 0x7E;
817 .................... #endif
818 ....................
819 .................... #if defined(__PCD__) // Takes care of IEEE format
820 .................... data2 = *(((unsigned int8 *)(&y))+3);
821 .................... *(((unsigned int8 *)(&y))+3) = 0x3F;
822 .................... data1 = *(((unsigned int8 *)(&y))+2);
823 .................... bit_clear(data1,7);
824 .................... *(((unsigned int8 *)(&y))+2) = data1;
825 .................... if(bit_test(data2,7))
826 .................... bit_set(*(((unsigned int8 *)(&y))+3),7);
827 .................... #endif
828 ....................
829 .................... y = (y - 1.0)/(y + 1.0);
830 ....................
831 .................... y2=y*y;
832 ....................
833 .................... res = pl[0]*y2 + pl[1];
834 .................... res = res*y2 + pl[2];
835 .................... res = res*y2 + pl[3];
836 ....................
837 .................... r = ql[0]*y2 + ql[1];
838 .................... r = r*y2 + ql[2];
839 .................... r = r*y2 + ql[3];
840 ....................
841 .................... res = y*res/r;
842 .................... #if !defined(__PCD__)
843 .................... n = *((unsigned int8 *)(&x)) - 0x7E;
844 .................... #endif
845 .................... #if defined(__PCD__)
846 .................... data1 = *(((unsigned int8 *)(&x)+3));
847 .................... rotate_left(&data1,1);
848 .................... data2 = *(((unsigned int8 *)(&x)+2));
849 .................... if(bit_test (data2,7))
850 .................... bit_set(data1,0);
851 .................... n = data1 - 0x7E;
852 .................... #endif
853 ....................
854 .................... if (n<0)
855 .................... r = -(float32)-n;
856 .................... else
857 .................... r = (float32)n;
858 ....................
859 .................... res += r*LN2;
860 .................... }
861 ....................
862 .................... else
863 .................... res = 0.0;
864 ....................
865 .................... return(res);
866 .................... }
867 ....................
868 .................... //Overloaded function for log() for PCD
869 .................... // Overloaded function log() for data type - Float48
870 .................... #if defined(__PCD__)
871 .................... float48 log(float48 x)
872 .................... {
873 .................... float48 y, res, r, y2;
874 .................... unsigned int8 data1,data2;
875 .................... signed int8 n;
876 .................... #ifdef _ERRNO
877 .................... if(x <0)
878 .................... {
879 .................... errno=EDOM;
880 .................... }
881 .................... if(x ==0)
882 .................... {
883 .................... errno=ERANGE;
884 .................... return(0);
885 .................... }
886 .................... #endif
887 .................... y = x;
888 ....................
889 .................... if (y != 1.0)
890 .................... {
891 ....................
892 .................... #if !defined(__PCD__)
893 .................... *((unsigned int8 *)(&y)) = 0x7E;
894 .................... #endif
895 .................... data2 = *(((unsigned int8 *)(&y))+5);
896 .................... *(((unsigned int8 *)(&y))+5) = 0x3F;
897 .................... data1 = *(((unsigned int8 *)(&y))+4);
898 .................... bit_clear(data1,7);
899 .................... *(((unsigned int8 *)(&y))+4) = data1;
900 ....................
901 .................... if(bit_test(data2,7))
902 .................... bit_set(*(((unsigned int8 *)(&y))+4),7);
903 .................... y = (y - 1.0)/(y + 1.0);
904 ....................
905 .................... y2=y*y;
906 ....................
907 .................... res = pl[0]*y2 + pl[1];
908 .................... res = res*y2 + pl[2];
909 .................... res = res*y2 + pl[3];
910 ....................
911 .................... r = ql[0]*y2 + ql[1];
912 .................... r = r*y2 + ql[2];
913 .................... r = r*y2 + ql[3];
914 ....................
915 .................... res = y*res/r;
916 ....................
917 .................... data1 = *(((unsigned int8 *)(&x)+5));
918 .................... rotate_left(&data1,1);
919 .................... data2 = *(((unsigned int8 *)(&x)+4));
920 .................... if(bit_test (data2,7))
921 .................... bit_set(data1,0);
922 ....................
923 .................... n = data1 - 0x7E;
924 ....................
925 .................... if (n<0)
926 .................... r = -(float48)-n;
927 .................... else
928 .................... r = (float48)n;
929 ....................
930 .................... res += r*LN2;
931 .................... }
932 ....................
933 .................... else
934 .................... res = 0.0;
935 ....................
936 .................... return(res);
937 .................... }
938 ....................
939 .................... // Overloaded function log() for data type - Float48
940 .................... #if defined(__PCD__)
941 .................... float32 const pl_64[4] = {0.45145214, -9.0558803, 26.940971, -19.860189};
942 .................... float32 const ql_64[4] = {1.0000000, -8.1354259, 16.780517, -9.9300943};
943 .................... #endif
944 .................... float64 log(float64 x)
945 .................... {
946 .................... float64 y, res, r, y2;
947 .................... unsigned int16 data1,data2;
948 .................... unsigned int16 *p;
949 .................... signed int16 n;
950 .................... #ifdef _ERRNO
951 .................... if(x <0)
952 .................... {
953 .................... errno=EDOM;
954 .................... }
955 .................... if(x ==0)
956 .................... {
957 .................... errno=ERANGE;
958 .................... return(0);
959 .................... }
960 .................... #endif
961 .................... y = x;
962 ....................
963 .................... if (y != 1.0)
964 .................... {
965 .................... #if !defined(__PCD__)
966 .................... *((unsigned int8 *)(&y)) = 0x7E;
967 .................... #endif
968 .................... p= (((unsigned int16 *)(&y))+3);
969 .................... data1 = *p;
970 .................... data2 = *p;
971 .................... data1 = 0x3FE;
972 .................... data1 = data1 <<4;
973 .................... if(bit_test (data2,15))
974 .................... bit_set(data1,15);
975 .................... data2 = data2 & 0x000F;
976 .................... data1 ^=data2;
977 ....................
978 .................... *p = data1;
979 ....................
980 .................... y = (y - 1.0)/(y + 1.0);
981 ....................
982 .................... y2=y*y;
983 ....................
984 .................... res = pl_64[0]*y2 + pl_64[1];
985 .................... res = res*y2 + pl_64[2];
986 .................... res = res*y2 + pl_64[3];
987 ....................
988 .................... r = ql_64[0]*y2 + ql_64[1];
989 .................... r = r*y2 + ql_64[2];
990 .................... r = r*y2 + ql_64[3];
991 ....................
992 .................... res = y*res/r;
993 ....................
994 .................... p= (((unsigned int16 *)(&x))+3);
995 .................... data1 = *p;
996 .................... bit_clear(data1,15);
997 .................... data1 = data1 >>4;
998 .................... n = data1 - 0x3FE;
999 ....................
1000 ....................
1001 .................... if (n<0)
1002 .................... r = -(float64)-n;
1003 .................... else
1004 .................... r = (float64)n;
1005 ....................
1006 .................... res += r*LN2;
1007 .................... }
1008 ....................
1009 .................... else
1010 .................... res = 0.0;
1011 ....................
1012 .................... return(res);
1013 .................... }
1014 .................... #endif
1015 ....................
1016 ....................
1017 .................... #define LN10 2.3025850929940456
1018 ....................
1019 .................... ////////////////////////////////////////////////////////////////////////////
1020 .................... // float log10(float x)
1021 .................... ////////////////////////////////////////////////////////////////////////////
1022 .................... // Description : returns the the log base 10 of x
1023 .................... // Date : N/A
1024 .................... //
1025 .................... float32 log10(float32 x)
1026 .................... {
1027 .................... float32 r;
1028 ....................
1029 .................... r = log(x);
1030 .................... r = r/LN10;
1031 .................... return(r);
1032 .................... }
1033 ....................
1034 .................... //Overloaded functions for log10() for PCD
1035 .................... // Overloaded function log10() for data type - Float48
1036 .................... #if defined(__PCD__)
1037 .................... float48 log10(float48 x)
1038 .................... {
1039 .................... float48 r;
1040 ....................
1041 .................... r = log(x);
1042 .................... r = r/LN10;
1043 .................... return(r);
1044 .................... }
1045 ....................
1046 .................... // Overloaded function log10() for data type - Float64
1047 .................... float64 log10(float64 x)
1048 .................... {
1049 .................... float64 r;
1050 ....................
1051 .................... r = log(x);
1052 .................... r = r/LN10;
1053 .................... return(r);
1054 .................... }
1055 .................... #endif
1056 .................... ////////////////////////////////////////////////////////////////////////////
1057 .................... // float modf(float x)
1058 .................... ////////////////////////////////////////////////////////////////////////////
1059 .................... // Description :breaks the argument value int integral and fractional parts,
1060 .................... // ach of which have the same sign as the argument. It stores the integral part
1061 .................... // as a float in the object pointed to by the iptr
1062 .................... // Returns : returns the signed fractional part of value.
1063 .................... // Date : N/A
1064 .................... //
1065 ....................
1066 .................... float32 modf(float32 value,float32 *iptr)
1067 .................... {
1068 .................... *iptr=(value < 0.0)? ceil(value): floor(value);
1069 .................... return(value - *iptr);
1070 .................... }
1071 .................... //Overloaded functions for modf() for PCD
1072 .................... // Overloaded function modf() for data type - Float48
1073 .................... #if defined(__PCD__)
1074 .................... float48 modf(float48 value,float48 *iptr)
1075 .................... {
1076 .................... *iptr=(value < 0.0)? ceil(value): floor(value);
1077 .................... return(value - *iptr);
1078 .................... }
1079 .................... // Overloaded function modf() for data type - Float64
1080 .................... float64 modf(float64 value,float64 *iptr)
1081 .................... {
1082 .................... *iptr=(value < 0.0)? ceil(value): floor(value);
1083 .................... return(value - *iptr);
1084 .................... }
1085 .................... #endif
1086 ....................
1087 .................... ////////////////////////////////////////////////////////////////////////////
1088 .................... // float pwr(float x,float y)
1089 .................... ////////////////////////////////////////////////////////////////////////////
1090 .................... // Description : returns the value (x^y)
1091 .................... // Date : N/A
1092 .................... // Note : 0 is returned when the function will generate an imaginary number
1093 .................... //
1094 .................... float32 pwr(float32 x,float32 y)
1095 .................... {
1096 .................... if(0 > x && fmod(y, 1) == 0) {
1097 .................... if(fmod(y, 2) == 0) {
1098 .................... return (exp(log(-x) * y));
1099 .................... } else {
1100 .................... return (-exp(log(-x) * y));
1101 .................... }
1102 .................... } else if(0 > x && fmod(y, 1) != 0) {
1103 .................... return 0;
1104 .................... } else {
1105 .................... if(x != 0 || 0 >= y) {
1106 .................... return (exp(log(x) * y));
1107 .................... }
1108 .................... }
1109 .................... }
1110 .................... //Overloaded functions for pwr() for PCD
1111 .................... // Overloaded function pwr() for data type - Float48
1112 .................... #if defined(__PCD__)
1113 .................... float48 pwr(float48 x,float48 y)
1114 .................... {
1115 .................... if(0 > x && fmod(y, 1) == 0) {
1116 .................... if(fmod(y, 2) == 0) {
1117 .................... return (exp(log(-x) * y));
1118 .................... } else {
1119 .................... return (-exp(log(-x) * y));
1120 .................... }
1121 .................... } else if(0 > x && fmod(y, 1) != 0) {
1122 .................... return 0;
1123 .................... } else {
1124 .................... if(x != 0 || 0 >= y) {
1125 .................... return (exp(log(x) * y));
1126 .................... }
1127 .................... }
1128 .................... }
1129 .................... // Overloaded function pwr() for data type - Float64
1130 .................... float64 pwr(float64 x,float64 y)
1131 .................... {
1132 .................... if(0 > x && fmod(y, 1) == 0) {
1133 .................... if(fmod(y, 2) == 0) {
1134 .................... return (exp(log(-x) * y));
1135 .................... } else {
1136 .................... return (-exp(log(-x) * y));
1137 .................... }
1138 .................... } else if(0 > x && fmod(y, 1) != 0) {
1139 .................... return 0;
1140 .................... } else {
1141 .................... if(x != 0 || 0 >= y) {
1142 .................... return (exp(log(x) * y));
1143 .................... }
1144 .................... }
1145 .................... }
1146 .................... #endif
1147 ....................
1148 .................... //////////////////// Power functions ////////////////////
1149 ....................
1150 .................... ////////////////////////////////////////////////////////////////////////////
1151 .................... // float pow(float x,float y)
1152 .................... ////////////////////////////////////////////////////////////////////////////
1153 .................... // Description : returns the value (x^y)
1154 .................... // Date : N/A
1155 .................... // Note : 0 is returned when the function will generate an imaginary number
1156 .................... //
1157 .................... float32 pow(float32 x,float32 y)
1158 .................... {
1159 .................... if(0 > x && fmod(y, 1) == 0) {
1160 .................... if(fmod(y, 2) == 0) {
1161 .................... return (exp(log(-x) * y));
1162 .................... } else {
1163 .................... return (-exp(log(-x) * y));
1164 .................... }
1165 .................... } else if(0 > x && fmod(y, 1) != 0) {
1166 .................... return 0;
1167 .................... } else {
1168 .................... if(x != 0 || 0 >= y) {
1169 .................... return (exp(log(x) * y));
1170 .................... }
1171 .................... }
1172 .................... }
1173 .................... //Overloaded functions for pow() for PCD
1174 .................... // Overloaded function for pow() data type - Float48
1175 .................... #if defined(__PCD__)
1176 .................... float48 pow(float48 x,float48 y)
1177 .................... {
1178 .................... if(0 > x && fmod(y, 1) == 0) {
1179 .................... if(fmod(y, 2) == 0) {
1180 .................... return (exp(log(-x) * y));
1181 .................... } else {
1182 .................... return (-exp(log(-x) * y));
1183 .................... }
1184 .................... } else if(0 > x && fmod(y, 1) != 0) {
1185 .................... return 0;
1186 .................... } else {
1187 .................... if(x != 0 || 0 >= y) {
1188 .................... return (exp(log(x) * y));
1189 .................... }
1190 .................... }
1191 .................... }
1192 ....................
1193 .................... // Overloaded function pow() for data type - Float64
1194 .................... float64 pow(float64 x,float64 y)
1195 .................... {
1196 .................... if(0 > x && fmod(y, 1) == 0) {
1197 .................... if(fmod(y, 2) == 0) {
1198 .................... return (exp(log(-x) * y));
1199 .................... } else {
1200 .................... return (-exp(log(-x) * y));
1201 .................... }
1202 .................... } else if(0 > x && fmod(y, 1) != 0) {
1203 .................... return 0;
1204 .................... } else {
1205 .................... if(x != 0 || 0 >= y) {
1206 .................... return (exp(log(x) * y));
1207 .................... }
1208 .................... }
1209 .................... }
1210 .................... #endif
1211 ....................
1212 .................... ////////////////////////////////////////////////////////////////////////////
1213 .................... // float sqrt(float x)
1214 .................... ////////////////////////////////////////////////////////////////////////////
1215 .................... // Description : returns the square root of x
1216 .................... // Date : N/A
1217 .................... //
1218 .................... float32 sqrt(float32 x)
1219 .................... {
1220 .................... float32 y, res;
1221 .................... #if defined(__PCD__)
1222 .................... unsigned int16 data1,data2;
1223 .................... #endif
1224 .................... BYTE *p;
1225 ....................
1226 .................... #ifdef _ERRNO
1227 .................... if(x < 0)
1228 .................... {
1229 .................... errno=EDOM;
1230 .................... }
1231 .................... #endif
1232 ....................
1233 .................... if( x<=0.0)
1234 .................... return(0.0);
1235 ....................
1236 .................... y=x;
1237 ....................
1238 .................... #if !defined(__PCD__)
1239 .................... p=&y;
1240 .................... (*p)=(BYTE)((((unsigned int16)(*p)) + 127) >> 1);
1241 .................... #endif
1242 ....................
1243 .................... #if defined(__PCD__)
1244 .................... p = (((unsigned int8 *)(&y))+3);
1245 .................... data1 = *(((unsigned int8 *)(&y))+3);
1246 .................... data2 = *(((unsigned int8 *)(&y))+2);
1247 .................... rotate_left(&data1,1);
1248 .................... if(bit_test(data2,7))
1249 .................... bit_set(data1,0);
1250 .................... data1 = ((data1+127) >>1);
1251 .................... bit_clear(data2,7);
1252 .................... if(bit_test(data1,0))
1253 .................... bit_set(data2,7);
1254 .................... data1 = data1 >>1;
1255 .................... *(((unsigned int8 *)(&y))+3) = data1;
1256 .................... *(((unsigned int8 *)(&y))+2) = data2;
1257 ....................
1258 .................... #endif
1259 ....................
1260 .................... do {
1261 .................... res=y;
1262 .................... y+=(x/y);
1263 ....................
1264 .................... #if !defined(__PCD__)
1265 .................... (*p)--;
1266 .................... #endif
1267 ....................
1268 .................... #if defined(__PCD__)
1269 .................... data1 = *(((unsigned int8 *)(&y))+3);
1270 .................... data2 = *(((unsigned int8 *)(&y))+2);
1271 .................... rotate_left(&data1,1);
1272 .................... if(bit_test(data2,7))
1273 .................... bit_set(data1,0);
1274 .................... data1--;
1275 .................... bit_clear(data2,7);
1276 .................... if(bit_test(data1,0))
1277 .................... bit_set(data2,7);
1278 .................... data1 = data1 >>1;
1279 .................... *(((unsigned int8 *)(&y))+3) = data1;
1280 .................... *(((unsigned int8 *)(&y))+2) = data2;
1281 ....................
1282 .................... #endif
1283 .................... } while(res != y);
1284 ....................
1285 .................... return(res);
1286 .................... }
1287 .................... //Overloaded functions for sqrt() for PCD
1288 .................... // Overloaded function sqrt() for data type - Float48
1289 .................... #if defined(__PCD__)
1290 .................... float48 sqrt(float48 x)
1291 .................... {
1292 .................... float48 y, res;
1293 .................... unsigned int16 data1,data2;
1294 .................... BYTE *p;
1295 ....................
1296 .................... #ifdef _ERRNO
1297 .................... if(x < 0)
1298 .................... {
1299 .................... errno=EDOM;
1300 .................... }
1301 .................... #endif
1302 ....................
1303 .................... if( x<=0.0)
1304 .................... return(0.0);
1305 ....................
1306 .................... y=x;
1307 ....................
1308 .................... #if !defined(__PCD__)
1309 .................... p=&y;
1310 .................... (*p)=(BYTE)((((unsigned int16)(*p)) + 127) >> 1);
1311 .................... #endif
1312 ....................
1313 .................... #if defined(__PCD__)
1314 .................... p = (((unsigned int8 *)(&y))+5);
1315 .................... data1 = *(((unsigned int8 *)(&y))+5);
1316 .................... data2 = *(((unsigned int8 *)(&y))+4);
1317 .................... rotate_left(&data1,1);
1318 .................... if(bit_test(data2,7))
1319 .................... bit_set(data1,0);
1320 .................... data1 = ((data1+127) >>1);
1321 .................... bit_clear(data2,7);
1322 .................... if(bit_test(data1,0))
1323 .................... bit_set(data2,7);
1324 .................... data1 = data1 >>1;
1325 .................... *(((unsigned int8 *)(&y))+5) = data1;
1326 .................... *(((unsigned int8 *)(&y))+4) = data2;
1327 ....................
1328 .................... #endif
1329 ....................
1330 .................... do {
1331 .................... res=y;
1332 .................... y+=(x/y);
1333 ....................
1334 .................... #if !defined(__PCD__)
1335 .................... (*p)--;
1336 .................... #endif
1337 ....................
1338 .................... data1 = *(((unsigned int8 *)(&y))+5);
1339 .................... data2 = *(((unsigned int8 *)(&y))+4);
1340 .................... rotate_left(&data1,1);
1341 .................... if(bit_test(data2,7))
1342 .................... bit_set(data1,0);
1343 .................... data1--;
1344 .................... bit_clear(data2,7);
1345 .................... if(bit_test(data1,0))
1346 .................... bit_set(data2,7);
1347 .................... data1 = data1 >>1;
1348 .................... *(((unsigned int8 *)(&y))+5) = data1;
1349 .................... *(((unsigned int8 *)(&y))+4) = data2;
1350 ....................
1351 .................... } while(res != y);
1352 ....................
1353 .................... return(res);
1354 .................... }
1355 ....................
1356 .................... // Overloaded function sqrt() for data type - Float64
1357 .................... float64 sqrt(float64 x)
1358 .................... {
1359 .................... float64 y, res;
1360 .................... unsigned int16 *p;
1361 .................... unsigned int16 temp1,temp2;
1362 ....................
1363 .................... #ifdef _ERRNO
1364 .................... if(x < 0)
1365 .................... {
1366 .................... errno=EDOM;
1367 .................... }
1368 .................... #endif
1369 ....................
1370 .................... if( x<=0.0)
1371 .................... return(0.0);
1372 ....................
1373 .................... y=x;
1374 .................... p= (((unsigned int16 *)(&y))+3);
1375 .................... temp1 = *p;
1376 .................... temp2 = *p;
1377 .................... bit_clear(temp1,15);
1378 .................... temp1 = (temp1>>4)+1023;
1379 .................... temp1 = temp1 >> 1;
1380 .................... temp1 = (temp1<<4) & 0xFFF0;
1381 .................... if(bit_test(temp2,15))
1382 .................... bit_set(temp1,15);
1383 .................... temp2 = temp2 & 0x000F;
1384 .................... temp1 ^= temp2;
1385 ....................
1386 .................... (*p) = temp1;
1387 ....................
1388 .................... do {
1389 .................... res=y;
1390 .................... y+=(x/y);
1391 .................... temp1 = *p;
1392 .................... temp2 = *p;
1393 .................... bit_clear(temp1,15);
1394 .................... temp1 = (temp1>>4);
1395 .................... temp1--;
1396 .................... temp1 = (temp1<<4) & 0xFFF0;
1397 .................... if(bit_test(temp2,15))
1398 .................... bit_set(temp1,15);
1399 .................... temp2 = temp2 & 0x000F;
1400 .................... temp1 ^= temp2;
1401 .................... (*p) = temp1;
1402 ....................
1403 .................... } while(res != y);
1404 ....................
1405 .................... return(res);
1406 .................... }
1407 .................... #endif
1408 ....................
1409 .................... ////////////////////////////// Trig Functions //////////////////////////////
1410 .................... #ifdef PI_DIV_BY_TWO
1411 .................... #undef PI_DIV_BY_TWO
1412 .................... #endif
1413 .................... #define PI_DIV_BY_TWO 1.5707963267948966
1414 .................... #ifdef TWOBYPI
1415 .................... #undef TWOBYPI
1416 .................... #define TWOBYPI 0.6366197723675813
1417 .................... #endif
1418 .................... ////////////////////////////////////////////////////////////////////////////
1419 .................... // float cos(float x)
1420 .................... ////////////////////////////////////////////////////////////////////////////
1421 .................... // Description : returns the cosine value of the angle x, which is in radian
1422 .................... // Date : 9/20/2001
1423 .................... //
1424 .................... float32 cos(float32 x)
1425 .................... {
1426 .................... float32 y, t, t2 = 1.0;
1427 .................... unsigned int8 quad, i;
1428 .................... float32 frac;
1429 .................... float32 p[6] = { //by the series definition for cosine
1430 .................... -0.5, // sum ( ( (-1)^n * x^2n )/(2n)! )
1431 .................... 0.04166666666667,
1432 .................... -0.00138888888889,
1433 .................... 0.00002480158730,
1434 .................... -0.00000027557319,
1435 .................... 0.00000000208767,
1436 .................... //-0.00000000001147,
1437 .................... // 0.00000000000005
1438 .................... };
1439 ....................
1440 .................... if (x < 0) x = -x; // absolute value of input
1441 ....................
1442 .................... quad = (unsigned int8)(x / PI_DIV_BY_TWO); // quadrant
1443 .................... frac = (x / PI_DIV_BY_TWO) - quad; // fractional part of input
1444 .................... quad = quad % 4; // quadrant (0 to 3)
1445 ....................
1446 .................... if (quad == 0 || quad == 2)
1447 .................... t = frac * PI_DIV_BY_TWO;
1448 .................... else if (quad == 1)
1449 .................... t = (1-frac) * PI_DIV_BY_TWO;
1450 .................... else // should be 3
1451 .................... t = (frac-1) * PI_DIV_BY_TWO;
1452 ....................
1453 .................... y = 1.0;
1454 .................... t = t * t;
1455 .................... for (i = 0; i <= 5; i++)
1456 .................... {
1457 .................... t2 = t2 * t;
1458 .................... y = y + p[i] * t2;
1459 .................... }
1460 ....................
1461 .................... if (quad == 2 || quad == 1)
1462 .................... y = -y; // correct sign
1463 ....................
1464 .................... return (y);
1465 .................... }
1466 ....................
1467 ....................
1468 .................... //Overloaded functions for cos() for PCD
1469 .................... // Overloaded function cos() for data type - Float48
1470 .................... #if defined(__PCD__)
1471 .................... float48 cos(float48 x)
1472 .................... {
1473 .................... float48 y, t, t2 = 1.0;
1474 .................... unsigned int8 quad, i;
1475 .................... float48 frac;
1476 .................... float48 p[6] = { //by the series definition for cosine
1477 .................... -0.5, // sum ( ( (-1)^n * x^2n )/(2n)! )
1478 .................... 0.04166666666667,
1479 .................... -0.00138888888889,
1480 .................... 0.00002480158730,
1481 .................... -0.00000027557319,
1482 .................... 0.00000000208767,
1483 .................... //-0.00000000001147,
1484 .................... // 0.00000000000005
1485 .................... };
1486 ....................
1487 .................... if (x < 0) x = -x; // absolute value of input
1488 ....................
1489 .................... quad = (unsigned int8)(x / PI_DIV_BY_TWO); // quadrant
1490 .................... frac = (x / PI_DIV_BY_TWO) - quad; // fractional part of input
1491 .................... quad = quad % 4; // quadrant (0 to 3)
1492 ....................
1493 .................... if (quad == 0 || quad == 2)
1494 .................... t = frac * PI_DIV_BY_TWO;
1495 .................... else if (quad == 1)
1496 .................... t = (1-frac) * PI_DIV_BY_TWO;
1497 .................... else // should be 3
1498 .................... t = (frac-1) * PI_DIV_BY_TWO;
1499 ....................
1500 .................... y = 0.999999999781;
1501 .................... t = t * t;
1502 .................... for (i = 0; i <= 5; i++)
1503 .................... {
1504 .................... t2 = t2 * t;
1505 .................... y = y + p[i] * t2;
1506 .................... }
1507 ....................
1508 .................... if (quad == 2 || quad == 1)
1509 .................... y = -y; // correct sign
1510 ....................
1511 .................... return (y);
1512 .................... }
1513 ....................
1514 .................... // Overloaded function cos() for data type - Float48
1515 .................... float64 cos(float64 x)
1516 .................... {
1517 .................... float64 y, t, t2 = 1.0;
1518 .................... unsigned int8 quad, i;
1519 .................... float64 frac;
1520 .................... float64 p[6] = { //by the series definition for cosine
1521 .................... -0.5, // sum ( ( (-1)^n * x^2n )/(2n)! )
1522 .................... 0.04166666666667,
1523 .................... -0.00138888888889,
1524 .................... 0.00002480158730,
1525 .................... -0.00000027557319,
1526 .................... 0.00000000208767,
1527 .................... //-0.00000000001147,
1528 .................... // 0.00000000000005
1529 .................... };
1530 ....................
1531 .................... if (x < 0) x = -x; // absolute value of input
1532 ....................
1533 .................... quad = (unsigned int8)(x / PI_DIV_BY_TWO); // quadrant
1534 .................... frac = (x / PI_DIV_BY_TWO) - quad; // fractional part of input
1535 .................... quad = quad % 4; // quadrant (0 to 3)
1536 ....................
1537 .................... if (quad == 0 || quad == 2)
1538 .................... t = frac * PI_DIV_BY_TWO;
1539 .................... else if (quad == 1)
1540 .................... t = (1-frac) * PI_DIV_BY_TWO;
1541 .................... else // should be 3
1542 .................... t = (frac-1) * PI_DIV_BY_TWO;
1543 ....................
1544 .................... y = 0.999999999781;
1545 .................... t = t * t;
1546 .................... for (i = 0; i <= 5; i++)
1547 .................... {
1548 .................... t2 = t2 * t;
1549 .................... y = y + p[i] * t2;
1550 .................... }
1551 ....................
1552 .................... if (quad == 2 || quad == 1)
1553 .................... y = -y; // correct sign
1554 ....................
1555 .................... return (y);
1556 .................... }
1557 ....................
1558 .................... #endif
1559 ....................
1560 .................... ////////////////////////////////////////////////////////////////////////////
1561 .................... // float sin(float x)
1562 .................... ////////////////////////////////////////////////////////////////////////////
1563 .................... // Description : returns the sine value of the angle x, which is in radian
1564 .................... // Date : 9/20/2001
1565 .................... //
1566 .................... float32 sin(float32 x)
1567 .................... {
1568 .................... return cos(x - PI_DIV_BY_TWO);
1569 .................... }
1570 ....................
1571 .................... //Overloaded functions for sin() for PCD
1572 .................... // Overloaded function sin() for data type - Float48
1573 .................... #if defined(__PCD__)
1574 .................... float48 sin(float48 x)
1575 .................... {
1576 .................... return cos(x - PI_DIV_BY_TWO);
1577 .................... }
1578 ....................
1579 .................... // Overloaded function sin() for data type - Float48
1580 .................... float64 sin(float64 x)
1581 .................... {
1582 .................... return cos(x - PI_DIV_BY_TWO);
1583 .................... }
1584 .................... #endif
1585 ....................
1586 .................... ////////////////////////////////////////////////////////////////////////////
1587 .................... // float tan(float x)
1588 .................... ////////////////////////////////////////////////////////////////////////////
1589 .................... // Description : returns the tangent value of the angle x, which is in radian
1590 .................... // Date : 9/20/2001
1591 .................... //
1592 .................... float32 tan(float32 x)
1593 .................... {
1594 .................... float32 c, s;
1595 ....................
1596 .................... c = cos(x);
1597 .................... if (c == 0.0)
1598 .................... return (1.0e+36);
1599 ....................
1600 .................... s = sin(x);
1601 .................... return(s/c);
1602 .................... }
1603 .................... //Overloaded functions for tan() for PCD
1604 .................... // Overloaded function tan() for data type - Float48
1605 .................... #if defined(__PCD__)
1606 .................... float48 tan(float48 x)
1607 .................... {
1608 .................... float48 c, s;
1609 ....................
1610 .................... c = cos(x);
1611 .................... if (c == 0.0)
1612 .................... return (1.0e+36);
1613 ....................
1614 .................... s = sin(x);
1615 .................... return(s/c);
1616 .................... }
1617 ....................
1618 .................... // Overloaded function tan() for data type - Float48
1619 .................... float64 tan(float64 x)
1620 .................... {
1621 .................... float64 c, s;
1622 ....................
1623 .................... c = cos(x);
1624 .................... if (c == 0.0)
1625 .................... return (1.0e+36);
1626 ....................
1627 .................... s = sin(x);
1628 .................... return(s/c);
1629 .................... }
1630 .................... #endif
1631 ....................
1632 .................... float32 const pas[3] = {0.49559947, -4.6145309, 5.6036290};
1633 .................... float32 const qas[3] = {1.0000000, -5.5484666, 5.6036290};
1634 ....................
1635 .................... float32 ASIN_COS(float32 x, unsigned int8 n)
1636 .................... {
1637 .................... float32 y, res, r, y2;
1638 .................... int1 s;
1639 .................... #ifdef _ERRNO
1640 .................... if(x <-1 || x > 1)
1641 .................... {
1642 .................... errno=EDOM;
1643 .................... }
1644 .................... #endif
1645 .................... s = 0;
1646 .................... y = x;
1647 ....................
1648 .................... if (x < 0)
1649 .................... {
1650 .................... s = 1;
1651 .................... y = -y;
1652 .................... }
1653 ....................
1654 .................... if (y > 0.5)
1655 .................... {
1656 .................... y = sqrt((1.0 - y)/2.0);
1657 .................... n += 2;
1658 .................... }
1659 ....................
1660 .................... y2=y*y;
1661 ....................
1662 .................... res = pas[0]*y2 + pas[1];
1663 .................... res = res*y2 + pas[2];
1664 ....................
1665 .................... r = qas[0]*y2 + qas[1];
1666 .................... r = r*y2 + qas[2];
1667 ....................
1668 .................... res = y*res/r;
1669 ....................
1670 .................... if (n & 2) // |x| > 0.5
1671 .................... res = PI_DIV_BY_TWO - 2.0*res;
1672 .................... if (s)
1673 .................... res = -res;
1674 .................... if (n & 1) // take arccos
1675 .................... res = PI_DIV_BY_TWO - res;
1676 ....................
1677 .................... return(res);
1678 .................... }
1679 ....................
1680 .................... //Overloaded functions for ASIN_COS() for PCD
1681 .................... // Overloaded function ASIN_COS() for data type - Float48
1682 .................... #if defined(__PCD__)
1683 .................... float48 ASIN_COS(float48 x, unsigned int8 n)
1684 .................... {
1685 .................... float48 y, res, r, y2;
1686 .................... int1 s;
1687 .................... #ifdef _ERRNO
1688 .................... if(x <-1 || x > 1)
1689 .................... {
1690 .................... errno=EDOM;
1691 .................... }
1692 .................... #endif
1693 .................... s = 0;
1694 .................... y = x;
1695 ....................
1696 .................... if (x < 0)
1697 .................... {
1698 .................... s = 1;
1699 .................... y = -y;
1700 .................... }
1701 ....................
1702 .................... if (y > 0.5)
1703 .................... {
1704 .................... y = sqrt((1.0 - y)/2.0);
1705 .................... n += 2;
1706 .................... }
1707 ....................
1708 .................... y2=y*y;
1709 ....................
1710 .................... res = pas[0]*y2 + pas[1];
1711 .................... res = res*y2 + pas[2];
1712 ....................
1713 .................... r = qas[0]*y2 + qas[1];
1714 .................... r = r*y2 + qas[2];
1715 ....................
1716 .................... res = y*res/r;
1717 ....................
1718 .................... if (n & 2) // |x| > 0.5
1719 .................... res = PI_DIV_BY_TWO - 2.0*res;
1720 .................... if (s)
1721 .................... res = -res;
1722 .................... if (n & 1) // take arccos
1723 .................... res = PI_DIV_BY_TWO - res;
1724 ....................
1725 .................... return(res);
1726 .................... }
1727 ....................
1728 .................... // Overloaded function ASIN_COS() for data type - Float64
1729 .................... float64 ASIN_COS(float64 x, unsigned int8 n)
1730 .................... {
1731 .................... float64 y, res, r, y2;
1732 .................... int1 s;
1733 .................... #ifdef _ERRNO
1734 .................... if(x <-1 || x > 1)
1735 .................... {
1736 .................... errno=EDOM;
1737 .................... }
1738 .................... #endif
1739 .................... s = 0;
1740 .................... y = x;
1741 ....................
1742 .................... if (x < 0)
1743 .................... {
1744 .................... s = 1;
1745 .................... y = -y;
1746 .................... }
1747 ....................
1748 .................... if (y > 0.5)
1749 .................... {
1750 .................... y = sqrt((1.0 - y)/2.0);
1751 .................... n += 2;
1752 .................... }
1753 ....................
1754 .................... y2=y*y;
1755 ....................
1756 .................... res = pas[0]*y2 + pas[1];
1757 .................... res = res*y2 + pas[2];
1758 ....................
1759 .................... r = qas[0]*y2 + qas[1];
1760 .................... r = r*y2 + qas[2];
1761 ....................
1762 .................... res = y*res/r;
1763 ....................
1764 .................... if (n & 2) // |x| > 0.5
1765 .................... res = PI_DIV_BY_TWO - 2.0*res;
1766 .................... if (s)
1767 .................... res = -res;
1768 .................... if (n & 1) // take arccos
1769 .................... res = PI_DIV_BY_TWO - res;
1770 ....................
1771 .................... return(res);
1772 .................... }
1773 .................... #endif
1774 ....................
1775 .................... ////////////////////////////////////////////////////////////////////////////
1776 .................... // float asin(float x)
1777 .................... ////////////////////////////////////////////////////////////////////////////
1778 .................... // Description : returns the arcsine value of the value x.
1779 .................... // Date : N/A
1780 .................... //
1781 .................... float32 asin(float32 x)
1782 .................... {
1783 .................... float32 r;
1784 ....................
1785 .................... r = ASIN_COS(x, 0);
1786 .................... return(r);
1787 .................... }
1788 .................... //Overloaded functions for asin() for PCD
1789 .................... // Overloaded function asin() for data type - Float48
1790 .................... #if defined(__PCD__)
1791 .................... float48 asin(float48 x)
1792 .................... {
1793 .................... float48 r;
1794 ....................
1795 .................... r = ASIN_COS(x, 0);
1796 .................... return(r);
1797 .................... }
1798 ....................
1799 .................... // Overloaded function asin() for data type - Float64
1800 .................... float64 asin(float64 x)
1801 .................... {
1802 .................... float64 r;
1803 ....................
1804 .................... r = ASIN_COS(x, 0);
1805 .................... return(r);
1806 .................... }
1807 .................... #endif
1808 ....................
1809 .................... ////////////////////////////////////////////////////////////////////////////
1810 .................... // float acos(float x)
1811 .................... ////////////////////////////////////////////////////////////////////////////
1812 .................... // Description : returns the arccosine value of the value x.
1813 .................... // Date : N/A
1814 .................... //
1815 .................... float32 acos(float32 x)
1816 .................... {
1817 .................... float32 r;
1818 ....................
1819 .................... r = ASIN_COS(x, 1);
1820 .................... return(r);
1821 .................... }
1822 .................... //Overloaded functions for acos() for PCD
1823 .................... // Overloaded function acos() for data type - Float48
1824 .................... #if defined(__PCD__)
1825 .................... float48 acos(float48 x)
1826 .................... {
1827 .................... float48 r;
1828 ....................
1829 .................... r = ASIN_COS(x, 1);
1830 .................... return(r);
1831 .................... }
1832 ....................
1833 .................... // Overloaded function acos() for data type - Float64
1834 .................... float64 acos(float64 x)
1835 .................... {
1836 .................... float64 r;
1837 ....................
1838 .................... r = ASIN_COS(x, 1);
1839 .................... return(r);
1840 .................... }
1841 .................... #endif
1842 ....................
1843 .................... float32 const pat[4] = {0.17630401, 5.6710795, 22.376096, 19.818457};
1844 .................... float32 const qat[4] = {1.0000000, 11.368190, 28.982246, 19.818457};
1845 ....................
1846 .................... ////////////////////////////////////////////////////////////////////////////
1847 .................... // float atan(float x)
1848 .................... ////////////////////////////////////////////////////////////////////////////
1849 .................... // Description : returns the arctangent value of the value x.
1850 .................... // Date : N/A
1851 .................... //
1852 .................... float32 atan(float32 x)
1853 .................... {
1854 .................... float32 y, res, r;
1855 .................... int1 s, flag;
1856 ....................
1857 .................... s = 0;
1858 *
1859 095D: BCF 67.0
1860 .................... flag = 0;
1861 095E: BCF 67.1
1862 .................... y = x;
1863 095F: MOVF 5A,W
1864 0960: MOVWF 5E
1865 0961: MOVF 59,W
1866 0962: MOVWF 5D
1867 0963: MOVF 58,W
1868 0964: MOVWF 5C
1869 0965: MOVF 57,W
1870 0966: MOVWF 5B
1871 ....................
1872 .................... if (x < 0)
1873 0967: MOVF 5A,W
1874 0968: MOVWF 6B
1875 0969: MOVF 59,W
1876 096A: MOVWF 6A
1877 096B: MOVF 58,W
1878 096C: MOVWF 69
1879 096D: MOVF 57,W
1880 096E: MOVWF 68
1881 096F: CLRF 6F
1882 0970: CLRF 6E
1883 0971: CLRF 6D
1884 0972: CLRF 6C
1885 0973: BCF 0A.3
1886 0974: CALL 5E7
1887 0975: BSF 0A.3
1888 0976: BTFSS 03.0
1889 0977: GOTO 17C
1890 .................... {
1891 .................... s = 1;
1892 0978: BSF 67.0
1893 .................... y = -y;
1894 0979: MOVF 5C,W
1895 097A: XORLW 80
1896 097B: MOVWF 5C
1897 .................... }
1898 ....................
1899 .................... if (y > 1.0)
1900 097C: CLRF 6B
1901 097D: CLRF 6A
1902 097E: CLRF 69
1903 097F: MOVLW 7F
1904 0980: MOVWF 68
1905 0981: MOVF 5E,W
1906 0982: MOVWF 6F
1907 0983: MOVF 5D,W
1908 0984: MOVWF 6E
1909 0985: MOVF 5C,W
1910 0986: MOVWF 6D
1911 0987: MOVF 5B,W
1912 0988: MOVWF 6C
1913 0989: BCF 0A.3
1914 098A: CALL 5E7
1915 098B: BSF 0A.3
1916 098C: BTFSS 03.0
1917 098D: GOTO 1A7
1918 .................... {
1919 .................... y = 1.0/y;
1920 098E: CLRF 6F
1921 098F: CLRF 6E
1922 0990: CLRF 6D
1923 0991: MOVLW 7F
1924 0992: MOVWF 6C
1925 0993: MOVF 5E,W
1926 0994: MOVWF 73
1927 0995: MOVF 5D,W
1928 0996: MOVWF 72
1929 0997: MOVF 5C,W
1930 0998: MOVWF 71
1931 0999: MOVF 5B,W
1932 099A: MOVWF 70
1933 099B: BCF 0A.3
1934 099C: CALL 506
1935 099D: BSF 0A.3
1936 099E: MOVF 7A,W
1937 099F: MOVWF 5E
1938 09A0: MOVF 79,W
1939 09A1: MOVWF 5D
1940 09A2: MOVF 78,W
1941 09A3: MOVWF 5C
1942 09A4: MOVF 77,W
1943 09A5: MOVWF 5B
1944 .................... flag = 1;
1945 09A6: BSF 67.1
1946 .................... }
1947 ....................
1948 .................... res = pat[0]*y*y + pat[1];
1949 09A7: MOVLW 0A
1950 09A8: MOVWF 6F
1951 09A9: MOVLW 89
1952 09AA: MOVWF 6E
1953 09AB: MOVLW 34
1954 09AC: MOVWF 6D
1955 09AD: MOVLW 7C
1956 09AE: MOVWF 6C
1957 09AF: MOVF 5E,W
1958 09B0: MOVWF 73
1959 09B1: MOVF 5D,W
1960 09B2: MOVWF 72
1961 09B3: MOVF 5C,W
1962 09B4: MOVWF 71
1963 09B5: MOVF 5B,W
1964 09B6: MOVWF 70
1965 09B7: BCF 0A.3
1966 09B8: CALL 626
1967 09B9: BSF 0A.3
1968 09BA: MOVF 77,W
1969 09BB: MOVWF 68
1970 09BC: MOVF 78,W
1971 09BD: MOVWF 69
1972 09BE: MOVF 79,W
1973 09BF: MOVWF 6A
1974 09C0: MOVF 7A,W
1975 09C1: MOVWF 6B
1976 09C2: MOVWF 6F
1977 09C3: MOVF 79,W
1978 09C4: MOVWF 6E
1979 09C5: MOVF 78,W
1980 09C6: MOVWF 6D
1981 09C7: MOVF 77,W
1982 09C8: MOVWF 6C
1983 09C9: MOVF 5E,W
1984 09CA: MOVWF 73
1985 09CB: MOVF 5D,W
1986 09CC: MOVWF 72
1987 09CD: MOVF 5C,W
1988 09CE: MOVWF 71
1989 09CF: MOVF 5B,W
1990 09D0: MOVWF 70
1991 09D1: BCF 0A.3
1992 09D2: CALL 626
1993 09D3: BSF 0A.3
1994 09D4: MOVF 77,W
1995 09D5: MOVWF 68
1996 09D6: MOVF 78,W
1997 09D7: MOVWF 69
1998 09D8: MOVF 79,W
1999 09D9: MOVWF 6A
2000 09DA: MOVF 7A,W
2001 09DB: MOVWF 6B
2002 09DC: BCF 03.1
2003 09DD: MOVF 7A,W
2004 09DE: MOVWF 6F
2005 09DF: MOVF 79,W
2006 09E0: MOVWF 6E
2007 09E1: MOVF 78,W
2008 09E2: MOVWF 6D
2009 09E3: MOVF 77,W
2010 09E4: MOVWF 6C
2011 09E5: MOVLW 7C
2012 09E6: MOVWF 73
2013 09E7: MOVLW 79
2014 09E8: MOVWF 72
2015 09E9: MOVLW 35
2016 09EA: MOVWF 71
2017 09EB: MOVLW 81
2018 09EC: MOVWF 70
2019 09ED: CALL 000
2020 09EE: MOVF 7A,W
2021 09EF: MOVWF 62
2022 09F0: MOVF 79,W
2023 09F1: MOVWF 61
2024 09F2: MOVF 78,W
2025 09F3: MOVWF 60
2026 09F4: MOVF 77,W
2027 09F5: MOVWF 5F
2028 .................... res = res*y*y + pat[2];
2029 09F6: MOVF 62,W
2030 09F7: MOVWF 6F
2031 09F8: MOVF 61,W
2032 09F9: MOVWF 6E
2033 09FA: MOVF 60,W
2034 09FB: MOVWF 6D
2035 09FC: MOVF 5F,W
2036 09FD: MOVWF 6C
2037 09FE: MOVF 5E,W
2038 09FF: MOVWF 73
2039 0A00: MOVF 5D,W
2040 0A01: MOVWF 72
2041 0A02: MOVF 5C,W
2042 0A03: MOVWF 71
2043 0A04: MOVF 5B,W
2044 0A05: MOVWF 70
2045 0A06: BCF 0A.3
2046 0A07: CALL 626
2047 0A08: BSF 0A.3
2048 0A09: MOVF 77,W
2049 0A0A: MOVWF 68
2050 0A0B: MOVF 78,W
2051 0A0C: MOVWF 69
2052 0A0D: MOVF 79,W
2053 0A0E: MOVWF 6A
2054 0A0F: MOVF 7A,W
2055 0A10: MOVWF 6B
2056 0A11: MOVWF 6F
2057 0A12: MOVF 79,W
2058 0A13: MOVWF 6E
2059 0A14: MOVF 78,W
2060 0A15: MOVWF 6D
2061 0A16: MOVF 77,W
2062 0A17: MOVWF 6C
2063 0A18: MOVF 5E,W
2064 0A19: MOVWF 73
2065 0A1A: MOVF 5D,W
2066 0A1B: MOVWF 72
2067 0A1C: MOVF 5C,W
2068 0A1D: MOVWF 71
2069 0A1E: MOVF 5B,W
2070 0A1F: MOVWF 70
2071 0A20: BCF 0A.3
2072 0A21: CALL 626
2073 0A22: BSF 0A.3
2074 0A23: MOVF 77,W
2075 0A24: MOVWF 68
2076 0A25: MOVF 78,W
2077 0A26: MOVWF 69
2078 0A27: MOVF 79,W
2079 0A28: MOVWF 6A
2080 0A29: MOVF 7A,W
2081 0A2A: MOVWF 6B
2082 0A2B: BCF 03.1
2083 0A2C: MOVF 7A,W
2084 0A2D: MOVWF 6F
2085 0A2E: MOVF 79,W
2086 0A2F: MOVWF 6E
2087 0A30: MOVF 78,W
2088 0A31: MOVWF 6D
2089 0A32: MOVF 77,W
2090 0A33: MOVWF 6C
2091 0A34: MOVLW 3F
2092 0A35: MOVWF 73
2093 0A36: MOVLW 02
2094 0A37: MOVWF 72
2095 0A38: MOVLW 33
2096 0A39: MOVWF 71
2097 0A3A: MOVLW 83
2098 0A3B: MOVWF 70
2099 0A3C: CALL 000
2100 0A3D: MOVF 7A,W
2101 0A3E: MOVWF 62
2102 0A3F: MOVF 79,W
2103 0A40: MOVWF 61
2104 0A41: MOVF 78,W
2105 0A42: MOVWF 60
2106 0A43: MOVF 77,W
2107 0A44: MOVWF 5F
2108 .................... res = res*y*y + pat[3];
2109 0A45: MOVF 62,W
2110 0A46: MOVWF 6F
2111 0A47: MOVF 61,W
2112 0A48: MOVWF 6E
2113 0A49: MOVF 60,W
2114 0A4A: MOVWF 6D
2115 0A4B: MOVF 5F,W
2116 0A4C: MOVWF 6C
2117 0A4D: MOVF 5E,W
2118 0A4E: MOVWF 73
2119 0A4F: MOVF 5D,W
2120 0A50: MOVWF 72
2121 0A51: MOVF 5C,W
2122 0A52: MOVWF 71
2123 0A53: MOVF 5B,W
2124 0A54: MOVWF 70
2125 0A55: BCF 0A.3
2126 0A56: CALL 626
2127 0A57: BSF 0A.3
2128 0A58: MOVF 77,W
2129 0A59: MOVWF 68
2130 0A5A: MOVF 78,W
2131 0A5B: MOVWF 69
2132 0A5C: MOVF 79,W
2133 0A5D: MOVWF 6A
2134 0A5E: MOVF 7A,W
2135 0A5F: MOVWF 6B
2136 0A60: MOVWF 6F
2137 0A61: MOVF 79,W
2138 0A62: MOVWF 6E
2139 0A63: MOVF 78,W
2140 0A64: MOVWF 6D
2141 0A65: MOVF 77,W
2142 0A66: MOVWF 6C
2143 0A67: MOVF 5E,W
2144 0A68: MOVWF 73
2145 0A69: MOVF 5D,W
2146 0A6A: MOVWF 72
2147 0A6B: MOVF 5C,W
2148 0A6C: MOVWF 71
2149 0A6D: MOVF 5B,W
2150 0A6E: MOVWF 70
2151 0A6F: BCF 0A.3
2152 0A70: CALL 626
2153 0A71: BSF 0A.3
2154 0A72: MOVF 77,W
2155 0A73: MOVWF 68
2156 0A74: MOVF 78,W
2157 0A75: MOVWF 69
2158 0A76: MOVF 79,W
2159 0A77: MOVWF 6A
2160 0A78: MOVF 7A,W
2161 0A79: MOVWF 6B
2162 0A7A: BCF 03.1
2163 0A7B: MOVF 7A,W
2164 0A7C: MOVWF 6F
2165 0A7D: MOVF 79,W
2166 0A7E: MOVWF 6E
2167 0A7F: MOVF 78,W
2168 0A80: MOVWF 6D
2169 0A81: MOVF 77,W
2170 0A82: MOVWF 6C
2171 0A83: MOVLW 33
2172 0A84: MOVWF 73
2173 0A85: MOVLW 8C
2174 0A86: MOVWF 72
2175 0A87: MOVLW 1E
2176 0A88: MOVWF 71
2177 0A89: MOVLW 83
2178 0A8A: MOVWF 70
2179 0A8B: CALL 000
2180 0A8C: MOVF 7A,W
2181 0A8D: MOVWF 62
2182 0A8E: MOVF 79,W
2183 0A8F: MOVWF 61
2184 0A90: MOVF 78,W
2185 0A91: MOVWF 60
2186 0A92: MOVF 77,W
2187 0A93: MOVWF 5F
2188 ....................
2189 .................... r = qat[0]*y*y + qat[1];
2190 0A94: CLRF 6F
2191 0A95: CLRF 6E
2192 0A96: CLRF 6D
2193 0A97: MOVLW 7F
2194 0A98: MOVWF 6C
2195 0A99: MOVF 5E,W
2196 0A9A: MOVWF 73
2197 0A9B: MOVF 5D,W
2198 0A9C: MOVWF 72
2199 0A9D: MOVF 5C,W
2200 0A9E: MOVWF 71
2201 0A9F: MOVF 5B,W
2202 0AA0: MOVWF 70
2203 0AA1: BCF 0A.3
2204 0AA2: CALL 626
2205 0AA3: BSF 0A.3
2206 0AA4: MOVF 77,W
2207 0AA5: MOVWF 68
2208 0AA6: MOVF 78,W
2209 0AA7: MOVWF 69
2210 0AA8: MOVF 79,W
2211 0AA9: MOVWF 6A
2212 0AAA: MOVF 7A,W
2213 0AAB: MOVWF 6B
2214 0AAC: MOVWF 6F
2215 0AAD: MOVF 79,W
2216 0AAE: MOVWF 6E
2217 0AAF: MOVF 78,W
2218 0AB0: MOVWF 6D
2219 0AB1: MOVF 77,W
2220 0AB2: MOVWF 6C
2221 0AB3: MOVF 5E,W
2222 0AB4: MOVWF 73
2223 0AB5: MOVF 5D,W
2224 0AB6: MOVWF 72
2225 0AB7: MOVF 5C,W
2226 0AB8: MOVWF 71
2227 0AB9: MOVF 5B,W
2228 0ABA: MOVWF 70
2229 0ABB: BCF 0A.3
2230 0ABC: CALL 626
2231 0ABD: BSF 0A.3
2232 0ABE: MOVF 77,W
2233 0ABF: MOVWF 68
2234 0AC0: MOVF 78,W
2235 0AC1: MOVWF 69
2236 0AC2: MOVF 79,W
2237 0AC3: MOVWF 6A
2238 0AC4: MOVF 7A,W
2239 0AC5: MOVWF 6B
2240 0AC6: BCF 03.1
2241 0AC7: MOVF 7A,W
2242 0AC8: MOVWF 6F
2243 0AC9: MOVF 79,W
2244 0ACA: MOVWF 6E
2245 0ACB: MOVF 78,W
2246 0ACC: MOVWF 6D
2247 0ACD: MOVF 77,W
2248 0ACE: MOVWF 6C
2249 0ACF: MOVLW 1B
2250 0AD0: MOVWF 73
2251 0AD1: MOVLW E4
2252 0AD2: MOVWF 72
2253 0AD3: MOVLW 35
2254 0AD4: MOVWF 71
2255 0AD5: MOVLW 82
2256 0AD6: MOVWF 70
2257 0AD7: CALL 000
2258 0AD8: MOVF 7A,W
2259 0AD9: MOVWF 66
2260 0ADA: MOVF 79,W
2261 0ADB: MOVWF 65
2262 0ADC: MOVF 78,W
2263 0ADD: MOVWF 64
2264 0ADE: MOVF 77,W
2265 0ADF: MOVWF 63
2266 .................... r = r*y*y + qat[2];
2267 0AE0: MOVF 66,W
2268 0AE1: MOVWF 6F
2269 0AE2: MOVF 65,W
2270 0AE3: MOVWF 6E
2271 0AE4: MOVF 64,W
2272 0AE5: MOVWF 6D
2273 0AE6: MOVF 63,W
2274 0AE7: MOVWF 6C
2275 0AE8: MOVF 5E,W
2276 0AE9: MOVWF 73
2277 0AEA: MOVF 5D,W
2278 0AEB: MOVWF 72
2279 0AEC: MOVF 5C,W
2280 0AED: MOVWF 71
2281 0AEE: MOVF 5B,W
2282 0AEF: MOVWF 70
2283 0AF0: BCF 0A.3
2284 0AF1: CALL 626
2285 0AF2: BSF 0A.3
2286 0AF3: MOVF 77,W
2287 0AF4: MOVWF 68
2288 0AF5: MOVF 78,W
2289 0AF6: MOVWF 69
2290 0AF7: MOVF 79,W
2291 0AF8: MOVWF 6A
2292 0AF9: MOVF 7A,W
2293 0AFA: MOVWF 6B
2294 0AFB: MOVWF 6F
2295 0AFC: MOVF 79,W
2296 0AFD: MOVWF 6E
2297 0AFE: MOVF 78,W
2298 0AFF: MOVWF 6D
2299 0B00: MOVF 77,W
2300 0B01: MOVWF 6C
2301 0B02: MOVF 5E,W
2302 0B03: MOVWF 73
2303 0B04: MOVF 5D,W
2304 0B05: MOVWF 72
2305 0B06: MOVF 5C,W
2306 0B07: MOVWF 71
2307 0B08: MOVF 5B,W
2308 0B09: MOVWF 70
2309 0B0A: BCF 0A.3
2310 0B0B: CALL 626
2311 0B0C: BSF 0A.3
2312 0B0D: MOVF 77,W
2313 0B0E: MOVWF 68
2314 0B0F: MOVF 78,W
2315 0B10: MOVWF 69
2316 0B11: MOVF 79,W
2317 0B12: MOVWF 6A
2318 0B13: MOVF 7A,W
2319 0B14: MOVWF 6B
2320 0B15: BCF 03.1
2321 0B16: MOVF 7A,W
2322 0B17: MOVWF 6F
2323 0B18: MOVF 79,W
2324 0B19: MOVWF 6E
2325 0B1A: MOVF 78,W
2326 0B1B: MOVWF 6D
2327 0B1C: MOVF 77,W
2328 0B1D: MOVWF 6C
2329 0B1E: MOVLW A4
2330 0B1F: MOVWF 73
2331 0B20: MOVLW DB
2332 0B21: MOVWF 72
2333 0B22: MOVLW 67
2334 0B23: MOVWF 71
2335 0B24: MOVLW 83
2336 0B25: MOVWF 70
2337 0B26: CALL 000
2338 0B27: MOVF 7A,W
2339 0B28: MOVWF 66
2340 0B29: MOVF 79,W
2341 0B2A: MOVWF 65
2342 0B2B: MOVF 78,W
2343 0B2C: MOVWF 64
2344 0B2D: MOVF 77,W
2345 0B2E: MOVWF 63
2346 .................... r = r*y*y + qat[3];
2347 0B2F: MOVF 66,W
2348 0B30: MOVWF 6F
2349 0B31: MOVF 65,W
2350 0B32: MOVWF 6E
2351 0B33: MOVF 64,W
2352 0B34: MOVWF 6D
2353 0B35: MOVF 63,W
2354 0B36: MOVWF 6C
2355 0B37: MOVF 5E,W
2356 0B38: MOVWF 73
2357 0B39: MOVF 5D,W
2358 0B3A: MOVWF 72
2359 0B3B: MOVF 5C,W
2360 0B3C: MOVWF 71
2361 0B3D: MOVF 5B,W
2362 0B3E: MOVWF 70
2363 0B3F: BCF 0A.3
2364 0B40: CALL 626
2365 0B41: BSF 0A.3
2366 0B42: MOVF 77,W
2367 0B43: MOVWF 68
2368 0B44: MOVF 78,W
2369 0B45: MOVWF 69
2370 0B46: MOVF 79,W
2371 0B47: MOVWF 6A
2372 0B48: MOVF 7A,W
2373 0B49: MOVWF 6B
2374 0B4A: MOVWF 6F
2375 0B4B: MOVF 79,W
2376 0B4C: MOVWF 6E
2377 0B4D: MOVF 78,W
2378 0B4E: MOVWF 6D
2379 0B4F: MOVF 77,W
2380 0B50: MOVWF 6C
2381 0B51: MOVF 5E,W
2382 0B52: MOVWF 73
2383 0B53: MOVF 5D,W
2384 0B54: MOVWF 72
2385 0B55: MOVF 5C,W
2386 0B56: MOVWF 71
2387 0B57: MOVF 5B,W
2388 0B58: MOVWF 70
2389 0B59: BCF 0A.3
2390 0B5A: CALL 626
2391 0B5B: BSF 0A.3
2392 0B5C: MOVF 77,W
2393 0B5D: MOVWF 68
2394 0B5E: MOVF 78,W
2395 0B5F: MOVWF 69
2396 0B60: MOVF 79,W
2397 0B61: MOVWF 6A
2398 0B62: MOVF 7A,W
2399 0B63: MOVWF 6B
2400 0B64: BCF 03.1
2401 0B65: MOVF 7A,W
2402 0B66: MOVWF 6F
2403 0B67: MOVF 79,W
2404 0B68: MOVWF 6E
2405 0B69: MOVF 78,W
2406 0B6A: MOVWF 6D
2407 0B6B: MOVF 77,W
2408 0B6C: MOVWF 6C
2409 0B6D: MOVLW 33
2410 0B6E: MOVWF 73
2411 0B6F: MOVLW 8C
2412 0B70: MOVWF 72
2413 0B71: MOVLW 1E
2414 0B72: MOVWF 71
2415 0B73: MOVLW 83
2416 0B74: MOVWF 70
2417 0B75: CALL 000
2418 0B76: MOVF 7A,W
2419 0B77: MOVWF 66
2420 0B78: MOVF 79,W
2421 0B79: MOVWF 65
2422 0B7A: MOVF 78,W
2423 0B7B: MOVWF 64
2424 0B7C: MOVF 77,W
2425 0B7D: MOVWF 63
2426 ....................
2427 .................... res = y*res/r;
2428 0B7E: MOVF 5E,W
2429 0B7F: MOVWF 6F
2430 0B80: MOVF 5D,W
2431 0B81: MOVWF 6E
2432 0B82: MOVF 5C,W
2433 0B83: MOVWF 6D
2434 0B84: MOVF 5B,W
2435 0B85: MOVWF 6C
2436 0B86: MOVF 62,W
2437 0B87: MOVWF 73
2438 0B88: MOVF 61,W
2439 0B89: MOVWF 72
2440 0B8A: MOVF 60,W
2441 0B8B: MOVWF 71
2442 0B8C: MOVF 5F,W
2443 0B8D: MOVWF 70
2444 0B8E: BCF 0A.3
2445 0B8F: CALL 626
2446 0B90: BSF 0A.3
2447 0B91: MOVF 77,W
2448 0B92: MOVWF 68
2449 0B93: MOVF 78,W
2450 0B94: MOVWF 69
2451 0B95: MOVF 79,W
2452 0B96: MOVWF 6A
2453 0B97: MOVF 7A,W
2454 0B98: MOVWF 6B
2455 0B99: MOVWF 6F
2456 0B9A: MOVF 79,W
2457 0B9B: MOVWF 6E
2458 0B9C: MOVF 78,W
2459 0B9D: MOVWF 6D
2460 0B9E: MOVF 77,W
2461 0B9F: MOVWF 6C
2462 0BA0: MOVF 66,W
2463 0BA1: MOVWF 73
2464 0BA2: MOVF 65,W
2465 0BA3: MOVWF 72
2466 0BA4: MOVF 64,W
2467 0BA5: MOVWF 71
2468 0BA6: MOVF 63,W
2469 0BA7: MOVWF 70
2470 0BA8: BCF 0A.3
2471 0BA9: CALL 506
2472 0BAA: BSF 0A.3
2473 0BAB: MOVF 7A,W
2474 0BAC: MOVWF 62
2475 0BAD: MOVF 79,W
2476 0BAE: MOVWF 61
2477 0BAF: MOVF 78,W
2478 0BB0: MOVWF 60
2479 0BB1: MOVF 77,W
2480 0BB2: MOVWF 5F
2481 ....................
2482 ....................
2483 .................... if (flag) // for |x| > 1
2484 0BB3: BTFSS 67.1
2485 0BB4: GOTO 3CF
2486 .................... res = PI_DIV_BY_TWO - res;
2487 0BB5: BSF 03.1
2488 0BB6: MOVLW DB
2489 0BB7: MOVWF 6F
2490 0BB8: MOVLW 0F
2491 0BB9: MOVWF 6E
2492 0BBA: MOVLW 49
2493 0BBB: MOVWF 6D
2494 0BBC: MOVLW 7F
2495 0BBD: MOVWF 6C
2496 0BBE: MOVF 62,W
2497 0BBF: MOVWF 73
2498 0BC0: MOVF 61,W
2499 0BC1: MOVWF 72
2500 0BC2: MOVF 60,W
2501 0BC3: MOVWF 71
2502 0BC4: MOVF 5F,W
2503 0BC5: MOVWF 70
2504 0BC6: CALL 000
2505 0BC7: MOVF 7A,W
2506 0BC8: MOVWF 62
2507 0BC9: MOVF 79,W
2508 0BCA: MOVWF 61
2509 0BCB: MOVF 78,W
2510 0BCC: MOVWF 60
2511 0BCD: MOVF 77,W
2512 0BCE: MOVWF 5F
2513 .................... if (s)
2514 0BCF: BTFSS 67.0
2515 0BD0: GOTO 3D4
2516 .................... res = -res;
2517 0BD1: MOVF 60,W
2518 0BD2: XORLW 80
2519 0BD3: MOVWF 60
2520 ....................
2521 .................... return(res);
2522 0BD4: MOVF 5F,W
2523 0BD5: MOVWF 77
2524 0BD6: MOVF 60,W
2525 0BD7: MOVWF 78
2526 0BD8: MOVF 61,W
2527 0BD9: MOVWF 79
2528 0BDA: MOVF 62,W
2529 0BDB: MOVWF 7A
2530 .................... }
2531 0BDC: RETURN
2532 .................... //Overloaded functions for atan() for PCD
2533 .................... // Overloaded function atan() for data type - Float48
2534 .................... #if defined(__PCD__)
2535 .................... float48 atan(float48 x)
2536 .................... {
2537 .................... float48 y, res, r;
2538 .................... int1 s, flag;
2539 ....................
2540 .................... s = 0;
2541 .................... flag = 0;
2542 .................... y = x;
2543 ....................
2544 .................... if (x < 0)
2545 .................... {
2546 .................... s = 1;
2547 .................... y = -y;
2548 .................... }
2549 ....................
2550 .................... if (y > 1.0)
2551 .................... {
2552 .................... y = 1.0/y;
2553 .................... flag = 1;
2554 .................... }
2555 ....................
2556 .................... res = pat[0]*y*y + pat[1];
2557 .................... res = res*y*y + pat[2];
2558 .................... res = res*y*y + pat[3];
2559 ....................
2560 .................... r = qat[0]*y*y + qat[1];
2561 .................... r = r*y*y + qat[2];
2562 .................... r = r*y*y + qat[3];
2563 ....................
2564 .................... res = y*res/r;
2565 ....................
2566 ....................
2567 .................... if (flag) // for |x| > 1
2568 .................... res = PI_DIV_BY_TWO - res;
2569 .................... if (s)
2570 .................... res = -res;
2571 ....................
2572 .................... return(res);
2573 .................... }
2574 ....................
2575 .................... // Overloaded function atan() for data type - Float64
2576 .................... float64 atan(float64 x)
2577 .................... {
2578 .................... float64 y, res, r;
2579 .................... int1 s, flag;
2580 ....................
2581 .................... s = 0;
2582 .................... flag = 0;
2583 .................... y = x;
2584 ....................
2585 .................... if (x < 0)
2586 .................... {
2587 .................... s = 1;
2588 .................... y = -y;
2589 .................... }
2590 ....................
2591 .................... if (y > 1.0)
2592 .................... {
2593 .................... y = 1.0/y;
2594 .................... flag = 1;
2595 .................... }
2596 ....................
2597 .................... res = pat[0]*y*y + pat[1];
2598 .................... res = res*y*y + pat[2];
2599 .................... res = res*y*y + pat[3];
2600 ....................
2601 .................... r = qat[0]*y*y + qat[1];
2602 .................... r = r*y*y + qat[2];
2603 .................... r = r*y*y + qat[3];
2604 ....................
2605 .................... res = y*res/r;
2606 ....................
2607 ....................
2608 .................... if (flag) // for |x| > 1
2609 .................... res = PI_DIV_BY_TWO - res;
2610 .................... if (s)
2611 .................... res = -res;
2612 ....................
2613 .................... return(res);
2614 .................... }
2615 .................... #endif
2616 ....................
2617 .................... /////////////////////////////////////////////////////////////////////////////
2618 .................... // float atan2(float y, float x)
2619 .................... /////////////////////////////////////////////////////////////////////////////
2620 .................... // Description :computes the principal value of arc tangent of y/x, using the
2621 .................... // signs of both the arguments to determine the quadrant of the return value
2622 .................... // Returns : returns the arc tangent of y/x.
2623 .................... // Date : N/A
2624 .................... //
2625 ....................
2626 .................... float32 atan2(float32 y,float32 x)
2627 .................... {
2628 .................... float32 z;
2629 .................... int1 sign;
2630 .................... unsigned int8 quad;
2631 .................... sign=0;
2632 .................... quad=0; //quadrant
2633 .................... quad=((y<=0.0)?((x<=0.0)?3:4):((x<0.0)?2:1));
2634 .................... if(y<0.0)
2635 .................... {
2636 .................... sign=1;
2637 .................... y=-y;
2638 .................... }
2639 .................... if(x<0.0)
2640 .................... {
2641 .................... x=-x;
2642 .................... }
2643 .................... if (x==0.0)
2644 .................... {
2645 .................... if(y==0.0)
2646 .................... {
2647 .................... #ifdef _ERRNO
2648 .................... {
2649 .................... errno=EDOM;
2650 .................... }
2651 .................... #endif
2652 .................... }
2653 .................... else
2654 .................... {
2655 .................... if(sign)
2656 .................... {
2657 .................... return (-(PI_DIV_BY_TWO));
2658 .................... }
2659 .................... else
2660 .................... {
2661 .................... return (PI_DIV_BY_TWO);
2662 .................... }
2663 .................... }
2664 .................... }
2665 .................... else
2666 .................... {
2667 .................... z=y/x;
2668 .................... switch(quad)
2669 .................... {
2670 .................... case 1:
2671 .................... {
2672 .................... return atan(z);
2673 .................... break;
2674 .................... }
2675 .................... case 2:
2676 .................... {
2677 .................... // return (atan(z)+PI_DIV_BY_TWO); //2L3122
2678 .................... return (PI-atan(z));
2679 .................... break;
2680 .................... }
2681 .................... case 3:
2682 .................... {
2683 .................... return (atan(z)-PI);
2684 .................... break;
2685 .................... }
2686 .................... case 4:
2687 .................... {
2688 .................... return (-atan(z));
2689 .................... break;
2690 .................... }
2691 .................... }
2692 .................... }
2693 .................... }
2694 ....................
2695 .................... //Overloaded functions for atan2() for PCD
2696 .................... // Overloaded function atan2() for data type - Float48
2697 .................... #if defined(__PCD__)
2698 .................... float48 atan2(float48 y,float48 x)
2699 .................... {
2700 .................... float48 z;
2701 .................... int1 sign;
2702 .................... unsigned int8 quad;
2703 .................... sign=0;
2704 .................... quad=0; //quadrant
2705 .................... quad=((y<=0.0)?((x<=0.0)?3:4):((x<0.0)?2:1));
2706 .................... if(y<0.0)
2707 .................... {
2708 .................... sign=1;
2709 .................... y=-y;
2710 .................... }
2711 .................... if(x<0.0)
2712 .................... {
2713 .................... x=-x;
2714 .................... }
2715 .................... if (x==0.0)
2716 .................... {
2717 .................... if(y==0.0)
2718 .................... {
2719 .................... #ifdef _ERRNO
2720 .................... {
2721 .................... errno=EDOM;
2722 .................... }
2723 .................... #endif
2724 .................... }
2725 .................... else
2726 .................... {
2727 .................... if(sign)
2728 .................... {
2729 .................... return (-(PI_DIV_BY_TWO));
2730 .................... }
2731 .................... else
2732 .................... {
2733 .................... return (PI_DIV_BY_TWO);
2734 .................... }
2735 .................... }
2736 .................... }
2737 .................... else
2738 .................... {
2739 .................... z=y/x;
2740 .................... switch(quad)
2741 .................... {
2742 .................... case 1:
2743 .................... {
2744 .................... return atan(z);
2745 .................... break;
2746 .................... }
2747 .................... case 2:
2748 .................... {
2749 .................... // return (atan(z)+PI_DIV_BY_TWO); //2L3122
2750 .................... return (PI-atan(z));
2751 .................... break;
2752 .................... }
2753 .................... case 3:
2754 .................... {
2755 .................... return (atan(z)-PI);
2756 .................... break;
2757 .................... }
2758 .................... case 4:
2759 .................... {
2760 .................... return (-atan(z));
2761 .................... break;
2762 .................... }
2763 .................... }
2764 .................... }
2765 .................... }
2766 ....................
2767 .................... // Overloaded function atan2() for data type - Float64
2768 .................... float64 atan2(float64 y,float64 x)
2769 .................... {
2770 .................... float64 z;
2771 .................... int1 sign;
2772 .................... unsigned int8 quad;
2773 .................... sign=0;
2774 .................... quad=0; //quadrant
2775 .................... quad=((y<=0.0)?((x<=0.0)?3:4):((x<0.0)?2:1));
2776 .................... if(y<0.0)
2777 .................... {
2778 .................... sign=1;
2779 .................... y=-y;
2780 .................... }
2781 .................... if(x<0.0)
2782 .................... {
2783 .................... x=-x;
2784 .................... }
2785 .................... if (x==0.0)
2786 .................... {
2787 .................... if(y==0.0)
2788 .................... {
2789 .................... #ifdef _ERRNO
2790 .................... {
2791 .................... errno=EDOM;
2792 .................... }
2793 .................... #endif
2794 .................... }
2795 .................... else
2796 .................... {
2797 .................... if(sign)
2798 .................... {
2799 .................... return (-(PI_DIV_BY_TWO));
2800 .................... }
2801 .................... else
2802 .................... {
2803 .................... return (PI_DIV_BY_TWO);
2804 .................... }
2805 .................... }
2806 .................... }
2807 .................... else
2808 .................... {
2809 .................... z=y/x;
2810 .................... switch(quad)
2811 .................... {
2812 .................... case 1:
2813 .................... {
2814 .................... return atan(z);
2815 .................... break;
2816 .................... }
2817 .................... case 2:
2818 .................... {
2819 .................... // return (atan(z)+PI_DIV_BY_TWO); //2L3122
2820 .................... return (PI-atan(z));
2821 .................... break;
2822 .................... }
2823 .................... case 3:
2824 .................... {
2825 .................... return (atan(z)-PI);
2826 .................... break;
2827 .................... }
2828 .................... case 4:
2829 .................... {
2830 .................... return (-atan(z));
2831 .................... break;
2832 .................... }
2833 .................... }
2834 .................... }
2835 .................... }
2836 .................... #endif
2837 ....................
2838 .................... //////////////////// Hyperbolic functions ////////////////////
2839 ....................
2840 .................... ////////////////////////////////////////////////////////////////////////////
2841 .................... // float cosh(float x)
2842 .................... ////////////////////////////////////////////////////////////////////////////
2843 .................... // Description : Computes the hyperbolic cosine value of x
2844 .................... // Returns : returns the hyperbolic cosine value of x
2845 .................... // Date : N/A
2846 .................... //
2847 ....................
2848 .................... float32 cosh(float32 x)
2849 .................... {
2850 .................... return ((exp(x)+exp(-x))/2);
2851 .................... }
2852 .................... //Overloaded functions for cosh() for PCD
2853 .................... // Overloaded function cosh() for data type - Float48
2854 .................... #if defined(__PCD__)
2855 .................... float48 cosh(float48 x)
2856 .................... {
2857 .................... return ((exp(x)+exp(-x))/2);
2858 .................... }
2859 ....................
2860 .................... // Overloaded function cosh() for data type - Float64
2861 .................... float64 cosh(float64 x)
2862 .................... {
2863 .................... return ((exp(x)+exp(-x))/2);
2864 .................... }
2865 .................... #endif
2866 ....................
2867 .................... ////////////////////////////////////////////////////////////////////////////
2868 .................... // float sinh(float x)
2869 .................... ////////////////////////////////////////////////////////////////////////////
2870 .................... // Description : Computes the hyperbolic sine value of x
2871 .................... // Returns : returns the hyperbolic sine value of x
2872 .................... // Date : N/A
2873 .................... //
2874 ....................
2875 .................... float32 sinh(float32 x)
2876 .................... {
2877 ....................
2878 .................... return ((exp(x) - exp(-x))/2);
2879 .................... }
2880 .................... //Overloaded functions for sinh() for PCD
2881 .................... // Overloaded function sinh() for data type - Float48
2882 .................... #if defined(__PCD__)
2883 .................... float48 sinh(float48 x)
2884 .................... {
2885 ....................
2886 .................... return ((exp(x) - exp(-x))/2);
2887 .................... }
2888 ....................
2889 .................... // Overloaded function sinh() for data type - Float48
2890 .................... float64 sinh(float64 x)
2891 .................... {
2892 ....................
2893 .................... return ((exp(x) - exp(-x))/2);
2894 .................... }
2895 .................... #endif
2896 ....................
2897 .................... ////////////////////////////////////////////////////////////////////////////
2898 .................... // float tanh(float x)
2899 .................... ////////////////////////////////////////////////////////////////////////////
2900 .................... // Description : Computes the hyperbolic tangent value of x
2901 .................... // Returns : returns the hyperbolic tangent value of x
2902 .................... // Date : N/A
2903 .................... //
2904 ....................
2905 .................... float32 tanh(float32 x)
2906 .................... {
2907 .................... return(sinh(x)/cosh(x));
2908 .................... }
2909 .................... //Overloaded functions for tanh() for PCD
2910 .................... // Overloaded function tanh() for data type - Float48
2911 .................... #if defined(__PCD__)
2912 .................... float48 tanh(float48 x)
2913 .................... {
2914 .................... return(sinh(x)/cosh(x));
2915 .................... }
2916 ....................
2917 .................... // Overloaded function tanh() for data type - Float64
2918 .................... float64 tanh(float64 x)
2919 .................... {
2920 .................... return(sinh(x)/cosh(x));
2921 .................... }
2922 .................... #endif
2923 ....................
2924 .................... ////////////////////////////////////////////////////////////////////////////
2925 .................... // float frexp(float x, signed int *exp)
2926 .................... ////////////////////////////////////////////////////////////////////////////
2927 .................... // Description : breaks a floating point number into a normalized fraction and an integral
2928 .................... // power of 2. It stores the integer in the signed int object pointed to by exp.
2929 .................... // Returns : returns the value x, such that x is a double with magnitude in the interval
2930 .................... // [1/2,1) or zero, and value equals x times 2 raised to the power *exp.If value is zero,
2931 .................... // both parts of the result are zero.
2932 .................... // Date : N/A
2933 .................... //
2934 ....................
2935 .................... #define LOG2 .30102999566398119521
2936 .................... float32 frexp(float32 x, signed int8 *exp)
2937 .................... {
2938 .................... float32 res;
2939 .................... int1 sign = 0;
2940 .................... if(x == 0.0)
2941 .................... {
2942 .................... *exp=0;
2943 .................... return (0.0);
2944 .................... }
2945 .................... if(x < 0.0)
2946 .................... {
2947 .................... x=-x;
2948 .................... sign=1;
2949 .................... }
2950 .................... if (x > 1.0)
2951 .................... {
2952 .................... *exp=(ceil(log10(x)/LOG2));
2953 .................... res=x/(pow(2, *exp));
2954 .................... if (res == 1)
2955 .................... {
2956 .................... *exp=*exp+1;
2957 .................... res=.5;
2958 .................... }
2959 .................... }
2960 .................... else
2961 .................... {
2962 .................... if(x < 0.5)
2963 .................... {
2964 .................... *exp=-1;
2965 .................... res=x*2;
2966 .................... }
2967 .................... else
2968 .................... {
2969 .................... *exp=0;
2970 .................... res=x;
2971 .................... }
2972 .................... }
2973 .................... if(sign)
2974 .................... {
2975 .................... res=-res;
2976 .................... }
2977 .................... return res;
2978 .................... }
2979 ....................
2980 .................... //Overloaded functions for frexp() for PCD
2981 .................... // Overloaded function frexp() for data type - Float48
2982 .................... #if defined(__PCD__)
2983 .................... float48 frexp(float48 x, signed int8 *exp)
2984 .................... {
2985 .................... float48 res;
2986 .................... int1 sign = 0;
2987 .................... if(x == 0.0)
2988 .................... {
2989 .................... *exp=0;
2990 .................... return (0.0);
2991 .................... }
2992 .................... if(x < 0.0)
2993 .................... {
2994 .................... x=-x;
2995 .................... sign=1;
2996 .................... }
2997 .................... if (x > 1.0)
2998 .................... {
2999 .................... *exp=(ceil(log10(x)/LOG2));
3000 .................... res=x/(pow(2, *exp));
3001 .................... if (res == 1)
3002 .................... {
3003 .................... *exp=*exp+1;
3004 .................... res=.5;
3005 .................... }
3006 .................... }
3007 .................... else
3008 .................... {
3009 .................... if(x < 0.5)
3010 .................... {
3011 .................... *exp=-1;
3012 .................... res=x*2;
3013 .................... }
3014 .................... else
3015 .................... {
3016 .................... *exp=0;
3017 .................... res=x;
3018 .................... }
3019 .................... }
3020 .................... if(sign)
3021 .................... {
3022 .................... res=-res;
3023 .................... }
3024 .................... return res;
3025 .................... }
3026 ....................
3027 .................... // Overloaded function frexp() for data type - Float64
3028 .................... float64 frexp(float64 x, signed int8 *exp)
3029 .................... {
3030 .................... float64 res;
3031 .................... int1 sign = 0;
3032 .................... if(x == 0.0)
3033 .................... {
3034 .................... *exp=0;
3035 .................... return (0.0);
3036 .................... }
3037 .................... if(x < 0.0)
3038 .................... {
3039 .................... x=-x;
3040 .................... sign=1;
3041 .................... }
3042 .................... if (x > 1.0)
3043 .................... {
3044 .................... *exp=(ceil(log10(x)/LOG2));
3045 .................... res=x/(pow(2, *exp));
3046 .................... if (res == 1)
3047 .................... {
3048 .................... *exp=*exp+1;
3049 .................... res=.5;
3050 .................... }
3051 .................... }
3052 .................... else
3053 .................... {
3054 .................... if(x < 0.5)
3055 .................... {
3056 .................... *exp=-1;
3057 .................... res=x*2;
3058 .................... }
3059 .................... else
3060 .................... {
3061 .................... *exp=0;
3062 .................... res=x;
3063 .................... }
3064 .................... }
3065 .................... if(sign)
3066 .................... {
3067 .................... res=-res;
3068 .................... }
3069 .................... return res;
3070 .................... }
3071 .................... #endif
3072 ....................
3073 .................... //////////////////////////////////////////////////////////////////////////////
3074 .................... // float ldexp(float x, signed int *exp)
3075 .................... //////////////////////////////////////////////////////////////////////////////
3076 .................... // Description : multiplies a floating point number by an integral power of 2.
3077 .................... // Returns : returns the value of x times 2 raised to the power exp.
3078 .................... // Date : N/A
3079 .................... //
3080 ....................
3081 .................... float32 ldexp(float32 value, signed int8 exp)
3082 .................... {
3083 .................... return (value * pow(2,exp));
3084 .................... }
3085 .................... //Overloaded functions for ldexp() for PCD
3086 .................... // Overloaded function ldexp() for data type - Float48
3087 ....................
3088 .................... #if defined(__PCD__)
3089 .................... float48 ldexp(float48 value, signed int8 exp)
3090 .................... {
3091 .................... return (value * pow(2,exp));
3092 .................... }
3093 .................... // Overloaded function ldexp() for data type - Float64
3094 .................... float64 ldexp(float64 value, signed int8 exp)
3095 .................... {
3096 .................... return (value * pow(2,exp));
3097 .................... }
3098 .................... #endif
3099 ....................
3100 .................... #endif
3101 ....................
3102 .................... #include <stdio.h>
3103 .................... ///////////////////////////////////////////////////////////////////////////
3104 .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
3105 .................... //// This source code may only be used by licensed users of the CCS C ////
3106 .................... //// compiler. This source code may only be distributed to other ////
3107 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
3108 .................... //// or distribution is permitted without written permission. ////
3109 .................... //// Derivative programs created using this software in object code ////
3110 .................... //// form are not restricted in any way. ////
3111 .................... ///////////////////////////////////////////////////////////////////////////
3112 ....................
3113 .................... #ifndef _STDIO
3114 .................... #define _STDIO
3115 .................... #include <string.h>
3116 .................... ////////////////////////////////////////////////////////////////////////////
3117 .................... //// (C) Copyright 1996,2008 Custom Computer Services ////
3118 .................... //// This source code may only be used by licensed users of the CCS C ////
3119 .................... //// compiler. This source code may only be distributed to other ////
3120 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
3121 .................... //// or distribution is permitted without written permission. ////
3122 .................... //// Derivative programs created using this software in object code ////
3123 .................... //// form are not restricted in any way. ////
3124 .................... ////////////////////////////////////////////////////////////////////////////
3125 ....................
3126 .................... #ifndef _STRING
3127 .................... #define _STRING
3128 .................... #include <stddef.h>
3129 .................... ///////////////////////////////////////////////////////////////////////////
3130 .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
3131 .................... //// This source code may only be used by licensed users of the CCS C ////
3132 .................... //// compiler. This source code may only be distributed to other ////
3133 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
3134 .................... //// or distribution is permitted without written permission. ////
3135 .................... //// Derivative programs created using this software in object code ////
3136 .................... //// form are not restricted in any way. ////
3137 .................... ///////////////////////////////////////////////////////////////////////////
3138 ....................
3139 .................... #ifndef _STDDEF
3140 ....................
3141 .................... #define _STDDEF
3142 ....................
3143 .................... #if sizeof(unsigned int8 *)==1
3144 .................... #define ptrdiff_t unsigned int8
3145 .................... #else
3146 .................... #define ptrdiff_t unsigned int16
3147 .................... #endif
3148 ....................
3149 .................... #define size_t unsigned int8
3150 .................... #define wchar_t char
3151 .................... #define NULL 0
3152 ....................
3153 .................... #define offsetof(s,f) (offsetofbit(s,f)/8)
3154 ....................
3155 .................... #endif
3156 ....................
3157 .................... #include <ctype.h>
3158 .................... ////////////////////////////////////////////////////////////////////////////
3159 .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
3160 .................... //// This source code may only be used by licensed users of the CCS C ////
3161 .................... //// compiler. This source code may only be distributed to other ////
3162 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
3163 .................... //// or distribution is permitted without written permission. ////
3164 .................... //// Derivative programs created using this software in object code ////
3165 .................... //// form are not restricted in any way. ////
3166 .................... ////////////////////////////////////////////////////////////////////////////
3167 ....................
3168 .................... #ifndef _CTYPE
3169 .................... #define _CTYPE
3170 ....................
3171 .................... #define islower(x) isamong(x,"abcdefghijklmnopqrstuvwxyz")
3172 .................... #define isupper(x) isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZ")
3173 .................... #define isalnum(x) isamong(x,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
3174 .................... #define isalpha(x) isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
3175 .................... #define isdigit(x) isamong(x,"0123456789")
3176 .................... #define isspace(x) ((x)==' ')
3177 .................... #define isxdigit(x) isamong(x,"0123456789ABCDEFabcdef")
3178 .................... #define iscntrl(x) ((x)<' ')
3179 .................... #define isprint(x) ((x)>=' ')
3180 .................... #define isgraph(x) ((x)>' ')
3181 .................... #define ispunct(x) (((x)>' ')&&!isalnum(x))
3182 ....................
3183 .................... #endif
3184 ....................
3185 ....................
3186 ....................
3187 ....................
3188 ....................
3189 .................... //////////////////////////////////////////////
3190 .................... //// Uncomment the following define to ////
3191 .................... //// allow some functions to use a ////
3192 .................... //// quicker algorithm, but use more ROM ////
3193 .................... //// ////
3194 .................... //// #define FASTER_BUT_MORE_ROM ////
3195 .................... //////////////////////////////////////////////
3196 ....................
3197 ....................
3198 ....................
3199 .................... /*Copying functions*/
3200 .................... /* standard template:
3201 .................... void *memmove(void *s1, void *s2, size_t n).
3202 .................... Copies max of n characters safely (not following ending '\0')
3203 .................... from s2 in s1; if s2 has less than n characters, appends 0 */
3204 ....................
3205 .................... char *memmove(void *s1,char *s2,size_t n)
3206 .................... {
3207 .................... char *sc1;
3208 .................... char *sc2;
3209 .................... sc1=s1;
3210 .................... sc2=s2;
3211 .................... if(sc2<sc1 && sc1 <sc2 +n)
3212 .................... for(sc1+=n,sc2+=n;0<n;--n)
3213 .................... *--sc1=*--sc2;
3214 .................... else
3215 .................... for(;0<n;--n)
3216 .................... *sc1++=*sc2++;
3217 .................... return s1;
3218 .................... }
3219 ....................
3220 .................... /* Standard template: char *strcpy(char *s1, const char *s2)
3221 .................... copies the string s2 including the null character to s1.
3222 .................... This is a compiler built in to handle the different address
3223 .................... spaces */
3224 ....................
3225 .................... #define strcopy strcpy
3226 ....................
3227 .................... /* standard template:
3228 .................... char *strncpy(char *s1, const char *s2, size_t n).
3229 .................... Copies max of n characters (not following ending '\0')
3230 .................... from s2 in s1; if s2 has less than n characters, appends 0 */
3231 ....................
3232 .................... char *strncpy(char *s1, char *s2, size_t n)
3233 .................... {
3234 .................... char *s;
3235 ....................
3236 .................... for (s = s1; n > 0 && *s2 != '\0'; n--)
3237 .................... *s++ = *s2++;
3238 .................... for (; n > 0; n--)
3239 .................... *s++ = '\0';
3240 ....................
3241 .................... return(s1);
3242 .................... }
3243 .................... /***********************************************************/
3244 ....................
3245 .................... /*concatenation functions*/
3246 .................... /* standard template: char *strcat(char *s1, const char *s2)
3247 .................... appends s2 to s1*/
3248 ....................
3249 .................... char *strcat(char *s1, char *s2)
3250 .................... {
3251 .................... char *s;
3252 ....................
3253 .................... for (s = s1; *s != '\0'; ++s);
3254 .................... while(*s2 != '\0')
3255 .................... {
3256 .................... *s = *s2;
3257 .................... ++s;
3258 .................... ++s2;
3259 .................... }
3260 ....................
3261 .................... *s = '\0';
3262 .................... return(s1);
3263 .................... }
3264 .................... /* standard template: char *strncat(char *s1, char *s2,size_t n)
3265 .................... appends not more than n characters from s2 to s1*/
3266 ....................
3267 .................... char *strncat(char *s1, char *s2, size_t n)
3268 .................... {
3269 .................... char *s;
3270 ....................
3271 .................... for (s = s1; *s != '\0'; ++s);
3272 .................... while(*s2 != '\0' && 0<n)
3273 .................... {
3274 .................... *s = *s2;
3275 .................... ++s;
3276 .................... ++s2;
3277 .................... --n;
3278 .................... }
3279 ....................
3280 .................... *s = '\0';
3281 .................... return(s1);
3282 .................... }
3283 ....................
3284 .................... /***********************************************************/
3285 ....................
3286 ....................
3287 .................... /*comparison functions*/
3288 .................... /* standard template: signed int memcmp(void *s1, void *s2).
3289 .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
3290 ....................
3291 .................... signed int8 memcmp(void * s1,char *s2,size_t n)
3292 .................... {
3293 .................... char *su1, *su2;
3294 .................... for(su1=s1, su2=s2; 0<n; ++su1, ++su2, --n)
3295 .................... {
3296 .................... if(*su1!=*su2)
3297 .................... return ((*su1<*su2)?-1:+1);
3298 .................... }
3299 .................... return 0;
3300 .................... }
3301 ....................
3302 .................... /* standard template: int strcmp(const char *s1, const char *s2).
3303 .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
3304 ....................
3305 .................... signed int8 strcmp(char *s1, char *s2)
3306 .................... {
3307 .................... for (; *s1 == *s2; s1++, s2++)
3308 .................... if (*s1 == '\0')
3309 .................... return(0);
3310 .................... return((*s1 < *s2) ? -1: 1);
3311 .................... }
3312 .................... /* standard template: int strcoll(const char *s1, const char *s2).
3313 .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
3314 ....................
3315 .................... signed int8 strcoll(char *s1, char *s2)
3316 .................... {
3317 .................... for (; *s1 == *s2; s1++, s2++)
3318 .................... if (*s1 == '\0')
3319 .................... return(0);
3320 .................... return((*s1 < *s2) ? -1: 1);
3321 .................... }
3322 ....................
3323 .................... /* standard template:
3324 .................... int strncmp(const char *s1, const char *s2, size_t n).
3325 .................... Compares max of n characters (not following 0) from s1 to s2;
3326 .................... returns same as strcmp */
3327 ....................
3328 .................... signed int8 strncmp(char *s1, char *s2, size_t n)
3329 .................... {
3330 .................... for (; n > 0; s1++, s2++, n--)
3331 .................... if (*s1 != *s2)
3332 .................... return((*s1 <*s2) ? -1: 1);
3333 .................... else if (*s1 == '\0')
3334 .................... return(0);
3335 .................... return(0);
3336 .................... }
3337 .................... /* standard template:
3338 .................... int strxfrm(const char *s1, const char *s2, size_t n).
3339 .................... transforms maximum of n characters from s2 and places them into s1*/
3340 .................... size_t strxfrm(char *s1, char *s2, size_t n)
3341 .................... {
3342 .................... char *s;
3343 .................... unsigned int8 n1;
3344 .................... n1=n;
3345 .................... for (s = s1; n > 0 && *s2 != '\0'; n--)
3346 .................... *s++ = *s2++;
3347 .................... for (; n > 0; n--)
3348 .................... *s++ = '\0';
3349 ....................
3350 .................... return(n1);
3351 .................... }
3352 ....................
3353 ....................
3354 ....................
3355 ....................
3356 ....................
3357 .................... /***********************************************************/
3358 .................... /*Search functions*/
3359 .................... /* standard template: void *memchr(const char *s, int c).
3360 .................... Finds first occurrence of c in n characters of s */
3361 ....................
3362 .................... char *memchr(void *s,unsigned int8 c,size_t n)
3363 .................... {
3364 .................... char uc;
3365 .................... char *su;
3366 .................... uc=c;
3367 .................... for(su=s;0<n;++su,--n)
3368 .................... if(*su==uc)
3369 .................... return su;
3370 .................... return NULL;
3371 .................... }
3372 ....................
3373 .................... /* standard template: char *strchr(const char *s, int c).
3374 .................... Finds first occurrence of c in s */
3375 ....................
3376 .................... char *strchr(char *s, unsigned int8 c)
3377 .................... {
3378 .................... for (; *s != c; s++)
3379 .................... if (*s == '\0')
3380 .................... return(0);
3381 .................... return(s);
3382 .................... }
3383 .................... /* standard template:
3384 .................... size_t strcspn(const char *s1, const char *s2).
3385 .................... Computes length of max initial segment of s1 that
3386 .................... consists entirely of characters NOT from s2*/
3387 ....................
3388 .................... unsigned int8 strcspn(char *s1, char *s2)
3389 .................... {
3390 .................... char *sc1, *sc2;
3391 ....................
3392 .................... for (sc1 = s1; *sc1 != 0; sc1++)
3393 .................... for (sc2 = s2; *sc2 != 0; sc2++)
3394 .................... if (*sc1 == *sc2)
3395 .................... return(sc1 - s1);
3396 .................... return(sc1 - s1);
3397 .................... }
3398 .................... /* standard template:
3399 .................... char *strpbrk(const char *s1, const char *s2).
3400 .................... Locates first occurence of any character from s2 in s1;
3401 .................... returns s1 if s2 is empty string */
3402 ....................
3403 .................... char *strpbrk(char *s1, char *s2)
3404 .................... {
3405 .................... char *sc1, *sc2;
3406 ....................
3407 .................... for (sc1 = s1; *sc1 != 0; sc1++)
3408 .................... for (sc2 = s2; *sc2 != 0; sc2++)
3409 .................... if (*sc1 == *sc2)
3410 .................... return(sc1);
3411 .................... return(0);
3412 .................... }
3413 ....................
3414 ....................
3415 .................... /* standard template: char *strrchr(const char *s, int c).
3416 .................... Finds last occurrence of c in s */
3417 ....................
3418 .................... char *strrchr(char *s, unsigned int8 c)
3419 .................... {
3420 .................... char *p;
3421 ....................
3422 .................... for (p = 0; ; s++)
3423 .................... {
3424 .................... if (*s == c)
3425 .................... p = s;
3426 .................... if (*s == '\0')
3427 .................... return(p);
3428 .................... }
3429 .................... }
3430 .................... /* computes length of max initial segment of s1 consisting
3431 .................... entirely of characters from s2 */
3432 ....................
3433 .................... unsigned int8 strspn(char *s1, char *s2)
3434 .................... {
3435 .................... char *sc1, *sc2;
3436 ....................
3437 .................... for (sc1 = s1; *sc1 != 0; sc1++)
3438 .................... for (sc2 = s2; ; sc2++)
3439 .................... if (*sc2 == '\0')
3440 .................... return(sc1 - s1);
3441 .................... else if (*sc1 == *sc2)
3442 .................... break;
3443 .................... return(sc1 - s1);
3444 .................... }
3445 .................... /* standard template:
3446 .................... char *strstr(const char *s1, const char *s2);
3447 .................... Locates first occurence of character sequence s2 in s1;
3448 .................... returns 0 if s2 is empty string
3449 ....................
3450 .................... Uncomment #define FASTER_BUT_MORE_ROM at the top of the
3451 .................... file to use the faster algorithm */
3452 .................... char *strstr(char *s1, char *s2)
3453 .................... {
3454 .................... char *s, *t;
3455 ....................
3456 .................... #ifdef FASTER_BUT_MORE_ROM
3457 .................... if (*s2 == '\0')
3458 .................... return(s1);
3459 .................... #endif
3460 ....................
3461 .................... while (*s1)
3462 .................... {
3463 .................... for(s = s1, t = s2; *t && (*s == *t); ++s, ++t);
3464 ....................
3465 .................... if (*t == '\0')
3466 .................... return s1;
3467 .................... ++s1;
3468 .................... #ifdef FASTER_BUT_MORE_ROM
3469 .................... while(*s1 != '\0' && *s1 != *s2)
3470 .................... ++s1;
3471 .................... #endif
3472 .................... }
3473 .................... return 0;
3474 .................... }
3475 ....................
3476 .................... /* standard template: char *strtok(char *s1, const char *s2).
3477 ....................
3478 .................... Finds next token in s1 delimited by a character from separator
3479 .................... string s2 (which can be different from call to call). First call
3480 .................... starts at beginning of s1 searching for first character NOT
3481 .................... contained in s2; returns 0 if none is found.
3482 .................... If one is found, it is the start of first token (return value).
3483 .................... Function then searches from there for a character contained in s2.
3484 .................... If none is found, current token extends to end of s1, and subsequent
3485 .................... searches for a token will return 0. If one is found, it is
3486 .................... overwritten by '\0', which terminates current token. Function saves
3487 .................... pointer to following character from which next search will start.
3488 .................... Each subsequent call, with 0 as first argument, starts searching
3489 .................... from saved pointer */
3490 ....................
3491 .................... char *strtok(char *s1, char *s2)
3492 .................... {
3493 .................... char *beg, *end;
3494 .................... static char *save;
3495 *
3496 10CE: CLRF 21
3497 10CF: CLRF 22
3498 ....................
3499 .................... beg = (s1)? s1: save;
3500 .................... beg += strspn(beg, s2);
3501 .................... if (*beg == '\0')
3502 .................... {
3503 .................... *save = ' ';
3504 .................... return(0);
3505 .................... }
3506 .................... end = strpbrk(beg, s2);
3507 .................... if (*end != '\0')
3508 .................... {
3509 .................... *end = '\0';
3510 .................... end++;
3511 .................... }
3512 .................... save = end;
3513 .................... return(beg);
3514 .................... }
3515 ....................
3516 .................... /*****************************************************************/
3517 .................... /*Miscellaneous functions*/
3518 .................... /* standard template
3519 .................... maps error number in errnum to an error message string
3520 .................... Returns: Pointer to string
3521 .................... */
3522 .................... #ifdef _ERRNO
3523 .................... char * strerror(unsigned int8 errnum)
3524 .................... {
3525 .................... char s[15];
3526 .................... switch( errnum)
3527 .................... {
3528 .................... case 0:
3529 .................... strcpy(s,"no errors");
3530 .................... return s;
3531 .................... case EDOM :
3532 .................... strcpy(s,"domain error");
3533 .................... return s;
3534 .................... case ERANGE:
3535 .................... strcpy(s,"range error");
3536 .................... return s;
3537 .................... }
3538 .................... }
3539 .................... #ENDIF
3540 .................... /* standard template: size_t strlen(const char *s).
3541 .................... Computes length of s1 (preceding terminating 0) */
3542 ....................
3543 .................... unsigned int8 strlen(char *s)
3544 .................... {
3545 .................... char *sc;
3546 ....................
3547 .................... for (sc = s; *sc != 0; sc++);
3548 .................... return(sc - s);
3549 .................... }
3550 ....................
3551 .................... /* standard template: size_t stricmp(const char *s1, const char *s2).
3552 .................... Compares s1 to s2 ignoring case (upper vs. lower) */
3553 ....................
3554 .................... signed int8 stricmp(char *s1, char *s2)
3555 .................... {
3556 .................... for(; *s1==*s2||(isalpha(*s1)&&isalpha(*s2)&&(*s1==*s2+32||*s2==*s1+32));
3557 .................... s1++, s2++)
3558 .................... if (*s1 == '\0')
3559 .................... return(0);
3560 .................... return((*s1 < *s2) ? -1: 1);
3561 .................... }
3562 ....................
3563 ....................
3564 .................... /* standard template: char *strlwr(char *s).
3565 .................... Replaces uppercase letters by lowercase;
3566 .................... returns pointer to new string s */
3567 ....................
3568 .................... char *strlwr(char *s)
3569 .................... {
3570 .................... char *p;
3571 ....................
3572 .................... for (p = s; *p != '\0'; p++)
3573 .................... if (*p >= 'A' && *p <='Z')
3574 .................... *p += 'a' - 'A';
3575 .................... return(s);
3576 .................... }
3577 ....................
3578 ....................
3579 .................... /************************************************************/
3580 ....................
3581 ....................
3582 .................... #endif
3583 ....................
3584 .................... #ifndef getc
3585 .................... #define getc getch
3586 .................... #define getchar getch
3587 .................... #define puts(s) {printf(s); putchar(13); putchar(10);}
3588 .................... #define putc putchar
3589 .................... #endif
3590 .................... /* maps error number to an error message. Writes a sequence of characters to
3591 .................... stderr stream thus: if s is not null then string pointed to by s follwed by
3592 .................... a colon (:) and a space and the appropriate error message returned by strerror
3593 .................... function with argument errno
3594 ....................
3595 .................... Returns: no value
3596 .................... */
3597 ....................
3598 .................... #ifdef _ERRNO
3599 .................... void perror(char *s)
3600 .................... {
3601 .................... if(s)
3602 .................... fprintf(STDERR,"%s: ",s);
3603 .................... fprintf(STDERR,"%s\r\n",strerror(errno));
3604 .................... }
3605 .................... #endif
3606 .................... #endif
3607 ....................
3608 ....................
3609 .................... #include <stdlib.h>
3610 .................... ///////////////////////////////////////////////////////////////////////////
3611 .................... //// (C) Copyright 1996,2007 Custom Computer Services ////
3612 .................... //// This source code may only be used by licensed users of the CCS C ////
3613 .................... //// compiler. This source code may only be distributed to other ////
3614 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
3615 .................... //// or distribution is permitted without written permission. ////
3616 .................... //// Derivative programs created using this software in object code ////
3617 .................... //// form are not restricted in any way. ////
3618 .................... ///////////////////////////////////////////////////////////////////////////
3619 ....................
3620 .................... #ifndef _STDLIB
3621 .................... #define _STDLIB
3622 ....................
3623 .................... //---------------------------------------------------------------------------
3624 .................... // Definitions and types
3625 .................... //---------------------------------------------------------------------------
3626 ....................
3627 .................... #ifndef RAND_MAX
3628 .................... #define RAND_MAX 32767 // The value of which is the maximum value
3629 .................... // ... returned by the rand function
3630 .................... #endif
3631 ....................
3632 ....................
3633 .................... #IF (sizeof(int16*)>1)
3634 .................... #DEFINE LONG_POINTERS 1
3635 .................... #ELSE
3636 .................... #DEFINE LONG_POINTERS 0
3637 .................... #ENDIF
3638 ....................
3639 .................... typedef struct {
3640 .................... signed int quot;
3641 .................... signed int rem;
3642 .................... } div_t;
3643 ....................
3644 .................... typedef struct {
3645 .................... signed long quot;
3646 .................... signed long rem;
3647 .................... } ldiv_t;
3648 ....................
3649 .................... #include <stddef.h>
3650 .................... ///////////////////////////////////////////////////////////////////////////
3651 .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
3652 .................... //// This source code may only be used by licensed users of the CCS C ////
3653 .................... //// compiler. This source code may only be distributed to other ////
3654 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
3655 .................... //// or distribution is permitted without written permission. ////
3656 .................... //// Derivative programs created using this software in object code ////
3657 .................... //// form are not restricted in any way. ////
3658 .................... ///////////////////////////////////////////////////////////////////////////
3659 ....................
3660 .................... #ifndef _STDDEF
3661 ....................
3662 .................... #define _STDDEF
3663 ....................
3664 .................... #if sizeof(unsigned int8 *)==1
3665 .................... #define ptrdiff_t unsigned int8
3666 .................... #else
3667 .................... #define ptrdiff_t unsigned int16
3668 .................... #endif
3669 ....................
3670 .................... #define size_t unsigned int8
3671 .................... #define wchar_t char
3672 .................... #define NULL 0
3673 ....................
3674 .................... #define offsetof(s,f) (offsetofbit(s,f)/8)
3675 ....................
3676 .................... #endif
3677 ....................
3678 ....................
3679 .................... //---------------------------------------------------------------------------
3680 .................... // String conversion functions
3681 .................... //---------------------------------------------------------------------------
3682 ....................
3683 .................... /* Standard template: signed int atoi(char * s)
3684 .................... * converts the initial portion of the string s to a signed int
3685 .................... * returns the converted value if any, 0 otherwise
3686 .................... */
3687 .................... signed int atoi(char *s);
3688 ....................
3689 .................... /* Syntax: signed int32 atoi32(char * s)
3690 .................... converts the initial portion of the string s to a signed int32
3691 .................... returns the converted value if any, 0 otherwise*/
3692 .................... #if (sizeof(long)==4)
3693 .................... #define atoi32(s) atol(s)
3694 .................... #else
3695 .................... signed int32 atoi32(char *s);
3696 .................... #endif
3697 ....................
3698 .................... #if defined(__PCD__)
3699 .................... // The following functions only work on the 24 bit compiler
3700 .................... // for the 30F, 33F, 24F and 24H parts
3701 .................... /* Syntax: signed int48 atoi48(char * s)
3702 .................... converts the initial portion of the string s to a signed int48
3703 .................... returns the converted value if any, 0 otherwise*/
3704 ....................
3705 .................... signed int48 atoi48(char *s);
3706 ....................
3707 .................... /* Syntax: signed int64 atoi64(char * s)
3708 .................... converts the initial portion of the string s to a signed int64
3709 .................... returns the converted value if any, 0 otherwise*/
3710 .................... signed int64 atoi64(char *s);
3711 .................... #endif
3712 ....................
3713 .................... /* Syntax: char * itoa(signed int32 num, int8 base, char * s)
3714 .................... converts the signed int32 to a string and
3715 .................... returns the converted value if any, 0 otherwise*/
3716 .................... char * itoa(signed int32 num, unsigned int base, char * s);
3717 ....................
3718 .................... /* Standard template: signed int16 atol(char * s)
3719 .................... * converts the initial portion of the string s to a signed int16
3720 .................... * returns the converted value if any, 0 otherwise
3721 .................... */
3722 .................... signed long atol(char *s);
3723 ....................
3724 .................... /* Standard template: int16 strtoul(char * s,char *endptr,signed int base)
3725 .................... * converts the initial portion of the string s, represented as an
3726 .................... * integral value of radix base to a signed long.
3727 .................... * Returns the converted value if any, 0 otherwise
3728 .................... * the final string is returned in the endptr, if endptr is not null
3729 .................... */
3730 .................... signed long strtol(char *s,char *endptr, signed int base);
3731 ....................
3732 .................... /* Standard template: int16 strtoul(char * s,char *endptr,signed int base)
3733 .................... * converts the initial portion of the string s, represented as an
3734 .................... * integral value of radix base to a unsigned long.
3735 .................... * returns the converted value if any, 0 otherwise
3736 .................... * the final string is returned in the endptr, if endptr is not null
3737 .................... */
3738 .................... unsigned long strtoul(char *s,char *endptr, signed int base);
3739 ....................
3740 .................... /* Standart template: float strtof(char * s,char *endptr)
3741 .................... float48 strtof48(char *s,char *endptr);
3742 .................... float64 strtod(char *s,char *endptr);
3743 .................... * converts the initial portion of the string s to a float32, float48 or float64,
3744 .................... * returns the converted value if any, 0 otherwise
3745 .................... * the final string is returned in the endptr, if endptr is not null
3746 .................... */
3747 .................... float strtof(char *s,char *endptr);
3748 .................... #if defined(__PCD__)
3749 .................... float48 strtof48(char *s,char *endptr);
3750 .................... float64 strtod(char *s,char *endptr);
3751 .................... #else
3752 .................... //provided for compatibility
3753 .................... #define strtof48(s, e) strtof(s, e)
3754 .................... #define strtod(s, e) strtof(s, e)
3755 .................... #endif
3756 ....................
3757 .................... /* Standard template: float32 atof(char * s)
3758 .................... * converts the initial portion of the string s to a float.
3759 .................... * returns the converted value if any, 0 otherwise
3760 .................... */
3761 .................... #define atof(s) strtof(s, 0)
3762 ....................
3763 .................... #if defined(__PCD__)
3764 .................... // The following functions only work on the 24 bit compiler
3765 .................... // for the 30F, 33F, 24F and 24H parts
3766 ....................
3767 .................... /* Standard template: float48 atof48(char * s)
3768 .................... * converts the initial portion of the string s to a float.
3769 .................... * returns the converted value if any, 0 otherwise
3770 .................... */
3771 .................... #define atof48(s) strtof48(s, 0)
3772 ....................
3773 .................... /* Standard template: float64 atof64(char * s)
3774 .................... * converts the initial portion of the string s to a float.
3775 .................... * returns the converted value if any, 0 otherwise
3776 .................... */
3777 .................... #define atof64(s) strtod(s, 0)
3778 .................... #endif
3779 ....................
3780 .................... /* Standard template: float32 atoe(char * s)
3781 .................... * converts the initial portion of the string s to a float.
3782 .................... * returns the converted value if any, 0 otherwise
3783 .................... * also handles E format numbers
3784 .................... */
3785 .................... #if !defined(__PCD__)
3786 .................... float atoe(char * s);
3787 .................... #endif
3788 ....................
3789 .................... #if defined(__PCD__)
3790 .................... float32 atoe(char * s);
3791 .................... #endif
3792 ....................
3793 .................... //---------------------------------------------------------------------------
3794 .................... // Pseudo-random sequence generation functions
3795 .................... //---------------------------------------------------------------------------
3796 ....................
3797 .................... /* The rand function computes a sequence of pseudo-random integers in
3798 .................... * the range 0 to RAND_MAX
3799 .................... *
3800 .................... * Parameters:
3801 .................... * (none)
3802 .................... *
3803 .................... * Returns:
3804 .................... * The pseudo-random integer
3805 .................... */
3806 .................... unsigned int16 rand(void);
3807 ....................
3808 .................... /* The srand function uses the argument as a seed for a new sequence of
3809 .................... * pseudo-random numbers to be returned by subsequent calls to rand.
3810 .................... *
3811 .................... * Parameters:
3812 .................... * [in] seed: The seed value to start from. You might need to pass
3813 .................... *
3814 .................... * Returns:
3815 .................... * (none)
3816 .................... *
3817 .................... * Remarks
3818 .................... * The srand function sets the starting point for generating
3819 .................... * a series of pseudorandom integers. To reinitialize the
3820 .................... * generator, use 1 as the seed argument. Any other value for
3821 .................... * seed sets the generator to a random starting point. rand
3822 .................... * retrieves the pseudorandom numbers that are generated.
3823 .................... * Calling rand before any call to srand generates the same
3824 .................... * sequence as calling srand with seed passed as 1.
3825 .................... * Usually, you need to pass a time here from outer source
3826 .................... * so that the numbers will be different every time you run.
3827 .................... */
3828 .................... void srand(unsigned int32 seed);
3829 ....................
3830 .................... //---------------------------------------------------------------------------
3831 .................... // Memory management functions
3832 .................... //---------------------------------------------------------------------------
3833 ....................
3834 .................... // Comming soon
3835 ....................
3836 .................... //---------------------------------------------------------------------------
3837 .................... // Communication with the environment
3838 .................... //---------------------------------------------------------------------------
3839 ....................
3840 .................... /* The function returns 0 always
3841 .................... */
3842 .................... signed int8 system(char *string);
3843 ....................
3844 .................... //---------------------------------------------------------------------------
3845 .................... // Searching and sorting utilities
3846 .................... //---------------------------------------------------------------------------
3847 ....................
3848 .................... /* Performs a binary search of a sorted array..
3849 .................... *
3850 .................... * Parameters:
3851 .................... * [in] key: Object to search for
3852 .................... * [in] base: Pointer to base of search data
3853 .................... * [in] num: Number of elements
3854 .................... * [in] width: Width of elements
3855 .................... * [in] compare: Function that compares two elements
3856 .................... *
3857 .................... * Returns:
3858 .................... * bsearch returns a pointer to an occurrence of key in the array pointed
3859 .................... * to by base. If key is not found, the function returns NULL. If the
3860 .................... * array is not in order or contains duplicate records with identical keys,
3861 .................... * the result is unpredictable.
3862 .................... */
3863 .................... //void *bsearch(const void *key, const void *base, size_t num, size_t width,
3864 .................... // int (*compare)(const void *, const void *));
3865 ....................
3866 .................... /* Performs the shell-metzner sort (not the quick sort algorithm). The contents
3867 .................... * of the array are sorted into ascending order according to a comparison
3868 .................... * function pointed to by compar.
3869 .................... *
3870 .................... * Parameters:
3871 .................... * [in] base: Pointer to base of search data
3872 .................... * [in] num: Number of elements
3873 .................... * [in] width: Width of elements
3874 .................... * [in] compare: Function that compares two elements
3875 .................... *
3876 .................... * Returns:
3877 .................... * (none)
3878 .................... */
3879 .................... //void *qsort(const void *base, size_t num, size_t width,
3880 .................... // int (*compare)(const void *, const void *));
3881 ....................
3882 .................... //---------------------------------------------------------------------------
3883 .................... // Integer arithmetic functions
3884 .................... //---------------------------------------------------------------------------
3885 ....................
3886 .................... #define labs abs
3887 ....................
3888 .................... div_t div(signed int numer, signed int denom);
3889 .................... ldiv_t ldiv(signed long numer, signed long denom);
3890 ....................
3891 .................... //---------------------------------------------------------------------------
3892 .................... // Multibyte character functions
3893 .................... //---------------------------------------------------------------------------
3894 ....................
3895 .................... // Not supported
3896 ....................
3897 .................... //---------------------------------------------------------------------------
3898 .................... // Multibyte string functions
3899 .................... //---------------------------------------------------------------------------
3900 ....................
3901 .................... // Not supported
3902 ....................
3903 ....................
3904 .................... //---------------------------------------------------------------------------
3905 .................... // Internal implementation
3906 .................... //---------------------------------------------------------------------------
3907 ....................
3908 .................... #include <stddef.h>
3909 .................... ///////////////////////////////////////////////////////////////////////////
3910 .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
3911 .................... //// This source code may only be used by licensed users of the CCS C ////
3912 .................... //// compiler. This source code may only be distributed to other ////
3913 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
3914 .................... //// or distribution is permitted without written permission. ////
3915 .................... //// Derivative programs created using this software in object code ////
3916 .................... //// form are not restricted in any way. ////
3917 .................... ///////////////////////////////////////////////////////////////////////////
3918 ....................
3919 .................... #ifndef _STDDEF
3920 ....................
3921 .................... #define _STDDEF
3922 ....................
3923 .................... #if sizeof(unsigned int8 *)==1
3924 .................... #define ptrdiff_t unsigned int8
3925 .................... #else
3926 .................... #define ptrdiff_t unsigned int16
3927 .................... #endif
3928 ....................
3929 .................... #define size_t unsigned int8
3930 .................... #define wchar_t char
3931 .................... #define NULL 0
3932 ....................
3933 .................... #define offsetof(s,f) (offsetofbit(s,f)/8)
3934 ....................
3935 .................... #endif
3936 ....................
3937 .................... #include <string.h>
3938 .................... ////////////////////////////////////////////////////////////////////////////
3939 .................... //// (C) Copyright 1996,2008 Custom Computer Services ////
3940 .................... //// This source code may only be used by licensed users of the CCS C ////
3941 .................... //// compiler. This source code may only be distributed to other ////
3942 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
3943 .................... //// or distribution is permitted without written permission. ////
3944 .................... //// Derivative programs created using this software in object code ////
3945 .................... //// form are not restricted in any way. ////
3946 .................... ////////////////////////////////////////////////////////////////////////////
3947 ....................
3948 .................... #ifndef _STRING
3949 .................... #define _STRING
3950 .................... #include <stddef.h>
3951 .................... #include <ctype.h>
3952 ....................
3953 ....................
3954 ....................
3955 .................... //////////////////////////////////////////////
3956 .................... //// Uncomment the following define to ////
3957 .................... //// allow some functions to use a ////
3958 .................... //// quicker algorithm, but use more ROM ////
3959 .................... //// ////
3960 .................... //// #define FASTER_BUT_MORE_ROM ////
3961 .................... //////////////////////////////////////////////
3962 ....................
3963 ....................
3964 ....................
3965 .................... /*Copying functions*/
3966 .................... /* standard template:
3967 .................... void *memmove(void *s1, void *s2, size_t n).
3968 .................... Copies max of n characters safely (not following ending '\0')
3969 .................... from s2 in s1; if s2 has less than n characters, appends 0 */
3970 ....................
3971 .................... char *memmove(void *s1,char *s2,size_t n)
3972 .................... {
3973 .................... char *sc1;
3974 .................... char *sc2;
3975 .................... sc1=s1;
3976 .................... sc2=s2;
3977 .................... if(sc2<sc1 && sc1 <sc2 +n)
3978 .................... for(sc1+=n,sc2+=n;0<n;--n)
3979 .................... *--sc1=*--sc2;
3980 .................... else
3981 .................... for(;0<n;--n)
3982 .................... *sc1++=*sc2++;
3983 .................... return s1;
3984 .................... }
3985 ....................
3986 .................... /* Standard template: char *strcpy(char *s1, const char *s2)
3987 .................... copies the string s2 including the null character to s1.
3988 .................... This is a compiler built in to handle the different address
3989 .................... spaces */
3990 ....................
3991 .................... #define strcopy strcpy
3992 ....................
3993 .................... /* standard template:
3994 .................... char *strncpy(char *s1, const char *s2, size_t n).
3995 .................... Copies max of n characters (not following ending '\0')
3996 .................... from s2 in s1; if s2 has less than n characters, appends 0 */
3997 ....................
3998 .................... char *strncpy(char *s1, char *s2, size_t n)
3999 .................... {
4000 .................... char *s;
4001 ....................
4002 .................... for (s = s1; n > 0 && *s2 != '\0'; n--)
4003 .................... *s++ = *s2++;
4004 .................... for (; n > 0; n--)
4005 .................... *s++ = '\0';
4006 ....................
4007 .................... return(s1);
4008 .................... }
4009 .................... /***********************************************************/
4010 ....................
4011 .................... /*concatenation functions*/
4012 .................... /* standard template: char *strcat(char *s1, const char *s2)
4013 .................... appends s2 to s1*/
4014 ....................
4015 .................... char *strcat(char *s1, char *s2)
4016 .................... {
4017 .................... char *s;
4018 ....................
4019 .................... for (s = s1; *s != '\0'; ++s);
4020 .................... while(*s2 != '\0')
4021 .................... {
4022 .................... *s = *s2;
4023 .................... ++s;
4024 .................... ++s2;
4025 .................... }
4026 ....................
4027 .................... *s = '\0';
4028 .................... return(s1);
4029 .................... }
4030 .................... /* standard template: char *strncat(char *s1, char *s2,size_t n)
4031 .................... appends not more than n characters from s2 to s1*/
4032 ....................
4033 .................... char *strncat(char *s1, char *s2, size_t n)
4034 .................... {
4035 .................... char *s;
4036 ....................
4037 .................... for (s = s1; *s != '\0'; ++s);
4038 .................... while(*s2 != '\0' && 0<n)
4039 .................... {
4040 .................... *s = *s2;
4041 .................... ++s;
4042 .................... ++s2;
4043 .................... --n;
4044 .................... }
4045 ....................
4046 .................... *s = '\0';
4047 .................... return(s1);
4048 .................... }
4049 ....................
4050 .................... /***********************************************************/
4051 ....................
4052 ....................
4053 .................... /*comparison functions*/
4054 .................... /* standard template: signed int memcmp(void *s1, void *s2).
4055 .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
4056 ....................
4057 .................... signed int8 memcmp(void * s1,char *s2,size_t n)
4058 .................... {
4059 .................... char *su1, *su2;
4060 .................... for(su1=s1, su2=s2; 0<n; ++su1, ++su2, --n)
4061 .................... {
4062 .................... if(*su1!=*su2)
4063 .................... return ((*su1<*su2)?-1:+1);
4064 .................... }
4065 .................... return 0;
4066 .................... }
4067 ....................
4068 .................... /* standard template: int strcmp(const char *s1, const char *s2).
4069 .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
4070 ....................
4071 .................... signed int8 strcmp(char *s1, char *s2)
4072 .................... {
4073 .................... for (; *s1 == *s2; s1++, s2++)
4074 .................... if (*s1 == '\0')
4075 .................... return(0);
4076 .................... return((*s1 < *s2) ? -1: 1);
4077 .................... }
4078 .................... /* standard template: int strcoll(const char *s1, const char *s2).
4079 .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
4080 ....................
4081 .................... signed int8 strcoll(char *s1, char *s2)
4082 .................... {
4083 .................... for (; *s1 == *s2; s1++, s2++)
4084 .................... if (*s1 == '\0')
4085 .................... return(0);
4086 .................... return((*s1 < *s2) ? -1: 1);
4087 .................... }
4088 ....................
4089 .................... /* standard template:
4090 .................... int strncmp(const char *s1, const char *s2, size_t n).
4091 .................... Compares max of n characters (not following 0) from s1 to s2;
4092 .................... returns same as strcmp */
4093 ....................
4094 .................... signed int8 strncmp(char *s1, char *s2, size_t n)
4095 .................... {
4096 .................... for (; n > 0; s1++, s2++, n--)
4097 .................... if (*s1 != *s2)
4098 .................... return((*s1 <*s2) ? -1: 1);
4099 .................... else if (*s1 == '\0')
4100 .................... return(0);
4101 .................... return(0);
4102 .................... }
4103 .................... /* standard template:
4104 .................... int strxfrm(const char *s1, const char *s2, size_t n).
4105 .................... transforms maximum of n characters from s2 and places them into s1*/
4106 .................... size_t strxfrm(char *s1, char *s2, size_t n)
4107 .................... {
4108 .................... char *s;
4109 .................... unsigned int8 n1;
4110 .................... n1=n;
4111 .................... for (s = s1; n > 0 && *s2 != '\0'; n--)
4112 .................... *s++ = *s2++;
4113 .................... for (; n > 0; n--)
4114 .................... *s++ = '\0';
4115 ....................
4116 .................... return(n1);
4117 .................... }
4118 ....................
4119 ....................
4120 ....................
4121 ....................
4122 ....................
4123 .................... /***********************************************************/
4124 .................... /*Search functions*/
4125 .................... /* standard template: void *memchr(const char *s, int c).
4126 .................... Finds first occurrence of c in n characters of s */
4127 ....................
4128 .................... char *memchr(void *s,unsigned int8 c,size_t n)
4129 .................... {
4130 .................... char uc;
4131 .................... char *su;
4132 .................... uc=c;
4133 .................... for(su=s;0<n;++su,--n)
4134 .................... if(*su==uc)
4135 .................... return su;
4136 .................... return NULL;
4137 .................... }
4138 ....................
4139 .................... /* standard template: char *strchr(const char *s, int c).
4140 .................... Finds first occurrence of c in s */
4141 ....................
4142 .................... char *strchr(char *s, unsigned int8 c)
4143 .................... {
4144 .................... for (; *s != c; s++)
4145 .................... if (*s == '\0')
4146 .................... return(0);
4147 .................... return(s);
4148 .................... }
4149 .................... /* standard template:
4150 .................... size_t strcspn(const char *s1, const char *s2).
4151 .................... Computes length of max initial segment of s1 that
4152 .................... consists entirely of characters NOT from s2*/
4153 ....................
4154 .................... unsigned int8 strcspn(char *s1, char *s2)
4155 .................... {
4156 .................... char *sc1, *sc2;
4157 ....................
4158 .................... for (sc1 = s1; *sc1 != 0; sc1++)
4159 .................... for (sc2 = s2; *sc2 != 0; sc2++)
4160 .................... if (*sc1 == *sc2)
4161 .................... return(sc1 - s1);
4162 .................... return(sc1 - s1);
4163 .................... }
4164 .................... /* standard template:
4165 .................... char *strpbrk(const char *s1, const char *s2).
4166 .................... Locates first occurence of any character from s2 in s1;
4167 .................... returns s1 if s2 is empty string */
4168 ....................
4169 .................... char *strpbrk(char *s1, char *s2)
4170 .................... {
4171 .................... char *sc1, *sc2;
4172 ....................
4173 .................... for (sc1 = s1; *sc1 != 0; sc1++)
4174 .................... for (sc2 = s2; *sc2 != 0; sc2++)
4175 .................... if (*sc1 == *sc2)
4176 .................... return(sc1);
4177 .................... return(0);
4178 .................... }
4179 ....................
4180 ....................
4181 .................... /* standard template: char *strrchr(const char *s, int c).
4182 .................... Finds last occurrence of c in s */
4183 ....................
4184 .................... char *strrchr(char *s, unsigned int8 c)
4185 .................... {
4186 .................... char *p;
4187 ....................
4188 .................... for (p = 0; ; s++)
4189 .................... {
4190 .................... if (*s == c)
4191 .................... p = s;
4192 .................... if (*s == '\0')
4193 .................... return(p);
4194 .................... }
4195 .................... }
4196 .................... /* computes length of max initial segment of s1 consisting
4197 .................... entirely of characters from s2 */
4198 ....................
4199 .................... unsigned int8 strspn(char *s1, char *s2)
4200 .................... {
4201 .................... char *sc1, *sc2;
4202 ....................
4203 .................... for (sc1 = s1; *sc1 != 0; sc1++)
4204 .................... for (sc2 = s2; ; sc2++)
4205 .................... if (*sc2 == '\0')
4206 .................... return(sc1 - s1);
4207 .................... else if (*sc1 == *sc2)
4208 .................... break;
4209 .................... return(sc1 - s1);
4210 .................... }
4211 .................... /* standard template:
4212 .................... char *strstr(const char *s1, const char *s2);
4213 .................... Locates first occurence of character sequence s2 in s1;
4214 .................... returns 0 if s2 is empty string
4215 ....................
4216 .................... Uncomment #define FASTER_BUT_MORE_ROM at the top of the
4217 .................... file to use the faster algorithm */
4218 .................... char *strstr(char *s1, char *s2)
4219 .................... {
4220 .................... char *s, *t;
4221 ....................
4222 .................... #ifdef FASTER_BUT_MORE_ROM
4223 .................... if (*s2 == '\0')
4224 .................... return(s1);
4225 .................... #endif
4226 ....................
4227 .................... while (*s1)
4228 .................... {
4229 .................... for(s = s1, t = s2; *t && (*s == *t); ++s, ++t);
4230 ....................
4231 .................... if (*t == '\0')
4232 .................... return s1;
4233 .................... ++s1;
4234 .................... #ifdef FASTER_BUT_MORE_ROM
4235 .................... while(*s1 != '\0' && *s1 != *s2)
4236 .................... ++s1;
4237 .................... #endif
4238 .................... }
4239 .................... return 0;
4240 .................... }
4241 ....................
4242 .................... /* standard template: char *strtok(char *s1, const char *s2).
4243 ....................
4244 .................... Finds next token in s1 delimited by a character from separator
4245 .................... string s2 (which can be different from call to call). First call
4246 .................... starts at beginning of s1 searching for first character NOT
4247 .................... contained in s2; returns 0 if none is found.
4248 .................... If one is found, it is the start of first token (return value).
4249 .................... Function then searches from there for a character contained in s2.
4250 .................... If none is found, current token extends to end of s1, and subsequent
4251 .................... searches for a token will return 0. If one is found, it is
4252 .................... overwritten by '\0', which terminates current token. Function saves
4253 .................... pointer to following character from which next search will start.
4254 .................... Each subsequent call, with 0 as first argument, starts searching
4255 .................... from saved pointer */
4256 ....................
4257 .................... char *strtok(char *s1, char *s2)
4258 .................... {
4259 .................... char *beg, *end;
4260 .................... static char *save;
4261 ....................
4262 .................... beg = (s1)? s1: save;
4263 .................... beg += strspn(beg, s2);
4264 .................... if (*beg == '\0')
4265 .................... {
4266 .................... *save = ' ';
4267 .................... return(0);
4268 .................... }
4269 .................... end = strpbrk(beg, s2);
4270 .................... if (*end != '\0')
4271 .................... {
4272 .................... *end = '\0';
4273 .................... end++;
4274 .................... }
4275 .................... save = end;
4276 .................... return(beg);
4277 .................... }
4278 ....................
4279 .................... /*****************************************************************/
4280 .................... /*Miscellaneous functions*/
4281 .................... /* standard template
4282 .................... maps error number in errnum to an error message string
4283 .................... Returns: Pointer to string
4284 .................... */
4285 .................... #ifdef _ERRNO
4286 .................... char * strerror(unsigned int8 errnum)
4287 .................... {
4288 .................... char s[15];
4289 .................... switch( errnum)
4290 .................... {
4291 .................... case 0:
4292 .................... strcpy(s,"no errors");
4293 .................... return s;
4294 .................... case EDOM :
4295 .................... strcpy(s,"domain error");
4296 .................... return s;
4297 .................... case ERANGE:
4298 .................... strcpy(s,"range error");
4299 .................... return s;
4300 .................... }
4301 .................... }
4302 .................... #ENDIF
4303 .................... /* standard template: size_t strlen(const char *s).
4304 .................... Computes length of s1 (preceding terminating 0) */
4305 ....................
4306 .................... unsigned int8 strlen(char *s)
4307 .................... {
4308 .................... char *sc;
4309 ....................
4310 .................... for (sc = s; *sc != 0; sc++);
4311 .................... return(sc - s);
4312 .................... }
4313 ....................
4314 .................... /* standard template: size_t stricmp(const char *s1, const char *s2).
4315 .................... Compares s1 to s2 ignoring case (upper vs. lower) */
4316 ....................
4317 .................... signed int8 stricmp(char *s1, char *s2)
4318 .................... {
4319 .................... for(; *s1==*s2||(isalpha(*s1)&&isalpha(*s2)&&(*s1==*s2+32||*s2==*s1+32));
4320 .................... s1++, s2++)
4321 .................... if (*s1 == '\0')
4322 .................... return(0);
4323 .................... return((*s1 < *s2) ? -1: 1);
4324 .................... }
4325 ....................
4326 ....................
4327 .................... /* standard template: char *strlwr(char *s).
4328 .................... Replaces uppercase letters by lowercase;
4329 .................... returns pointer to new string s */
4330 ....................
4331 .................... char *strlwr(char *s)
4332 .................... {
4333 .................... char *p;
4334 ....................
4335 .................... for (p = s; *p != '\0'; p++)
4336 .................... if (*p >= 'A' && *p <='Z')
4337 .................... *p += 'a' - 'A';
4338 .................... return(s);
4339 .................... }
4340 ....................
4341 ....................
4342 .................... /************************************************************/
4343 ....................
4344 ....................
4345 .................... #endif
4346 ....................
4347 ....................
4348 .................... div_t div(signed int numer, signed int denom)
4349 .................... {
4350 .................... div_t val;
4351 .................... val.quot = numer / denom;
4352 .................... val.rem = numer - (denom * val.quot);
4353 .................... return (val);
4354 .................... }
4355 ....................
4356 .................... ldiv_t ldiv(signed long numer, signed long denom)
4357 .................... {
4358 .................... ldiv_t val;
4359 ....................
4360 .................... val.quot = numer / denom;
4361 .................... val.rem = numer - (denom * val.quot);
4362 .................... return (val);
4363 .................... }
4364 ....................
4365 .................... #if defined(__PCD__)
4366 .................... float32 atoe(char * s)
4367 .................... {
4368 .................... float32 pow10 = 1.0;
4369 .................... float32 result = 0.0;
4370 .................... unsigned int8 sign = 0;
4371 .................... unsigned int8 expsign = 0;
4372 .................... char c;
4373 .................... unsigned int8 ptr = 0;
4374 .................... unsigned int8 i;
4375 .................... float32 exp = 1.0;
4376 .................... unsigned int8 expcnt = 0;
4377 ....................
4378 .................... c = s[ptr++];
4379 ....................
4380 .................... if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.' || c=='E' || c=='e') {
4381 .................... if(c == '-') {
4382 .................... sign = 1;
4383 .................... c = s[ptr++];
4384 .................... }
4385 .................... if(c == '+')
4386 .................... c = s[ptr++];
4387 ....................
4388 .................... while((c >= '0' && c <= '9')) {
4389 .................... result = 10*result + c - '0';
4390 .................... c = s[ptr++];
4391 .................... }
4392 ....................
4393 .................... if (c == '.') {
4394 .................... c = s[ptr++];
4395 .................... while((c >= '0' && c <= '9')) {
4396 .................... pow10 = pow10*10;
4397 .................... result += (c - '0')/pow10;
4398 .................... c = s[ptr++];
4399 .................... }
4400 .................... }
4401 ....................
4402 .................... // Handling the exponent
4403 .................... if (c=='e' || c=='E') {
4404 .................... c = s[ptr++];
4405 ....................
4406 .................... if(c == '-') {
4407 .................... expsign = 1;
4408 .................... c = s[ptr++];
4409 .................... }
4410 .................... if(c == '+')
4411 .................... c = s[ptr++];
4412 ....................
4413 .................... while((c >= '0' && c <= '9')) {
4414 .................... expcnt = 10*expcnt + c - '0';
4415 .................... c = s[ptr++];
4416 .................... }
4417 ....................
4418 .................... for(i=0;i<expcnt;i++)
4419 .................... exp*=10;
4420 ....................
4421 .................... if(expsign==1)
4422 .................... result/=exp;
4423 .................... else
4424 .................... result*=exp;
4425 .................... }
4426 .................... }
4427 ....................
4428 .................... if (sign == 1)
4429 .................... result = -1*result;
4430 .................... return(result);
4431 .................... }
4432 .................... #endif
4433 ....................
4434 .................... #if !defined(__PCD__)
4435 .................... float atoe(char * s)
4436 .................... {
4437 .................... float pow10 = 1.0;
4438 .................... float result = 0.0;
4439 .................... unsigned int8 sign = 0;
4440 .................... unsigned int8 expsign = 0;
4441 .................... char c;
4442 .................... unsigned int8 ptr = 0;
4443 .................... unsigned int8 i;
4444 .................... float exp = 1.0;
4445 .................... unsigned int8 expcnt = 0;
4446 ....................
4447 .................... c = s[ptr++];
4448 ....................
4449 .................... if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.' || c=='E' || c=='e') {
4450 .................... if(c == '-') {
4451 .................... sign = 1;
4452 .................... c = s[ptr++];
4453 .................... }
4454 .................... if(c == '+')
4455 .................... c = s[ptr++];
4456 ....................
4457 .................... while((c >= '0' && c <= '9')) {
4458 .................... result = 10*result + c - '0';
4459 .................... c = s[ptr++];
4460 .................... }
4461 ....................
4462 .................... if (c == '.') {
4463 .................... c = s[ptr++];
4464 .................... while((c >= '0' && c <= '9')) {
4465 .................... pow10 = pow10*10;
4466 .................... result += (c - '0')/pow10;
4467 .................... c = s[ptr++];
4468 .................... }
4469 .................... }
4470 ....................
4471 .................... // Handling the exponent
4472 .................... if (c=='e' || c=='E') {
4473 .................... c = s[ptr++];
4474 ....................
4475 .................... if(c == '-') {
4476 .................... expsign = 1;
4477 .................... c = s[ptr++];
4478 .................... }
4479 .................... if(c == '+')
4480 .................... c = s[ptr++];
4481 ....................
4482 .................... while((c >= '0' && c <= '9')) {
4483 .................... expcnt = 10*expcnt + c - '0';
4484 .................... c = s[ptr++];
4485 .................... }
4486 ....................
4487 .................... for(i=0;i<expcnt;i++)
4488 .................... exp*=10;
4489 ....................
4490 .................... if(expsign==1)
4491 .................... result/=exp;
4492 .................... else
4493 .................... result*=exp;
4494 .................... }
4495 .................... }
4496 ....................
4497 .................... if (sign == 1)
4498 .................... result = -1*result;
4499 .................... return(result);
4500 .................... }
4501 .................... #endif
4502 ....................
4503 .................... signed int atoi(char *s)
4504 .................... {
4505 .................... signed int result;
4506 .................... unsigned int sign, base, index;
4507 .................... char c;
4508 ....................
4509 .................... index = 0;
4510 .................... sign = 0;
4511 .................... base = 10;
4512 .................... result = 0;
4513 ....................
4514 .................... if (!s)
4515 .................... return 0;
4516 .................... // Omit all preceeding alpha characters
4517 .................... c = s[index++];
4518 ....................
4519 .................... // increase index if either positive or negative sign is detected
4520 .................... if (c == '-')
4521 .................... {
4522 .................... sign = 1; // Set the sign to negative
4523 .................... c = s[index++];
4524 .................... }
4525 .................... else if (c == '+')
4526 .................... {
4527 .................... c = s[index++];
4528 .................... }
4529 ....................
4530 .................... if (c >= '0' && c <= '9')
4531 .................... {
4532 ....................
4533 .................... // Check for hexa number
4534 .................... if (c == '0' && (s[index] == 'x' || s[index] == 'X'))
4535 .................... {
4536 .................... base = 16;
4537 .................... index++;
4538 .................... c = s[index++];
4539 .................... }
4540 ....................
4541 .................... // The number is a decimal number
4542 .................... if (base == 10)
4543 .................... {
4544 .................... while (c >= '0' && c <= '9')
4545 .................... {
4546 .................... result = 10*result + (c - '0');
4547 .................... c = s[index++];
4548 .................... }
4549 .................... }
4550 .................... else if (base == 16) // The number is a hexa number
4551 .................... {
4552 .................... c = toupper(c);
4553 .................... while ( (c >= '0' && c <= '9') || (c >= 'A' && c<='F'))
4554 .................... {
4555 .................... if (c >= '0' && c <= '9')
4556 .................... result = (result << 4) + (c - '0');
4557 .................... else
4558 .................... result = (result << 4) + (c - 'A' + 10);
4559 ....................
4560 .................... c = s[index++];
4561 .................... c = toupper(c);
4562 .................... }
4563 .................... }
4564 .................... }
4565 ....................
4566 .................... if (sign == 1 && base == 10)
4567 .................... result = -result;
4568 ....................
4569 .................... return(result);
4570 .................... }
4571 ....................
4572 .................... signed long atol(char *s)
4573 .................... {
4574 .................... signed long result;
4575 .................... unsigned int sign, base, index;
4576 .................... char c;
4577 ....................
4578 .................... index = 0;
4579 .................... sign = 0;
4580 .................... base = 10;
4581 .................... result = 0;
4582 ....................
4583 .................... if (!s)
4584 .................... return 0;
4585 .................... c = s[index++];
4586 ....................
4587 .................... // increase index if either positive or negative sign is detected
4588 .................... if (c == '-')
4589 .................... {
4590 .................... sign = 1; // Set the sign to negative
4591 .................... c = s[index++];
4592 .................... }
4593 .................... else if (c == '+')
4594 .................... {
4595 .................... c = s[index++];
4596 .................... }
4597 ....................
4598 .................... if (c >= '0' && c <= '9')
4599 .................... {
4600 .................... if (c == '0' && (s[index] == 'x' || s[index] == 'X'))
4601 .................... {
4602 .................... base = 16;
4603 .................... index++;
4604 .................... c = s[index++];
4605 .................... }
4606 ....................
4607 .................... // The number is a decimal number
4608 .................... if (base == 10)
4609 .................... {
4610 .................... while (c >= '0' && c <= '9')
4611 .................... {
4612 .................... result = 10*result + (c - '0');
4613 .................... c = s[index++];
4614 .................... }
4615 .................... }
4616 .................... else if (base == 16) // The number is a hexa number
4617 .................... {
4618 .................... c = toupper(c);
4619 .................... while ( (c >= '0' && c <= '9') || (c >= 'A' && c <='F'))
4620 .................... {
4621 .................... if (c >= '0' && c <= '9')
4622 .................... result = (result << 4) + (c - '0');
4623 .................... else
4624 .................... result = (result << 4) + (c - 'A' + 10);
4625 ....................
4626 .................... c = s[index++];c = toupper(c);
4627 .................... }
4628 .................... }
4629 .................... }
4630 ....................
4631 .................... if (base == 10 && sign == 1)
4632 .................... result = -result;
4633 ....................
4634 .................... return(result);
4635 .................... }
4636 ....................
4637 .................... /* A fast routine to multiply by 10
4638 .................... */
4639 .................... signed int32 mult_with10(int32 num)
4640 .................... {
4641 .................... return ( (num << 1) + (num << 3) );
4642 .................... }
4643 ....................
4644 .................... #if sizeof(long)==2
4645 .................... signed int32 atoi32(char *s)
4646 .................... {
4647 .................... signed int32 result;
4648 .................... int8 sign, base, index;
4649 .................... char c;
4650 ....................
4651 .................... index = 0;
4652 .................... sign = 0;
4653 .................... base = 10;
4654 .................... result = 0;
4655 ....................
4656 .................... if (!s)
4657 .................... return 0;
4658 .................... c = s[index++];
4659 ....................
4660 .................... // increase index if either positive or negative sign is detected
4661 .................... if (c == '-')
4662 .................... {
4663 .................... sign = 1; // Set the sign to negative
4664 .................... c = s[index++];
4665 .................... }
4666 .................... else if (c == '+')
4667 .................... {
4668 .................... c = s[index++];
4669 .................... }
4670 ....................
4671 .................... if (c >= '0' && c <= '9')
4672 .................... {
4673 .................... if (c == '0' && (s[index] == 'x' || s[index] == 'X'))
4674 .................... {
4675 .................... base = 16;
4676 .................... index++;
4677 .................... c = s[index++];
4678 .................... }
4679 ....................
4680 .................... // The number is a decimal number
4681 .................... if (base == 10)
4682 .................... {
4683 .................... while (c >= '0' && c <= '9') {
4684 .................... result = (result << 1) + (result << 3); // result *= 10;
4685 .................... result += (c - '0');
4686 .................... c = s[index++];
4687 .................... }
4688 .................... }
4689 .................... else if (base == 16) // The number is a hexa number
4690 .................... {
4691 .................... c = toupper(c);
4692 .................... while ((c >= '0' && c <= '9') || (c >= 'A' && c <='F'))
4693 .................... {
4694 .................... if (c >= '0' && c <= '9')
4695 .................... result = (result << 4) + (c - '0');
4696 .................... else
4697 .................... result = (result << 4) + (c - 'A' + 10);
4698 ....................
4699 .................... c = s[index++];c = toupper(c);
4700 .................... }
4701 .................... }
4702 .................... }
4703 ....................
4704 .................... if (base == 10 && sign == 1)
4705 .................... result = -result;
4706 ....................
4707 .................... return(result);
4708 .................... }
4709 .................... #endif
4710 ....................
4711 .................... #if defined(__PCD__)
4712 ....................
4713 .................... signed int48 atoi48(char *s)
4714 .................... {
4715 .................... signed int48 result;
4716 .................... int8 sign, base, index;
4717 .................... char c;
4718 ....................
4719 .................... index = 0;
4720 .................... sign = 0;
4721 .................... base = 10;
4722 .................... result = 0;
4723 ....................
4724 .................... if (!s)
4725 .................... return 0;
4726 .................... c = s[index++];
4727 ....................
4728 .................... // increase index if either positive or negative sign is detected
4729 .................... if (c == '-')
4730 .................... {
4731 .................... sign = 1; // Set the sign to negative
4732 .................... c = s[index++];
4733 .................... }
4734 .................... else if (c == '+')
4735 .................... {
4736 .................... c = s[index++];
4737 .................... }
4738 ....................
4739 .................... if (c >= '0' && c <= '9')
4740 .................... {
4741 .................... if (c == '0' && (s[index] == 'x' || s[index] == 'X'))
4742 .................... {
4743 .................... base = 16;
4744 .................... index++;
4745 .................... c = s[index++];
4746 .................... }
4747 ....................
4748 .................... // The number is a decimal number
4749 .................... if (base == 10)
4750 .................... {
4751 .................... while (c >= '0' && c <= '9') {
4752 .................... result = (result << 1) + (result << 3); // result *= 10;
4753 .................... result += (c - '0');
4754 .................... c = s[index++];
4755 .................... }
4756 .................... }
4757 .................... else if (base == 16) // The number is a hexa number
4758 .................... {
4759 .................... c = toupper(c);
4760 .................... while ((c >= '0' && c <= '9') || (c >= 'A' && c <='F'))
4761 .................... {
4762 .................... if (c >= '0' && c <= '9')
4763 .................... result = (result << 4) + (c - '0');
4764 .................... else
4765 .................... result = (result << 4) + (c - 'A' + 10);
4766 ....................
4767 .................... c = s[index++];c = toupper(c);
4768 .................... }
4769 .................... }
4770 .................... }
4771 ....................
4772 .................... if (base == 10 && sign == 1)
4773 .................... result = -result;
4774 ....................
4775 .................... return(result);
4776 .................... }
4777 ....................
4778 .................... signed int64 atoi64(char *s)
4779 .................... {
4780 .................... signed int64 result;
4781 .................... int8 sign, base, index;
4782 .................... char c;
4783 ....................
4784 .................... index = 0;
4785 .................... sign = 0;
4786 .................... base = 10;
4787 .................... result = 0;
4788 ....................
4789 .................... if (!s)
4790 .................... return 0;
4791 .................... c = s[index++];
4792 ....................
4793 .................... // increase index if either positive or negative sign is detected
4794 .................... if (c == '-')
4795 .................... {
4796 .................... sign = 1; // Set the sign to negative
4797 .................... c = s[index++];
4798 .................... }
4799 .................... else if (c == '+')
4800 .................... {
4801 .................... c = s[index++];
4802 .................... }
4803 ....................
4804 .................... if (c >= '0' && c <= '9')
4805 .................... {
4806 .................... if (c == '0' && (s[index] == 'x' || s[index] == 'X'))
4807 .................... {
4808 .................... base = 16;
4809 .................... index++;
4810 .................... c = s[index++];
4811 .................... }
4812 ....................
4813 .................... // The number is a decimal number
4814 .................... if (base == 10)
4815 .................... {
4816 .................... while (c >= '0' && c <= '9') {
4817 .................... result = (result << 1) + (result << 3); // result *= 10;
4818 .................... result += (c - '0');
4819 .................... c = s[index++];
4820 .................... }
4821 .................... }
4822 .................... else if (base == 16) // The number is a hexa number
4823 .................... {
4824 .................... c = toupper(c);
4825 .................... while ((c >= '0' && c <= '9') || (c >= 'A' && c <='F'))
4826 .................... {
4827 .................... if (c >= '0' && c <= '9')
4828 .................... result = (result << 4) + (c - '0');
4829 .................... else
4830 .................... result = (result << 4) + (c - 'A' + 10);
4831 ....................
4832 .................... c = s[index++];c = toupper(c);
4833 .................... }
4834 .................... }
4835 .................... }
4836 ....................
4837 .................... if (base == 10 && sign == 1)
4838 .................... result = -result;
4839 ....................
4840 .................... return(result);
4841 .................... }
4842 .................... #endif
4843 ....................
4844 .................... char * itoa(signed int32 num, unsigned int base, char * s)
4845 .................... {
4846 .................... unsigned int32 temp=1;
4847 .................... unsigned int8 i,sign=0,cnt=0;
4848 .................... char c;
4849 ....................
4850 .................... if(num<0) {
4851 .................... sign=1; // Check for negative number
4852 .................... num*=-1;
4853 .................... }
4854 ....................
4855 .................... while(temp>0) {
4856 .................... temp=(num/base);
4857 .................... s[cnt]=(num%base)+'0'; // Conversion
4858 ....................
4859 .................... if(s[cnt]>0x39)
4860 .................... s[cnt]+=0x7;
4861 ....................
4862 .................... cnt++;
4863 .................... num=temp;
4864 .................... }
4865 ....................
4866 .................... if(sign==1) {
4867 .................... s[cnt]=0x2D; // Negative sign
4868 .................... cnt++;
4869 .................... }
4870 ....................
4871 .................... for(i = 0;i<(int8)(cnt/2);i++) {
4872 ....................
4873 .................... c=s[i];
4874 .................... s[i]=s[cnt-i-1]; // Reverse the number
4875 .................... s[cnt-i-1]=c;
4876 .................... }
4877 .................... s[cnt]='\0'; // End the string
4878 .................... return s;
4879 .................... }
4880 ....................
4881 .................... float strtof(char *s, char *endptr)
4882 .................... {
4883 .................... float pow10 = 1.0;
4884 .................... float result = 0.0;
4885 .................... int1 skip = 1, sign = 0, point = 0;
4886 .................... char c;
4887 .................... unsigned int8 ptr = 0;
4888 ....................
4889 .................... if (!s)
4890 .................... return 0;
4891 ....................
4892 .................... for(c=s[ptr++]; c!=0; c=s[ptr++])
4893 .................... {
4894 .................... if (skip && !isspace(c))
4895 .................... {
4896 .................... skip = 0;
4897 .................... if (c == '+')
4898 .................... {
4899 .................... sign = 0;
4900 .................... continue;
4901 .................... }
4902 .................... else if (c == '-')
4903 .................... {
4904 .................... sign = 1;
4905 .................... continue;
4906 .................... }
4907 .................... }
4908 .................... if (!skip && (c == '.') && !point)
4909 .................... point = 1;
4910 .................... else if (!skip && isdigit(c))
4911 .................... {
4912 .................... c -= '0';
4913 .................... if (point)
4914 .................... {
4915 .................... pow10 = pow10 * 10.0;
4916 .................... result += (float)c / pow10;
4917 .................... }
4918 .................... else
4919 .................... {
4920 .................... result = 10.0 * result + (float)c;
4921 .................... }
4922 .................... }
4923 .................... else if (!skip)
4924 .................... break;
4925 .................... }
4926 ....................
4927 .................... if (sign)
4928 .................... result = -1*result;
4929 ....................
4930 .................... if(endptr)
4931 .................... {
4932 .................... if (ptr) {
4933 .................... ptr--;
4934 .................... #IF LONG_POINTERS
4935 .................... *((long *)endptr)= s+ptr;
4936 .................... #ELSE
4937 .................... *((char *)endptr)=s+ptr;
4938 .................... #ENDIF
4939 .................... }
4940 .................... else
4941 .................... {
4942 .................... #IF LONG_POINTERS
4943 .................... *((long *)endptr)= s;
4944 .................... #ELSE
4945 .................... *((char *)endptr)=s;
4946 .................... #ENDIF
4947 .................... }
4948 .................... }
4949 ....................
4950 .................... return(result);
4951 .................... }
4952 ....................
4953 .................... #if defined(__PCD__)
4954 .................... float48 strtof48(char *s, char *endptr)
4955 .................... {
4956 .................... float48 pow10 = 1.0;
4957 .................... float48 result = 0.0;
4958 .................... int1 skip = 1, sign = 0, point = 0;
4959 .................... char c;
4960 .................... unsigned int8 ptr = 0;
4961 ....................
4962 .................... if (!s)
4963 .................... return 0;
4964 ....................
4965 .................... for(c=s[ptr++]; c!=0; c=s[ptr++])
4966 .................... {
4967 .................... if (skip && !isspace(c))
4968 .................... {
4969 .................... skip = 0;
4970 .................... if (c == '+')
4971 .................... {
4972 .................... sign = 0;
4973 .................... continue;
4974 .................... }
4975 .................... else if (c == '-')
4976 .................... {
4977 .................... sign = 1;
4978 .................... continue;
4979 .................... }
4980 .................... }
4981 .................... if (!skip && (c == '.') && !point)
4982 .................... point = 1;
4983 .................... else if (!skip && isdigit(c))
4984 .................... {
4985 .................... c -= '0';
4986 .................... if (point)
4987 .................... {
4988 .................... pow10 = pow10 * 10.0;
4989 .................... result += (float48)c / pow10;
4990 .................... }
4991 .................... else
4992 .................... {
4993 .................... result = 10.0 * result + (float48)c;
4994 .................... }
4995 .................... }
4996 .................... else if (!skip)
4997 .................... break;
4998 .................... }
4999 ....................
5000 .................... if (sign)
5001 .................... result = -1*result;
5002 ....................
5003 .................... if(endptr)
5004 .................... {
5005 .................... if (ptr) {
5006 .................... ptr--;
5007 .................... #IF LONG_POINTERS
5008 .................... *((long *)endptr)= s+ptr;
5009 .................... #ELSE
5010 .................... *((char *)endptr)=s+ptr;
5011 .................... #ENDIF
5012 .................... }
5013 .................... else
5014 .................... {
5015 .................... #IF LONG_POINTERS
5016 .................... *((long *)endptr)= s;
5017 .................... #ELSE
5018 .................... *((char *)endptr)=s;
5019 .................... #ENDIF
5020 .................... }
5021 .................... }
5022 ....................
5023 .................... return(result);
5024 .................... }
5025 ....................
5026 .................... float64 strtod(char *s, char *endptr)
5027 .................... {
5028 .................... float64 pow10 = 1.0;
5029 .................... float64 result = 0.0;
5030 .................... int1 skip = 1, sign = 0, point = 0;
5031 .................... char c;
5032 .................... unsigned int8 ptr = 0;
5033 ....................
5034 .................... if (!s)
5035 .................... return 0;
5036 ....................
5037 .................... for(c=s[ptr++]; c!=0; c=s[ptr++])
5038 .................... {
5039 .................... if (skip && !isspace(c))
5040 .................... {
5041 .................... skip = 0;
5042 .................... if (c == '+')
5043 .................... {
5044 .................... sign = 0;
5045 .................... continue;
5046 .................... }
5047 .................... else if (c == '-')
5048 .................... {
5049 .................... sign = 1;
5050 .................... continue;
5051 .................... }
5052 .................... }
5053 .................... if (!skip && (c == '.') && !point)
5054 .................... point = 1;
5055 .................... else if (!skip && isdigit(c))
5056 .................... {
5057 .................... c -= '0';
5058 .................... if (point)
5059 .................... {
5060 .................... pow10 = pow10 * 10.0;
5061 .................... result += (float64)c / pow10;
5062 .................... }
5063 .................... else
5064 .................... {
5065 .................... result = 10.0 * result + (float64)c;
5066 .................... }
5067 .................... }
5068 .................... else if (!skip)
5069 .................... break;
5070 .................... }
5071 ....................
5072 .................... if (sign)
5073 .................... result = -1*result;
5074 ....................
5075 .................... if(endptr)
5076 .................... {
5077 .................... if (ptr) {
5078 .................... ptr--;
5079 .................... #IF LONG_POINTERS
5080 .................... *((long *)endptr)= s+ptr;
5081 .................... #ELSE
5082 .................... *((char *)endptr)=s+ptr;
5083 .................... #ENDIF
5084 .................... }
5085 .................... else
5086 .................... {
5087 .................... #IF LONG_POINTERS
5088 .................... *((long *)endptr)= s;
5089 .................... #ELSE
5090 .................... *((char *)endptr)=s;
5091 .................... #ENDIF
5092 .................... }
5093 .................... }
5094 ....................
5095 .................... return(result);
5096 .................... }
5097 .................... #endif
5098 ....................
5099 .................... unsigned long strtoul(char *s, char *endptr, signed int base)
5100 .................... {
5101 .................... char *sc,*s1,*sd;
5102 .................... unsigned long x=0;
5103 .................... char sign;
5104 .................... char digits[]="0123456789abcdefghijklmnopqstuvwxyz";
5105 .................... for(sc=s;isspace(*sc);++sc);
5106 .................... sign=*sc=='-'||*sc=='+'?*sc++:'+';
5107 .................... if(sign=='-' || base <0 || base ==1|| base >36) // invalid base
5108 .................... goto StrtoulGO;
5109 ....................
5110 .................... else if (base)
5111 .................... {
5112 .................... if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X'))
5113 .................... sc+=2;
5114 .................... if(base==8 && *sc =='0')
5115 .................... sc+=1;
5116 .................... if(base==2 && *sc =='0'&&sc[1]=='b')
5117 .................... sc+=2;
5118 ....................
5119 .................... }
5120 .................... else if(*sc!='0') // base is 0, find base
5121 .................... base=10;
5122 .................... else if (sc[1]=='x' || sc[1]=='X')
5123 .................... base =16,sc+=2;
5124 .................... else if(sc[1]=='b')
5125 .................... base=2,sc+=2;
5126 .................... else
5127 .................... base=8;
5128 .................... for (s1=sc;*sc=='0';++sc);// skip leading zeroes
5129 .................... sd=memchr(digits,tolower(*sc),base);
5130 .................... for(; sd!=0; )
5131 .................... {
5132 .................... x=x*base+(int16)(sd-digits);
5133 .................... ++sc;
5134 .................... sd=memchr(digits,tolower(*sc),base);
5135 .................... }
5136 .................... if(s1==sc)
5137 .................... {
5138 .................... StrtoulGO:
5139 .................... if (endptr)
5140 .................... {
5141 .................... #IF LONG_POINTERS
5142 .................... *((long *)endptr)= s;
5143 .................... #ELSE
5144 .................... *((char *)endptr)=s;
5145 .................... #ENDIF
5146 .................... }
5147 .................... return 0;
5148 .................... }
5149 .................... if (endptr)
5150 .................... {
5151 .................... #IF LONG_POINTERS
5152 .................... *((long *)endptr)= sc;
5153 .................... #ELSE
5154 .................... *((char *)endptr)=sc;
5155 .................... #ENDIF
5156 .................... }
5157 .................... return x;
5158 .................... }
5159 ....................
5160 ....................
5161 .................... signed long strtol(char *s,char *endptr, signed int base)
5162 .................... {
5163 .................... char *sc,*s1,*sd;
5164 .................... signed long x=0;
5165 .................... char sign;
5166 .................... char digits[]="0123456789abcdefghijklmnopqstuvwxyz";
5167 .................... for(sc=s;isspace(*sc);++sc);
5168 .................... sign=*sc=='-'||*sc=='+'?*sc++:'+';
5169 .................... if (base <0 || base ==1|| base >36) // invalid base
5170 .................... goto StrtolGO;
5171 .................... else if (base)
5172 .................... {
5173 .................... if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X'))
5174 .................... sc+=2;
5175 .................... if(base==8 && *sc =='0')
5176 .................... sc+=1;
5177 .................... if(base==2 && *sc =='0'&&sc[1]=='b')
5178 .................... sc+=2;
5179 ....................
5180 .................... }
5181 .................... else if(*sc!='0') // base is 0, find base
5182 .................... base=10;
5183 .................... else if (sc[1]=='x' || sc[1]=='X')
5184 .................... base =16,sc+=2;
5185 .................... else if(sc[1]=='b')
5186 .................... base=2,sc+=2;
5187 .................... else
5188 .................... base=8;
5189 .................... for (s1=sc;*sc=='0';++sc);// skip leading zeroes
5190 ....................
5191 .................... sd=memchr(digits,tolower(*sc),base);
5192 .................... for(;sd!=0;)
5193 .................... {
5194 .................... x=x*base+(int16)(sd-digits);
5195 .................... ++sc;
5196 .................... sd=memchr(digits,tolower(*sc),base);
5197 .................... }
5198 .................... if(s1==sc)
5199 .................... {
5200 .................... StrtolGO:
5201 .................... if (endptr)
5202 .................... {
5203 .................... #IF LONG_POINTERS
5204 .................... *((long *)endptr)= s;
5205 .................... #ELSE
5206 .................... *((char *)endptr)=s;
5207 .................... #ENDIF
5208 .................... }
5209 .................... return 0;
5210 .................... }
5211 .................... if(sign=='-')
5212 .................... x =-x;
5213 .................... if (endptr)
5214 .................... {
5215 .................... #IF LONG_POINTERS
5216 .................... *((long *)endptr)= sc;
5217 .................... #ELSE
5218 .................... *((char *)endptr)=sc;
5219 .................... #ENDIF
5220 .................... }
5221 .................... return x;
5222 .................... }
5223 ....................
5224 .................... signed int8 system(char *string)
5225 .................... {
5226 .................... return 0;
5227 .................... }
5228 ....................
5229 .................... int8 mblen(char *s,size_t n)
5230 .................... {
5231 .................... return strlen(s);
5232 .................... }
5233 ....................
5234 .................... int8 mbtowc(wchar_t *pwc,char *s,size_t n)
5235 .................... {
5236 .................... *pwc=*s;
5237 .................... return 1;
5238 .................... }
5239 ....................
5240 .................... int8 wctomb(char *s,wchar_t wchar)
5241 .................... {
5242 .................... *s=wchar;
5243 .................... return 1;
5244 .................... }
5245 ....................
5246 .................... size_t mbstowcs(wchar_t *pwcs,char *s,size_t n)
5247 .................... {
5248 .................... strncpy(pwcs,s,n);
5249 .................... return strlen(pwcs);
5250 .................... }
5251 ....................
5252 .................... size_t wcstombs(char *s,wchar_t *pwcs,size_t n)
5253 .................... {
5254 .................... strncpy(s,pwcs,n);
5255 .................... return strlen(s);
5256 .................... }
5257 ....................
5258 .................... //---------------------------------------------------------------------------
5259 .................... // The random number implementation
5260 .................... //---------------------------------------------------------------------------
5261 ....................
5262 .................... unsigned int32 _Randseed;
5263 ....................
5264 .................... unsigned int16 rand(void)
5265 .................... {
5266 .................... _Randseed = _Randseed * 1103515245 + 12345;
5267 .................... return ((unsigned int16)(_Randseed >> 16) % RAND_MAX);
5268 .................... }
5269 ....................
5270 .................... void srand(unsigned int32 seed)
5271 .................... {
5272 .................... _Randseed = seed;
5273 .................... }
5274 ....................
5275 .................... //---------------------------------------------------------------------------
5276 .................... // Searching and sorting utilities implementation
5277 .................... //---------------------------------------------------------------------------
5278 ....................
5279 .................... #if !defined(__PCD__)
5280 .................... typedef signed int8 (*_Cmpfun)(char * p1,char * p2);
5281 .................... #else
5282 .................... typedef signed int16 (*_Cmpfun)(char * p1,char * p2);
5283 .................... #endif
5284 ....................
5285 ....................
5286 ....................
5287 .................... void qsort(char * qdata, unsigned int qitems, unsigned int qsize, _Cmpfun cmp) {
5288 .................... unsigned int m,j,i,l;
5289 .................... int1 done;
5290 .................... unsigned int8 t[16];
5291 ....................
5292 .................... m = qitems/2;
5293 .................... while( m > 0 ) {
5294 .................... for(j=0; j<(qitems-m); ++j) {
5295 .................... i = j;
5296 .................... do
5297 .................... {
5298 .................... done=1;
5299 .................... l = i+m;
5300 .................... if( (*cmp)(qdata+i*qsize, qdata+l*qsize) > 0 ) {
5301 .................... memcpy(t, qdata+i*qsize, qsize);
5302 .................... memcpy(qdata+i*qsize, qdata+l*qsize, qsize);
5303 .................... memcpy(qdata+l*qsize, t, qsize);
5304 .................... if(m <= i)
5305 .................... i -= m;
5306 .................... done = 0;
5307 .................... }
5308 .................... } while(!done);
5309 .................... }
5310 .................... m = m/2;
5311 .................... }
5312 .................... }
5313 ....................
5314 ....................
5315 .................... char *bsearch(char *key, char *base, size_t num, size_t width,_Cmpfun cmp)
5316 .................... {
5317 .................... char *p, *q;
5318 .................... size_t n;
5319 .................... size_t pivot;
5320 .................... signed int val;
5321 ....................
5322 .................... p = base;
5323 .................... n = num;
5324 ....................
5325 .................... while (n > 0)
5326 .................... {
5327 .................... pivot = n >> 1;
5328 .................... q = p + width * pivot;
5329 ....................
5330 .................... val = (*cmp)(key, q);
5331 ....................
5332 .................... if (val < 0)
5333 .................... n = pivot;
5334 .................... else if (val == 0)
5335 .................... return ((char *)q);
5336 .................... else {
5337 .................... p = q + width;
5338 .................... n -= pivot + 1;
5339 .................... }
5340 .................... }
5341 ....................
5342 .................... return NULL; // There's no match
5343 .................... }
5344 ....................
5345 ....................
5346 .................... #endif
5347 ....................
5348 .................... #include <input.c>
5349 .................... ///////////////////////////////////////////////////////////////////////////
5350 .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
5351 .................... //// This source code may only be used by licensed users of the CCS C ////
5352 .................... //// compiler. This source code may only be distributed to other ////
5353 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
5354 .................... //// or distribution is permitted without written permission. ////
5355 .................... //// Derivative programs created using this software in object code ////
5356 .................... //// form are not restricted in any way. ////
5357 .................... ///////////////////////////////////////////////////////////////////////////
5358 ....................
5359 ....................
5360 .................... #include <ctype.h>
5361 .................... ////////////////////////////////////////////////////////////////////////////
5362 .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
5363 .................... //// This source code may only be used by licensed users of the CCS C ////
5364 .................... //// compiler. This source code may only be distributed to other ////
5365 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
5366 .................... //// or distribution is permitted without written permission. ////
5367 .................... //// Derivative programs created using this software in object code ////
5368 .................... //// form are not restricted in any way. ////
5369 .................... ////////////////////////////////////////////////////////////////////////////
5370 ....................
5371 .................... #ifndef _CTYPE
5372 .................... #define _CTYPE
5373 ....................
5374 .................... #define islower(x) isamong(x,"abcdefghijklmnopqrstuvwxyz")
5375 .................... #define isupper(x) isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZ")
5376 .................... #define isalnum(x) isamong(x,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
5377 .................... #define isalpha(x) isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
5378 .................... #define isdigit(x) isamong(x,"0123456789")
5379 .................... #define isspace(x) ((x)==' ')
5380 .................... #define isxdigit(x) isamong(x,"0123456789ABCDEFabcdef")
5381 .................... #define iscntrl(x) ((x)<' ')
5382 .................... #define isprint(x) ((x)>=' ')
5383 .................... #define isgraph(x) ((x)>' ')
5384 .................... #define ispunct(x) (((x)>' ')&&!isalnum(x))
5385 ....................
5386 .................... #endif
5387 ....................
5388 ....................
5389 ....................
5390 .................... BYTE gethex1() {
5391 .................... char digit;
5392 ....................
5393 .................... digit = getc();
5394 ....................
5395 .................... putc(digit);
5396 ....................
5397 .................... if(digit<='9')
5398 .................... return(digit-'0');
5399 .................... else
5400 .................... return((toupper(digit)-'A')+10);
5401 .................... }
5402 ....................
5403 .................... BYTE gethex() {
5404 .................... unsigned int8 lo,hi;
5405 ....................
5406 .................... hi = gethex1();
5407 .................... lo = gethex1();
5408 .................... if(lo==0xdd)
5409 .................... return(hi);
5410 .................... else
5411 .................... return( hi*16+lo );
5412 .................... }
5413 ....................
5414 .................... void get_string(char* s, unsigned int8 max) {
5415 .................... unsigned int8 len;
5416 .................... char c;
5417 ....................
5418 .................... --max;
5419 .................... len=0;
5420 .................... do {
5421 .................... c=getc();
5422 .................... if(c==8) { // Backspace
5423 .................... if(len>0) {
5424 .................... len--;
5425 .................... putc(c);
5426 .................... putc(' ');
5427 .................... putc(c);
5428 .................... }
5429 .................... } else if ((c>=' ')&&(c<='~'))
5430 .................... if(len<=max) {
5431 .................... s[len++]=c;
5432 .................... putc(c);
5433 .................... }
5434 .................... } while(c!=13);
5435 .................... s[len]=0;
5436 .................... }
5437 ....................
5438 .................... // stdlib.h is required for the ato_ conversions
5439 .................... // in the following functions
5440 .................... #ifdef _STDLIB
5441 .................... #if !defined(__PCD__)
5442 .................... signed int8 get_int() {
5443 .................... char s[5];
5444 .................... signed int8 i;
5445 ....................
5446 .................... get_string(s, 5);
5447 ....................
5448 .................... i=atoi(s);
5449 .................... return(i);
5450 .................... }
5451 .................... #endif
5452 ....................
5453 .................... #if defined(__PCD__)
5454 .................... signed int16 get_int() {
5455 .................... char s[5];
5456 .................... signed int16 i;
5457 ....................
5458 .................... get_string(s, 7);
5459 ....................
5460 .................... i=atoi(s);
5461 .................... return(i);
5462 .................... }
5463 .................... #endif
5464 ....................
5465 .................... #if !defined(__PCD__)
5466 .................... signed int16 get_long() {
5467 .................... char s[7];
5468 .................... signed int16 l;
5469 ....................
5470 .................... get_string(s, 7);
5471 .................... l=atol(s);
5472 .................... return(l);
5473 .................... }
5474 .................... #endif
5475 ....................
5476 .................... #if defined(__PCD__)
5477 .................... signed int32 get_long() {
5478 .................... char s[7];
5479 .................... signed int32 l;
5480 ....................
5481 .................... get_string(s, 10);
5482 .................... l=atoi32(s);
5483 .................... return(l);
5484 .................... }
5485 .................... #endif
5486 ....................
5487 .................... float get_float() {
5488 .................... char s[20];
5489 .................... float f;
5490 ....................
5491 .................... get_string(s, 20);
5492 .................... f = atof(s);
5493 .................... return(f);
5494 .................... }
5495 ....................
5496 .................... #endif
5497 ....................
5498 .................... #include <string.h>
5499 .................... ////////////////////////////////////////////////////////////////////////////
5500 .................... //// (C) Copyright 1996,2008 Custom Computer Services ////
5501 .................... //// This source code may only be used by licensed users of the CCS C ////
5502 .................... //// compiler. This source code may only be distributed to other ////
5503 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
5504 .................... //// or distribution is permitted without written permission. ////
5505 .................... //// Derivative programs created using this software in object code ////
5506 .................... //// form are not restricted in any way. ////
5507 .................... ////////////////////////////////////////////////////////////////////////////
5508 ....................
5509 .................... #ifndef _STRING
5510 .................... #define _STRING
5511 .................... #include <stddef.h>
5512 .................... #include <ctype.h>
5513 ....................
5514 ....................
5515 ....................
5516 .................... //////////////////////////////////////////////
5517 .................... //// Uncomment the following define to ////
5518 .................... //// allow some functions to use a ////
5519 .................... //// quicker algorithm, but use more ROM ////
5520 .................... //// ////
5521 .................... //// #define FASTER_BUT_MORE_ROM ////
5522 .................... //////////////////////////////////////////////
5523 ....................
5524 ....................
5525 ....................
5526 .................... /*Copying functions*/
5527 .................... /* standard template:
5528 .................... void *memmove(void *s1, void *s2, size_t n).
5529 .................... Copies max of n characters safely (not following ending '\0')
5530 .................... from s2 in s1; if s2 has less than n characters, appends 0 */
5531 ....................
5532 .................... char *memmove(void *s1,char *s2,size_t n)
5533 .................... {
5534 .................... char *sc1;
5535 .................... char *sc2;
5536 .................... sc1=s1;
5537 .................... sc2=s2;
5538 .................... if(sc2<sc1 && sc1 <sc2 +n)
5539 .................... for(sc1+=n,sc2+=n;0<n;--n)
5540 .................... *--sc1=*--sc2;
5541 .................... else
5542 .................... for(;0<n;--n)
5543 .................... *sc1++=*sc2++;
5544 .................... return s1;
5545 .................... }
5546 ....................
5547 .................... /* Standard template: char *strcpy(char *s1, const char *s2)
5548 .................... copies the string s2 including the null character to s1.
5549 .................... This is a compiler built in to handle the different address
5550 .................... spaces */
5551 ....................
5552 .................... #define strcopy strcpy
5553 ....................
5554 .................... /* standard template:
5555 .................... char *strncpy(char *s1, const char *s2, size_t n).
5556 .................... Copies max of n characters (not following ending '\0')
5557 .................... from s2 in s1; if s2 has less than n characters, appends 0 */
5558 ....................
5559 .................... char *strncpy(char *s1, char *s2, size_t n)
5560 .................... {
5561 .................... char *s;
5562 ....................
5563 .................... for (s = s1; n > 0 && *s2 != '\0'; n--)
5564 .................... *s++ = *s2++;
5565 .................... for (; n > 0; n--)
5566 .................... *s++ = '\0';
5567 ....................
5568 .................... return(s1);
5569 .................... }
5570 .................... /***********************************************************/
5571 ....................
5572 .................... /*concatenation functions*/
5573 .................... /* standard template: char *strcat(char *s1, const char *s2)
5574 .................... appends s2 to s1*/
5575 ....................
5576 .................... char *strcat(char *s1, char *s2)
5577 .................... {
5578 .................... char *s;
5579 ....................
5580 .................... for (s = s1; *s != '\0'; ++s);
5581 .................... while(*s2 != '\0')
5582 .................... {
5583 .................... *s = *s2;
5584 .................... ++s;
5585 .................... ++s2;
5586 .................... }
5587 ....................
5588 .................... *s = '\0';
5589 .................... return(s1);
5590 .................... }
5591 .................... /* standard template: char *strncat(char *s1, char *s2,size_t n)
5592 .................... appends not more than n characters from s2 to s1*/
5593 ....................
5594 .................... char *strncat(char *s1, char *s2, size_t n)
5595 .................... {
5596 .................... char *s;
5597 ....................
5598 .................... for (s = s1; *s != '\0'; ++s);
5599 .................... while(*s2 != '\0' && 0<n)
5600 .................... {
5601 .................... *s = *s2;
5602 .................... ++s;
5603 .................... ++s2;
5604 .................... --n;
5605 .................... }
5606 ....................
5607 .................... *s = '\0';
5608 .................... return(s1);
5609 .................... }
5610 ....................
5611 .................... /***********************************************************/
5612 ....................
5613 ....................
5614 .................... /*comparison functions*/
5615 .................... /* standard template: signed int memcmp(void *s1, void *s2).
5616 .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
5617 ....................
5618 .................... signed int8 memcmp(void * s1,char *s2,size_t n)
5619 .................... {
5620 .................... char *su1, *su2;
5621 .................... for(su1=s1, su2=s2; 0<n; ++su1, ++su2, --n)
5622 .................... {
5623 .................... if(*su1!=*su2)
5624 .................... return ((*su1<*su2)?-1:+1);
5625 .................... }
5626 .................... return 0;
5627 .................... }
5628 ....................
5629 .................... /* standard template: int strcmp(const char *s1, const char *s2).
5630 .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
5631 ....................
5632 .................... signed int8 strcmp(char *s1, char *s2)
5633 .................... {
5634 .................... for (; *s1 == *s2; s1++, s2++)
5635 .................... if (*s1 == '\0')
5636 .................... return(0);
5637 .................... return((*s1 < *s2) ? -1: 1);
5638 .................... }
5639 .................... /* standard template: int strcoll(const char *s1, const char *s2).
5640 .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
5641 ....................
5642 .................... signed int8 strcoll(char *s1, char *s2)
5643 .................... {
5644 .................... for (; *s1 == *s2; s1++, s2++)
5645 .................... if (*s1 == '\0')
5646 .................... return(0);
5647 .................... return((*s1 < *s2) ? -1: 1);
5648 .................... }
5649 ....................
5650 .................... /* standard template:
5651 .................... int strncmp(const char *s1, const char *s2, size_t n).
5652 .................... Compares max of n characters (not following 0) from s1 to s2;
5653 .................... returns same as strcmp */
5654 ....................
5655 .................... signed int8 strncmp(char *s1, char *s2, size_t n)
5656 .................... {
5657 .................... for (; n > 0; s1++, s2++, n--)
5658 .................... if (*s1 != *s2)
5659 .................... return((*s1 <*s2) ? -1: 1);
5660 .................... else if (*s1 == '\0')
5661 .................... return(0);
5662 .................... return(0);
5663 .................... }
5664 .................... /* standard template:
5665 .................... int strxfrm(const char *s1, const char *s2, size_t n).
5666 .................... transforms maximum of n characters from s2 and places them into s1*/
5667 .................... size_t strxfrm(char *s1, char *s2, size_t n)
5668 .................... {
5669 .................... char *s;
5670 .................... unsigned int8 n1;
5671 .................... n1=n;
5672 .................... for (s = s1; n > 0 && *s2 != '\0'; n--)
5673 .................... *s++ = *s2++;
5674 .................... for (; n > 0; n--)
5675 .................... *s++ = '\0';
5676 ....................
5677 .................... return(n1);
5678 .................... }
5679 ....................
5680 ....................
5681 ....................
5682 ....................
5683 ....................
5684 .................... /***********************************************************/
5685 .................... /*Search functions*/
5686 .................... /* standard template: void *memchr(const char *s, int c).
5687 .................... Finds first occurrence of c in n characters of s */
5688 ....................
5689 .................... char *memchr(void *s,unsigned int8 c,size_t n)
5690 .................... {
5691 .................... char uc;
5692 .................... char *su;
5693 .................... uc=c;
5694 .................... for(su=s;0<n;++su,--n)
5695 .................... if(*su==uc)
5696 .................... return su;
5697 .................... return NULL;
5698 .................... }
5699 ....................
5700 .................... /* standard template: char *strchr(const char *s, int c).
5701 .................... Finds first occurrence of c in s */
5702 ....................
5703 .................... char *strchr(char *s, unsigned int8 c)
5704 .................... {
5705 .................... for (; *s != c; s++)
5706 .................... if (*s == '\0')
5707 .................... return(0);
5708 .................... return(s);
5709 .................... }
5710 .................... /* standard template:
5711 .................... size_t strcspn(const char *s1, const char *s2).
5712 .................... Computes length of max initial segment of s1 that
5713 .................... consists entirely of characters NOT from s2*/
5714 ....................
5715 .................... unsigned int8 strcspn(char *s1, char *s2)
5716 .................... {
5717 .................... char *sc1, *sc2;
5718 ....................
5719 .................... for (sc1 = s1; *sc1 != 0; sc1++)
5720 .................... for (sc2 = s2; *sc2 != 0; sc2++)
5721 .................... if (*sc1 == *sc2)
5722 .................... return(sc1 - s1);
5723 .................... return(sc1 - s1);
5724 .................... }
5725 .................... /* standard template:
5726 .................... char *strpbrk(const char *s1, const char *s2).
5727 .................... Locates first occurence of any character from s2 in s1;
5728 .................... returns s1 if s2 is empty string */
5729 ....................
5730 .................... char *strpbrk(char *s1, char *s2)
5731 .................... {
5732 .................... char *sc1, *sc2;
5733 ....................
5734 .................... for (sc1 = s1; *sc1 != 0; sc1++)
5735 .................... for (sc2 = s2; *sc2 != 0; sc2++)
5736 .................... if (*sc1 == *sc2)
5737 .................... return(sc1);
5738 .................... return(0);
5739 .................... }
5740 ....................
5741 ....................
5742 .................... /* standard template: char *strrchr(const char *s, int c).
5743 .................... Finds last occurrence of c in s */
5744 ....................
5745 .................... char *strrchr(char *s, unsigned int8 c)
5746 .................... {
5747 .................... char *p;
5748 ....................
5749 .................... for (p = 0; ; s++)
5750 .................... {
5751 .................... if (*s == c)
5752 .................... p = s;
5753 .................... if (*s == '\0')
5754 .................... return(p);
5755 .................... }
5756 .................... }
5757 .................... /* computes length of max initial segment of s1 consisting
5758 .................... entirely of characters from s2 */
5759 ....................
5760 .................... unsigned int8 strspn(char *s1, char *s2)
5761 .................... {
5762 .................... char *sc1, *sc2;
5763 ....................
5764 .................... for (sc1 = s1; *sc1 != 0; sc1++)
5765 .................... for (sc2 = s2; ; sc2++)
5766 .................... if (*sc2 == '\0')
5767 .................... return(sc1 - s1);
5768 .................... else if (*sc1 == *sc2)
5769 .................... break;
5770 .................... return(sc1 - s1);
5771 .................... }
5772 .................... /* standard template:
5773 .................... char *strstr(const char *s1, const char *s2);
5774 .................... Locates first occurence of character sequence s2 in s1;
5775 .................... returns 0 if s2 is empty string
5776 ....................
5777 .................... Uncomment #define FASTER_BUT_MORE_ROM at the top of the
5778 .................... file to use the faster algorithm */
5779 .................... char *strstr(char *s1, char *s2)
5780 .................... {
5781 .................... char *s, *t;
5782 ....................
5783 .................... #ifdef FASTER_BUT_MORE_ROM
5784 .................... if (*s2 == '\0')
5785 .................... return(s1);
5786 .................... #endif
5787 ....................
5788 .................... while (*s1)
5789 .................... {
5790 .................... for(s = s1, t = s2; *t && (*s == *t); ++s, ++t);
5791 ....................
5792 .................... if (*t == '\0')
5793 .................... return s1;
5794 .................... ++s1;
5795 .................... #ifdef FASTER_BUT_MORE_ROM
5796 .................... while(*s1 != '\0' && *s1 != *s2)
5797 .................... ++s1;
5798 .................... #endif
5799 .................... }
5800 .................... return 0;
5801 .................... }
5802 ....................
5803 .................... /* standard template: char *strtok(char *s1, const char *s2).
5804 ....................
5805 .................... Finds next token in s1 delimited by a character from separator
5806 .................... string s2 (which can be different from call to call). First call
5807 .................... starts at beginning of s1 searching for first character NOT
5808 .................... contained in s2; returns 0 if none is found.
5809 .................... If one is found, it is the start of first token (return value).
5810 .................... Function then searches from there for a character contained in s2.
5811 .................... If none is found, current token extends to end of s1, and subsequent
5812 .................... searches for a token will return 0. If one is found, it is
5813 .................... overwritten by '\0', which terminates current token. Function saves
5814 .................... pointer to following character from which next search will start.
5815 .................... Each subsequent call, with 0 as first argument, starts searching
5816 .................... from saved pointer */
5817 ....................
5818 .................... char *strtok(char *s1, char *s2)
5819 .................... {
5820 .................... char *beg, *end;
5821 .................... static char *save;
5822 ....................
5823 .................... beg = (s1)? s1: save;
5824 .................... beg += strspn(beg, s2);
5825 .................... if (*beg == '\0')
5826 .................... {
5827 .................... *save = ' ';
5828 .................... return(0);
5829 .................... }
5830 .................... end = strpbrk(beg, s2);
5831 .................... if (*end != '\0')
5832 .................... {
5833 .................... *end = '\0';
5834 .................... end++;
5835 .................... }
5836 .................... save = end;
5837 .................... return(beg);
5838 .................... }
5839 ....................
5840 .................... /*****************************************************************/
5841 .................... /*Miscellaneous functions*/
5842 .................... /* standard template
5843 .................... maps error number in errnum to an error message string
5844 .................... Returns: Pointer to string
5845 .................... */
5846 .................... #ifdef _ERRNO
5847 .................... char * strerror(unsigned int8 errnum)
5848 .................... {
5849 .................... char s[15];
5850 .................... switch( errnum)
5851 .................... {
5852 .................... case 0:
5853 .................... strcpy(s,"no errors");
5854 .................... return s;
5855 .................... case EDOM :
5856 .................... strcpy(s,"domain error");
5857 .................... return s;
5858 .................... case ERANGE:
5859 .................... strcpy(s,"range error");
5860 .................... return s;
5861 .................... }
5862 .................... }
5863 .................... #ENDIF
5864 .................... /* standard template: size_t strlen(const char *s).
5865 .................... Computes length of s1 (preceding terminating 0) */
5866 ....................
5867 .................... unsigned int8 strlen(char *s)
5868 .................... {
5869 .................... char *sc;
5870 ....................
5871 .................... for (sc = s; *sc != 0; sc++);
5872 .................... return(sc - s);
5873 .................... }
5874 ....................
5875 .................... /* standard template: size_t stricmp(const char *s1, const char *s2).
5876 .................... Compares s1 to s2 ignoring case (upper vs. lower) */
5877 ....................
5878 .................... signed int8 stricmp(char *s1, char *s2)
5879 .................... {
5880 .................... for(; *s1==*s2||(isalpha(*s1)&&isalpha(*s2)&&(*s1==*s2+32||*s2==*s1+32));
5881 .................... s1++, s2++)
5882 .................... if (*s1 == '\0')
5883 .................... return(0);
5884 .................... return((*s1 < *s2) ? -1: 1);
5885 .................... }
5886 ....................
5887 ....................
5888 .................... /* standard template: char *strlwr(char *s).
5889 .................... Replaces uppercase letters by lowercase;
5890 .................... returns pointer to new string s */
5891 ....................
5892 .................... char *strlwr(char *s)
5893 .................... {
5894 .................... char *p;
5895 ....................
5896 .................... for (p = s; *p != '\0'; p++)
5897 .................... if (*p >= 'A' && *p <='Z')
5898 .................... *p += 'a' - 'A';
5899 .................... return(s);
5900 .................... }
5901 ....................
5902 ....................
5903 .................... /************************************************************/
5904 ....................
5905 ....................
5906 .................... #endif
5907 ....................
5908 ....................
5909 .................... //Akcelerometr
5910 .................... #define AK_W 0x38 //adresa akcelerometru zápis
5911 .................... #define AK_R 0x39 //adresa akcelerometru ètení
5912 .................... #define AK_XH 0x01 //osa X LSB
5913 .................... #define AK_XL 0x02 //osa X MSB
5914 .................... #define AK_YH 0x03 //osa Y LSB
5915 .................... #define AK_YL 0x04 //osa Y MSB
5916 .................... #define AK_ZH 0x05 //osa Z LSB
5917 .................... #define AK_ZL 0x06 //osa Z MSB
5918 ....................
5919 .................... //Magnetometr
5920 .................... #define MAG_W 0x3C //adresa akcelerometru zápis
5921 .................... #define MAG_R 0x3D //adresa akcelerometru ètení
5922 .................... #define MAG_XH 0x03 //osa X LSB
5923 .................... #define MAG_XL 0x04 //osa X MSB
5924 .................... #define MAG_ZH 0x05 //osa Y LSB
5925 .................... #define MAG_ZL 0x06 //osa Y MSB
5926 .................... #define MAG_YH 0x07 //osa Z LSB
5927 .................... #define MAG_YL 0x08 //osa Z MSB
5928 ....................
5929 ....................
5930 ....................
5931 ....................
5932 ....................
5933 .................... //pøipojení motorù
5934 .................... //AIN1 - pro vysku slunce
5935 .................... #define AIN1 PIN_D0
5936 .................... #define AIN2 PIN_D1
5937 .................... //motor A -cerveny vodic na AOUT1
5938 .................... //motor A -modry vodic na Aout2
5939 ....................
5940 .................... //AIN2 - pro azimut
5941 .................... #define BIN1 PIN_D2
5942 .................... #define BIN2 PIN_D3
5943 .................... //motor B - èerveny vodic na BOUT2
5944 .................... //motor B - modrý vodic na BOUT1
5945 ....................
5946 .................... signed int16 X, Y, Z,AX, AY, AZ; //promenne pro magnetometr a akcelerometr
5947 ....................
5948 .................... unsigned int16 azimutZAD, elevaceZAD;
5949 ....................
5950 .................... void setAK (void) //nastaveni akcelerometru
5951 .................... {
5952 .................... i2c_start();
5953 *
5954 0122: BSF 20.4
5955 0123: MOVF 20,W
5956 0124: BSF 03.5
5957 0125: MOVWF 07
5958 0126: NOP
5959 0127: BCF 03.5
5960 0128: BSF 20.3
5961 0129: MOVF 20,W
5962 012A: BSF 03.5
5963 012B: MOVWF 07
5964 012C: NOP
5965 012D: BCF 03.5
5966 012E: BCF 07.4
5967 012F: BCF 20.4
5968 0130: MOVF 20,W
5969 0131: BSF 03.5
5970 0132: MOVWF 07
5971 0133: NOP
5972 0134: BCF 03.5
5973 0135: BCF 07.3
5974 0136: BCF 20.3
5975 0137: MOVF 20,W
5976 0138: BSF 03.5
5977 0139: MOVWF 07
5978 .................... I2C_Write(AK_W);
5979 013A: MOVLW 38
5980 013B: BCF 03.5
5981 013C: MOVWF 5D
5982 013D: CALL 0D8
5983 .................... I2C_write(0x2A);
5984 013E: MOVLW 2A
5985 013F: MOVWF 5D
5986 0140: CALL 0D8
5987 .................... I2C_write(0x01); //nastaví aktivní stav
5988 0141: MOVLW 01
5989 0142: MOVWF 5D
5990 0143: CALL 0D8
5991 ....................
5992 .................... i2c_stop();
5993 0144: BCF 20.4
5994 0145: MOVF 20,W
5995 0146: BSF 03.5
5996 0147: MOVWF 07
5997 0148: NOP
5998 0149: BCF 03.5
5999 014A: BSF 20.3
6000 014B: MOVF 20,W
6001 014C: BSF 03.5
6002 014D: MOVWF 07
6003 014E: BCF 03.5
6004 014F: BTFSS 07.3
6005 0150: GOTO 14F
6006 0151: NOP
6007 0152: GOTO 153
6008 0153: NOP
6009 0154: BSF 20.4
6010 0155: MOVF 20,W
6011 0156: BSF 03.5
6012 0157: MOVWF 07
6013 0158: NOP
6014 .................... }
6015 0159: BCF 03.5
6016 015A: BCF 0A.3
6017 015B: BSF 0A.4
6018 015C: GOTO 122 (RETURN)
6019 ....................
6020 .................... void setmag (void)
6021 .................... {
6022 .................... i2c_start();
6023 *
6024 0171: BSF 20.4
6025 0172: MOVF 20,W
6026 0173: BSF 03.5
6027 0174: MOVWF 07
6028 0175: NOP
6029 0176: BCF 03.5
6030 0177: BSF 20.3
6031 0178: MOVF 20,W
6032 0179: BSF 03.5
6033 017A: MOVWF 07
6034 017B: NOP
6035 017C: BCF 03.5
6036 017D: BCF 07.4
6037 017E: BCF 20.4
6038 017F: MOVF 20,W
6039 0180: BSF 03.5
6040 0181: MOVWF 07
6041 0182: NOP
6042 0183: BCF 03.5
6043 0184: BCF 07.3
6044 0185: BCF 20.3
6045 0186: MOVF 20,W
6046 0187: BSF 03.5
6047 0188: MOVWF 07
6048 .................... I2C_Write(MAG_W); // W
6049 0189: MOVLW 3C
6050 018A: BCF 03.5
6051 018B: MOVWF 5D
6052 018C: CALL 0D8
6053 .................... I2C_Write(0x00);
6054 018D: CLRF 5D
6055 018E: CALL 0D8
6056 .................... I2C_Write(0x78);
6057 018F: MOVLW 78
6058 0190: MOVWF 5D
6059 0191: CALL 0D8
6060 .................... i2c_stop();
6061 0192: BCF 20.4
6062 0193: MOVF 20,W
6063 0194: BSF 03.5
6064 0195: MOVWF 07
6065 0196: NOP
6066 0197: BCF 03.5
6067 0198: BSF 20.3
6068 0199: MOVF 20,W
6069 019A: BSF 03.5
6070 019B: MOVWF 07
6071 019C: BCF 03.5
6072 019D: BTFSS 07.3
6073 019E: GOTO 19D
6074 019F: NOP
6075 01A0: GOTO 1A1
6076 01A1: NOP
6077 01A2: BSF 20.4
6078 01A3: MOVF 20,W
6079 01A4: BSF 03.5
6080 01A5: MOVWF 07
6081 01A6: NOP
6082 .................... Delay_ms(6);
6083 01A7: MOVLW 06
6084 01A8: BCF 03.5
6085 01A9: MOVWF 4F
6086 01AA: CALL 15D
6087 ....................
6088 .................... i2c_start();
6089 01AB: BSF 20.4
6090 01AC: MOVF 20,W
6091 01AD: BSF 03.5
6092 01AE: MOVWF 07
6093 01AF: NOP
6094 01B0: BCF 03.5
6095 01B1: BSF 20.3
6096 01B2: MOVF 20,W
6097 01B3: BSF 03.5
6098 01B4: MOVWF 07
6099 01B5: NOP
6100 01B6: BCF 03.5
6101 01B7: BCF 07.4
6102 01B8: BCF 20.4
6103 01B9: MOVF 20,W
6104 01BA: BSF 03.5
6105 01BB: MOVWF 07
6106 01BC: NOP
6107 01BD: BCF 03.5
6108 01BE: BCF 07.3
6109 01BF: BCF 20.3
6110 01C0: MOVF 20,W
6111 01C1: BSF 03.5
6112 01C2: MOVWF 07
6113 .................... I2C_Write(MAG_W); // W
6114 01C3: MOVLW 3C
6115 01C4: BCF 03.5
6116 01C5: MOVWF 5D
6117 01C6: CALL 0D8
6118 .................... I2C_Write(0x01);
6119 01C7: MOVLW 01
6120 01C8: MOVWF 5D
6121 01C9: CALL 0D8
6122 .................... I2C_Write(0x00);
6123 01CA: CLRF 5D
6124 01CB: CALL 0D8
6125 .................... i2c_stop();
6126 01CC: BCF 20.4
6127 01CD: MOVF 20,W
6128 01CE: BSF 03.5
6129 01CF: MOVWF 07
6130 01D0: NOP
6131 01D1: BCF 03.5
6132 01D2: BSF 20.3
6133 01D3: MOVF 20,W
6134 01D4: BSF 03.5
6135 01D5: MOVWF 07
6136 01D6: BCF 03.5
6137 01D7: BTFSS 07.3
6138 01D8: GOTO 1D7
6139 01D9: NOP
6140 01DA: GOTO 1DB
6141 01DB: NOP
6142 01DC: BSF 20.4
6143 01DD: MOVF 20,W
6144 01DE: BSF 03.5
6145 01DF: MOVWF 07
6146 01E0: NOP
6147 ....................
6148 .................... Delay_ms(6);
6149 01E1: MOVLW 06
6150 01E2: BCF 03.5
6151 01E3: MOVWF 4F
6152 01E4: CALL 15D
6153 ....................
6154 .................... i2c_start();
6155 01E5: BSF 20.4
6156 01E6: MOVF 20,W
6157 01E7: BSF 03.5
6158 01E8: MOVWF 07
6159 01E9: NOP
6160 01EA: BCF 03.5
6161 01EB: BSF 20.3
6162 01EC: MOVF 20,W
6163 01ED: BSF 03.5
6164 01EE: MOVWF 07
6165 01EF: NOP
6166 01F0: BCF 03.5
6167 01F1: BCF 07.4
6168 01F2: BCF 20.4
6169 01F3: MOVF 20,W
6170 01F4: BSF 03.5
6171 01F5: MOVWF 07
6172 01F6: NOP
6173 01F7: BCF 03.5
6174 01F8: BCF 07.3
6175 01F9: BCF 20.3
6176 01FA: MOVF 20,W
6177 01FB: BSF 03.5
6178 01FC: MOVWF 07
6179 .................... I2C_Write(MAG_W); // W
6180 01FD: MOVLW 3C
6181 01FE: BCF 03.5
6182 01FF: MOVWF 5D
6183 0200: CALL 0D8
6184 .................... I2C_Write(0x02);
6185 0201: MOVLW 02
6186 0202: MOVWF 5D
6187 0203: CALL 0D8
6188 .................... I2C_Write(0x00);
6189 0204: CLRF 5D
6190 0205: CALL 0D8
6191 .................... i2c_stop();
6192 0206: BCF 20.4
6193 0207: MOVF 20,W
6194 0208: BSF 03.5
6195 0209: MOVWF 07
6196 020A: NOP
6197 020B: BCF 03.5
6198 020C: BSF 20.3
6199 020D: MOVF 20,W
6200 020E: BSF 03.5
6201 020F: MOVWF 07
6202 0210: BCF 03.5
6203 0211: BTFSS 07.3
6204 0212: GOTO 211
6205 0213: NOP
6206 0214: GOTO 215
6207 0215: NOP
6208 0216: BSF 20.4
6209 0217: MOVF 20,W
6210 0218: BSF 03.5
6211 0219: MOVWF 07
6212 021A: NOP
6213 .................... Delay_ms(6);
6214 021B: MOVLW 06
6215 021C: BCF 03.5
6216 021D: MOVWF 4F
6217 021E: CALL 15D
6218 .................... }
6219 021F: BCF 0A.3
6220 0220: BSF 0A.4
6221 0221: GOTO 125 (RETURN)
6222 ....................
6223 .................... int16 akR (int8 H, int8 L) //vycitani hodnot z akcelerometru
6224 .................... {
6225 *
6226 03D4: CLRF 59
6227 03D5: CLRF 5A
6228 .................... unsigned int8 XL=0,XH=0;
6229 .................... signed int16 x;
6230 ....................
6231 .................... i2c_start();
6232 03D6: BSF 20.4
6233 03D7: MOVF 20,W
6234 03D8: BSF 03.5
6235 03D9: MOVWF 07
6236 03DA: NOP
6237 03DB: BCF 03.5
6238 03DC: BSF 20.3
6239 03DD: MOVF 20,W
6240 03DE: BSF 03.5
6241 03DF: MOVWF 07
6242 03E0: NOP
6243 03E1: BCF 03.5
6244 03E2: BCF 07.4
6245 03E3: BCF 20.4
6246 03E4: MOVF 20,W
6247 03E5: BSF 03.5
6248 03E6: MOVWF 07
6249 03E7: NOP
6250 03E8: BCF 03.5
6251 03E9: BCF 07.3
6252 03EA: BCF 20.3
6253 03EB: MOVF 20,W
6254 03EC: BSF 03.5
6255 03ED: MOVWF 07
6256 .................... I2C_Write(AK_W);
6257 03EE: MOVLW 38
6258 03EF: BCF 03.5
6259 03F0: MOVWF 5D
6260 03F1: CALL 0D8
6261 .................... I2C_write(H);
6262 03F2: MOVF 57,W
6263 03F3: MOVWF 5D
6264 03F4: CALL 0D8
6265 .................... i2c_start();
6266 03F5: BSF 20.4
6267 03F6: MOVF 20,W
6268 03F7: BSF 03.5
6269 03F8: MOVWF 07
6270 03F9: NOP
6271 03FA: BCF 03.5
6272 03FB: BSF 20.3
6273 03FC: MOVF 20,W
6274 03FD: BSF 03.5
6275 03FE: MOVWF 07
6276 03FF: NOP
6277 0400: BCF 03.5
6278 0401: BTFSS 07.3
6279 0402: GOTO 401
6280 0403: BCF 07.4
6281 0404: BCF 20.4
6282 0405: MOVF 20,W
6283 0406: BSF 03.5
6284 0407: MOVWF 07
6285 0408: NOP
6286 0409: BCF 03.5
6287 040A: BCF 07.3
6288 040B: BCF 20.3
6289 040C: MOVF 20,W
6290 040D: BSF 03.5
6291 040E: MOVWF 07
6292 .................... I2C_Write(AK_R);
6293 040F: MOVLW 39
6294 0410: BCF 03.5
6295 0411: MOVWF 5D
6296 0412: CALL 0D8
6297 .................... XH=i2c_read(0);
6298 0413: CLRF 77
6299 0414: CALL 38F
6300 0415: MOVF 78,W
6301 0416: MOVWF 5A
6302 .................... i2c_stop();
6303 0417: BCF 20.4
6304 0418: MOVF 20,W
6305 0419: BSF 03.5
6306 041A: MOVWF 07
6307 041B: NOP
6308 041C: BCF 03.5
6309 041D: BSF 20.3
6310 041E: MOVF 20,W
6311 041F: BSF 03.5
6312 0420: MOVWF 07
6313 0421: BCF 03.5
6314 0422: BTFSS 07.3
6315 0423: GOTO 422
6316 0424: NOP
6317 0425: GOTO 426
6318 0426: NOP
6319 0427: BSF 20.4
6320 0428: MOVF 20,W
6321 0429: BSF 03.5
6322 042A: MOVWF 07
6323 042B: NOP
6324 ....................
6325 .................... i2c_start();
6326 042C: BCF 03.5
6327 042D: BSF 20.4
6328 042E: MOVF 20,W
6329 042F: BSF 03.5
6330 0430: MOVWF 07
6331 0431: NOP
6332 0432: BCF 03.5
6333 0433: BSF 20.3
6334 0434: MOVF 20,W
6335 0435: BSF 03.5
6336 0436: MOVWF 07
6337 0437: NOP
6338 0438: BCF 03.5
6339 0439: BCF 07.4
6340 043A: BCF 20.4
6341 043B: MOVF 20,W
6342 043C: BSF 03.5
6343 043D: MOVWF 07
6344 043E: NOP
6345 043F: BCF 03.5
6346 0440: BCF 07.3
6347 0441: BCF 20.3
6348 0442: MOVF 20,W
6349 0443: BSF 03.5
6350 0444: MOVWF 07
6351 .................... I2C_Write(AK_W);
6352 0445: MOVLW 38
6353 0446: BCF 03.5
6354 0447: MOVWF 5D
6355 0448: CALL 0D8
6356 .................... I2C_write(L);
6357 0449: MOVF 58,W
6358 044A: MOVWF 5D
6359 044B: CALL 0D8
6360 .................... i2c_start();
6361 044C: BSF 20.4
6362 044D: MOVF 20,W
6363 044E: BSF 03.5
6364 044F: MOVWF 07
6365 0450: NOP
6366 0451: BCF 03.5
6367 0452: BSF 20.3
6368 0453: MOVF 20,W
6369 0454: BSF 03.5
6370 0455: MOVWF 07
6371 0456: NOP
6372 0457: BCF 03.5
6373 0458: BTFSS 07.3
6374 0459: GOTO 458
6375 045A: BCF 07.4
6376 045B: BCF 20.4
6377 045C: MOVF 20,W
6378 045D: BSF 03.5
6379 045E: MOVWF 07
6380 045F: NOP
6381 0460: BCF 03.5
6382 0461: BCF 07.3
6383 0462: BCF 20.3
6384 0463: MOVF 20,W
6385 0464: BSF 03.5
6386 0465: MOVWF 07
6387 .................... I2C_Write(AK_R);
6388 0466: MOVLW 39
6389 0467: BCF 03.5
6390 0468: MOVWF 5D
6391 0469: CALL 0D8
6392 .................... XL=i2c_read(0);
6393 046A: CLRF 77
6394 046B: CALL 38F
6395 046C: MOVF 78,W
6396 046D: MOVWF 59
6397 .................... i2c_stop();
6398 046E: BCF 20.4
6399 046F: MOVF 20,W
6400 0470: BSF 03.5
6401 0471: MOVWF 07
6402 0472: NOP
6403 0473: BCF 03.5
6404 0474: BSF 20.3
6405 0475: MOVF 20,W
6406 0476: BSF 03.5
6407 0477: MOVWF 07
6408 0478: BCF 03.5
6409 0479: BTFSS 07.3
6410 047A: GOTO 479
6411 047B: NOP
6412 047C: GOTO 47D
6413 047D: NOP
6414 047E: BSF 20.4
6415 047F: MOVF 20,W
6416 0480: BSF 03.5
6417 0481: MOVWF 07
6418 0482: NOP
6419 ....................
6420 .................... x = (((unsigned int16) XH << 8) + XL ); //prevod na 16bit hodnotu
6421 0483: BCF 03.5
6422 0484: CLRF 5E
6423 0485: MOVF 5A,W
6424 0486: MOVWF 5D
6425 0487: MOVWF 5E
6426 0488: CLRF 5D
6427 0489: MOVF 59,W
6428 048A: ADDWF 5D,W
6429 048B: MOVWF 78
6430 048C: MOVF 5E,W
6431 048D: MOVWF 7A
6432 048E: BTFSC 03.0
6433 048F: INCF 7A,F
6434 0490: MOVF 78,W
6435 0491: MOVWF 5B
6436 0492: MOVF 7A,W
6437 0493: MOVWF 5C
6438 .................... x=x/4;
6439 0494: MOVF 5C,W
6440 0495: MOVWF 5E
6441 0496: MOVF 5B,W
6442 0497: MOVWF 5D
6443 0498: CLRF 60
6444 0499: MOVLW 04
6445 049A: MOVWF 5F
6446 *
6447 04D8: MOVF 79,W
6448 04D9: MOVWF 5C
6449 04DA: MOVF 78,W
6450 04DB: MOVWF 5B
6451 ....................
6452 .................... return x;
6453 04DC: MOVF 5B,W
6454 04DD: MOVWF 78
6455 04DE: MOVF 5C,W
6456 04DF: MOVWF 79
6457 .................... }
6458 04E0: RETURN
6459 ....................
6460 .................... int16 magR (int8 H, int8 L) //vycitani hodnot z magnetometru
6461 .................... {
6462 *
6463 0DBB: CLRF 59
6464 0DBC: CLRF 5A
6465 .................... unsigned int8 XL=0,XH=0;
6466 .................... signed int16 x;
6467 ....................
6468 .................... i2c_start();
6469 0DBD: BSF 20.4
6470 0DBE: MOVF 20,W
6471 0DBF: BSF 03.5
6472 0DC0: MOVWF 07
6473 0DC1: NOP
6474 0DC2: BCF 03.5
6475 0DC3: BSF 20.3
6476 0DC4: MOVF 20,W
6477 0DC5: BSF 03.5
6478 0DC6: MOVWF 07
6479 0DC7: NOP
6480 0DC8: BCF 03.5
6481 0DC9: BCF 07.4
6482 0DCA: BCF 20.4
6483 0DCB: MOVF 20,W
6484 0DCC: BSF 03.5
6485 0DCD: MOVWF 07
6486 0DCE: NOP
6487 0DCF: BCF 03.5
6488 0DD0: BCF 07.3
6489 0DD1: BCF 20.3
6490 0DD2: MOVF 20,W
6491 0DD3: BSF 03.5
6492 0DD4: MOVWF 07
6493 .................... I2C_Write(MAG_W);
6494 0DD5: MOVLW 3C
6495 0DD6: BCF 03.5
6496 0DD7: MOVWF 5D
6497 0DD8: BCF 0A.3
6498 0DD9: CALL 0D8
6499 0DDA: BSF 0A.3
6500 .................... I2C_write(H);
6501 0DDB: MOVF 57,W
6502 0DDC: MOVWF 5D
6503 0DDD: BCF 0A.3
6504 0DDE: CALL 0D8
6505 0DDF: BSF 0A.3
6506 .................... i2c_start();
6507 0DE0: BSF 20.4
6508 0DE1: MOVF 20,W
6509 0DE2: BSF 03.5
6510 0DE3: MOVWF 07
6511 0DE4: NOP
6512 0DE5: BCF 03.5
6513 0DE6: BSF 20.3
6514 0DE7: MOVF 20,W
6515 0DE8: BSF 03.5
6516 0DE9: MOVWF 07
6517 0DEA: NOP
6518 0DEB: BCF 03.5
6519 0DEC: BTFSS 07.3
6520 0DED: GOTO 5EC
6521 0DEE: BCF 07.4
6522 0DEF: BCF 20.4
6523 0DF0: MOVF 20,W
6524 0DF1: BSF 03.5
6525 0DF2: MOVWF 07
6526 0DF3: NOP
6527 0DF4: BCF 03.5
6528 0DF5: BCF 07.3
6529 0DF6: BCF 20.3
6530 0DF7: MOVF 20,W
6531 0DF8: BSF 03.5
6532 0DF9: MOVWF 07
6533 .................... I2C_Write(MAG_R);
6534 0DFA: MOVLW 3D
6535 0DFB: BCF 03.5
6536 0DFC: MOVWF 5D
6537 0DFD: BCF 0A.3
6538 0DFE: CALL 0D8
6539 0DFF: BSF 0A.3
6540 .................... XH=i2c_read(0);
6541 0E00: CLRF 77
6542 0E01: BCF 0A.3
6543 0E02: CALL 38F
6544 0E03: BSF 0A.3
6545 0E04: MOVF 78,W
6546 0E05: MOVWF 5A
6547 .................... i2c_stop();
6548 0E06: BCF 20.4
6549 0E07: MOVF 20,W
6550 0E08: BSF 03.5
6551 0E09: MOVWF 07
6552 0E0A: NOP
6553 0E0B: BCF 03.5
6554 0E0C: BSF 20.3
6555 0E0D: MOVF 20,W
6556 0E0E: BSF 03.5
6557 0E0F: MOVWF 07
6558 0E10: BCF 03.5
6559 0E11: BTFSS 07.3
6560 0E12: GOTO 611
6561 0E13: NOP
6562 0E14: GOTO 615
6563 0E15: NOP
6564 0E16: BSF 20.4
6565 0E17: MOVF 20,W
6566 0E18: BSF 03.5
6567 0E19: MOVWF 07
6568 0E1A: NOP
6569 ....................
6570 .................... i2c_start();
6571 0E1B: BCF 03.5
6572 0E1C: BSF 20.4
6573 0E1D: MOVF 20,W
6574 0E1E: BSF 03.5
6575 0E1F: MOVWF 07
6576 0E20: NOP
6577 0E21: BCF 03.5
6578 0E22: BSF 20.3
6579 0E23: MOVF 20,W
6580 0E24: BSF 03.5
6581 0E25: MOVWF 07
6582 0E26: NOP
6583 0E27: BCF 03.5
6584 0E28: BCF 07.4
6585 0E29: BCF 20.4
6586 0E2A: MOVF 20,W
6587 0E2B: BSF 03.5
6588 0E2C: MOVWF 07
6589 0E2D: NOP
6590 0E2E: BCF 03.5
6591 0E2F: BCF 07.3
6592 0E30: BCF 20.3
6593 0E31: MOVF 20,W
6594 0E32: BSF 03.5
6595 0E33: MOVWF 07
6596 .................... I2C_Write(MAG_W);
6597 0E34: MOVLW 3C
6598 0E35: BCF 03.5
6599 0E36: MOVWF 5D
6600 0E37: BCF 0A.3
6601 0E38: CALL 0D8
6602 0E39: BSF 0A.3
6603 .................... I2C_write(L);
6604 0E3A: MOVF 58,W
6605 0E3B: MOVWF 5D
6606 0E3C: BCF 0A.3
6607 0E3D: CALL 0D8
6608 0E3E: BSF 0A.3
6609 .................... i2c_start();
6610 0E3F: BSF 20.4
6611 0E40: MOVF 20,W
6612 0E41: BSF 03.5
6613 0E42: MOVWF 07
6614 0E43: NOP
6615 0E44: BCF 03.5
6616 0E45: BSF 20.3
6617 0E46: MOVF 20,W
6618 0E47: BSF 03.5
6619 0E48: MOVWF 07
6620 0E49: NOP
6621 0E4A: BCF 03.5
6622 0E4B: BTFSS 07.3
6623 0E4C: GOTO 64B
6624 0E4D: BCF 07.4
6625 0E4E: BCF 20.4
6626 0E4F: MOVF 20,W
6627 0E50: BSF 03.5
6628 0E51: MOVWF 07
6629 0E52: NOP
6630 0E53: BCF 03.5
6631 0E54: BCF 07.3
6632 0E55: BCF 20.3
6633 0E56: MOVF 20,W
6634 0E57: BSF 03.5
6635 0E58: MOVWF 07
6636 .................... I2C_Write(MAG_R);
6637 0E59: MOVLW 3D
6638 0E5A: BCF 03.5
6639 0E5B: MOVWF 5D
6640 0E5C: BCF 0A.3
6641 0E5D: CALL 0D8
6642 0E5E: BSF 0A.3
6643 .................... XL=i2c_read(0);
6644 0E5F: CLRF 77
6645 0E60: BCF 0A.3
6646 0E61: CALL 38F
6647 0E62: BSF 0A.3
6648 0E63: MOVF 78,W
6649 0E64: MOVWF 59
6650 .................... i2c_stop();
6651 0E65: BCF 20.4
6652 0E66: MOVF 20,W
6653 0E67: BSF 03.5
6654 0E68: MOVWF 07
6655 0E69: NOP
6656 0E6A: BCF 03.5
6657 0E6B: BSF 20.3
6658 0E6C: MOVF 20,W
6659 0E6D: BSF 03.5
6660 0E6E: MOVWF 07
6661 0E6F: BCF 03.5
6662 0E70: BTFSS 07.3
6663 0E71: GOTO 670
6664 0E72: NOP
6665 0E73: GOTO 674
6666 0E74: NOP
6667 0E75: BSF 20.4
6668 0E76: MOVF 20,W
6669 0E77: BSF 03.5
6670 0E78: MOVWF 07
6671 0E79: NOP
6672 ....................
6673 .................... x = (((unsigned int16) XH << 8) + XL );
6674 0E7A: BCF 03.5
6675 0E7B: CLRF 5E
6676 0E7C: MOVF 5A,W
6677 0E7D: MOVWF 5D
6678 0E7E: MOVWF 5E
6679 0E7F: CLRF 5D
6680 0E80: MOVF 59,W
6681 0E81: ADDWF 5D,W
6682 0E82: MOVWF 5B
6683 0E83: MOVF 5E,W
6684 0E84: MOVWF 5C
6685 0E85: BTFSC 03.0
6686 0E86: INCF 5C,F
6687 ....................
6688 ....................
6689 .................... return x;
6690 0E87: MOVF 5B,W
6691 0E88: MOVWF 78
6692 0E89: MOVF 5C,W
6693 0E8A: MOVWF 79
6694 .................... }
6695 0E8B: RETURN
6696 ....................
6697 .................... float elevace (void) //vypocet aktualni elevace panelu
6698 .................... {
6699 .................... //printf("Akcelerometr5: \r\n",);
6700 ....................
6701 .................... X= akR (AK_XH, AK_XL);
6702 *
6703 0BDD: MOVLW 01
6704 0BDE: MOVWF 57
6705 0BDF: MOVLW 02
6706 0BE0: MOVWF 58
6707 0BE1: BCF 0A.3
6708 0BE2: CALL 3D4
6709 0BE3: BSF 0A.3
6710 0BE4: MOVF 79,W
6711 0BE5: MOVWF 28
6712 0BE6: MOVF 78,W
6713 0BE7: MOVWF 27
6714 .................... Y= akR (AK_YH, AK_YL);
6715 0BE8: MOVLW 03
6716 0BE9: MOVWF 57
6717 0BEA: MOVLW 04
6718 0BEB: MOVWF 58
6719 0BEC: BCF 0A.3
6720 0BED: CALL 3D4
6721 0BEE: BSF 0A.3
6722 0BEF: MOVF 79,W
6723 0BF0: MOVWF 2A
6724 0BF1: MOVF 78,W
6725 0BF2: MOVWF 29
6726 .................... Z= akR (AK_ZH, AK_ZL);
6727 0BF3: MOVLW 05
6728 0BF4: MOVWF 57
6729 0BF5: MOVLW 06
6730 0BF6: MOVWF 58
6731 0BF7: BCF 0A.3
6732 0BF8: CALL 3D4
6733 0BF9: BSF 0A.3
6734 0BFA: MOVF 79,W
6735 0BFB: MOVWF 2C
6736 0BFC: MOVF 78,W
6737 0BFD: MOVWF 2B
6738 ....................
6739 .................... AX=abs(X);
6740 0BFE: MOVF 28,W
6741 0BFF: MOVWF 7A
6742 0C00: MOVF 27,W
6743 0C01: BTFSS 28.7
6744 0C02: GOTO 40C
6745 0C03: MOVF 27,W
6746 0C04: SUBLW 00
6747 0C05: MOVWF 77
6748 0C06: CLRF 7A
6749 0C07: MOVF 28,W
6750 0C08: BTFSS 03.0
6751 0C09: INCFSZ 28,W
6752 0C0A: SUBWF 7A,F
6753 0C0B: MOVF 77,W
6754 0C0C: MOVWF 2D
6755 0C0D: MOVF 7A,W
6756 0C0E: MOVWF 2E
6757 .................... AY=abs(Y)+250;
6758 0C0F: MOVF 2A,W
6759 0C10: MOVWF 7A
6760 0C11: MOVF 29,W
6761 0C12: BTFSS 2A.7
6762 0C13: GOTO 41D
6763 0C14: MOVF 29,W
6764 0C15: SUBLW 00
6765 0C16: MOVWF 77
6766 0C17: CLRF 7A
6767 0C18: MOVF 2A,W
6768 0C19: BTFSS 03.0
6769 0C1A: INCFSZ 2A,W
6770 0C1B: SUBWF 7A,F
6771 0C1C: MOVF 77,W
6772 0C1D: MOVWF 57
6773 0C1E: MOVLW FA
6774 0C1F: ADDWF 57,W
6775 0C20: MOVWF 2F
6776 0C21: MOVF 7A,W
6777 0C22: MOVWF 30
6778 0C23: BTFSC 03.0
6779 0C24: INCF 30,F
6780 .................... AZ=abs(Z)+250;
6781 0C25: MOVF 2C,W
6782 0C26: MOVWF 7A
6783 0C27: MOVF 2B,W
6784 0C28: BTFSS 2C.7
6785 0C29: GOTO 433
6786 0C2A: MOVF 2B,W
6787 0C2B: SUBLW 00
6788 0C2C: MOVWF 77
6789 0C2D: CLRF 7A
6790 0C2E: MOVF 2C,W
6791 0C2F: BTFSS 03.0
6792 0C30: INCFSZ 2C,W
6793 0C31: SUBWF 7A,F
6794 0C32: MOVF 77,W
6795 0C33: MOVWF 57
6796 0C34: MOVLW FA
6797 0C35: ADDWF 57,W
6798 0C36: MOVWF 31
6799 0C37: MOVF 7A,W
6800 0C38: MOVWF 32
6801 0C39: BTFSC 03.0
6802 0C3A: INCF 32,F
6803 ....................
6804 .................... float a, b;
6805 .................... a=(float)Y/Z;
6806 0C3B: MOVF 2A,W
6807 0C3C: MOVWF 5C
6808 0C3D: MOVF 29,W
6809 0C3E: MOVWF 5B
6810 0C3F: BCF 0A.3
6811 0C40: CALL 4E1
6812 0C41: BSF 0A.3
6813 0C42: MOVF 77,W
6814 0C43: MOVWF 57
6815 0C44: MOVF 78,W
6816 0C45: MOVWF 58
6817 0C46: MOVF 79,W
6818 0C47: MOVWF 59
6819 0C48: MOVF 7A,W
6820 0C49: MOVWF 5A
6821 0C4A: MOVF 2C,W
6822 0C4B: MOVWF 5C
6823 0C4C: MOVF 2B,W
6824 0C4D: MOVWF 5B
6825 0C4E: BCF 0A.3
6826 0C4F: CALL 4E1
6827 0C50: BSF 0A.3
6828 0C51: MOVF 5A,W
6829 0C52: MOVWF 6F
6830 0C53: MOVF 59,W
6831 0C54: MOVWF 6E
6832 0C55: MOVF 58,W
6833 0C56: MOVWF 6D
6834 0C57: MOVF 57,W
6835 0C58: MOVWF 6C
6836 0C59: MOVF 7A,W
6837 0C5A: MOVWF 73
6838 0C5B: MOVF 79,W
6839 0C5C: MOVWF 72
6840 0C5D: MOVF 78,W
6841 0C5E: MOVWF 71
6842 0C5F: MOVF 77,W
6843 0C60: MOVWF 70
6844 0C61: BCF 0A.3
6845 0C62: CALL 506
6846 0C63: BSF 0A.3
6847 0C64: MOVF 7A,W
6848 0C65: MOVWF 52
6849 0C66: MOVF 79,W
6850 0C67: MOVWF 51
6851 0C68: MOVF 78,W
6852 0C69: MOVWF 50
6853 0C6A: MOVF 77,W
6854 0C6B: MOVWF 4F
6855 .................... b=atan(a);
6856 0C6C: MOVF 52,W
6857 0C6D: MOVWF 5A
6858 0C6E: MOVF 51,W
6859 0C6F: MOVWF 59
6860 0C70: MOVF 50,W
6861 0C71: MOVWF 58
6862 0C72: MOVF 4F,W
6863 0C73: MOVWF 57
6864 0C74: CALL 15D
6865 0C75: MOVF 7A,W
6866 0C76: MOVWF 56
6867 0C77: MOVF 79,W
6868 0C78: MOVWF 55
6869 0C79: MOVF 78,W
6870 0C7A: MOVWF 54
6871 0C7B: MOVF 77,W
6872 0C7C: MOVWF 53
6873 .................... b = (b/3.14)*180;
6874 0C7D: MOVF 56,W
6875 0C7E: MOVWF 6F
6876 0C7F: MOVF 55,W
6877 0C80: MOVWF 6E
6878 0C81: MOVF 54,W
6879 0C82: MOVWF 6D
6880 0C83: MOVF 53,W
6881 0C84: MOVWF 6C
6882 0C85: MOVLW C3
6883 0C86: MOVWF 73
6884 0C87: MOVLW F5
6885 0C88: MOVWF 72
6886 0C89: MOVLW 48
6887 0C8A: MOVWF 71
6888 0C8B: MOVLW 80
6889 0C8C: MOVWF 70
6890 0C8D: BCF 0A.3
6891 0C8E: CALL 506
6892 0C8F: BSF 0A.3
6893 0C90: MOVF 77,W
6894 0C91: MOVWF 57
6895 0C92: MOVF 78,W
6896 0C93: MOVWF 58
6897 0C94: MOVF 79,W
6898 0C95: MOVWF 59
6899 0C96: MOVF 7A,W
6900 0C97: MOVWF 5A
6901 0C98: MOVWF 6F
6902 0C99: MOVF 79,W
6903 0C9A: MOVWF 6E
6904 0C9B: MOVF 78,W
6905 0C9C: MOVWF 6D
6906 0C9D: MOVF 77,W
6907 0C9E: MOVWF 6C
6908 0C9F: CLRF 73
6909 0CA0: CLRF 72
6910 0CA1: MOVLW 34
6911 0CA2: MOVWF 71
6912 0CA3: MOVLW 86
6913 0CA4: MOVWF 70
6914 0CA5: BCF 0A.3
6915 0CA6: CALL 626
6916 0CA7: BSF 0A.3
6917 0CA8: MOVF 7A,W
6918 0CA9: MOVWF 56
6919 0CAA: MOVF 79,W
6920 0CAB: MOVWF 55
6921 0CAC: MOVF 78,W
6922 0CAD: MOVWF 54
6923 0CAE: MOVF 77,W
6924 0CAF: MOVWF 53
6925 .................... b=abs(b);
6926 0CB0: MOVF 53,W
6927 0CB1: MOVWF 77
6928 0CB2: MOVF 54,W
6929 0CB3: MOVWF 78
6930 0CB4: MOVF 55,W
6931 0CB5: MOVWF 79
6932 0CB6: MOVF 56,W
6933 0CB7: MOVWF 7A
6934 0CB8: BCF 78.7
6935 0CB9: MOVF 56,W
6936 0CBA: MOVWF 56
6937 0CBB: MOVF 55,W
6938 0CBC: MOVWF 55
6939 0CBD: MOVF 78,W
6940 0CBE: MOVWF 54
6941 0CBF: MOVF 53,W
6942 0CC0: MOVWF 53
6943 ....................
6944 .................... if(((AX>AY) || (AX>AZ))) //indikace prevraceni panelu
6945 0CC1: BTFSS 30.7
6946 0CC2: GOTO 4C6
6947 0CC3: BTFSS 2E.7
6948 0CC4: GOTO 4E3
6949 0CC5: GOTO 4C8
6950 0CC6: BTFSC 2E.7
6951 0CC7: GOTO 4D2
6952 0CC8: MOVF 30,W
6953 0CC9: SUBWF 2E,W
6954 0CCA: BTFSS 03.0
6955 0CCB: GOTO 4D2
6956 0CCC: BTFSS 03.2
6957 0CCD: GOTO 4E3
6958 0CCE: MOVF 2D,W
6959 0CCF: SUBWF 2F,W
6960 0CD0: BTFSS 03.0
6961 0CD1: GOTO 4E3
6962 0CD2: BTFSS 32.7
6963 0CD3: GOTO 4D7
6964 0CD4: BTFSS 2E.7
6965 0CD5: GOTO 4E3
6966 0CD6: GOTO 4D9
6967 0CD7: BTFSC 2E.7
6968 0CD8: GOTO 50C
6969 0CD9: MOVF 32,W
6970 0CDA: SUBWF 2E,W
6971 0CDB: BTFSS 03.0
6972 0CDC: GOTO 50C
6973 0CDD: BTFSS 03.2
6974 0CDE: GOTO 4E3
6975 0CDF: MOVF 2D,W
6976 0CE0: SUBWF 31,W
6977 0CE1: BTFSC 03.0
6978 0CE2: GOTO 50C
6979 .................... {
6980 .................... printf("Prevracený panel)\r\n", );
6981 0CE3: MOVLW 04
6982 0CE4: BSF 03.6
6983 0CE5: MOVWF 0D
6984 0CE6: MOVLW 00
6985 0CE7: MOVWF 0F
6986 .................... }
6987 .................... else
6988 *
6989 0D0A: GOTO 598
6990 0D0B: BCF 03.6
6991 .................... {
6992 .................... if(Z==0) //osetreni proti deleni 0
6993 0D0C: MOVF 2B,F
6994 0D0D: BTFSS 03.2
6995 0D0E: GOTO 527
6996 0D0F: MOVF 2C,F
6997 0D10: BTFSS 03.2
6998 0D11: GOTO 527
6999 .................... {
7000 .................... if(Y>0)
7001 0D12: BTFSC 2A.7
7002 0D13: GOTO 522
7003 0D14: MOVF 2A,F
7004 0D15: BTFSS 03.2
7005 0D16: GOTO 51B
7006 0D17: MOVF 29,W
7007 0D18: SUBLW 00
7008 0D19: BTFSC 03.0
7009 0D1A: GOTO 522
7010 .................... {
7011 .................... b=180;
7012 0D1B: CLRF 56
7013 0D1C: CLRF 55
7014 0D1D: MOVLW 34
7015 0D1E: MOVWF 54
7016 0D1F: MOVLW 86
7017 0D20: MOVWF 53
7018 .................... }
7019 .................... else
7020 0D21: GOTO 526
7021 .................... {
7022 .................... b=0;
7023 0D22: CLRF 56
7024 0D23: CLRF 55
7025 0D24: CLRF 54
7026 0D25: CLRF 53
7027 .................... }
7028 .................... }
7029 .................... else
7030 0D26: GOTO 597
7031 .................... {
7032 .................... if(Z>0)
7033 0D27: BTFSC 2C.7
7034 0D28: GOTO 564
7035 0D29: MOVF 2C,F
7036 0D2A: BTFSS 03.2
7037 0D2B: GOTO 530
7038 0D2C: MOVF 2B,W
7039 0D2D: SUBLW 00
7040 0D2E: BTFSC 03.0
7041 0D2F: GOTO 564
7042 .................... {
7043 .................... if(Y>=0)
7044 0D30: BTFSC 2A.7
7045 0D31: GOTO 54B
7046 .................... {
7047 .................... b=90+b;
7048 0D32: BCF 03.1
7049 0D33: CLRF 6F
7050 0D34: CLRF 6E
7051 0D35: MOVLW 34
7052 0D36: MOVWF 6D
7053 0D37: MOVLW 85
7054 0D38: MOVWF 6C
7055 0D39: MOVF 56,W
7056 0D3A: MOVWF 73
7057 0D3B: MOVF 55,W
7058 0D3C: MOVWF 72
7059 0D3D: MOVF 54,W
7060 0D3E: MOVWF 71
7061 0D3F: MOVF 53,W
7062 0D40: MOVWF 70
7063 0D41: CALL 000
7064 0D42: MOVF 7A,W
7065 0D43: MOVWF 56
7066 0D44: MOVF 79,W
7067 0D45: MOVWF 55
7068 0D46: MOVF 78,W
7069 0D47: MOVWF 54
7070 0D48: MOVF 77,W
7071 0D49: MOVWF 53
7072 .................... }
7073 .................... else
7074 0D4A: GOTO 563
7075 .................... {
7076 .................... b=90-b;
7077 0D4B: BSF 03.1
7078 0D4C: CLRF 6F
7079 0D4D: CLRF 6E
7080 0D4E: MOVLW 34
7081 0D4F: MOVWF 6D
7082 0D50: MOVLW 85
7083 0D51: MOVWF 6C
7084 0D52: MOVF 56,W
7085 0D53: MOVWF 73
7086 0D54: MOVF 55,W
7087 0D55: MOVWF 72
7088 0D56: MOVF 54,W
7089 0D57: MOVWF 71
7090 0D58: MOVF 53,W
7091 0D59: MOVWF 70
7092 0D5A: CALL 000
7093 0D5B: MOVF 7A,W
7094 0D5C: MOVWF 56
7095 0D5D: MOVF 79,W
7096 0D5E: MOVWF 55
7097 0D5F: MOVF 78,W
7098 0D60: MOVWF 54
7099 0D61: MOVF 77,W
7100 0D62: MOVWF 53
7101 .................... }
7102 .................... }
7103 .................... else
7104 0D63: GOTO 597
7105 .................... {
7106 .................... if(Y>=0)
7107 0D64: BTFSC 2A.7
7108 0D65: GOTO 57F
7109 .................... {
7110 .................... b=180-b;
7111 0D66: BSF 03.1
7112 0D67: CLRF 6F
7113 0D68: CLRF 6E
7114 0D69: MOVLW 34
7115 0D6A: MOVWF 6D
7116 0D6B: MOVLW 86
7117 0D6C: MOVWF 6C
7118 0D6D: MOVF 56,W
7119 0D6E: MOVWF 73
7120 0D6F: MOVF 55,W
7121 0D70: MOVWF 72
7122 0D71: MOVF 54,W
7123 0D72: MOVWF 71
7124 0D73: MOVF 53,W
7125 0D74: MOVWF 70
7126 0D75: CALL 000
7127 0D76: MOVF 7A,W
7128 0D77: MOVWF 56
7129 0D78: MOVF 79,W
7130 0D79: MOVWF 55
7131 0D7A: MOVF 78,W
7132 0D7B: MOVWF 54
7133 0D7C: MOVF 77,W
7134 0D7D: MOVWF 53
7135 .................... }
7136 .................... else
7137 0D7E: GOTO 597
7138 .................... {
7139 .................... b=270+b;
7140 0D7F: BCF 03.1
7141 0D80: CLRF 6F
7142 0D81: CLRF 6E
7143 0D82: MOVLW 07
7144 0D83: MOVWF 6D
7145 0D84: MOVLW 87
7146 0D85: MOVWF 6C
7147 0D86: MOVF 56,W
7148 0D87: MOVWF 73
7149 0D88: MOVF 55,W
7150 0D89: MOVWF 72
7151 0D8A: MOVF 54,W
7152 0D8B: MOVWF 71
7153 0D8C: MOVF 53,W
7154 0D8D: MOVWF 70
7155 0D8E: CALL 000
7156 0D8F: MOVF 7A,W
7157 0D90: MOVWF 56
7158 0D91: MOVF 79,W
7159 0D92: MOVWF 55
7160 0D93: MOVF 78,W
7161 0D94: MOVWF 54
7162 0D95: MOVF 77,W
7163 0D96: MOVWF 53
7164 0D97: BSF 03.6
7165 .................... }
7166 .................... }
7167 ....................
7168 .................... }
7169 ....................
7170 ....................
7171 ....................
7172 .................... }
7173 .................... // printf("uhel namìreny %10.2f \r\n", b);
7174 ....................
7175 .................... if(b>355)
7176 0D98: BCF 03.6
7177 0D99: CLRF 6B
7178 0D9A: MOVLW 80
7179 0D9B: MOVWF 6A
7180 0D9C: MOVLW 31
7181 0D9D: MOVWF 69
7182 0D9E: MOVLW 87
7183 0D9F: MOVWF 68
7184 0DA0: MOVF 56,W
7185 0DA1: MOVWF 6F
7186 0DA2: MOVF 55,W
7187 0DA3: MOVWF 6E
7188 0DA4: MOVF 54,W
7189 0DA5: MOVWF 6D
7190 0DA6: MOVF 53,W
7191 0DA7: MOVWF 6C
7192 0DA8: BCF 0A.3
7193 0DA9: CALL 5E7
7194 0DAA: BSF 0A.3
7195 0DAB: BTFSS 03.0
7196 0DAC: GOTO 5B2
7197 .................... {
7198 .................... b=0;
7199 0DAD: CLRF 56
7200 0DAE: CLRF 55
7201 0DAF: CLRF 54
7202 0DB0: CLRF 53
7203 .................... }
7204 .................... else
7205 0DB1: GOTO 5B2
7206 .................... {
7207 ....................
7208 .................... }
7209 .................... return b;
7210 0DB2: MOVF 53,W
7211 0DB3: MOVWF 77
7212 0DB4: MOVF 54,W
7213 0DB5: MOVWF 78
7214 0DB6: MOVF 55,W
7215 0DB7: MOVWF 79
7216 0DB8: MOVF 56,W
7217 0DB9: MOVWF 7A
7218 ....................
7219 .................... }
7220 0DBA: RETURN
7221 ....................
7222 .................... float azimut (void) //vypocet aktualni vysky panelu
7223 .................... {
7224 .................... X= magR (MAG_XH, MAG_XL);
7225 *
7226 0E8C: MOVLW 03
7227 0E8D: MOVWF 57
7228 0E8E: MOVLW 04
7229 0E8F: MOVWF 58
7230 0E90: CALL 5BB
7231 0E91: MOVF 79,W
7232 0E92: MOVWF 28
7233 0E93: MOVF 78,W
7234 0E94: MOVWF 27
7235 .................... Y= magR (MAG_YH, MAG_YL);
7236 0E95: MOVLW 07
7237 0E96: MOVWF 57
7238 0E97: MOVLW 08
7239 0E98: MOVWF 58
7240 0E99: CALL 5BB
7241 0E9A: MOVF 79,W
7242 0E9B: MOVWF 2A
7243 0E9C: MOVF 78,W
7244 0E9D: MOVWF 29
7245 .................... Z= magR (MAG_ZH, MAG_ZL);
7246 0E9E: MOVLW 05
7247 0E9F: MOVWF 57
7248 0EA0: MOVLW 06
7249 0EA1: MOVWF 58
7250 0EA2: CALL 5BB
7251 0EA3: MOVF 79,W
7252 0EA4: MOVWF 2C
7253 0EA5: MOVF 78,W
7254 0EA6: MOVWF 2B
7255 ....................
7256 ....................
7257 ....................
7258 ....................
7259 .................... AX=abs(X);
7260 0EA7: MOVF 28,W
7261 0EA8: MOVWF 7A
7262 0EA9: MOVF 27,W
7263 0EAA: BTFSS 28.7
7264 0EAB: GOTO 6B5
7265 0EAC: MOVF 27,W
7266 0EAD: SUBLW 00
7267 0EAE: MOVWF 77
7268 0EAF: CLRF 7A
7269 0EB0: MOVF 28,W
7270 0EB1: BTFSS 03.0
7271 0EB2: INCFSZ 28,W
7272 0EB3: SUBWF 7A,F
7273 0EB4: MOVF 77,W
7274 0EB5: MOVWF 2D
7275 0EB6: MOVF 7A,W
7276 0EB7: MOVWF 2E
7277 .................... AY=abs(Y);
7278 0EB8: MOVF 2A,W
7279 0EB9: MOVWF 7A
7280 0EBA: MOVF 29,W
7281 0EBB: BTFSS 2A.7
7282 0EBC: GOTO 6C6
7283 0EBD: MOVF 29,W
7284 0EBE: SUBLW 00
7285 0EBF: MOVWF 77
7286 0EC0: CLRF 7A
7287 0EC1: MOVF 2A,W
7288 0EC2: BTFSS 03.0
7289 0EC3: INCFSZ 2A,W
7290 0EC4: SUBWF 7A,F
7291 0EC5: MOVF 77,W
7292 0EC6: MOVWF 2F
7293 0EC7: MOVF 7A,W
7294 0EC8: MOVWF 30
7295 .................... AZ=abs(Z);
7296 0EC9: MOVF 2C,W
7297 0ECA: MOVWF 7A
7298 0ECB: MOVF 2B,W
7299 0ECC: BTFSS 2C.7
7300 0ECD: GOTO 6D7
7301 0ECE: MOVF 2B,W
7302 0ECF: SUBLW 00
7303 0ED0: MOVWF 77
7304 0ED1: CLRF 7A
7305 0ED2: MOVF 2C,W
7306 0ED3: BTFSS 03.0
7307 0ED4: INCFSZ 2C,W
7308 0ED5: SUBWF 7A,F
7309 0ED6: MOVF 77,W
7310 0ED7: MOVWF 31
7311 0ED8: MOVF 7A,W
7312 0ED9: MOVWF 32
7313 ....................
7314 .................... float a, b;
7315 .................... a=(float)Y/X;
7316 0EDA: MOVF 2A,W
7317 0EDB: MOVWF 5C
7318 0EDC: MOVF 29,W
7319 0EDD: MOVWF 5B
7320 0EDE: BCF 0A.3
7321 0EDF: CALL 4E1
7322 0EE0: BSF 0A.3
7323 0EE1: MOVF 77,W
7324 0EE2: MOVWF 57
7325 0EE3: MOVF 78,W
7326 0EE4: MOVWF 58
7327 0EE5: MOVF 79,W
7328 0EE6: MOVWF 59
7329 0EE7: MOVF 7A,W
7330 0EE8: MOVWF 5A
7331 0EE9: MOVF 28,W
7332 0EEA: MOVWF 5C
7333 0EEB: MOVF 27,W
7334 0EEC: MOVWF 5B
7335 0EED: BCF 0A.3
7336 0EEE: CALL 4E1
7337 0EEF: BSF 0A.3
7338 0EF0: MOVF 5A,W
7339 0EF1: MOVWF 6F
7340 0EF2: MOVF 59,W
7341 0EF3: MOVWF 6E
7342 0EF4: MOVF 58,W
7343 0EF5: MOVWF 6D
7344 0EF6: MOVF 57,W
7345 0EF7: MOVWF 6C
7346 0EF8: MOVF 7A,W
7347 0EF9: MOVWF 73
7348 0EFA: MOVF 79,W
7349 0EFB: MOVWF 72
7350 0EFC: MOVF 78,W
7351 0EFD: MOVWF 71
7352 0EFE: MOVF 77,W
7353 0EFF: MOVWF 70
7354 0F00: BCF 0A.3
7355 0F01: CALL 506
7356 0F02: BSF 0A.3
7357 0F03: MOVF 7A,W
7358 0F04: MOVWF 52
7359 0F05: MOVF 79,W
7360 0F06: MOVWF 51
7361 0F07: MOVF 78,W
7362 0F08: MOVWF 50
7363 0F09: MOVF 77,W
7364 0F0A: MOVWF 4F
7365 .................... b=atan(a);
7366 0F0B: MOVF 52,W
7367 0F0C: MOVWF 5A
7368 0F0D: MOVF 51,W
7369 0F0E: MOVWF 59
7370 0F0F: MOVF 50,W
7371 0F10: MOVWF 58
7372 0F11: MOVF 4F,W
7373 0F12: MOVWF 57
7374 0F13: CALL 15D
7375 0F14: MOVF 7A,W
7376 0F15: MOVWF 56
7377 0F16: MOVF 79,W
7378 0F17: MOVWF 55
7379 0F18: MOVF 78,W
7380 0F19: MOVWF 54
7381 0F1A: MOVF 77,W
7382 0F1B: MOVWF 53
7383 .................... b = (b/3.14)*180;
7384 0F1C: MOVF 56,W
7385 0F1D: MOVWF 6F
7386 0F1E: MOVF 55,W
7387 0F1F: MOVWF 6E
7388 0F20: MOVF 54,W
7389 0F21: MOVWF 6D
7390 0F22: MOVF 53,W
7391 0F23: MOVWF 6C
7392 0F24: MOVLW C3
7393 0F25: MOVWF 73
7394 0F26: MOVLW F5
7395 0F27: MOVWF 72
7396 0F28: MOVLW 48
7397 0F29: MOVWF 71
7398 0F2A: MOVLW 80
7399 0F2B: MOVWF 70
7400 0F2C: BCF 0A.3
7401 0F2D: CALL 506
7402 0F2E: BSF 0A.3
7403 0F2F: MOVF 77,W
7404 0F30: MOVWF 57
7405 0F31: MOVF 78,W
7406 0F32: MOVWF 58
7407 0F33: MOVF 79,W
7408 0F34: MOVWF 59
7409 0F35: MOVF 7A,W
7410 0F36: MOVWF 5A
7411 0F37: MOVWF 6F
7412 0F38: MOVF 79,W
7413 0F39: MOVWF 6E
7414 0F3A: MOVF 78,W
7415 0F3B: MOVWF 6D
7416 0F3C: MOVF 77,W
7417 0F3D: MOVWF 6C
7418 0F3E: CLRF 73
7419 0F3F: CLRF 72
7420 0F40: MOVLW 34
7421 0F41: MOVWF 71
7422 0F42: MOVLW 86
7423 0F43: MOVWF 70
7424 0F44: BCF 0A.3
7425 0F45: CALL 626
7426 0F46: BSF 0A.3
7427 0F47: MOVF 7A,W
7428 0F48: MOVWF 56
7429 0F49: MOVF 79,W
7430 0F4A: MOVWF 55
7431 0F4B: MOVF 78,W
7432 0F4C: MOVWF 54
7433 0F4D: MOVF 77,W
7434 0F4E: MOVWF 53
7435 .................... b=abs(b);
7436 0F4F: MOVF 53,W
7437 0F50: MOVWF 77
7438 0F51: MOVF 54,W
7439 0F52: MOVWF 78
7440 0F53: MOVF 55,W
7441 0F54: MOVWF 79
7442 0F55: MOVF 56,W
7443 0F56: MOVWF 7A
7444 0F57: BCF 78.7
7445 0F58: MOVF 56,W
7446 0F59: MOVWF 56
7447 0F5A: MOVF 55,W
7448 0F5B: MOVWF 55
7449 0F5C: MOVF 78,W
7450 0F5D: MOVWF 54
7451 0F5E: MOVF 53,W
7452 0F5F: MOVWF 53
7453 ....................
7454 ....................
7455 ....................
7456 ....................
7457 .................... if(X==0) //osetreni proti deleni 0
7458 0F60: MOVF 27,F
7459 0F61: BTFSS 03.2
7460 0F62: GOTO 77D
7461 0F63: MOVF 28,F
7462 0F64: BTFSS 03.2
7463 0F65: GOTO 77D
7464 .................... {
7465 .................... if(Y>0)
7466 0F66: BTFSC 2A.7
7467 0F67: GOTO 776
7468 0F68: MOVF 2A,F
7469 0F69: BTFSS 03.2
7470 0F6A: GOTO 76F
7471 0F6B: MOVF 29,W
7472 0F6C: SUBLW 00
7473 0F6D: BTFSC 03.0
7474 0F6E: GOTO 776
7475 .................... {
7476 .................... b=90;
7477 0F6F: CLRF 56
7478 0F70: CLRF 55
7479 0F71: MOVLW 34
7480 0F72: MOVWF 54
7481 0F73: MOVLW 85
7482 0F74: MOVWF 53
7483 .................... }
7484 .................... else
7485 0F75: GOTO 77C
7486 .................... {
7487 .................... b=270;
7488 0F76: CLRF 56
7489 0F77: CLRF 55
7490 0F78: MOVLW 07
7491 0F79: MOVWF 54
7492 0F7A: MOVLW 87
7493 0F7B: MOVWF 53
7494 .................... }
7495 .................... }
7496 .................... else
7497 0F7C: GOTO 7D4
7498 .................... {
7499 .................... if(X>0)
7500 0F7D: BTFSC 28.7
7501 0F7E: GOTO 7A1
7502 0F7F: MOVF 28,F
7503 0F80: BTFSS 03.2
7504 0F81: GOTO 786
7505 0F82: MOVF 27,W
7506 0F83: SUBLW 00
7507 0F84: BTFSC 03.0
7508 0F85: GOTO 7A1
7509 .................... {
7510 .................... if(Y>=0)
7511 0F86: BTFSS 2A.7
7512 .................... {
7513 .................... b=b;
7514 .................... }
7515 .................... else
7516 0F87: GOTO 7A0
7517 .................... {
7518 .................... b=360-b;
7519 0F88: BSF 03.1
7520 0F89: CLRF 6F
7521 0F8A: CLRF 6E
7522 0F8B: MOVLW 34
7523 0F8C: MOVWF 6D
7524 0F8D: MOVLW 87
7525 0F8E: MOVWF 6C
7526 0F8F: MOVF 56,W
7527 0F90: MOVWF 73
7528 0F91: MOVF 55,W
7529 0F92: MOVWF 72
7530 0F93: MOVF 54,W
7531 0F94: MOVWF 71
7532 0F95: MOVF 53,W
7533 0F96: MOVWF 70
7534 0F97: CALL 000
7535 0F98: MOVF 7A,W
7536 0F99: MOVWF 56
7537 0F9A: MOVF 79,W
7538 0F9B: MOVWF 55
7539 0F9C: MOVF 78,W
7540 0F9D: MOVWF 54
7541 0F9E: MOVF 77,W
7542 0F9F: MOVWF 53
7543 .................... }
7544 .................... }
7545 .................... else
7546 0FA0: GOTO 7D4
7547 .................... {
7548 .................... if(Y>=0)
7549 0FA1: BTFSC 2A.7
7550 0FA2: GOTO 7BC
7551 .................... {
7552 .................... b=180-b;
7553 0FA3: BSF 03.1
7554 0FA4: CLRF 6F
7555 0FA5: CLRF 6E
7556 0FA6: MOVLW 34
7557 0FA7: MOVWF 6D
7558 0FA8: MOVLW 86
7559 0FA9: MOVWF 6C
7560 0FAA: MOVF 56,W
7561 0FAB: MOVWF 73
7562 0FAC: MOVF 55,W
7563 0FAD: MOVWF 72
7564 0FAE: MOVF 54,W
7565 0FAF: MOVWF 71
7566 0FB0: MOVF 53,W
7567 0FB1: MOVWF 70
7568 0FB2: CALL 000
7569 0FB3: MOVF 7A,W
7570 0FB4: MOVWF 56
7571 0FB5: MOVF 79,W
7572 0FB6: MOVWF 55
7573 0FB7: MOVF 78,W
7574 0FB8: MOVWF 54
7575 0FB9: MOVF 77,W
7576 0FBA: MOVWF 53
7577 .................... }
7578 .................... else
7579 0FBB: GOTO 7D4
7580 .................... {
7581 .................... b=180+b;
7582 0FBC: BCF 03.1
7583 0FBD: CLRF 6F
7584 0FBE: CLRF 6E
7585 0FBF: MOVLW 34
7586 0FC0: MOVWF 6D
7587 0FC1: MOVLW 86
7588 0FC2: MOVWF 6C
7589 0FC3: MOVF 56,W
7590 0FC4: MOVWF 73
7591 0FC5: MOVF 55,W
7592 0FC6: MOVWF 72
7593 0FC7: MOVF 54,W
7594 0FC8: MOVWF 71
7595 0FC9: MOVF 53,W
7596 0FCA: MOVWF 70
7597 0FCB: CALL 000
7598 0FCC: MOVF 7A,W
7599 0FCD: MOVWF 56
7600 0FCE: MOVF 79,W
7601 0FCF: MOVWF 55
7602 0FD0: MOVF 78,W
7603 0FD1: MOVWF 54
7604 0FD2: MOVF 77,W
7605 0FD3: MOVWF 53
7606 .................... }
7607 .................... }
7608 ....................
7609 .................... }
7610 ....................
7611 ....................
7612 .................... if(b>355)
7613 0FD4: CLRF 6B
7614 0FD5: MOVLW 80
7615 0FD6: MOVWF 6A
7616 0FD7: MOVLW 31
7617 0FD8: MOVWF 69
7618 0FD9: MOVLW 87
7619 0FDA: MOVWF 68
7620 0FDB: MOVF 56,W
7621 0FDC: MOVWF 6F
7622 0FDD: MOVF 55,W
7623 0FDE: MOVWF 6E
7624 0FDF: MOVF 54,W
7625 0FE0: MOVWF 6D
7626 0FE1: MOVF 53,W
7627 0FE2: MOVWF 6C
7628 0FE3: BCF 0A.3
7629 0FE4: CALL 5E7
7630 0FE5: BSF 0A.3
7631 0FE6: BTFSS 03.0
7632 0FE7: GOTO 7ED
7633 .................... {
7634 .................... b=0;
7635 0FE8: CLRF 56
7636 0FE9: CLRF 55
7637 0FEA: CLRF 54
7638 0FEB: CLRF 53
7639 .................... }
7640 .................... else
7641 0FEC: GOTO 7ED
7642 .................... {
7643 ....................
7644 .................... }
7645 ....................
7646 .................... return b;
7647 0FED: MOVF 53,W
7648 0FEE: MOVWF 77
7649 0FEF: MOVF 54,W
7650 0FF0: MOVWF 78
7651 0FF1: MOVF 55,W
7652 0FF2: MOVWF 79
7653 0FF3: MOVF 56,W
7654 0FF4: MOVWF 7A
7655 ....................
7656 .................... }
7657 0FF5: RETURN
7658 ....................
7659 .................... void motorA (int8 H) //pro ovladani prvniho motoru nastaveni vysky
7660 .................... {
7661 .................... switch(H){
7662 *
7663 0092: MOVF 4F,W
7664 0093: XORLW 01
7665 0094: BTFSC 03.2
7666 0095: GOTO 09A
7667 0096: XORLW 03
7668 0097: BTFSC 03.2
7669 0098: GOTO 0A3
7670 0099: GOTO 0AC
7671 .................... case 1: //reverzní chod
7672 .................... output_low (AIN2);
7673 009A: BSF 03.5
7674 009B: BCF 08.1
7675 009C: BCF 03.5
7676 009D: BCF 08.1
7677 .................... output_high (AIN1);
7678 009E: BSF 03.5
7679 009F: BCF 08.0
7680 00A0: BCF 03.5
7681 00A1: BSF 08.0
7682 .................... break;
7683 00A2: GOTO 0B4
7684 ....................
7685 .................... case 2: //dopøedu
7686 .................... output_low (AIN1);
7687 00A3: BSF 03.5
7688 00A4: BCF 08.0
7689 00A5: BCF 03.5
7690 00A6: BCF 08.0
7691 .................... output_high (AIN2);
7692 00A7: BSF 03.5
7693 00A8: BCF 08.1
7694 00A9: BCF 03.5
7695 00AA: BSF 08.1
7696 .................... break;
7697 00AB: GOTO 0B4
7698 ....................
7699 .................... default:
7700 .................... output_low (AIN2);
7701 00AC: BSF 03.5
7702 00AD: BCF 08.1
7703 00AE: BCF 03.5
7704 00AF: BCF 08.1
7705 .................... output_low (AIN1);
7706 00B0: BSF 03.5
7707 00B1: BCF 08.0
7708 00B2: BCF 03.5
7709 00B3: BCF 08.0
7710 .................... }
7711 .................... }
7712 00B4: RETURN
7713 ....................
7714 .................... void motorB (int8 H) //pro ovladani prvniho motoru nastaveni vysky
7715 .................... {
7716 .................... switch(H){
7717 00B5: MOVF 4F,W
7718 00B6: XORLW 01
7719 00B7: BTFSC 03.2
7720 00B8: GOTO 0BD
7721 00B9: XORLW 03
7722 00BA: BTFSC 03.2
7723 00BB: GOTO 0C6
7724 00BC: GOTO 0CF
7725 .................... case 1: //reverzní chod
7726 .................... output_low (BIN2);
7727 00BD: BSF 03.5
7728 00BE: BCF 08.3
7729 00BF: BCF 03.5
7730 00C0: BCF 08.3
7731 .................... output_high (BIN1);
7732 00C1: BSF 03.5
7733 00C2: BCF 08.2
7734 00C3: BCF 03.5
7735 00C4: BSF 08.2
7736 .................... break;
7737 00C5: GOTO 0D7
7738 ....................
7739 .................... case 2: //dopøedu
7740 .................... output_low (BIN1);
7741 00C6: BSF 03.5
7742 00C7: BCF 08.2
7743 00C8: BCF 03.5
7744 00C9: BCF 08.2
7745 .................... output_high (BIN2);
7746 00CA: BSF 03.5
7747 00CB: BCF 08.3
7748 00CC: BCF 03.5
7749 00CD: BSF 08.3
7750 .................... break;
7751 00CE: GOTO 0D7
7752 ....................
7753 .................... default:
7754 .................... output_low (BIN2);
7755 00CF: BSF 03.5
7756 00D0: BCF 08.3
7757 00D1: BCF 03.5
7758 00D2: BCF 08.3
7759 .................... output_low (BIN1);
7760 00D3: BSF 03.5
7761 00D4: BCF 08.2
7762 00D5: BCF 03.5
7763 00D6: BCF 08.2
7764 .................... }
7765 .................... }
7766 00D7: RETURN
7767 ....................
7768 .................... void elevace_set (int16 H) //slouzi pro nastaveni nove vysky panelu
7769 .................... {
7770 .................... //printf("Akcelerometr4: \r\n",);
7771 .................... float a;
7772 .................... int16 b,c;
7773 ....................
7774 ....................
7775 ....................
7776 ....................
7777 ....................
7778 ....................
7779 ....................
7780 .................... a=elevace();
7781 *
7782 06D8: BSF 0A.3
7783 06D9: CALL 3DD
7784 06DA: BCF 0A.3
7785 06DB: MOVF 7A,W
7786 06DC: MOVWF 4A
7787 06DD: MOVF 79,W
7788 06DE: MOVWF 49
7789 06DF: MOVF 78,W
7790 06E0: MOVWF 48
7791 06E1: MOVF 77,W
7792 06E2: MOVWF 47
7793 .................... b= (int16) a;
7794 06E3: MOVF 4A,W
7795 06E4: MOVWF 52
7796 06E5: MOVF 49,W
7797 06E6: MOVWF 51
7798 06E7: MOVF 48,W
7799 06E8: MOVWF 50
7800 06E9: MOVF 47,W
7801 06EA: MOVWF 4F
7802 06EB: CALL 6B9
7803 06EC: MOVF 79,W
7804 06ED: MOVWF 4C
7805 06EE: MOVF 78,W
7806 06EF: MOVWF 4B
7807 .................... c=abs(H-b);
7808 06F0: MOVF 4B,W
7809 06F1: SUBWF 45,W
7810 06F2: MOVWF 4F
7811 06F3: MOVF 46,W
7812 06F4: MOVWF 50
7813 06F5: MOVF 4C,W
7814 06F6: BTFSS 03.0
7815 06F7: INCFSZ 4C,W
7816 06F8: SUBWF 50,F
7817 06F9: MOVF 50,W
7818 06FA: MOVWF 4E
7819 06FB: MOVF 4F,W
7820 06FC: MOVWF 4D
7821 ....................
7822 .................... while(c>2) //maximalni odchylka uhlu, aby nebylo potreba panelem hybat
7823 .................... {
7824 06FD: MOVF 4E,F
7825 06FE: BTFSS 03.2
7826 06FF: GOTO 704
7827 0700: MOVF 4D,W
7828 0701: SUBLW 02
7829 0702: BTFSC 03.0
7830 0703: GOTO 74D
7831 .................... while(H!=b) //probiha dokud se uhel panelu nerovna zadanemu na cele stupne
7832 .................... {
7833 0704: MOVF 4B,W
7834 0705: SUBWF 45,W
7835 0706: BTFSS 03.2
7836 0707: GOTO 70C
7837 0708: MOVF 4C,W
7838 0709: SUBWF 46,W
7839 070A: BTFSC 03.2
7840 070B: GOTO 74C
7841 ....................
7842 .................... if(H>b)
7843 070C: MOVF 4C,W
7844 070D: SUBWF 46,W
7845 070E: BTFSS 03.0
7846 070F: GOTO 71A
7847 0710: BTFSS 03.2
7848 0711: GOTO 716
7849 0712: MOVF 45,W
7850 0713: SUBWF 4B,W
7851 0714: BTFSC 03.0
7852 0715: GOTO 71A
7853 .................... {
7854 .................... motorA(2);
7855 0716: MOVLW 02
7856 0717: MOVWF 4F
7857 0718: CALL 092
7858 ....................
7859 .................... }
7860 .................... else
7861 0719: GOTO 71D
7862 .................... {
7863 .................... motorA(1);
7864 071A: MOVLW 01
7865 071B: MOVWF 4F
7866 071C: CALL 092
7867 .................... }
7868 ....................
7869 .................... delay_ms (50); //cas sepnuti motoru
7870 071D: MOVLW 32
7871 071E: MOVWF 4F
7872 071F: CALL 15D
7873 ....................
7874 .................... motorA(3); //vypne motor
7875 0720: MOVLW 03
7876 0721: MOVWF 4F
7877 0722: CALL 092
7878 .................... delay_ms (50); //doma na ustaleni panelu pred merenim
7879 0723: MOVLW 32
7880 0724: MOVWF 4F
7881 0725: CALL 15D
7882 .................... a=elevace();
7883 0726: BSF 0A.3
7884 0727: CALL 3DD
7885 0728: BCF 0A.3
7886 0729: MOVF 7A,W
7887 072A: MOVWF 4A
7888 072B: MOVF 79,W
7889 072C: MOVWF 49
7890 072D: MOVF 78,W
7891 072E: MOVWF 48
7892 072F: MOVF 77,W
7893 0730: MOVWF 47
7894 .................... b= (int16) a;
7895 0731: MOVF 4A,W
7896 0732: MOVWF 52
7897 0733: MOVF 49,W
7898 0734: MOVWF 51
7899 0735: MOVF 48,W
7900 0736: MOVWF 50
7901 0737: MOVF 47,W
7902 0738: MOVWF 4F
7903 0739: CALL 6B9
7904 073A: MOVF 79,W
7905 073B: MOVWF 4C
7906 073C: MOVF 78,W
7907 073D: MOVWF 4B
7908 ....................
7909 ....................
7910 .................... c=abs(H-b);
7911 073E: MOVF 4B,W
7912 073F: SUBWF 45,W
7913 0740: MOVWF 4F
7914 0741: MOVF 46,W
7915 0742: MOVWF 50
7916 0743: MOVF 4C,W
7917 0744: BTFSS 03.0
7918 0745: INCFSZ 4C,W
7919 0746: SUBWF 50,F
7920 0747: MOVF 50,W
7921 0748: MOVWF 4E
7922 0749: MOVF 4F,W
7923 074A: MOVWF 4D
7924 .................... }
7925 074B: GOTO 704
7926 .................... }
7927 074C: GOTO 6FD
7928 .................... motorA(3); //vypne motor
7929 074D: MOVLW 03
7930 074E: MOVWF 4F
7931 074F: CALL 092
7932 .................... printf("Podaøené nastavení výška: %Ld\r\n", b);
7933 0750: MOVLW 18
7934 0751: BSF 03.6
7935 0752: MOVWF 0D
7936 0753: MOVLW 00
7937 0754: MOVWF 0F
7938 0755: MOVLW 1A
7939 0756: BCF 03.6
7940 0757: MOVWF 4F
7941 0758: CALL 2EE
7942 0759: MOVLW 10
7943 075A: MOVWF 04
7944 075B: MOVF 4C,W
7945 075C: MOVWF 50
7946 075D: MOVF 4B,W
7947 075E: MOVWF 4F
7948 075F: CALL 30F
7949 0760: MOVLW 0D
7950 0761: MOVWF 59
7951 0762: CALL 222
7952 0763: MOVLW 0A
7953 0764: MOVWF 59
7954 0765: CALL 222
7955 ....................
7956 ....................
7957 .................... }
7958 0766: BCF 0A.3
7959 0767: BSF 0A.4
7960 0768: GOTO 254 (RETURN)
7961 ....................
7962 ....................
7963 ....................
7964 .................... void azimut_set (int16 H) //slouzi pro nastaveni nove vysky panelu
7965 .................... {
7966 .................... float a;
7967 .................... int16 b,c;
7968 ....................
7969 ....................
7970 .................... a=azimut();
7971 *
7972 1000: BCF 0A.4
7973 1001: BSF 0A.3
7974 1002: CALL 68C
7975 1003: BSF 0A.4
7976 1004: BCF 0A.3
7977 1005: MOVF 7A,W
7978 1006: MOVWF 4A
7979 1007: MOVF 79,W
7980 1008: MOVWF 49
7981 1009: MOVF 78,W
7982 100A: MOVWF 48
7983 100B: MOVF 77,W
7984 100C: MOVWF 47
7985 .................... b= (int16) a;
7986 100D: MOVF 4A,W
7987 100E: MOVWF 52
7988 100F: MOVF 49,W
7989 1010: MOVWF 51
7990 1011: MOVF 48,W
7991 1012: MOVWF 50
7992 1013: MOVF 47,W
7993 1014: MOVWF 4F
7994 1015: BCF 0A.4
7995 1016: CALL 6B9
7996 1017: BSF 0A.4
7997 1018: MOVF 79,W
7998 1019: MOVWF 4C
7999 101A: MOVF 78,W
8000 101B: MOVWF 4B
8001 .................... c=abs(H-b);
8002 101C: MOVF 4B,W
8003 101D: SUBWF 45,W
8004 101E: MOVWF 4F
8005 101F: MOVF 46,W
8006 1020: MOVWF 50
8007 1021: MOVF 4C,W
8008 1022: BTFSS 03.0
8009 1023: INCFSZ 4C,W
8010 1024: SUBWF 50,F
8011 1025: MOVF 50,W
8012 1026: MOVWF 4E
8013 1027: MOVF 4F,W
8014 1028: MOVWF 4D
8015 ....................
8016 .................... while(c>2) //maximalni odchylka uhlu, aby nebylo potreba panelem hybat
8017 .................... {
8018 1029: MOVF 4E,F
8019 102A: BTFSS 03.2
8020 102B: GOTO 030
8021 102C: MOVF 4D,W
8022 102D: SUBLW 02
8023 102E: BTFSC 03.0
8024 102F: GOTO 087
8025 .................... while(H!=b) //probiha dokud se uhel panelu nerovna zadanemu na cele stupne
8026 .................... {
8027 1030: MOVF 4B,W
8028 1031: SUBWF 45,W
8029 1032: BTFSS 03.2
8030 1033: GOTO 038
8031 1034: MOVF 4C,W
8032 1035: SUBWF 46,W
8033 1036: BTFSC 03.2
8034 1037: GOTO 086
8035 ....................
8036 .................... if(H>b)
8037 1038: MOVF 4C,W
8038 1039: SUBWF 46,W
8039 103A: BTFSS 03.0
8040 103B: GOTO 048
8041 103C: BTFSS 03.2
8042 103D: GOTO 042
8043 103E: MOVF 45,W
8044 103F: SUBWF 4B,W
8045 1040: BTFSC 03.0
8046 1041: GOTO 048
8047 .................... {
8048 .................... motorB(2);
8049 1042: MOVLW 02
8050 1043: MOVWF 4F
8051 1044: BCF 0A.4
8052 1045: CALL 0B5
8053 1046: BSF 0A.4
8054 ....................
8055 .................... }
8056 .................... else
8057 1047: GOTO 04D
8058 .................... {
8059 .................... motorB(1);
8060 1048: MOVLW 01
8061 1049: MOVWF 4F
8062 104A: BCF 0A.4
8063 104B: CALL 0B5
8064 104C: BSF 0A.4
8065 .................... }
8066 ....................
8067 .................... delay_ms (50); //cas sepnuti motoru
8068 104D: MOVLW 32
8069 104E: MOVWF 4F
8070 104F: BCF 0A.4
8071 1050: CALL 15D
8072 1051: BSF 0A.4
8073 ....................
8074 .................... motorB(3); //vypne motor
8075 1052: MOVLW 03
8076 1053: MOVWF 4F
8077 1054: BCF 0A.4
8078 1055: CALL 0B5
8079 1056: BSF 0A.4
8080 .................... delay_ms (50); //doma na ustaleni panelu pred merenim
8081 1057: MOVLW 32
8082 1058: MOVWF 4F
8083 1059: BCF 0A.4
8084 105A: CALL 15D
8085 105B: BSF 0A.4
8086 .................... a=azimut();
8087 105C: BCF 0A.4
8088 105D: BSF 0A.3
8089 105E: CALL 68C
8090 105F: BSF 0A.4
8091 1060: BCF 0A.3
8092 1061: MOVF 7A,W
8093 1062: MOVWF 4A
8094 1063: MOVF 79,W
8095 1064: MOVWF 49
8096 1065: MOVF 78,W
8097 1066: MOVWF 48
8098 1067: MOVF 77,W
8099 1068: MOVWF 47
8100 .................... b= (int16) a;
8101 1069: MOVF 4A,W
8102 106A: MOVWF 52
8103 106B: MOVF 49,W
8104 106C: MOVWF 51
8105 106D: MOVF 48,W
8106 106E: MOVWF 50
8107 106F: MOVF 47,W
8108 1070: MOVWF 4F
8109 1071: BCF 0A.4
8110 1072: CALL 6B9
8111 1073: BSF 0A.4
8112 1074: MOVF 79,W
8113 1075: MOVWF 4C
8114 1076: MOVF 78,W
8115 1077: MOVWF 4B
8116 ....................
8117 .................... c=abs(H-b);
8118 1078: MOVF 4B,W
8119 1079: SUBWF 45,W
8120 107A: MOVWF 4F
8121 107B: MOVF 46,W
8122 107C: MOVWF 50
8123 107D: MOVF 4C,W
8124 107E: BTFSS 03.0
8125 107F: INCFSZ 4C,W
8126 1080: SUBWF 50,F
8127 1081: MOVF 50,W
8128 1082: MOVWF 4E
8129 1083: MOVF 4F,W
8130 1084: MOVWF 4D
8131 .................... }
8132 1085: GOTO 030
8133 .................... }
8134 1086: GOTO 029
8135 .................... motorA(3); //vypne motor
8136 1087: MOVLW 03
8137 1088: MOVWF 4F
8138 1089: BCF 0A.4
8139 108A: CALL 092
8140 108B: BSF 0A.4
8141 .................... printf("Podaøené nastavení azimut: %Ld\r\n", b);
8142 108C: MOVLW 38
8143 108D: BSF 03.6
8144 108E: MOVWF 0D
8145 108F: MOVLW 00
8146 1090: MOVWF 0F
8147 1091: MOVLW 1B
8148 1092: BCF 03.6
8149 1093: MOVWF 4F
8150 1094: BCF 0A.4
8151 1095: CALL 2EE
8152 1096: BSF 0A.4
8153 1097: MOVLW 10
8154 1098: MOVWF 04
8155 1099: MOVF 4C,W
8156 109A: MOVWF 50
8157 109B: MOVF 4B,W
8158 109C: MOVWF 4F
8159 109D: BCF 0A.4
8160 109E: CALL 30F
8161 109F: BSF 0A.4
8162 10A0: MOVLW 0D
8163 10A1: MOVWF 59
8164 10A2: BCF 0A.4
8165 10A3: CALL 222
8166 10A4: BSF 0A.4
8167 10A5: MOVLW 0A
8168 10A6: MOVWF 59
8169 10A7: BCF 0A.4
8170 10A8: CALL 222
8171 10A9: BSF 0A.4
8172 ....................
8173 ....................
8174 ....................
8175 .................... }
8176 10AA: BCF 0A.3
8177 10AB: BSF 0A.4
8178 10AC: GOTO 25A (RETURN)
8179 ....................
8180 .................... void main()
8181 .................... {
8182 10AD: CLRF 04
8183 10AE: BCF 03.7
8184 10AF: MOVLW 1F
8185 10B0: ANDWF 03,F
8186 10B1: MOVLW 71
8187 10B2: BSF 03.5
8188 10B3: MOVWF 0F
8189 10B4: MOVF 0F,W
8190 10B5: BCF 03.5
8191 10B6: BCF 20.7
8192 10B7: MOVF 20,W
8193 10B8: BSF 03.5
8194 10B9: MOVWF 07
8195 10BA: BCF 03.5
8196 10BB: BSF 07.7
8197 10BC: BSF 03.5
8198 10BD: BSF 03.6
8199 10BE: MOVF 09,W
8200 10BF: ANDLW C0
8201 10C0: MOVWF 09
8202 10C1: BCF 03.6
8203 10C2: BCF 1F.4
8204 10C3: BCF 1F.5
8205 10C4: MOVLW 00
8206 10C5: BSF 03.6
8207 10C6: MOVWF 08
8208 10C7: BCF 03.5
8209 10C8: CLRF 07
8210 10C9: CLRF 08
8211 10CA: CLRF 09
8212 .................... setup_adc_ports(NO_ANALOGS|VSS_VDD);
8213 *
8214 10D0: BSF 03.5
8215 10D1: BSF 03.6
8216 10D2: MOVF 09,W
8217 10D3: ANDLW C0
8218 10D4: MOVWF 09
8219 10D5: BCF 03.6
8220 10D6: BCF 1F.4
8221 10D7: BCF 1F.5
8222 10D8: MOVLW 00
8223 10D9: BSF 03.6
8224 10DA: MOVWF 08
8225 .................... setup_adc(ADC_CLOCK_DIV_2);
8226 10DB: BCF 03.5
8227 10DC: BCF 03.6
8228 10DD: BCF 1F.6
8229 10DE: BCF 1F.7
8230 10DF: BSF 03.5
8231 10E0: BCF 1F.7
8232 10E1: BCF 03.5
8233 10E2: BSF 1F.0
8234 .................... setup_spi(SPI_SS_DISABLED);
8235 10E3: BCF 14.5
8236 10E4: BCF 20.5
8237 10E5: MOVF 20,W
8238 10E6: BSF 03.5
8239 10E7: MOVWF 07
8240 10E8: BCF 03.5
8241 10E9: BSF 20.4
8242 10EA: MOVF 20,W
8243 10EB: BSF 03.5
8244 10EC: MOVWF 07
8245 10ED: BCF 03.5
8246 10EE: BCF 20.3
8247 10EF: MOVF 20,W
8248 10F0: BSF 03.5
8249 10F1: MOVWF 07
8250 10F2: MOVLW 01
8251 10F3: BCF 03.5
8252 10F4: MOVWF 14
8253 10F5: MOVLW 00
8254 10F6: BSF 03.5
8255 10F7: MOVWF 14
8256 .................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
8257 10F8: MOVF 01,W
8258 10F9: ANDLW C7
8259 10FA: IORLW 08
8260 10FB: MOVWF 01
8261 .................... setup_timer_1(T1_DISABLED);
8262 10FC: BCF 03.5
8263 10FD: CLRF 10
8264 .................... setup_timer_2(T2_DISABLED,0,1);
8265 10FE: MOVLW 00
8266 10FF: MOVWF 78
8267 1100: MOVWF 12
8268 1101: MOVLW 00
8269 1102: BSF 03.5
8270 1103: MOVWF 12
8271 .................... setup_ccp1(CCP_OFF);
8272 1104: BCF 03.5
8273 1105: BSF 20.2
8274 1106: MOVF 20,W
8275 1107: BSF 03.5
8276 1108: MOVWF 07
8277 1109: BCF 03.5
8278 110A: CLRF 17
8279 110B: BSF 03.5
8280 110C: CLRF 1B
8281 110D: CLRF 1C
8282 110E: MOVLW 01
8283 110F: MOVWF 1D
8284 .................... setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
8285 1110: BCF 03.5
8286 1111: BSF 03.6
8287 1112: CLRF 07
8288 1113: CLRF 08
8289 1114: CLRF 09
8290 ....................
8291 .................... //setup_adc_ports(PIN_A0); //piny pro A/D RA0
8292 .................... //setup_adc_ports(PIN_A1); //piny pro A/D RA1
8293 ....................
8294 .................... motorA(3); //vyponuti motorù
8295 1115: MOVLW 03
8296 1116: BCF 03.6
8297 1117: MOVWF 4F
8298 1118: BCF 0A.4
8299 1119: CALL 092
8300 111A: BSF 0A.4
8301 .................... motorB(3);
8302 111B: MOVLW 03
8303 111C: MOVWF 4F
8304 111D: BCF 0A.4
8305 111E: CALL 0B5
8306 111F: BSF 0A.4
8307 ....................
8308 .................... setAK(); //nastaveni akcelerometru
8309 1120: BCF 0A.4
8310 1121: GOTO 122
8311 1122: BSF 0A.4
8312 .................... setmag();
8313 1123: BCF 0A.4
8314 1124: GOTO 171
8315 1125: BSF 0A.4
8316 .................... printf("System nataceni panelu \r\n",);
8317 1126: MOVLW 59
8318 1127: BSF 03.6
8319 1128: MOVWF 0D
8320 1129: MOVLW 00
8321 112A: MOVWF 0F
8322 112B: BCF 0A.4
8323 112C: BCF 03.6
8324 112D: GOTO 246
8325 112E: BSF 0A.4
8326 .................... while(TRUE)
8327 .................... {
8328 .................... int i[10];
8329 .................... int16 vysledek;
8330 .................... int b=0;
8331 .................... int c;
8332 112F: CLRF 43
8333 .................... do {
8334 .................... b++;
8335 1130: INCF 43,F
8336 .................... i[b] = getchar();
8337 1131: MOVLW 37
8338 1132: ADDWF 43,W
8339 1133: MOVWF 04
8340 1134: BCF 03.7
8341 1135: CLRF 48
8342 1136: MOVF 04,W
8343 1137: MOVWF 47
8344 1138: BCF 48.0
8345 1139: BTFSC 03.7
8346 113A: BSF 48.0
8347 113B: BCF 0A.4
8348 113C: CALL 28E
8349 113D: BSF 0A.4
8350 113E: MOVF 47,W
8351 113F: MOVWF 04
8352 1140: BCF 03.7
8353 1141: BTFSC 48.0
8354 1142: BSF 03.7
8355 1143: MOVF 78,W
8356 1144: MOVWF 00
8357 ....................
8358 .................... // printf("zadaný azimut %d \r\n", i[b]);
8359 ....................
8360 .................... } while (i[b] != ' ');
8361 1145: MOVLW 37
8362 1146: ADDWF 43,W
8363 1147: MOVWF 04
8364 1148: BCF 03.7
8365 1149: MOVF 00,W
8366 114A: SUBLW 20
8367 114B: BTFSS 03.2
8368 114C: GOTO 130
8369 .................... b=b-1;
8370 114D: MOVLW 01
8371 114E: SUBWF 43,F
8372 ....................
8373 .................... switch(b){
8374 114F: MOVF 43,W
8375 1150: XORLW 01
8376 1151: BTFSC 03.2
8377 1152: GOTO 15A
8378 1153: XORLW 03
8379 1154: BTFSC 03.2
8380 1155: GOTO 15F
8381 1156: XORLW 01
8382 1157: BTFSC 03.2
8383 1158: GOTO 170
8384 1159: GOTO 199
8385 .................... case 1: //reverzní chod
8386 .................... elevaceZAD=i[1]-48;
8387 115A: MOVLW 30
8388 115B: SUBWF 38,W
8389 115C: MOVWF 35
8390 115D: CLRF 36
8391 .................... break;
8392 115E: GOTO 199
8393 ....................
8394 .................... case 2: //dopøedu
8395 .................... elevaceZAD=(i[2]-48)+(i[1]-48)*10;
8396 115F: MOVLW 30
8397 1160: SUBWF 39,W
8398 1161: MOVWF 45
8399 1162: MOVLW 30
8400 1163: SUBWF 38,W
8401 1164: MOVWF 47
8402 1165: MOVWF 48
8403 1166: MOVLW 0A
8404 1167: MOVWF 49
8405 1168: BCF 0A.4
8406 1169: CALL 2B4
8407 116A: BSF 0A.4
8408 116B: MOVF 78,W
8409 116C: ADDWF 45,W
8410 116D: MOVWF 35
8411 116E: CLRF 36
8412 .................... break;
8413 116F: GOTO 199
8414 .................... case 3: //dopøedu
8415 .................... elevaceZAD=(i[3]-48)+(i[2]-48)*10+((int16)i[1]-48)*100;
8416 1170: MOVLW 30
8417 1171: SUBWF 3A,W
8418 1172: MOVWF 45
8419 1173: MOVLW 30
8420 1174: SUBWF 39,W
8421 1175: MOVWF 47
8422 1176: MOVWF 48
8423 1177: MOVLW 0A
8424 1178: MOVWF 49
8425 1179: BCF 0A.4
8426 117A: CALL 2B4
8427 117B: BSF 0A.4
8428 117C: MOVF 78,W
8429 117D: ADDWF 45,F
8430 117E: CLRF 47
8431 117F: MOVF 38,W
8432 1180: MOVWF 46
8433 1181: MOVLW 30
8434 1182: SUBWF 46,F
8435 1183: MOVLW 00
8436 1184: BTFSS 03.0
8437 1185: MOVLW 01
8438 1186: SUBWF 47,F
8439 1187: MOVF 47,W
8440 1188: MOVWF 49
8441 1189: MOVF 46,W
8442 118A: MOVWF 48
8443 118B: CLRF 4B
8444 118C: MOVLW 64
8445 118D: MOVWF 4A
8446 118E: BCF 0A.4
8447 118F: CALL 2D9
8448 1190: BSF 0A.4
8449 1191: MOVF 78,W
8450 1192: ADDWF 45,W
8451 1193: MOVWF 35
8452 1194: MOVF 79,W
8453 1195: MOVWF 36
8454 1196: BTFSC 03.0
8455 1197: INCF 36,F
8456 .................... break;
8457 1198: GOTO 199
8458 ....................
8459 .................... default:
8460 ....................
8461 .................... }
8462 .................... printf("Zadaná elevace %Ld \r\n", elevaceZAD);
8463 1199: MOVLW 67
8464 119A: BSF 03.6
8465 119B: MOVWF 0D
8466 119C: MOVLW 00
8467 119D: MOVWF 0F
8468 119E: MOVLW 0F
8469 119F: BCF 03.6
8470 11A0: MOVWF 4F
8471 11A1: BCF 0A.4
8472 11A2: CALL 2EE
8473 11A3: BSF 0A.4
8474 11A4: MOVLW 10
8475 11A5: MOVWF 04
8476 11A6: MOVF 36,W
8477 11A7: MOVWF 50
8478 11A8: MOVF 35,W
8479 11A9: MOVWF 4F
8480 11AA: BCF 0A.4
8481 11AB: CALL 30F
8482 11AC: BSF 0A.4
8483 11AD: MOVLW 20
8484 11AE: MOVWF 59
8485 11AF: BCF 0A.4
8486 11B0: CALL 222
8487 11B1: BSF 0A.4
8488 11B2: MOVLW 0D
8489 11B3: MOVWF 59
8490 11B4: BCF 0A.4
8491 11B5: CALL 222
8492 11B6: BSF 0A.4
8493 11B7: MOVLW 0A
8494 11B8: MOVWF 59
8495 11B9: BCF 0A.4
8496 11BA: CALL 222
8497 11BB: BSF 0A.4
8498 ....................
8499 .................... i=0;
8500 11BC: CLRF 38
8501 11BD: CLRF 37
8502 .................... vysledek=0;
8503 11BE: CLRF 42
8504 11BF: CLRF 41
8505 .................... b=0;
8506 11C0: CLRF 43
8507 .................... c=0;
8508 11C1: CLRF 44
8509 .................... do {
8510 .................... b++;
8511 11C2: INCF 43,F
8512 .................... i[b] = getchar();
8513 11C3: MOVLW 37
8514 11C4: ADDWF 43,W
8515 11C5: MOVWF 04
8516 11C6: BCF 03.7
8517 11C7: CLRF 48
8518 11C8: MOVF 04,W
8519 11C9: MOVWF 47
8520 11CA: BCF 48.0
8521 11CB: BTFSC 03.7
8522 11CC: BSF 48.0
8523 11CD: BCF 0A.4
8524 11CE: CALL 28E
8525 11CF: BSF 0A.4
8526 11D0: MOVF 47,W
8527 11D1: MOVWF 04
8528 11D2: BCF 03.7
8529 11D3: BTFSC 48.0
8530 11D4: BSF 03.7
8531 11D5: MOVF 78,W
8532 11D6: MOVWF 00
8533 ....................
8534 .................... //printf("Zadaný azimut %d \r\n", i[b]);
8535 ....................
8536 .................... } while (i[b] != ' ');
8537 11D7: MOVLW 37
8538 11D8: ADDWF 43,W
8539 11D9: MOVWF 04
8540 11DA: BCF 03.7
8541 11DB: MOVF 00,W
8542 11DC: SUBLW 20
8543 11DD: BTFSS 03.2
8544 11DE: GOTO 1C2
8545 .................... b=b-1;
8546 11DF: MOVLW 01
8547 11E0: SUBWF 43,F
8548 ....................
8549 .................... switch(b){
8550 11E1: MOVF 43,W
8551 11E2: XORLW 01
8552 11E3: BTFSC 03.2
8553 11E4: GOTO 1EC
8554 11E5: XORLW 03
8555 11E6: BTFSC 03.2
8556 11E7: GOTO 1F1
8557 11E8: XORLW 01
8558 11E9: BTFSC 03.2
8559 11EA: GOTO 202
8560 11EB: GOTO 22B
8561 .................... case 1: //reverzní chod
8562 .................... azimutZAD=i[1]-48;
8563 11EC: MOVLW 30
8564 11ED: SUBWF 38,W
8565 11EE: MOVWF 33
8566 11EF: CLRF 34
8567 .................... break;
8568 11F0: GOTO 22B
8569 ....................
8570 .................... case 2: //dopøedu
8571 .................... azimutZAD=(i[2]-48)+(i[1]-48)*10;
8572 11F1: MOVLW 30
8573 11F2: SUBWF 39,W
8574 11F3: MOVWF 45
8575 11F4: MOVLW 30
8576 11F5: SUBWF 38,W
8577 11F6: MOVWF 47
8578 11F7: MOVWF 48
8579 11F8: MOVLW 0A
8580 11F9: MOVWF 49
8581 11FA: BCF 0A.4
8582 11FB: CALL 2B4
8583 11FC: BSF 0A.4
8584 11FD: MOVF 78,W
8585 11FE: ADDWF 45,W
8586 11FF: MOVWF 33
8587 1200: CLRF 34
8588 .................... break;
8589 1201: GOTO 22B
8590 .................... case 3: //dopøedu
8591 .................... azimutZAD=(i[3]-48)+(i[2]-48)*10+((int16)i[1]-48)*100;
8592 1202: MOVLW 30
8593 1203: SUBWF 3A,W
8594 1204: MOVWF 45
8595 1205: MOVLW 30
8596 1206: SUBWF 39,W
8597 1207: MOVWF 47
8598 1208: MOVWF 48
8599 1209: MOVLW 0A
8600 120A: MOVWF 49
8601 120B: BCF 0A.4
8602 120C: CALL 2B4
8603 120D: BSF 0A.4
8604 120E: MOVF 78,W
8605 120F: ADDWF 45,F
8606 1210: CLRF 47
8607 1211: MOVF 38,W
8608 1212: MOVWF 46
8609 1213: MOVLW 30
8610 1214: SUBWF 46,F
8611 1215: MOVLW 00
8612 1216: BTFSS 03.0
8613 1217: MOVLW 01
8614 1218: SUBWF 47,F
8615 1219: MOVF 47,W
8616 121A: MOVWF 49
8617 121B: MOVF 46,W
8618 121C: MOVWF 48
8619 121D: CLRF 4B
8620 121E: MOVLW 64
8621 121F: MOVWF 4A
8622 1220: BCF 0A.4
8623 1221: CALL 2D9
8624 1222: BSF 0A.4
8625 1223: MOVF 78,W
8626 1224: ADDWF 45,W
8627 1225: MOVWF 33
8628 1226: MOVF 79,W
8629 1227: MOVWF 34
8630 1228: BTFSC 03.0
8631 1229: INCF 34,F
8632 .................... break;
8633 122A: GOTO 22B
8634 ....................
8635 .................... default:
8636 ....................
8637 .................... }
8638 ....................
8639 ....................
8640 .................... printf("Zadaný azimut %Ld \r\n", azimutZAD);
8641 122B: MOVLW 7D
8642 122C: BSF 03.6
8643 122D: MOVWF 0D
8644 122E: MOVLW 00
8645 122F: MOVWF 0F
8646 1230: MOVLW 0E
8647 1231: BCF 03.6
8648 1232: MOVWF 4F
8649 1233: BCF 0A.4
8650 1234: CALL 2EE
8651 1235: BSF 0A.4
8652 1236: MOVLW 10
8653 1237: MOVWF 04
8654 1238: MOVF 34,W
8655 1239: MOVWF 50
8656 123A: MOVF 33,W
8657 123B: MOVWF 4F
8658 123C: BCF 0A.4
8659 123D: CALL 30F
8660 123E: BSF 0A.4
8661 123F: MOVLW 20
8662 1240: MOVWF 59
8663 1241: BCF 0A.4
8664 1242: CALL 222
8665 1243: BSF 0A.4
8666 1244: MOVLW 0D
8667 1245: MOVWF 59
8668 1246: BCF 0A.4
8669 1247: CALL 222
8670 1248: BSF 0A.4
8671 1249: MOVLW 0A
8672 124A: MOVWF 59
8673 124B: BCF 0A.4
8674 124C: CALL 222
8675 124D: BSF 0A.4
8676 ....................
8677 ....................
8678 ....................
8679 ....................
8680 .................... elevace_set (elevaceZAD);
8681 124E: MOVF 36,W
8682 124F: MOVWF 46
8683 1250: MOVF 35,W
8684 1251: MOVWF 45
8685 1252: BCF 0A.4
8686 1253: GOTO 6D8
8687 1254: BSF 0A.4
8688 .................... azimut_set(azimutZAD);
8689 1255: MOVF 34,W
8690 1256: MOVWF 46
8691 1257: MOVF 33,W
8692 1258: MOVWF 45
8693 1259: GOTO 000
8694 ....................
8695 ....................
8696 ....................
8697 .................... delay_ms (2000);
8698 125A: MOVLW 08
8699 125B: MOVWF 45
8700 125C: MOVLW FA
8701 125D: MOVWF 4F
8702 125E: BCF 0A.4
8703 125F: CALL 15D
8704 1260: BSF 0A.4
8705 1261: DECFSZ 45,F
8706 1262: GOTO 25C
8707 ....................
8708 ....................
8709 .................... }
8710 1263: GOTO 12F
8711 .................... }
8712 1264: SLEEP
8713  
8714 Configuration Fuses:
8715 Word 1: 2CF5 INTRC NOWDT NOPUT MCLR NOPROTECT NOCPD NOBROWNOUT IESO FCMEN NOLVP NODEBUG
8716 Word 2: 3FFF NOWRT BORV40