Wait for a NMI [?]

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

Moderator: Moderators

Post Reply
User avatar
Zepper
Formerly Fx3
Posts: 3194
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Wait for a NMI [?]

Post by Zepper » Tue Jan 26, 2010 8:16 pm

- AFAIK, the JMP $current_pc is used to wait for a NMI.
- Is there another way? I'd like to improve my NSF player.

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

Post by tepples » Tue Jan 26, 2010 8:51 pm

Here's the handler I use:

Code: Select all

nmi_handler:
  inc nmis
  rti
wait_for_vblank:
  lda nmis
:
  cmp nmis
  beq :-
  rts
'nmis' is a 1-byte variable in an area of RAM into which the NSF itself is forbidden to write.

Drag
Posts: 1314
Joined: Mon Sep 27, 2004 2:57 pm
Contact:

Post by Drag » Wed Jan 27, 2010 11:51 am

Code: Select all

vblank equ [some byte in zp]

NMI
 ~code~
 INC vblank
 ~more code~
 RTI

Wait_For_Vblank
 LDA #$00
 STA vblank
Wait_For_Vblank_Loop
 LDA vblank
 BEQ Wait_For_Vblank_Loop
 RTS
This is how I do it. Obviously not as compact. :P

Wave
Posts: 110
Joined: Mon Nov 16, 2009 5:59 am

Post by Wave » Wed Jan 27, 2010 1:06 pm

My neshla version:

Code: Select all

interrupt.nmi int_nmi() {
	int_nmi_func()
}

function int_nmi_func() {
	ldx #1
	stx inVBlank
...Other code
}

inline int_waitVbl() {
	vid_getPPU_CTRL_1()
	and #CR_NMI
	if(true) {
		do {
			lda inVBlank
		} while(zero)
		lda #0
		sta inVBlank
	} else {
		vblank_wait()
//Call our nmi routine because interrupts are not set
		int_nmi_func()
		unvblank_wait()
	}
}

inline vblank_wait()
{
	do 
		lda PPU.STATUS
	while(is plus)
}

inline unvblank_wait()
{
	do 
		lda PPU.STATUS
	while(is minus)
}

User avatar
Zepper
Formerly Fx3
Posts: 3194
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Post by Zepper » Wed Jan 27, 2010 3:20 pm

- Huh ?? /Bregalad :)

- Well, the forbidden RAM location bothers me. Actually, I use 4018-403F as free space and put my NSF code there. I use C for the sync code; with NMI, I can take it out and use pure ASM.

CartCollector
Posts: 122
Joined: Mon Oct 30, 2006 8:32 pm

Post by CartCollector » Fri Jan 29, 2010 5:18 pm

What's so wrong with having the return from the NMI go to JMP $current_pc if you don't need a frame counter?

Post Reply