Sprites corrupted.

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Sprites corrupted.
by on (#108272)
Hi All,

I'm having a problem loading in my player two sprite for my pong game. For some reason, it seems like my sprite is becoming corrupted after the initial load. Here is the code I'm using to load my sprites

Code:

;;Load Dave Ninja Standing Sprite
   
    LoadSprites:
   
    LoadNinjas:
   
    LDA #$01
    CMP #STATEPLAYING
    BNE DaveStandingDone

    LoadDaveStandingLoop:

    LDA DaveNinjaStand, x        ; load data from address (sprites +  x)
    STA $0204, x          ; store into RAM address ($0200 + x)
    INX                   ; X = X + 1
    CPX #$40              ; Compare X to hex $28, decimal 40
    BNE LoadDaveStandingLoop   ; Branch to LoadSpritesLoop if compare was Not Equal to zero
                        ; if compare was equal to 4, keep going down
    DaveStandingDone:


    LoadJohnStandingLoop:
    LDA JohnNinjaStand, x
    STA $0244, x
    INX
    CPX #$40
    BNE LoadJohnStandingLoop
   
    JohnStandingDone:
   

LoadScoreSprites:

    LDA scoresprites, x        ; load data from address (sprites +  x)
    STA $0284, x          ; store into RAM address ($0200 + x)
    INX                   ; X = X + 1
    CPX #$18              ; Compare X to hex $18, decimal 24
    BNE LoadScoreSprites   ; Branch to LoadSpritesLoop if compare was Not Equal to zero
                        ; if compare was equal to 4, keep going down
    LoadScoreSpritesDone:
   
    RTS




Just standard stuff. A simple loop to load the Ninja Sprites and Score Sprites. On the title screen, when the start button is pressed I shut rendering off and load the character sprites, score sprites and background. Also, my character sprites (technically metasprites I believe) are quite large. 4x4 tiles for a total of 16 tiles per character.

Any help would be appreciated guys. This is the last hoop I have to jump through before I get started on the sound engine so I'm really excited to solve this issue.

Also,

attatched is a zip file containing the code and the rom for the game. I've scanned through it in and out but cannot locate the issue.

-Mysteriousity
Re: Sprites corrupted.
by on (#108280)
Um... this is really tough for me to give a good answer to.

But, here's at least one thing I did find. In "DaveSlap.asm", you have the following code:
Code:
.loop:
  LDA daveslapback_anim_frames, x
  STA $021D, y  ;;;CHANGE THIS!!!!
  INY
  INY
  INY
  INY
  INX
  CPY #$40
  BCC .loop

First, note that you have a "CHANGE THIS!!!!", right there.

Now, when X is $0E, and Y is $38, the tile ID $01 is stored to $0255 when this code is run. (This is the 1 being written to the green ninja instead of his graphics.) Why this happens, I have no idea. I'm hoping you'll just realize, "Oh snap, I never changed that code I was supposed to change!" To look more into it, I may have to read a LOT of code. Your program structure also makes things really difficult to read (for me at least), so I may give some tips on that later.
Re: Sprites corrupted.
by on (#108309)
Wow, I cannot believe I missed/forgot about that! I kid you not I literally spent 5 hours yesterday looking for what was causing this issue. Sometimes I guess you just need a fresh pair of eyes.

Concerning the organization of the code, I know its definately not very tight. Its my first project. If you have any suggestions, I'd be very open to hearing them. I plan on tightening everything up as best I can, and then submitting the code here for more tightening suggestions, at which point I will re-write it again based on those suggestions, and then release the source as sort of a learning aid for begginers like me. I plan to document everything very thoroughly. Since I'm a beginner, I'm pretty sure other people who have just started coding will have a lot of the same questions that I just went through to complete this project, so I'll try to fill in all those details for them.


Kasumi wrote:
Um... this is really tough for me to give a good answer to.

But, here's at least one thing I did find. In "DaveSlap.asm", you have the following code:
Code:
.loop:
  LDA daveslapback_anim_frames, x
  STA $021D, y  ;;;CHANGE THIS!!!!
  INY
  INY
  INY
  INY
  INX
  CPY #$40
  BCC .loop

First, note that you have a "CHANGE THIS!!!!", right there.

Now, when X is $0E, and Y is $38, the tile ID $01 is stored to $0255 when this code is run. (This is the 1 being written to the green ninja instead of his graphics.) Why this happens, I have no idea. I'm hoping you'll just realize, "Oh snap, I never changed that code I was supposed to change!" To look more into it, I may have to read a LOT of code. Your program structure also makes things really difficult to read (for me at least), so I may give some tips on that later.
Re: Sprites corrupted.
by on (#108319)
To tighten up code, I suggest structuring code like this:

One main data file. Maybe you ca split it in to sub-files, but I've never had to yet.

Subroutines. A few of them. This keeps your main loop small and pretty relocatable,outside of the the last JMP in the engine. (I always use JMP in any semi-complex engine to make sure I will be able to rely on it to just work.)

If the program is on a mapper, I use a Bank/ folder in the program folder to keep data in all the banks I want. This helps a lot, as it keeps the program in the main program files organized in to their right banks.

Here's one example from a source I released just a few days ago:

https://docs.google.com/file/d/0B1laUfq ... sp=sharing

One thing I didn't do is make a file just for variables/RAM space reserves. I should have, but it's a small project for me so I didn't. But I'd highly suggest them later. Tabbed editors are much easier than scrolling through an upwards of 2000 SLoC.