#include "../../../dinkusr.h" /* Set the number for a fixed number of dhrystone loops here. */ #define NUMBER_OF_RUNS 10000000 #include /* Substitute DINK functions for the functions. */ #define getchar local_get_char #define putchar write_char 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); } #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 /* A version of malloc that will only supply up to 2048 bytes total. */ char *malloc(unsigned int size) { static char buffer[2048]; static char *next = buffer; char *p = next; next += ((size + 7) & ~7); if (next >= buffer + sizeof(buffer)) /* Terminate by executing a zero. */ asm(".long 0"); return p; } /* Scanf is used only to read the number of times through the loop. */ /*ARGSUSED*/ #if FOR_PSIM void scanf(char *fmt, int *v) { *v = NUMBER_OF_RUNS; } #else void scanf(char *fmt, int *v) { char ch; int no_runs = 0; while ((ch = getchar()) != 0xd) /* Carriage return? */ { if ( (ch == 0x7f) || (ch == 0x8)) /* Delete? */ { putchar(0x8); /* Backspace */ putchar(0x20); /* Overprint a space. */ putchar(0x8); /* Backspace */ /* Assume modulo arithmetic to subtract last digit added. */ no_runs = no_runs / 10; } else if ( (ch >= '0') && (ch <= '9')) /* A digit? */ { putchar(ch); /* Echo it and */ /* Accumulate the value. */ no_runs = (no_runs * 10) + (ch - 48); /* ASCII character - 48 equals the digit. */ } } *v = no_runs; /* Assign second Arg the value. */ } #endif /* 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_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