Created
September 3, 2021 21:57
-
-
Save mori0091/0f6aa629cc272b93d5c7b6e864836f24 to your computer and use it in GitHub Desktop.
Bash script to make BLOAD format .bin file of MSX from a binary file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# -*- coding: utf-8-unix -*- | |
# Usage: msxbin.sh FILE BASE RUN | |
# Outputs BSAVE header followed by contents of the given FILE to stdout. | |
# | |
# - FILE :: input file name of the memory image | |
# - BASE :: base address where the memory image would to be loaded | |
# - RUN :: entry point address of the memory image that shall be run by "BLOAD ..., R" command | |
size=$(stat -c '%s' $1) | |
beg=$(($2)) | |
end=$((beg + size - 1)) | |
run=$(($3)) | |
printf '\xfe' | |
printf $(printf '\\x%02x\\x%02x' $((beg % 256)) $((beg / 256))) | |
printf $(printf '\\x%02x\\x%02x' $((end % 256)) $((end / 256))) | |
printf $(printf '\\x%02x\\x%02x' $((run % 256)) $((run / 256))) | |
cat $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To make
foo.bin
from a binary filefoo.dat
on Ubuntu and so on:msxbin.sh foo.dat 0x8000 0x9000 > foo.bin
Then, on MSX,
BLOAD "foo.bin",R
loads the file contents at address 0x8000 and runs from 0x9000.