mirror of
https://github.com/robmcmullen/asmgen.git
synced 2025-01-20 15:30:17 +00:00
Added mask and changed filler bit to match mask or sprite
This commit is contained in:
parent
bb06a8bf65
commit
a5d08f4284
40
HiSprite.py
40
HiSprite.py
@ -167,7 +167,7 @@ class Listing(object):
|
|||||||
|
|
||||||
|
|
||||||
class Sprite(Listing):
|
class Sprite(Listing):
|
||||||
def __init__(self, pngfile, assembler, screen, xdraw=False, processor="any", name=""):
|
def __init__(self, pngfile, assembler, screen, xdraw=False, use_mask=False, processor="any", name=""):
|
||||||
Listing.__init__(self, assembler)
|
Listing.__init__(self, assembler)
|
||||||
self.screen = screen
|
self.screen = screen
|
||||||
|
|
||||||
@ -175,6 +175,7 @@ class Sprite(Listing):
|
|||||||
pngdata = reader.asRGB8()
|
pngdata = reader.asRGB8()
|
||||||
|
|
||||||
self.xdraw = xdraw
|
self.xdraw = xdraw
|
||||||
|
self.use_mask = use_mask
|
||||||
self.processor = processor
|
self.processor = processor
|
||||||
if not name:
|
if not name:
|
||||||
name = os.path.splitext(pngfile)[0]
|
name = os.path.splitext(pngfile)[0]
|
||||||
@ -317,7 +318,7 @@ class Sprite(Listing):
|
|||||||
for chunkIndex in range(len(byteSplits)):
|
for chunkIndex in range(len(byteSplits)):
|
||||||
|
|
||||||
# Optimization
|
# Optimization
|
||||||
if maskSplits[chunkIndex] == "00000000":
|
if maskSplits[chunkIndex] == "01111111":
|
||||||
optimizationCount += 1
|
optimizationCount += 1
|
||||||
else:
|
else:
|
||||||
value = self.binary_constant(byteSplits[chunkIndex])
|
value = self.binary_constant(byteSplits[chunkIndex])
|
||||||
@ -329,6 +330,14 @@ class Sprite(Listing):
|
|||||||
"\teor %s\n" % value + \
|
"\teor %s\n" % value + \
|
||||||
"\tsta (SCRATCH0),y\n";
|
"\tsta (SCRATCH0),y\n";
|
||||||
cycleCount += 5 + 2 + 6
|
cycleCount += 5 + 2 + 6
|
||||||
|
elif self.use_mask:
|
||||||
|
mask = self.binary_constant(maskSplits[chunkIndex])
|
||||||
|
spriteChunks[chunkIndex][row] = \
|
||||||
|
"\tlda (SCRATCH0),y\n" + \
|
||||||
|
"\tand %s\n" % mask + \
|
||||||
|
"\tora %s\n" % value + \
|
||||||
|
"\tsta (SCRATCH0),y\n";
|
||||||
|
cycleCount += 5 + 2 + 6
|
||||||
else:
|
else:
|
||||||
spriteChunks[chunkIndex][row] = \
|
spriteChunks[chunkIndex][row] = \
|
||||||
"\tlda %s\n" % value + \
|
"\tlda %s\n" % value + \
|
||||||
@ -361,15 +370,7 @@ class Sprite(Listing):
|
|||||||
"\ttay\n", 4 + 3 + 4 + 3 + 3 + 4 + 2;
|
"\ttay\n", 4 + 3 + 4 + 3 + 3 + 4 + 2;
|
||||||
|
|
||||||
|
|
||||||
def fillOutByte(numBits):
|
def shiftStringRight(string, shift, bitsPerPixel, fillerBit):
|
||||||
filler = ""
|
|
||||||
for bit in range(numBits):
|
|
||||||
filler += "0"
|
|
||||||
|
|
||||||
return filler
|
|
||||||
|
|
||||||
|
|
||||||
def shiftStringRight(string, shift, bitsPerPixel):
|
|
||||||
if shift==0:
|
if shift==0:
|
||||||
return string
|
return string
|
||||||
|
|
||||||
@ -377,7 +378,7 @@ def shiftStringRight(string, shift, bitsPerPixel):
|
|||||||
result = ""
|
result = ""
|
||||||
|
|
||||||
for i in range(shift):
|
for i in range(shift):
|
||||||
result += "0"
|
result += fillerBit
|
||||||
|
|
||||||
result += string
|
result += string
|
||||||
return result
|
return result
|
||||||
@ -442,9 +443,9 @@ class HGR(ScreenFormat):
|
|||||||
|
|
||||||
def bitsForMask(self, pixel):
|
def bitsForMask(self, pixel):
|
||||||
if pixel == self.key:
|
if pixel == self.key:
|
||||||
return "00"
|
return "11"
|
||||||
|
|
||||||
return "11"
|
return "00"
|
||||||
|
|
||||||
def highBitForColor(self, pixel):
|
def highBitForColor(self, pixel):
|
||||||
# Note that we prefer high-bit white because blue fringe is less noticeable than magenta.
|
# Note that we prefer high-bit white because blue fringe is less noticeable than magenta.
|
||||||
@ -493,9 +494,11 @@ class HGR(ScreenFormat):
|
|||||||
if mask:
|
if mask:
|
||||||
bitDelegate = self.bitsForMask
|
bitDelegate = self.bitsForMask
|
||||||
highBitDelegate = self.highBitForMask
|
highBitDelegate = self.highBitForMask
|
||||||
|
fillerBit = "1"
|
||||||
else:
|
else:
|
||||||
bitDelegate = self.bitsForColor
|
bitDelegate = self.bitsForColor
|
||||||
highBitDelegate = self.highBitForColor
|
highBitDelegate = self.highBitForColor
|
||||||
|
fillerBit = "0"
|
||||||
|
|
||||||
for row in range(source.height):
|
for row in range(source.height):
|
||||||
bitStream = ""
|
bitStream = ""
|
||||||
@ -513,7 +516,7 @@ class HGR(ScreenFormat):
|
|||||||
highBitFound = True
|
highBitFound = True
|
||||||
|
|
||||||
# Shift bit stream as needed
|
# Shift bit stream as needed
|
||||||
bitStream = shiftStringRight(bitStream, shift, self.bitsPerPixel)
|
bitStream = shiftStringRight(bitStream, shift, self.bitsPerPixel, fillerBit)
|
||||||
bitStream = bitStream[:byteWidth*8]
|
bitStream = bitStream[:byteWidth*8]
|
||||||
|
|
||||||
# Split bitstream into bytes
|
# Split bitstream into bytes
|
||||||
@ -526,11 +529,11 @@ class HGR(ScreenFormat):
|
|||||||
bitChunk = ""
|
bitChunk = ""
|
||||||
|
|
||||||
if remainingBits < 0:
|
if remainingBits < 0:
|
||||||
bitChunk = "0000000"
|
bitChunk = fillerBit * 7
|
||||||
else:
|
else:
|
||||||
if remainingBits < 7:
|
if remainingBits < 7:
|
||||||
bitChunk = bitStream[bitPos:]
|
bitChunk = bitStream[bitPos:]
|
||||||
bitChunk += fillOutByte(7-remainingBits)
|
bitChunk += fillerBit * (7-remainingBits)
|
||||||
else:
|
else:
|
||||||
bitChunk = bitStream[bitPos:bitPos+7]
|
bitChunk = bitStream[bitPos:bitPos+7]
|
||||||
|
|
||||||
@ -633,6 +636,7 @@ if __name__ == "__main__":
|
|||||||
parser.add_argument("-c", "--cols", action="store_true", default=False, help="output column (x position) lookup tables")
|
parser.add_argument("-c", "--cols", action="store_true", default=False, help="output column (x position) lookup tables")
|
||||||
parser.add_argument("-r", "--rows", action="store_true", default=False, help="output row (y position) lookup tables")
|
parser.add_argument("-r", "--rows", action="store_true", default=False, help="output row (y position) lookup tables")
|
||||||
parser.add_argument("-x", "--xdraw", action="store_true", default=False, help="use XOR for sprite drawing")
|
parser.add_argument("-x", "--xdraw", action="store_true", default=False, help="use XOR for sprite drawing")
|
||||||
|
parser.add_argument("-m", "--mask", action="store_true", default=False, help="use mask for sprite drawing")
|
||||||
parser.add_argument("-a", "--assembler", default="cc65", choices=["cc65","mac65"], help="Assembler syntax (default: %(default)s)")
|
parser.add_argument("-a", "--assembler", default="cc65", choices=["cc65","mac65"], help="Assembler syntax (default: %(default)s)")
|
||||||
parser.add_argument("-p", "--processor", default="any", choices=["any","6502", "65C02"], help="Processor type (default: %(default)s)")
|
parser.add_argument("-p", "--processor", default="any", choices=["any","6502", "65C02"], help="Processor type (default: %(default)s)")
|
||||||
parser.add_argument("-s", "--screen", default="hgrcolor", choices=["hgrcolor","hgrbw"], help="Screen format (default: %(default)s)")
|
parser.add_argument("-s", "--screen", default="hgrcolor", choices=["hgrcolor","hgrbw"], help="Screen format (default: %(default)s)")
|
||||||
@ -662,7 +666,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
for pngfile in options.files:
|
for pngfile in options.files:
|
||||||
try:
|
try:
|
||||||
listings.append(Sprite(pngfile, assembler, screen, options.xdraw, options.processor, options.name))
|
listings.append(Sprite(pngfile, assembler, screen, options.xdraw, options.mask, options.processor, options.name))
|
||||||
except RuntimeError, e:
|
except RuntimeError, e:
|
||||||
print "%s: %s" % (pngfile, e)
|
print "%s: %s" % (pngfile, e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user