98 lines
4.5 KiB
C++
98 lines
4.5 KiB
C++
// Dev tool: render the ROM battle art to BMP files for inspection. usage: gfx_dump ROM OUTDIR [stage]
|
|
#include <algorithm>
|
|
#include <cstdio>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <iterator>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "gfx/rom_gfx.hpp"
|
|
|
|
namespace {
|
|
|
|
void write_bmp(const std::filesystem::path& p, const gfx::Image& img, int scale = 1) {
|
|
const int w = img.w * scale, h = img.h * scale;
|
|
const int row = w * 4;
|
|
std::vector<std::uint8_t> f(54 + static_cast<std::size_t>(row * h));
|
|
auto put32 = [&](std::size_t o, std::uint32_t v) {
|
|
for (int i = 0; i < 4; ++i) f[o + static_cast<std::size_t>(i)] = static_cast<std::uint8_t>(v >> (8 * i));
|
|
};
|
|
f[0] = 'B', f[1] = 'M';
|
|
put32(2, static_cast<std::uint32_t>(f.size()));
|
|
put32(10, 54);
|
|
put32(14, 40);
|
|
put32(18, static_cast<std::uint32_t>(w));
|
|
put32(22, static_cast<std::uint32_t>(-h)); // top-down
|
|
f[26] = 1, f[28] = 32;
|
|
for (int y = 0; y < h; ++y)
|
|
for (int x = 0; x < w; ++x) {
|
|
std::uint32_t v = img.at(x / scale, y / scale);
|
|
if ((v >> 24) == 0) v = 0xFF303040; // show transparency as dark slate
|
|
put32(54 + static_cast<std::size_t>(y * row + x * 4), v);
|
|
}
|
|
std::ofstream(p, std::ios::binary).write(reinterpret_cast<const char*>(f.data()), static_cast<std::streamsize>(f.size()));
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int main(int argc, char** argv) {
|
|
if (argc < 3) return std::fprintf(stderr, "usage: %s ROM OUTDIR [stage]\n", argv[0]), 2;
|
|
std::ifstream in(argv[1], std::ios::binary);
|
|
const std::vector<std::uint8_t> data{std::istreambuf_iterator<char>(in), {}};
|
|
if (!gfx::battle_art_supported(data)) return std::fprintf(stderr, "unsupported ROM\n"), 1;
|
|
const gfx::Rom rom(data);
|
|
const int stage = argc > 3 ? std::stoi(argv[3]) : 1;
|
|
const std::filesystem::path out = argv[2];
|
|
std::filesystem::create_directories(out);
|
|
const gfx::BattleArt a = gfx::load_battle_art(rom, stage);
|
|
write_bmp(out / "frame.bmp", a.frame, 3);
|
|
write_bmp(out / "queue_box.bmp", a.queue_box, 3);
|
|
write_bmp(out / "stage.bmp", a.stage, 2);
|
|
gfx::Image cells(13 * 9, 4 * 9 + 9);
|
|
for (int p = 0; p < 4; ++p)
|
|
for (int v = 0; v < 13; ++v)
|
|
for (int y = 0; y < 8; ++y)
|
|
for (int x = 0; x < 8; ++x) cells.at(v * 9 + x, p * 9 + y) = a.cells[static_cast<std::size_t>(p)][static_cast<std::size_t>(v)].at(x, y);
|
|
for (int p = 0; p < 4; ++p)
|
|
for (int y = 0; y < 8; ++y)
|
|
for (int x = 0; x < 8; ++x) cells.at(p * 9 + x, 36 + y) = a.block[static_cast<std::size_t>(p)].at(x, y);
|
|
write_bmp(out / "cells.bmp", cells, 6);
|
|
for (int c = 0; c < 10; ++c) write_bmp(out / ("cutin" + std::to_string(c) + ".bmp"), gfx::load_cutin_sheet(rom, c), 2);
|
|
// Every cut-in frame of every character in one row each, then the 8 select portraits.
|
|
int w = 0, h = 0;
|
|
std::vector<gfx::CutinAnim> anims;
|
|
for (int c = 0; c < 10; ++c) {
|
|
anims.push_back(gfx::load_cutin(rom, c));
|
|
int rw = 0;
|
|
for (const auto& f : anims.back().frames) rw += f.w + 2, h = std::max(h, f.h);
|
|
w = std::max(w, rw);
|
|
}
|
|
gfx::Image sheet(std::max(w, 8 * 66), (h + 2) * 10 + 66);
|
|
for (int c = 0; c < 10; ++c) {
|
|
int x = 0;
|
|
for (const auto& f : anims[static_cast<std::size_t>(c)].frames) {
|
|
for (int yy = 0; yy < f.h; ++yy)
|
|
for (int xx = 0; xx < f.w; ++xx) sheet.at(x + xx, c * (h + 2) + yy) = f.at(xx, yy);
|
|
x += f.w + 2;
|
|
}
|
|
std::printf("cutin %d: %zu frames, %d video frames\n", c, anims[static_cast<std::size_t>(c)].frames.size(),
|
|
anims[static_cast<std::size_t>(c)].length());
|
|
}
|
|
for (int k = 0; k < 8; ++k) {
|
|
const gfx::Image p = gfx::load_select_portrait(rom, k);
|
|
for (int yy = 0; yy < 64; ++yy)
|
|
for (int xx = 0; xx < 64; ++xx) sheet.at(k * 66 + xx, 10 * (h + 2) + yy) = p.at(xx, yy);
|
|
}
|
|
write_bmp(out / "cutins_all.bmp", sheet, 1);
|
|
for (int p = 0; p < 43; ++p)
|
|
if (const gfx::Image fx = gfx::load_effect_sheet(rom, p); fx.w) write_bmp(out / ("fx" + std::to_string(p) + ".bmp"), fx, 3);
|
|
const auto rg = gfx::load_ready_go(rom);
|
|
gfx::Image letters(7 * 26, 16);
|
|
for (int k = 0; k < 7; ++k)
|
|
for (int yy = 0; yy < 16; ++yy)
|
|
for (int xx = 0; xx < rg[static_cast<std::size_t>(k)].w; ++xx) letters.at(k * 26 + xx, yy) = rg[static_cast<std::size_t>(k)].at(xx, yy);
|
|
write_bmp(out / "readygo.bmp", letters, 4);
|
|
std::printf("wrote %s\n", out.c_str());
|
|
}
|