1
0
mirror of https://github.com/UzixLS/pacemuzx.git synced 2025-07-18 23:01:36 +03:00

Converted Perl build helpers to Python

png2bin.pl is replaced by tile2sam.py (external)
remove_rom.pl is replaced by remove_rom.py
This commit is contained in:
Simon Owen
2018-01-17 20:17:58 +00:00
parent ec4006bbef
commit a067f335b5
5 changed files with 48 additions and 135 deletions

View File

@ -7,11 +7,11 @@ UNAME := $(shell uname -s)
$(NAME).tap: loader.tap $(NAME).o $(NAME).tap: loader.tap $(NAME).o
cat loader.tap $(NAME).o > $@ cat loader.tap $(NAME).o > $@
tiles.bin: tiles.png
./png2bin.pl $< 6
sprites.bin: sprites.png sprites.bin: sprites.png
./png2bin.pl $< 12 tile2sam.py -q --mode 1 --tiles 76 sprites.png 12x12
tiles.bin: tiles.png
tile2sam.py -q --mode 1 tiles.png 6x6
$(NAME).o: $(NAME).asm tiles.bin sprites.bin $(ROMS) $(NAME).o: $(NAME).asm tiles.bin sprites.bin $(ROMS)
pasmo --tap $(NAME).asm $(NAME).o $(NAME).sym pasmo --tap $(NAME).asm $(NAME).o $(NAME).sym
@ -24,13 +24,11 @@ else
endif endif
dist: $(NAME).tap dist: $(NAME).tap
rm -rf dist mkdir -p dist
mkdir dist
cp ReadMe.txt dist/ cp ReadMe.txt dist/
cp Makefile-dist dist/Makefile cp Makefile-dist dist/Makefile
cp make.bat-dist dist/make.bat cp make.bat-dist dist/make.bat
./remove_rom.pl $(NAME).tap ./remove_rom.py $(NAME).tap pacman.6e 16384 dist/start.part dist/end.part
mv start.part end.part dist/
clean: clean:
rm -f $(NAME).tap $(NAME).sym $(NAME).o rm -f $(NAME).tap $(NAME).sym $(NAME).o

View File

@ -4,32 +4,32 @@ set NAME=pacemuzx
if "%1"=="clean" goto clean if "%1"=="clean" goto clean
png2bin.pl tiles.png 6 tile2sam.py -q --mode 1 --tiles 76 sprites.png 12x12
png2bin.pl sprites.png 12 tile2sam.py -q --mode 1 tiles.png 6x6
pasmo --tap %NAME%.asm %NAME%.o %NAME%.sym pasmo --tap %NAME%.asm %NAME%.o %NAME%.sym
if errorlevel 1 goto end if errorlevel 1 goto end
copy /b loader.tap+%NAME%.o %NAME%.tap copy /b loader.tap+%NAME%.o %NAME%.tap
if "%1"=="dist" goto dist
if "%1"=="run" start %NAME%.tap if "%1"=="run" start %NAME%.tap
goto end
if not "%1"=="dist" goto end :dist
if not exist dist mkdir dist if not exist dist mkdir dist
copy ReadMe.txt dist\ copy ReadMe.txt dist\
copy Makefile-dist dist\Makefile copy Makefile-dist dist\Makefile
copy make.bat-dist dist\make.bat copy make.bat-dist dist\make.bat
remove_rom.pl remove_rom.py %NAME%.tap pacman.6e 16384 dist\start.part dist\end.part
move start.part dist\
move end.part dist\
goto end goto end
:clean :clean
if exist %NAME%.tap del %NAME%.tap %NAME%.sym %NAME%.o del /q %NAME%.tap %NAME%.sym %NAME%.o 2>nul
if exist tiles.bin del tiles.bin sprites.bin del /q tiles.bin sprites.bin 2>nul
if exist dist\ del dist\ReadMe.txt dist\Makefile dist\make.bat dist\start.part dist\end.part del /q dist\ReadMe.txt dist\Makefile dist\make.bat dist\start.part dist\end.part 2>nul
if exist dist\%NAME%.tap del dist\%NAME%.tap del /q dist\%NAME%.tap 2>nul
if exist dist\ rmdir dist rmdir dist 2>nul
:end :end
endlocal endlocal

View File

