Re: [stella] Re: Help with efficient code

Subject: Re: [stella] Re: Help with efficient code
From: crackers@xxxxxxxx
Date: Tue, 30 Sep 1997 03:01:51 -0400 (EDT)
In article <199709300042.RAA15688@xxxxxxxxxxxxxxxxxxx>, you wrote:
>> 		beq  pointers,x
>
>This isn't a valid instruction.  Conditional branches can only go to one
>fixed location +/- 127 bytes away from the branch instruction itself.
~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~

Doh! Doesn't that just figure!

~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~
>If you have a single state in "VARIABLE", as your example did, try:
>
        lda variable
        cmp #num_entries
        bcs not_in_table
        asl
        tax
        lda jump_table,x
        sta temp     ; temp should be 2 bytes somewhere in RAM
        lda jump_table+1,x
        sta temp+1
        jmp (temp)   ; jump indirect through temp
>@not_in_table:
>; continue with rest of program
>
>jump_table:
>        dc.w framistat    ; your assembler may prefer .word
>        dc.w dohickey
>        dc.w whachamacallit
>        dc.w thingy
>        dc.w dodad
>num_entries equ (*-jump_table)/2    ; some assemblers use $, not *
>                                    ; to refer to current address
>(or if all else fails:)
>num_entries equ 5         ; but it isn't as nice
>
>It's possible to rearrange the jump table into two halves (low and
>high byte of the addresses in separate tables) but doing so only 
>saves 1 instruction and makes the code harder to change.  Give this
>method a try.
~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~

I think I understand what's going on here, thanks!

Infact I think it might take care of another problem I've been contemplating.
Let's say I've got a routine that loads a block of data into memory.
The block is always the same size and will always be loaded to the same
block of memory but depending on the value of the VARIABLE, the data
for the block will be drawn from one of a number of locations.

Would I accomplish this like so...

-----------------------------------------------------------------------------
BLOCK    = $80
TEMP	 = $88
VARIABLE = $8A

		lda  VARIABLE
		cmp  #$05	;number of VARIABLE values (+1) 
		bcs  continue
		asl
		tax
		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.

		ldx  #$09	;number of bytes in a block (+1)
load		lda  (TEMP),x
		sta  BLOCK,x
		dex
		txa
		bne  load


continue	lda  blablabla	;rest of programme
		"	"
		"	"
		rts

blocks		.word  block0
		.word  block1
		.word  block2
		.word  block3
		.word  block4

block0		.byte  $00,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff

block1		.byte  $00,$aa,$aa,$aa,$aa,$aa,$aa,$aa,$aa

block2		.byte  $00,$bb,$bb,$bb,$bb,$bb,$bb,$bb,$bb

etc..etc..etc..

----------------------------------------------------------------------------

Am I on the right track here or am I making an inaccurate assumption again?

                                  CRACKERS
                      (Starting to understand from hell!!)

-- 

Accordionist - Wethifl Musician - Atari 2600 Collector | /\/\
*NEW CrAB URL* http://www.hwcn.org/~ad329/crab.html ***| \^^/
Bira Bira Devotee - FES Member - Samurai Pizza Cats Fan| =\/=



--
Archives updated once/day at http://www.biglist.com/lists/stella/archives/
Unsubscribing and other info at http://www.biglist.com/lists/stella/stella.html

Current Thread