Re: [stella] incoming source

Subject: Re: [stella] incoming source
From: Thomas Jentzsch <tjentzsch@xxxxxx>
Date: Fri, 10 Dec 2004 21:18:06 +0100
Ben Larson wrote:
> Thomas J. requested the source for 'Incoming' from me over on the
> Atariage forums last week in order to do some space optimization, so
> I figured I'd just post it here.

Ok, I am a bit lazy, so I'll just give you some hints for gaining
space now: :-)

1. Testing bits:
Test Bit7:
  lda status
  and #%10000000
  bne .somewhere
better:
  bit status
  bmi .somewhere
  
Test Bit6:
  lda status
  and #%01000000
  bne .somewhere
better:
  bit status
  bvs .somewhere

Test Bit0:
  lda status
  and #%00000001
  bne .somewhere
better:
  lda status
  lsr
  bcs .somewhere

Since you are doing this very often, this should save a lot of bytes.

2. Random number generation:
This code should do the whole job and is *much* shorter:
  lda random    ; initialize to non-zero at start
  lsr
  bcs .skipEor
  eor #$b2      ; various values possible here
.skipEor:
  sta random

It always creates a whole new random byte. It is not as random as your
code, but I highly doubt anyone will notice a difference.

3. Maths:
You are doing a lot of 16 bit math (e.g. shots), so you could use a
subroutine like:
Add16:
  clc
  adc $00,x
  sta $00,x
  tya
  adc $01,x
  sta $01,x
  rts
  
Arrange your variables, so that the high-byte always follows the
low-byte and then load the address of the low-byte into X

You can even make the code more useful:
Add16_0
  ldy #0       ; add value < 256
Add16:
  clc
  adc $00,x
  sta $00,x
  tya
  adc $01,x
  sta $01,x
  rts

You can also you this for subtracting, just add negative values.

4. Use non-BCD variables when you do a lot of calculations with them
(e.g. P1/2Power). It's easier to convert them for display only than
having to convert them for calculations.

5. Make you code more universal, e.g. don't code twice for player 1
and player 2. Rearrange your variables and code so that a player 1
variable precedes the matching player 2 variable. And use GRP0 for
player 1 and GRP1 for player 2. Then you can loop over the code twice.

And maybe better call them player 0 and 1 ;-)


Ok, if implementing those tips doesn't give you enough bytes, I still
know plenty of more bytes to gain. :-)

BTW:
You are calling the first subroutine before initializing the stack!

Have fun!
Thomas                            
_______________________________________________________
Thomas Jentzsch         | *** Every bit is sacred ! ***
tjentzsch at web dot de |


Current Thread