Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - BMPtoTile enhancement request ?

Reply to topic
Author Message
  • Joined: 27 Feb 2023
  • Posts: 135
  • Location: France
Reply with quote
BMPtoTile enhancement request ?
Post Posted: Fri Feb 02, 2024 7:08 pm
Hello everyone,

I have been using BMPtoTile to create my games and it has been a fantastic tool, so thanks a lot to Maxim who created it.

As I am using sverx devkitsms to work on my games, there are few very simple steps I find myself doing constantly.

Whenever I generate tiles using BMPtoTile, I get this kind of output :


As you can guess, this is not really the kind of syntax you expect in a C file. So what I end up doing is copy paste the content and do the following replaces :
$ becomes ,0x
.db becomes nothing
; becomes //
as well as removing the very first comma ,

In order to end up having something like this :


So I was wondering if it could be possible to update BMPtoTile with a checkbox that would say "Output for C file" and if you check it, it would do these simple replacements.

Maybe this is something I need to try and do myself though (using the github repository) ?

Still, I wanted to share in case others might be interested as well. Thanks.
Capture.PNG (92.57 KB)
init_output
Capture.PNG
Capture1.PNG (36.48 KB)
after_output
Capture1.PNG

  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14744
  • Location: London
Reply with quote
Post Posted: Fri Feb 02, 2024 7:41 pm
To be honest, I’d expect you to use binary formats because the text version is only uncompressed data. sverx can probably direct you towards the docs for managing assets as binary files.

I guess there might be a use for emitting both compressed and uncompressed data as .c files, but it will in reality just make compilation slower as the files need to be parsed back into the binary bytes you started with…
  View user's profile Send private message Visit poster's website
  • Joined: 06 Mar 2022
  • Posts: 670
  • Location: London, UK
Reply with quote
Post Posted: Fri Feb 02, 2024 11:04 pm
I guess you're on Windows, so not really sure what options are available, but on Linux (and macos) we can simply do

xxd -i <binary_file>


And it generates C declarations directly. Extremely useful.

Maybe there is a similar utility for Windows, or a way to run xxd you can use.
  View user's profile Send private message Visit poster's website
  • Joined: 23 Jan 2010
  • Posts: 437
Reply with quote
Post Posted: Sat Feb 03, 2024 12:36 am
https://linuxhint.com/run-xxd-command-in-windows/
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14744
  • Location: London
Reply with quote
Post Posted: Sat Feb 03, 2024 8:58 am
These only exist because #embed didn’t exist yet…
  View user's profile Send private message Visit poster's website
  • Joined: 27 Feb 2023
  • Posts: 135
  • Location: France
Reply with quote
Post Posted: Sat Feb 03, 2024 10:08 am
Thank you for the suggestions. I understand I could be doing things differently, using the Save button of course.

I work on my free time like all of you I am sure, so I tend to try and find the less time consuming way to make progress.

Until now, I have been copy pasting the raw output and organizing my banks very easily this way. I know I have 16 KB in a bank, so I simply fill one with things that make sense being together and this is very quick and not relying on additional tools or steps. And of course, there is no compression (not that I really need any yet).

I am curious to see how a similar process could be done with binaries, though I like copy pasting the raw text as I very often change my visuals for several reasons and rearrange them in banks. Which means I would have to redo the steps regulargly. I am expecting that many of you have built suits of scripts that do all of these steps automically.
  View user's profile Send private message
  • Joined: 12 Aug 2021
  • Posts: 74
Reply with quote
Post Posted: Sat Feb 03, 2024 1:05 pm
Quote
I am expecting that many of you have built suits of scripts that do all of these steps automically.

In my case I have done exactly that.

After I started modifying resources often (palettes and pixels), I did not want to manually convert graphic resources all the time, so I ended up making scripts. I'll admit it's a bit boring at the start but the time gained if you change graphics often is really worth it.

My workflow goes between my Windows machine and a Linux Virtual Machine (where all SDCC stuff is), but if you're exclusively on Windows this could be even faster to automate in a single script!

I use BMP2Tile on Windows via the command line. The batch script I made looks like this:

