Annotation of nono/vm/genrom.cpp, revision 1.1.1.2

1.1       root        1: //
1.1.1.2 ! root        2: // Copyright (C) 2012-2022 Tetsuya Isaki
1.1       root        3: //
                      4: // ROM イメージを C ソースに変換する
                      5: //
                      6: // 書式
                      7: //     genrom <rom.dat> <rom.cpp> <variable_name>
                      8: // 例
                      9: //     genrom CGROM.DAT cgrom.cpp CGROM
                     10: //
                     11: 
                     12: #include <cstdint>
                     13: #include <cstdio>
                     14: #include <cstdlib>
                     15: #include <cstring>
                     16: 
                     17: int
                     18: main(int ac, char *av[])
                     19: {
                     20:        char buf[4096];
                     21:        const char *infile;
                     22:        const char *outfile;
                     23:        const char *varname;
                     24:        FILE *in;
                     25:        FILE *out;
                     26:        int n;
                     27:        int i;
                     28: 
                     29:        if (ac < 4) {
                     30:                fprintf(stderr, "usage: %s <infile> <outfile> <variable_name>\n",
                     31:                        av[0]);
                     32:                exit(1);
                     33:        }
                     34: 
                     35:        infile  = av[1];
                     36:        outfile = av[2];
                     37:        varname = av[3];
                     38: 
                     39:        in = fopen(infile, "rb");
                     40:        if (in == NULL) {
                     41:                fprintf(stderr, "cannot open %s\n", infile);
                     42:                exit(1);
                     43:        }
                     44: 
                     45:        out = fopen(outfile, "wb");
                     46:        if (out == NULL) {
                     47:                fprintf(stderr, "cannot open %s\n", outfile);
                     48:                exit(1);
                     49:        }
                     50: 
                     51:        fprintf(out, "// This file was generated by %s\n", av[0]);
                     52:        fprintf(out, "#include \"builtinrom.h\"\n");
                     53:        fprintf(out, "/*static*/ uint8 const Builtin::%s[] = {", varname);
                     54: 
                     55:        for (;;) {
                     56:                n = fread(buf, 1, sizeof(buf), in);
                     57:                if (n == 0) {
                     58:                        break;
                     59:                }
                     60: 
                     61:                for (i = 0; i < n; i++) {
                     62:                        if (i % 8 == 0) {
                     63:                                fprintf(out, "\n\t");
                     64:                        }
                     65:                        fprintf(out, "0x%02x,", (unsigned char)buf[i]);
                     66:                }
                     67:        }
                     68:        fprintf(out, "\n};\n");
                     69: 
                     70:        fclose(in);
                     71:        fclose(out);
                     72:        exit(0);
                     73: }

unix.superglobalmegacorp.com

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