+Cafeman Posted August 16, 2002 Share Posted August 16, 2002 When I write to a place in memory, such as a Player Sprite's bitmap, I use this kind of STA statement which I'm sure you 8bit/ 5200 coders recognize: ldy #$00 LOOP1 LDA AnimalTable,y STA ($19),y ;$19 and $20 point to Player memory iny cpy MaxBytesForPlayerSprite bne LOOP1 ... HOWEVER, when I try to use the X register, I have found unpredictable results. For example if I try this: ldx #$00 LOOP1 LDA AnimalTable,x STA ($19),x ;$19 and $20 point to Player memory inx cpx MaxBytesForPlayerSprite bne LOOP1 ... I don't have a concrete example right now, but I have had problems with using the X register in this way, so I have gotten into the habit of only using y -- it is the STA statement where I seem to get this problem, not the LDA statement. Is there any explanation for my problems? DASM allows the program to compile using X in this way, but as I said, my routines never work with X on the STA statement. Quote Link to comment Share on other sites More sharing options...
DEBRO Posted August 16, 2002 Share Posted August 16, 2002 sta (memorylocation),x is an illegal operation isn't it? You have to use the y register for this don't you? Someone better at 6502 ASM would be better at answering this because I'm suprised DASM let you compile that. Can you look at the code and see what DASM is producing for this instruction? Quote Link to comment Share on other sites More sharing options...
atarifan49 Posted August 16, 2002 Share Posted August 16, 2002 sta (memorylocation),x is an illegal operation isn't it? You have to use the y register for this don't you? Someone better at 6502 ASM would be better at answering this because I'm suprised DASM let you compile that. Can you look at the code and see what DASM is producing for this instruction? You are correct on that. You can't do that type of indirect operation with the X register. You can do STA (memorylocation,X) or STA (memorylocation),Y, but not vice versa. Nice table of 6502 instructions here for the Atari (Sally): http://www.xmission.com/~trevin/atari/6502...02_opcodes.html Also, you can shorten your code if you do this: ldy #MaxBytesForPlayerSpriteMove LOOP1 LDA AnimalTable,y STA ($19),y ;$19 and $20 point to Player memory dey bpl LOOP1 ... You eliminate one instruction there and execute your move just slightly faster. Unless you need Y register to point at the end of the Player memory location that you moving the data to, then the other way is better. Hope that helps. Quote Link to comment Share on other sites More sharing options...
+Cafeman Posted August 16, 2002 Author Share Posted August 16, 2002 Okay, thanks guys. I'm glad I know for sure now. ANd Glenn, I actually *do* the dey and use a BEQ normally, unlike my quickly-typed example above, but thanks for the efficiency reminder. Quote Link to comment Share on other sites More sharing options...
atarifan49 Posted August 16, 2002 Share Posted August 16, 2002 Okay, thanks guys. I'm glad I know for sure now. ANd Glenn, I actually *do* the dey and use a BEQ normally, unlike my quickly-typed example above, but thanks for the efficiency reminder. No problem. Glad to help. 6502 is so fun! Quote Link to comment Share on other sites More sharing options...
Tempest Posted August 16, 2002 Share Posted August 16, 2002 Aww damn it! I have to miss the one question I know the answer to. Debro helped me figure that out a long time ago when I wanted to do some funky coding to randomize Cypher's patterns. Cypher.... Coming in 2003 to a 5200 near you! Tempest Quote Link to comment Share on other sites More sharing options...
DanBoris Posted August 16, 2002 Share Posted August 16, 2002 You are correct on that. You can't do that type of indirect operation with the X register. You can do STA (memorylocation,X) or STA (memorylocation),Y, but not vice versa. Don't you just hate asymetric instruction sets Dan Quote Link to comment Share on other sites More sharing options...
+Cafeman Posted August 16, 2002 Author Share Posted August 16, 2002 STA (memorylocation,X) or STA (memorylocation),Y Okay, what's the difference? I never use the former? Do they work the same? Quote Link to comment Share on other sites More sharing options...
DEBRO Posted August 16, 2002 Share Posted August 16, 2002 This comes from the Assembler In One Step document... Indexed Indirect Addressing --------------------------- Find the 16-bit address starting at the given location plus the current X register. The value is the contents of that address. For example, LDA ($B4,X) where X contains 6 gives an address of $B4 + 6 = $BA. If $BA and $BB contain $12 and $EE respectively, then the final address is $EE12. The value at location $EE12 is put in the accumulator. Indirect Indexed Addressing --------------------------- Find the 16-bit address contained in the given location ( and the one following). Add to that address the contents of the Y register. Fetch the value stored at that address. For example, LDA ($B4),Y where Y contains 6 If $B4 contains $EE and $B5 contains $12 then the value at memory location $12EE + Y (6) = $12F4 is fetched and put in the accumulator. Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted August 16, 2002 Share Posted August 16, 2002 Don't you just hate asymetric instruction sets I love them! Else everything would be just way too easy. Quote Link to comment Share on other sites More sharing options...
calamari Posted August 17, 2002 Share Posted August 17, 2002 Don't you just hate asymetric instruction sets I love them! Else everything would be just way too easy. * calamari vaporizes Thomas Jentzsch with a malfunctioning Solitaire sprite. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.