All Projects → exelotl → trick

exelotl / trick

Licence: Zlib license
Library for GBA/NDS image conversion, and more!

Programming Languages

nim
578 projects
shell
77523 projects

Projects that are alternatives of or similar to trick

Mgba
mGBA Game Boy Advance Emulator
Stars: ✭ 3,355 (+14486.96%)
Mutual labels:  gba, gameboy-advance
smaghetti
A web based level editor for Super Mario Advance 4, the GBA port of Super Mario Bros 3
Stars: ✭ 31 (+34.78%)
Mutual labels:  gba, gameboy-advance
gba-pong
Classic pong game on the GameBoy Advance.
Stars: ✭ 23 (+0%)
Mutual labels:  gba, gameboy-advance
gba-sprite-engine
An object-oriented Game Boy Advance sprite engine concept
Stars: ✭ 68 (+195.65%)
Mutual labels:  gba, gameboy-advance
magia
magia is a toy GBA emulator written in golang.
Stars: ✭ 432 (+1778.26%)
Mutual labels:  gba, gameboy-advance
awesome-emu-resources
A curated list of emulator development resources
Stars: ✭ 26 (+13.04%)
Mutual labels:  gba, gameboy-advance
Hades
🔥 A Nintendo Game Boy Advance emulator
Stars: ✭ 44 (+91.3%)
Mutual labels:  gba, gameboy-advance
OptimeGBA
Optime GBA - Nintendo Game Boy Advance (and WIP Nintendo DS) emulator, written in C# with .NET Core.
Stars: ✭ 87 (+278.26%)
Mutual labels:  gba
PokemonRNGGuides
A repository of Pokemon RNG abuse guides
Stars: ✭ 62 (+169.57%)
Mutual labels:  gba
luvdis
Pure-Python Game Boy Advance Disassembler
Stars: ✭ 27 (+17.39%)
Mutual labels:  gba
gba-modern
An attempt to create a Game Boy Advance game using Modern C++
Stars: ✭ 59 (+156.52%)
Mutual labels:  gba
GBASnake
Snake Game for Gameboy Advance
Stars: ✭ 58 (+152.17%)
Mutual labels:  gameboy-advance
minishmaker
Level editing suite for The Legend of Zelda: The Minish Cap
Stars: ✭ 58 (+152.17%)
Mutual labels:  gba
piugba
🎮 PIU emulator for the GBA 🎮
Stars: ✭ 43 (+86.96%)
Mutual labels:  gba
UnkrawerterGBA
A tool to rip music from Gameboy Advance games that use the Krawall sound engine.
Stars: ✭ 26 (+13.04%)
Mutual labels:  gameboy-advance
Herebedragons
A basic 3D scene implemented with various engines, frameworks or APIs.
Stars: ✭ 1,616 (+6926.09%)
Mutual labels:  gba
HeartLib
Comprehensive API for Nintendo GBA inspired by HAMLib and HELlib.
Stars: ✭ 23 (+0%)
Mutual labels:  gba
AdvanceOS
Tiny Operating System to emulate GBA on Raspberry Pi
Stars: ✭ 46 (+100%)
Mutual labels:  gba
gba-remote-play
Stream Raspberry Pi games to a GBA via Link Cable
Stars: ✭ 356 (+1447.83%)
Mutual labels:  gba
react-gbajs
🕹 GBA emulator on your React project - easy and powerful to use!
Stars: ✭ 35 (+52.17%)
Mutual labels:  gameboy-advance

Trick ;)

Trick is a library for GBA and NDS asset conversion in Nim.

It is used by the Natu project tool, providing an easy way to put images & maps into your GBA games.

It was also used for the PP20th translation project, thus is able to convert binary data back to PNG in some cases.

