Große Umstellung. Viel hinzugefügt.
[h316.git] / pc-tools / ldc / hw_helpers.c
1 #include <stdio.h>
2 #include <string.h>
3
4 #include "hw_types.h"
5 #include "hw_helpers.h"
6
7 char *bin2str (unsigned long value, int length)
8 {
9 int c;
10 // printf("length: %i\n", length);
11 if ((length < 1) || (length > (sizeof (long) * 8)))
12 return NULL;
13 char *result = (char *) malloc (length + 1);
14 // if (result==NULL) return NULL;
15 result[length] = 0;
16 result[0] = 'f';
17 for (c = 0; c < length; c++)
18 result[length - c - 1] = '0' + ((value >> c) & 1);
19 return result;
20 }
21
22 void parstrip (char *data, int size)
23 {
24 int c;
25 for (c = 0; c < size; c++)
26 data[c] &= 127;
27 }
28
29 void parset (char *data, int size)
30 {
31 int c;
32 for (c = 0; c < size; c++)
33 data[c] |= 128;
34 }
35
36 void twistbytes (hw16 * start, int count)
37 {
38 int c;
39 char tmp;
40 for (c = 0; c < count; c++) {
41 tmp = start[c].bytes.high;
42 start[c].bytes.high = start[c].bytes.low;
43 start[c].bytes.low = tmp;
44 }
45 }