.SetupViewInNMI PHA ; Store the bitplane flags on the stack so we can ; retrieve them later JSR WaitForPPUToFinish ; Wait until both bitplanes of the screen have been ; sent to the PPU, so the screen is fully updated and ; there is no more data waiting to be sent to the PPU LDA QQ11 ; If the view type in QQ11 is not $96 (Data on System), CMP #$96 ; jump to svin1 to keep checking for view types BNE svin1 ; If we get here then this is the Data on System screen JSR GetSystemBack_b5 ; Fetch the background image for the current system and ; store it in the pattern buffers JMP svin2 ; Jump to svin2 to continue setting up the view .svin1 CMP #$98 ; If the view type in QQ11 is not $98 (Status Mode), BNE svin2 ; jump to svin2 to keep checking for view types ; If we get here then this is the Status Mode screen JSR GetHeadshot_b4 ; Fetch the headshot image for the commander and store ; it in the pattern buffers, starting at pattern number ; picturePattern .svin2 LDA QQ11 ; If bit 6 of the view type is clear, then there is an AND #%01000000 ; icon bar, so jump to svin3 to skip the following BEQ svin3 ; instruction LDA #0 ; There is no icon bar, so set showUserInterface to 0 to STA showUserInterface ; indicate that there is no user interface .svin3 JSR SetupSprite0 ; Set the coordinates of sprite 0 so we can detect when ; the PPU starts to draw the icon bar LDA #0 ; Tell the NMI handler to send nametable entries from STA firstNameTile ; tile 0 onwards LDA #37 ; Tell the NMI handler to send pattern entries from STA firstPattern ; pattern 37 in the buffer LDA firstFreePattern ; Tell the NMI handler to send pattern entries up to the STA lastPattern ; first free pattern, for both bitplanes STA lastPattern+1 LDA #%01010100 ; This instruction has no effect as we are about to pull ; the value of A from the stack LDX #0 ; This instruction has no effect as the call to ; SetDrawPlaneFlags overwrites X with the value of the ; drawing bitplane, though this could be remnants of ; code to set the drawing bitplane to 0, as the ; following code depends on this being the case PLA ; Retrieve the bitplane flags that were passed to this ; routine and which we stored on the stack above JSR SetDrawPlaneFlags ; Set the bitplane flags to A for the current drawing ; bitplane, which must be bitplane 0 at this point ; (though it is not entirely obvious why this is the ; case) INC drawingBitplane ; Increment drawingBitplane to 1 JSR SetDrawPlaneFlags ; Set the bitplane flags to A for bitplane 1 JSR WaitForPPUToFinish ; Wait until both bitplanes of the screen have been ; sent to the PPU, so the screen is fully updated and ; there is no more data waiting to be sent to the PPU LDA #80 ; Tell the PPU to send nametable entries up to tile STA lastNameTile ; 80 * 8 = 640 (i.e. to the end of tile row 19) in both STA lastNameTile+1 ; bitplanes LDA QQ11 ; Set the old view type in QQ11a to the new view type STA QQ11a ; in QQ11, to denote that we have now changed view to ; the view in QQ11 LDA firstFreePattern ; Set clearingPattern for both bitplanes to the number STA clearingPattern ; of the first free pattern, so the NMI handler only STA clearingPattern+1 ; clears patterns from this point onwards ; ; This ensures that the tiles that have already been ; sent to the PPU above don't get cleared out by the NMI ; handler LDA #0 ; Set A = 0, though this has no effect as we don't use ; it LDX #0 ; Hide bitplane 0, so: STX hiddenBitplane ; ; * Colour %01 (1) is the hidden colour (black) ; * Colour %10 (2) is the visible colour (cyan) STX nmiBitplane ; Set nmiBitplane = 0 so bitplane 0 is the first to be ; sent in the NMI handler JSR SetDrawingBitplane ; Set the drawing bitplane to bitplane 0 LDA QQ11 ; If bit 6 of the view type is set, then there is no AND #%01000000 ; icon bar, so jump to svin4 to skip the following BNE svin4 ; instructions JSR WaitForNMI ; Wait until the next NMI interrupt has passed (i.e. the ; next VBlank) LDA #%10000000 ; Set bit 7 of showUserInterface to denote that there is STA showUserInterface ; a user interface .svin4 LDA screenFadedToBlack ; If bit 7 of screenFadedToBlack is clear then the BPL svin5 ; screen is visible and has not been faded to black, so ; jump to svin5 to update the screen without fading it JMP FadeToColour_b3 ; Reverse-fade the screen from black to full colour over ; the next four VBlanks, returning from the subroutine ; using a tail call .svin5 LDA QQ11 ; Set X to the new view type in the low nibble of QQ11 AND #%00001111 TAX LDA paletteForView,X ; Set A to the palette number used by the view from the CMP screenReset ; paletteForView table, compare it to screenReset, set STA screenReset ; the processor flags accordingly, and store the palette ; number in screenReset ; ; This has no effect, as screenReset is not read ; anywhere and neither the value of A nor the processor ; flags are used in the following JSR GetViewPalettes ; Get the palette for the view type in QQ11a and store ; it in a table at XX3 DEC updatePaletteInNMI ; Decrement updatePaletteInNMI to a non-zero value so we ; do send palette data from XX3 to the PPU during NMI, ; which will ensure the screen updates with the colours ; as we fade to black JSR WaitForNMI ; Wait until the next NMI interrupt has passed (i.e. the ; next VBlank) so we know the palette data has been sent ; to the PPU INC updatePaletteInNMI ; Increment updatePaletteInNMI back to the value it had ; before we decremented it above RTS ; Return from the subroutineName: SetupViewInNMI [Show more] Type: Subroutine Category: Drawing the screen Summary: Setup the view and configure the NMI to send both bitplanes to the PPU during VBlank Deep dive: Views and view types in NES EliteContext: See this subroutine in context in the source code References: This subroutine is called as follows: * SetupViewInNMI_b3 calls SetupViewInNMI
This routine is only ever called with the following bitplane flags in A: * Bit 2 clear = send tiles up to configured numbers * Bit 3 clear = don't clear buffers after sending * Bit 4 clear = we've not started sending data yet * Bit 5 clear = we have not yet sent all the data * Bit 6 set = send both pattern and nametable data * Bit 7 set = send data to the PPU Bits 0 and 1 are ignored and are always clear. This routine therefore configures the NMI to send both bitplanes to the PPU.
Arguments: A The bitplane flags to set for the drawing bitplane
[X]
Subroutine FadeToColour_b3 (category: Drawing the screen)
Call the FadeToColour routine in ROM bank 3
[X]
Subroutine GetHeadshot_b4 (category: Status)
Call the GetHeadshot routine in ROM bank 4
[X]
Subroutine GetSystemBack_b5 (category: Universe)
Call the GetSystemBack routine in ROM bank 5
[X]
Subroutine GetViewPalettes (category: Drawing the screen)
Get the palette for the view type in QQ11a and store it in a table at XX3
[X]
Subroutine SetDrawPlaneFlags (category: Drawing the screen)
Set the drawing bitplane flags to the specified value, draw the box edges and set the next free tile number
[X]
Subroutine SetDrawingBitplane (category: Drawing the screen)
Set the drawing bitplane to a specified value
[X]
Subroutine SetupSprite0 (category: PPU)
Set the coordinates of sprite 0 so we can detect when the PPU starts to draw the icon bar
[X]
Subroutine WaitForNMI (category: Utility routines)
Wait until the next NMI interrupt has passed (i.e. the next VBlank)
[X]
Subroutine WaitForPPUToFinish (category: PPU)
Wait until the NMI handler has finished updating both bitplanes, so the screen is no longer refreshing
[X]
Variable clearingPattern in workspace ZP
The number of the first pattern to clear in pattern buffer 0 when the NMI handler clears patterns
[X]
Variable drawingBitplane in workspace ZP
Flipped manually by calling FlipDrawingPlane, controls whether we are showing nametable/palette buffer 0 or 1
[X]
Variable firstFreePattern in workspace ZP
Contains the number of the first free pattern in the pattern buffer that we can draw into next (or 0 if there are no free patterns)
[X]
Variable firstNameTile in workspace ZP
The number of the first tile for which we send nametable data to the PPU in the NMI handler (potentially for both bitplanes, if both are configured to be sent)
[X]
Variable firstPattern in workspace ZP
The number of the first pattern for which we send data to the PPU in the NMI handler (potentially for both bitplanes, if both are configured to be sent)
[X]
Variable lastNameTile in workspace ZP
The number of the last nametable buffer entry to send to the PPU nametable table in the NMI handler for bitplane 0, divided by 8
[X]
Variable lastPattern in workspace ZP
The number of the last pattern entry to send from pattern buffer 0 to bitplane 0 of the PPU pattern table in the NMI handler
[X]
Variable nmiBitplane in workspace ZP
The number of the bitplane (0 or 1) that is currently being processed in the NMI handler during VBlank
[X]
Variable paletteForView (category: Drawing the screen)
Palette numbers for each view
[X]
Variable screenFadedToBlack in workspace WP
Records whether the screen has been faded to black
[X]
Variable screenReset in workspace WP
Gets set to 245 when the screen is reset, but this value is only read once (in SetupViewInNMI) and the value is ignored, so this doesn't have any effect
[X]
Variable showUserInterface in workspace ZP
Bit 7 set means display the user interface (so we only clear it for the game over screen)
[X]
Label svin1 is local to this routine
[X]
Label svin2 is local to this routine
[X]
Label svin3 is local to this routine
[X]
Label svin4 is local to this routine
[X]
Label svin5 is local to this routine
[X]
Variable updatePaletteInNMI in workspace ZP
A flag that controls whether to send the palette data from XX3 to the PPU during NMI