Help with tile graphics bug?

Yo! so as you all know I'm working on my Indie NES game currently known as Project Hexagon. But anyway my current issue is when loading the units aka the tile changes during postscreenload.asm
the game while working one hundred percent correctly in gameplay... the graphics bug out hard! here is an example:
tile glitch.png
so yeah... again in postscreenload this happens when loading all these tiles at once for gameplay purposes
here is my tile change macro's (originally made by @dale_coop) subroutine for changing tiles:

doLoadUnitTiles:
LDA arg1_hold
ASL
ASL
ASL
ASL
AND #%11110000
STA tempz
LDA arg0_hold




ORA tempz
TAY
LDA arg4_hold
BEQ +isEvenCt
; is an odd ct, so looking in collisionTable2
LDA arg3_hold
STA collisionTable2,y
JMP +doneWithTileUpdate
+isEvenCt
LDA arg3_hold
STA collisionTable,y

+doneWithTileUpdate

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; This part will actually update the tile with tile 0 in the tile set.
; ys is carried over from above.

; GET THE HIGH BYTE OF THE TILE TO CHANGE
LDA arg4_hold
BEQ +isEvenNt
;;is odd nt
LDA #$24
JMP +gotNt
+isEvenNt
;;is even nt
LDA #$24
+gotNt
STA temp1
; GET THE LOW BYTE OF THE TILE TO CHANGE
TYA
STA temp
LSR
LSR
LSR
LSR
LSR
LSR
clc
ADC temp1
STA temp2 ;;;temp16+1
TYA
AND #%11110000
ASL
ASL
STA tempz
TYA
AND #%00001111
ASL
ORA tempz
STA temp3 ;temp16

; SET THE TILE NUMBER TO CHANGE TO.
LDA arg2_hold ;; the tile to change.
; this is in tiles, so if you wanted the second "metatile",
; use 2, not 1. If you wanted the tile in the next row,
; use #$20, not #$10. Etc.
STA tempA
CLC
ADC #$01
STA tempB
CLC
ADC #$0F
STA tempC
CLC
ADC #$01
STA tempD


LDY scrollOffsetCounter
LDA temp2
STA scrollUpdateRam,y
INY
LDA temp3
STA scrollUpdateRam,y
INY
LDA tempA
STA scrollUpdateRam,y
INY

LDA temp2
STA scrollUpdateRam,y
INY
LDA temp3
CLC
ADC #$01
STA scrollUpdateRam,y
INY
LDA tempB
STA scrollUpdateRam,y
INY

LDA temp3
CLC
ADC #$20
STA temp3
LDA temp2
ADC #$00
STA temp2

LDA temp2
STA scrollUpdateRam,y
INY
LDA temp3
STA scrollUpdateRam,y
INY
LDA tempC
STA scrollUpdateRam,y
INY

LDA temp2
STA scrollUpdateRam,y
INY
LDA temp3
CLC
ADC #$01
STA scrollUpdateRam,y
INY
LDA tempD
STA scrollUpdateRam,y
INY

TYA
STA scrollOffsetCounter
STA maxScrollOffsetCounter


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Turn on update screen on next frame.
LDA updateScreenData
ORA #%0000100
STA updateScreenData
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
RTS
and to clarify where I think the bug resides it's in this part:
TYA
STA scrollOffsetCounter ; <--- the culprit line of code when removed stops the graphical errors but only loads the last unit in postscreenload as a trade-off
STA maxScrollOffsetCounter
so yeah... any advice?

also ignore the fact the units are numbers, just wanted to make it easier for me to debug something else I already solved

UPDATE:
found the script that probably is the one that needs a paint job being -
doUpadateScrollColumn.asm:

;;; This routine will spread over two frames.
;; The offset for where in the column is being drawn will be held in scrollOffsetCounter.
;; It will load 32 (#$20) tiles per frame, but not quite, because the screen is only
;; 240 px high. So there are 3 reads per tile, 12 per metatile...12x15 rows = 180.

LDY scrollOffsetCounter
LDX #$10
loop_LoadScrollColumn:
LDA scrollUpdateRam,y
STA $2006
STA $07FE
INY

LDA scrollUpdateRam,y
STA $2006
STA $07FF
INY

LDA scrollUpdateRam,y
STA $2007
INY
TYA
STA scrollOffsetCounter
CMP maxScrollOffsetCounter ;; this should probably be variable.
BEQ doneUpdatingColumn

DEX
BNE loop_LoadScrollColumn
JMP notDoneUpdatingColumn
doneUpdatingColumn:
LDA updateScreenData
AND #%11111011
STA updateScreenData
LDA scrollByte
AND #%11111110
STA scrollByte
LDA #$00
STA scrollOffsetCounter
notDoneUpdatingColumn:
when I remove this code no PostScreenLoad.asm tiles appear at all so again I think I'm onto something to solve my weird graphics bug

almost got it!
it seems when I remove the top two lines of this routine (which looked odd to me) it mostly fixes it!
LDY scrollOffsetCounter <--- the top two lines
LDX #$10
it seems to eliminate most of the graphical errors!
so it went from this:

tile glitch details.png
to this:
removed top two lines.png
but now the other half of the screen's tile changes are a bit iffy... any thoughts?
 
Last edited:

mouse spirit

Well-known member
Yo! so as you all know I'm working on my Indie NES game currently known as Project Hexagon. But anyway my current issue is when loading the units aka the tile changes during postscreenload.asm
the game while working one hundred percent correctly in gameplay... the graphics bug out hard! here is an example:
View attachment 6769
so yeah... again in postscreenload this happens when loading all these tiles at once for gameplay purposes
here is my tile change macro's (originally made by @dale_coop) subroutine for changing tiles:


and to clarify where I think the bug resides it's in this part:

so yeah... any advice?

also ignore the fact the units are numbers, just wanted to make it easier for me to debug something else I already solved

UPDATE:
found the script that probably is the one that needs a paint job being -
doUpadateScrollColumn.asm:


when I remove this code no PostScreenLoad.asm tiles appear at all so again I think I'm onto something to solve my weird graphics bug

almost got it!
it seems when I remove the top two lines of this routine (which looked odd to me) it mostly fixes it!

it seems to eliminate most of the graphical errors!
so it went from this:

View attachment 6771
to this:
View attachment 6772
but now the other half of the screen's tile changes are a bit iffy... any thoughts?
So those 2 lines are loading what's in y and x,basically. So there might be some saves after that. Try commenting out the saves after that,or even try putting 0's in those load spots.
Because even though you're stopping those loads,something is still loaded into y or x and being saved or used atleast.
 
So those 2 lines are loading what's in y and x,basically. So there might be some saves after that. Try commenting out the saves after that,or even try putting 0's in those load spots.
Because even though you're stopping those loads,something is still loaded into y or x and being saved or used atleast.
thanks for the suggestion... but it didn't work... what did (almost) work however is removing:
LDY scrollOffsetCounter
and keeping:
and it sorta worked? it just didn't load every unit... until I started messing with the LDX and increased it's value higher!
then it kept loading more units... until I set it to...
which made the game glitch out with scrolling vertically out of nowhere
but
works completely fine which loads 6 units total... but I still want to load 10

and yes I know this sounds confusing why the LDX & LDY work that way in doUpdateScrollCollumn... but hey I'm at least most of the way there now

but I would still love a bit more help... anyone?

NEVERMIND!
CutterCross Helped me fix it completely in the Discord!
 
Last edited:
Top Bottom