git @ Cat's Eye Technologies The-Dipple / master perl / spr2stx
master

Tree @master (Download .tar.gz)

spr2stx @masterraw · history · blame

#!/usr/bin/perl

# Reads in a C64 binary PRG containing sprites and outputs text file for them.

# SPDX-FileCopyrightText: Chris Pressey, the original author of this work, has dedicated it to the public domain.
# For more information, please refer to <https://unlicense.org/>
# SPDX-License-Identifier: Unlicense

open FILE, "<$ARGV[0]";
binmode FILE;

my $len, $buffer;

read FILE, $len, 2;   # skip header: load address

read FILE, $buffer, 64;
while (1)
{
    my $offset = 0;
    for ($i = 0; $i < 21; $i++)
    {
        for $delta (0, 1, 2) {
            print_byte(substr($buffer, $offset+ $delta, 1));
        }
        print "\n";
        $offset += 3;
    }
    print "\n";   # padding
    read FILE, $buffer, 64;
    last if length($buffer) < 64;
}

sub print_byte
{
    my $byte = ord(shift);
    for $bit (128, 64, 32, 16, 8, 4, 2, 1) {
        print $byte & $bit ? "X" : ".";
    }
}

close FILE;