It is currently Tue Nov 20, 2018 5:30 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Mon Oct 29, 2018 5:58 pm 
Offline
User avatar

Joined: Wed Sep 05, 2018 11:13 am
Posts: 146
Location: Colorado
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


Top
 Profile  
 
PostPosted: Mon Oct 29, 2018 6:05 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2334
Location: DIGDUG
Quote:
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


Top
 Profile  
 
PostPosted: Mon Oct 29, 2018 6:14 pm 
Offline
User avatar

Joined: Wed Sep 05, 2018 11:13 am
Posts: 146
Location: Colorado
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


Top
 Profile  
 
PostPosted: Mon Oct 29, 2018 6:17 pm 
Offline
User avatar

Joined: Wed Sep 05, 2018 11:13 am
Posts: 146
Location: Colorado
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


Top
 Profile  
 
PostPosted: Mon Oct 29, 2018 6:24 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2334
Location: DIGDUG
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


Top
 Profile  
 
PostPosted: Mon Oct 29, 2018 6:57 pm 
Offline
User avatar

Joined: Wed Sep 05, 2018 11:13 am
Posts: 146
Location: Colorado
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:
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:
File comment: ROM File
nesteroids.nes [40.02 KiB]
Downloaded 28 times

_________________
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
Top
 Profile  
 
PostPosted: Mon Oct 29, 2018 6:59 pm 
Offline
User avatar

Joined: Wed Sep 05, 2018 11:13 am
Posts: 146
Location: Colorado
I had to rename the .dbg file with a .txt extension for some reason


Attachments:
File comment: Had to rename this with a .txt extension
nesteroids.nes.dbg.txt [449.7 KiB]
Downloaded 28 times

_________________
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
Top
 Profile  
 
PostPosted: Mon Oct 29, 2018 7:06 pm 
Offline
User avatar

Joined: Wed Sep 05, 2018 11:13 am
Posts: 146
Location: Colorado
The procedure that calls the reset is "press_start"

Code:
.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


Top
 Profile  
 
PostPosted: Mon Oct 29, 2018 7:46 pm 
Offline
User avatar

Joined: Tue Jun 24, 2008 8:38 pm
Posts: 2056
Location: Fukuoka, Japan
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.


Top
 Profile  
 
PostPosted: Mon Oct 29, 2018 8:11 pm 
Offline
User avatar

Joined: Wed Sep 05, 2018 11:13 am
Posts: 146
Location: Colorado
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


Top
 Profile  
 
PostPosted: Mon Oct 29, 2018 8:22 pm 
Offline
User avatar

Joined: Tue Jun 24, 2008 8:38 pm
Posts: 2056
Location: Fukuoka, Japan
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.


Top
 Profile  
 
PostPosted: Mon Oct 29, 2018 8:33 pm 
Offline
User avatar

Joined: Wed Sep 05, 2018 11:13 am
Posts: 146
Location: Colorado
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


Top
 Profile  
 
PostPosted: Mon Oct 29, 2018 8:52 pm 
Offline

Joined: Sun Feb 07, 2016 6:16 pm
Posts: 526
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)


Top
 Profile  
 
PostPosted: Mon Oct 29, 2018 9:28 pm 
Offline
User avatar

Joined: Tue Jun 24, 2008 8:38 pm
Posts: 2056
Location: Fukuoka, Japan
@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.


Top
 Profile  
 
PostPosted: Tue Oct 30, 2018 6:06 am 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2334
Location: DIGDUG
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group