How to debug a nes crash?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

adam_smasher
Posts: 271
Joined: Sun Mar 27, 2011 10:49 am
Location: Seattle

Re: How to debug a nes crash?

Post by adam_smasher » Thu Feb 04, 2016 2:20 pm

I would rather use Windows than try to write an NES game without a debugger :|

If it works repeatedly at the beginning of the game

and crashes every time at the end of the level

then something happens during gameplay that causes the crash

(in particular, some global state (either in memory or in the hardware) is changed)

If you know it happens during ppu_on_all(), then you know that the
correct behaviour of ppu_on_all() depends on the the global state that is
changed during gameplay

What does ppu_on_all() look like?

tepples
Posts: 21752
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: How to debug a nes crash?

Post by tepples » Thu Feb 04, 2016 3:08 pm

calima wrote:
tepples wrote:Unless you're using Linux on a non-x86 platform, you can do what I did: sudo apt-get install wine and then use the Windows version.
Pure 64-bit, so Wine is not a possibility.
Then go impure (that is, multi-arch) with i386 and amd64. Or install a VM and run 32-bit Linux and Wine in the VM. Or buy a copy of Windows to use on another computer, compile FCEUX for Windows in 64-bit mode, and run that in 64-bit Wine.

User avatar
GradualGames
Posts: 1107
Joined: Sun Nov 09, 2008 9:18 pm
Location: Pennsylvania, USA
Contact:

Re: How to debug a nes crash?

Post by GradualGames » Thu Feb 04, 2016 3:13 pm

Something's gotta be stepping on something. While I was experimenting with C, I could swear I got into a situation once where something was mysteriously stepping on a zp variable of mine. It made me wonder at one point if the linker configuration was set up so that my zp variables actually shared space with cc65's zp space. I never found out what that particular problem was as that bug just hid after a while. With 6502, I've been able to consistently find the root cause of bugs throughout the deveopment of each game (and know for sure it was my own code...the assembler itself only caused trouble in 3 instances I can recall and were minor problems)---something I can't say for any other language I've worked with (sometimes a workaround is the only thing you can find in the face of immense complexity).

lidnariq
Posts: 8786
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: How to debug a nes crash?

Post by lidnariq » Thu Feb 04, 2016 3:24 pm

tepples wrote:Then go impure (that is, multi-arch) with i386 and amd64. Or install a VM and run 32-bit Linux and Wine in the VM.
Or debootstrap yourself a 32-bit chroot and use schroot.

User avatar
dougeff
Posts: 2616
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: How to debug a nes crash?

Post by dougeff » Thu Feb 04, 2016 3:53 pm

Maybe you could just post the Source Code and/or the ROM, and one of the people here can look at it with a debugger.

(And if cc65 source code, please indicate what version of cc65 you use).

Or perhaps, buy a $20 used windows laptop from ebay.
nesdoug.com -- blog/tutorial on programming for the NES

Rahsennor
Posts: 475
Joined: Thu Aug 20, 2015 3:09 am

Re: How to debug a nes crash?

Post by Rahsennor » Thu Feb 04, 2016 5:22 pm

The Debian version of mednafen has a debugger. It has a really obtuse interface, but it's something.

User avatar
tokumaru
Posts: 11466
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: How to debug a nes crash?

Post by tokumaru » Thu Feb 04, 2016 5:27 pm

Not having a debugger at your disposal is crazy, solving bugs will take you 10 times longer if you have to keep guessing where the problem is... Come on, just install VirtualBox and a 200MB stripped down version of XP so you can do things properly.

Rahsennor
Posts: 475
Joined: Thu Aug 20, 2015 3:09 am

Re: How to debug a nes crash?

Post by Rahsennor » Thu Feb 04, 2016 5:54 pm

I know I'm being completely unhelpful here, but I find it depressing that the answer to "how to debug a NES game on Linux" is "use Windows".

Seriously though, why is the Linux port of FCEUX so pathetic?

User avatar
rainwarrior
Posts: 7677
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: How to debug a nes crash?

