-
Notifications
You must be signed in to change notification settings - Fork 2
/
make4bitbin.c
47 lines (40 loc) · 1021 Bytes
/
make4bitbin.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
void main(int argc, char **argv) {
FILE *ifp;
FILE *ofp;
int address;
uint8_t idata[2];
uint8_t odata[2];
if (argc < 3) {
printf("Usage: %s [1ppb input] [4ppb output] [default load address]\n", argv[0]);
return;
}
ifp = fopen(argv[1], "r");
if (ifp == NULL) {
printf("Error opening %s for reading\n", argv[1]);
return;
}
ofp = fopen(argv[2], "w");
if (ofp == NULL) {
printf("Error opening %s for writing\n", argv[2]);
return;
}
if (argc >= 4) {
sscanf(argv[3],"%x",&address);
} else {
// set default load address to 0x0000
address = 0x0000;
}
odata[0] = (uint8_t) (address & 0x00FF);
odata[1] = (uint8_t) ((address & 0xFF00) >> 8);
fwrite(odata,1,2,ofp);
while (!feof(ifp)) {
if (fread(idata,1,2,ifp) > 0) {
odata[0] = (idata[0] & 0xf) << 4;
odata[0] |= idata[1] & 0xf;
fwrite(odata,1,1,ofp);
}
}
}