From a067f335b5263bb2baf2673997b2f2d49d697a68 Mon Sep 17 00:00:00 2001 From: Simon Owen Date: Wed, 17 Jan 2018 20:17:58 +0000 Subject: [PATCH] Converted Perl build helpers to Python png2bin.pl is replaced by tile2sam.py (external) remove_rom.pl is replaced by remove_rom.py --- Makefile | 14 ++++---- make.bat | 24 +++++++------- png2bin.pl | 89 --------------------------------------------------- remove_rom.pl | 26 --------------- remove_rom.py | 30 +++++++++++++++++ 5 files changed, 48 insertions(+), 135 deletions(-) delete mode 100755 png2bin.pl delete mode 100755 remove_rom.pl create mode 100755 remove_rom.py diff --git a/Makefile b/Makefile index 74270de..7b2ab12 100644 --- a/Makefile +++ b/Makefile @@ -7,11 +7,11 @@ UNAME := $(shell uname -s) $(NAME).tap: loader.tap $(NAME).o cat loader.tap $(NAME).o > $@ -tiles.bin: tiles.png - ./png2bin.pl $< 6 - 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) pasmo --tap $(NAME).asm $(NAME).o $(NAME).sym @@ -24,13 +24,11 @@ else endif dist: $(NAME).tap - rm -rf dist - mkdir dist + mkdir -p dist cp ReadMe.txt dist/ cp Makefile-dist dist/Makefile cp make.bat-dist dist/make.bat - ./remove_rom.pl $(NAME).tap - mv start.part end.part dist/ + ./remove_rom.py $(NAME).tap pacman.6e 16384 dist/start.part dist/end.part clean: rm -f $(NAME).tap $(NAME).sym $(NAME).o diff --git a/make.bat b/make.bat index fc4cc62..d5884e3 100644 --- a/make.bat +++ b/make.bat @@ -4,32 +4,32 @@ set NAME=pacemuzx if "%1"=="clean" goto clean -png2bin.pl tiles.png 6 -png2bin.pl sprites.png 12 +tile2sam.py -q --mode 1 --tiles 76 sprites.png 12x12 +tile2sam.py -q --mode 1 tiles.png 6x6 pasmo --tap %NAME%.asm %NAME%.o %NAME%.sym if errorlevel 1 goto end copy /b loader.tap+%NAME%.o %NAME%.tap + +if "%1"=="dist" goto dist if "%1"=="run" start %NAME%.tap +goto end -if not "%1"=="dist" goto end - +:dist if not exist dist mkdir dist copy ReadMe.txt dist\ copy Makefile-dist dist\Makefile copy make.bat-dist dist\make.bat -remove_rom.pl -move start.part dist\ -move end.part dist\ +remove_rom.py %NAME%.tap pacman.6e 16384 dist\start.part dist\end.part goto end :clean -if exist %NAME%.tap del %NAME%.tap %NAME%.sym %NAME%.o -if exist tiles.bin del tiles.bin sprites.bin -if exist dist\ del dist\ReadMe.txt dist\Makefile dist\make.bat dist\start.part dist\end.part -if exist dist\%NAME%.tap del dist\%NAME%.tap -if exist dist\ rmdir dist +del /q %NAME%.tap %NAME%.sym %NAME%.o 2>nul +del /q tiles.bin sprites.bin 2>nul +del /q dist\ReadMe.txt dist\Makefile dist\make.bat dist\start.part dist\end.part 2>nul +del /q dist\%NAME%.tap 2>nul +rmdir dist 2>nul :end endlocal diff --git a/png2bin.pl b/png2bin.pl deleted file mode 100755 index 4cb5a35..0000000 --- a/png2bin.pl +++ /dev/null @@ -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 - -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 []\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; diff --git a/remove_rom.pl b/remove_rom.pl deleted file mode 100755 index 71cb24f..0000000 --- a/remove_rom.pl +++ /dev/null @@ -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; diff --git a/remove_rom.py b/remove_rom.py new file mode 100755 index 0000000..74c4a9d --- /dev/null +++ b/remove_rom.py @@ -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)