Post by rainwarrior » Thu Feb 04, 2016 5:59 pm

Rahsennor wrote:Seriously though, why is the Linux port of FCEUX so pathetic?
You act like this is some sort of professional project. The reason is obvious: nobody is sufficiently interested to do it for free.

If it's something you care about, why not contribute to the project yourself?

Rahsennor
Posts: 475
Joined: Thu Aug 20, 2015 3:09 am

Re: How to debug a nes crash?

Post by Rahsennor » Thu Feb 04, 2016 6:49 pm

I was not intending to act like it was a professional project, and you're right that the answer is obvious. I should have kept my mouth shut.

User avatar
rainwarrior
Posts: 7677
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: How to debug a nes crash?

Post by rainwarrior » Thu Feb 04, 2016 7:32 pm

Sorry, I didn't want to admonish you for speaking about it; what I was trying to do (perhaps with too bitter a tone) was encourage you to join the FCEUX project and help bring it up to snuff.

tepples
Posts: 21752
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: How to debug a nes crash?

Post by tepples » Thu Feb 04, 2016 8:39 pm

Rahsennor wrote:I find it depressing that the answer to "how to debug a NES game on Linux" is "use Windows".
No, it's "use Wine". That works for NES (FCEUX), and it works for Super NES (NO$SNS).
Seriously though, why is the Linux port of FCEUX so pathetic?
Is it necessarily more pathetic than wanting to adhere to some standard of 64-bit purity?

calima
Posts: 1018
Joined: Tue Oct 06, 2015 10:16 am

Re: How to debug a nes crash?

Post by calima » Fri Feb 05, 2016 2:32 am

tepples wrote:Is it necessarily more pathetic than wanting to adhere to some standard of 64-bit purity?
And waste several gigs? I have better use for that space.

To the people telling me to pirate or pay for Windows, screw you. That is never the solution, it's a problem.
(in particular, some global state (either in memory or in the hardware) is changed)
I know, but there is no such state change in my code. So it must be a compiler bug, which is rather hard to track. If the cc65 stack underflows, it scribbles on the 0x2000 registers, if the hw stack overflows, it scribbles on ZP vars.
What does ppu_on_all() look like?

Code: Select all

;void __fastcall__ ppu_on_all(void);

_ppu_on_all:

        lda <PPU_MASK_VAR
        ora #%00011000

ppu_onoff:

        sta <PPU_MASK_VAR
        jmp _ppu_wait_nmi
While I was experimenting with C, I could swear I got into a situation once where something was mysteriously stepping on a zp variable of mine
They are allocated the same, so that was a bug in the compiler (or the standard library, if you used it).
dougeff wrote:Maybe you could just post the Source Code and/or the ROM, and one of the people here can look at it with a debugger.

(And if cc65 source code, please indicate what version of cc65 you use).
I use cc65 from git master. Will post the ROM in a bit.
No, it's "use Wine". That works for NES (FCEUX), and it works for Super NES (NO$SNS).
I won't use closed-source software on principle. Yes, fceux Windows would be open source, but that's a huge waste of both time and disk space.

I'm thinking about building fceux with debug symbols, finding where it keeps the RAM, and setting watches by debugging the emulator on the host. Crazy, but far less crazy than installing Windows.

calima
Posts: 1018
Joined: Tue Oct 06, 2015 10:16 am

Re: How to debug a nes crash?

Post by calima » Fri Feb 05, 2016 4:02 am

ROM link:
https://u.pomf.is/vstins.gz

Wait a second or two and press select.

User avatar
cpow
NESICIDE developer
Posts: 1089
Joined: Mon Oct 13, 2008 7:55 pm
Location: Minneapolis, MN
Contact:

Re: How to debug a nes crash?

Post by cpow » Fri Feb 05, 2016 6:07 am

calima wrote:AFAIK no emulator for Linux supports any debugging, though I've only tried the most popular ones. That's making this quite hard.
NESICIDE does. But it's been *forever* since I built and provided a Linux binary. Not that it won't work. Just will take me a little bit to get my Linux VM back.

Post Reply