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

Wait for a NMI [?]

Wait for a NMI [?]
by on (#55743)
- AFAIK, the JMP $current_pc is used to wait for a NMI.
- Is there another way? I'd like to improve my NSF player.

by on (#55745)
Here's the handler I use:
Code:
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.

by on (#55777)
Code:
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

by on (#55781)
My neshla version:
Code:
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)
}

by on (#55789)
- 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.

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