Re: [stella] Re: Help with efficient code

Subject: Re: [stella] Re: Help with efficient code
From: Greg Troutman <mor@xxxxxxx>
Date: Tue, 30 Sep 1997 00:56:59 -0700
crackers@xxxxxxxx wrote:

>                 lda  blocks,x   ;I'm still a little fuzzy on what exactly
>                 sta  TEMP       ;this part here is doing and how
>                 lda  blocks+1,x ;it's doing it, but I guess it'll be in
>                 sta  TEMP+1     ;my 6502 book.

All you are doing is getting the full 16 bit address of the particular
"block" of data you want into a 16 bit variable (low order byte/high
order byte) in the zero page.  Once the address is loaded, you then read
the data using this variable address, rather than having to hardcode
each of the addresses somehow...
>                 ldx  #$09       ;number of bytes in a block (+1)
> load            lda  (TEMP),x
>                 sta  BLOCK,x
>                 dex
>                 txa
>                 bne  load

You don't need the TXA above.  And you need to use Y instead of X for
this particular loop because:

LDA (TEMP),X	;is illegal (may actually assemble without an error
message 			;as...
;LDA (TEMP,X)   ;which is different than what you want and would
produce 			;goofy results)

		;should instead be:

X and Y are interchangeable for straight indexed reads/writes, but when
you are stretching out to indirect "pointers" they are used slightly

Also, you should set the index register to one less than the number of
items you wish to move, and end the loop with BPL, so that you don't
move a byte beyond your string, and DO move the byte at BLOCK,0.  That
is, your 9 items would be indexed numbered as 0-through-8, so set up
your index to move those.

And you can save space by only using the low-order bytes in a table like
this.  Assuming you can arrange your code and data so that all the data
from these blocks is in the same memory page (use an ALIGN pseudo-op to
force it, if you have enough ROM available) you could do this:

;at program init
	lda #>blockPage		
	sta blockPtr + 1	;preload the page of all your blocks

;later, during program execution	
	ldx VARIABLE	;skip the BCS by not allowing VARIABLE to
	lda blocks,x	; exceed the legal limit
	sta blockPtr	;store the low order byte of the desired block
	ldy #8		;index on 0-through-8
	lda (blockPtr),y	;read
	sta BLOCK,y		;write
	dey			;next item in string
	bpl load		;loop until index 0 has been done

blocks .byte #<block0,#<block1, etc. ;.byte instead of .word

This is some real important junk and you're definitely on the right
track.  You're going to be very glad when you work out the kinks and
have the mechanics of this particular stuff all squared away in your


Archives updated once/day at
Unsubscribing and other info at

Current Thread