/*file : support.c */ #include "dinkusr.h" #include /* Set the number for a fixed number of dhrystone loops here. */ #define NUMBER_OF_RUNS 10000000 int local_get_char() { /* get the keyboard parameter (which port are we using) then * call get_char with the keyboard value */ long keyboard = get_KEYBOARD(); return get_char(keyboard); } /* Dummy out the calls to exit, fopen, fprintf, and fclose. */ void my_exit() {} int my_fopen() { return 1; } int my_fprintf() {} int my_fclose() {} #if FOR_PSIM #undef NUMBER_OF_RUNS #define NUMBER_OF_RUNS 100 #undef printf extern int printf(const char *, ...); int (*dink_printf)() = (int (*)()) printf; #endif #if FOR_GCC || FOR_MECC char *strcpy(s1,s2) char *s1, *s2; { /* this is so that we can return the proper value to the caller when we exit */ char *retvalue; /* it just so happens that s1 is the proper return value */ retvalue = s1; /* now lets loop on s2 until *s2 is equal to '\0' and in this loop we need to copy the value from s2 into s1 and increment both pointers. */ while( *s2 != '\0' ) { *s1=*s2; s1 ++; s2 ++; } /* since we terminated the loop on detecting the NULL char without copying the character we need to place '\0' on s1 so that we have a proper C-string in s1 */ *s1 = '\0'; /* now lets return to the caller what he/she needs */ return retvalue; } #endif #if 0 int strlen(s) char *s; { /* this is our counter so that we can keep track of the number of characters in the string */ int i; /* so lets clear the counter to zero */ i = 0; /* now lets loop until we find a \0 on the the string. We need to increment the pointer each time and the counter each time */ while (*s != '\0') { s ++; i ++; } /* all set!!! now lets return the value to the calling program */ return i; } #endif #if FOR_GCC int strcmp(s1,s2) char *s1, *s2; { /* first thing we need to do is get to a point where the is no equality between the two strings. And if we find that one string is shorter than the other we need to exit also */ while((*s1 == *s2) && (*s1 !='\0') && (*s2 != '\0') ) { s1 ++; s2 ++; } /* now we can evaluate the current characters and respond accordingly */ if(*s1 > *s2) return 1; if(*s1 < *s2) return -1; /* they must be equal at this point */ return 0; } #endif #if FOR_GCC char *memcpy(s1,s2,n) char *s1; char *s2; int n; { char *a; char *b; a = s1; b = s2; for(;n > 0; --n, ++a,++b) *a =*b; return s1; } #endif