mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-11-21 23:30:58 +00:00
added bitmap tools
This commit is contained in:
parent
8be8c11ae5
commit
91d8136ad3
13
tools/Makefile
Normal file
13
tools/Makefile
Normal file
@ -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 $@
|
||||
|
17
tools/README
Normal file
17
tools/README
Normal file
@ -0,0 +1,17 @@
|
||||
|
||||
This directory contains tools for bitmap conversion.
|
||||
|
||||
Requires ImageMagick (convert) and Python 2.x.
|
||||
|
||||
make <filename>.pf.hex
|
||||
|
||||
Converts a .jpg into a 40-pixel wide playfield bitmap.
|
||||
Cut-and-paste output into program.
|
||||
(See Chapter 20, Asynchronous Bitmaps)
|
||||
|
||||
make <filename>.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)
|
||||
|
23
tools/galois.c
Normal file
23
tools/galois.c
Normal file
@ -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<n; i++) {
|
||||
int c = x&1;
|
||||
x >>= 1;
|
||||
if (c) x ^= 0xd400; // 0b1101010000000000
|
||||
printf("%4x\n", x);
|
||||
}
|
||||
for (int i=0; i<n; i++) {
|
||||
int c = x&0x8000;
|
||||
x <<= 1;
|
||||
if (c) x ^= 0xa801;
|
||||
printf("%4x\n", x);
|
||||
}
|
||||
return 0;
|
||||
}
|
BIN
tools/images/ada-40.pbm
Normal file
BIN
tools/images/ada-40.pbm
Normal file
Binary file not shown.
BIN
tools/images/ali-40.pbm
Normal file
BIN
tools/images/ali-40.pbm
Normal file
Binary file not shown.
BIN
tools/images/ein-48.pbm
Normal file
BIN
tools/images/ein-48.pbm
Normal file
Binary file not shown.
BIN
tools/images/scrappy-48.pbm
Normal file
BIN
tools/images/scrappy-48.pbm
Normal file
Binary file not shown.
BIN
tools/images/thisisfine-48.pbm
Normal file
BIN
tools/images/thisisfine-48.pbm
Normal file
Binary file not shown.
58
tools/p4_to_48pix.py
Normal file
58
tools/p4_to_48pix.py
Normal file
@ -0,0 +1,58 @@
|
||||
#!/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==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('<q',row)[0]
|
||||
#print '%010lx' % pix
|
||||
# generate playfield bytes
|
||||
out(0, pix, 0, 8, 0)
|
||||
out(1, pix, 8, 16, 0)
|
||||
out(2, pix, 16, 24, 0)
|
||||
out(3, pix, 24, 32, 0)
|
||||
out(4, pix, 32, 40, 0)
|
||||
out(5, pix, 40, 48, 0)
|
||||
|
||||
# output bitmap tables
|
||||
for c in range(0,6):
|
||||
print "\talign $100"
|
||||
print "Bitmap%d" % c
|
||||
print "\thex 00"
|
||||
s = '\thex '
|
||||
for i in range(0,height):
|
||||
s += '%02x' % output[c][height-i-1]
|
||||
if i % 16 == 15:
|
||||
print s
|
||||
s = '\thex '
|
||||
if len(s)>5:
|
||||
print s
|
62
tools/p4_to_pfbytes.py
Normal file
62
tools/p4_to_pfbytes.py
Normal file
@ -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('<q',row2)[0]
|
||||
#print '%010lx' % pix
|
||||
# generate playfield bytes
|
||||
out(0, pix, 0, 4, 0, 4)
|
||||
out(1, pix, 4, 12, 1)
|
||||
out(2, pix, 12, 20, 0)
|
||||
out(3, pix, 20, 24, 0, 4)
|
||||
out(4, pix, 24, 32, 1)
|
||||
out(5, pix, 32, 40, 0)
|
||||
|
||||
# output bitmap tables
|
||||
for c in range(0,6):
|
||||
print "\talign $100"
|
||||
print "PFBitmap%d" % c
|
||||
print "\thex 00"
|
||||
s = '\thex '
|
||||
for i in range(0,height):
|
||||
s += '%02x' % output[c][height-i-1]
|
||||
if i % 16 == 15:
|
||||
print s
|
||||
s = '\thex '
|
||||
if len(s)>5:
|
||||
print s
|
Loading…
Reference in New Issue
Block a user