Page 1 of 1

Wait for a NMI [?]

Posted: Tue Jan 26, 2010 8:16 pm
by Zepper
- AFAIK, the JMP $current_pc is used to wait for a NMI.
- Is there another way? I'd like to improve my NSF player.

Posted: Tue Jan 26, 2010 8:51 pm
by tepples
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.

Posted: Wed Jan 27, 2010 11:51 am
by Drag

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

Posted: Wed Jan 27, 2010 1:06 pm
by Wave
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)
}

Posted: Wed Jan 27, 2010 3:20 pm
by Zepper
- 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.

Posted: Fri Jan 29, 2010 5:18 pm
by CartCollector
What's so wrong with having the return from the NMI go to JMP $current_pc if you don't need a frame counter?