doomlib.c (2925B)
1 /* doomlib.c */ 2 3 #include "doomdef.h" 4 5 #define WORDMASK 7 6 7 /* 8 ==================== 9 = 10 = D_memmove 11 = 12 ==================== 13 */ 14 15 void D_memmove(void *dest, void *src) // 800019F0 16 { 17 byte p; 18 byte *p1; 19 byte *p2; 20 21 p = *(byte *)src; 22 p1 = (byte *)src; 23 p2 = (byte *)dest; 24 25 *p2++ = *p1++; 26 27 while (p != '\0') 28 { 29 p = *p1; 30 *p2++ = *p1++; 31 } 32 } 33 34 /* 35 ==================== 36 = 37 = D_memset 38 = 39 ==================== 40 */ 41 42 void D_memset(void *dest, int val, int count) // 80001A20 43 { 44 byte *p; 45 int *lp; 46 int v; 47 48 /* round up to nearest word */ 49 p = dest; 50 while ((int)p & WORDMASK) 51 { 52 if (--count < 0) 53 return; 54 *p++ = (char)val; 55 } 56 57 /* write 8 bytes at a time */ 58 lp = (int *)p; 59 v = (int)(val << 24) | (val << 16) | (val << 8) | val; 60 while (count >= 8) 61 { 62 lp[0] = lp[1] = v; 63 lp += 2; 64 count -= 8; 65 } 66 67 /* finish up */ 68 p = (byte *)lp; 69 while (count--) 70 *p++ = (char)val; 71 } 72 73 /* 74 ==================== 75 = 76 = D_memcpy 77 = 78 ==================== 79 */ 80 81 void D_memcpy(void *dest, void *src, int count) // 80001ACC 82 { 83 byte *d, *s; 84 int *ld, *ls; 85 int stopcnt; 86 87 ld = (int *)dest; 88 ls = (int *)src; 89 90 if ((((int)ld | (int)ls | count) & 7)) 91 { 92 d = (byte *)dest; 93 s = (byte *)src; 94 while (count--) 95 *d++ = *s++; 96 } 97 else 98 { 99 if (count == 0) 100 return; 101 102 if(-(count & 31)) 103 { 104 stopcnt = -(count & 31) + count; 105 while (stopcnt != count) 106 { 107 ld[0] = ls[0]; 108 ld[1] = ls[1]; 109 ld += 2; 110 ls += 2; 111 count -= 8; 112 } 113 114 if (count == 0) 115 return; 116 } 117 118 while (count) 119 { 120 ld[0] = ls[0]; 121 ld[1] = ls[1]; 122 ld[2] = ls[2]; 123 ld[3] = ls[3]; 124 ld[4] = ls[4]; 125 ld[5] = ls[5]; 126 ld[6] = ls[6]; 127 ld[7] = ls[7]; 128 ld += 8; 129 ls += 8; 130 count -= 32; 131 } 132 } 133 } 134 135 /* 136 ==================== 137 = 138 = D_strncpy 139 = 140 ==================== 141 */ 142 143 void D_strncpy(char *dest, char *src, int maxcount) // 8000lBB0 144 { 145 byte *p1, *p2; 146 p1 = (byte *)dest; 147 p2 = (byte *)src; 148 while (maxcount--) 149 if (!(*p1++ = *p2++)) 150 return; 151 } 152 153 /* 154 ==================== 155 = 156 = D_strncasecmp 157 = 158 ==================== 159 */ 160 161 int D_strncasecmp(char *s1, char *s2, int len) // 80001BEC 162 { 163 while (*s1 && *s2) 164 { 165 if (*s1 != *s2) 166 return 1; 167 s1++; 168 s2++; 169 if (!--len) 170 return 0; 171 } 172 if (*s1 != *s2) 173 return 1; 174 return 0; 175 } 176 177 /* 178 ==================== 179 = 180 = D_strupr 181 = 182 ==================== 183 */ 184 185 void D_strupr(char *s) // 80001C74 186 { 187 char c; 188 189 while ((c = *s) != 0) 190 { 191 if (c >= 'a' && c <= 'z') 192 c -= 'a' - 'A'; 193 *s++ = c; 194 } 195 } 196 197 /* 198 ==================== 199 = 200 = D_strlen 201 = 202 ==================== 203 */ 204 205 int D_strlen(char *s) // 80001CC0 206 { 207 int len = 0; 208 209 while(*(s++)) 210 len++; 211 212 return len; 213 }