Created
June 6, 2019 08:57
-
-
Save bit-hack/dfec2b8eed2f80461bf923b8aef8c874 to your computer and use it in GitHub Desktop.
Join even and odd roms into one binary image.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(const int argc, const char **args) { | |
if (argc < 4) { | |
printf("usage: %s even.bin odd.bin out.bin", args[0]); | |
return 1; | |
} | |
FILE *odd = NULL; | |
FILE *even = NULL; | |
FILE *out = NULL; | |
// open input files | |
even = fopen(args[1], "rb"); | |
odd = fopen(args[2], "rb"); | |
if (!even || !odd) { | |
printf("unable to load bios halves"); | |
return 1; | |
} | |
// open output file | |
out = fopen(args[3], "wb"); | |
if (!out) { | |
printf("unable to open output file"); | |
return 1; | |
} | |
// while there are bytes to read | |
while (!feof(even) && !feof(odd)) { | |
unsigned char duo[2]; | |
// read 16bit byte pair | |
if (!fread(duo + 0, 1, 1, even)) | |
break; | |
if (!fread(duo + 1, 1, 1, odd)) | |
break; | |
// write pair to output file | |
fwrite(duo, 1, 2, out); | |
} | |
// close file handles | |
fclose(even); | |
fclose(odd); | |
fclose(out); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment