File:  [Isaki's NoNo m68k/m88k emulator] / nono / vm / gencgrom.cpp
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs
Wed Apr 29 17:04:35 2026 UTC (2 months, 3 weeks ago) by root
Branches: MAIN, Isaki
CVS tags: v015, v014, v013, v012, v011, v010, v009, v008, v007, v006, v005, v004, HEAD
nono 0.1.0

//
// Copyright (C) 2012-2016 [email protected]
//
// cgrom.dat を C ソースに変換する
//
// 書式
//	gencgrom <cgrom.dat> <cgrom.cpp>
//

#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>

int
main(int ac, char *av[])
{
	char buf[4096];
	const char *infile;
	const char *outfile;
	FILE *in;
	FILE *out;
	int n;
	int i;

	if (ac < 3) {
		fprintf(stderr, "usage: %s <infile> <outfile>\n", av[0]);
		exit(1);
	}

	infile  = av[1];
	outfile = av[2];

	in = fopen(infile, "rb");
	if (in == NULL) {
		fprintf(stderr, "cannot open %s\n", infile);
		exit(1);
	}

	out = fopen(outfile, "wb");
	if (out == NULL) {
		fprintf(stderr, "cannot open %s\n", outfile);
		exit(1);
	}

	fprintf(out, "// This file is auto-generated by %s\n", av[0]);
	fprintf(out, "#include \"cgrom.h\"\n");
	fprintf(out, "/*static*/ uint8 const BuiltinCGROM::data[] = {");

	for (;;) {
		n = fread(buf, 1, sizeof(buf), in);
		if (n == 0) {
			break;
		}

		for (i = 0; i < n; i++) {
			if (i % 8 == 0) {
				fprintf(out, "\n\t");
			}
			fprintf(out, "0x%02x,", (unsigned char)buf[i]);
		}
	}
	fprintf(out, "\n};\n");

	fclose(in);
	fclose(out);
	exit(0);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.