Why must VECTORS be direct?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

Why must VECTORS be direct?

Post by calima »

I wanted to put my IRQ handler in a separate file, so in crt0.s I put "import irq" at the top, and "export irq" at the top of the separate file. The resulting ROM did not boot.

Then I renamed it, and put a stub in crt0.s:

Code: Select all

irq:
    jmp myirq
This worked. Can anyone explain why the imported function did not work?
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Why must VECTORS be direct?

Post by tepples »

When I see something that won't boot, I usually open the ROM in a debugging emulator and put a breakpoint somewhere. If you suspect that the IRQ handler may be at fault, put the breakpoint at the start of the IRQ handler.

Unfortunately, the most popular debugging emulators use either 32-bit Wine (FCEUX) or Mono (Mesen) rather than Qt, GTK+, or SDL. If you lack the space to install the libraries needed to run 32-bit or CLR executables, you could check the FCEUX (SDL) source code out of FCEUX SVN and add an execution logging feature that writes each executed instruction to a file. Or have you tried building NESICIDE?
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

Re: Why must VECTORS be direct?

Post by calima »

The irq handler consists of a single "rti".
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Why must VECTORS be direct?

Post by tepples »

In order to guess the cause without access to a debugger, such as a bug that occurs only on hardware and not in a debugging emulator, I would need to see the rti in context. In particular, what is the source of this IRQ? Is it something that needs a few cycles to self-acknowledge? Which mapper is this program using? Or are you instead using the APU Frame Counter IRQ or DMC IRQ, which are built into the CPU? These need to be acknowledged explicitly or they'll just recur.
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

Re: Why must VECTORS be direct?

Post by calima »

Well, this was my mistake. When I removed the irq handler from neslib,

Code: Select all

irq: rti
I didn't see it was also used as the NMI's end rti, being separated by several newlines from the nmi code. Neslib and its optimized ways, sigh.

So, without its end rti, the NMI continued to random code, reaching a rts, wrapping around the stack and jumping to random places.
Post Reply