#png #tile #gameboy #image #command-line-tool #convert #gbdk

应用 gbtile

一个小型命令行工具,用于将PNG图像转换为GBDK兼容的游戏机瓷砖

2个不稳定版本

0.2.0 2023年3月19日
0.1.0 2020年5月20日

118模拟器

每月下载量29

MIT许可

26KB
296 行代码

GB Tile

一个小型命令行工具,用于将PNG图像转换为GBDKRGBDS兼容的游戏机瓷砖。瓷砖作为C unsigned char数组生成,用于GBDK瓷砖,以及ROM中的字面量字节数组,用于RGBDS瓷砖。

输入示例

ASCII PNG

您可以在您的游戏机程序中使用它

Emulator Example

安装

安装 cargorust

从cargo

cargo install gbtile

从源码

$ git clone [email protected]:blakesmith/gbtile.git
$ cd gbtile/
$ cargo install --path .

默认情况下,gbtile可执行文件将被安装在$HOME/.cargo/bin/

用法

游戏机瓷砖生成器 0.2.0 Blake Smith [email protected] 从PNG图像生成GBDK或RGBDS游戏机瓷砖

USAGE:
    gbtile [FLAGS] [OPTIONS] -i <input> -o <output>

FLAGS:
    -d               Enable debug logging
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -i <input>              The PNG image to generate tiles from. Example: 'image.png'
    -o <output>             The output file to generate. Usually something like 'tiles.h' for GBDK output, or
                            'tiles.asm' for RGBDS
    -t <output-type>        The output type. Either 'gbdk' or 'rgbds'. Defaults to 'gbdk'

找到一个符合以下图像标准的图像,或者在您喜欢的照片编辑器中创建自己的图像,然后按照以下方式转换

GBDK

$ gbtile -t gbdk -i ascii.png -o ascii.tile.h
2020-05-19 21:07:02,154 INFO  [gbtile] File: ascii.png, Tile rows: 14,
columns: 16, unique colors: 2

确保瓷砖数量和唯一颜色符合您的预期。输出将是一个有效的C数组,如下所示

unsigned char ascii[] = {
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x40,0x40,0x00,0x00,
    ...
    0x10,0x10,0x38,0x38,0x54,0x54,0x50,0x50,0x38,0x38,0x14,0x14,0x54,0x54,0x38,0x38,
};

变量名称应与输入文件名匹配。

现在您可以将瓷砖数组包含在您的GBDK游戏机项目中,并使用C函数set_bkg_dataset_sprite_data加载它。

RGBDS

$ gbtile -t rgbds -i ascii.png -o tiles.asm
2023-03-19 08:29:04,797 INFO  [gbtile] File: img/ascii.png, Tile rows: 14, columns: 16, unique colors: 2

瓷砖的标签名称将与文件名匹配,将被放置在ROM中,并导出以供其他.as文件引用。

您将获得一个类似于以下内容的输出文件

SECTION "Tiles for 'ascii'", ROM0

EXPORT ascii, ascii_end

ascii:
    db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,
    db $00,$00,$40,$40,$40,$40,$40,$40,$40,$40,$00,$00,$40,$40,$00,$00,
    db $00,$00,$6c,$6c,$24,$24,$48,$48,$00,$00,$00,$00,$00,$00,$00,$00,
    db $00,$00,$24,$24,$7e,$7e,$24,$24,$24,$24,$7e,$7e,$24,$24,$00,$00,
    ...
    db $00,$00,$28,$28,$00,$00,$44,$44,$44,$44,$28,$28,$10,$10,$60,$60
ascii_end:

You can assemble the file along with the rest of your project with something like:

rgbasm -L -o tiles.o tiles.asm


Once the tile data is assembled with the rest of you're project, you'll need to copy
the tiles into video memory correctly using some sort of `Memcopy` routine like so:

```asm
; Called at game startup
InitGame:
        ; Call routine to initialize tile data
        call InitTileData
        ; Jump to main game loop after initializing tile data
        jp Main

; Initialize the tile data. In this example, we've converted a tile image
; named 'ascii_tiles' from gbtile, so we should have two symbols exported
; for our project to use: 'ascii_files' and 'ascii_tiles_end', which should reference
; to the beginning and end address of the tile data in ROM.
InitTileData:
        ; Copy tile data from the exported tile named 'ascii_tiles'
        ld de, ascii_tiles
        ; Load the tiles into the start of video memory address
        ld hl, $9000
        ; The length of the copy is the difference between the start
        ; of the ascii_tiles symbol, and ascii_tiles_end symbol.
        ld bc, ascii_tiles_end - ascii_tiles
        call Memcopy
        ret

; Copy bytes from one area to another.
; @param de: Source
; @param hl: Destination
; @param bc: Length
Memcopy:
        ld a, [de]
        ld [hli], a
        inc de
        dec bc
        ld a, b
        or a, c
        jp nz, Memcopy
        ret

图像

在我的工作流程中,我使用以下图像设置

  1. 创建一个像素尺寸可被8整除的图像,且不超过256x256
  2. 使用4种不同的颜色。0xFFFFFF为白色,0x000000为黑色。深灰色,任何介于0xbfbfbf和0x7f7f7f之间的RGB值。浅灰色,任何介于0x7f7f7f和0x3f3f3f之间的RGB颜色。
  3. 图像将被切割成每个8x8像素的瓷砖。
  4. 我一直在使用RGB格式的PNG图像,但理论上其他格式也应适用。

许可证

MIT许可。

依赖项

~1.5MB
~21K SLoC