.NMI JSR SendPaletteSprites ; Send the current palette and sprite data to the PPU LDA showUserInterface ; Set the value of setupPPUForIconBar so that if there STA setupPPUForIconBar ; is an on-screen user interface (which there will be if ; this isn't the game over screen), then the calls to ; the SETUP_PPU_FOR_ICON_BAR macro sprinkled throughout ; the codebase will make sure we set nametable 0 and ; palette table 0 when the PPU starts drawing the icon ; bar IF _NTSC LDA #HI(6797) ; Set cycleCount = 6797 STA cycleCount+1 ; LDA #LO(6797) ; We use this to keep track of how many cycles we have STA cycleCount ; left in the current VBlank, so we only send data to ; the PPU when VBlank is in progress, splitting up the ; larger PPU operations across multiple VBlanks ELIF _PAL LDA #HI(7433) ; Set cycleCount = 7433 STA cycleCount+1 ; LDA #LO(7433) ; We use this to keep track of how many cycles we have STA cycleCount ; left in the current VBlank, so we only send data to ; the PPU when VBlank is in progress, splitting up the ; larger PPU operations across multiple VBlanks ENDIF JSR SendScreenToPPU ; Update the screen by sending the nametable and pattern ; data from the buffers to the PPU, configuring the PPU ; registers accordingly, and clearing the buffers if ; required JSR ReadControllers ; Read the buttons on the controllers and update the ; control variables LDA autoPlayDemo ; If bit 7 of autoPlayDemo is clear then the demo is not BPL inmi1 ; being played automatically, so jump to inmi1 to skip ; the following JSR AutoPlayDemo ; Bit 7 of autoPlayDemo is set, so call AutoPlayDemo to ; automatically play the demo using the controller key ; presses in the autoPlayKeys tables .inmi1 JSR MoveIconBarPointer ; Move the sprites that make up the icon bar pointer and ; record any choices JSR UpdateJoystick ; Update the values of JSTX and JSTY with the values ; from the controller JSR UpdateNMITimer ; Update the NMI timer, which we can use in place of ; hardware timers (which the NES does not support) LDA runningSetBank ; If the NMI handler was called from within the SetBank BNE inmi2 ; routine, then runningSetBank will be $FF, so jump to ; inmi2 to skip the call to MakeSounds JSR MakeSounds_b6 ; Call the MakeSounds routine to make the current sounds ; (music and sound effects) LDA nmiStoreA ; Restore the values of A, X and Y that we stored at LDX nmiStoreX ; the start of the NMI handler LDY nmiStoreY RTI ; Return from the interrupt handler .inmi2 INC runningSetBank ; Increment runningSetBank LDA nmiStoreA ; Restore the values of A, X and Y that we stored at LDX nmiStoreX ; the start of the NMI handler LDY nmiStoreY RTI ; Return from the interrupt handlerName: NMI [Show more] Type: Subroutine Category: Utility routines Summary: The NMI interrupt handler that gets called every VBlank and which updates the screen, reads the controllers and plays music Deep dive: The split-screen mode in NES Elite Drawing vector graphics using NES tiles Auto-playing the combat demoContext: See this subroutine in context in the source code References: This subroutine is called as follows: * Vectors_b0 calls NMI * Vectors_b1 calls NMI * Vectors_b2 calls NMI * Vectors_b3 calls NMI * Vectors_b4 calls NMI * Vectors_b5 calls NMI * Vectors_b6 calls NMI * Vectors_b7 calls NMI
[X]
Subroutine AutoPlayDemo (category: Combat demo)
Automatically play the demo using the auto-play commands from the autoplayKeys tables
[X]
Subroutine MakeSounds_b6 (category: Sound)
Call the MakeSounds routine in ROM bank 6
[X]
Subroutine MoveIconBarPointer (category: Icon bar)
Move the sprites that make up the icon bar pointer and record any choices
[X]
Subroutine ReadControllers (category: Controllers)
Read the buttons on the controllers and update the control variables
[X]
Subroutine SendPaletteSprites (category: Drawing sprites)
Send the current palette and sprite data to the PPU
[X]
Subroutine SendScreenToPPU (category: PPU)
Update the screen with the contents of the buffers
[X]
Subroutine UpdateJoystick (category: Controllers)
Update the values of JSTX and JSTY with the values from the controller
[X]
Subroutine UpdateNMITimer (category: Utility routines)
Update the NMI timer, which we can use to keep track of time for places like the combat demo
[X]
Variable autoPlayDemo in workspace WP
Controls whether to play the demo automatically (which happens after it is left idle for a while)
[X]
Variable cycleCount in workspace ZP
Counts the number of CPU cycles left in the current VBlank in the NMI handler
[X]
Label inmi1 is local to this routine
[X]
Label inmi2 is local to this routine
[X]
Variable runningSetBank in workspace ZP
A flag that records whether we are in the process of switching ROM banks in the SetBank routine when the NMI handler is called
[X]
Variable setupPPUForIconBar in workspace ZP
Controls whether we force the nametable and pattern table to 0 when the PPU starts drawing the icon bar
[X]
Variable showUserInterface in workspace ZP
Bit 7 set means display the user interface (so we only clear it for the game over screen)