-
Notifications
You must be signed in to change notification settings - Fork 0
/
satconv.c
111 lines (95 loc) · 2.62 KB
/
satconv.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* satconv.c: Entry point for program
* Copyright (C) 2021 Nathan Misner
*
* This file is part of Satconv.
*
* Satconv is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Satconv is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Satconv. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <string.h>
#include "map.h"
#include "sprite.h"
#include "tile.h"
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define BUFFER_LEN (256)
#define ASCII_NUMBER_BASE (0x30)
int main(int argc, char **argv) {
if (argc < 2) {
printf("Usage: satconv [asset list]\n");
return -1;
}
FILE *asset_list = fopen(argv[1], "r");
if (asset_list == NULL) {
printf("Error: couldn't open asset list.\n");
return -2;
}
char line[BUFFER_LEN];
while (fgets(line, BUFFER_LEN - 1, asset_list)) {
line[strcspn(line, "\r\n")] = 0;
char *infile;
char *ext;
int ext_index;
int type;
#define OUTFILE_LEN (32)
char outfile[OUTFILE_LEN];
switch(line[0]) {
// sprite directory
case 's':
case 'S':
switch(line[1]) {
case '4':
type = SPRITE_4BPP;
break;
case 'r':
case 'R':
type = SPRITE_RGB;
break;
default:
printf("Invalid sprite type %c\nBad line: %s\n", line[1], line);
continue;
}
infile = &line[3];
// cd-rom filesystem only allows 8.3 filenames
ext_index = MIN(8, strlen(infile));
memcpy(outfile, infile, ext_index);
strcpy(outfile + ext_index, ".spr");
sprite_process(infile, outfile, type);
break;
// tile graphics
case 't':
case 'T':
infile = &line[3];
ext = strchr(infile, '.');
ext_index = MIN(8, ext - infile);
memcpy(outfile, infile, ext_index);
strcpy(outfile + ext_index, ".tle");
tile_process(infile, outfile, line[1] - ASCII_NUMBER_BASE);
break;
// tilemap
case 'm':
case 'M':
infile = &line[4];
ext = strchr(infile, '.');
ext_index = MIN(8, ext - infile);
memcpy(outfile, infile, ext_index);
strcpy(outfile + ext_index, ".map");
map_process(infile, outfile, line[1] - ASCII_NUMBER_BASE, line[2] - ASCII_NUMBER_BASE);
break;
default:
break;
}
}
fclose(asset_list);
return 0;
}