@ -1,89 +0,0 @@
#!/usr/bin/perl -w
#
# Convert PNG image to Spectrum format sprite image data
#
# Input image should be palettised 1-bit with no transparency
#
# Simon Owen <simon@simonowen.com>
use Compress::Zlib;
use Getopt::Std;
# Allow -v option for verbose output
getopts('v');
# Strip path from input filename, and check
$0 =~ s/.*\///;
die "Usage: $0 <image> <sprite-width> [<sprite-height>]\n" unless @ARGV == 2 or @ARGV == 3;
# Input image and output data file
($file,$w,$h) = (@ARGV,$ARGV[1]); # height defaults to width if not provided
die "Input image must be in PNG format\n" unless $file =~ /.png$/i;
die "Sprite width should be 2-16 pixels\n" unless $w >= 2 && $w <= 16;
die "Sprite height should be at least 1 pixel\n" unless $h > 0;
# Slurp the entire PNG image
open INPUT, "<$file" and binmode INPUT or die "$file: $!\n";
read INPUT, $data='', -s $file;
close INPUT;
# Extract and check the image dimensions
$data =~ /IHDR(.{8})/s;
($iw,$ih) = unpack "N2", $1;
die "Input image (${iw}x${ih}) must be an exact multiple of sprite size (${w}x${h})\n" if ($iw%$w) or ($ih%$h);
# Extract and expand the compressed image data
($data) = $data =~ /IDAT(.*).{8}IEND/s;
$data = Compress::Zlib::uncompress($data);
# Remove the type byte from the start of each line, leaving just 0+1 pixel values
if (length($data) == (($iw+1)*$ih)) { # 8bpp?
$data =~ s/.(.{$iw})/$1/sg;
@data = map { $_&1 } unpack("C*", $data);
} elsif (length($data) == (($iw/2+1)*$ih)) { # 4bpp?
my $iw_2 = $iw/2;
$data =~ s/.(.{$iw_2})/$1/sg;
foreach (unpack("C*", $data)) {
push @data, ($_>>4)&1, $_&1;
}
} else {
die "Image data format is unsupported (size = ".@data." bytes)\n";
}
# Calculate rows+columns and the expected size of the output data
($c,$r) = ($iw/$w,$ih/$h);
$size = int(($w+7)/8)*$h*$r*$c;
print "Input image ($file) = ${iw}x${ih}, sprite = ${w}x${h}\n" if $opt_v;
foreach $y (0..$r-1)
{
foreach $x (0..$c-1)
{
foreach $l (0..$h-1) # line
{
# Calculate the offset of the required bit sequence
my $o = ((($y*$h+$l)*$c) + $x) * $w;
# Convert the individual bits to a binary string then a decimal value
my $n = unpack("N", pack("B32", substr("0"x32 . join('', @data[$o..$o+$w-1]), -32)));
# Pack into 1 or 2 bytes, with the bits left-aligned (MSB)
$output .= pack(($w<=8)?"C":"n", $n << (8-($w & 7)));
}
}
}
# Sanity check the output data size
die "Output data ", length($output), " is the wrong size! (should be $size)\n" unless length($output) == $size;
# The output file is the input filename with a .bin extension instead of .png
$file =~ s/png$/bin/i;
open OUTPUT, ">$file" and binmode OUTPUT or die "$file: $!\n";
# Determine the size of a single sprite, and strip blank sprites from the end of the data
$ss = length($output) / ($r*$c);
$output =~ s/(\0{$ss})*$//;
print "Output data ($file) = ", length($output), " bytes = ", length($output)/$ss, " sprites\n" if $opt_v;
print OUTPUT $output;
close OUTPUT;

View File

@ -1,26 +0,0 @@
#!/usr/bin/perl -w
# First 4K of Pac-Man ROM
$file = 'pacman.6e';
open FILE, "<$file" and binmode FILE or die "$file: $!\n";
read FILE, $rom='', -s $file;
close FILE;
# Full TAP image for emulator, including ROM
$file = 'pacemuzx.tap';
open FILE, "<$file" and binmode FILE or die "$file: $!\n";
read FILE, $data='', -s $file;
close FILE;
$index = index($data, $rom);
die "ROM image not found in TAP file!\n" if $index < 0;
$file = 'start.part';
open FILE, ">$file" and binmode FILE or die "$file: $!\n";
print FILE substr $data, 0, $index;
close FILE;
$file = 'end.part';
open FILE, ">$file" and binmode FILE or die "$file: $!\n";
print FILE substr $data, $index+16384;
close FILE;

30
remove_rom.py Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env python
import sys
import argparse
parser = argparse.ArgumentParser("Remove ROM placeholder from pacemu master disk image")
parser.add_argument("tapfile", help="input TAP file containing ROM")
parser.add_argument("romfile", help="start of ROM image to remove")
parser.add_argument("romsize", type=int, help="size of ROM to remove")
parser.add_argument("startfile", help="output file for start segment")
parser.add_argument("endfile", help="output file for end segment")
args = parser.parse_args()
with open(args.tapfile, 'rb') as tapfile:
tap = tapfile.read()
with open(args.romfile, 'rb') as romfile:
rom = romfile.read()
rom_offset = tap.find(rom)
if rom_offset == -1:
sys.exit("error: ROM image not found in TAP file!")
start_part = tap[:rom_offset]
end_part = tap[rom_offset + args.romsize:]
with open(args.startfile, 'wb') as startfile:
startfile.write(start_part)
with open(args.endfile, 'wb') as endfile:
endfile.write(end_part)