diff --git a/tools/Makefile b/tools/Makefile new file mode 100644 index 00000000..7b1ae43a --- /dev/null +++ b/tools/Makefile @@ -0,0 +1,13 @@ + +%-pf.hex: %-pf.pbm p4_to_pfbytes.py + python p4_to_pfbytes.py $< > $@ + +%-48.hex: %-48.pbm p4_to_48pix.py + python p4_to_48pix.py $< > $@ + +%-pf.pbm: %.jpg + convert $< -resize 40x192\! -colorspace Gray -dither FloydSteinberg $@ + +%-48.pbm: %.jpg + convert $< -resize 48x192\! -colorspace Gray -dither FloydSteinberg $@ + diff --git a/tools/README b/tools/README new file mode 100644 index 00000000..299fb117 --- /dev/null +++ b/tools/README @@ -0,0 +1,17 @@ + +This directory contains tools for bitmap conversion. + +Requires ImageMagick (convert) and Python 2.x. + +make .pf.hex + + Converts a .jpg into a 40-pixel wide playfield bitmap. + Cut-and-paste output into program. + (See Chapter 20, Asynchronous Bitmaps) + +make .48.hex + + Converts a .jpg into a 48-pixel wide sprite bitmap. + Cut-and-paste output into program. + (See Chapter 22, A Big 48-Pixel Sprite) + diff --git a/tools/galois.c b/tools/galois.c new file mode 100644 index 00000000..7d2dc288 --- /dev/null +++ b/tools/galois.c @@ -0,0 +1,23 @@ + +/* test of 16-bit Galois LFSR */ + +#include "stdio.h" + +int main() +{ + int n = 100; + unsigned short x = 1; + for (int i=0; i>= 1; + if (c) x ^= 0xd400; // 0b1101010000000000 + printf("%4x\n", x); + } + for (int i=0; i> lb) & ((1<<(hb-lb))-1) + if reverse: + x = rev(x) + if shift: + x = x << shift + assert(x>=0 and x<=255) + output[i].append(x) + +# read PBM (binary P4 format) file +with open(sys.argv[1],'rb') as f: + # read PBM header + header = f.readline().strip() + assert(header == 'P4') + dims = f.readline().strip() + if dims[0] == '#': + dims = f.readline().strip() + width,height = map(int, dims.split()) + assert(width==48) + # read bitmap rows + for y in range(0,height): + row = bytes(f.read(6) + '\0\0') # pad to 8 bytes + # convert to 64-bit integer + pix = struct.unpack('5: + print s diff --git a/tools/p4_to_pfbytes.py b/tools/p4_to_pfbytes.py new file mode 100644 index 00000000..21ad2241 --- /dev/null +++ b/tools/p4_to_pfbytes.py @@ -0,0 +1,62 @@ +#!/usr/bin/python + +import sys, struct + +# playfield bytes, one array for each of 6 columns +output = [[],[],[],[],[],[]] + +# reverse byte +def rev(n): + return int('{:08b}'.format(n)[::-1], 2) + +# output bits in given range +def out(i, pix, lb, hb, reverse=0, shift=0): + x = (pix >> lb) & ((1<<(hb-lb))-1) + if reverse: + x = rev(x) + if shift: + x = x << shift + assert(x>=0 and x<=255) + output[i].append(x) + +# read PBM (binary P4 format) file +with open(sys.argv[1],'rb') as f: + # read PBM header + header = f.readline().strip() + assert(header == 'P4') + dims = f.readline().strip() + if dims[0] == '#': + dims = f.readline().strip() + width,height = map(int, dims.split()) + assert(width==40) + # read bitmap rows + for y in range(0,height): + row = bytes(f.read(5) + '\0\0\0') # pad to 8 bytes + # convert bytes from MSB first to LSB first + row2 = '' + for i in range(0,8): + row2 += chr(rev(ord(row[i]))) + # convert to 64-bit integer + pix = struct.unpack('5: + print s