Re: [stella] Space Treat with score

Subject: Re: [stella] Space Treat with score
From: Thomas Jentzsch <tjentzsch@xxxxxx>
Date: Tue, 31 Dec 2002 11:17:43 +0100
Fabrizio wrote:
>Tasty optimizations to work on... thanks! :)

Here is another one. :-)

Instead of writing ten times something like
	LDA <#SoundMovePlayer
	STA SoundChannel0Ptr
	LDA >#SoundMovePlayer
	STA SoundChannel0Ptr+1
	JSR ActivateChannel0

you should use an index here and load the values from a table:
	ldy #SOUND_MOVEPLAYER	; = 0
	jsr ActivateChannel0
      ...
SetSoundPtr
	lda SoundTbl_Lo,y
	sta SoundChannel0Ptr
	lda SoundTbl_Hi,y
	sta SoundChannel0Ptr+1
	LDY #0			; save two extra bytes
	rts

ActivateChannel0
	jsr SetSoundPtr
	LDA (SoundChannel0Ptr),Y
	STA SoundChannel0Cnt	; Load index to the sound data...
	INY
	STY SoundChannel0Delay	; ...and start sound
	LDA (SoundChannel0Ptr),Y
	STA AUDC0
	RTS

ActivateChannel1
	jsr SetSoundPtr
	LDA (SoundChannel1Ptr),Y
	STA SoundChannel1Cnt	; Load index to the sound data...
	INY
	STY SoundChannel1Delay	; ...and start sound
	LDA (SoundChannel1Ptr),Y
	STA AUDC1
	RTS

Then you'd save 6 bytes with every subroutine call and need two 
bytes for the table. That gives 4 saved bytes/call (or 40 bytes 
in total). The new code requires 19 bytes and saves 4 bytes. So 
you gain (at least) 25 bytes here.

SoundTbl_Lo:
	<SoundMovePlayer, <SoundIntro,...
SoundTbl_Hi:
	>SoundMovePlayer, >SoundIntro,...

And if you put all sounds into one page, you don't need the hi-
table and only have to set the hi-pointer once.

And with some rather weird optimizations (e.g. using X as an 
index for the channels) there are a few bytes more to gain.


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