Jump to content
IGNORED

Question about 6502 STA (ScreenRam),y


Cafeman

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...