Hooking a function to NMI in c (cc65)

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

Moderator: Moderators

Post Reply
User avatar
Petruza
Posts: 311
Joined: Mon Dec 22, 2008 10:45 pm
Location: Argentina

Hooking a function to NMI in c (cc65)

Post by Petruza »

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)

Code: Select all

unsigned char counter;

void func()
{ ++counter; }

void main()
{
	counter = 0;		
	// *( (unsigned char*) 0xFFFA ) = (unsigned char*) func;	
	asm( "lda %v", func );
	asm( "sta $FFFA" );
} 
Thanks!
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

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.
Post Reply