rem "gfx_armix_logo - starts at address 64"
.\BMP2Tile.exe "Project_GFX\gfx_armix_logo.bmp" -savetiles "Project_GFX\gfx_armix_logo_tileset.bin"
.\BMP2Tile.exe "Project_GFX\gfx_armix_logo.bmp" -tileoffset 64 -savetilemap "Project_GFX\gfx_armix_logo_tilemap.bin"
.\BMP2Tile.exe "Project_GFX\gfx_armix_logo.bmp" -fullpalette -palgg  -savepalette "Project_GFX\gfx_armix_logo_palette_gg.bin"
.\BMP2Tile.exe "Project_GFX\gfx_armix_logo.bmp" -fullpalette -palsms -savepalette "Project_GFX\gfx_armix_logo_palette_sms.bin"

[... other resources]


I save the tile, tilemap and palette data as uncompressed bin files. Then I copy all of them into my C project folder on my Linux VM.

I have organised my binary resources in different folders in my C project (1 folder per bank I wanted to manage).

I have created another batch script which calls the "assets2banks" program in devkitSMS to convert these binary files to C code. (it creates .h files, see docs here: https://github.com/sverx/devkitSMS/tree/master/assets2banks )
I use the python script because my SDCC is on a Linux VM, but on Windows, you've got an exe file to use!

My resulting command line script looks like this:
python3 /path/to/assets2banks.py assets/graphics --firstbank=2 --compile
python3 /path/to/assets2banks.py assets/sounds_bank_A --firstbank=3 --compile
python3 /path/to/assets2banks.py assets/sounds_bank_B --firstbank=4 --compile


Also note the --compile command line parameter I have added here: it makes assets2banks prebuild the bank as a .rel file after it is done creating the .h file. With this, you don't need to compile the bank from C code with SDCC every time, just link the .rel file at the end! Time saved on every build!


Note that I didn't go through automating music and sfx import via PSGTool, because I modify those resources much less often, but it would probably be worth doing that for my next project!

Also I could have used a shared folder to save myself from manually copy-pasting the binary files to the Linux machine, but... I got lazy! ;)
  View user's profile Send private message
  • Joined: 06 Mar 2022
  • Posts: 670
  • Location: London, UK
Reply with quote
Post Posted: Sat Feb 03, 2024 1:17 pm
Oh I totally forgot that assets2banks can do this too! Yeah much better than xxd since it knows about bank limits.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3827
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Sat Feb 03, 2024 3:58 pm
Last edited by sverx on Sun Feb 04, 2024 2:02 pm; edited 1 time in total
cireza wrote
Until now, I have been copy pasting the raw output and organizing my banks very easily this way. I know I have 16 KB in a bank, so I simply fill one with things that make sense being together and this is very quick and not relying on additional tools or steps.
[...]
I am curious to see how a similar process could be done with binaries, though I like copy pasting the raw text as I very often change my visuals for several reasons and rearrange them in banks. Which means I would have to redo the steps regulargly. I am expecting that many of you have built suits of scripts that do all of these steps automically.


I created assets2banks for making it easy to do all this without ever having to rearrange things by hand - it's automated.

So, let's say you have an image and you open it up in BMP2Tile.
You then can save, using the button on each of BMP2Tile's tabs:
- one binary raw file for the uncompressed tiles (say 'tileset.bin')
- one binary raw file for the uncompressed tilemap (say 'tilemap.bin')
- one binary raw file for the uncompressed palette (say 'palette.bin')
(I'm using uncompressed here but even if you switched to compressed there wouldn't be any change in your approach, just in the code that you would use to load the data)

You then put all these 3 files in a folder that you call for example 'assets', and you run:
assets2banks assets

This will create one C file and one header file, provided the data can fit 16 KiB. The C file will contain the data in array form (basically what you would do manually) and the header file will contain the array definitions, plus the size and the bank number for each array.

For example, your header file would contain:
extern const unsigned char   tileset_bin[256];
#define            tileset_bin_size 256
#define            tileset_bin_bank 2
extern const unsigned char   tilemap_bin[1024];
#define            tilemap_bin_size 1024
#define            tilemap_bin_bank 2
extern const unsigned char   palette_bin[16];
#define            palette_bin_size 16
#define            palette_bin_bank 2


But this is just the basic thing assets2banks can do - once you have more assets you will find handy that it automatically arranges assets so that to better fit everything into 16 KiB banks. Also, instead of having multiple header files you can tell assets2banks to generate a single header file, or even to provide compiled .rel files instead of C files that you would have to compile yourself.

Of course you might instead need to have some assets in the same bank, you don't want them all around. So here's why you can have assets grouping. You do that by placing a config file in your assets folder and then you can instruct assets2banks regarding how you want your assets to be arranged.

