+ for (int i = 0, cnt = 0; i < gfx->row_tiles; ++i) {
+ for (int j = 0; j < gfx->col_tiles; ++j, ++cnt) {
+
+ if (i == 0 && j == 0) {
+ gfxstream = openstream(outfile, "gfx", 0, false);
+ palstream = openstream(outfile, "pal", 0, false);
+ } else {
+ if (seperate_gfx) {
+ gfxstream = openstream(outfile, "gfx", cnt, false);
+ }
+ if (seperate_pal) {
+ palstream = openstream(outfile, "pal", cnt, false);
+ }
+ }
+
+ generate_4bpp_tile(tile_buf, gfx, true);
+ int ret = fwrite(tile_buf, sizeof(unsigned char), TILE_SZ, gfxstream);
+ if (ret != TILE_SZ) {
+ fprintf(stderr, "failed to convert, only write %d instead of %d\n", ret, TILE_SZ);
+ fclose(gfxstream);
+ goto cleanup;
+ }