Reset problems and Schrodinger's cat

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

User avatar
battagline
Posts: 152
Joined: Wed Sep 05, 2018 11:13 am
Location: Colorado
Contact:

Reset problems and Schrodinger's cat

Post by battagline »

I'm having a kind of Schrodinger's cat problem with my reset. I have a value that is getting set when the game loads up but doesn't get set when I hit reset. However, if I step through the reset in the Mesen debugger, it gets set and everything works fine.

Any ideas why that would happen?

Thanks
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Reset problems and Schrodinger's cat

Post by dougeff »

reset
In mesen?

Soft reset (reset button) or hard reset (power off and on)?

Do you have "Default power on state for RAM = random" set in Advanced settings?
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
battagline
Posts: 152
Joined: Wed Sep 05, 2018 11:13 am
Location: Colorado
Contact:

Re: Reset problems and Schrodinger's cat

Post by battagline »

dougeff wrote: In mesen?
Yes, in Mesen
dougeff wrote: Soft reset (reset button) or hard reset (power off and on)?
Soft reset through the menu. Hard reset (reloading the file) seems to work fine.
dougeff wrote: Do you have "Default power on state for RAM = random" set in Advanced settings?
In Advanced settings I see "Start game from power on instead of resuming the previous gameplay session", but I'm not sure that's the setting your talking about.

Thanks for your help
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
User avatar
battagline
Posts: 152
Joined: Wed Sep 05, 2018 11:13 am
Location: Colorado
Contact:

Re: Reset problems and Schrodinger's cat

Post by battagline »

I found that setting you were talking about in Emulation. My background gets random tiles dumped into it (thought I was clearing the background but I guess not). That doesn't give me the other problem though
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Reset problems and Schrodinger's cat

Post by dougeff »

No, but that could be a clue that something at startup isn't behaving like you think.

Maybe something isn't getting zeroed, or maybe you aren't waiting enough vblanks before writing to PPU.

Code or .nes file would help.
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
battagline
Posts: 152
Joined: Wed Sep 05, 2018 11:13 am
Location: Colorado
Contact:

Re: Reset problems and Schrodinger's cat

Post by battagline »

dougeff wrote:No, but that could be a clue that something at startup isn't behaving like you think.

Maybe something isn't getting zeroed, or maybe you aren't waiting enough vblanks before writing to PPU.

Code or .nes file would help.
Ok, I'm no longer having an issue with the reset (I don't think). I am having a problem when I try to force a reset when the game is over. I added a

Code: Select all

jmp reset
that gets run when your game is over and you press start. If I step through it in the debugger it works fine. If I don't run the debugger, the game freezes while trying to find the sprite0 collision. It shouldn't hit that part of the code because I have an open screen flag that gets set in the reset code. This seems to happen only if I step through it in the debugger.

I'm attaching the game and the mesen dbg file.

Thanks for your help Doug
Attachments
nesteroids.nes
ROM File
(40.02 KiB) Downloaded 144 times
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
User avatar
battagline
Posts: 152
Joined: Wed Sep 05, 2018 11:13 am
Location: Colorado
Contact:

Re: Reset problems and Schrodinger's cat

Post by battagline »

I had to rename the .dbg file with a .txt extension for some reason
Attachments
nesteroids.nes.dbg.txt
Had to rename this with a .txt extension
(449.7 KiB) Downloaded 142 times
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
User avatar
battagline
Posts: 152
Joined: Wed Sep 05, 2018 11:13 am
Location: Colorado
Contact:

Re: Reset problems and Schrodinger's cat

Post by battagline »

The procedure that calls the reset is "press_start"

Code: Select all

.proc press_start
    lda PRESS_START
    and gamepad_press
    beq skip_press_start
        advance_random_ptr ; advance the random pointer based on the frame

        lda start_delay
        bne skip_press_start
        
        lda open_screen_active
        beq dont_start
            lda #0
            sta open_screen_active
            jsr start_game

            lda #30
            sta start_delay

            jmp start_end
        dont_start:

        lda game_over_active
        beq dont_reset
            lda #30
            sta start_delay
            lda #0
            sta PPU_CTRL

            set nmi_ready, #1 ; I ADDED THIS RECENTLY TO DISABLE THE NMI (IN CASE THAT WAS THE PROBLEM)

            jmp reset ; THIS WORKS IF I START DEBUGGING FROM HERE
        dont_reset:
        ; THE START BUTTON IS PRESSED
        ; start button action
        jmp start_end
    skip_press_start:
        ; if the start is not pressed
    start_end:
    rts
.endproc

Basically I'm trying to trigger a reset when the game is over and the player hits start. I do this with a jmp. I'm not sure if there's a different way to do this, but a soft reset seems to be working now. Now I'm just having an issue triggering the reset from the game over screen
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
User avatar
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: Reset problems and Schrodinger's cat

Post by Banshaku »

I'm just guessing here:

before the reset, you set the PPUCTRL to 0, which disable the NMI. If you had some NMI code that had to be done then it may have stopped processed the thing you were waiting for, like a flag that waits for nmi to continue or things like that.
User avatar
battagline
Posts: 152
Joined: Wed Sep 05, 2018 11:13 am
Location: Colorado
Contact:

Re: Reset problems and Schrodinger's cat

Post by battagline »

Banshaku wrote:I'm just guessing here:

before the reset, you set the PPUCTRL to 0, which disable the NMI. If you had some NMI code that had to be done then it may have stopped processed the thing you were waiting for, like a flag that waits for nmi to continue or things like that.
Thanks for getting back to me.

I don't think that's the issue because initially I didn't have that in there and it was happening. I added that because at first I thought the NMI was coming in and clobbering things or possibly doing something in a half baked state. It didn't fix anything so I'll try it again without the PPUCTRL stuff. Maybe some other changes I made would have fixed it if I hadn't added that code in.

Anyway, I'll give it a quick try just in case.

Thanks again
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
User avatar
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: Reset problems and Schrodinger's cat

Post by Banshaku »

It's is sometime hard to find a issue without looking a the complete code (reset etc) and the only thing that can be done in that case is give opinion on what could be going wrong.

The currently shown code doesn't seems to do anything strange, so calling the "reset", if it is the same one as the one when pressing the reset button, should have restarted it properly. This means there is a good chance that something is going on in the reset code that causes it to freeze. A good guess would be that it is something state related, like a state that occurs when a variable has not been reset properly and cause the game to do something it was not supposed to.

You should review your reset code for such state.
User avatar
battagline
Posts: 152
Joined: Wed Sep 05, 2018 11:13 am
Location: Colorado
Contact:

Re: Reset problems and Schrodinger's cat

Post by battagline »

Banshaku wrote:It's is sometime hard to find a issue without looking a the complete code (reset etc) and the only thing that can be done in that case is give opinion on what could be going wrong.

The currently shown code doesn't seems to do anything strange, so calling the "reset", if it is the same one as the one when pressing the reset button, should have restarted it properly. This means there is a good chance that something is going on in the reset code that causes it to freeze. A good guess would be that it is something state related, like a state that occurs when a variable has not been reset properly and cause the game to do something it was not supposed to.

You should review your reset code for such state.
I'm not sure my code is in a great state for a review right now. The problem seems to be a value in a flag "open_screen_active" that should be getting set at the end of my reset isn't getting set for some reason. However, if I step through the code with the debugger to see why it isn't getting set, it magically gets set and everything works just fine.

I was wondering if doing a jmp reset needs to do something else to make it work. Do I need to do something to clear out the stack? Or does the ldx #$ff and txs near the beginning of my reset work the same if I'm jumping to that code as it would if I hit the reset through the menu system? Since I'm doing the jmp from within a procedure, do I need to worry about it jumping back to the calling procedure when the reset is complete?

I'm mostly looking for some ideas of things to look in to. This has been helpful so far because it's given me some new areas to explore. Unfortunately none of them have been the problem yet.

Is it normal to try and reset the game back to the main menu using a jmp to reset on the game over screen? Or is that a strange thing to do and perhaps I should try a different method of restarting the game?

Thanks for your help
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
Sour
Posts: 891
Joined: Sun Feb 07, 2016 6:16 pm

Re: Reset problems and Schrodinger's cat

Post by Sour »

I can't test at the moment since i don't have access to a computer, but if NMI was causing the problem, it's possible that the code was executing with a different timing due to the debugger being opened? A good way to check would be to use the trace logger and compare both executions to see where they differ (ppu cycle and scanline,etc.) and confirm if NMI had something to do with it.

In general though, the debugger should never affect the execution of the game (if it does, that's a bug)
User avatar
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: Reset problems and Schrodinger's cat

Post by Banshaku »

@battagline

Well, jumping from that part of code to reset, if the stack is reset properly should be fine. As for reset is the "right" way, it may be a matter of preference. I personally prefer to use reset when the machine is powered or reset is pressed. That code just prepare the machine initial state, special settings for mapper etc.

Once this is done, I enter my main loop which decide what to do next. In your case the main loop would "jsr" to the start state and once the "playing" look is over, it would return to the main loop, reset some state and wait what to do next.

Everything is suggestive, there is no best way, just what is easier for you to manage.
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Reset problems and Schrodinger's cat

Post by dougeff »

I had a chance to look at it.

The problem happens when you are holding down the start button while the game is reset. It seems you are checking the start button before something critical is done. (not exactly sure what that 'something' is).

It crashes on a sprite zero hit that never happens.

EDIT - it seems the sprite is in place, but there is no non-transparent tile in place.

EDIT2 - yes. Your title / pre-game code checks for the Start button about 3-4 frames before the Lives / Score and Sprite Zero collision tile are loaded.

On a side note. You might want to make the "lives" lower on the screen. Old CRT TVs will tend to cut off some of those pixels. See the "overscan" entry in the wiki.
nesdoug.com -- blog/tutorial on programming for the NES
Post Reply