Features

  • Sprite Graphics
    • Convert PNG images to raw GBA image data, and vice-versa
    • Supported formats: 2 / 4 / 8 bpp paletted images using 15-bit BGR color, with bitmap or tile arrangement
  • Backgrounds / Tilemaps
    • Convert PNG images to a map + tileset + palette.
    • Tileset reduction: identify & remove duplicate tiles, including flipped versions
    • Rearrange maps into screenblocks
  • Palette Reduction
    • Given a list of palettes, attempt to merge them into the least number of 16-color palettes necessary. This doesn't produce optimal results, but may be good enough for some projects.
  • Data Utils
    • Facilities to reinterpret data as an array of some known type, without copying
    • Convert raw bytes to C strings (a utility borrowed from the Nim compiler)
    • Name helpers: filename to identifier, snake_case to camelCase

Overview

Trick is intended to allow you to make your own command-line tools to wrangle assets for your homebrew projects.

Installation

$ nimble install trick

Examples

These examples use hardcoded settings and paths, but in practise you'll want to be looping over directories, reading from config files, etc.

PNG to binary

Convert your sprite sheets into raw binary formats used by GBA/NDS games:

import trick

var conf = GfxInfo(
  pal: @[clrEmpty],   # initial palette
  bpp: gfx4bpp,       # bit depth
  layout: gfxTiles,   # arrange into 8x8 tiles
)

# do the conversion
# `data` is now a string containing raw pixel data
# `conf.pal` will be populated with all the colors in the image
let data = pngToBin("mario.png", conf, buildPal=true)

# output to files
writeFile("mario.img.bin", data)
writePal("mario.pal.bin", conf.pal)

Binary to PNG

The inverse of the above process. This may be useful for rom hacking, validation etc.

let conf = GfxInfo(
  pal: readPal("mario.pal.bin"),
  bpp: gfx4bpp,       # bit depth
  layout: gfxTiles,   # unscramble from tile arrangement
)
let data = readFile("mario.img.bin")
let png = binToPng(data, conf)
writeFile("mario_out.png", png)

PNG to tileset + tilemap + palettes

The typical use case here is to take an image of your whole level and transform it into a tile map. Under the hood this involves both tileset reduction and palette reduction.

let bg4 = loadBg4("brinstar.png")
writeFile("brinstar.map.bin", toBytes(bg4.map))
writeFile("brinstar.img.bin", toBytes(bg4.img))
writeFile("brinstar.pal.bin", toBytes(joinPalettes(bg4.pals)))

Data to C

While the above examples use .bin files, the preferred way to embed read-only data in your Nim GBA games is by using extenal C files.

Example:

let data = readFile("mario.img.bin")

# convert binary data to a C string literal
let imgStringLit = makeCString(data)

# output C source code
writeFile("source/gfxdata.c", fmt"""
const char *marioImg = {imgStringLit};
""")

# output Nim source code
writeFile("source/gfxdata.nim", fmt"""
{{.compile: "gfxdata.c".}}
var marioImg* {{.importc, extern:"marioImg", codegenDecl:"extern const $# $#".}}: array[{data.len}, uint8]
""")

To explain the generated Nim code: the {.compile.} pragma ensures that gfxdata.c is compiled and linked into the final ROM. The {.importc.} and {.extern.} pragmas are used to make the C variable accessible to Nim. {.codegenDecl.} is just to help avoid compiler warnings.

It's worth mentioning that this Nim code could be written by hand, but I recommend this approach to maintain integrity between the assets and the game code. It will also save a lot of work once you modify your tool to support multiple images, by using a config file or by processing all images in a certain folder, etc.

Example of using data in your game code:

import natu, gfxdata

# copy the image data into VRAM
memcpy32(addr tileMemObj[0], addr marioImg, marioImg.len div sizeof(uint32))

Todo

  • Fonts (currently the only way to produce TTE compatible fonts is Usenti)

  • ASM output?

  • Ability to convert backgrounds/tilemaps back into PNG

  • Affine backgrounds

  • More graphic formats (in particular, NDS 3D texture formats with alpha bits have been implemented by MyLegGuy for PP20th, but I've yet to merge this code)

  • Metatiles? Currently, sprite sheets must be supplied as a vertical strip (i.e. 1 frame wide, N frames tall). This is maybe unconventional, but an advantage is you can guarantee no space in the spritesheet is wasted.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].