A fix for Wrong Srpites being drawn.......

tbizzle

Well-known member
Nevermind that just
Awesome, thanks for the explanation.
Unless overtime I notice more issues or something im more than happy to stick with the previous code for now. I didnt have half as many wrong sprite sheets before I started adding in things like animated tiles etc so as far as I know your thoery makes alot of sense. I will keep testing my game and keep track of any issues, but seriously ive only seen that one time so far.
Might not hurt to check your project for any other places where you are using userscreenbytes7 and put that check there too. Just incase something else is making use of that and increasing it oer a value of 31 (#$1F).
 

JayJayHux

Active member
Nevermind that just

Might not hurt to check your project for any other places where you are using userscreenbytes7 and put that check there too. Just incase something else is making use of that and increasing it oer a value of 31 (#$1F).
Ok thanks for the tip.
Im sure once I see another wrong sprite sheet(if I do) i will feel the need to do that.
So, all scripts using userScreenByte7(0 for me) i should add the glitch code or just the reset code?
 

tbizzle

Well-known member
@JayJayHux That is what I am going to test out. Currently the onl places in my game that are using it are the doLoadScreen16 and Game Timer script where the cycle for the animated tiles is.
 

JayJayHux

Active member
@JayJayHux That is what I am going to test out. Currently the onl places in my game that are using it are the doLoadScreen16 and Game Timer script where the cycle for the animated tiles is.
Ok cool, please let me know whatever you suggest is best.
I ran my game for about another 10 mins or so and got one wrong sprite sheet load. So still way better than it was, like 95 percent better. Massive improvement regardless.
 

tbizzle

Well-known member
I played it right now for five minutes and got one like on the 10th screen, lol. Ugh! I need to do a full playthrough, I'm keeping count too...
 

JayJayHux

Active member
I played it right now for five minutes and got one like on the 10th screen, lol. Ugh! I need to do a full playthrough, I'm keeping count too...
Could be just a coincidence but the 2 times ive seen wrong sprite sheets since adding this code was only once per play and both were withing the first 5 to 10 screen loads. Just an observation.
 

tbizzle

Well-known member
Could be just a coincidence but the 2 times ive seen wrong sprite sheets since adding this code was only once per play and both were withing the first 5 to 10 screen loads. Just an observation.
Hopefully! I mean, it is not the worst glitch. It definitely didn't happen as much as the 8x16 phantom tile glitch. I'm so glad I got rid of that one!
 

JayJayHux

Active member
Hopefully! I mean, it is not the worst glitch. It definitely didn't happen as much as the 8x16 phantom tile glitch. I'm so glad I got rid of that one!
Absolutely!
There were several glitches(phantom8x16 tile, sprite garbling, wrong sprite sheets, animTiles, probably others ive forgotten) that all together made things very messy.
Thankfully only the wrong sprite sheets and animTiles(maybe) remain, but there now for me ALMOST non existent. So im very happy with your fix. Im just hoping it stays this rare for me. Are you sure it has decreased your glitches??
 

tbizzle

Well-known member
I'll do a full playthrough in the next week to find out. With the short plays I'e had recently, things have looked like it is reduced.
 

JayJayHux

Active member
@JayJayHux I completed a playthrough. It takes 7 hours to play it from beginning to end, had it happen 8 times. So pretty much one glitch per hour...
Ok, thats a solid test and a solid game. Ive gotta play it when I get more time.
How often where you getting glitches before adding the fix?
And what did you test it on? Nesmaker?
Ive found 4 glitches so far when testing with nesmaker since adding the fix. Wat less than before but I might try your other idea just to see if there is any difference.
Was it just to reset the useScreenByte at start of doLoadScreen16 and GameTimer scripts?
 

tbizzle

Well-known member
Ok, I think I know why the glitch is happening. I''m 85% percent sure this is the reason, lol. I just did a playthrough of 2.5 hours with no glitch! The thinking is that somewhere along the code userscreenbyte7 is getting INC somewhere when it should not be. So then userscreenbyte needs to be more tightly controlled inside of the doLoadScreen16 script by not INC it but rather by giving it a reset and LDA and STA it. This way there is no unitentional increase somewhere along the line of the game code. So at line 17 inside the doLoadScreen16 script, after those 4 load sub pallete macros, put this code in:
Code:
LoadObjectSubPalettes spriteSubPal1, #$00
    LoadObjectSubPalettes spriteSubPal2, #$04
    LoadObjectSubPalettes spriteSubPal3, #$08
    LoadObjectSubPalettes spriteSubPal4, #$0C
    
    
     LDA userScreenByte7;;;;;;;;;;;glitch code
     CMP #$1D       
     BCC +animOk
     LDA #$00
     STA userScreenByte7
         +animOk:;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Then at the bottom of the doLoadScreen16 script, rplace this code:
Code:
;SwitchCHRBank #$01
        ;LoadChrData #$17, #$10, #$00, #$20, AnimTiles_Lo, AnimTiles_Hi, userScreenByte7
        
      
        ;INC userScreenByte7
      
        ;SwitchCHRBank #$02
        ;LoadChrData #$17, #$10, #$00, #$20, AnimTiles_Lo, AnimTiles_Hi, userScreenByte7

With this code:
Code:
LDA userScreenByte7;;;;;;;;;;;;;glitch code
    STA tempA

    SwitchCHRBank #$01
    LoadChrData #$17, #$10, #$00, #$20, AnimTiles_Lo, AnimTiles_Hi, tempA

    INC tempA

    SwitchCHRBank #$02
    LoadChrData #$17, #$10, #$00, #$20, AnimTiles_Lo, AnimTiles_Hi, tempA;;;glitch
 

JayJayHux

Active member
Ok, I think I know why the glitch is happening. I''m 85% percent sure this is the reason, lol. I just did a playthrough of 2.5 hours with no glitch! The thinking is that somewhere along the code userscreenbyte7 is getting INC somewhere when it should not be. So then userscreenbyte needs to be more tightly controlled inside of the doLoadScreen16 script by not INC it but rather by giving it a reset and LDA and STA it. This way there is no unitentional increase somewhere along the line of the game code. So at line 17 inside the doLoadScreen16 script, after those 4 load sub pallete macros, put this code in:
Code:
LoadObjectSubPalettes spriteSubPal1, #$00
    LoadObjectSubPalettes spriteSubPal2, #$04
    LoadObjectSubPalettes spriteSubPal3, #$08
    LoadObjectSubPalettes spriteSubPal4, #$0C
   
   
     LDA userScreenByte7;;;;;;;;;;;glitch code
     CMP #$1D      
     BCC +animOk
     LDA #$00
     STA userScreenByte7
         +animOk:;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Then at the bottom of the doLoadScreen16 script, rplace this code:
Code:
;SwitchCHRBank #$01
        ;LoadChrData #$17, #$10, #$00, #$20, AnimTiles_Lo, AnimTiles_Hi, userScreenByte7
       
     
        ;INC userScreenByte7
     
        ;SwitchCHRBank #$02
        ;LoadChrData #$17, #$10, #$00, #$20, AnimTiles_Lo, AnimTiles_Hi, userScreenByte7

With this code:
Code:
LDA userScreenByte7;;;;;;;;;;;;;glitch code
    STA tempA

    SwitchCHRBank #$01
    LoadChrData #$17, #$10, #$00, #$20, AnimTiles_Lo, AnimTiles_Hi, tempA

    INC tempA

    SwitchCHRBank #$02
    LoadChrData #$17, #$10, #$00, #$20, AnimTiles_Lo, AnimTiles_Hi, tempA;;;glitch
Nice tbizzle,
Very keen to try this out.
Please let me know if any bugs are found and does this include wrong sprite sheets?

PS ive also been experimenting with a fix and might have made some progress but its a wip. But if your code works then it wont be neccesary anyway.
 

tbizzle

Well-known member
@JayJayHux I finally did get the glitch again. I was testing out my last level and got the glitch after the second screen. So the bug may not be totally exterminated, but hopefully greatly reduced!
 

JayJayHux

Active member
@JayJayHux I finally did get the glitch again. I was testing out my last level and got the glitch after the second screen. So the bug may not be totally exterminated, but hopefully greatly reduced!
Thats great,
It sounds like it must have reduced greatly overall so ill be trying this out shortly.
Since im already in the middle of trying a fix ill finish testing it first and then if it doesnt work ill use this one for sure.
 

JayJayHux

Active member
Possible (HIGHLY PROBABLE) NESMaker animated tile / wrong sprite sheet corruption fix (Mapper30 / UNROM512)

Issue symptoms:
  • wrong sprite sheets
  • +$80 sprite swaps
  • wrong sprite positions
  • duplicated CHR chunks
  • intermittent animated tile corruption
Fix:
At the end of doLoadChrRam.asm, before ReturnBank / RTS, add:

LDA #$00
STA temp1
STA arg3_hold
STA temp16
STA temp16+1

Final section should look like:

doneLoadingTiles:

LDA #$00
STA temp1
STA arg3_hold
STA temp16
STA temp16+1

ReturnBank
RTS
Likely cause:
Stale CHR upload variables/pointers persisting between sequential CHR loads.

Testing:
~2000 rapid/semi-rapid screen transitions tested with ZERO issues across:

  • NESMaker Mesen
  • PC Mesen
  • FCEUX
  • Nestopia UE

    @tbizzle @dale_coop
    This is a colaboration I have been working on constantly for weeks with cGPT to find the true source of wrong sprite sheets and animated tile/bg tile glitches.
    It took a long time and we tried many different fixes in many different places along the way but eventually we found a fix (see above^^^^) that since I added it I have tested in 4 different emulators for a total of over 2,000 screen loads, at differnt speeds, on anim and non anim screens etc....
    There has been ZERO, truly zero glitches at all.
    The only thing i have not been able to test yet is true NES hardware.

    This must be the true fix......

    Please let me know how it goes either way?? and if I finally experience any bugs at all I will update.
 

JayJayHux

Active member
@JayJayHux Made it half way through a playthrough (4ish hours), the glitch only happened one time!
That is both very good news but also bad news. I had really hoped for 100 percent success rate. Was it tested on the NES?? And what was the exact glitch??
Hopefully 1 glitch in 4 hours is at least an improvement??
 

tbizzle

Well-known member
That is both very good news but also bad news. I had really hoped for 100 percent success rate. Was it tested on the NES?? And what was the exact glitch??
Hopefully 1 glitch in 4 hours is at least an improvement??
I tested it on cartridge, played on my Analogue NT Mini Noir. It was a CHR tile switch glitch, no sprites glitched out, just tiles.
 
Top Bottom