Skip to content

Instantly share code, notes, and snippets.

@mori0091
Created September 3, 2021 21:57
Show Gist options
  • Save mori0091/0f6aa629cc272b93d5c7b6e864836f24 to your computer and use it in GitHub Desktop.
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
#!/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
@mori0091
Copy link
Author

mori0091 commented Sep 3, 2021

To make foo.bin from a binary file foo.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment