-
Notifications
You must be signed in to change notification settings - Fork 0
/
maketiles.c
73 lines (62 loc) · 1.5 KB
/
maketiles.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#define DEFAULT_WIDTH 384
void main(int argc, char **argv) {
FILE *ifp;
FILE *ofp;
uint8_t *idata;
uint8_t *odata;
int width;
int address;
int i,j,k;
if (argc < 3) {
printf("Usage: %s [input raw data] [tile data file] [width] [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) {
width = atoi(argv[3]);
} else {
width = DEFAULT_WIDTH;
}
idata = malloc(width*16);
odata = calloc(width,16);
// start 12-bit with default address
if (argc >= 5) {
sscanf(argv[4],"%x",&address);
} else {
// set default load address to 0x5000
address = 0x5000;
}
odata[0] = (uint8_t) (address & 0x00FF);
odata[1] = (uint8_t) ((address & 0xFF00) >> 8);
fwrite(odata,1,2,ofp);
// make black tile
fwrite(&odata[2],256,1,ofp);
while (!feof(ifp)) {
if (fread(idata,1,width*16,ifp) >= 6144) {
for (i=0;i<width/16;i++) {
for (j=0;j<16;j++) {
for (k=0;k<16;k++) {
odata[i*256+j*16+k] = idata[j*width+i*16+k];
}
}
}
fwrite(odata,1,width*16,ofp);
}
}
fclose(ifp);
fclose(ofp);
free(idata);
free(odata);
}