Re: [stella] Re: Help with efficient code

Subject: Re: [stella] Re: Help with efficient code
From: Greg Troutman <mor@xxxxxxx>
Date: Mon, 29 Sep 1997 17:46:23 -0700
crackers@xxxxxxxx wrote:
> I'm sorry if this is the third time everyone has seen this post, but
> on my end, for some reason, everytime I post this message everything
> goes nuts. I'm hoping the message goes through this time and if it has
> been all along, well consider it a mid-season repeat. ;)
> ~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~
> I was curious if there was a more efficient way to do something like this.
> ----------------------------------------------------------------------------
>                 lda  #$00
>                 sta  CHECK
> checkit         ldx  CHECK
>                 lda  VARIABLE
>                 cmp  CHECK
>                 beq  pointers,x

You can't do the above.  What you need is a JMP (ZERO_PAGE_INDIRECT). 
There are lots of ways to build a table of offsets, but the bottom line
is putting the low byte, then the hi byte of where you want to jump to
in 2 bytes of zero page memory.  In order to save space in both the
table sizes and the amount of code needed, I *usually* try and build a
table only with the low bytes, and put all the target addresses into the
same page of memory.  So, I'll end up with something like:

	ldx variable
	lda jmpTable,x
	sta jmpWord

	lda #>routinePage	;this byte might need to be loaded only once
	sta jmpWord + 1		;when program inits, unless you are recycling
				;this memory with other routines
	jmp (jmpWord)


jmpTable #<firstRoutine,#<secondRoutine,#<thirdRoutine ;etc.

As a rule, I don't like to see code where there might be an illegal
value sent to a routine like this, so I rarely check it.  The main
reason for doing this sort of thing is to save space over a long list of
lda/cmp/bne, so cutting out checks for invalid values furthers that
cause...  One exception would be something that gets re-used, like a
menuing system, in which case you'd need the checks, as well as indirect
pointers to the list of jmp-to addresses (or pre-load them into zero


Archives updated once/day at
Unsubscribing and other info at

Current Thread