]>
Commit | Line | Data |
---|---|---|
1 | #include "console.h" | |
2 | #include <minilib.h> | |
3 | ||
4 | void memcpy(void *dest, void *src, int bytes) | |
5 | { | |
6 | char * cdest = dest; | |
7 | char * csrc = src; | |
8 | while (bytes--) | |
9 | *(cdest++) = *(csrc++); | |
10 | } | |
11 | ||
12 | void memmove(void *dest, void *src, int bytes) | |
13 | { | |
14 | char * cdest = dest; | |
15 | char * csrc = src; | |
16 | if ((cdest > csrc) && (cdest <= (csrc + bytes))) | |
17 | { | |
18 | /* do it backwards! */ | |
19 | cdest += bytes; | |
20 | csrc += bytes; | |
21 | while (bytes--) | |
22 | *(--cdest) = *(--csrc); | |
23 | } else | |
24 | while (bytes--) | |
25 | *(cdest++) = *(csrc++); | |
26 | } | |
27 | ||
28 | int memcmp (const char *a2, const char *a1, int bytes) { | |
29 | while (bytes--) | |
30 | { | |
31 | if (*(a2++) != *(a1++)) | |
32 | return 1; | |
33 | } | |
34 | return 0; | |
35 | } | |
36 | ||
37 | int strcmp (const char *a2, const char *a1) { | |
38 | while (1) { | |
39 | if (*a2 != *a1) return 1; | |
40 | if (*a2 == 0) return 0; | |
41 | a1++; | |
42 | a2++; | |
43 | } | |
44 | } | |
45 | ||
46 | int strlen(const char *c) | |
47 | { | |
48 | int l = 0; | |
49 | while (*(c++)) | |
50 | l++; | |
51 | return l; | |
52 | } | |
53 | ||
54 | void strcpy(char *a2, const char *a1) | |
55 | { | |
56 | do { | |
57 | *(a2++) = *a1; | |
58 | } while (*(a1++)); | |
59 | } | |
60 | ||
61 | void puts(const char *c) | |
62 | { | |
63 | putbytes(c, strlen(c)); | |
64 | } | |
65 | ||
66 | static char hexarr[] = "0123456789ABCDEF"; | |
67 | void tohex(char *s, unsigned long l) | |
68 | { | |
69 | int i; | |
70 | for (i = 0; i < 8; i++) | |
71 | { | |
72 | s[i] = hexarr[l >> 28]; | |
73 | l <<= 4; | |
74 | } | |
75 | } | |
76 | ||
77 | void puthex(unsigned long l) | |
78 | { | |
79 | char d[9]; | |
80 | d[8] = 0; | |
81 | tohex(d, l); | |
82 | puts(d); | |
83 | } |