Added option to clobber registers in sprite code

* caller has to save what they need, but saves 26 cycles
This commit is contained in:
Rob McMullen 2017-06-30 12:52:15 -07:00
parent 6dfab0efb5
commit 18101794b9
4 changed files with 26 additions and 18 deletions

View File

@ -203,7 +203,7 @@ class Listing(object):
class Sprite(Listing):
backing_store_sizes = set()
def __init__(self, pngfile, assembler, screen, xdraw=False, use_mask=False, backing_store=False, processor="any", name=""):
def __init__(self, pngfile, assembler, screen, xdraw=False, use_mask=False, backing_store=False, clobber=False, processor="any", name=""):
Listing.__init__(self, assembler)
self.screen = screen
@ -213,6 +213,7 @@ class Sprite(Listing):
self.xdraw = xdraw
self.use_mask = use_mask
self.backing_store = backing_store
self.clobber = clobber
self.processor = processor
if not name:
name = os.path.splitext(pngfile)[0]
@ -267,7 +268,8 @@ class Sprite(Listing):
self.asm("pla")
def jump65C02(self):
self.save_axy_65C02()
if not self.clobber:
self.save_axy_65C02()
self.asm("ldy PARAM0")
self.asm("ldx MOD%d_%d,y" % (self.screen.numShifts, self.screen.bitsPerPixel))
@ -280,7 +282,8 @@ class Sprite(Listing):
self.addr("%s_SHIFT%d" % (self.slug, shift))
def jump6502(self):
self.save_axy_6502()
if not self.clobber:
self.save_axy_6502()
self.asm("ldy PARAM0")
self.asm("ldx MOD%d_%d,y" % (self.screen.numShifts, self.screen.bitsPerPixel))
@ -320,18 +323,20 @@ class Sprite(Listing):
cycleCount, optimizationCount = self.generateBlitter(colorStreams, maskStreams, cycleCount)
if self.processor == "any":
self.out(".ifpC02")
self.restore_axy_65C02()
self.out(".else")
self.restore_axy_6502()
self.out(".endif")
elif self.processor == "65C02":
self.restore_axy_65C02()
elif self.processor == "6502":
self.restore_axy_6502()
else:
raise RuntimeError("Processor %s not supported" % self.processor)
if not self.clobber:
if self.processor == "any":
self.out(".ifpC02")
self.restore_axy_65C02()
self.out(".else")
self.restore_axy_6502()
self.out(".endif")
elif self.processor == "65C02":
self.restore_axy_65C02()
elif self.processor == "6502":
self.restore_axy_6502()
else:
raise RuntimeError("Processor %s not supported" % self.processor)
self.out()
self.asm("rts")
self.comment("Cycle count: %d, Optimized %d rows." % (cycleCount,optimizationCount))
@ -698,6 +703,7 @@ if __name__ == "__main__":
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("-n", "--name", default="", help="Name for generated assembly function (default: based on image filename)")
parser.add_argument("-k", "--clobber", action="store_true", default=False, help="don't save the registers on the stack")
parser.add_argument("-o", "--output-prefix", default="", help="Base name to create a set of output files. If not supplied, all code will be sent to stdout.")
parser.add_argument("files", metavar="IMAGE", nargs="*", help="a PNG image [or a list of them]. PNG files must not have an alpha channel!")
options, extra_args = parser.parse_known_args()
@ -725,7 +731,7 @@ if __name__ == "__main__":
for pngfile in options.files:
try:
listings.append(Sprite(pngfile, assembler, screen, options.xdraw, options.mask, options.backing_store, options.processor, options.name))
listings.append(Sprite(pngfile, assembler, screen, options.xdraw, options.mask, options.backing_store, options.clobber, options.processor, options.name))
except RuntimeError, e:
print "%s: %s" % (pngfile, e)
sys.exit(1)

View File

@ -29,7 +29,7 @@ colortest.dsk: HiSprite.py colortest.s bwsprite.s
atrcopy colortest.dsk boot -b colortest.xex --brun 6000 -f
multitest-sprite-driver.s: HiSprite.py $(BWSPRITE)
python HiSprite.py -a mac65 -p 6502 -s hgrbw -m -b -o multitest $(BWSPRITE) $(COLORSPRITE)
python HiSprite.py -a mac65 -p 6502 -s hgrbw -m -b -k -o multitest $(BWSPRITE) $(COLORSPRITE)
multitest.dsk: HiSprite.py multitest.s multitest-sprite-driver.s
atasm -omultitest.xex multitest.s -Lmultitest.var -gmultitest.lst

Binary file not shown.

View File

@ -57,8 +57,10 @@ initsprites
; Draw sprites by looping through the list of sprites
renderstart
ldy #0
sty PARAM3
renderloop
ldy PARAM3
lda sprite_active,y
bmi renderend ; end of list if negative
beq renderskip ; skip if zero
@ -74,7 +76,7 @@ renderloop
jsrsprite
jsr $ffff ; wish you could JSR ($nnnn)
renderskip
iny
inc PARAM3
bne renderloop ; branch always because always positive; otherwise limited to 255 sprites (haha)
renderend