sta/sty randomly not working?

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
Spronk
Posts: 2
Joined: Tue Jan 11, 2022 8:28 am

sta/sty randomly not working?

Post by Spronk »

I'm not sure why, but a piece of my code just doesn't seem to work.

Code: Select all

	ldy #$00
loadActor:
	lda actorList, y
	sta currentactor, y
	iny
	cmp #$07
	bne loadActor

	ldx currentactor+4
	ldy #$00
	lda #$02
	sta currentsprite
	sty currentsprite+1
actorList is just a data label in the code segment I'm using for testing purposes. currentactor and currentsprite are two zeropage variable, with 7 and 2 bytes reserved respectively.

For the first part of loadActor, it works fine, and whatever needs to be written to actorList is written. However, when trying to store a constant value in currentsprite, it just doesn't get written. What is going wrong here?
Joe
Posts: 650
Joined: Mon Apr 01, 2013 11:17 pm

Re: sta/sty randomly not working?

Post by Joe »

Maybe that CMP should be CPY.
Spronk
Posts: 2
Joined: Tue Jan 11, 2022 8:28 am

Re: sta/sty randomly not working?

Post by Spronk »

Joe wrote: Mon Jan 24, 2022 12:08 pm Maybe that CMP should be CPY.
That... worked. I've been dealing with the problem for multiple days and it was that simple a fix. I am an idiot, thank you so much.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: sta/sty randomly not working?

Post by unregistered »

hi Spronk,

It seems this fix would have been obvious if you had been using a debugger, like Mesen’s debugger. :)

Mesen is a great emulator; its Debugger window is really excellent; has current values of each register displayed, like every other debugger, at its top. Stepping through this code, one instruction at a time, would be a great way to solve these problems.

I recommend Mesen. :) Find the Mesen thread in theEMU part of this forum and then find the latest released version by mkwong98. Sour is no longer making it, but the newest released version is tons better than Sour’s version 0.9.9.0 (0.9.9.0, by Sour, is the most recent original-version currently available… Sour made many super helpful edits past 0.9.9.0, but those are only available now in 3rd party releases like mkwong98’s).
Post Reply