Created
March 28, 2018 14:55
-
-
Save raybellis/76faf71aeac985a358fdf1c1af2898ec to your computer and use it in GitHub Desktop.
16-bit ROM merger
This file contains 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 <stdlib.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
#include <stddef.h> | |
int main(int argc, char *argv[]) | |
{ | |
const size_t bufsize = 4096; | |
uint8_t buf_a[bufsize]; | |
uint8_t buf_b[bufsize]; | |
uint8_t buf_c[bufsize * 2]; | |
if (argc != 4) { | |
fprintf(stderr, "usage: merged <msb_file> <lsb_file> <out_file>\n"); | |
return EXIT_FAILURE; | |
} | |
int a = open(argv[1], O_RDONLY); | |
if (a < 0) { | |
fprintf(stderr, "couldn't open MSB file\n"); | |
return EXIT_FAILURE; | |
} | |
int b = open(argv[2], O_RDONLY); | |
if (b < 0) { | |
fprintf(stderr, "couldn't open LSB file\n"); | |
return EXIT_FAILURE; | |
} | |
int c = open(argv[3], O_RDWR | O_CREAT, 0644); | |
if (c < 0) { | |
fprintf(stderr, "couldn't open output file\n"); | |
return EXIT_FAILURE; | |
} | |
while (1) { | |
ssize_t n_a, n_b; | |
if ((n_a = read(a, &buf_a, bufsize)) <= 0) break; | |
if ((n_b = read(b, &buf_b, bufsize)) != n_a) break; | |
uint8_t *p = buf_c; | |
for (int i = 0; i < n_a; ++i) { | |
*p++ = buf_a[i]; | |
*p++ = buf_b[i]; | |
} | |
write(c, &buf_c, bufsize * 2); | |
} | |
close(a); | |
close(b); | |
close(c); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This program can re-combine the separate 8-bit ROMs found in some old 16-bit gear into a single file for subsequent analysis.