From fc04ca30169f7a89616bdbc16d111ce951200f62 Mon Sep 17 00:00:00 2001 From: Javier Degirolmo Date: Thu, 28 Jun 2012 10:11:45 -0300 Subject: Added C devkit :o and some instructions for which files you have to use depending whether you want the asm or C devkit --- c/tool/blob2c.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 c/tool/blob2c.c (limited to 'c/tool') diff --git a/c/tool/blob2c.c b/c/tool/blob2c.c new file mode 100644 index 0000000..d76aaae --- /dev/null +++ b/c/tool/blob2c.c @@ -0,0 +1,77 @@ +// Required headers +#include +#include +#include +#include + +// Where the Z80 blob is stored +#define MAX_SIZE 0x2000 +uint8_t blob[MAX_SIZE]; +size_t blob_size; + +//*************************************************************************** +// Program entry point +//*************************************************************************** + +int main(int argc, char **argv) { + // Check number of arguments + if (argc != 3) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return EXIT_FAILURE; + } + + // Open input file + FILE *file = fopen(argv[1], "rb"); + if (file == NULL) { + fputs("Error: couldn't open input file\n", stderr); + return EXIT_FAILURE; + } + + // Read the blob into memory and get its filesize + // Use ferror() to check for failure since most likely we will be + // attempting to read more data than is actually in the blob + blob_size = fread(blob, 1, MAX_SIZE, file); + if (ferror(file) && !feof(file)) { + fputs("Error: couldn't read input file\n", stderr); + fclose(file); + return EXIT_FAILURE; + } + + // Done with input file + fclose(file); + + // Open output file + file = fopen(argv[2], "w"); + if (file == NULL) { + fputs("Error: couldn't open output file\n", stderr); + return EXIT_FAILURE; + } + + // Start the table + fputs("static uint8_t echo_blob[] = {", file); + + // Output the blob data as a C array + // Pretty formatting too! + unsigned i; + for (i = 0; i < blob_size; i++) { + fprintf(file, "%s%3u%s", + i % 0x10 == 0 ? "\n " : "", blob[i], + i == blob_size-1 ? "" : ","); + } + + // End the table + fputs("\n};\n", file); + + // Check if there was an error (to output an error message) + if (ferror(file)) { + fputs("Error: couldn't write output file\n", stderr); + fclose(file); + return EXIT_FAILURE; + } + + // Done with output file + fclose(file); + + // Done + return EXIT_SUCCESS; +} -- cgit v1.2.3