-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpriteBinaryGenerator.c
More file actions
44 lines (37 loc) · 968 Bytes
/
SpriteBinaryGenerator.c
File metadata and controls
44 lines (37 loc) · 968 Bytes
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
/* SpriteParser.c - Parses the t files from matlab into an MIF file format
*/
#include <stdio.h>
#include <stdlib.h>
#define INPUT_FILE "pokemon_sprites.png" // Input filename
#define OUTPUT_FILE "pokemon.ram" // Name of file to output to
#define NUM_COLORS 4 // Total number of different colors
#define WIDTH 8
#define DEPTH 3072
// Use this to define value of each color in the palette
const long Palette_Colors []= {426715, 0, 182960, 255255255};
int addr = 0;
int main()
{
char line[21];
FILE *in = fopen(INPUT_FILE, "r");
FILE *out = fopen(OUTPUT_FILE, "w");
size_t num_chars = 20;
long value = 0;
int i;
int *p;
if(!in)
{
printf("Unable to open input file!");
return -1;
}
// Get a line, convert it to an integer, and compare it to the palette values.
while(fgets(line, num_chars, in) != NULL)
{
value = (char)strtol(line, NULL, 10);
p = (int *)&value;
fwrite(p, 2, 1, out);
}
fclose(out);
fclose(in);
return 0;
}