| Crates.io | retrolang-bin2c |
| lib.rs | retrolang-bin2c |
| version | 0.1.1 |
| created_at | 2025-12-09 00:50:03.783656+00 |
| updated_at | 2025-12-13 00:26:19.466285+00 |
| description | Convert Z80 binary ROMs to C arrays for Arduino sketches |
| homepage | |
| repository | https://github.com/ajokela/retrolang |
| max_upload_size | |
| id | 1974624 |
| size | 14,762 |
A command-line tool to convert binary ROM files into C header files for embedding in Arduino sketches and other embedded projects.
bin2c reads a binary file (such as a Z80 ROM image) and outputs a C header file containing the data as a constant array. This is useful for embedding compiled programs directly into Arduino firmware for the RetroShield platform.
cargo install --path .
Or build from source:
cargo build --release
# Basic usage - output to stdout
bin2c program.bin
# Write to a header file
bin2c program.bin -o program.h
# Specify custom array name
bin2c program.bin -o rom.h --name my_program
# Generate with PROGMEM attribute (for AVR Arduino)
bin2c program.bin -o rom.h --progmem
# Use uint8_t instead of unsigned char
bin2c program.bin -o rom.h --uint8
# Adjust bytes per line (default: 16)
bin2c program.bin -o rom.h --width 12
| Option | Short | Description |
|---|---|---|
--output |
-o |
Output file path (default: stdout) |
--name |
-n |
Array name (default: derived from filename) |
--width |
-w |
Bytes per line in output (default: 16) |
--progmem |
-p |
Add PROGMEM attribute for AVR Arduino |
--uint8 |
Use uint8_t instead of unsigned char |
Given a binary file hello.bin, running:
bin2c hello.bin -o hello.h --progmem
Produces:
#ifndef HELLO_H
#define HELLO_H
#include <avr/pgmspace.h>
#define HELLO_SIZE 256
const unsigned char hello[256] PROGMEM = {
0x3E, 0x48, 0xD3, 0x81, 0x3E, 0x65, 0xD3, 0x81, 0x3E, 0x6C, 0xD3, 0x81, 0x3E, 0x6C, 0xD3, 0x81,
0x3E, 0x6F, 0xD3, 0x81, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// ... remaining bytes
};
#endif // HELLO_H
This tool is designed to work with the RetroShield Z80 platform. A typical workflow:
# Compile a RetroLang program
retrolang program.rl --binary -o program.bin
# Convert to Arduino header
bin2c program.bin -o program.h --progmem
# Include in Arduino sketch and upload
BSD-3-Clause