This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Hooking a function to NMI in c (cc65)

Hooking a function to NMI in c (cc65)
by on (#41267)
Hi, I'm trying to hook my func() to the NMI interrupt. I know I can detect vertical blanks in other ways, but I'd like to know if I can do it this way.

Does someone know if this is possible in c? Am I doing something wrong?

I wrote this code, but counter doesn't ever get incremented. The commented line was my attempt to do it in pure c but it didn't work either.
(only significant code is pasted here)
unsigned char counter;

void func()
{ ++counter; }

void main()
   counter = 0;      
   // *( (unsigned char*) 0xFFFA ) = (unsigned char*) func;   
   asm( "lda %v", func );
   asm( "sta $FFFA" );


by on (#41268)
All known mappers put ROM, not RAM, at $FFFA. Writing to ROM doesn't change its contents; all it does is issue commands to the mapper. As I understand it, you'll need to read the source code of cc65's implementation of the C library to understand what's going on.