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) badChoice ... 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 page). -- mor@xxxxxxx http://www.crl.com/~mor/ -- 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [stella] 6507 vs. 6502, Nick S Bensema | Thread | Re: [stella] Re: Help with efficien, Eckhard Stolberg |
RE: [stella] Re: Help with efficien, arb | Date | [stella] Re: Help with efficient co, Jim Nitchals |
Month |