Re: [stella] Space Treat with score

Subject: Re: [stella] Space Treat with score
From: Thomas Jentzsch <tjentzsch@xxxxxx>
Date: Mon, 30 Dec 2002 23:07:34 +0100
Fabrizio wrote:

>At the moment I'm almost completely out of ROM space, but I'd
>still like to add a few more features...

Just a few quick peephole optimizations:

ApplicationLoop	
	LDA GameScreen
	BEQ StartIntroScreen
	CMP #5
	BCC ContinueApplicationLoop1
	JMP MainLoop
ContinueApplicationLoop1
	CMP #1
	BEQ MainLoopIntroScreen
	CMP #2
	BEQ StartLevelScreen
	CMP #3
	BEQ MainLoopLevelScreen
	CMP #4
	BEQ StartGameScreen
You could save a few bytes here by reversing the order and 
using DEX/DEY.

In LoadLevelPointers you could use a table and a loop instead 
of the current code.

And you are quite ofting using code like this:
  JSR somewhere
  RTS
Replace this with JMP and save one byte.

And here LDA #0 is superfluous:
	LDA plrLives
	BNE StartGameScreen
	LDA #0
	STA GameScreen

Here you could use LSR/BCS and save one byte:
	LDA SWCHB
	AND #%00000001
	BNE NoResetGame

And why don't you use X or Y here?
	LDA LevelCounter+1
	CLC
	ADC #1
	STA LevelCounter+1
That would save you two bytes.

And instead of:
	CMP #10
	BNE NoResetLevelCounter
	LDA #0
	STA LevelCounter+1
...you could write:
	EOR #10
	BNE NoResetLevelCounter
	STA LevelCounter+1

Often a JMP can be safely replace by an unconditional branch. 
E.g.:
Fuel4
	LDA PfFuel+4
	BEQ Fuel3
	LSR
	STA PfFuel+4
	JMP NoZeroFuelDelay
BPL will always work here

And sometimes some code rearrangement might help to reuse 
register values. Like here:
	LDA #0
	STA plrExploding
	LDA GoingUp
	BEQ ChangeDirectionAnim2
	LDA #0
	STA GoingUp	; Rimette il vecchio set di nemici (Anim)
If you use X or Y to load GoingUp, then you can reuse the 0 in 
the accu.

Or here:
	LDA FuelColor
	CMP #FUELCOLOR_WARNING
	BEQ NoRestartFuelSound
	LDA #FUELCOLOR_WARNING
	STA FuelColor
Replace with
	LDA #FUELCOLOR_WARNING
	CMP FuelColor
	BEQ NoRestartFuelSound
	STA FuelColor

And if the LeftRandom subroutine would return random, you could 
avoid loading it again and again. ;)
 
Have fun!	
Thomas


----------------------------------------------------------------------------------------------
Archives (includes files) at http://www.biglist.com/lists/stella/archives/
Unsub & more at http://www.biglist.com/lists/stella/


Current Thread