And there's plenty more useful features too - you can read everything here.
Let me know if something isn't clear!
  View user's profile Send private message Visit poster's website
  • Joined: 27 Feb 2023
  • Posts: 135
  • Location: France
Reply with quote
Post Posted: Sat Feb 03, 2024 6:27 pm
armixer24 wrote
1 folder per bank I wanted to manage

Yes, I figured I would have to organize things like this eventually. The issue is that this is not really my way of organizing my resources as I create them and manage my project. Thank you for the detailed answer though, I will be sure to read it again in the future when I try to make some progress on how I deal with this.

sverx wrote
I created assets2banks for making it easy to do all this without ever having to rearrange things by hand - it's automated.

I have been using assets2banks to convert my music, and I saw that it was indeed organizing banks.

Your explanation is very clear, even if it does lead to other questions haha.

For example what happens if you specify a group but you go beyond 16 KB with this group.

Also I still need to refer to my banks in my code everytime I need to switch bank, I need to see how this is done. I name my banks, for exemple like this :

This is very useful in the code of course to keep track of what you do. This is done at the moment of compiling (assigning the number of the bank to the right file, that has a "functional name" and not simply a number).

I need to try it out and see by myself. Thanks for the link.
Capture.PNG (49.21 KB)
Capture.PNG

  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3827
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Sun Feb 04, 2024 2:01 pm
cireza wrote
Your explanation is very clear, even if it does lead to other questions haha.
For example what happens if you specify a group but you go beyond 16 KB with this group.


Basically you shouldn't do that. If you do, you'll get a "Fatal: asset group too big to fit" error message.

But, let me tell you, there are *very few* cases where you *really* need to define an asset group - for instance when you need to access two (or more) assets at the same time, for example because you have level maps made of metatiles and you need to draw on screen, so you'll likely have to access both the map and your metatiles definitions at the same time.

But most often you don't need to. Instead, say you have those three files that you converted from an image using BMP2Tile: you need to load your tiles and your tilemap to VRAM and upload you palette to CRAM. Since you'll completely perform each operation before starting the next one you would simply do:

SMS_mapROMBank(tileset_bin_bank);
SMS_loadTiles(tileset_bin, 0, tileset_bin_size);
SMS_mapROMBank(tilemap_bin_bank);
SMS_loadTileMap(0, 0, tilemap_bin, tilemap_bin_size);
SMS_mapROMBank(palette_bin_bank);
SMS_loadBGPalette(palette_bin);

and don't worry about the overhead, each mapROMBank() will just write a single byte to a specific location, so it's absolutely fast.
  View user's profile Send private message Visit poster's website
  • Joined: 27 Feb 2023
  • Posts: 135
  • Location: France
Reply with quote
Post Posted: Sun Feb 04, 2024 3:31 pm
Got it. I should actually save everything as binary files and use asset2bank. It will generate the smallest number of banks possible, and #define for every single asset. So I don't really have to worry about the bank number. And I don't have to organize things in folders with 1 folder = 1 bank.

Compiling simply requires listing all banks in order according to the number that was generated. In the rom, everything will be shuffled but this has no consequence whatsoever.

Makes sense indeed.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3827
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Sun Feb 04, 2024 4:48 pm
Yes!

I usually put
assets2banks assets_folder --compile --singleheader

so that it generates .REL files directly (so I don't have to then compile the data) and I also get a single assets2banks.h header file that I simply
#include "assets2banks.h"

in my sources.
  View user's profile Send private message Visit poster's website
  • Joined: 27 Feb 2023
  • Posts: 135
  • Location: France
Reply with quote
Post Posted: Tue Feb 06, 2024 8:24 pm
I wanted to drop a quick reply to say I have moved on using asset2bank for all my battle animations, which has worked perfectly well on the first try. I had to organize my way to convert my data a bit differently, and made single frames instead of a big file with all frames, as well as saving in binaries.

I am not fully in a state where I want to use asset2bank for absolutely everything yet, I have to figure out a few things. But I am keeping in mind that I could use compression in the future for the more static things. I am quite sure I will do it.

For now I am planning on using it with singleheader and firstbank number options, and it should work quite well for my use-case.

Thanks for the suggestion !

Edit : used the PSGaiden compression today and it works like a charm. Pretty big gain on top of this, a little more than 50%. That's pretty awesome :)
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!