CCS PCD C Compiler, Version 4.070, 41662 04-aug-08 11:08 Filename: t01.lst ROM used: 1204 bytes (1%) Largest free fragment is 65536 RAM used: 172 (1%) at main() level 174 (1%) worst case Stack: 3 worst case (1 in main + 2 for interrupts) * 00000: GOTO 200 * 00006: DATA D2,10,00 00008: DATA D2,10,00 0000A: DATA D2,10,00 0000C: DATA D2,10,00 0000E: DATA D2,10,00 00010: DATA D2,10,00 00012: DATA D2,10,00 00014: DATA 00,11,00 00016: DATA D2,10,00 00018: DATA D2,10,00 0001A: DATA D2,10,00 0001C: DATA D2,10,00 0001E: DATA D2,10,00 00020: DATA D2,10,00 00022: DATA D2,10,00 00024: DATA D2,10,00 00026: DATA D2,10,00 00028: DATA D2,10,00 0002A: DATA C0,11,00 0002C: DATA D2,10,00 0002E: DATA D2,10,00 00030: DATA D2,10,00 00032: DATA D2,10,00 00034: DATA D2,10,00 00036: DATA D2,10,00 00038: DATA D2,10,00 0003A: DATA D2,10,00 0003C: DATA 30,11,00 0003E: DATA D2,10,00 00040: DATA D2,10,00 00042: DATA D2,10,00 00044: DATA D2,10,00 00046: DATA D2,10,00 00048: DATA D2,10,00 0004A: DATA D2,10,00 0004C: DATA D2,10,00 0004E: DATA 60,11,00 00050: DATA D2,10,00 00052: DATA D2,10,00 00054: DATA D2,10,00 00056: DATA D2,10,00 00058: DATA D2,10,00 0005A: DATA D2,10,00 0005C: DATA D2,10,00 0005E: DATA D2,10,00 00060: DATA D2,10,00 00062: DATA D2,10,00 00064: DATA D2,10,00 00066: DATA D2,10,00 00068: DATA D2,10,00 0006A: DATA D2,10,00 0006C: DATA D2,10,00 0006E: DATA D2,10,00 00070: DATA D2,10,00 00072: DATA D2,10,00 00074: DATA D2,10,00 00076: DATA D2,10,00 00078: DATA D2,10,00 0007A: DATA D2,10,00 0007C: DATA D2,10,00 0007E: DATA 90,11,00 00080: DATA D2,10,00 00082: DATA D2,10,00 00084: DATA D2,10,00 00086: DATA D2,10,00 00088: DATA D2,10,00 0008A: DATA D2,10,00 0008C: DATA D2,10,00 0008E: DATA D2,10,00 00090: DATA D2,10,00 00092: DATA D2,10,00 00094: DATA D2,10,00 00096: DATA D2,10,00 00098: DATA D2,10,00 0009A: DATA D2,10,00 0009C: DATA D2,10,00 0009E: DATA D2,10,00 000A0: DATA D2,10,00 000A2: DATA D2,10,00 000A4: DATA D2,10,00 000A6: DATA D2,10,00 000A8: DATA D2,10,00 000AA: DATA D2,10,00 000AC: DATA D2,10,00 000AE: DATA D2,10,00 000B0: DATA D2,10,00 000B2: DATA D2,10,00 000B4: DATA D2,10,00 000B6: DATA D2,10,00 000B8: DATA D2,10,00 000BA: DATA D2,10,00 000BC: DATA D2,10,00 000BE: DATA D2,10,00 000C0: DATA D2,10,00 000C2: DATA D2,10,00 000C4: DATA D2,10,00 000C6: DATA D2,10,00 000C8: DATA D2,10,00 000CA: DATA D2,10,00 000CC: DATA D2,10,00 000CE: DATA D2,10,00 000D0: DATA D2,10,00 000D2: DATA D2,10,00 000D4: DATA D2,10,00 000D6: DATA D2,10,00 000D8: DATA D2,10,00 000DA: DATA D2,10,00 000DC: DATA D2,10,00 000DE: DATA D2,10,00 000E0: DATA D2,10,00 000E2: DATA D2,10,00 000E4: DATA D2,10,00 000E6: DATA D2,10,00 000E8: DATA D2,10,00 000EA: DATA D2,10,00 000EC: DATA D2,10,00 000EE: DATA D2,10,00 000F0: DATA D2,10,00 000F2: DATA D2,10,00 000F4: DATA D2,10,00 000F6: DATA D2,10,00 000F8: DATA D2,10,00 000FA: DATA D2,10,00 000FC: DATA D2,10,00 000FE: DATA D2,10,00 .................... ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// .................... /* .................... .................... CCS compiler PCWHD .................... .................... .................... July- 2008 .................... .................... www.techdesign.be .................... info@techdesign.be .................... .................... .................... */ .................... ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// .................... // .................... #include <33FJ256GP506.h> // device selection .................... //////// Standard Header file for the DSPIC33FJ256GP506 device //////////////// .................... #device DSPIC33FJ256GP506 .................... #list .................... .................... //#include .................... #device *=16 .................... .................... /* .................... //#EXPORT(HEX) .................... #define MAX_FLASH getenv("PROGRAM_MEMORY") //for PICs with 32KB of mem .................... #define LOADER_SIZE 0xff //tinybld size + a bit more (200 bytes is enough) .................... #org MAX_FLASH-LOADER_SIZE , MAX_FLASH-1 void boot_loader(void) {} .................... */ .................... .................... #include .................... //////////////////////////////////////////////////////////////////////////// .................... //// (C) Copyright 1996,2008 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 .................... /////////////////////////////////////////////////////////////////////////// .................... //// (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(unsigned int8 *)==1 .................... #define ptrdiff_t unsigned int8 .................... #else .................... #define ptrdiff_t unsigned int16 .................... #endif .................... .................... #define size_t unsigned int8 .................... #define wchar_t char .................... #define NULL 0 .................... .................... #define offsetof(s,f) (offsetofbit(s,f)/8) .................... .................... #endif .................... .................... #include .................... //////////////////////////////////////////////////////////////////////////// .................... //// (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 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' && 0s2 */ .................... .................... signed int8 memcmp(void * s1,char *s2,size_t n) .................... { .................... char *su1, *su2; .................... for(su1=s1, su2=s2; 0s2 */ .................... .................... signed int8 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 s1s2 */ .................... .................... signed int8 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 int8 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; .................... unsigned int8 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,unsigned int8 c,size_t n) .................... { .................... char uc; .................... char *su; .................... uc=c; .................... for(su=s;0= 'A' && *p <='Z') .................... *p += 'a' - 'A'; .................... return(s); .................... } .................... .................... .................... /************************************************************/ .................... .................... .................... #endif .................... .................... #include .................... /////////////////////////////////////////////////////////////////////////// .................... //// (C) Copyright 1996,2007 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 .................... .................... .................... #IF (sizeof(int16*)>1) .................... #DEFINE LONG_POINTERS 1 .................... #ELSE .................... #DEFINE LONG_POINTERS 0 .................... #ENDIF .................... .................... typedef struct { .................... signed int quot; .................... signed int rem; .................... } div_t; .................... .................... typedef struct { .................... signed long quot; .................... signed long rem; .................... } ldiv_t; .................... .................... #include .................... /////////////////////////////////////////////////////////////////////////// .................... //// (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(unsigned int8 *)==1 .................... #define ptrdiff_t unsigned int8 .................... #else .................... #define ptrdiff_t unsigned int16 .................... #endif .................... .................... #define size_t unsigned int8 .................... #define wchar_t char .................... #define NULL 0 .................... .................... #define offsetof(s,f) (offsetofbit(s,f)/8) .................... .................... #endif .................... .................... .................... //--------------------------------------------------------------------------- .................... // String conversion functions .................... //--------------------------------------------------------------------------- .................... .................... /* Standard template: float32 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); .................... .................... .................... #if defined(__PCD__) .................... .................... /* Standard template: atof(char * s) .................... * converts the initial portion of the string s to a float. .................... * returns the converted value if any, 0 otherwise .................... */ .................... float32 atof(char * s); .................... // The following functions only work on the 24 bit compiler .................... // for the 30F, 33F, 24F and 24H parts .................... .................... /* Standard template: float48 atof48(char * s) .................... * converts the initial portion of the string s to a float. .................... * returns the converted value if any, 0 otherwise .................... */ .................... float48 atof48(char * s); .................... .................... /* Standard template: float64 atof64(char * s) .................... * converts the initial portion of the string s to a float. .................... * returns the converted value if any, 0 otherwise .................... */ .................... float64 atof64(char * s); .................... #endif .................... .................... /* Standard template: float32 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 .................... */ .................... #if !defined(__PCD__) .................... float atoe(char * s); .................... #endif .................... .................... #if defined(__PCD__) .................... float32 atoe(char * s); .................... #endif .................... .................... /* 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*/ .................... #if (sizeof(long)==4) .................... #define atoi32(s) atol(s) .................... #else .................... signed int32 atoi32(char *s); .................... #endif .................... .................... #if defined(__PCD__) .................... // The following functions only work on the 24 bit compiler .................... // for the 30F, 33F, 24F and 24H parts .................... /* Syntax: signed int48 atoi48(char * s) .................... converts the initial portion of the string s to a signed int48 .................... returns the converted value if any, 0 otherwise*/ .................... .................... signed int48 atoi48(char *s); .................... .................... /* Syntax: signed int64 atoi64(char * s) .................... converts the initial portion of the string s to a signed int64 .................... returns the converted value if any, 0 otherwise*/ .................... signed int64 atoi64(char *s); .................... #endif .................... .................... /* 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, unsigned int base, char * s); .................... .................... /* Standard template: signed int16 atol(char * s) .................... * converts the initial portion of the string s to a signed int16 .................... * returns the converted value if any, 0 otherwise .................... */ .................... signed long atol(char *s); .................... .................... /* Standard template: float32 strtod(char * s,char *endptr) .................... * converts the initial portion of the string s to a float32 .................... * returns the converted value if any, 0 otherwise .................... * the final string is returned in the endptr, if endptr is not null .................... */ .................... // This function is called strtod in PCM/PCH .................... // This ensures compatibility between compilers .................... #if !defined(__PCD__) .................... float strtod(char *s,char *endptr); .................... #endif .................... .................... /* Standart template: float32 strto(char * s,char *endptr) .................... float48 strtof48(char *s,char *endptr); .................... float64 strtod(char *s,char *endptr); .................... * converts the initial portion of the string s to a float32, float48 or float64, .................... * returns the converted value if any, 0 otherwise .................... * the final string is returned in the endptr, if endptr is not null .................... */ .................... #if defined(__PCD__) .................... float32 strtof(char *s,char *endptr); .................... float48 strtof48(char *s,char *endptr); .................... float64 strtod(char *s,char *endptr); .................... #endif .................... .................... /* Standard template: int16 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: int16 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 .................... */ .................... unsigned 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 .................... */ .................... unsigned int16 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 int8 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 .................... /////////////////////////////////////////////////////////////////////////// .................... //// (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(unsigned int8 *)==1 .................... #define ptrdiff_t unsigned int8 .................... #else .................... #define ptrdiff_t unsigned int16 .................... #endif .................... .................... #define size_t unsigned int8 .................... #define wchar_t char .................... #define NULL 0 .................... .................... #define offsetof(s,f) (offsetofbit(s,f)/8) .................... .................... #endif .................... .................... #include .................... //////////////////////////////////////////////////////////////////////////// .................... //// (C) Copyright 1996,2008 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 .................... #include .................... .................... .................... .................... ////////////////////////////////////////////// .................... //// 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 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' && 0s2 */ .................... .................... signed int8 memcmp(void * s1,char *s2,size_t n) .................... { .................... char *su1, *su2; .................... for(su1=s1, su2=s2; 0s2 */ .................... .................... signed int8 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 s1s2 */ .................... .................... signed int8 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 int8 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; .................... unsigned int8 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,unsigned int8 c,size_t n) .................... { .................... char uc; .................... char *su; .................... uc=c; .................... for(su=s;0= '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); .................... } .................... #if !defined(__PCD__) .................... .................... float atof(char * s) .................... { .................... float pow10 = 1.0; .................... float result = 0.0; .................... unsigned int8 sign = 0; .................... char c; .................... unsigned int8 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); .................... } .................... #endif .................... .................... #if defined(__PCD__) .................... float32 atof(char * s) .................... { .................... float32 pow10 = 1.0; .................... float32 result = 0.0; .................... unsigned int8 sign = 0; .................... char c; .................... unsigned int8 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); .................... } .................... .................... .................... .................... float48 atof48(char * s) .................... { .................... float48 pow10 = 1.0; .................... float48 result = 0.0; .................... unsigned int8 sign = 0; .................... char c; .................... unsigned int8 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); .................... } .................... .................... float64 atof64(char * s) .................... { .................... float64 pow10 = 1.0; .................... float64 result = 0.0; .................... unsigned int8 sign = 0; .................... char c; .................... unsigned int8 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); .................... } .................... #endif .................... .................... #if defined(__PCD__) .................... float32 atoe(char * s) .................... { .................... float32 pow10 = 1.0; .................... float32 result = 0.0; .................... unsigned int8 sign = 0; .................... unsigned int8 expsign = 0; .................... char c; .................... unsigned int8 ptr = 0; .................... unsigned int8 i; .................... float32 exp = 1.0; .................... unsigned int8 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='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= '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; .................... unsigned 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) ); .................... } .................... .................... #if sizeof(long)==2 .................... signed int32 atoi32(char *s) .................... { .................... signed int32 result; .................... int8 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); .................... } .................... #endif .................... .................... #if defined(__PCD__) .................... .................... signed int48 atoi48(char *s) .................... { .................... signed int48 result; .................... int8 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); .................... } .................... .................... signed int64 atoi64(char *s) .................... { .................... signed int64 result; .................... int8 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); .................... } .................... #endif .................... .................... char * itoa(signed int32 num, unsigned int base, char * s) .................... { .................... unsigned int32 temp=1; .................... unsigned 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; .................... } .................... .................... #if !defined(__PCD__) .................... float strtod(char *s,char *endptr) { .................... float pow10 = 1.0; .................... float result = 0.0; .................... unsigned int8 sign = 0, point = 0; .................... char c; .................... unsigned int8 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--; .................... #IF LONG_POINTERS .................... *((long *)endptr)= s+ptr; .................... #ELSE .................... *((char *)endptr)=s+ptr; .................... #ENDIF .................... } .................... else .................... { .................... #IF LONG_POINTERS .................... *((long *)endptr)= s; .................... #ELSE .................... *((char *)endptr)=s; .................... #ENDIF .................... } .................... } .................... .................... return(result); .................... } .................... #endif .................... .................... #if defined(__PCD__) .................... float32 strtof(char *s,char *endptr) .................... { .................... float32 pow10 = 1.0; .................... float32 result = 0.0; .................... unsigned int8 sign = 0, point = 0; .................... char c; .................... unsigned int8 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--; .................... #IF LONG_POINTERS .................... *((long *)endptr)= s+ptr; .................... #ELSE .................... *((char *)endptr)=s+ptr; .................... #ENDIF .................... } .................... else .................... { .................... #IF LONG_POINTERS .................... *((long *)endptr)= s; .................... #ELSE .................... *((char *)endptr)=s; .................... #ENDIF .................... } .................... } .................... .................... return(result); .................... } .................... .................... float48 strtof48(char *s,char *endptr) .................... { .................... float48 pow10 = 1.0; .................... float48 result = 0.0; .................... unsigned int8 sign = 0, point = 0; .................... char c; .................... unsigned int8 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--; .................... #IF LONG_POINTERS .................... *((long *)endptr)= s+ptr; .................... #ELSE .................... *((char *)endptr)=s+ptr; .................... #ENDIF .................... } .................... else .................... { .................... #IF LONG_POINTERS .................... *((long *)endptr)= s; .................... #ELSE .................... *((char *)endptr)=s; .................... #ENDIF .................... } .................... } .................... .................... return(result); .................... } .................... .................... float64 strtod(char *s,char *endptr) .................... { .................... float64 pow10 = 1.0; .................... float64 result = 0.0; .................... unsigned int8 sign = 0, point = 0; .................... char c; .................... unsigned int8 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--; .................... #IF LONG_POINTERS .................... *((long *)endptr)= s+ptr; .................... #ELSE .................... *((char *)endptr)=s+ptr; .................... #ENDIF .................... } .................... else .................... { .................... #IF LONG_POINTERS .................... *((long *)endptr)= s; .................... #ELSE .................... *((char *)endptr)=s; .................... #ENDIF .................... } .................... } .................... .................... return(result); .................... } .................... #endif .................... .................... unsigned 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=='-' || base <0 || base ==1|| base >36) // invalid base .................... goto StrtoulGO; .................... .................... 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) .................... { .................... StrtoulGO: .................... if (endptr) .................... { .................... #IF LONG_POINTERS .................... *((long *)endptr)= s; .................... #ELSE .................... *((char *)endptr)=s; .................... #ENDIF .................... } .................... return 0; .................... } .................... if (endptr) .................... { .................... #IF LONG_POINTERS .................... *((long *)endptr)= sc; .................... #ELSE .................... *((char *)endptr)=sc; .................... #ENDIF .................... } .................... 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 .................... goto StrtolGO; .................... 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) .................... { .................... StrtolGO: .................... if (endptr) .................... { .................... #IF LONG_POINTERS .................... *((long *)endptr)= s; .................... #ELSE .................... *((char *)endptr)=s; .................... #ENDIF .................... } .................... return 0; .................... } .................... if(sign=='-') .................... x =-x; .................... if (endptr) .................... { .................... #IF LONG_POINTERS .................... *((long *)endptr)= sc; .................... #ELSE .................... *((char *)endptr)=sc; .................... #ENDIF .................... } .................... return x; .................... } .................... .................... signed int8 system(char *string) .................... { .................... return 0; .................... } .................... .................... int8 mblen(char *s,size_t n) .................... { .................... return strlen(s); .................... } .................... .................... int8 mbtowc(wchar_t *pwc,char *s,size_t n) .................... { .................... *pwc=*s; .................... return 1; .................... } .................... .................... int8 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; .................... .................... unsigned int16 rand(void) .................... { .................... _Randseed = _Randseed * 1103515245 + 12345; .................... return ((unsigned int16)(_Randseed >> 16) % RAND_MAX); .................... } .................... .................... void srand(unsigned int32 seed) .................... { .................... _Randseed = seed; .................... } .................... .................... //--------------------------------------------------------------------------- .................... // Searching and sorting utilities implementation .................... //--------------------------------------------------------------------------- .................... .................... #if !defined(__PCD__) .................... typedef signed int8 (*_Cmpfun)(char * p1,char * p2); .................... #else .................... typedef signed int16 (*_Cmpfun)(char * p1,char * p2); .................... #endif .................... .................... .................... .................... void qsort(char * qdata, unsigned int qitems, unsigned int qsize, _Cmpfun cmp) { .................... unsigned int m,j,i,l; .................... int1 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 .................... .................... .................... //#org 0x00200,0x0201 void dummy(){} .................... .................... //////// Program memory: 87552x24 Data RAM: 16384 Stack: 31 .................... //////// I/O: 61 Analog Pins: 18 .................... //////// Fuses: ICS0,ICS1,ICS2,ICS3,JTAG,NOJTAG,COE,NOCOE,DEBUG,NODEBUG .................... //////// Fuses: NOPUT,PUT2,PUT4,PUT8,PUT16,PUT32,PUT64,PUT128,WPOSTS1 .................... //////// Fuses: WPOSTS2,WPOSTS3,WPOSTS4,WPOSTS5,WPOSTS6,WPOST7,WPOSTS8 .................... //////// Fuses: WPOSTS9,WPOSTS10,WPOSTS11,WPOSTS12,WPOSTS13,WPOSTS14 .................... //////// Fuses: WPOSTS15,WPOSTS16,WPRES128,WPRES32,WINDIS,NOWINDIS,WDT,NOWDT .................... //////// Fuses: EC,XT,HS,NOPR,OSCIO,NOOSCIO,CKSFSM,NOCKSFSM,FRC_PLL,PR .................... //////// Fuses: PR_PLL,LP,LPRC,FRC,TEMP,NOTEMP,IESO,NOIESO,WRT,NOWRT .................... //////// Fuses: PROTECTH,NOPROTECT,PROTECTS,WRTSS,NOWRTSS,SSSH,SSSS,NOSSS .................... //////// Fuses: NORSS,RSS,WRTB,NOWRTB,BSSH,BSSS,NOBSS,RBS,NORBS,CKSNOFSM .................... .................... /* from 048 hs40 .................... */ .................... .................... #FUSES NORBS,NOBSS,NOWRTB // 0 .................... #FUSES NORSS,NOSSS,NOWRTSS // 2 .................... #FUSES NOWRT,NOPROTECT // 4 .................... #FUSES PR,TEMP,IESO // 6 .................... #FUSES HS,OSCIO // 8 .................... #FUSES WPOSTS16,WPRES32,NOWINDIS,NOWDT // A .................... #FUSES PUT128 // C .................... #FUSES ICS1,NOJTAG,NOCOE // E .................... .................... #FUSES NODEBUG //NOCKSFSM, .................... #FUSES RESERVED //Used to set the reserved FUSE bits .................... .................... .................... //#rom 0xf80000 = {0xcf,0xcf,0x07,0xa1,0x83,0x5f,0xe7,0xe3} .................... .................... .................... .................... /* .................... config __FBS, RBS_NO_RAM & BSS_NO_BOOT_CODE & BWRP_WRPROTECT_OFF .................... config __FSS, RSS_NO_SEC_RAM & SSS_NO_SEC_CODE & SWRP_WRPROTECT_OFF .................... config __FGS, GSS_OFF & GCP_OFF & GWRP_OFF .................... config __FOSCSEL, FNOSC_PRI & IESO_ON .................... config __FOSC, FCKSM_CSECME & OSCIOFNC_OFF & POSCMD_HS .................... config __FWDT, FWDTEN_OFF & WINDIS_OFF & WDTPRE_PR32 & WDTPOST_PS32768 .................... config __FPOR, FPWRT_PWR2 .................... config __FICD, BKBUG_ON & COE_ON & JTAGEN_OFF & ICS_PGD2 .................... */ .................... .................... #use delay(clock=40000000) // 40 MhZ * 01204: CP0 W0 01206: BTSC.B 42.1 01208: BRA 121A 0120A: REPEAT #E19 0120C: NOP 0120E: REPEAT #5 01210: NOP 01212: REPEAT #3FFF 01214: NOP 01216: DEC W0,W0 01218: BRA 1204 0121A: RETURN .................... .................... .................... #use rs232(UART2,baud=115200,stream=ser2) .................... .................... .................... .................... .................... #use standard_io(B) .................... #use standard_io(C) .................... #use standard_io(D) .................... #use standard_io(F) .................... #use standard_io(G) .................... .................... /* .................... #use standard_io(B) .................... #use fast_io(C) .................... #use fast_io(D) .................... #use fast_io(F) .................... #use fast_io(G) .................... */ .................... .................... #define rs232_2_en PIN_B0 .................... .................... .................... #define NOP #asm nop #endasm .................... .................... .................... .................... //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// .................... //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// .................... // declaration of global variables and routines .................... .................... .................... #define BUFFER_SIZE 32 .................... BYTE buffer[BUFFER_SIZE]; .................... BYTE next_in = 0; * 00228: CLR.B 826 .................... BYTE next_out = 0; 0022A: CLR.B 827 .................... .................... unsigned int32 st_addr=0x2a800; 0022C: MOV #A800,W4 0022E: MOV W4,828 00230: MOV #2,W4 00232: MOV W4,82A .................... .................... .................... //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// .................... .................... #int_default .................... default_isr() { * 010D2: PUSH 36 010D4: MOV W0,[W15++] 010D6: MOV #2,W0 010D8: REPEAT #C 010DA: MOV [W0++],[W15++] .................... .................... fprintf(ser2,"Default interrupt\r\n"); 010DC: MOV #0,W1 010DE: MOV W1,W0 010E0: CALL 1002 010E4: INC W1,W1 010E6: BTSC.B 233.1 010E8: BRA 10E6 010EA: MOV W0,234 010EC: MOV #12,W0 010EE: CPSGT W1,W0 010F0: BRA 10DE .................... return 0; 010F2: CLR.B 0 .................... .................... } .................... 010F4: MOV #1A,W0 010F6: REPEAT #C 010F8: MOV [--W15],[W0--] 010FA: MOV [--W15],W0 010FC: POP 36 010FE: RETFIE .................... #int_ext0 .................... default_ext0() { 01100: PUSH 36 01102: MOV W0,[W15++] 01104: MOV #2,W0 01106: REPEAT #C 01108: MOV [W0++],[W15++] .................... .................... fprintf(ser2,"ext0 interrupt\r\n"); 0110A: MOV #0,W1 0110C: MOV W1,W0 0110E: CALL 1022 01112: INC W1,W1 01114: BTSC.B 233.1 01116: BRA 1114 01118: MOV W0,234 0111A: MOV #F,W0 0111C: CPSGT W1,W0 0111E: BRA 110C .................... return 0; 01120: CLR.B 0 .................... } .................... 01122: BCLR.B 84.0 01124: MOV #1A,W0 01126: REPEAT #C 01128: MOV [--W15],[W0--] 0112A: MOV [--W15],W0 0112C: POP 36 0112E: RETFIE .................... #int_ext1 .................... default_ext1() { 01130: PUSH 36 01132: MOV W0,[W15++] 01134: MOV #2,W0 01136: REPEAT #C 01138: MOV [W0++],[W15++] .................... .................... fprintf(ser2,"ext1 interrupt\r\n"); 0113A: MOV #0,W1 0113C: MOV W1,W0 0113E: CALL 1040 01142: INC W1,W1 01144: BTSC.B 233.1 01146: BRA 1144 01148: MOV W0,234 0114A: MOV #F,W0 0114C: CPSGT W1,W0 0114E: BRA 113C .................... return 0; 01150: CLR.B 0 .................... } .................... 01152: BCLR.B 86.4 01154: MOV #1A,W0 01156: REPEAT #C 01158: MOV [--W15],[W0--] 0115A: MOV [--W15],W0 0115C: POP 36 0115E: RETFIE .................... #int_ext2 .................... default_ext2() { 01160: PUSH 36 01162: MOV W0,[W15++] 01164: MOV #2,W0 01166: REPEAT #C 01168: MOV [W0++],[W15++] .................... .................... fprintf(ser2,"ext2 interrupt\r\n"); 0116A: MOV #0,W1 0116C: MOV W1,W0 0116E: CALL 105E 01172: INC W1,W1 01174: BTSC.B 233.1 01176: BRA 1174 01178: MOV W0,234 0117A: MOV #F,W0 0117C: CPSGT W1,W0 0117E: BRA 116C .................... return 0; 01180: CLR.B 0 .................... } .................... 01182: BCLR.B 87.5 01184: MOV #1A,W0 01186: REPEAT #C 01188: MOV [--W15],[W0--] 0118A: MOV [--W15],W0 0118C: POP 36 0118E: RETFIE .................... #int_ext3 .................... default_ext3() { 01190: PUSH 36 01192: MOV W0,[W15++] 01194: MOV #2,W0 01196: REPEAT #C 01198: MOV [W0++],[W15++] .................... .................... fprintf(ser2,"ext3 interrupt\r\n"); 0119A: MOV #0,W1 0119C: MOV W1,W0 0119E: CALL 107C 011A2: INC W1,W1 011A4: BTSC.B 233.1 011A6: BRA 11A4 011A8: MOV W0,234 011AA: MOV #F,W0 011AC: CPSGT W1,W0 011AE: BRA 119C .................... return 0; 011B0: CLR.B 0 .................... } .................... .................... .................... .................... .................... 011B2: BCLR.B 8A.5 011B4: MOV #1A,W0 011B6: REPEAT #C 011B8: MOV [--W15],[W0--] 011BA: MOV [--W15],W0 011BC: POP 36 011BE: RETFIE .................... #int_rda .................... void serial_isr() { 011C0: PUSH 36 011C2: MOV W0,[W15++] 011C4: MOV #2,W0 011C6: REPEAT #C 011C8: MOV [W0++],[W15++] .................... int t; .................... .................... buffer[next_in]=getc(ser2); 011CA: MOV 826,W4 011CC: CLR.B 9 011CE: MOV #806,W3 011D0: ADD W4,W3,W5 011D2: BTSS.B 232.0 011D4: BRA 11D2 011D6: MOV 236,W0 011D8: MOV.B W0L,[W5] .................... t=next_in; 011DA: MOV.B 826,W0L 011DC: MOV.B W0L,82C 011DE: CLR.B 82D .................... next_in=(next_in+1) % BUFFER_SIZE; 011E0: MOV 826,W4 011E2: ADD.B W4L,#1,W4L 011E4: MOV.B W4L,W0L 011E6: MOV.B W0L,0 011E8: AND.B W0L,#1F,W0L 011EA: MOV.B W0L,826 .................... if(next_in==next_out) 011EC: MOV.B 826,W0L 011EE: CP.B 827 011F0: BRA NZ,11F6 .................... next_in=t; // Buffer full !! 011F2: MOV.B 82C,W0L 011F4: MOV.B W0L,826 .................... } .................... .................... #define bkbhit (next_in!=next_out) .................... 011F6: BCLR.B 85.3 011F8: MOV #1A,W0 011FA: REPEAT #C 011FC: MOV [--W15],[W0--] 011FE: MOV [--W15],W0 01200: POP 36 01202: RETFIE .................... BYTE bgetc() { .................... BYTE c; .................... .................... while(!bkbhit) ; .................... c=buffer[next_out]; .................... next_out=(next_out+1) % BUFFER_SIZE; .................... return(c); .................... } .................... .................... .................... .................... .................... #zero_ram // all ram variables to zero .................... .................... .................... //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// .................... //------------------------------------------- .................... //#org 0x00200,0x00201 void dummy(){} .................... // .................... .................... // dummy(){} .................... //#build(reset=0x200:0x200,interrupt=0x004:0x1ff) .................... // .................... .................... //#build(memory=0x00000:0x2ab00) .................... //#build(reset=0x00200:0x00200) .................... //#build(reset=0x200) .................... .................... //#build(reset=0x200:0x201) .................... .................... .................... .................... //#rom 0x00000={1,2,3,4,5,6,7,8} .................... .................... //#org 0x2a800,0x2ab00 auto=1 .................... // .................... // .................... //#build (interrupt= 0x004:0x1fe) .................... .................... //#define LOADER_ISR 0x104 .................... //#build(interrupt=LOADER_ISR) .................... .................... //#define LOADER_res 0x200 .................... //#build(reset=LOADER_res) .................... .................... //#asm .org #st_addr #endasm .................... .................... #org 0x200,0x1000 void main() .................... { * 00200: MOV #4444,W0 00202: MOV W0,A8 00204: MOV #800,W0 00206: MOV #1FFE,W1 00208: REPEAT W1 0020A: CLR [W0++] 0020C: CLR.B 20 0020E: MOV #8000,W4 00210: MOV W4,230 00212: MOV #400,W4 00214: MOV W4,232 00216: MOV #A,W4 00218: MOV W4,238 0021A: CLR 32C 0021C: CLR 32A 0021E: MOV #1F80,W15 00220: MOV #1FFF,W0 00222: MOV W0,20 00224: NOP .................... // .................... //#build(reset=0x00200) .................... //write_configuration_memory(cdata,1); .................... // .................... //goto_address(0x2a800); .................... .................... .................... .................... SETUP_ADC_PORTS(NO_ANALOGS); * 00234: SETM 32C 00236: SETM 32A .................... .................... // set port directions // o= output // i=input .................... SET_TRIS_B(0x4002); // oioo oooo oooo ooio 00238: MOV #4002,W4 0023A: MOV W4,2C6 .................... SET_TRIS_C(0x4080); // oioo oooo iooo oooo 0023C: MOV #4080,W4 0023E: MOV W4,2CC .................... SET_TRIS_D(0xff00); // iiii iiii oooo oooo 00240: MOV #FF00,W4 00242: MOV W4,2D2 .................... SET_TRIS_F(0x14); // oooi oioo 00244: MOV #14,W4 00246: MOV W4,2DE .................... SET_TRIS_G(0x1200); // oooi ooio oooo oooo 00248: MOV #1200,W4 0024A: MOV W4,2E4 .................... .................... .................... //setup_spi(SPI_SS_DISABLED); .................... setup_spi2(SPI_SS_DISABLED); 0024C: BSET.B 262.7 0024E: BCLR.B 260.6 00250: MOV #8000,W4 00252: MOV W4,262 00254: BSET.B 261.7 .................... .................... setup_wdt(WDT_OFF); // needed in PLL mode, otherwise auto reset after approx. 9 min. ???? <--- todo: check 00256: BCLR.B 740.5 .................... disABLE_INTERRUPTS(INT_RDA); 00258: BCLR.B 95.3 .................... disaBLE_INTERRUPTS(INT_EXT0); 0025A: BCLR.B 94.0 .................... disable_interrupts(INTR_NORMAL); .................... disable_interrupts(INTR_GLOBAL); 0025C: MOV #E0,W4 0025E: MOV W4,42 .................... .................... .................... OUTPUT_BIT(rs232_2_en,0); 00260: BCLR.B 2CA.0 00262: BCLR.B 2C6.0 .................... .................... .................... /////////////////////////////////////////////////////////////////////////////////////////// .................... /////////////////////////////////////////////////////////////////////////////////////////// .................... ///////////////////////////////////////////// .................... while(true){ // BOF while(true) .................... .................... .................... .................... delay_ms(100); 00264: MOV #64,W0 00266: CALL 1204 .................... fprintf(ser2," hi there! "); 0026A: MOV #0,W1 0026C: MOV W1,W0 0026E: CALL 109A 00272: INC W1,W1 00274: BTSC.B 233.1 00276: BRA 274 00278: MOV W0,234 0027A: MOV #A,W0 0027C: CPSGT W1,W0 0027E: BRA 26C .................... fprintf(ser2," ** hello world ** "); 00280: MOV #0,W1 00282: MOV W1,W0 00284: CALL 10B2 00288: INC W1,W1 0028A: BTSC.B 233.1 0028C: BRA 28A 0028E: MOV W0,234 00290: MOV #12,W0 00292: CPSGT W1,W0 00294: BRA 282 .................... } // EOF while(true) 00296: BRA 264 .................... .................... .................... } // EOF main .................... ///////////////////////////////////////////////////////////// .................... /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// .................... .................... ////////////////////////////////////////////////////////////////////////////////// .................... ////////////////////////////////////////////////////////////////////////////////// .................... .................... .................... .................... // The End! .................... // 00298: PWRSAV #0 Configuration Fuses: Word 1L: 00CF NOWRTB NOBSS NORBS H: 0000 Word 2L: 00CF NOWRTSS NOSSS NORSS H: 0000 Word 3L: 0007 NOWRT NOPROTECT H: 0000 Word 4L: 00A2 PR TEMP IESO H: 0000 Word 5L: 00C6 HS OSCIO NOCKSFSM H: 0000 Word 6L: 000F WPOSTS16 WPRES32 NOWINDIS NOWDT H: 0000 Word 7L: 00E7 PUT128 RESERVED H: 0000 Word 8L: 00C2 ICS1 NOJTAG NOCOE NODEBUG H: 0000