After the link are three tools, chrtobmp, banktobmp, and bgtobmp.
Chrtobmp is the crux of the set and takes a single, 16-byte PPU character on the standard input and spits out a 4bpp indexed color Windows bitmap, either supplying colors from a built-in palette or optionally taking a 4-byte PPU palette binary as an argument. I've only tested it on target aarch64-unknown-linux-gnu, but tried to make it platform and endianness agnostic. One plan I have is to harmonize my bitmap handling routine interfaces with those presented by wingdi.h so that way, if one wanted to, the code could be used with the native bitmap handler on Windows instead, integrated with GDI components, etc. While it is 2C02 character focused, I may try and extend it or use it as a base for other tile formats.
Banktobmp is then a script that uses this, along with ImageMagick's montage tool, to convert a bank of character graphics into a 16x32 bitmap of the tiles. Similarly, an optional palette can be provided, otherwise the underlying default behavior of chrtobmp is used. It's not the most efficient way to go about things, it first converts each tile into an individual 4bpp bitmap ala chrtobmp and *then* uses montage to combine all of those back together. A more efficient approach would convert all of the desired tiles into raw 4bpp but then stand up that whole array under one bitmap immediately, but that would likely require implementation in C or a more general set of bitmap CLI utilities and a pipeable command that *just* does the 2bpp->4bpp conversion
Finally, bgtobmp operates somewhat similarly, but rather than taking a whole list of tiles and building them into a sequential 16x32 map, this tool only extracts a single bank, so just the first 256 tiles provided in the file on the first argument. Like the other tools, an optional palette can be provided as the closing argument. The mapping file, a full 1024 byte 2C02 background map, is then converted into a 32x32 matrix of tiles by bitmap filename which is then supplied as the argument list to montage.
So basically, with a CHR bank in hand (all examples assume default palette):
To extract the first tile as a bitmap:
Code: Select all
dd if=CHR.bin bs=16 skip=0 count=1 | chrtobmp >out.bmp
Code: Select all
dd if=CHR.bin bs=16 skip=4 count=1 | chrtobmp >out.bmp
Code: Select all
banktobmp <CHR.bin >out.bmp
Code: Select all
bgtobmp CHR.bin <title_map.bin >out.bmp
These are not bug free, I haven't done a whole lot of bounds checking or testing with marginal values. Per my license in the repository, banktobmp and bgtobmp are public domain and I disclaim any liabilities. Chrtobmp, on the other hand, is BSD licensed, so the usual terms of that license apply. That said, if you start building some really cool suite of programs using this work, be cool and give credit if you can, or better, reach out, you'll find I'm certainly interested in helping others use what I create, I just make no guarantees that help is going to be what you asked for.
Anywho, feel free to fork, raise a merge, etc. if you want to play with these. Lastly, if you would do anything different, just do it, these are tools I wrote for me, not anyone else, so if they aren't perfect for you, they're open source
