From b10768d7539d01df09cdbd2ec66a82406c382e7c Mon Sep 17 00:00:00 2001 From: dannye <33dannye@gmail.com> Date: Sun, 13 Dec 2020 14:27:45 -0600 Subject: Use rgbgfx instead of gfx.py and use pokered's Makefile structure --- tools/common.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tools/common.h (limited to 'tools/common.h') diff --git a/tools/common.h b/tools/common.h new file mode 100644 index 0000000..4da0b2e --- /dev/null +++ b/tools/common.h @@ -0,0 +1,40 @@ +#ifndef GUARD_COMMON_H +#define GUARD_COMMON_H + +int __getopt_long_i__; +#define getopt_long(c, v, s, l) getopt_long(c, v, s, l, &__getopt_long_i__) + +FILE *fopen_verbose(char *filename, char *mode) { + FILE *f = fopen(filename, mode); + if (!f) { + fprintf(stderr, "Could not open file: \"%s\"\n", filename); + } + return f; +} + +uint8_t *read_u8(char *filename, int *size) { + FILE *f = fopen_verbose(filename, "rb"); + if (!f) { + exit(1); + } + fseek(f, 0, SEEK_END); + *size = ftell(f); + rewind(f); + uint8_t *data = malloc(*size); + if (*size != (int)fread(data, 1, *size, f)) { + fprintf(stderr, "Could not read file: \"%s\"\n", filename); + exit(1); + } + fclose(f); + return data; +} + +void write_u8(char *filename, uint8_t *data, int size) { + FILE *f = fopen_verbose(filename, "wb"); + if (f) { + fwrite(data, 1, size, f); + fclose(f); + } +} + +#endif // GUARD_COMMON_H -- cgit v1.2.3