CCS PCM C Compiler, Version 4.005, 35009               27-Oct-06 16:17

               Filename: Gulper_Main.lst

               ROM used: 2630 words (32%)
                         Largest free fragment is 2048
               RAM used: 122 (33%) at main() level
                         178 (48%) worst case
               Stack:    7 worst case (5 in main + 2 for interrupts)

*
0000:  MOVLW  08
0001:  MOVWF  0A
0002:  GOTO   0AA
0003:  NOP
0004:  MOVWF  7F
0005:  SWAPF  03,W
0006:  CLRF   03
0007:  MOVWF  21
0008:  MOVF   0A,W
0009:  MOVWF  20
000A:  CLRF   0A
000B:  MOVF   04,W
000C:  MOVWF  22
000D:  MOVF   77,W
000E:  MOVWF  23
000F:  MOVF   78,W
0010:  MOVWF  24
0011:  MOVF   79,W
0012:  MOVWF  25
0013:  MOVF   7A,W
0014:  MOVWF  26
0015:  MOVF   7B,W
0016:  MOVWF  27
0017:  BCF    03.7
0018:  BCF    03.5
0019:  BTFSS  0B.4
001A:  GOTO   01D
001B:  BTFSC  0B.1
001C:  GOTO   03C
001D:  MOVLW  8C
001E:  MOVWF  04
001F:  BTFSS  00.5
0020:  GOTO   023
0021:  BTFSC  0C.5
0022:  GOTO   03F
0023:  MOVLW  8C
0024:  MOVWF  04
0025:  BTFSS  00.0
0026:  GOTO   029
0027:  BTFSC  0C.0
0028:  GOTO   042
0029:  MOVF   22,W
002A:  MOVWF  04
002B:  MOVF   23,W
002C:  MOVWF  77
002D:  MOVF   24,W
002E:  MOVWF  78
002F:  MOVF   25,W
0030:  MOVWF  79
0031:  MOVF   26,W
0032:  MOVWF  7A
0033:  MOVF   27,W
0034:  MOVWF  7B
0035:  MOVF   20,W
0036:  MOVWF  0A
0037:  SWAPF  21,W
0038:  MOVWF  03
0039:  SWAPF  7F,F
003A:  SWAPF  7F,W
003B:  RETFIE
003C:  BCF    0A.3
003D:  BCF    0A.4
003E:  GOTO   161
003F:  BCF    0A.3
0040:  BCF    0A.4
0041:  GOTO   09F
0042:  BCF    0A.3
0043:  BCF    0A.4
0044:  GOTO   13F
.................... /****************************************************************************/ 
.................... /* Copyright 2005 MBARI.                                                    */ 
.................... /* Monterey Bay Aquarium Research Institute Proprietary Information.        */ 
.................... /* All rights reserved.                                                     */ 
.................... /****************************************************************************/ 
.................... #include <16f876A.h> 
.................... //////// Standard Header file for the PIC16F876A device //////////////// 
.................... #device PIC16F876A 
.................... #list 
....................  
.................... #include <string.h> 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services            //// 
.................... //// This source code may only be used by licensed users of the CCS C   //// 
.................... //// compiler.  This source code may only be distributed to other       //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction  //// 
.................... //// or distribution is permitted without written permission.           //// 
.................... //// Derivative programs created using this software in object code     //// 
.................... //// form are not restricted in any way.                                //// 
.................... //////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STRING 
.................... #define _STRING 
.................... #include <stddef.h> 
.................... /////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services           //// 
.................... //// This source code may only be used by licensed users of the CCS C  //// 
.................... //// compiler.  This source code may only be distributed to other      //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction //// 
.................... //// or distribution is permitted without written permission.          //// 
.................... //// Derivative programs created using this software in object code    //// 
.................... //// form are not restricted in any way.                               //// 
.................... /////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STDDEF 
....................  
.................... #define _STDDEF 
....................  
.................... #if sizeof(int *)==1 
.................... #define ptrdiff_t int 
.................... #else 
.................... #define ptrdiff_t long 
.................... #endif 
....................  
.................... #define size_t int 
.................... #define wchar_t char 
.................... #define NULL 0 
....................  
.................... #define offsetof(s,f) (offsetofbit(s,f)/8) 
....................  
.................... #endif 
....................  
.................... #include <ctype.h> 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services            //// 
.................... //// This source code may only be used by licensed users of the CCS C   //// 
.................... //// compiler.  This source code may only be distributed to other       //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction  //// 
.................... //// or distribution is permitted without written permission.           //// 
.................... //// Derivative programs created using this software in object code     //// 
.................... //// form are not restricted in any way.                                //// 
.................... //////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _CTYPE 
.................... #define _CTYPE 
....................  
.................... #define islower(x)  isamong(x,"abcdefghijklmnopqrstuvwxyz") 
.................... #define isupper(x)  isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZ") 
.................... #define isalnum(x)  isamong(x,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") 
.................... #define isalpha(x)  isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") 
.................... #define isdigit(x)  isamong(x,"0123456789") 
.................... #define isspace(x)  (x==' ') 
.................... #define isxdigit(x) isamong(x,"0123456789ABCDEFabcdef") 
.................... #define iscntrl(x)  (x<' ') 
.................... #define isprint(x)  (x>=' ') 
.................... #define isgraph(x)  (x>' ') 
.................... #define ispunct(x)  ((x>' ')&&!isalnum(x)) 
....................  
.................... #endif 
....................  
....................  
....................  
....................  
....................  
.................... ////////////////////////////////////////////// 
.................... //// Uncomment the following define to    //// 
.................... //// allow some functions to use a        //// 
.................... //// quicker algorithm, but use more ROM  //// 
.................... ////                                      //// 
.................... //// #define FASTER_BUT_MORE_ROM          //// 
.................... ////////////////////////////////////////////// 
....................  
....................  
....................  
.................... /*Copying functions*/ 
.................... /* standard template: 
....................    void *memmove(void *s1, void *s2, size_t n). 
....................    Copies max of n characters safely (not following ending '\0') 
....................    from s2 in s1; if s2 has less than n characters, appends 0 */ 
....................  
.................... char *memmove(void *s1,char *s2,size_t n) 
.................... { 
....................    char *sc1; 
....................    char *sc2; 
....................    sc1=s1; 
....................    sc2=s2; 
....................    if(sc2<sc1 && sc1 <sc2 +n) 
....................       for(sc1+=n,sc2+=n;0<n;--n) 
....................          *--sc1=*--sc2; 
....................    else 
....................       for(;0<n;--n) 
....................          *sc1++=*sc2++; 
....................   return s1; 
....................   } 
....................  
.................... /* compiler ignored the name 'strcpy()'; perhaps, it's reserved? 
....................    Standard template: char *strcpy(char *s1, const char *s2) 
....................    copies the string s2 including the null character to s1*/ 
....................  
.................... char *strcopy(char *s1, char *s2) 
.................... { 
....................   char *s; 
....................  
....................   for (s = s1; *s2 != 0; s++, s2++) { 
....................      *s = *s2; 
....................   } 
....................   *s = *s2; 
....................   return(s1); 
.................... } 
....................  
.................... /* standard template: 
....................    char *strncpy(char *s1, const char *s2, size_t n). 
....................    Copies max of n characters (not following ending '\0') 
....................    from s2 in s1; if s2 has less than n characters, appends 0 */ 
....................  
.................... char *strncpy(char *s1, char *s2, size_t n) 
.................... { 
....................   char *s; 
....................  
....................   for (s = s1; n > 0 && *s2 != '\0'; n--) 
....................      *s++ = *s2++; 
....................   for (; n > 0; n--) 
....................      *s++ = '\0'; 
....................  
....................   return(s1); 
.................... } 
.................... /***********************************************************/ 
....................  
.................... /*concatenation functions*/ 
.................... /* standard template: char *strcat(char *s1, const char *s2) 
.................... appends s2 to s1*/ 
....................  
.................... char *strcat(char *s1, char *s2) 
.................... { 
....................    char *s; 
....................  
....................    for (s = s1; *s != '\0'; ++s); 
....................    while(*s2 != '\0') 
....................    { 
....................       *s = *s2; 
....................       ++s; 
....................       ++s2; 
....................    } 
....................  
....................    *s = '\0'; 
....................    return(s1); 
.................... } 
.................... /* standard template: char *strncat(char *s1, char *s2,size_t n) 
.................... appends not more than n characters from s2 to s1*/ 
....................  
.................... char *strncat(char *s1, char *s2, size_t n) 
.................... { 
....................    char *s; 
....................  
....................    for (s = s1; *s != '\0'; ++s); 
*
01FB:  BSF    03.5
01FC:  MOVF   6A,W
01FD:  MOVWF  6F
01FE:  MOVF   69,W
01FF:  MOVWF  6E
0200:  MOVF   6F,W
0201:  MOVWF  7A
0202:  MOVF   6E,W
0203:  MOVWF  04
0204:  BCF    03.7
0205:  BTFSC  7A.0
0206:  BSF    03.7
0207:  MOVF   00,F
0208:  BTFSC  03.2
0209:  GOTO   20E
020A:  INCF   6E,F
020B:  BTFSC  03.2
020C:  INCF   6F,F
020D:  GOTO   200
....................    while(*s2 != '\0' && 0<n) 
....................    { 
020E:  MOVF   6C,W
020F:  MOVWF  7A
0210:  MOVF   6B,W
0211:  MOVWF  04
0212:  BCF    03.7
0213:  BTFSC  7A.0
0214:  BSF    03.7
0215:  MOVF   00,F
0216:  BTFSC  03.2
0217:  GOTO   240
0218:  MOVF   6D,W
0219:  SUBLW  00
021A:  BTFSC  03.0
021B:  GOTO   240
....................       *s = *s2; 
021C:  MOVF   6F,W
021D:  MOVWF  7A
021E:  MOVF   6E,W
021F:  BCF    03.5
0220:  BSF    03.6
0221:  MOVWF  10
0222:  MOVF   7A,W
0223:  MOVWF  11
0224:  BSF    03.5
0225:  BCF    03.6
0226:  MOVF   6B,W
0227:  MOVWF  04
0228:  BCF    03.7
0229:  BTFSC  6C.0
022A:  BSF    03.7
022B:  MOVF   00,W
022C:  BCF    03.5
022D:  BSF    03.6
022E:  MOVWF  12
022F:  MOVF   10,W
0230:  MOVWF  04
0231:  BCF    03.7
0232:  BTFSC  11.0
0233:  BSF    03.7
0234:  MOVF   12,W
0235:  MOVWF  00
....................       ++s; 
0236:  BSF    03.5
0237:  BCF    03.6
0238:  INCF   6E,F
0239:  BTFSC  03.2
023A:  INCF   6F,F
....................       ++s2; 
023B:  INCF   6B,F
023C:  BTFSC  03.2
023D:  INCF   6C,F
....................       --n; 
023E:  DECF   6D,F
....................    } 
023F:  GOTO   20E
....................  
....................    *s = '\0'; 
0240:  MOVF   6E,W
0241:  MOVWF  04
0242:  BCF    03.7
0243:  BTFSC  6F.0
0244:  BSF    03.7
0245:  CLRF   00
....................    return(s1); 
0246:  MOVF   69,W
0247:  MOVWF  78
0248:  MOVF   6A,W
0249:  MOVWF  79
.................... } 
024A:  BCF    03.5
024B:  RETLW  00
....................  
.................... /***********************************************************/ 
....................  
....................  
.................... /*comparison functions*/ 
.................... /* standard template: signed int memcmp(void *s1, void *s2). 
....................    Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ 
....................  
.................... signed int memcmp(void * s1,char *s2,size_t n) 
.................... { 
.................... char *su1, *su2; 
.................... for(su1=s1, su2=s2; 0<n; ++su1, ++su2, --n) 
.................... { 
....................    if(*su1!=*su2) 
....................       return ((*su1<*su2)?-1:+1); 
.................... } 
.................... return 0; 
.................... } 
....................  
.................... /* standard template: int strcmp(const char *s1, const char *s2). 
....................    Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ 
....................  
.................... signed int strcmp(char *s1, char *s2) 
.................... { 
....................    for (; *s1 == *s2; s1++, s2++) 
*
039A:  BSF    03.5
039B:  MOVF   3F,W
039C:  MOVWF  7A
039D:  MOVF   3E,W
039E:  MOVWF  04
039F:  BCF    03.7
03A0:  BTFSC  7A.0
03A1:  BSF    03.7
03A2:  MOVF   00,W
03A3:  MOVWF  42
03A4:  MOVF   41,W
03A5:  MOVWF  7A
03A6:  MOVF   40,W
03A7:  MOVWF  04
03A8:  BCF    03.7
03A9:  BTFSC  7A.0
03AA:  BSF    03.7
03AB:  MOVF   00,W
03AC:  SUBWF  42,W
03AD:  BTFSS  03.2
03AE:  GOTO   3C6
....................       if (*s1 == '\0') 
03AF:  MOVF   3F,W
03B0:  MOVWF  7A
03B1:  MOVF   3E,W
03B2:  MOVWF  04
03B3:  BCF    03.7
03B4:  BTFSC  7A.0
03B5:  BSF    03.7
03B6:  MOVF   00,F
03B7:  BTFSS  03.2
03B8:  GOTO   3BC
....................          return(0); 
03B9:  MOVLW  00
03BA:  MOVWF  78
03BB:  GOTO   3DF
03BC:  MOVF   3F,W
03BD:  MOVWF  7A
03BE:  MOVF   3E,W
03BF:  INCF   3E,F
03C0:  BTFSC  03.2
03C1:  INCF   3F,F
03C2:  INCF   40,F
03C3:  BTFSC  03.2
03C4:  INCF   41,F
03C5:  GOTO   39B
....................    return((*s1 < *s2) ? -1: 1); 
03C6:  MOVF   3F,W
03C7:  MOVWF  7A
03C8:  MOVF   3E,W
03C9:  MOVWF  04
03CA:  BCF    03.7
03CB:  BTFSC  3F.0
03CC:  BSF    03.7
03CD:  MOVF   00,W
03CE:  MOVWF  42
03CF:  MOVF   41,W
03D0:  MOVWF  7A
03D1:  MOVF   40,W
03D2:  MOVWF  04
03D3:  BCF    03.7
03D4:  BTFSC  41.0
03D5:  BSF    03.7
03D6:  MOVF   00,W
03D7:  SUBWF  42,W
03D8:  BTFSC  03.0
03D9:  GOTO   3DD
03DA:  MOVLW  FF
03DB:  MOVWF  7A
03DC:  GOTO   3DE
03DD:  MOVLW  01
03DE:  MOVWF  78
.................... } 
03DF:  BCF    03.5
03E0:  RETLW  00
.................... /* standard template: int strcoll(const char *s1, const char *s2). 
....................    Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ 
....................  
.................... signed int strcoll(char *s1, char *s2) 
.................... { 
....................    for (; *s1 == *s2; s1++, s2++) 
....................       if (*s1 == '\0') 
....................          return(0); 
....................    return((*s1 < *s2) ? -1: 1); 
.................... } 
....................  
.................... /* standard template: 
....................    int strncmp(const char *s1, const char *s2, size_t n). 
....................    Compares max of n characters (not following 0) from s1 to s2; 
....................    returns same as strcmp */ 
....................  
.................... signed int strncmp(char *s1, char *s2, size_t n) 
.................... { 
....................    for (; n > 0; s1++, s2++, n--) 
....................       if (*s1 != *s2) 
....................          return((*s1 <*s2) ? -1: 1); 
....................       else if (*s1 == '\0') 
....................          return(0); 
....................    return(0); 
.................... } 
.................... /* standard template: 
....................    int strxfrm(const char *s1, const char *s2, size_t n). 
....................    transforms maximum of n characters from s2 and places them into s1*/ 
.................... size_t strxfrm(char *s1, char *s2, size_t n) 
.................... { 
....................   char *s; 
....................   int n1; 
....................   n1=n; 
....................   for (s = s1; n > 0 && *s2 != '\0'; n--) 
....................      *s++ = *s2++; 
....................   for (; n > 0; n--) 
....................      *s++ = '\0'; 
....................  
....................   return(n1); 
.................... } 
....................  
....................  
....................  
....................  
....................  
.................... /***********************************************************/ 
.................... /*Search functions*/ 
.................... /* standard template: void *memchr(const char *s, int c). 
....................    Finds first occurrence of c in n characters of s */ 
....................  
.................... char *memchr(void *s,int c,size_t n) 
.................... { 
....................    char uc; 
....................    char *su; 
....................    uc=c; 
....................    for(su=s;0<n;++su,--n) 
....................       if(*su==uc) 
....................       return su; 
....................    return NULL; 
.................... } 
....................  
.................... /* standard template: char *strchr(const char *s, int c). 
....................    Finds first occurrence of c in s */ 
....................  
.................... char *strchr(char *s, int c) 
.................... { 
....................    for (; *s != c; s++) 
....................       if (*s == '\0') 
....................          return(0); 
....................    return(s); 
.................... } 
.................... /* standard template: 
....................    size_t strcspn(const char *s1, const char *s2). 
....................    Computes length of max initial segment of s1 that 
....................    consists entirely of characters NOT from s2*/ 
....................  
.................... int *strcspn(char *s1, char *s2) 
.................... { 
....................    char *sc1, *sc2; 
....................  
....................    for (sc1 = s1; *sc1 != 0; sc1++) 
....................       for (sc2 = s2; *sc2 != 0; sc2++) 
....................          if (*sc1 == *sc2) 
....................             return(sc1 - s1); 
....................    return(sc1 - s1); 
.................... } 
.................... /* standard template: 
....................    char *strpbrk(const char *s1, const char *s2). 
....................    Locates first occurence of any character from s2 in s1; 
....................    returns s1 if s2 is empty string */ 
....................  
.................... char *strpbrk(char *s1, char *s2) 
.................... { 
....................    char *sc1, *sc2; 
....................  
....................    for (sc1 = s1; *sc1 != 0; sc1++) 
....................       for (sc2 = s2; *sc2 != 0; sc2++) 
....................          if (*sc1 == *sc2) 
....................             return(sc1); 
....................    return(0); 
.................... } 
....................  
....................  
.................... /* standard template: char *strrchr(const char *s, int c). 
....................    Finds last occurrence of c in s */ 
....................  
.................... char *strrchr(char *s, int c) 
.................... { 
....................    char *p; 
....................  
....................    for (p = 0; ; s++) 
....................    { 
....................       if (*s == c) 
....................          p = s; 
....................       if (*s == '\0') 
....................          return(p); 
....................    } 
.................... } 
.................... /* computes length of max initial segment of s1 consisting 
....................    entirely of characters from s2 */ 
....................  
.................... int *strspn(char *s1, char *s2) 
.................... { 
....................    char *sc1, *sc2; 
....................  
....................    for (sc1 = s1; *sc1 != 0; sc1++) 
....................       for (sc2 = s2; ; sc2++) 
....................     if (*sc2 == '\0') 
....................        return(sc1 - s1); 
....................          else if (*sc1 == *sc2) 
....................             break; 
....................    return(sc1 - s1); 
.................... } 
.................... /* standard template: 
....................    char *strstr(const char *s1, const char *s2); 
....................    Locates first occurence of character sequence s2 in s1; 
....................    returns 0 if s2 is empty string 
....................  
....................    Uncomment #define FASTER_BUT_MORE_ROM at the top of the 
....................    file to use the faster algorithm */ 
.................... char *strstr(char *s1, char *s2) 
.................... { 
....................    char *s, *t; 
....................  
....................    #ifdef FASTER_BUT_MORE_ROM 
....................    if (*s2 == '\0') 
....................          return(s1); 
....................    #endif 
....................  
....................    while (*s1) 
....................    { 
....................       for(s = s1, t = s2; *t && (*s == *t); ++s, ++t); 
....................  
....................       if (*t == '\0') 
....................          return s1; 
....................       ++s1; 
....................       #ifdef FASTER_BUT_MORE_ROM 
....................          while(*s1 != '\0' && *s1 != *s2) 
....................             ++s1; 
....................       #endif 
....................    } 
....................    return 0; 
.................... } 
....................  
.................... /* standard template: char *strtok(char *s1, const char *s2). 
....................  
....................    Finds next token in s1 delimited by a character from separator 
....................    string s2 (which can be different from call to call).  First call 
....................    starts at beginning of s1 searching for first character NOT 
....................    contained in s2; returns 0 if none is found. 
....................    If one is found, it is the start of first token (return value). 
....................    Function then searches from there for a character contained in s2. 
....................    If none is found, current token extends to end of s1, and subsequent 
....................    searches for a token will return 0.  If one is found, it is 
....................    overwritten by '\0', which terminates current token.  Function saves 
....................    pointer to following character from which next search will start. 
....................    Each subsequent call, with 0 as first argument, starts searching 
....................    from saved pointer */ 
....................  
.................... char *strtok(char *s1, char *s2) 
.................... { 
....................    char *beg, *end; 
....................    static char *save; 
*
08BD:  BCF    03.5
08BE:  CLRF   29
08BF:  CLRF   2A
....................  
....................    beg = (s1)? s1: save; 
....................    beg += strspn(beg, s2); 
....................    if (*beg == '\0') 
....................    { 
....................       *save = ' '; 
....................       return(0); 
....................    } 
....................    end = strpbrk(beg, s2); 
....................    if (*end != '\0') 
....................    { 
....................       *end = '\0'; 
....................       end++; 
....................    } 
....................    save = end; 
....................    return(beg); 
.................... } 
....................  
.................... /*****************************************************************/ 
.................... /*Miscellaneous functions*/ 
.................... /* standard template 
.................... maps error number in errnum to an error message string 
.................... Returns: Pointer to string 
.................... */ 
.................... #ifdef _ERRNO 
.................... char * strerror(int errnum) 
.................... { 
.................... char s[15]; 
.................... switch( errnum) 
.................... { 
.................... case 0: 
....................    strcpy(s,"no errors"); 
....................    return s; 
.................... case EDOM : 
....................    strcpy(s,"domain error"); 
....................    return s; 
.................... case ERANGE: 
....................    strcpy(s,"range error"); 
....................    return s; 
.................... } 
.................... } 
.................... #ENDIF 
.................... /* standard template: size_t strlen(const char *s). 
....................    Computes length of s1 (preceding terminating 0) */ 
....................  
.................... int *strlen(char *s) 
.................... { 
....................    char *sc; 
....................  
....................    for (sc = s; *sc != 0; sc++); 
....................    return(sc - s); 
.................... } 
....................  
.................... /* standard template: size_t stricmp(const char *s1, const char *s2). 
....................    Compares s1 to s2 ignoring case (upper vs. lower) */ 
....................  
.................... signed int stricmp(char *s1, char *s2) 
.................... { 
....................  for(; *s1==*s2||(isalpha(*s1)&&isalpha(*s2)&&(*s1==*s2+32||*s2==*s1+32)); 
....................     s1++, s2++) 
....................     if (*s1 == '\0') 
....................        return(0); 
....................  return((*s1 < *s2) ? -1: 1); 
.................... } 
....................  
....................  
.................... /* standard template: char *strlwr(char *s). 
....................    Replaces uppercase letters by lowercase; 
....................    returns pointer to new string s */ 
....................  
.................... char *strlwr(char *s) 
.................... { 
....................    char *p; 
....................  
....................    for (p = s; *p != '\0'; p++) 
....................       if (*p >= 'A' && *p <='Z') 
....................          *p += 'a' - 'A'; 
....................    return(s); 
.................... } 
....................  
....................  
.................... /************************************************************/ 
....................  
....................  
.................... #endif 
....................  
.................... #include <stdlib.h> 
.................... /////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services           //// 
.................... //// This source code may only be used by licensed users of the CCS C  //// 
.................... //// compiler.  This source code may only be distributed to other      //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction //// 
.................... //// or distribution is permitted without written permission.          //// 
.................... //// Derivative programs created using this software in object code    //// 
.................... //// form are not restricted in any way.                               //// 
.................... /////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STDLIB 
.................... #define _STDLIB 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Definitions and types 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #ifndef RAND_MAX 
.................... #define RAND_MAX  32767    // The value of which is the maximum value 
....................                            // ... returned by the rand function 
.................... #endif 
....................  
.................... typedef struct { 
....................    signed int quot; 
....................    signed int rem; 
.................... } div_t; 
....................  
.................... typedef struct { 
....................    signed long quot; 
....................    signed long rem; 
.................... } ldiv_t; 
....................  
.................... #include <stddef.h> 
.................... /////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services           //// 
.................... //// This source code may only be used by licensed users of the CCS C  //// 
.................... //// compiler.  This source code may only be distributed to other      //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction //// 
.................... //// or distribution is permitted without written permission.          //// 
.................... //// Derivative programs created using this software in object code    //// 
.................... //// form are not restricted in any way.                               //// 
.................... /////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STDDEF 
....................  
.................... #define _STDDEF 
....................  
.................... #if sizeof(int *)==1 
.................... #define ptrdiff_t int 
.................... #else 
.................... #define ptrdiff_t long 
.................... #endif 
....................  
.................... #define size_t int 
.................... #define wchar_t char 
.................... #define NULL 0 
....................  
.................... #define offsetof(s,f) (offsetofbit(s,f)/8) 
....................  
.................... #endif 
....................  
....................  
.................... //--------------------------------------------------------------------------- 
.................... // String conversion functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* Standard template: float atof(char * s) 
....................  * converts the initial portion of the string s to a float. 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... float atof(char * s); 
....................  
.................... /* Standard template: float atoe(char * s) 
....................  * converts the initial portion of the string s to a float. 
....................  * returns the converted value if any, 0 otherwise 
....................  * also handles E format numbers 
....................  */ 
.................... float atoe(char * s); 
....................  
.................... /* Standard template: signed int  atoi(char * s) 
....................  * converts the initial portion of the string s to a signed int 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... signed int atoi(char *s); 
....................  
.................... /* Syntax: signed int32  atoi32(char * s) 
....................    converts the initial portion of the string s to a signed int32 
....................    returns the converted value if any, 0 otherwise*/ 
.................... signed int32 atoi32(char *s); 
....................  
.................... /* Syntax: char *  itoa(signed int32 num, int8 base, char * s) 
....................    converts the signed int32 to a string and 
....................    returns the converted value if any, 0 otherwise*/ 
.................... char * itoa(signed int32 num, int8 base, char * s); 
....................  
.................... /* Standard template: signed long  atol(char * s) 
....................  * converts the initial portion of the string s to a signed long 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... signed long atol(char *s); 
....................  
.................... /* Standard template: float strtol(char * s,char *endptr) 
....................  * converts the initial portion of the string s to a float 
....................  * returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... float strtod(char *s,char *endptr); 
....................  
.................... /* Standard template: long strtoul(char * s,char *endptr,signed int base) 
....................  * converts the initial portion of the string s, represented as an 
....................  * integral value of radix base  to a signed long. 
....................  * Returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... signed long strtol(char *s,char *endptr,signed int base); 
....................  
.................... /* Standard template: long strtoul(char * s,char *endptr,signed int base) 
....................  * converts the initial portion of the string s, represented as an 
....................  * integral value of radix base to a unsigned long. 
....................  * returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... long strtoul(char *s,char *endptr,signed int base); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Pseudo-random sequence generation functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* The rand function computes a sequence of pseudo-random integers in 
....................  * the range 0 to RAND_MAX 
....................  * 
....................  * Parameters: 
....................  *       (none) 
....................  * 
....................  * Returns: 
....................  *       The pseudo-random integer 
....................  */ 
.................... long rand(void); 
....................  
.................... /* The srand function uses the argument as a seed for a new sequence of 
....................  * pseudo-random numbers to be returned by subsequent calls to rand. 
....................  * 
....................  * Parameters: 
....................  *       [in] seed: The seed value to start from. You might need to pass 
....................  * 
....................  * Returns: 
....................  *       (none) 
....................  * 
....................  * Remarks 
....................  *          The srand function sets the starting point for generating 
....................  *       a series of pseudorandom integers. To reinitialize the 
....................  *       generator, use 1 as the seed argument. Any other value for 
....................  *       seed sets the generator to a random starting point. rand 
....................  *       retrieves the pseudorandom numbers that are generated. 
....................  *       Calling rand before any call to srand generates the same 
....................  *       sequence as calling srand with seed passed as 1. 
....................  *          Usually, you need to pass a time here from outer source 
....................  *       so that the numbers will be different every time you run. 
....................  */ 
.................... void srand(unsigned int32 seed); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Memory management functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Comming soon 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Communication with the environment 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* The function returns 0 always 
....................  */ 
.................... signed int system(char *string); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Searching and sorting utilities 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* Performs a binary search of a sorted array.. 
....................  * 
....................  * Parameters: 
....................  *       [in] key: Object to search for 
....................  *       [in] base: Pointer to base of search data 
....................  *       [in] num: Number of elements 
....................  *       [in] width: Width of elements 
....................  *       [in] compare: Function that compares two elements 
....................  * 
....................  * Returns: 
....................  *       bsearch returns a pointer to an occurrence of key in the array pointed 
....................  *       to by base. If key is not found, the function returns NULL. If the 
....................  *       array is not in order or contains duplicate records with identical keys, 
....................  *       the result is unpredictable. 
....................  */ 
.................... //void *bsearch(const void *key, const void *base, size_t num, size_t width, 
.................... //              int (*compare)(const void *, const void *)); 
....................  
.................... /* Performs the shell-metzner sort (not the quick sort algorithm). The contents 
....................  * of the array are sorted into ascending order according to a comparison 
....................  * function pointed to by compar. 
....................  * 
....................  * Parameters: 
....................  *       [in] base: Pointer to base of search data 
....................  *       [in] num: Number of elements 
....................  *       [in] width: Width of elements 
....................  *       [in] compare: Function that compares two elements 
....................  * 
....................  * Returns: 
....................  *       (none) 
....................  */ 
.................... //void *qsort(const void *base, size_t num, size_t width, 
.................... //              int (*compare)(const void *, const void *)); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Integer arithmetic functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #define labs abs 
....................  
.................... div_t div(signed int numer,signed int denom); 
.................... ldiv_t ldiv(signed long numer,signed long denom); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Multibyte character functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Not supported 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Multibyte string functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Not supported 
....................  
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Internal implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #include <stddef.h> 
.................... /////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services           //// 
.................... //// This source code may only be used by licensed users of the CCS C  //// 
.................... //// compiler.  This source code may only be distributed to other      //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction //// 
.................... //// or distribution is permitted without written permission.          //// 
.................... //// Derivative programs created using this software in object code    //// 
.................... //// form are not restricted in any way.                               //// 
.................... /////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STDDEF 
....................  
.................... #define _STDDEF 
....................  
.................... #if sizeof(int *)==1 
.................... #define ptrdiff_t int 
.................... #else 
.................... #define ptrdiff_t long 
.................... #endif 
....................  
.................... #define size_t int 
.................... #define wchar_t char 
.................... #define NULL 0 
....................  
.................... #define offsetof(s,f) (offsetofbit(s,f)/8) 
....................  
.................... #endif 
....................  
.................... #include <string.h> 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services            //// 
.................... //// This source code may only be used by licensed users of the CCS C   //// 
.................... //// compiler.  This source code may only be distributed to other       //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction  //// 
.................... //// or distribution is permitted without written permission.           //// 
.................... //// Derivative programs created using this software in object code     //// 
.................... //// form are not restricted in any way.                                //// 
.................... //////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STRING 
.................... #define _STRING 
.................... #include <stddef.h> 
.................... #include <ctype.h> 
....................  
....................  
....................  
.................... ////////////////////////////////////////////// 
.................... //// Uncomment the following define to    //// 
.................... //// allow some functions to use a        //// 
.................... //// quicker algorithm, but use more ROM  //// 
.................... ////                                      //// 
.................... //// #define FASTER_BUT_MORE_ROM          //// 
.................... ////////////////////////////////////////////// 
....................  
....................  
....................  
.................... /*Copying functions*/ 
.................... /* standard template: 
....................    void *memmove(void *s1, void *s2, size_t n). 
....................    Copies max of n characters safely (not following ending '\0') 
....................    from s2 in s1; if s2 has less than n characters, appends 0 */ 
....................  
.................... char *memmove(void *s1,char *s2,size_t n) 
.................... { 
....................    char *sc1; 
....................    char *sc2; 
....................    sc1=s1; 
....................    sc2=s2; 
....................    if(sc2<sc1 && sc1 <sc2 +n) 
....................       for(sc1+=n,sc2+=n;0<n;--n) 
....................          *--sc1=*--sc2; 
....................    else 
....................       for(;0<n;--n) 
....................          *sc1++=*sc2++; 
....................   return s1; 
....................   } 
....................  
.................... /* compiler ignored the name 'strcpy()'; perhaps, it's reserved? 
....................    Standard template: char *strcpy(char *s1, const char *s2) 
....................    copies the string s2 including the null character to s1*/ 
....................  
.................... char *strcopy(char *s1, char *s2) 
.................... { 
....................   char *s; 
....................  
....................   for (s = s1; *s2 != 0; s++, s2++) { 
....................      *s = *s2; 
....................   } 
....................   *s = *s2; 
....................   return(s1); 
.................... } 
....................  
.................... /* standard template: 
....................    char *strncpy(char *s1, const char *s2, size_t n). 
....................    Copies max of n characters (not following ending '\0') 
....................    from s2 in s1; if s2 has less than n characters, appends 0 */ 
....................  
.................... char *strncpy(char *s1, char *s2, size_t n) 
.................... { 
....................   char *s; 
....................  
....................   for (s = s1; n > 0 && *s2 != '\0'; n--) 
....................      *s++ = *s2++; 
....................   for (; n > 0; n--) 
....................      *s++ = '\0'; 
....................  
....................   return(s1); 
.................... } 
.................... /***********************************************************/ 
....................  
.................... /*concatenation functions*/ 
.................... /* standard template: char *strcat(char *s1, const char *s2) 
.................... appends s2 to s1*/ 
....................  
.................... char *strcat(char *s1, char *s2) 
.................... { 
....................    char *s; 
....................  
....................    for (s = s1; *s != '\0'; ++s); 
....................    while(*s2 != '\0') 
....................    { 
....................       *s = *s2; 
....................       ++s; 
....................       ++s2; 
....................    } 
....................  
....................    *s = '\0'; 
....................    return(s1); 
.................... } 
.................... /* standard template: char *strncat(char *s1, char *s2,size_t n) 
.................... appends not more than n characters from s2 to s1*/ 
....................  
.................... char *strncat(char *s1, char *s2, size_t n) 
.................... { 
....................    char *s; 
....................  
....................    for (s = s1; *s != '\0'; ++s); 
....................    while(*s2 != '\0' && 0<n) 
....................    { 
....................       *s = *s2; 
....................       ++s; 
....................       ++s2; 
....................       --n; 
....................    } 
....................  
....................    *s = '\0'; 
....................    return(s1); 
.................... } 
....................  
.................... /***********************************************************/ 
....................  
....................  
.................... /*comparison functions*/ 
.................... /* standard template: signed int memcmp(void *s1, void *s2). 
....................    Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ 
....................  
.................... signed int memcmp(void * s1,char *s2,size_t n) 
.................... { 
.................... char *su1, *su2; 
.................... for(su1=s1, su2=s2; 0<n; ++su1, ++su2, --n) 
.................... { 
....................    if(*su1!=*su2) 
....................       return ((*su1<*su2)?-1:+1); 
.................... } 
.................... return 0; 
.................... } 
....................  
.................... /* standard template: int strcmp(const char *s1, const char *s2). 
....................    Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ 
....................  
.................... signed int strcmp(char *s1, char *s2) 
.................... { 
....................    for (; *s1 == *s2; s1++, s2++) 
....................       if (*s1 == '\0') 
....................          return(0); 
....................    return((*s1 < *s2) ? -1: 1); 
.................... } 
.................... /* standard template: int strcoll(const char *s1, const char *s2). 
....................    Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ 
....................  
.................... signed int strcoll(char *s1, char *s2) 
.................... { 
....................    for (; *s1 == *s2; s1++, s2++) 
....................       if (*s1 == '\0') 
....................          return(0); 
....................    return((*s1 < *s2) ? -1: 1); 
.................... } 
....................  
.................... /* standard template: 
....................    int strncmp(const char *s1, const char *s2, size_t n). 
....................    Compares max of n characters (not following 0) from s1 to s2; 
....................    returns same as strcmp */ 
....................  
.................... signed int strncmp(char *s1, char *s2, size_t n) 
.................... { 
....................    for (; n > 0; s1++, s2++, n--) 
....................       if (*s1 != *s2) 
....................          return((*s1 <*s2) ? -1: 1); 
....................       else if (*s1 == '\0') 
....................          return(0); 
....................    return(0); 
.................... } 
.................... /* standard template: 
....................    int strxfrm(const char *s1, const char *s2, size_t n). 
....................    transforms maximum of n characters from s2 and places them into s1*/ 
.................... size_t strxfrm(char *s1, char *s2, size_t n) 
.................... { 
....................   char *s; 
....................   int n1; 
....................   n1=n; 
....................   for (s = s1; n > 0 && *s2 != '\0'; n--) 
....................      *s++ = *s2++; 
....................   for (; n > 0; n--) 
....................      *s++ = '\0'; 
....................  
....................   return(n1); 
.................... } 
....................  
....................  
....................  
....................  
....................  
.................... /***********************************************************/ 
.................... /*Search functions*/ 
.................... /* standard template: void *memchr(const char *s, int c). 
....................    Finds first occurrence of c in n characters of s */ 
....................  
.................... char *memchr(void *s,int c,size_t n) 
.................... { 
....................    char uc; 
....................    char *su; 
....................    uc=c; 
....................    for(su=s;0<n;++su,--n) 
....................       if(*su==uc) 
....................       return su; 
....................    return NULL; 
.................... } 
....................  
.................... /* standard template: char *strchr(const char *s, int c). 
....................    Finds first occurrence of c in s */ 
....................  
.................... char *strchr(char *s, int c) 
.................... { 
....................    for (; *s != c; s++) 
....................       if (*s == '\0') 
....................          return(0); 
....................    return(s); 
.................... } 
.................... /* standard template: 
....................    size_t strcspn(const char *s1, const char *s2). 
....................    Computes length of max initial segment of s1 that 
....................    consists entirely of characters NOT from s2*/ 
....................  
.................... int *strcspn(char *s1, char *s2) 
.................... { 
....................    char *sc1, *sc2; 
....................  
....................    for (sc1 = s1; *sc1 != 0; sc1++) 
....................       for (sc2 = s2; *sc2 != 0; sc2++) 
....................          if (*sc1 == *sc2) 
....................             return(sc1 - s1); 
....................    return(sc1 - s1); 
.................... } 
.................... /* standard template: 
....................    char *strpbrk(const char *s1, const char *s2). 
....................    Locates first occurence of any character from s2 in s1; 
....................    returns s1 if s2 is empty string */ 
....................  
.................... char *strpbrk(char *s1, char *s2) 
.................... { 
....................    char *sc1, *sc2; 
....................  
....................    for (sc1 = s1; *sc1 != 0; sc1++) 
....................       for (sc2 = s2; *sc2 != 0; sc2++) 
....................          if (*sc1 == *sc2) 
....................             return(sc1); 
....................    return(0); 
.................... } 
....................  
....................  
.................... /* standard template: char *strrchr(const char *s, int c). 
....................    Finds last occurrence of c in s */ 
....................  
.................... char *strrchr(char *s, int c) 
.................... { 
....................    char *p; 
....................  
....................    for (p = 0; ; s++) 
....................    { 
....................       if (*s == c) 
....................          p = s; 
....................       if (*s == '\0') 
....................          return(p); 
....................    } 
.................... } 
.................... /* computes length of max initial segment of s1 consisting 
....................    entirely of characters from s2 */ 
....................  
.................... int *strspn(char *s1, char *s2) 
.................... { 
....................    char *sc1, *sc2; 
....................  
....................    for (sc1 = s1; *sc1 != 0; sc1++) 
....................       for (sc2 = s2; ; sc2++) 
....................     if (*sc2 == '\0') 
....................        return(sc1 - s1); 
....................          else if (*sc1 == *sc2) 
....................             break; 
....................    return(sc1 - s1); 
.................... } 
.................... /* standard template: 
....................    char *strstr(const char *s1, const char *s2); 
....................    Locates first occurence of character sequence s2 in s1; 
....................    returns 0 if s2 is empty string 
....................  
....................    Uncomment #define FASTER_BUT_MORE_ROM at the top of the 
....................    file to use the faster algorithm */ 
.................... char *strstr(char *s1, char *s2) 
.................... { 
....................    char *s, *t; 
....................  
....................    #ifdef FASTER_BUT_MORE_ROM 
....................    if (*s2 == '\0') 
....................          return(s1); 
....................    #endif 
....................  
....................    while (*s1) 
....................    { 
....................       for(s = s1, t = s2; *t && (*s == *t); ++s, ++t); 
....................  
....................       if (*t == '\0') 
....................          return s1; 
....................       ++s1; 
....................       #ifdef FASTER_BUT_MORE_ROM 
....................          while(*s1 != '\0' && *s1 != *s2) 
....................             ++s1; 
....................       #endif 
....................    } 
....................    return 0; 
.................... } 
....................  
.................... /* standard template: char *strtok(char *s1, const char *s2). 
....................  
....................    Finds next token in s1 delimited by a character from separator 
....................    string s2 (which can be different from call to call).  First call 
....................    starts at beginning of s1 searching for first character NOT 
....................    contained in s2; returns 0 if none is found. 
....................    If one is found, it is the start of first token (return value). 
....................    Function then searches from there for a character contained in s2. 
....................    If none is found, current token extends to end of s1, and subsequent 
....................    searches for a token will return 0.  If one is found, it is 
....................    overwritten by '\0', which terminates current token.  Function saves 
....................    pointer to following character from which next search will start. 
....................    Each subsequent call, with 0 as first argument, starts searching 
....................    from saved pointer */ 
....................  
.................... char *strtok(char *s1, char *s2) 
.................... { 
....................    char *beg, *end; 
....................    static char *save; 
....................  
....................    beg = (s1)? s1: save; 
....................    beg += strspn(beg, s2); 
....................    if (*beg == '\0') 
....................    { 
....................       *save = ' '; 
....................       return(0); 
....................    } 
....................    end = strpbrk(beg, s2); 
....................    if (*end != '\0') 
....................    { 
....................       *end = '\0'; 
....................       end++; 
....................    } 
....................    save = end; 
....................    return(beg); 
.................... } 
....................  
.................... /*****************************************************************/ 
.................... /*Miscellaneous functions*/ 
.................... /* standard template 
.................... maps error number in errnum to an error message string 
.................... Returns: Pointer to string 
.................... */ 
.................... #ifdef _ERRNO 
.................... char * strerror(int errnum) 
.................... { 
.................... char s[15]; 
.................... switch( errnum) 
.................... { 
.................... case 0: 
....................    strcpy(s,"no errors"); 
....................    return s; 
.................... case EDOM : 
....................    strcpy(s,"domain error"); 
....................    return s; 
.................... case ERANGE: 
....................    strcpy(s,"range error"); 
....................    return s; 
.................... } 
.................... } 
.................... #ENDIF 
.................... /* standard template: size_t strlen(const char *s). 
....................    Computes length of s1 (preceding terminating 0) */ 
....................  
.................... int *strlen(char *s) 
.................... { 
....................    char *sc; 
....................  
....................    for (sc = s; *sc != 0; sc++); 
....................    return(sc - s); 
.................... } 
....................  
.................... /* standard template: size_t stricmp(const char *s1, const char *s2). 
....................    Compares s1 to s2 ignoring case (upper vs. lower) */ 
....................  
.................... signed int stricmp(char *s1, char *s2) 
.................... { 
....................  for(; *s1==*s2||(isalpha(*s1)&&isalpha(*s2)&&(*s1==*s2+32||*s2==*s1+32)); 
....................     s1++, s2++) 
....................     if (*s1 == '\0') 
....................        return(0); 
....................  return((*s1 < *s2) ? -1: 1); 
.................... } 
....................  
....................  
.................... /* standard template: char *strlwr(char *s). 
....................    Replaces uppercase letters by lowercase; 
....................    returns pointer to new string s */ 
....................  
.................... char *strlwr(char *s) 
.................... { 
....................    char *p; 
....................  
....................    for (p = s; *p != '\0'; p++) 
....................       if (*p >= 'A' && *p <='Z') 
....................          *p += 'a' - 'A'; 
....................    return(s); 
.................... } 
....................  
....................  
.................... /************************************************************/ 
....................  
....................  
.................... #endif 
....................  
....................  
.................... div_t div(signed int numer,signed int denom) 
.................... { 
....................    div_t val; 
....................    val.quot = numer / denom; 
....................    val.rem = numer - (denom * val.quot); 
....................    return (val); 
.................... } 
....................  
.................... ldiv_t ldiv(signed long numer,signed long denom) 
.................... { 
....................    ldiv_t val; 
....................    val.quot = numer / denom; 
....................    val.rem = numer - (denom * val.quot); 
....................    return (val); 
.................... } 
....................  
.................... float atof(char * s) 
.................... { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0; 
....................    char c; 
....................    int ptr = 0; 
....................  
....................    c = s[ptr++]; 
....................  
....................    if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................       if(c == '+') 
....................          c = s[ptr++]; 
....................  
....................       while((c >= '0' && c <= '9')) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          c = s[ptr++]; 
....................          while((c >= '0' && c <= '9')) { 
....................              pow10 = pow10*10; 
....................              result += (c - '0')/pow10; 
....................              c = s[ptr++]; 
....................          } 
....................       } 
....................  
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    return(result); 
.................... } 
....................  
.................... float atoe(char * s) 
.................... { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0; 
....................    int expsign = 0; 
....................    char c; 
....................    int ptr = 0; 
....................    int i; 
....................    float exp = 1.0; 
....................    int expcnt = 0; 
....................  
....................    c = s[ptr++]; 
....................  
....................    if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.' || c=='E' || c=='e') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................       if(c == '+') 
....................          c = s[ptr++]; 
....................  
....................       while((c >= '0' && c <= '9')) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          c = s[ptr++]; 
....................          while((c >= '0' && c <= '9')) { 
....................              pow10 = pow10*10; 
....................              result += (c - '0')/pow10; 
....................              c = s[ptr++]; 
....................          } 
....................       } 
....................  
....................       // Handling the exponent 
....................       if (c=='e' || c=='E') { 
....................          c = s[ptr++]; 
....................  
....................          if(c == '-') { 
....................             expsign = 1; 
....................             c = s[ptr++]; 
....................          } 
....................          if(c == '+') 
....................             c = s[ptr++]; 
....................  
....................          while((c >= '0' && c <= '9')) { 
....................             expcnt = 10*expcnt + c - '0'; 
....................             c = s[ptr++]; 
....................          } 
....................  
....................          for(i=0;i<expcnt;i++) 
....................             exp*=10; 
....................  
....................          if(expsign==1) 
....................             result/=exp; 
....................          else 
....................             result*=exp; 
....................       } 
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    return(result); 
.................... } 
....................  
.................... signed int atoi(char *s) 
.................... { 
....................    signed int result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    // Omit all preceeding alpha characters 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................  
....................       // Check for hexa number 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') 
....................          { 
....................             result = 10*result + (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ( (c >= '0' && c <= '9') || (c >= 'A' && c<='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++]; 
....................             c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (sign == 1 && base == 10) 
....................        result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... signed long atol(char *s) 
.................... { 
....................    signed long result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') 
....................          { 
....................             result = 10*result + (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ( (c >= '0' && c <= '9') || (c >= 'A' && c <='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++];c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (base == 10 && sign == 1) 
....................       result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... /* A fast routine to multiply by 10 
....................  */ 
.................... signed int32 mult_with10(int32 num) 
.................... { 
....................    return ( (num << 1) + (num << 3) ); 
.................... } 
....................  
.................... signed int32 atoi32(char *s) 
.................... { 
....................    signed int32 result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') { 
....................             result = (result << 1) + (result << 3);  // result *= 10; 
....................             result += (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ((c >= '0' && c <= '9') || (c >= 'A' && c <='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++];c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (base == 10 && sign == 1) 
....................       result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... char * itoa(signed int32 num, int8 base, char *s) 
.................... { 
....................      int32 temp=1; 
....................      int8 i,sign=0,cnt=0; 
....................      char c; 
....................  
....................      if(num<0) { 
....................          sign=1;        // Check for negative number 
....................          num*=-1; 
....................      } 
....................  
....................      while(temp>0) { 
....................          temp=(num/base); 
....................          s[cnt]=(num%base)+'0';    // Conversion 
....................  
....................          if(s[cnt]>0x39) 
....................             s[cnt]+=0x7; 
....................  
....................          cnt++; 
....................          num=temp; 
....................      } 
....................  
....................      if(sign==1) { 
....................          s[cnt]=0x2D;      // Negative sign 
....................          cnt++; 
....................      } 
....................  
....................      for(i = 0;i<(int8)(cnt/2);i++) { 
....................  
....................          c=s[i]; 
....................          s[i]=s[cnt-i-1];        // Reverse the number 
....................          s[cnt-i-1]=c; 
....................      } 
....................      s[cnt]='\0';     // End the string 
....................      return s; 
.................... } 
....................  
.................... float strtod(char *s,char *endptr) { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0, point = 0; 
....................    char c; 
....................    int ptr = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c=s[ptr++]; 
....................  
....................  
....................    while((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       while((c >= '0' && c <= '9') && point == 0) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          point = 1; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       while((c >= '0' && c <= '9') && point == 1) { 
....................          pow10 = pow10*10; 
....................          result += (c - '0')/pow10; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '+') { 
....................          c = s[ptr++]; 
....................       } 
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    if(endptr) 
....................    { 
....................       if (ptr) { 
....................          ptr--; 
....................          *((char *)endptr)=s+ptr; 
....................       } 
....................       else 
....................          *((char *)endptr)=s; 
....................    } 
....................  
....................    return(result); 
.................... } 
....................  
.................... long strtoul(char *s,char *endptr,signed int base) 
.................... { 
....................    char *sc,*s1,*sd; 
....................    unsigned long x=0; 
....................    char sign; 
....................    char digits[]="0123456789abcdefghijklmnopqstuvwxyz"; 
....................    for(sc=s;isspace(*sc);++sc); 
....................    sign=*sc=='-'||*sc=='+'?*sc++:'+'; 
....................    if(sign=='-') 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................       return 0; 
....................    } 
....................  
....................    if (base <0 || base ==1|| base >36) // invalid base 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................       return 0; 
....................    } 
....................    else if (base) 
....................    { 
....................       if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X')) 
....................          sc+=2; 
....................       if(base==8 && *sc =='0') 
....................          sc+=1; 
....................       if(base==2 && *sc =='0'&&sc[1]=='b') 
....................          sc+=2; 
....................  
....................    } 
....................    else if(*sc!='0') // base is 0, find base 
....................       base=10; 
....................    else if (sc[1]=='x' || sc[1]=='X') 
....................       base =16,sc+=2; 
....................    else if(sc[1]=='b') 
....................       base=2,sc+=2; 
....................    else 
....................       base=8; 
....................    for (s1=sc;*sc=='0';++sc);// skip leading zeroes 
....................    sd=memchr(digits,tolower(*sc),base); 
....................    for(; sd!=0; ) 
....................    { 
....................       x=x*base+(int16)(sd-digits); 
....................       ++sc; 
....................       sd=memchr(digits,tolower(*sc),base); 
....................    } 
....................    if(s1==sc) 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................    return 0; 
....................    } 
....................    if (endptr) 
....................         *((char *)endptr)=sc; 
....................    return x; 
.................... } 
....................  
....................  
.................... signed long strtol(char *s,char *endptr,signed int base) 
.................... { 
....................    char *sc,*s1,*sd; 
....................    signed long x=0; 
....................    char sign; 
....................    char digits[]="0123456789abcdefghijklmnopqstuvwxyz"; 
....................    for(sc=s;isspace(*sc);++sc); 
....................    sign=*sc=='-'||*sc=='+'?*sc++:'+'; 
....................    if (base <0 || base ==1|| base >36) // invalid base 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................       return 0; 
....................    } 
....................    else if (base) 
....................    { 
....................       if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X')) 
....................          sc+=2; 
....................       if(base==8 && *sc =='0') 
....................          sc+=1; 
....................       if(base==2 && *sc =='0'&&sc[1]=='b') 
....................          sc+=2; 
....................  
....................    } 
....................    else if(*sc!='0') // base is 0, find base 
....................       base=10; 
....................    else if (sc[1]=='x' || sc[1]=='X') 
....................       base =16,sc+=2; 
....................    else if(sc[1]=='b') 
....................       base=2,sc+=2; 
....................    else 
....................       base=8; 
....................    for (s1=sc;*sc=='0';++sc);// skip leading zeroes 
....................  
....................    sd=memchr(digits,tolower(*sc),base); 
....................    for(;sd!=0;) 
....................    { 
....................       x=x*base+(int16)(sd-digits); 
....................       ++sc; 
....................       sd=memchr(digits,tolower(*sc),base); 
....................    } 
....................    if(s1==sc) 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................    return 0; 
....................    } 
....................    if(sign=='-') 
....................       x  =-x; 
....................    if (endptr) 
....................         *((char *)endptr)=sc; 
....................    return x; 
.................... } 
....................  
.................... signed int system(char *string) 
.................... { 
....................    return 0; 
.................... } 
....................  
.................... int mblen(char *s,size_t n) 
.................... { 
....................    return strlen(s); 
.................... } 
....................  
.................... int mbtowc(wchar_t *pwc,char *s,size_t n) 
.................... { 
....................    *pwc=*s; 
....................    return 1; 
.................... } 
....................  
.................... int wctomb(char *s,wchar_t wchar) 
.................... { 
....................    *s=wchar; 
....................    return 1; 
.................... } 
....................  
.................... size_t mbstowcs(wchar_t *pwcs,char *s,size_t n) 
.................... { 
....................    strncpy(pwcs,s,n); 
....................    return strlen(pwcs); 
.................... } 
....................  
.................... size_t wcstombs(char *s,wchar_t *pwcs,size_t n) 
.................... { 
....................    strncpy(s,pwcs,n); 
....................    return strlen(s); 
.................... } 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // The random number implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... unsigned int32 _Randseed; 
....................  
.................... long rand(void) 
.................... { 
....................    _Randseed = _Randseed * 1103515245 + 12345; 
....................    return ((unsigned long)(_Randseed >> 16) % RAND_MAX); 
.................... } 
....................  
.................... void srand(unsigned int32 seed) 
.................... { 
....................    _Randseed = seed; 
.................... } 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Searching and sorting utilities implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... typedef signed int (*_Cmpfun)(char * p1,char * p2); 
....................  
.................... void qsort(char * qdata, int qitems, int qsize, _Cmpfun cmp) { 
....................    int m,j,i,l; 
....................    short done; 
....................    BYTE t[16]; 
....................  
....................    m = qitems/2; 
....................    while( m > 0 ) { 
....................      for(j=0; j<(qitems-m); ++j) { 
....................         i = j; 
....................         do 
....................         { 
....................            done=TRUE; 
....................            l = i+m; 
....................            if( (*cmp)(qdata+i*qsize, qdata+l*qsize) > 0 ) { 
....................               memcpy(t, qdata+i*qsize, qsize); 
....................               memcpy(qdata+i*qsize, qdata+l*qsize, qsize); 
....................               memcpy(qdata+l*qsize, t, qsize); 
....................               if(m <= i) 
....................                 i -= m; 
....................                 done = FALSE; 
....................            } 
....................         } while(!done); 
....................      } 
....................      m = m/2; 
....................    } 
.................... } 
....................  
....................  
.................... char *bsearch(char *key, char *base, size_t num, size_t width,_Cmpfun cmp) 
.................... { 
....................    char *p, *q; 
....................    size_t n; 
....................    size_t pivot; 
....................    signed int val; 
....................  
....................    p = base; 
....................    n = num; 
....................  
....................    while (n > 0) 
....................    { 
....................       pivot = n >> 1; 
....................       q = p + width * pivot; 
....................  
....................       val = (*cmp)(key, q); 
....................  
....................       if (val < 0) 
....................          n = pivot; 
....................       else if (val == 0) 
....................          return ((char *)q); 
....................       else { 
....................          p = q + width; 
....................          n -= pivot + 1; 
....................       } 
....................    } 
....................  
....................    return NULL;      // There's no match 
.................... } 
....................  
....................  
.................... #endif 
....................  
.................... #include <stdio.h> 
.................... /////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services           //// 
.................... //// This source code may only be used by licensed users of the CCS C  //// 
.................... //// compiler.  This source code may only be distributed to other      //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction //// 
.................... //// or distribution is permitted without written permission.          //// 
.................... //// Derivative programs created using this software in object code    //// 
.................... //// form are not restricted in any way.                               //// 
.................... /////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STDIO 
.................... #define _STDIO 
.................... #include <string.h> 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services            //// 
.................... //// This source code may only be used by licensed users of the CCS C   //// 
.................... //// compiler.  This source code may only be distributed to other       //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction  //// 
.................... //// or distribution is permitted without written permission.           //// 
.................... //// Derivative programs created using this software in object code     //// 
.................... //// form are not restricted in any way.                                //// 
.................... //////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STRING 
.................... #define _STRING 
.................... #include <stddef.h> 
.................... #include <ctype.h> 
....................  
....................  
....................  
.................... ////////////////////////////////////////////// 
.................... //// Uncomment the following define to    //// 
.................... //// allow some functions to use a        //// 
.................... //// quicker algorithm, but use more ROM  //// 
.................... ////                                      //// 
.................... //// #define FASTER_BUT_MORE_ROM          //// 
.................... ////////////////////////////////////////////// 
....................  
....................  
....................  
.................... /*Copying functions*/ 
.................... /* standard template: 
....................    void *memmove(void *s1, void *s2, size_t n). 
....................    Copies max of n characters safely (not following ending '\0') 
....................    from s2 in s1; if s2 has less than n characters, appends 0 */ 
....................  
.................... char *memmove(void *s1,char *s2,size_t n) 
.................... { 
....................    char *sc1; 
....................    char *sc2; 
....................    sc1=s1; 
....................    sc2=s2; 
....................    if(sc2<sc1 && sc1 <sc2 +n) 
....................       for(sc1+=n,sc2+=n;0<n;--n) 
....................          *--sc1=*--sc2; 
....................    else 
....................       for(;0<n;--n) 
....................          *sc1++=*sc2++; 
....................   return s1; 
....................   } 
....................  
.................... /* compiler ignored the name 'strcpy()'; perhaps, it's reserved? 
....................    Standard template: char *strcpy(char *s1, const char *s2) 
....................    copies the string s2 including the null character to s1*/ 
....................  
.................... char *strcopy(char *s1, char *s2) 
.................... { 
....................   char *s; 
....................  
....................   for (s = s1; *s2 != 0; s++, s2++) { 
....................      *s = *s2; 
....................   } 
....................   *s = *s2; 
....................   return(s1); 
.................... } 
....................  
.................... /* standard template: 
....................    char *strncpy(char *s1, const char *s2, size_t n). 
....................    Copies max of n characters (not following ending '\0') 
....................    from s2 in s1; if s2 has less than n characters, appends 0 */ 
....................  
.................... char *strncpy(char *s1, char *s2, size_t n) 
.................... { 
....................   char *s; 
....................  
....................   for (s = s1; n > 0 && *s2 != '\0'; n--) 
....................      *s++ = *s2++; 
....................   for (; n > 0; n--) 
....................      *s++ = '\0'; 
....................  
....................   return(s1); 
.................... } 
.................... /***********************************************************/ 
....................  
.................... /*concatenation functions*/ 
.................... /* standard template: char *strcat(char *s1, const char *s2) 
.................... appends s2 to s1*/ 
....................  
.................... char *strcat(char *s1, char *s2) 
.................... { 
....................    char *s; 
....................  
....................    for (s = s1; *s != '\0'; ++s); 
....................    while(*s2 != '\0') 
....................    { 
....................       *s = *s2; 
....................       ++s; 
....................       ++s2; 
....................    } 
....................  
....................    *s = '\0'; 
....................    return(s1); 
.................... } 
.................... /* standard template: char *strncat(char *s1, char *s2,size_t n) 
.................... appends not more than n characters from s2 to s1*/ 
....................  
.................... char *strncat(char *s1, char *s2, size_t n) 
.................... { 
....................    char *s; 
....................  
....................    for (s = s1; *s != '\0'; ++s); 
....................    while(*s2 != '\0' && 0<n) 
....................    { 
....................       *s = *s2; 
....................       ++s; 
....................       ++s2; 
....................       --n; 
....................    } 
....................  
....................    *s = '\0'; 
....................    return(s1); 
.................... } 
....................  
.................... /***********************************************************/ 
....................  
....................  
.................... /*comparison functions*/ 
.................... /* standard template: signed int memcmp(void *s1, void *s2). 
....................    Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ 
....................  
.................... signed int memcmp(void * s1,char *s2,size_t n) 
.................... { 
.................... char *su1, *su2; 
.................... for(su1=s1, su2=s2; 0<n; ++su1, ++su2, --n) 
.................... { 
....................    if(*su1!=*su2) 
....................       return ((*su1<*su2)?-1:+1); 
.................... } 
.................... return 0; 
.................... } 
....................  
.................... /* standard template: int strcmp(const char *s1, const char *s2). 
....................    Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ 
....................  
.................... signed int strcmp(char *s1, char *s2) 
.................... { 
....................    for (; *s1 == *s2; s1++, s2++) 
....................       if (*s1 == '\0') 
....................          return(0); 
....................    return((*s1 < *s2) ? -1: 1); 
.................... } 
.................... /* standard template: int strcoll(const char *s1, const char *s2). 
....................    Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ 
....................  
.................... signed int strcoll(char *s1, char *s2) 
.................... { 
....................    for (; *s1 == *s2; s1++, s2++) 
....................       if (*s1 == '\0') 
....................          return(0); 
....................    return((*s1 < *s2) ? -1: 1); 
.................... } 
....................  
.................... /* standard template: 
....................    int strncmp(const char *s1, const char *s2, size_t n). 
....................    Compares max of n characters (not following 0) from s1 to s2; 
....................    returns same as strcmp */ 
....................  
.................... signed int strncmp(char *s1, char *s2, size_t n) 
.................... { 
....................    for (; n > 0; s1++, s2++, n--) 
....................       if (*s1 != *s2) 
....................          return((*s1 <*s2) ? -1: 1); 
....................       else if (*s1 == '\0') 
....................          return(0); 
....................    return(0); 
.................... } 
.................... /* standard template: 
....................    int strxfrm(const char *s1, const char *s2, size_t n). 
....................    transforms maximum of n characters from s2 and places them into s1*/ 
.................... size_t strxfrm(char *s1, char *s2, size_t n) 
.................... { 
....................   char *s; 
....................   int n1; 
....................   n1=n; 
....................   for (s = s1; n > 0 && *s2 != '\0'; n--) 
....................      *s++ = *s2++; 
....................   for (; n > 0; n--) 
....................      *s++ = '\0'; 
....................  
....................   return(n1); 
.................... } 
....................  
....................  
....................  
....................  
....................  
.................... /***********************************************************/ 
.................... /*Search functions*/ 
.................... /* standard template: void *memchr(const char *s, int c). 
....................    Finds first occurrence of c in n characters of s */ 
....................  
.................... char *memchr(void *s,int c,size_t n) 
.................... { 
....................    char uc; 
....................    char *su; 
....................    uc=c; 
....................    for(su=s;0<n;++su,--n) 
....................       if(*su==uc) 
....................       return su; 
....................    return NULL; 
.................... } 
....................  
.................... /* standard template: char *strchr(const char *s, int c). 
....................    Finds first occurrence of c in s */ 
....................  
.................... char *strchr(char *s, int c) 
.................... { 
....................    for (; *s != c; s++) 
....................       if (*s == '\0') 
....................          return(0); 
....................    return(s); 
.................... } 
.................... /* standard template: 
....................    size_t strcspn(const char *s1, const char *s2). 
....................    Computes length of max initial segment of s1 that 
....................    consists entirely of characters NOT from s2*/ 
....................  
.................... int *strcspn(char *s1, char *s2) 
.................... { 
....................    char *sc1, *sc2; 
....................  
....................    for (sc1 = s1; *sc1 != 0; sc1++) 
....................       for (sc2 = s2; *sc2 != 0; sc2++) 
....................          if (*sc1 == *sc2) 
....................             return(sc1 - s1); 
....................    return(sc1 - s1); 
.................... } 
.................... /* standard template: 
....................    char *strpbrk(const char *s1, const char *s2). 
....................    Locates first occurence of any character from s2 in s1; 
....................    returns s1 if s2 is empty string */ 
....................  
.................... char *strpbrk(char *s1, char *s2) 
.................... { 
....................    char *sc1, *sc2; 
....................  
....................    for (sc1 = s1; *sc1 != 0; sc1++) 
....................       for (sc2 = s2; *sc2 != 0; sc2++) 
....................          if (*sc1 == *sc2) 
....................             return(sc1); 
....................    return(0); 
.................... } 
....................  
....................  
.................... /* standard template: char *strrchr(const char *s, int c). 
....................    Finds last occurrence of c in s */ 
....................  
.................... char *strrchr(char *s, int c) 
.................... { 
....................    char *p; 
....................  
....................    for (p = 0; ; s++) 
....................    { 
....................       if (*s == c) 
....................          p = s; 
....................       if (*s == '\0') 
....................          return(p); 
....................    } 
.................... } 
.................... /* computes length of max initial segment of s1 consisting 
....................    entirely of characters from s2 */ 
....................  
.................... int *strspn(char *s1, char *s2) 
.................... { 
....................    char *sc1, *sc2; 
....................  
....................    for (sc1 = s1; *sc1 != 0; sc1++) 
....................       for (sc2 = s2; ; sc2++) 
....................     if (*sc2 == '\0') 
....................        return(sc1 - s1); 
....................          else if (*sc1 == *sc2) 
....................             break; 
....................    return(sc1 - s1); 
.................... } 
.................... /* standard template: 
....................    char *strstr(const char *s1, const char *s2); 
....................    Locates first occurence of character sequence s2 in s1; 
....................    returns 0 if s2 is empty string 
....................  
....................    Uncomment #define FASTER_BUT_MORE_ROM at the top of the 
....................    file to use the faster algorithm */ 
.................... char *strstr(char *s1, char *s2) 
.................... { 
....................    char *s, *t; 
....................  
....................    #ifdef FASTER_BUT_MORE_ROM 
....................    if (*s2 == '\0') 
....................          return(s1); 
....................    #endif 
....................  
....................    while (*s1) 
....................    { 
....................       for(s = s1, t = s2; *t && (*s == *t); ++s, ++t); 
....................  
....................       if (*t == '\0') 
....................          return s1; 
....................       ++s1; 
....................       #ifdef FASTER_BUT_MORE_ROM 
....................          while(*s1 != '\0' && *s1 != *s2) 
....................             ++s1; 
....................       #endif 
....................    } 
....................    return 0; 
.................... } 
....................  
.................... /* standard template: char *strtok(char *s1, const char *s2). 
....................  
....................    Finds next token in s1 delimited by a character from separator 
....................    string s2 (which can be different from call to call).  First call 
....................    starts at beginning of s1 searching for first character NOT 
....................    contained in s2; returns 0 if none is found. 
....................    If one is found, it is the start of first token (return value). 
....................    Function then searches from there for a character contained in s2. 
....................    If none is found, current token extends to end of s1, and subsequent 
....................    searches for a token will return 0.  If one is found, it is 
....................    overwritten by '\0', which terminates current token.  Function saves 
....................    pointer to following character from which next search will start. 
....................    Each subsequent call, with 0 as first argument, starts searching 
....................    from saved pointer */ 
....................  
.................... char *strtok(char *s1, char *s2) 
.................... { 
....................    char *beg, *end; 
....................    static char *save; 
....................  
....................    beg = (s1)? s1: save; 
....................    beg += strspn(beg, s2); 
....................    if (*beg == '\0') 
....................    { 
....................       *save = ' '; 
....................       return(0); 
....................    } 
....................    end = strpbrk(beg, s2); 
....................    if (*end != '\0') 
....................    { 
....................       *end = '\0'; 
....................       end++; 
....................    } 
....................    save = end; 
....................    return(beg); 
.................... } 
....................  
.................... /*****************************************************************/ 
.................... /*Miscellaneous functions*/ 
.................... /* standard template 
.................... maps error number in errnum to an error message string 
.................... Returns: Pointer to string 
.................... */ 
.................... #ifdef _ERRNO 
.................... char * strerror(int errnum) 
.................... { 
.................... char s[15]; 
.................... switch( errnum) 
.................... { 
.................... case 0: 
....................    strcpy(s,"no errors"); 
....................    return s; 
.................... case EDOM : 
....................    strcpy(s,"domain error"); 
....................    return s; 
.................... case ERANGE: 
....................    strcpy(s,"range error"); 
....................    return s; 
.................... } 
.................... } 
.................... #ENDIF 
.................... /* standard template: size_t strlen(const char *s). 
....................    Computes length of s1 (preceding terminating 0) */ 
....................  
.................... int *strlen(char *s) 
.................... { 
....................    char *sc; 
....................  
....................    for (sc = s; *sc != 0; sc++); 
....................    return(sc - s); 
.................... } 
....................  
.................... /* standard template: size_t stricmp(const char *s1, const char *s2). 
....................    Compares s1 to s2 ignoring case (upper vs. lower) */ 
....................  
.................... signed int stricmp(char *s1, char *s2) 
.................... { 
....................  for(; *s1==*s2||(isalpha(*s1)&&isalpha(*s2)&&(*s1==*s2+32||*s2==*s1+32)); 
....................     s1++, s2++) 
....................     if (*s1 == '\0') 
....................        return(0); 
....................  return((*s1 < *s2) ? -1: 1); 
.................... } 
....................  
....................  
.................... /* standard template: char *strlwr(char *s). 
....................    Replaces uppercase letters by lowercase; 
....................    returns pointer to new string s */ 
....................  
.................... char *strlwr(char *s) 
.................... { 
....................    char *p; 
....................  
....................    for (p = s; *p != '\0'; p++) 
....................       if (*p >= 'A' && *p <='Z') 
....................          *p += 'a' - 'A'; 
....................    return(s); 
.................... } 
....................  
....................  
.................... /************************************************************/ 
....................  
....................  
.................... #endif 
....................  
.................... #ifndef getc 
.................... #define getc getch 
.................... #define getchar getch 
.................... #define puts(s) {printf(s); putchar(13); putchar(10);} 
.................... #define putc putchar 
.................... #endif 
.................... /* maps error number to an error message. Writes a sequence of characters to 
.................... stderr stream thus: if s is not null then string pointed to by s follwed by 
.................... a colon (:) and a space and the appropriate error message returned by strerror 
.................... function with argument errno 
....................  
.................... Returns: no value 
.................... */ 
....................  
.................... #ifdef _ERRNO 
.................... void perror(char *s) 
.................... { 
....................   if(s) 
....................   fprintf(STDERR,"%s: ",s); 
....................   fprintf(STDERR,"%s\r\n",strerror(errno)); 
.................... } 
.................... #endif 
.................... #endif 
....................  
.................... #use delay(clock=4000000, restart_wdt) 
*
0285:  MOVLW  11
0286:  MOVWF  04
0287:  BSF    03.7
0288:  MOVF   00,W
0289:  BTFSC  03.2
028A:  GOTO   29C
028B:  MOVLW  01
028C:  MOVWF  78
028D:  MOVLW  BF
028E:  MOVWF  77
028F:  CLRWDT
0290:  DECFSZ 77,F
0291:  GOTO   28F
0292:  DECFSZ 78,F
0293:  GOTO   28D
0294:  MOVLW  4A
0295:  MOVWF  77
0296:  DECFSZ 77,F
0297:  GOTO   296
0298:  NOP
0299:  CLRWDT
029A:  DECFSZ 00,F
029B:  GOTO   28B
029C:  RETLW  00
*
03E1:  MOVLW  12
03E2:  BSF    03.5
03E3:  SUBWF  3F,F
03E4:  BTFSS  03.0
03E5:  GOTO   3F5
03E6:  MOVLW  BF
03E7:  MOVWF  04
03E8:  BCF    03.7
03E9:  MOVLW  FC
03EA:  ANDWF  00,F
03EB:  BCF    03.0
03EC:  RRF    00,F
03ED:  RRF    00,F
03EE:  MOVF   00,W
03EF:  BTFSC  03.2
03F0:  GOTO   3F5
03F1:  GOTO   3F3
03F2:  CLRWDT
03F3:  DECFSZ 00,F
03F4:  GOTO   3F2
03F5:  BCF    03.5
03F6:  BCF    0A.3
03F7:  BCF    0A.4
03F8:  GOTO   422 (RETURN)
.................... #include "Gulper_Main.h" 
.................... /****************************************************************************/ 
.................... /* Copyright 2006 MBARI.                                                    */ 
.................... /* Monterey Bay Aquarium Research Institute Proprietary Information.        */ 
.................... /* All rights reserved.                                                     */ 
.................... /****************************************************************************/ 
.................... #ifndef PH_PROBE_H 
.................... #define PH_PROBE_H 
....................  
.................... #define VS_VERSION  "0.1" 
.................... #define DEBUG 0 
....................  
....................  
.................... int8 fire[]="F"; 
*
08C0:  MOVLW  46
08C1:  MOVWF  2F
08C2:  CLRF   30
.................... int8 query[]="Q"; 
08C3:  MOVLW  51
08C4:  MOVWF  31
08C5:  CLRF   32
.................... int8 status[]= "S"; 
08C6:  MOVLW  53
08C7:  MOVWF  33
08C8:  CLRF   34
.................... int8 version[]="V"; 
08C9:  MOVLW  56
08CA:  MOVWF  35
08CB:  CLRF   36
.................... int8 actuation[]="A"; 
08CC:  MOVLW  41
08CD:  MOVWF  37
08CE:  CLRF   38
....................  
.................... char response_message[20]; // String for storing node response back to MVC 
....................  
....................  
.................... int32 seconds = 0;      // A running seconds counter 
08CF:  CLRF   4D
08D0:  CLRF   4E
08D1:  CLRF   4F
08D2:  CLRF   50
.................... int8 int_count = 0;    // Number of interrupts left before a second has elapsed 
08D3:  CLRF   51
.................... int32 ElapsedSeconds = 0;      // A running seconds counter 
08D4:  CLRF   52
08D5:  CLRF   53
08D6:  CLRF   54
08D7:  CLRF   55
.................... int32 Final_Proximity_Milliseconds = 0; // Used to store time between fire and proximity sensor 
08D8:  CLRF   56
08D9:  CLRF   57
08DA:  CLRF   58
08DB:  CLRF   59
.................... int32 Final_Actuation_Milliseconds = 0; // Used to store time between fire and pin puller voltage >= 2 volts 
08DC:  CLRF   5A
08DD:  CLRF   5B
08DE:  CLRF   5C
08DF:  CLRF   5D
.................... int8 Elapsed_int_count = 0;    // Number of interrupts left before a second has elapsed 
08E0:  CLRF   5E
....................  
.................... Boolean Fired = false; // Fire command received? 
08E1:  BCF    5F.0
.................... Boolean proximity = false; //Proximity sensor ISR called? 
08E2:  BCF    5F.1
.................... Boolean proximity_expired = false; // Set true at 30 seconds past firing if no prox interrupt received 
08E3:  BCF    5F.2
.................... Boolean bad_address = false; // Address out of range? 
08E4:  BCF    5F.3
....................  
....................  
.................... /* 
....................     The ticks per second is based on an 8-bit counter over flowing that 
....................     is driven by a 4 Mhz ocsillator prescaled by 4 and postscaled by 64. 
....................  
....................     TICKS_PER_SEC = (OSC_CLK) / (PRESCALE) / (POSTSCALE) / (8_BIT_OVERFLOW) 
....................                   = 4000000   /     4      /      64     /      256 
....................                   = 61.0351 
.................... */ 
.................... #define TICKS_PER_SEC   61 
....................  
.................... #define HI  1 
.................... #define LO  0 
....................  
.................... #define ON  1 
.................... #define OFF 0 
....................  
.................... void startTimer(void); 
.................... void getElapsedTime(void); 
....................  
.................... #endif 
....................  
.................... #include "RS485.c" 
.................... /****************************************************************************/ 
.................... /* Copyright 2004 MBARI.                                                    */ 
.................... /* Monterey Bay Aquarium Research Institute Proprietary Information.        */ 
.................... /* All rights reserved.                                                     */ 
.................... /****************************************************************************/ 
....................  
....................  
.................... #include <stdlib.h> 
.................... /////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services           //// 
.................... //// This source code may only be used by licensed users of the CCS C  //// 
.................... //// compiler.  This source code may only be distributed to other      //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction //// 
.................... //// or distribution is permitted without written permission.          //// 
.................... //// Derivative programs created using this software in object code    //// 
.................... //// form are not restricted in any way.                               //// 
.................... /////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STDLIB 
.................... #define _STDLIB 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Definitions and types 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #ifndef RAND_MAX 
.................... #define RAND_MAX  32767    // The value of which is the maximum value 
....................                            // ... returned by the rand function 
.................... #endif 
....................  
.................... typedef struct { 
....................    signed int quot; 
....................    signed int rem; 
.................... } div_t; 
....................  
.................... typedef struct { 
....................    signed long quot; 
....................    signed long rem; 
.................... } ldiv_t; 
....................  
.................... #include <stddef.h> 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // String conversion functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* Standard template: float atof(char * s) 
....................  * converts the initial portion of the string s to a float. 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... float atof(char * s); 
....................  
.................... /* Standard template: float atoe(char * s) 
....................  * converts the initial portion of the string s to a float. 
....................  * returns the converted value if any, 0 otherwise 
....................  * also handles E format numbers 
....................  */ 
.................... float atoe(char * s); 
....................  
.................... /* Standard template: signed int  atoi(char * s) 
....................  * converts the initial portion of the string s to a signed int 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... signed int atoi(char *s); 
....................  
.................... /* Syntax: signed int32  atoi32(char * s) 
....................    converts the initial portion of the string s to a signed int32 
....................    returns the converted value if any, 0 otherwise*/ 
.................... signed int32 atoi32(char *s); 
....................  
.................... /* Syntax: char *  itoa(signed int32 num, int8 base, char * s) 
....................    converts the signed int32 to a string and 
....................    returns the converted value if any, 0 otherwise*/ 
.................... char * itoa(signed int32 num, int8 base, char * s); 
....................  
.................... /* Standard template: signed long  atol(char * s) 
....................  * converts the initial portion of the string s to a signed long 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... signed long atol(char *s); 
....................  
.................... /* Standard template: float strtol(char * s,char *endptr) 
....................  * converts the initial portion of the string s to a float 
....................  * returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... float strtod(char *s,char *endptr); 
....................  
.................... /* Standard template: long strtoul(char * s,char *endptr,signed int base) 
....................  * converts the initial portion of the string s, represented as an 
....................  * integral value of radix base  to a signed long. 
....................  * Returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... signed long strtol(char *s,char *endptr,signed int base); 
....................  
.................... /* Standard template: long strtoul(char * s,char *endptr,signed int base) 
....................  * converts the initial portion of the string s, represented as an 
....................  * integral value of radix base to a unsigned long. 
....................  * returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... long strtoul(char *s,char *endptr,signed int base); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Pseudo-random sequence generation functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* The rand function computes a sequence of pseudo-random integers in 
....................  * the range 0 to RAND_MAX 
....................  * 
....................  * Parameters: 
....................  *       (none) 
....................  * 
....................  * Returns: 
....................  *       The pseudo-random integer 
....................  */ 
.................... long rand(void); 
....................  
.................... /* The srand function uses the argument as a seed for a new sequence of 
....................  * pseudo-random numbers to be returned by subsequent calls to rand. 
....................  * 
....................  * Parameters: 
....................  *       [in] seed: The seed value to start from. You might need to pass 
....................  * 
....................  * Returns: 
....................  *       (none) 
....................  * 
....................  * Remarks 
....................  *          The srand function sets the starting point for generating 
....................  *       a series of pseudorandom integers. To reinitialize the 
....................  *       generator, use 1 as the seed argument. Any other value for 
....................  *       seed sets the generator to a random starting point. rand 
....................  *       retrieves the pseudorandom numbers that are generated. 
....................  *       Calling rand before any call to srand generates the same 
....................  *       sequence as calling srand with seed passed as 1. 
....................  *          Usually, you need to pass a time here from outer source 
....................  *       so that the numbers will be different every time you run. 
....................  */ 
.................... void srand(unsigned int32 seed); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Memory management functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Comming soon 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Communication with the environment 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* The function returns 0 always 
....................  */ 
.................... signed int system(char *string); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Searching and sorting utilities 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* Performs a binary search of a sorted array.. 
....................  * 
....................  * Parameters: 
....................  *       [in] key: Object to search for 
....................  *       [in] base: Pointer to base of search data 
....................  *       [in] num: Number of elements 
....................  *       [in] width: Width of elements 
....................  *       [in] compare: Function that compares two elements 
....................  * 
....................  * Returns: 
....................  *       bsearch returns a pointer to an occurrence of key in the array pointed 
....................  *       to by base. If key is not found, the function returns NULL. If the 
....................  *       array is not in order or contains duplicate records with identical keys, 
....................  *       the result is unpredictable. 
....................  */ 
.................... //void *bsearch(const void *key, const void *base, size_t num, size_t width, 
.................... //              int (*compare)(const void *, const void *)); 
....................  
.................... /* Performs the shell-metzner sort (not the quick sort algorithm). The contents 
....................  * of the array are sorted into ascending order according to a comparison 
....................  * function pointed to by compar. 
....................  * 
....................  * Parameters: 
....................  *       [in] base: Pointer to base of search data 
....................  *       [in] num: Number of elements 
....................  *       [in] width: Width of elements 
....................  *       [in] compare: Function that compares two elements 
....................  * 
....................  * Returns: 
....................  *       (none) 
....................  */ 
.................... //void *qsort(const void *base, size_t num, size_t width, 
.................... //              int (*compare)(const void *, const void *)); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Integer arithmetic functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #define labs abs 
....................  
.................... div_t div(signed int numer,signed int denom); 
.................... ldiv_t ldiv(signed long numer,signed long denom); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Multibyte character functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Not supported 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Multibyte string functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Not supported 
....................  
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Internal implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #include <stddef.h> 
.................... #include <string.h> 
....................  
.................... div_t div(signed int numer,signed int denom) 
.................... { 
....................    div_t val; 
....................    val.quot = numer / denom; 
....................    val.rem = numer - (denom * val.quot); 
....................    return (val); 
.................... } 
....................  
.................... ldiv_t ldiv(signed long numer,signed long denom) 
.................... { 
....................    ldiv_t val; 
....................    val.quot = numer / denom; 
....................    val.rem = numer - (denom * val.quot); 
....................    return (val); 
.................... } 
....................  
.................... float atof(char * s) 
.................... { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0; 
....................    char c; 
....................    int ptr = 0; 
....................  
....................    c = s[ptr++]; 
....................  
....................    if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................       if(c == '+') 
....................          c = s[ptr++]; 
....................  
....................       while((c >= '0' && c <= '9')) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          c = s[ptr++]; 
....................          while((c >= '0' && c <= '9')) { 
....................              pow10 = pow10*10; 
....................              result += (c - '0')/pow10; 
....................              c = s[ptr++]; 
....................          } 
....................       } 
....................  
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    return(result); 
.................... } 
....................  
.................... float atoe(char * s) 
.................... { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0; 
....................    int expsign = 0; 
....................    char c; 
....................    int ptr = 0; 
....................    int i; 
....................    float exp = 1.0; 
....................    int expcnt = 0; 
....................  
....................    c = s[ptr++]; 
....................  
....................    if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.' || c=='E' || c=='e') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................       if(c == '+') 
....................          c = s[ptr++]; 
....................  
....................       while((c >= '0' && c <= '9')) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          c = s[ptr++]; 
....................          while((c >= '0' && c <= '9')) { 
....................              pow10 = pow10*10; 
....................              result += (c - '0')/pow10; 
....................              c = s[ptr++]; 
....................          } 
....................       } 
....................  
....................       // Handling the exponent 
....................       if (c=='e' || c=='E') { 
....................          c = s[ptr++]; 
....................  
....................          if(c == '-') { 
....................             expsign = 1; 
....................             c = s[ptr++]; 
....................          } 
....................          if(c == '+') 
....................             c = s[ptr++]; 
....................  
....................          while((c >= '0' && c <= '9')) { 
....................             expcnt = 10*expcnt + c - '0'; 
....................             c = s[ptr++]; 
....................          } 
....................  
....................          for(i=0;i<expcnt;i++) 
....................             exp*=10; 
....................  
....................          if(expsign==1) 
....................             result/=exp; 
....................          else 
....................             result*=exp; 
....................       } 
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    return(result); 
.................... } 
....................  
.................... signed int atoi(char *s) 
.................... { 
....................    signed int result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    // Omit all preceeding alpha characters 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................  
....................       // Check for hexa number 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') 
....................          { 
....................             result = 10*result + (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ( (c >= '0' && c <= '9') || (c >= 'A' && c<='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++]; 
....................             c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (sign == 1 && base == 10) 
....................        result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... signed long atol(char *s) 
.................... { 
....................    signed long result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') 
....................          { 
....................             result = 10*result + (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ( (c >= '0' && c <= '9') || (c >= 'A' && c <='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++];c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (base == 10 && sign == 1) 
....................       result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... /* A fast routine to multiply by 10 
....................  */ 
.................... signed int32 mult_with10(int32 num) 
.................... { 
....................    return ( (num << 1) + (num << 3) ); 
.................... } 
....................  
.................... signed int32 atoi32(char *s) 
.................... { 
....................    signed int32 result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') { 
....................             result = (result << 1) + (result << 3);  // result *= 10; 
....................             result += (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ((c >= '0' && c <= '9') || (c >= 'A' && c <='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++];c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (base == 10 && sign == 1) 
....................       result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... char * itoa(signed int32 num, int8 base, char *s) 
.................... { 
....................      int32 temp=1; 
....................      int8 i,sign=0,cnt=0; 
....................      char c; 
....................  
....................      if(num<0) { 
....................          sign=1;        // Check for negative number 
....................          num*=-1; 
....................      } 
....................  
....................      while(temp>0) { 
....................          temp=(num/base); 
....................          s[cnt]=(num%base)+'0';    // Conversion 
....................  
....................          if(s[cnt]>0x39) 
....................             s[cnt]+=0x7; 
....................  
....................          cnt++; 
....................          num=temp; 
....................      } 
....................  
....................      if(sign==1) { 
....................          s[cnt]=0x2D;      // Negative sign 
....................          cnt++; 
....................      } 
....................  
....................      for(i = 0;i<(int8)(cnt/2);i++) { 
....................  
....................          c=s[i]; 
....................          s[i]=s[cnt-i-1];        // Reverse the number 
....................          s[cnt-i-1]=c; 
....................      } 
....................      s[cnt]='\0';     // End the string 
....................      return s; 
.................... } 
....................  
.................... float strtod(char *s,char *endptr) { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0, point = 0; 
....................    char c; 
....................    int ptr = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c=s[ptr++]; 
....................  
....................  
....................    while((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       while((c >= '0' && c <= '9') && point == 0) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          point = 1; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       while((c >= '0' && c <= '9') && point == 1) { 
....................          pow10 = pow10*10; 
....................          result += (c - '0')/pow10; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '+') { 
....................          c = s[ptr++]; 
....................       } 
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    if(endptr) 
....................    { 
....................       if (ptr) { 
....................          ptr--; 
....................          *((char *)endptr)=s+ptr; 
....................       } 
....................       else 
....................          *((char *)endptr)=s; 
....................    } 
....................  
....................    return(result); 
.................... } 
....................  
.................... long strtoul(char *s,char *endptr,signed int base) 
.................... { 
....................    char *sc,*s1,*sd; 
....................    unsigned long x=0; 
....................    char sign; 
....................    char digits[]="0123456789abcdefghijklmnopqstuvwxyz"; 
....................    for(sc=s;isspace(*sc);++sc); 
....................    sign=*sc=='-'||*sc=='+'?*sc++:'+'; 
....................    if(sign=='-') 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................       return 0; 
....................    } 
....................  
....................    if (base <0 || base ==1|| base >36) // invalid base 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................       return 0; 
....................    } 
....................    else if (base) 
....................    { 
....................       if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X')) 
....................          sc+=2; 
....................       if(base==8 && *sc =='0') 
....................          sc+=1; 
....................       if(base==2 && *sc =='0'&&sc[1]=='b') 
....................          sc+=2; 
....................  
....................    } 
....................    else if(*sc!='0') // base is 0, find base 
....................       base=10; 
....................    else if (sc[1]=='x' || sc[1]=='X') 
....................       base =16,sc+=2; 
....................    else if(sc[1]=='b') 
....................       base=2,sc+=2; 
....................    else 
....................       base=8; 
....................    for (s1=sc;*sc=='0';++sc);// skip leading zeroes 
....................    sd=memchr(digits,tolower(*sc),base); 
....................    for(; sd!=0; ) 
....................    { 
....................       x=x*base+(int16)(sd-digits); 
....................       ++sc; 
....................       sd=memchr(digits,tolower(*sc),base); 
....................    } 
....................    if(s1==sc) 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................    return 0; 
....................    } 
....................    if (endptr) 
....................         *((char *)endptr)=sc; 
....................    return x; 
.................... } 
....................  
....................  
.................... signed long strtol(char *s,char *endptr,signed int base) 
.................... { 
....................    char *sc,*s1,*sd; 
....................    signed long x=0; 
....................    char sign; 
....................    char digits[]="0123456789abcdefghijklmnopqstuvwxyz"; 
....................    for(sc=s;isspace(*sc);++sc); 
....................    sign=*sc=='-'||*sc=='+'?*sc++:'+'; 
....................    if (base <0 || base ==1|| base >36) // invalid base 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................       return 0; 
....................    } 
....................    else if (base) 
....................    { 
....................       if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X')) 
....................          sc+=2; 
....................       if(base==8 && *sc =='0') 
....................          sc+=1; 
....................       if(base==2 && *sc =='0'&&sc[1]=='b') 
....................          sc+=2; 
....................  
....................    } 
....................    else if(*sc!='0') // base is 0, find base 
....................       base=10; 
....................    else if (sc[1]=='x' || sc[1]=='X') 
....................       base =16,sc+=2; 
....................    else if(sc[1]=='b') 
....................       base=2,sc+=2; 
....................    else 
....................       base=8; 
....................    for (s1=sc;*sc=='0';++sc);// skip leading zeroes 
....................  
....................    sd=memchr(digits,tolower(*sc),base); 
....................    for(;sd!=0;) 
....................    { 
....................       x=x*base+(int16)(sd-digits); 
....................       ++sc; 
....................       sd=memchr(digits,tolower(*sc),base); 
....................    } 
....................    if(s1==sc) 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................    return 0; 
....................    } 
....................    if(sign=='-') 
....................       x  =-x; 
....................    if (endptr) 
....................         *((char *)endptr)=sc; 
....................    return x; 
.................... } 
....................  
.................... signed int system(char *string) 
.................... { 
....................    return 0; 
.................... } 
....................  
.................... int mblen(char *s,size_t n) 
.................... { 
....................    return strlen(s); 
.................... } 
....................  
.................... int mbtowc(wchar_t *pwc,char *s,size_t n) 
.................... { 
....................    *pwc=*s; 
....................    return 1; 
.................... } 
....................  
.................... int wctomb(char *s,wchar_t wchar) 
.................... { 
....................    *s=wchar; 
....................    return 1; 
.................... } 
....................  
.................... size_t mbstowcs(wchar_t *pwcs,char *s,size_t n) 
.................... { 
....................    strncpy(pwcs,s,n); 
....................    return strlen(pwcs); 
.................... } 
....................  
.................... size_t wcstombs(char *s,wchar_t *pwcs,size_t n) 
.................... { 
....................    strncpy(s,pwcs,n); 
....................    return strlen(s); 
.................... } 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // The random number implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... unsigned int32 _Randseed; 
....................  
.................... long rand(void) 
.................... { 
....................    _Randseed = _Randseed * 1103515245 + 12345; 
....................    return ((unsigned long)(_Randseed >> 16) % RAND_MAX); 
.................... } 
....................  
.................... void srand(unsigned int32 seed) 
.................... { 
....................    _Randseed = seed; 
.................... } 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Searching and sorting utilities implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... typedef signed int (*_Cmpfun)(char * p1,char * p2); 
....................  
.................... void qsort(char * qdata, int qitems, int qsize, _Cmpfun cmp) { 
....................    int m,j,i,l; 
....................    short done; 
....................    BYTE t[16]; 
....................  
....................    m = qitems/2; 
....................    while( m > 0 ) { 
....................      for(j=0; j<(qitems-m); ++j) { 
....................         i = j; 
....................         do 
....................         { 
....................            done=TRUE; 
....................            l = i+m; 
....................            if( (*cmp)(qdata+i*qsize, qdata+l*qsize) > 0 ) { 
....................               memcpy(t, qdata+i*qsize, qsize); 
....................               memcpy(qdata+i*qsize, qdata+l*qsize, qsize); 
....................               memcpy(qdata+l*qsize, t, qsize); 
....................               if(m <= i) 
....................                 i -= m; 
....................                 done = FALSE; 
....................            } 
....................         } while(!done); 
....................      } 
....................      m = m/2; 
....................    } 
.................... } 
....................  
....................  
.................... char *bsearch(char *key, char *base, size_t num, size_t width,_Cmpfun cmp) 
.................... { 
....................    char *p, *q; 
....................    size_t n; 
....................    size_t pivot; 
....................    signed int val; 
....................  
....................    p = base; 
....................    n = num; 
....................  
....................    while (n > 0) 
....................    { 
....................       pivot = n >> 1; 
....................       q = p + width * pivot; 
....................  
....................       val = (*cmp)(key, q); 
....................  
....................       if (val < 0) 
....................          n = pivot; 
....................       else if (val == 0) 
....................          return ((char *)q); 
....................       else { 
....................          p = q + width; 
....................          n -= pivot + 1; 
....................       } 
....................    } 
....................  
....................    return NULL;      // There's no match 
.................... } 
....................  
....................  
.................... #endif 
....................  
....................  
....................  
.................... #ifndef RS485_DRIVER 
.................... #define RS485_DRIVER 
....................  
.................... // Defines the destination's RS485 ID 
.................... #define  RS485_DEST_ID        0x01 
.................... int8 RS485_ID=0;  
08E5:  CLRF   60
....................  
....................  
....................    #ifndef RS485_RX_PIN 
....................    #define RS485_RX_PIN       PIN_C7   // Data receive pin 
....................    #endif 
....................  
....................    #ifndef RS485_TX_PIN 
....................    #define RS485_TX_PIN       PIN_C6   // Data transmit pin 
....................    #endif 
....................  
....................    #ifndef RS485_RX_ENABLE 
....................    #define RS485_RX_ENABLE    PIN_B5   // Controls RE pin.  Should keep low. 
....................    #endif 
....................  
.................... //***#use rs232(baud=9600, xmit=RS485_TX_PIN, rcv=RS485_RX_PIN, enable=RS485_ENABLE_PIN,bits=8, stream=RS485,errors)//rcv 
.................... #use rs232(baud=9600, xmit=RS485_TX_PIN, rcv=RS485_RX_PIN,bits=8, stream=RS485,errors, RESTART_WDT, DISABLE_INTS)//rcv 
*
0093:  CLRWDT
0094:  BTFSS  0C.5
0095:  GOTO   093
0096:  MOVF   18,W
0097:  MOVWF  61
0098:  MOVF   1A,W
0099:  MOVWF  78
009A:  BTFSS  61.1
009B:  GOTO   09E
009C:  BCF    18.4
009D:  BSF    18.4
009E:  RETLW  00
*
027C:  BTFSS  0C.4
027D:  GOTO   27C
027E:  BSF    03.6
027F:  MOVF   12,W
0280:  BCF    03.6
0281:  MOVWF  19
0282:  BCF    0A.3
0283:  BCF    0A.4
0284:  GOTO   2BD (RETURN)
*
08E6:  CLRF   61
....................  
.................... #define RS485_wait_time 20             // Wait time in milliseconds 
....................  
.................... #bit    rs485_collision = rs232_errors.6 
....................  
.................... #ifndef RS485_RX_BUFFER_SIZE 
.................... #define RS485_RX_BUFFER_SIZE  32 
.................... #endif 
....................  
.................... int rs485_state, rs485_ni, rs485_no,new_message; 
.................... int8 rcv_state; 
....................  
....................  
.................... //int rs485_buffer[RS485_RX_BUFFER_SIZE]; 
.................... int8 rs485_InBuffer[30]; 
.................... int8 cmd_InBuffer[1]; 
.................... int index; 
.................... int Receiving = false; 
08E7:  CLRF   69
.................... int8 to_address = 0xFF; //initialize to impossible address 
08E8:  MOVLW  FF
08E9:  MOVWF  6A
....................  
....................  
.................... // Purpose:    Enable data reception 
.................... // Inputs:     None 
.................... // Outputs:    None 
.................... void RCV_ON(void) { 
....................       while(kbhit(RS485)) {fgetc(RS485);} // Clear RX buffer. Clear RDA interrupt flag. Clear overrun error flag.  
*
0171:  BTFSS  0C.5
0172:  GOTO   175
0173:  CALL   093
0174:  GOTO   171
....................          output_low(RS485_RX_ENABLE); 
0175:  BSF    03.5
0176:  BCF    06.5
0177:  BCF    03.5
0178:  BCF    06.5
.................... } 
0179:  RETLW  00
....................  
.................... void RCV_OFF(void) { 
....................    output_high(RS485_RX_ENABLE); 
*
024C:  BSF    03.5
024D:  BCF    06.5
024E:  BCF    03.5
024F:  BSF    06.5
.................... } 
0250:  RETLW  00
....................  
....................  
.................... // Purpose:    Initialize RS485 communication. Call this before 
.................... //             using any other RS485 functions. 
.................... // Inputs:     None 
.................... // Outputs:    None 
.................... void rs485_init() { 
....................    RS485_ID= ( (!input(PIN_C3)<<3)|(!input(PIN_C2)<<2)|(!input(PIN_C1)<<1)|(!input(PIN_C0)) ); 
*
017A:  BSF    6B.3
017B:  MOVF   6B,W
017C:  BSF    03.5
017D:  MOVWF  07
017E:  MOVLW  00
017F:  BCF    03.5
0180:  BTFSS  07.3
0181:  MOVLW  01
0182:  MOVWF  77
0183:  RLF    77,W
0184:  BSF    03.5
0185:  MOVWF  3F
0186:  RLF    3F,F
0187:  RLF    3F,F
0188:  MOVLW  F8
0189:  ANDWF  3F,F
018A:  BCF    03.5
018B:  BSF    6B.2
018C:  MOVF   6B,W
018D:  BSF    03.5
018E:  MOVWF  07
018F:  MOVLW  00
0190:  BCF    03.5
0191:  BTFSS  07.2
0192:  MOVLW  01
0193:  MOVWF  77
0194:  RLF    77,F
0195:  RLF    77,F
0196:  MOVLW  FC
0197:  ANDWF  77,F
0198:  MOVF   77,W
0199:  BSF    03.5
019A:  IORWF  3F,W
019B:  MOVWF  41
019C:  BCF    03.5
019D:  BSF    6B.1
019E:  MOVF   6B,W
019F:  BSF    03.5
01A0:  MOVWF  07
01A1:  MOVLW  00
01A2:  BCF    03.5
01A3:  BTFSS  07.1
01A4:  MOVLW  01
01A5:  MOVWF  77
01A6:  BCF    03.0
01A7:  RLF    77,F
01A8:  MOVF   77,W
01A9:  BSF    03.5
01AA:  IORWF  41,W
01AB:  MOVWF  43
01AC:  BCF    03.5
01AD:  BSF    6B.0
01AE:  MOVF   6B,W
01AF:  BSF    03.5
01B0:  MOVWF  07
01B1:  MOVLW  00
01B2:  BCF    03.5
01B3:  BTFSS  07.0
01B4:  MOVLW  01
01B5:  BSF    03.5
01B6:  IORWF  43,W
01B7:  BCF    03.5
01B8:  MOVWF  60
*
08EA:  MOVWF  6B
....................    RCV_ON(); 
*
01B9:  CALL   171
....................    rs485_state=0; 
01BA:  CLRF   62
....................    rs485_ni=0; 
01BB:  CLRF   63
....................    rs485_no=0; 
01BC:  CLRF   64
....................    rcv_state=0; 
01BD:  CLRF   66
....................    new_message=FALSE; 
01BE:  CLRF   65
....................    enable_interrupts(INT_RDA); 
01BF:  BSF    03.5
01C0:  BSF    0C.5
....................    enable_interrupts(GLOBAL); 
01C1:  MOVLW  C0
01C2:  BCF    03.5
01C3:  IORWF  0B,F
....................  
.................... } 
01C4:  BSF    0A.3
01C5:  BCF    0A.4
01C6:  GOTO   109 (RETURN)
....................  
....................  
.................... // Purpose:    Send a message over the RS485 bus 
.................... // Inputs:     1) To address 
.................... //             2) From address 
.................... //			   3) len 
.................... //             4) data (acknowlege, time to close) 
.................... // Outputs:    TRUE if successful 
.................... //             FALSE if failed 
.................... // Note:       Format:  msg typ | source | data  
.................... int1 rs485_send_message(int8 my_id, int8 len, int8* data) { 
....................    int8 try, i, cs; 
....................    int1 ret = FALSE; 
*
029D:  BSF    03.6
029E:  BCF    10.0
....................  
....................    RCV_OFF(); 
029F:  BCF    03.6
02A0:  CALL   24C
....................  
....................    for(try=0; try<5; ++try) { 
02A1:  BSF    03.5
02A2:  CLRF   6D
02A3:  MOVF   6D,W
02A4:  SUBLW  04
02A5:  BTFSS  03.0
02A6:  GOTO   2DD
....................       rs485_collision = 0; 
02A7:  BCF    03.5
02A8:  BCF    61.6
....................  
....................       for(i=0; i<len; ++i) { 
02A9:  BSF    03.5
02AA:  CLRF   6E
02AB:  MOVF   6A,W
02AC:  SUBWF  6E,W
02AD:  BTFSC  03.0
02AE:  GOTO   2C3
....................        //  cs ^= *data; 
....................          fputc(*data, RS485); 
02AF:  MOVF   6C,W
02B0:  MOVWF  7A
02B1:  MOVF   6B,W
02B2:  MOVWF  04
02B3:  BCF    03.7
02B4:  BTFSC  6C.0
02B5:  BSF    03.7
02B6:  MOVF   00,W
02B7:  BCF    03.5
02B8:  BSF    03.6
02B9:  MOVWF  11
02BA:  MOVWF  12
02BB:  BCF    03.6
02BC:  GOTO   27C
....................          ++data; 
02BD:  BSF    03.5
02BE:  INCF   6B,F
02BF:  BTFSC  03.2
02C0:  INCF   6C,F
....................       } 
02C1:  INCF   6E,F
02C2:  GOTO   2AB
....................              
....................       if(!rs485_collision) { 
02C3:  BCF    03.5
02C4:  BTFSC  61.6
02C5:  GOTO   2D3
....................       delay_ms(my_id); 
02C6:  BSF    03.5
02C7:  MOVF   69,W
02C8:  BCF    03.5
02C9:  BSF    03.6
02CA:  MOVWF  11
02CB:  BCF    03.6
02CC:  CALL   285
....................          ret = TRUE; 
02CD:  BSF    03.6
02CE:  BSF    10.0
....................          break; 
02CF:  BSF    03.5
02D0:  BCF    03.6
02D1:  GOTO   2DD
02D2:  BCF    03.5
....................       } 
....................       delay_ms(my_id); 
02D3:  BSF    03.5
02D4:  MOVF   69,W
02D5:  BCF    03.5
02D6:  BSF    03.6
02D7:  MOVWF  11
02D8:  BCF    03.6
02D9:  CALL   285
....................    } 
02DA:  BSF    03.5
02DB:  INCF   6D,F
02DC:  GOTO   2A3
....................    RCV_ON(); 
02DD:  BCF    03.5
02DE:  CALL   171
....................    return(ret); 
02DF:  MOVLW  00
02E0:  BSF    03.6
02E1:  BTFSC  10.0
02E2:  MOVLW  01
02E3:  MOVWF  78
.................... } 
02E4:  BCF    03.6
02E5:  RETLW  00
....................  
....................  
....................  
.................... // Purpose:    Interrupt service routine for handling incoming RS485 data 
.................... // data format: from address, to address, length, command, data (each 1 byte) 
.................... #int_rda 
.................... void incomming_rs485() { 
....................      rs485_InBuffer[index] = getc(); 
*
009F:  MOVLW  A0
00A0:  ADDWF  68,W
00A1:  MOVWF  04
00A2:  BCF    03.7
00A3:  BSF    03.6
00A4:  CLRF   16
00A5:  MOVF   04,W
00A6:  MOVWF  15
00A7:  BCF    16.0
00A8:  BTFSC  03.7
00A9:  BSF    16.0
00AA:  BCF    03.6
00AB:  CALL   093
00AC:  BSF    03.6
00AD:  MOVF   15,W
00AE:  MOVWF  04
00AF:  BCF    03.7
00B0:  BTFSC  16.0
00B1:  BSF    03.7
00B2:  MOVF   78,W
00B3:  MOVWF  00
....................      if(rs485_InBuffer[index] == '$') { 
00B4:  MOVLW  A0
00B5:  BCF    03.6
00B6:  ADDWF  68,W
00B7:  MOVWF  04
00B8:  BCF    03.7
00B9:  MOVF   00,W
00BA:  SUBLW  24
00BB:  BTFSS  03.2
00BC:  GOTO   0C4
....................          Receiving = true;	 
00BD:  MOVLW  01
00BE:  MOVWF  69
....................          index = 0; 
00BF:  CLRF   68
....................          rs485_InBuffer[0]= '$'; 
00C0:  MOVLW  24
00C1:  BSF    03.5
00C2:  MOVWF  20
00C3:  BCF    03.5
....................      } 
....................       
....................      if(Receiving) { 
00C4:  MOVF   69,F
00C5:  BTFSC  03.2
00C6:  GOTO   13B
....................        if(index == 4) { 
00C7:  MOVF   68,W
00C8:  SUBLW  04
00C9:  BTFSS  03.2
00CA:  GOTO   0E7
....................          cmd_InBuffer[index - 4] = rs485_InBuffer[index]; 
00CB:  MOVLW  04
00CC:  SUBWF  68,W
00CD:  ADDLW  67
00CE:  MOVWF  78
00CF:  CLRF   7A
00D0:  BTFSC  03.0
00D1:  INCF   7A,F
00D2:  MOVF   78,W
00D3:  BSF    03.6
00D4:  MOVWF  14
00D5:  MOVF   7A,W
00D6:  MOVWF  15
00D7:  MOVLW  A0
00D8:  BCF    03.6
00D9:  ADDWF  68,W
00DA:  MOVWF  04
00DB:  BCF    03.7
00DC:  MOVF   00,W
00DD:  BSF    03.6
00DE:  MOVWF  16
00DF:  MOVF   14,W
00E0:  MOVWF  04
00E1:  BCF    03.7
00E2:  BTFSC  15.0
00E3:  BSF    03.7
00E4:  MOVF   16,W
00E5:  MOVWF  00
00E6:  BCF    03.6
....................        }  
....................         
....................        index += 1; 
00E7:  MOVLW  01
00E8:  ADDWF  68,F
....................         
....................        if(index >=7) { 
00E9:  MOVF   68,W
00EA:  SUBLW  06
00EB:  BTFSC  03.0
00EC:  GOTO   13B
....................          Receiving = false; 
00ED:  CLRF   69
....................          index = 0; 
00EE:  CLRF   68
....................          new_message=TRUE; 
00EF:  MOVLW  01
00F0:  MOVWF  65
....................          
....................                   
....................          // Convert ascii to hex for to address 
....................          if( (isxdigit(rs485_InBuffer[1])) && (isxdigit(rs485_InBuffer[2])) ) 
00F1:  BSF    03.5
00F2:  MOVF   21,W
00F3:  SUBLW  2F
00F4:  BTFSC  03.0
00F5:  GOTO   0FA
00F6:  MOVF   21,W
00F7:  SUBLW  39
00F8:  BTFSC  03.0
00F9:  GOTO   10A
00FA:  MOVF   21,W
00FB:  SUBLW  40
00FC:  BTFSC  03.0
00FD:  GOTO   102
00FE:  MOVF   21,W
00FF:  SUBLW  46
0100:  BTFSC  03.0
0101:  GOTO   10A
0102:  MOVF   21,W
0103:  SUBLW  60
0104:  BTFSC  03.0
0105:  GOTO   139
0106:  MOVF   21,W
0107:  SUBLW  66
0108:  BTFSS  03.0
0109:  GOTO   139
010A:  MOVF   22,W
010B:  SUBLW  2F
010C:  BTFSC  03.0
010D:  GOTO   112
010E:  MOVF   22,W
010F:  SUBLW  39
0110:  BTFSC  03.0
0111:  GOTO   122
0112:  MOVF   22,W
0113:  SUBLW  40
0114:  BTFSC  03.0
0115:  GOTO   11A
0116:  MOVF   22,W
0117:  SUBLW  46
0118:  BTFSC  03.0
0119:  GOTO   122
011A:  MOVF   22,W
011B:  SUBLW  60
011C:  BTFSC  03.0
011D:  GOTO   139
011E:  MOVF   22,W
011F:  SUBLW  66
0120:  BTFSS  03.0
0121:  GOTO   139
....................          	{ 
....................             if (rs485_InBuffer[2] > '9')  
0122:  MOVF   22,W
0123:  SUBLW  39
0124:  BTFSC  03.0
0125:  GOTO   128
....................               { rs485_InBuffer[2] += 9; 
0126:  MOVLW  09
0127:  ADDWF  22,F
....................               } 
....................               rs485_InBuffer[2] &= 0x0F; 
0128:  MOVLW  0F
0129:  ANDWF  22,F
....................  
....................             if (rs485_InBuffer[1] > '9')  
012A:  MOVF   21,W
012B:  SUBLW  39
012C:  BTFSC  03.0
012D:  GOTO   130
....................               { rs485_InBuffer[1] += 9; 
012E:  MOVLW  09
012F:  ADDWF  21,F
....................               } 
....................               rs485_InBuffer[1] &= 0x0F; 
0130:  MOVLW  0F
0131:  ANDWF  21,F
....................             
....................             to_address =( (rs485_InBuffer[1]<<1)|(rs485_InBuffer[2]) );          
0132:  BCF    03.0
0133:  RLF    21,W
0134:  IORWF  22,W
0135:  BCF    03.5
0136:  MOVWF  6A
....................           } 
....................           else 
0137:  GOTO   13B
0138:  BSF    03.5
....................           bad_address = true;     
0139:  BCF    03.5
013A:  BSF    5F.3
....................        } 
....................      	 
....................     } 
....................       
....................      // Turn receive back on 
....................    	// RCV_ON(); 
.................... } 
....................  
....................  
013B:  BCF    0C.5
013C:  BCF    0A.3
013D:  BCF    0A.4
013E:  GOTO   029
.................... int1 rs485_get_new_message(int8 my_ID, int1 wait) 
.................... { 
....................    while(wait && (new_message==FALSE)) {} 
*
0373:  BSF    03.5
0374:  MOVF   3F,F
0375:  BTFSC  03.2
0376:  GOTO   37F
0377:  BCF    03.5
0378:  MOVF   65,F
0379:  BTFSC  03.2
037A:  GOTO   37D
037B:  BSF    03.5
037C:  GOTO   37F
037D:  GOTO   373
037E:  BSF    03.5
....................  
....................    if(new_message==FALSE) 
037F:  BCF    03.5
0380:  MOVF   65,F
0381:  BTFSS  03.2
0382:  GOTO   387
....................       return FALSE; 
0383:  MOVLW  00
0384:  MOVWF  78
0385:  GOTO   397
....................    else			 
0386:  GOTO   397
....................     { 
....................    	  if( (to_address == RS485_ID) && (!bad_address) )		//check if message is for this address 
0387:  MOVF   60,W
0388:  SUBWF  6A,W
0389:  BTFSS  03.2
038A:  GOTO   392
038B:  BTFSC  5F.3
038C:  GOTO   392
....................    	  { 
....................       new_message=FALSE;					//clear new_message flag 
038D:  CLRF   65
....................       return TRUE;} 
038E:  MOVLW  01
038F:  MOVWF  78
0390:  GOTO   397
....................       else	//message not for my address, clear new message flag but don't copy input data 
0391:  GOTO   397
....................       { 
....................       bad_address = false; 
0392:  BCF    5F.3
....................       new_message=FALSE; 
0393:  CLRF   65
....................       return FALSE;} 
0394:  MOVLW  00
0395:  MOVWF  78
0396:  GOTO   397
....................    } 
.................... } 
0397:  BSF    0A.3
0398:  BCF    0A.4
0399:  GOTO   178 (RETURN)
....................  
....................  
....................  
.................... // Purpose:    Wait for wait time for the RS485 bus to become idle 
.................... // Inputs:     TRUE - restart the watch dog timer to prevent reset 
.................... //             FALSE - watch dog timer not restarted 
.................... // Outputs:    None 
.................... void rs485_wait_for_bus(int1 clrwdt) 
.................... { 
....................    int16 i; 
....................  
....................    RCV_OFF(); 
*
0251:  CALL   24C
....................    for(i=0; i <= (rs485_wait_time*20); ++i) 
0252:  BSF    03.5
0253:  CLRF   6B
0254:  CLRF   6A
0255:  MOVF   6B,W
0256:  SUBLW  01
0257:  BTFSS  03.0
0258:  GOTO   279
0259:  BTFSS  03.2
025A:  GOTO   25F
025B:  MOVF   6A,W
025C:  SUBLW  90
025D:  BTFSS  03.0
025E:  GOTO   279
....................    { 
....................       if(!input(RS485_RX_PIN))//this is inverted as in the original file 
025F:  BCF    03.5
0260:  BSF    6B.7
0261:  MOVF   6B,W
0262:  BSF    03.5
0263:  MOVWF  07
0264:  BCF    03.5
0265:  BTFSC  07.7
0266:  GOTO   26C
....................          i = 0; 
0267:  BSF    03.5
0268:  CLRF   6B
0269:  CLRF   6A
....................       else 
026A:  GOTO   272
026B:  BCF    03.5
....................          delay_us(50); 
026C:  CLRWDT
026D:  MOVLW  10
026E:  MOVWF  77
026F:  DECFSZ 77,F
0270:  GOTO   26F
0271:  BSF    03.5
....................  
....................       if(clrwdt) 
0272:  MOVF   69,F
0273:  BTFSS  03.2
....................          restart_wdt(); 
0274:  CLRWDT
....................    } 
0275:  INCF   6A,F
0276:  BTFSC  03.2
0277:  INCF   6B,F
0278:  GOTO   255
.................... 	RCV_ON(); 
0279:  BCF    03.5
027A:  CALL   171
.................... } 
027B:  RETLW  00
....................  
.................... void send_response(char* s) 
.................... { 
....................    int8 size; 
....................    char* header[20]; 
....................  //   
....................    sprintf(header, "*%x",RS485_ID); 
*
032F:  CLRF   6D
0330:  MOVLW  C1
0331:  MOVWF  6C
0332:  MOVLW  2A
0333:  BSF    03.5
0334:  MOVWF  6B
0335:  BCF    03.5
0336:  CALL   1C7
0337:  MOVF   60,W
0338:  BSF    03.5
0339:  MOVWF  69
033A:  MOVLW  57
033B:  MOVWF  6A
033C:  BCF    03.5
033D:  CALL   1D6
*
08EB:  CLRF   6C
08EC:  CLRF   6D
....................    s = strncat(header, s, 16); 
*
033E:  BSF    03.5
033F:  CLRF   6A
0340:  MOVLW  C1
0341:  MOVWF  69
0342:  MOVF   3F,W
0343:  MOVWF  6C
0344:  MOVF   3E,W
0345:  MOVWF  6B
0346:  MOVLW  10
0347:  MOVWF  6D
0348:  BCF    03.5
0349:  CALL   1FB
034A:  MOVF   79,W
034B:  BSF    03.5
034C:  MOVWF  3F
034D:  MOVF   78,W
034E:  MOVWF  3E
....................  
....................    for(size=0; s[size]!='\0'; ++size); 
034F:  CLRF   40
0350:  MOVF   40,W
0351:  ADDWF  3E,W
0352:  MOVWF  04
0353:  BCF    03.7
0354:  BTFSC  3F.0
0355:  BSF    03.7
0356:  MOVF   00,F
0357:  BTFSC  03.2
0358:  GOTO   35B
0359:  INCF   40,F
035A:  GOTO   350
....................  
....................    rs485_wait_for_bus(false); 
035B:  CLRF   69
035C:  BCF    03.5
035D:  CALL   251
....................    while(!rs485_send_message(RS485_ID,size, s)) 
....................    {     
035E:  MOVF   60,W
035F:  BSF    03.5
0360:  MOVWF  69
0361:  MOVF   40,W
0362:  MOVWF  6A
0363:  MOVF   3F,W
0364:  MOVWF  6C
0365:  MOVF   3E,W
0366:  MOVWF  6B
0367:  BCF    03.5
0368:  CALL   29D
0369:  MOVF   78,F
036A:  BTFSS  03.2
036B:  GOTO   372
....................     delay_ms(10); 
036C:  MOVLW  0A
036D:  BSF    03.6
036E:  MOVWF  11
036F:  BCF    03.6
0370:  CALL   285
....................     } 
0371:  GOTO   35E
.................... } 
0372:  RETLW  00
....................  
.................... void send_error_response(char* s) 
.................... { 
....................    int8 size; 
....................    char* header[20]; 
....................  //   
....................    sprintf(header, "?%x ",RS485_ID); 
*
02E6:  CLRF   6D
02E7:  MOVLW  C1
02E8:  MOVWF  6C
02E9:  MOVLW  3F
02EA:  BSF    03.5
02EB:  MOVWF  6B
02EC:  BCF    03.5
02ED:  CALL   1C7
02EE:  MOVF   60,W
02EF:  BSF    03.5
02F0:  MOVWF  69
02F1:  MOVLW  57
02F2:  MOVWF  6A
02F3:  BCF    03.5
02F4:  CALL   1D6
02F5:  MOVLW  20
02F6:  BSF    03.5
02F7:  MOVWF  6B
02F8:  BCF    03.5
02F9:  CALL   1C7
....................    s = strncat(header, s, 16); 
02FA:  BSF    03.5
02FB:  CLRF   6A
02FC:  MOVLW  C1
02FD:  MOVWF  69
02FE:  MOVF   3F,W
02FF:  MOVWF  6C
0300:  MOVF   3E,W
0301:  MOVWF  6B
0302:  MOVLW  10
0303:  MOVWF  6D
0304:  BCF    03.5
0305:  CALL   1FB
0306:  MOVF   79,W
0307:  BSF    03.5
0308:  MOVWF  3F
0309:  MOVF   78,W
030A:  MOVWF  3E
....................  
....................    for(size=0; s[size]!='\0'; ++size); 
030B:  CLRF   40
030C:  MOVF   40,W
030D:  ADDWF  3E,W
030E:  MOVWF  04
030F:  BCF    03.7
0310:  BTFSC  3F.0
0311:  BSF    03.7
0312:  MOVF   00,F
0313:  BTFSC  03.2
0314:  GOTO   317
0315:  INCF   40,F
0316:  GOTO   30C
....................  
....................    rs485_wait_for_bus(false); 
0317:  CLRF   69
0318:  BCF    03.5
0319:  CALL   251
....................    while(!rs485_send_message(RS485_ID,size, s)) 
....................    {     
031A:  MOVF   60,W
031B:  BSF    03.5
031C:  MOVWF  69
031D:  MOVF   40,W
031E:  MOVWF  6A
031F:  MOVF   3F,W
0320:  MOVWF  6C
0321:  MOVF   3E,W
0322:  MOVWF  6B
0323:  BCF    03.5
0324:  CALL   29D
0325:  MOVF   78,F
0326:  BTFSS  03.2
0327:  GOTO   32E
....................     delay_ms(10); 
0328:  MOVLW  0A
0329:  BSF    03.6
032A:  MOVWF  11
032B:  BCF    03.6
032C:  CALL   285
....................     } 
032D:  GOTO   31A
.................... } 
032E:  RETLW  00
....................  
.................... //#endif 
....................  
.................... #include "Command_Handler.c" 
.................... /****************************************************************************/ 
.................... /* Copyright 2006 MBARI.                                                    */ 
.................... /* Monterey Bay Aquarium Research Institute Proprietary Information.        */ 
.................... /* All rights reserved.                                                     */ 
.................... /****************************************************************************/ 
....................  
....................  
.................... #include <stdlib.h> 
.................... /////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services           //// 
.................... //// This source code may only be used by licensed users of the CCS C  //// 
.................... //// compiler.  This source code may only be distributed to other      //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction //// 
.................... //// or distribution is permitted without written permission.          //// 
.................... //// Derivative programs created using this software in object code    //// 
.................... //// form are not restricted in any way.                               //// 
.................... /////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STDLIB 
.................... #define _STDLIB 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Definitions and types 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #ifndef RAND_MAX 
.................... #define RAND_MAX  32767    // The value of which is the maximum value 
....................                            // ... returned by the rand function 
.................... #endif 
....................  
.................... typedef struct { 
....................    signed int quot; 
....................    signed int rem; 
.................... } div_t; 
....................  
.................... typedef struct { 
....................    signed long quot; 
....................    signed long rem; 
.................... } ldiv_t; 
....................  
.................... #include <stddef.h> 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // String conversion functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* Standard template: float atof(char * s) 
....................  * converts the initial portion of the string s to a float. 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... float atof(char * s); 
....................  
.................... /* Standard template: float atoe(char * s) 
....................  * converts the initial portion of the string s to a float. 
....................  * returns the converted value if any, 0 otherwise 
....................  * also handles E format numbers 
....................  */ 
.................... float atoe(char * s); 
....................  
.................... /* Standard template: signed int  atoi(char * s) 
....................  * converts the initial portion of the string s to a signed int 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... signed int atoi(char *s); 
....................  
.................... /* Syntax: signed int32  atoi32(char * s) 
....................    converts the initial portion of the string s to a signed int32 
....................    returns the converted value if any, 0 otherwise*/ 
.................... signed int32 atoi32(char *s); 
....................  
.................... /* Syntax: char *  itoa(signed int32 num, int8 base, char * s) 
....................    converts the signed int32 to a string and 
....................    returns the converted value if any, 0 otherwise*/ 
.................... char * itoa(signed int32 num, int8 base, char * s); 
....................  
.................... /* Standard template: signed long  atol(char * s) 
....................  * converts the initial portion of the string s to a signed long 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... signed long atol(char *s); 
....................  
.................... /* Standard template: float strtol(char * s,char *endptr) 
....................  * converts the initial portion of the string s to a float 
....................  * returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... float strtod(char *s,char *endptr); 
....................  
.................... /* Standard template: long strtoul(char * s,char *endptr,signed int base) 
....................  * converts the initial portion of the string s, represented as an 
....................  * integral value of radix base  to a signed long. 
....................  * Returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... signed long strtol(char *s,char *endptr,signed int base); 
....................  
.................... /* Standard template: long strtoul(char * s,char *endptr,signed int base) 
....................  * converts the initial portion of the string s, represented as an 
....................  * integral value of radix base to a unsigned long. 
....................  * returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... long strtoul(char *s,char *endptr,signed int base); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Pseudo-random sequence generation functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* The rand function computes a sequence of pseudo-random integers in 
....................  * the range 0 to RAND_MAX 
....................  * 
....................  * Parameters: 
....................  *       (none) 
....................  * 
....................  * Returns: 
....................  *       The pseudo-random integer 
....................  */ 
.................... long rand(void); 
....................  
.................... /* The srand function uses the argument as a seed for a new sequence of 
....................  * pseudo-random numbers to be returned by subsequent calls to rand. 
....................  * 
....................  * Parameters: 
....................  *       [in] seed: The seed value to start from. You might need to pass 
....................  * 
....................  * Returns: 
....................  *       (none) 
....................  * 
....................  * Remarks 
....................  *          The srand function sets the starting point for generating 
....................  *       a series of pseudorandom integers. To reinitialize the 
....................  *       generator, use 1 as the seed argument. Any other value for 
....................  *       seed sets the generator to a random starting point. rand 
....................  *       retrieves the pseudorandom numbers that are generated. 
....................  *       Calling rand before any call to srand generates the same 
....................  *       sequence as calling srand with seed passed as 1. 
....................  *          Usually, you need to pass a time here from outer source 
....................  *       so that the numbers will be different every time you run. 
....................  */ 
.................... void srand(unsigned int32 seed); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Memory management functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Comming soon 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Communication with the environment 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* The function returns 0 always 
....................  */ 
.................... signed int system(char *string); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Searching and sorting utilities 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* Performs a binary search of a sorted array.. 
....................  * 
....................  * Parameters: 
....................  *       [in] key: Object to search for 
....................  *       [in] base: Pointer to base of search data 
....................  *       [in] num: Number of elements 
....................  *       [in] width: Width of elements 
....................  *       [in] compare: Function that compares two elements 
....................  * 
....................  * Returns: 
....................  *       bsearch returns a pointer to an occurrence of key in the array pointed 
....................  *       to by base. If key is not found, the function returns NULL. If the 
....................  *       array is not in order or contains duplicate records with identical keys, 
....................  *       the result is unpredictable. 
....................  */ 
.................... //void *bsearch(const void *key, const void *base, size_t num, size_t width, 
.................... //              int (*compare)(const void *, const void *)); 
....................  
.................... /* Performs the shell-metzner sort (not the quick sort algorithm). The contents 
....................  * of the array are sorted into ascending order according to a comparison 
....................  * function pointed to by compar. 
....................  * 
....................  * Parameters: 
....................  *       [in] base: Pointer to base of search data 
....................  *       [in] num: Number of elements 
....................  *       [in] width: Width of elements 
....................  *       [in] compare: Function that compares two elements 
....................  * 
....................  * Returns: 
....................  *       (none) 
....................  */ 
.................... //void *qsort(const void *base, size_t num, size_t width, 
.................... //              int (*compare)(const void *, const void *)); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Integer arithmetic functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #define labs abs 
....................  
.................... div_t div(signed int numer,signed int denom); 
.................... ldiv_t ldiv(signed long numer,signed long denom); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Multibyte character functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Not supported 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Multibyte string functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Not supported 
....................  
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Internal implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #include <stddef.h> 
.................... #include <string.h> 
....................  
.................... div_t div(signed int numer,signed int denom) 
.................... { 
....................    div_t val; 
....................    val.quot = numer / denom; 
....................    val.rem = numer - (denom * val.quot); 
....................    return (val); 
.................... } 
....................  
.................... ldiv_t ldiv(signed long numer,signed long denom) 
.................... { 
....................    ldiv_t val; 
....................    val.quot = numer / denom; 
....................    val.rem = numer - (denom * val.quot); 
....................    return (val); 
.................... } 
....................  
.................... float atof(char * s) 
.................... { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0; 
....................    char c; 
....................    int ptr = 0; 
....................  
....................    c = s[ptr++]; 
....................  
....................    if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................       if(c == '+') 
....................          c = s[ptr++]; 
....................  
....................       while((c >= '0' && c <= '9')) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          c = s[ptr++]; 
....................          while((c >= '0' && c <= '9')) { 
....................              pow10 = pow10*10; 
....................              result += (c - '0')/pow10; 
....................              c = s[ptr++]; 
....................          } 
....................       } 
....................  
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    return(result); 
.................... } 
....................  
.................... float atoe(char * s) 
.................... { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0; 
....................    int expsign = 0; 
....................    char c; 
....................    int ptr = 0; 
....................    int i; 
....................    float exp = 1.0; 
....................    int expcnt = 0; 
....................  
....................    c = s[ptr++]; 
....................  
....................    if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.' || c=='E' || c=='e') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................       if(c == '+') 
....................          c = s[ptr++]; 
....................  
....................       while((c >= '0' && c <= '9')) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          c = s[ptr++]; 
....................          while((c >= '0' && c <= '9')) { 
....................              pow10 = pow10*10; 
....................              result += (c - '0')/pow10; 
....................              c = s[ptr++]; 
....................          } 
....................       } 
....................  
....................       // Handling the exponent 
....................       if (c=='e' || c=='E') { 
....................          c = s[ptr++]; 
....................  
....................          if(c == '-') { 
....................             expsign = 1; 
....................             c = s[ptr++]; 
....................          } 
....................          if(c == '+') 
....................             c = s[ptr++]; 
....................  
....................          while((c >= '0' && c <= '9')) { 
....................             expcnt = 10*expcnt + c - '0'; 
....................             c = s[ptr++]; 
....................          } 
....................  
....................          for(i=0;i<expcnt;i++) 
....................             exp*=10; 
....................  
....................          if(expsign==1) 
....................             result/=exp; 
....................          else 
....................             result*=exp; 
....................       } 
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    return(result); 
.................... } 
....................  
.................... signed int atoi(char *s) 
.................... { 
....................    signed int result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    // Omit all preceeding alpha characters 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................  
....................       // Check for hexa number 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') 
....................          { 
....................             result = 10*result + (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ( (c >= '0' && c <= '9') || (c >= 'A' && c<='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++]; 
....................             c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (sign == 1 && base == 10) 
....................        result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... signed long atol(char *s) 
.................... { 
....................    signed long result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') 
....................          { 
....................             result = 10*result + (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ( (c >= '0' && c <= '9') || (c >= 'A' && c <='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++];c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (base == 10 && sign == 1) 
....................       result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... /* A fast routine to multiply by 10 
....................  */ 
.................... signed int32 mult_with10(int32 num) 
.................... { 
....................    return ( (num << 1) + (num << 3) ); 
.................... } 
....................  
.................... signed int32 atoi32(char *s) 
.................... { 
....................    signed int32 result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') { 
....................             result = (result << 1) + (result << 3);  // result *= 10; 
....................             result += (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ((c >= '0' && c <= '9') || (c >= 'A' && c <='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++];c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (base == 10 && sign == 1) 
....................       result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... char * itoa(signed int32 num, int8 base, char *s) 
.................... { 
....................      int32 temp=1; 
....................      int8 i,sign=0,cnt=0; 
....................      char c; 
....................  
....................      if(num<0) { 
....................          sign=1;        // Check for negative number 
....................          num*=-1; 
....................      } 
....................  
....................      while(temp>0) { 
....................          temp=(num/base); 
....................          s[cnt]=(num%base)+'0';    // Conversion 
....................  
....................          if(s[cnt]>0x39) 
....................             s[cnt]+=0x7; 
....................  
....................          cnt++; 
....................          num=temp; 
....................      } 
....................  
....................      if(sign==1) { 
....................          s[cnt]=0x2D;      // Negative sign 
....................          cnt++; 
....................      } 
....................  
....................      for(i = 0;i<(int8)(cnt/2);i++) { 
....................  
....................          c=s[i]; 
....................          s[i]=s[cnt-i-1];        // Reverse the number 
....................          s[cnt-i-1]=c; 
....................      } 
....................      s[cnt]='\0';     // End the string 
....................      return s; 
.................... } 
....................  
.................... float strtod(char *s,char *endptr) { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0, point = 0; 
....................    char c; 
....................    int ptr = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c=s[ptr++]; 
....................  
....................  
....................    while((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       while((c >= '0' && c <= '9') && point == 0) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          point = 1; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       while((c >= '0' && c <= '9') && point == 1) { 
....................          pow10 = pow10*10; 
....................          result += (c - '0')/pow10; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '+') { 
....................          c = s[ptr++]; 
....................       } 
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    if(endptr) 
....................    { 
....................       if (ptr) { 
....................          ptr--; 
....................          *((char *)endptr)=s+ptr; 
....................       } 
....................       else 
....................          *((char *)endptr)=s; 
....................    } 
....................  
....................    return(result); 
.................... } 
....................  
.................... long strtoul(char *s,char *endptr,signed int base) 
.................... { 
....................    char *sc,*s1,*sd; 
....................    unsigned long x=0; 
....................    char sign; 
....................    char digits[]="0123456789abcdefghijklmnopqstuvwxyz"; 
....................    for(sc=s;isspace(*sc);++sc); 
....................    sign=*sc=='-'||*sc=='+'?*sc++:'+'; 
....................    if(sign=='-') 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................       return 0; 
....................    } 
....................  
....................    if (base <0 || base ==1|| base >36) // invalid base 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................       return 0; 
....................    } 
....................    else if (base) 
....................    { 
....................       if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X')) 
....................          sc+=2; 
....................       if(base==8 && *sc =='0') 
....................          sc+=1; 
....................       if(base==2 && *sc =='0'&&sc[1]=='b') 
....................          sc+=2; 
....................  
....................    } 
....................    else if(*sc!='0') // base is 0, find base 
....................       base=10; 
....................    else if (sc[1]=='x' || sc[1]=='X') 
....................       base =16,sc+=2; 
....................    else if(sc[1]=='b') 
....................       base=2,sc+=2; 
....................    else 
....................       base=8; 
....................    for (s1=sc;*sc=='0';++sc);// skip leading zeroes 
....................    sd=memchr(digits,tolower(*sc),base); 
....................    for(; sd!=0; ) 
....................    { 
....................       x=x*base+(int16)(sd-digits); 
....................       ++sc; 
....................       sd=memchr(digits,tolower(*sc),base); 
....................    } 
....................    if(s1==sc) 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................    return 0; 
....................    } 
....................    if (endptr) 
....................         *((char *)endptr)=sc; 
....................    return x; 
.................... } 
....................  
....................  
.................... signed long strtol(char *s,char *endptr,signed int base) 
.................... { 
....................    char *sc,*s1,*sd; 
....................    signed long x=0; 
....................    char sign; 
....................    char digits[]="0123456789abcdefghijklmnopqstuvwxyz"; 
....................    for(sc=s;isspace(*sc);++sc); 
....................    sign=*sc=='-'||*sc=='+'?*sc++:'+'; 
....................    if (base <0 || base ==1|| base >36) // invalid base 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................       return 0; 
....................    } 
....................    else if (base) 
....................    { 
....................       if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X')) 
....................          sc+=2; 
....................       if(base==8 && *sc =='0') 
....................          sc+=1; 
....................       if(base==2 && *sc =='0'&&sc[1]=='b') 
....................          sc+=2; 
....................  
....................    } 
....................    else if(*sc!='0') // base is 0, find base 
....................       base=10; 
....................    else if (sc[1]=='x' || sc[1]=='X') 
....................       base =16,sc+=2; 
....................    else if(sc[1]=='b') 
....................       base=2,sc+=2; 
....................    else 
....................       base=8; 
....................    for (s1=sc;*sc=='0';++sc);// skip leading zeroes 
....................  
....................    sd=memchr(digits,tolower(*sc),base); 
....................    for(;sd!=0;) 
....................    { 
....................       x=x*base+(int16)(sd-digits); 
....................       ++sc; 
....................       sd=memchr(digits,tolower(*sc),base); 
....................    } 
....................    if(s1==sc) 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................    return 0; 
....................    } 
....................    if(sign=='-') 
....................       x  =-x; 
....................    if (endptr) 
....................         *((char *)endptr)=sc; 
....................    return x; 
.................... } 
....................  
.................... signed int system(char *string) 
.................... { 
....................    return 0; 
.................... } 
....................  
.................... int mblen(char *s,size_t n) 
.................... { 
....................    return strlen(s); 
.................... } 
....................  
.................... int mbtowc(wchar_t *pwc,char *s,size_t n) 
.................... { 
....................    *pwc=*s; 
....................    return 1; 
.................... } 
....................  
.................... int wctomb(char *s,wchar_t wchar) 
.................... { 
....................    *s=wchar; 
....................    return 1; 
.................... } 
....................  
.................... size_t mbstowcs(wchar_t *pwcs,char *s,size_t n) 
.................... { 
....................    strncpy(pwcs,s,n); 
....................    return strlen(pwcs); 
.................... } 
....................  
.................... size_t wcstombs(char *s,wchar_t *pwcs,size_t n) 
.................... { 
....................    strncpy(s,pwcs,n); 
....................    return strlen(s); 
.................... } 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // The random number implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... unsigned int32 _Randseed; 
....................  
.................... long rand(void) 
.................... { 
....................    _Randseed = _Randseed * 1103515245 + 12345; 
....................    return ((unsigned long)(_Randseed >> 16) % RAND_MAX); 
.................... } 
....................  
.................... void srand(unsigned int32 seed) 
.................... { 
....................    _Randseed = seed; 
.................... } 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Searching and sorting utilities implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... typedef signed int (*_Cmpfun)(char * p1,char * p2); 
....................  
.................... void qsort(char * qdata, int qitems, int qsize, _Cmpfun cmp) { 
....................    int m,j,i,l; 
....................    short done; 
....................    BYTE t[16]; 
....................  
....................    m = qitems/2; 
....................    while( m > 0 ) { 
....................      for(j=0; j<(qitems-m); ++j) { 
....................         i = j; 
....................         do 
....................         { 
....................            done=TRUE; 
....................            l = i+m; 
....................            if( (*cmp)(qdata+i*qsize, qdata+l*qsize) > 0 ) { 
....................               memcpy(t, qdata+i*qsize, qsize); 
....................               memcpy(qdata+i*qsize, qdata+l*qsize, qsize); 
....................               memcpy(qdata+l*qsize, t, qsize); 
....................               if(m <= i) 
....................                 i -= m; 
....................                 done = FALSE; 
....................            } 
....................         } while(!done); 
....................      } 
....................      m = m/2; 
....................    } 
.................... } 
....................  
....................  
.................... char *bsearch(char *key, char *base, size_t num, size_t width,_Cmpfun cmp) 
.................... { 
....................    char *p, *q; 
....................    size_t n; 
....................    size_t pivot; 
....................    signed int val; 
....................  
....................    p = base; 
....................    n = num; 
....................  
....................    while (n > 0) 
....................    { 
....................       pivot = n >> 1; 
....................       q = p + width * pivot; 
....................  
....................       val = (*cmp)(key, q); 
....................  
....................       if (val < 0) 
....................          n = pivot; 
....................       else if (val == 0) 
....................          return ((char *)q); 
....................       else { 
....................          p = q + width; 
....................          n -= pivot + 1; 
....................       } 
....................    } 
....................  
....................    return NULL;      // There's no match 
.................... } 
....................  
....................  
.................... #endif 
....................  
.................... #include "Gulper_Main.h" 
.................... /****************************************************************************/ 
.................... /* Copyright 2006 MBARI.                                                    */ 
.................... /* Monterey Bay Aquarium Research Institute Proprietary Information.        */ 
.................... /* All rights reserved.                                                     */ 
.................... /****************************************************************************/ 
.................... #ifndef PH_PROBE_H 
.................... #define PH_PROBE_H 
....................  
.................... #define VS_VERSION  "0.1" 
.................... #define DEBUG 0 
....................  
....................  
.................... int8 fire[]="F"; 
.................... int8 query[]="Q"; 
.................... int8 status[]= "S"; 
.................... int8 version[]="V"; 
.................... int8 actuation[]="A"; 
....................  
.................... char response_message[20]; // String for storing node response back to MVC 
....................  
....................  
.................... int32 seconds = 0;      // A running seconds counter 
.................... int8 int_count = 0;    // Number of interrupts left before a second has elapsed 
.................... int32 ElapsedSeconds = 0;      // A running seconds counter 
.................... int32 Final_Proximity_Milliseconds = 0; // Used to store time between fire and proximity sensor 
.................... int32 Final_Actuation_Milliseconds = 0; // Used to store time between fire and pin puller voltage >= 2 volts 
.................... int8 Elapsed_int_count = 0;    // Number of interrupts left before a second has elapsed 
....................  
.................... Boolean Fired = false; // Fire command received? 
.................... Boolean proximity = false; //Proximity sensor ISR called? 
.................... Boolean proximity_expired = false; // Set true at 30 seconds past firing if no prox interrupt received 
.................... Boolean bad_address = false; // Address out of range? 
....................  
....................  
.................... /* 
....................     The ticks per second is based on an 8-bit counter over flowing that 
....................     is driven by a 4 Mhz ocsillator prescaled by 4 and postscaled by 64. 
....................  
....................     TICKS_PER_SEC = (OSC_CLK) / (PRESCALE) / (POSTSCALE) / (8_BIT_OVERFLOW) 
....................                   = 4000000   /     4      /      64     /      256 
....................                   = 61.0351 
.................... */ 
.................... #define TICKS_PER_SEC   61 
....................  
.................... #define HI  1 
.................... #define LO  0 
....................  
.................... #define ON  1 
.................... #define OFF 0 
....................  
.................... void startTimer(void); 
.................... void getElapsedTime(void); 
....................  
.................... #endif 
....................  
....................  
.................... int8 system_status = 0; // Used to store time between fire and proximity sensor 
*
08ED:  CLRF   6E
....................  
....................  
.................... /* Actual Command Processing Below */ 
....................  
.................... ///*** Fire Command ***/// 
.................... void handle_fire_command() { 
.................... 	startTimer(); // Start the clock 
....................   output_bit(PIN_B2, HI); // Turn on fired LED 
*
0404:  BCF    03.5
0405:  BSF    06.2
0406:  BSF    03.5
0407:  BCF    06.2
....................    
.................... 	output_bit(PIN_C4, LO); // Fire pin puller 
0408:  BCF    03.5
0409:  BCF    07.4
040A:  BCF    6B.4
040B:  MOVF   6B,W
040C:  BSF    03.5
040D:  MOVWF  07
.................... 	output_bit(PIN_C5, HI); 
040E:  BCF    03.5
040F:  BSF    07.5
0410:  BCF    6B.5
0411:  MOVF   6B,W
0412:  BSF    03.5
0413:  MOVWF  07
....................  
....................   delay_us(150000); // Delay for 150 msec 
0414:  CLRWDT
0415:  MOVLW  95
0416:  BCF    03.5
0417:  BSF    03.6
0418:  MOVWF  11
0419:  BCF    03.6
041A:  CALL   285
041B:  MOVLW  09
041C:  BSF    03.5
041D:  MOVWF  3E
041E:  MOVLW  6C
041F:  MOVWF  3F
0420:  BCF    03.5
0421:  GOTO   3E1
0422:  BSF    03.5
0423:  DECFSZ 3E,F
0424:  GOTO   41E
....................  
....................   output_bit(PIN_C4, HI); // Clear pin puller 
0425:  BCF    03.5
0426:  BSF    07.4
0427:  BCF    6B.4
0428:  MOVF   6B,W
0429:  BSF    03.5
042A:  MOVWF  07
.................... 	output_bit(PIN_C5, LO); 
042B:  BCF    03.5
042C:  BCF    07.5
042D:  BCF    6B.5
042E:  MOVF   6B,W
042F:  BSF    03.5
0430:  MOVWF  07
....................  
....................   Fired = true;   	 
0431:  BCF    03.5
0432:  BSF    5F.0
.................... } 
0433:  BSF    0A.3
0434:  BCF    0A.4
0435:  GOTO   18C (RETURN)
....................  
....................  
.................... ///*** Query Command ***/// 
.................... void handle_query_command() { 
....................   if(Fired && proximity) { 
*
075B:  BTFSS  5F.0
075C:  GOTO   7D3
075D:  BTFSS  5F.1
075E:  GOTO   7D3
....................   	Final_Proximity_Milliseconds = ( (ElapsedSeconds * 1000) + (Elapsed_int_count * 66.6666) ); 
075F:  MOVF   55,W
0760:  BSF    03.5
0761:  MOVWF  41
0762:  BCF    03.5
0763:  MOVF   54,W
0764:  BSF    03.5
0765:  MOVWF  40
0766:  BCF    03.5
0767:  MOVF   53,W
0768:  BSF    03.5
0769:  MOVWF  3F
076A:  BCF    03.5
076B:  MOVF   52,W
076C:  BSF    03.5
076D:  MOVWF  3E
076E:  CLRF   45
076F:  CLRF   44
0770:  MOVLW  03
0771:  MOVWF  43
0772:  MOVLW  E8
0773:  MOVWF  42
0774:  BCF    03.5
0775:  GOTO   436
0776:  MOVF   7A,W
0777:  BSF    03.5
0778:  MOVWF  41
0779:  MOVF   79,W
077A:  MOVWF  40
077B:  MOVF   78,W
077C:  MOVWF  3F
077D:  MOVF   77,W
077E:  MOVWF  3E
077F:  CLRF   43
0780:  BCF    03.5
0781:  MOVF   5E,W
0782:  BSF    03.5
0783:  MOVWF  42
0784:  BCF    03.5
0785:  GOTO   464
0786:  MOVF   7A,W
0787:  BSF    03.5
0788:  MOVWF  45
0789:  MOVF   79,W
078A:  MOVWF  44
078B:  MOVF   78,W
078C:  MOVWF  43
078D:  MOVF   77,W
078E:  MOVWF  42
078F:  MOVLW  4D
0790:  MOVWF  49
0791:  MOVLW  55
0792:  MOVWF  48
0793:  MOVLW  05
0794:  MOVWF  47
0795:  MOVLW  85
0796:  MOVWF  46
0797:  BCF    03.5
0798:  GOTO   485
0799:  MOVF   77,W
079A:  BSF    03.5
079B:  MOVWF  42
079C:  MOVF   78,W
079D:  MOVWF  43
079E:  MOVF   79,W
079F:  MOVWF  44
07A0:  MOVF   7A,W
07A1:  MOVWF  45
07A2:  MOVF   41,W
07A3:  MOVWF  49
07A4:  MOVF   40,W
07A5:  MOVWF  48
07A6:  MOVF   3F,W
07A7:  MOVWF  47
07A8:  MOVF   3E,W
07A9:  MOVWF  46
07AA:  BCF    03.5
07AB:  GOTO   4FE
07AC:  BCF    03.1
07AD:  MOVF   7A,W
07AE:  BSF    03.5
07AF:  MOVWF  49
07B0:  MOVF   79,W
07B1:  MOVWF  48
07B2:  MOVF   78,W
07B3:  MOVWF  47
07B4:  MOVF   77,W
07B5:  MOVWF  46
07B6:  MOVF   45,W
07B7:  MOVWF  4D
07B8:  MOVF   44,W
07B9:  MOVWF  4C
07BA:  MOVF   43,W
07BB:  MOVWF  4B
07BC:  MOVF   42,W
07BD:  MOVWF  4A
07BE:  BCF    03.5
07BF:  GOTO   51D
07C0:  MOVF   7A,W
07C1:  BSF    03.5
07C2:  MOVWF  49
07C3:  MOVF   79,W
07C4:  MOVWF  48
07C5:  MOVF   78,W
07C6:  MOVWF  47
07C7:  MOVF   77,W
07C8:  MOVWF  46
07C9:  BCF    03.5
07CA:  GOTO   665
07CB:  MOVF   7A,W
07CC:  MOVWF  59
07CD:  MOVF   79,W
07CE:  MOVWF  58
07CF:  MOVF   78,W
07D0:  MOVWF  57
07D1:  MOVF   77,W
07D2:  MOVWF  56
....................   }  
....................   // Print the time 
....................   sprintf(response_message, "%Ld\r\n", Final_Proximity_Milliseconds);   
07D3:  CLRF   6D
07D4:  MOVLW  39
07D5:  MOVWF  6C
07D6:  MOVLW  41
07D7:  MOVWF  04
07D8:  MOVF   59,W
07D9:  BSF    03.5
07DA:  MOVWF  42
07DB:  BCF    03.5
07DC:  MOVF   58,W
07DD:  BSF    03.5
07DE:  MOVWF  41
07DF:  BCF    03.5
07E0:  MOVF   57,W
07E1:  BSF    03.5
07E2:  MOVWF  40
07E3:  BCF    03.5
07E4:  MOVF   56,W
07E5:  BSF    03.5
07E6:  MOVWF  3F
07E7:  BCF    03.5
07E8:  CALL   6CC
07E9:  MOVLW  0D
07EA:  BSF    03.5
07EB:  MOVWF  6B
07EC:  BCF    03.5
07ED:  CALL   1C7
07EE:  MOVLW  0A
07EF:  BSF    03.5
07F0:  MOVWF  6B
07F1:  BCF    03.5
07F2:  CALL   1C7
....................   send_response(response_message); 
07F3:  BSF    03.5
07F4:  CLRF   3F
07F5:  MOVLW  39
07F6:  MOVWF  3E
07F7:  BCF    03.5
07F8:  CALL   32F
.................... } 
07F9:  BSF    0A.3
07FA:  BCF    0A.4
07FB:  GOTO   19E (RETURN)
....................  
....................  
.................... ///*** Status Command ***/// 
.................... void handle_status_command() { 
.................... 	system_status = ( (Fired<<2)|(input(PIN_A0)<<1)|(proximity) ); 
*
0800:  MOVLW  00
0801:  BTFSC  5F.0
0802:  MOVLW  01
0803:  MOVWF  77
0804:  RLF    77,W
0805:  BSF    03.5
0806:  MOVWF  3F
0807:  RLF    3F,F
0808:  MOVLW  FC
0809:  ANDWF  3F,F
080A:  BSF    05.0
080B:  MOVLW  00
080C:  BCF    03.5
080D:  BTFSC  05.0
080E:  MOVLW  01
080F:  MOVWF  77
0810:  BCF    03.0
0811:  RLF    77,F
0812:  MOVF   77,W
0813:  BSF    03.5
0814:  IORWF  3F,W
0815:  MOVWF  41
0816:  MOVLW  00
0817:  BCF    03.5
0818:  BTFSC  5F.1
0819:  MOVLW  01
081A:  BSF    03.5
081B:  IORWF  41,W
081C:  BCF    03.5
081D:  MOVWF  6E
.................... 	sprintf(response_message, "%x\r\n", system_status); 
081E:  CLRF   6D
081F:  MOVLW  39
0820:  MOVWF  6C
0821:  MOVF   6E,W
0822:  BSF    03.5
0823:  MOVWF  69
0824:  MOVLW  57
0825:  MOVWF  6A
0826:  BCF    0A.3
0827:  BCF    03.5
0828:  CALL   1D6
0829:  BSF    0A.3
082A:  MOVLW  0D
082B:  BSF    03.5
082C:  MOVWF  6B
082D:  BCF    0A.3
082E:  BCF    03.5
082F:  CALL   1C7
0830:  BSF    0A.3
0831:  MOVLW  0A
0832:  BSF    03.5
0833:  MOVWF  6B
0834:  BCF    0A.3
0835:  BCF    03.5
0836:  CALL   1C7
0837:  BSF    0A.3
....................   send_response(response_message); 
0838:  BSF    03.5
0839:  CLRF   3F
083A:  MOVLW  39
083B:  MOVWF  3E
083C:  BCF    0A.3
083D:  BCF    03.5
083E:  CALL   32F
083F:  BSF    0A.3
.................... } 
0840:  BSF    0A.3
0841:  BCF    0A.4
0842:  GOTO   1AF (RETURN)
....................  
....................  
.................... ///*** Version Command ***/// 
.................... void handle_version_command() { 
....................   sprintf(response_message,"%s\r\n",VS_VERSION); 
0843:  CLRF   6D
0844:  MOVLW  39
0845:  MOVWF  6C
0846:  BSF    03.5
0847:  CLRF   3E
0848:  MOVF   3E,W
0849:  BCF    0A.3
084A:  BCF    03.5
084B:  CALL   045
084C:  BSF    0A.3
084D:  IORLW  00
084E:  BTFSC  03.2
084F:  GOTO   05A
0850:  BSF    03.5
0851:  INCF   3E,F
0852:  MOVWF  6B
0853:  BCF    0A.3
0854:  BCF    03.5
0855:  CALL   1C7
0856:  BSF    0A.3
0857:  BSF    03.5
0858:  GOTO   048
0859:  BCF    03.5
085A:  MOVLW  0D
085B:  BSF    03.5
085C:  MOVWF  6B
085D:  BCF    0A.3
085E:  BCF    03.5
085F:  CALL   1C7
0860:  BSF    0A.3
0861:  MOVLW  0A
0862:  BSF    03.5
0863:  MOVWF  6B
0864:  BCF    0A.3
0865:  BCF    03.5
0866:  CALL   1C7
0867:  BSF    0A.3
....................   send_response(response_message); 
0868:  BSF    03.5
0869:  CLRF   3F
086A:  MOVLW  39
086B:  MOVWF  3E
086C:  BCF    0A.3
086D:  BCF    03.5
086E:  CALL   32F
086F:  BSF    0A.3
.................... } 
0870:  BSF    0A.3
0871:  BCF    0A.4
0872:  GOTO   1BF (RETURN)
....................  
....................  
.................... ///*** Actuation Voltage Command ***/// 
.................... void handle_actuation_voltage_command() { 
....................   // Print the time 
....................   sprintf(response_message, "%Ld:Actuation\r\n", Final_Actuation_Milliseconds);   
0873:  CLRF   6D
0874:  MOVLW  39
0875:  MOVWF  6C
0876:  MOVLW  41
0877:  MOVWF  04
0878:  MOVF   5D,W
0879:  BSF    03.5
087A:  MOVWF  42
087B:  BCF    03.5
087C:  MOVF   5C,W
087D:  BSF    03.5
087E:  MOVWF  41
087F:  BCF    03.5
0880:  MOVF   5B,W
0881:  BSF    03.5
0882:  MOVWF  40
0883:  BCF    03.5
0884:  MOVF   5A,W
0885:  BSF    03.5
0886:  MOVWF  3F
0887:  BCF    0A.3
0888:  BCF    03.5
0889:  CALL   6CC
088A:  BSF    0A.3
088B:  MOVLW  03
088C:  BSF    03.5
088D:  MOVWF  3E
088E:  MOVF   3E,W
088F:  BCF    0A.3
0890:  BCF    03.5
0891:  CALL   04D
0892:  BSF    0A.3
0893:  BSF    03.5
0894:  INCF   3E,F
0895:  MOVWF  77
0896:  MOVWF  6B
0897:  BCF    0A.3
0898:  BCF    03.5
0899:  CALL   1C7
089A:  BSF    0A.3
089B:  MOVLW  0F
089C:  BSF    03.5
089D:  SUBWF  3E,W
089E:  BTFSS  03.2
089F:  GOTO   08E
....................   send_response(response_message); 
08A0:  CLRF   3F
08A1:  MOVLW  39
08A2:  MOVWF  3E
08A3:  BCF    0A.3
08A4:  BCF    03.5
08A5:  CALL   32F
08A6:  BSF    0A.3
.................... } 
08A7:  BSF    0A.3
08A8:  BCF    0A.4
08A9:  GOTO   1CF (RETURN)
....................  
....................  
....................  
.................... #if DEBUG 
.................... #device ICD=TRUE 
.................... #fuses XT,WDT,NOPROTECT,PUT,NOBROWNOUT,NOLVP 
.................... #else 
.................... #fuses XT,WDT,NOPROTECT,PUT,NOLVP 
.................... #endif 
....................  
.................... #define  RS485_RX_BUFFER_SIZE 64 
.................... #define  RS485_USE_EXT_INT    FALSE 
....................  
....................  
.................... int8 in_char = 0; 
*
08EE:  CLRF   6F
.................... int8 next_in = 0; 
08EF:  CLRF   70
.................... int8 next_out = 0; 
08F0:  CLRF   71
.................... int8 *command; 
.................... int8 data[1]; 
.................... #define INTS_PER_SECOND 15     // (20000000/(4*256*256)) 
....................  
....................  
.................... #INT_TIMER1                        // This function is called every time 
.................... void clock_isr() {                 // timer 1 overflows (65535->0), which is 
....................                                    // approximately 15 times per second for 
....................     if(--int_count==0) {           // this program. 
*
013F:  DECFSZ 51,F
0140:  GOTO   14B
....................       ++seconds; 
0141:  MOVLW  01
0142:  ADDWF  4D,F
0143:  BTFSC  03.0
0144:  INCF   4E,F
0145:  BTFSC  03.2
0146:  INCF   4F,F
0147:  BTFSC  03.2
0148:  INCF   50,F
....................       int_count = INTS_PER_SECOND; 
0149:  MOVLW  0F
014A:  MOVWF  51
....................     } 
.................... } 
....................  
.................... // Purpose: Clears elapsed time to "start" the clock 
014B:  BCF    0C.0
014C:  BCF    0A.3
014D:  BCF    0A.4
014E:  GOTO   029
.................... void startTimer(void) 
.................... { 
....................   disable_interrupts(INT_TIMER1); 
*
03F9:  BSF    03.5
03FA:  BCF    0C.0
....................  	seconds=0; 
03FB:  BCF    03.5
03FC:  CLRF   50
03FD:  CLRF   4F
03FE:  CLRF   4E
03FF:  CLRF   4D
....................  	int_count=INTS_PER_SECOND; 
0400:  MOVLW  0F
0401:  MOVWF  51
....................  	enable_interrupts(INT_TIMER1);				 
0402:  BSF    03.5
0403:  BSF    0C.0
.................... } 
....................  
.................... // Purpose: Stores elapsed time 
.................... void getElapsedTime(void) 
.................... { 
.................... 	disable_interrupts(INT_TIMER1); 
*
014F:  BSF    03.5
0150:  BCF    0C.0
....................  	ElapsedSeconds=seconds; 
0151:  BCF    03.5
0152:  MOVF   50,W
0153:  MOVWF  55
0154:  MOVF   4F,W
0155:  MOVWF  54
0156:  MOVF   4E,W
0157:  MOVWF  53
0158:  MOVF   4D,W
0159:  MOVWF  52
....................  	Elapsed_int_count=INTS_PER_SECOND-int_count; // Number of interrupts since the last second, there are 15 per sec 
015A:  MOVF   51,W
015B:  SUBLW  0F
015C:  MOVWF  5E
....................  	enable_interrupts(INT_TIMER1); 
015D:  BSF    03.5
015E:  BSF    0C.0
.................... } 
015F:  BCF    03.5
0160:  RETLW  00
....................  
....................  
.................... // Purpose: Interrupt service routine for handling incoming proximity sensor.  
.................... #INT_EXT 
.................... void proximity_isr() { 
....................  //Only service proximity sensor after firing has been commanded 
....................  //and only if proximity has not expired 
....................  if((Fired) && (!proximity) && (!proximity_expired)) { 
0161:  BTFSS  5F.0
0162:  GOTO   16D
0163:  BTFSC  5F.1
0164:  GOTO   16D
0165:  BTFSC  5F.2
0166:  GOTO   16D
....................    getElapsedTime(); 
0167:  CALL   14F
....................    output_bit(PIN_B4, HI); // Turn on proximity LED 
0168:  BSF    06.4
0169:  BSF    03.5
016A:  BCF    06.4
....................    proximity = true; 
016B:  BCF    03.5
016C:  BSF    5F.1
....................  } 
.................... } 
....................  
.................... // Purpose: Holds software in infinite loop to allow watchdog to reset 
016D:  BCF    0B.1
016E:  BCF    0A.3
016F:  BCF    0A.4
0170:  GOTO   029
.................... void software_reset() { 
....................   for(;;) { 
....................     null; 
....................   } 
.................... } 
....................  
.................... // 
.................... // Main execution loop 
.................... // 
.................... main() 
.................... { 
*
08AA:  CLRF   04
08AB:  BCF    03.7
08AC:  MOVLW  1F
08AD:  ANDWF  03,F
08AE:  MOVLW  19
08AF:  BSF    03.5
08B0:  MOVWF  19
08B1:  MOVLW  A6
08B2:  MOVWF  18
08B3:  MOVLW  90
08B4:  BCF    03.5
08B5:  MOVWF  18
08B6:  BSF    03.5
08B7:  BSF    1F.0
08B8:  BSF    1F.1
08B9:  BSF    1F.2
08BA:  BCF    1F.3
08BB:  MOVLW  07
08BC:  MOVWF  1C
....................      
....................   // Set up the system clocks 
....................   int_count=INTS_PER_SECOND; 
*
08F1:  MOVLW  0F
08F2:  MOVWF  51
....................   setup_wdt(WDT_288MS); // Initialize the watchdog. See fuses WDT also 
08F3:  MOVLW  0C
08F4:  MOVWF  77
08F5:  MOVLW  07
08F6:  CLRF   01
08F7:  MOVLW  81
08F8:  MOVWF  04
08F9:  BCF    03.7
08FA:  MOVF   00,W
08FB:  ANDLW  F0
08FC:  IORLW  07
08FD:  MOVWF  00
08FE:  CLRWDT
08FF:  MOVF   00,W
0900:  ANDLW  F7
0901:  BTFSC  77.3
0902:  ANDLW  F0
0903:  IORWF  77,W
0904:  MOVWF  00
....................    
....................   //Using timer 1 so as not to interfere with WDT/RTC/Timer0 
....................   setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);  
0905:  MOVLW  85
0906:  MOVWF  10
....................  
....................   // Initialize Serial and enable interrupts 
....................   rs485_init(); 
0907:  BCF    0A.3
0908:  GOTO   17A
0909:  BSF    0A.3
....................   enable_interrupts(INT_EXT); 
090A:  BSF    0B.4
....................   enable_interrupts(INT_TIMER1); 
090B:  BSF    03.5
090C:  BSF    0C.0
....................  
....................   // Initialize Outputs 
....................   output_bit(PIN_C4, HI);  
090D:  BCF    03.5
090E:  BSF    07.4
090F:  BCF    6B.4
0910:  MOVF   6B,W
0911:  BSF    03.5
0912:  MOVWF  07
.................... 	output_bit(PIN_C5, LO); 
0913:  BCF    03.5
0914:  BCF    07.5
0915:  BCF    6B.5
0916:  MOVF   6B,W
0917:  BSF    03.5
0918:  MOVWF  07
....................   output_bit(PIN_B1, LO); 
0919:  BCF    03.5
091A:  BCF    06.1
091B:  BSF    03.5
091C:  BCF    06.1
....................   output_bit(PIN_B2, LO); 
091D:  BCF    03.5
091E:  BCF    06.2
091F:  BSF    03.5
0920:  BCF    06.2
....................   output_bit(PIN_B4, LO); 
0921:  BCF    03.5
0922:  BCF    06.4
0923:  BSF    03.5
0924:  BCF    06.4
....................  
....................   // Check for WDT reset and output error if necessary 
....................   switch ( restart_cause() ) 
....................   { 
0925:  MOVF   03,W
0926:  ANDLW  18
0927:  MOVWF  77
0928:  MOVF   0E,W
0929:  ANDLW  03
092A:  IORWF  77,W
092B:  BSF    0E.0
092C:  BSF    0E.1
092D:  BSF    03.3
092E:  BSF    03.4
092F:  XORLW  0B
0930:  BCF    03.5
0931:  BTFSC  03.2
0932:  GOTO   137
0933:  XORLW  13
0934:  BTFSC  03.2
0935:  GOTO   156
0936:  GOTO   157
....................     case WDT_TIMEOUT: 
....................     { 
....................       sprintf(response_message, "WDT\r\n"); 
0937:  CLRF   6D
0938:  MOVLW  39
0939:  MOVWF  6C
093A:  BSF    03.5
093B:  CLRF   3E
093C:  MOVF   3E,W
093D:  BCF    0A.3
093E:  BCF    03.5
093F:  CALL   061
0940:  BSF    0A.3
0941:  BSF    03.5
0942:  INCF   3E,F
0943:  MOVWF  77
0944:  MOVWF  6B
0945:  BCF    0A.3
0946:  BCF    03.5
0947:  CALL   1C7
0948:  BSF    0A.3
0949:  MOVLW  05
094A:  BSF    03.5
094B:  SUBWF  3E,W
094C:  BTFSS  03.2
094D:  GOTO   13C
....................       send_error_response(response_message); 
094E:  CLRF   3F
094F:  MOVLW  39
0950:  MOVWF  3E
0951:  BCF    0A.3
0952:  BCF    03.5
0953:  CALL   2E6
0954:  BSF    0A.3
....................       break; 
0955:  GOTO   157
....................     } 
....................     case NORMAL_POWER_UP: 
....................     { 
....................       break; 
0956:  GOTO   157
....................     } 
....................   } 
....................  
....................  	// Send ID info via "blank" message 
....................  	// send_response fills in the address 
....................   sprintf(response_message, "\r\n");   
0957:  CLRF   6D
0958:  MOVLW  39
0959:  MOVWF  6C
095A:  MOVLW  0D
095B:  BSF    03.5
095C:  MOVWF  6B
095D:  BCF    0A.3
095E:  BCF    03.5
095F:  CALL   1C7
0960:  BSF    0A.3
0961:  MOVLW  0A
0962:  BSF    03.5
0963:  MOVWF  6B
0964:  BCF    0A.3
0965:  BCF    03.5
0966:  CALL   1C7
0967:  BSF    0A.3
....................   send_response(response_message); 
0968:  BSF    03.5
0969:  CLRF   3F
096A:  MOVLW  39
096B:  MOVWF  3E
096C:  BCF    0A.3
096D:  BCF    03.5
096E:  CALL   32F
096F:  BSF    0A.3
....................            
....................  
.................... /* Begin Loop */         
....................     for(;;) 
.................... 		{  
.................... 		  // strobe the dog 
.................... 		  restart_wdt();  
0970:  CLRWDT
.................... 		 
....................  	  	if(rs485_get_new_message(RS485_ID, FALSE)) // Check for new command 
0971:  MOVF   60,W
0972:  BSF    03.5
0973:  MOVWF  3E
0974:  CLRF   3F
0975:  BCF    0A.3
0976:  BCF    03.5
0977:  GOTO   373
0978:  BSF    0A.3
0979:  MOVF   78,F
097A:  BTFSC  03.2
097B:  GOTO   1EE
.................... 		 	{ 
.................... 		 		// Check to see which command was received... 
....................         if(!strcmp(cmd_InBuffer,fire)) { 
097C:  BSF    03.5
097D:  CLRF   3F
097E:  MOVLW  67
097F:  MOVWF  3E
0980:  CLRF   41
0981:  MOVLW  2F
0982:  MOVWF  40
0983:  BCF    0A.3
0984:  BCF    03.5
0985:  CALL   39A
0986:  BSF    0A.3
0987:  MOVF   78,F
0988:  BTFSS  03.2
0989:  GOTO   18E
....................           handle_fire_command(); 
098A:  BCF    0A.3
098B:  GOTO   3F9
098C:  BSF    0A.3
....................         } 
....................         else if(!strcmp(cmd_InBuffer,query))  { 
098D:  GOTO   1EE
098E:  BSF    03.5
098F:  CLRF   3F
0990:  MOVLW  67
0991:  MOVWF  3E
0992:  CLRF   41
0993:  MOVLW  31
0994:  MOVWF  40
0995:  BCF    0A.3
0996:  BCF    03.5
0997:  CALL   39A
0998:  BSF    0A.3
0999:  MOVF   78,F
099A:  BTFSS  03.2
099B:  GOTO   1A0
....................           handle_query_command(); 
099C:  BCF    0A.3
099D:  GOTO   75B
099E:  BSF    0A.3
....................         } 
....................         else if(!strcmp(cmd_InBuffer,status))  { 
099F:  GOTO   1EE
09A0:  BSF    03.5
09A1:  CLRF   3F
09A2:  MOVLW  67
09A3:  MOVWF  3E
09A4:  CLRF   41
09A5:  MOVLW  33
09A6:  MOVWF  40
09A7:  BCF    0A.3
09A8:  BCF    03.5
09A9:  CALL   39A
09AA:  BSF    0A.3
09AB:  MOVF   78,F
09AC:  BTFSS  03.2
09AD:  GOTO   1B0
....................           handle_status_command(); 
09AE:  GOTO   000
....................         } 
....................         else if(!strcmp(cmd_InBuffer,version))  { 
09AF:  GOTO   1EE
09B0:  BSF    03.5
09B1:  CLRF   3F
09B2:  MOVLW  67
09B3:  MOVWF  3E
09B4:  CLRF   41
09B5:  MOVLW  35
09B6:  MOVWF  40
09B7:  BCF    0A.3
09B8:  BCF    03.5
09B9:  CALL   39A
09BA:  BSF    0A.3
09BB:  MOVF   78,F
09BC:  BTFSS  03.2
09BD:  GOTO   1C0
....................           handle_version_command(); 
09BE:  GOTO   043
....................         } 
....................         else if(!strcmp(cmd_InBuffer,actuation))  { 
09BF:  GOTO   1EE
09C0:  BSF    03.5
09C1:  CLRF   3F
09C2:  MOVLW  67
09C3:  MOVWF  3E
09C4:  CLRF   41
09C5:  MOVLW  37
09C6:  MOVWF  40
09C7:  BCF    0A.3
09C8:  BCF    03.5
09C9:  CALL   39A
09CA:  BSF    0A.3
09CB:  MOVF   78,F
09CC:  BTFSS  03.2
09CD:  GOTO   1D0
....................           handle_actuation_voltage_command(); 
09CE:  GOTO   073
....................         } 
....................         //...Or if the command is invalid 
....................         else {  
09CF:  GOTO   1EE
....................           sprintf(response_message, "BAD COMMAND\r\n"); 
09D0:  CLRF   6D
09D1:  MOVLW  39
09D2:  MOVWF  6C
09D3:  BSF    03.5
09D4:  CLRF   3E
09D5:  MOVF   3E,W
09D6:  BCF    0A.3
09D7:  BCF    03.5
09D8:  CALL   06B
09D9:  BSF    0A.3
09DA:  BSF    03.5
09DB:  INCF   3E,F
09DC:  MOVWF  77
09DD:  MOVWF  6B
09DE:  BCF    0A.3
09DF:  BCF    03.5
09E0:  CALL   1C7
09E1:  BSF    0A.3
09E2:  MOVLW  0D
09E3:  BSF    03.5
09E4:  SUBWF  3E,W
09E5:  BTFSS  03.2
09E6:  GOTO   1D5
....................           send_error_response(response_message); 
09E7:  CLRF   3F
09E8:  MOVLW  39
09E9:  MOVWF  3E
09EA:  BCF    0A.3
09EB:  BCF    03.5
09EC:  CALL   2E6
09ED:  BSF    0A.3
....................         } 
.................... 			}	// Check for new command 
....................  
....................      
....................     /* If > 30 secs have elapsed and proximity ISR has not been called, 
....................        report 0 for time elapsed 
....................     */ 
....................     if( (Fired) && (!proximity) && (!proximity_expired) ) { 
09EE:  BTFSS  5F.0
09EF:  GOTO   248
09F0:  BTFSC  5F.1
09F1:  GOTO   248
09F2:  BTFSC  5F.2
09F3:  GOTO   248
....................       getElapsedTime(); 
09F4:  BCF    0A.3
09F5:  CALL   14F
09F6:  BSF    0A.3
....................       if(ElapsedSeconds >= 30) { 
09F7:  MOVF   55,F
09F8:  BTFSS  03.2
09F9:  GOTO   204
09FA:  MOVF   54,F
09FB:  BTFSS  03.2
09FC:  GOTO   204
09FD:  MOVF   53,F
09FE:  BTFSS  03.2
09FF:  GOTO   204
0A00:  MOVF   52,W
0A01:  SUBLW  1D
0A02:  BTFSC  03.0
0A03:  GOTO   248
....................         proximity_expired = true; 
0A04:  BSF    5F.2
....................         sprintf(response_message, "prox_exp at:%Ld\r\n", ElapsedSeconds); 
0A05:  CLRF   6D
0A06:  MOVLW  39
0A07:  MOVWF  6C
0A08:  BSF    03.5
0A09:  CLRF   3E
0A0A:  MOVF   3E,W
0A0B:  BCF    0A.3
0A0C:  BCF    03.5
0A0D:  CALL   07D
0A0E:  BSF    0A.3
0A0F:  BSF    03.5
0A10:  INCF   3E,F
0A11:  MOVWF  77
0A12:  MOVWF  6B
0A13:  BCF    0A.3
0A14:  BCF    03.5
0A15:  CALL   1C7
0A16:  BSF    0A.3
0A17:  MOVLW  0C
0A18:  BSF    03.5
0A19:  SUBWF  3E,W
0A1A:  BTFSS  03.2
0A1B:  GOTO   20A
0A1C:  MOVLW  41
0A1D:  MOVWF  04
0A1E:  BCF    03.5
0A1F:  MOVF   55,W
0A20:  BSF    03.5
0A21:  MOVWF  42
0A22:  BCF    03.5
0A23:  MOVF   54,W
0A24:  BSF    03.5
0A25:  MOVWF  41
0A26:  BCF    03.5
0A27:  MOVF   53,W
0A28:  BSF    03.5
0A29:  MOVWF  40
0A2A:  BCF    03.5
0A2B:  MOVF   52,W
0A2C:  BSF    03.5
0A2D:  MOVWF  3F
0A2E:  BCF    0A.3
0A2F:  BCF    03.5
0A30:  CALL   6CC
0A31:  BSF    0A.3
0A32:  MOVLW  0D
0A33:  BSF    03.5
0A34:  MOVWF  6B
0A35:  BCF    0A.3
0A36:  BCF    03.5
0A37:  CALL   1C7
0A38:  BSF    0A.3
0A39:  MOVLW  0A
0A3A:  BSF    03.5
0A3B:  MOVWF  6B
0A3C:  BCF    0A.3
0A3D:  BCF    03.5
0A3E:  CALL   1C7
0A3F:  BSF    0A.3
....................         send_response(response_message); 
0A40:  BSF    03.5
0A41:  CLRF   3F
0A42:  MOVLW  39
0A43:  MOVWF  3E
0A44:  BCF    0A.3
0A45:  BCF    03.5
0A46:  CALL   32F
0A47:  BSF    0A.3
....................       }   
....................     } 
....................  
.................... 		} // Main control loop 
0A48:  GOTO   170
....................          
....................     
....................  
.................... } 
0A49:  SLEEP

Configuration Fuses:
   Word  1: 3F75   XT WDT PUT NODEBUG NOPROTECT BROWNOUT NOLVP NOCPD NOWRT
