Added separate flags for row/col lookup table, and can be appended to sprite code

This commit is contained in:
Rob McMullen 2017-06-21 14:11:48 -07:00
parent 8b5a4afeab
commit 7ca6dd4ccd
1 changed files with 29 additions and 13 deletions

View File

@ -103,14 +103,9 @@ class CC65(AssemblerSyntax):
class Listing(object):
disclaimer = '''
; This file was generated by HiSprite.py, a sprite compiler by Quinn Dunki.
; If you feel the need to modify this file, you are probably doing it wrong.
'''
def __init__(self, assembler):
self.assembler = assembler
self.lines = [self.disclaimer]
self.lines = []
self.current = None
self.desired_count = 1
self.stash_list = []
@ -542,11 +537,10 @@ class HGRBW(HGR):
return color
class HorizontalLookup(Listing):
class RowLookup(Listing):
def __init__(self, assembler, screen):
Listing.__init__(self, assembler)
self.generate_y(screen)
self.generate_x(screen)
def generate_y(self, screen):
self.label("HGRROWS_H1")
@ -563,6 +557,12 @@ class HorizontalLookup(Listing):
for addr in screen.generate_row_addresses(0x2000):
self.byte("$%02x" % (addr & 0xff), 8)
class ColLookup(Listing):
def __init__(self, assembler, screen):
Listing.__init__(self, assembler)
self.generate_x(screen)
def generate_x(self, screen):
self.out("\n")
self.label("DIV%d_%d" % (screen.numShifts, screen.bitsPerPixel))
@ -576,9 +576,15 @@ class HorizontalLookup(Listing):
if __name__ == "__main__":
disclaimer = '''
; This file was generated by HiSprite.py, a sprite compiler by Quinn Dunki.
; If you feel the need to modify this file, you are probably doing it wrong.
'''
parser = argparse.ArgumentParser(description="Sprite compiler for 65C02/6502 to generate assembly code to render all shifts of the given sprite, optionally with exclusive-or drawing (if background will be non-black). Generated code has conditional compilation directives for the CC65 assembler to allow the same file to be compiled for either architecture.")
parser.add_argument("-v", "--verbose", default=0, action="count")
parser.add_argument("-t", "--tables", action="store_true", default=False, help="output only lookup tables for horizontal sprite shifts (division and modulus 7)")
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("-x", "--xdraw", action="store_true", default=False, help="use XOR for sprite drawing")
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)")
@ -604,13 +610,23 @@ if __name__ == "__main__":
parser.print_help()
exit(1)
if options.tables:
print HorizontalLookup(assembler, screen)
exit(0)
listings = []
for pngfile in options.files:
try:
print Sprite(pngfile, assembler, screen, options.xdraw, options.processor)
listings.append(Sprite(pngfile, assembler, screen, options.xdraw, options.processor))
except RuntimeError, e:
print e
parser.print_help()
if options.rows:
listings.append(RowLookup(assembler, screen))
if options.cols:
listings.append(ColLookup(assembler, screen))
if listings:
print disclaimer
for section in listings:
print section