2021-07-08 12:46:35 +00:00
|
|
|
; Renders a frame of animation
|
|
|
|
;
|
|
|
|
; The rendering engine is built around the idea of compositing all of the moving components
|
|
|
|
; on to the Bank 01 graphics buffer and then revealing everything in a single, vertical pass.
|
|
|
|
;
|
|
|
|
; If there was just a scrolling screen with no sprites, the screen would just get rendered
|
|
|
|
; in a single pass, but it gets more complicated with sprites and various effects.
|
|
|
|
;
|
|
|
|
; Here is the high-level pipeline:
|
|
|
|
;
|
|
|
|
; 1. Identify row ranges with effects. These effects can be sprites or user-defined overlays
|
|
|
|
; 2. Turn shadowing off
|
|
|
|
; 3. Render the background for each effect row range (in any order)
|
|
|
|
; 4. Render the sprites (in any order)
|
|
|
|
; 5. Turn shadowing on
|
|
|
|
; 6. Render the background for each non-effect row, a pei slam for sprite rows, and
|
|
|
|
; the user-defined overlays (in sorted order)
|
|
|
|
;
|
|
|
|
; As a concrete example, consider:
|
|
|
|
;
|
|
|
|
; Rows 0 - 9 have a user-defined floating overlay for a score board
|
|
|
|
; Rows 10 - 100 are background only
|
|
|
|
; Rows 101 - 120 have one or more sprites
|
|
|
|
; Rows 121 - 140 are background only
|
|
|
|
; Rows 141 - 159 have a user-defined solid overlay for an animated platform
|
|
|
|
;
|
|
|
|
; A floating overlay means that some background data bay show through. A solid overlay means that
|
|
|
|
; the user-defined data covers the entire scan line.
|
|
|
|
;
|
|
|
|
; The renderer would proceed as:
|
|
|
|
;
|
|
|
|
; - shadow off
|
|
|
|
; - render_background(0, 10)
|
|
|
|
; - render_background(101, 121)
|
|
|
|
; - render_sprites()
|
|
|
|
; - shadow_on
|
|
|
|
; - render_user_overlay_1()
|
|
|
|
; - render_background(10, 101)
|
|
|
|
; - pei_slam(101, 121)
|
|
|
|
; - render_background(121, 141)
|
|
|
|
; - render_user_overlay_2()
|
|
|
|
;
|
|
|
|
; Generally speaking, a PEI Slam is faster that trying to do any sort of dirty-rectangle update by
|
|
|
|
; tracking sprinte bounding boxes. But, if an application would benefit from skipping some background
|
|
|
|
; drawing on sprite rows, that can be handled by using the low level routines to control the left/right
|
|
|
|
; edges of the rendered play field.
|
|
|
|
|
|
|
|
|
2021-07-09 19:18:49 +00:00
|
|
|
; The render function is the point of committment -- most of the APIs that set sprintes and
|
|
|
|
; update coordinates are lazy; they simply save the value and set a dirty flag in the
|
|
|
|
; DirtyBits word.
|
|
|
|
;
|
|
|
|
; This function examines the dirty bits and actually performs the work to update the code field
|
|
|
|
; and internal data structure to properly render the play field. Then the update pipeline is
|
|
|
|
; executed.
|
2021-08-25 14:38:02 +00:00
|
|
|
Render ENT
|
|
|
|
phb
|
|
|
|
phk
|
|
|
|
plb
|
|
|
|
jsr _Render
|
|
|
|
plb
|
|
|
|
rtl
|
2021-07-09 20:38:32 +00:00
|
|
|
|
|
|
|
; TODO -- actually check the dirty bits and be selective on what gets updated. For example, if
|
|
|
|
; only the Y position changes, then we should only need to set new values on the
|
|
|
|
; virtual lines that were brought on screen. If the X position only changes by one
|
|
|
|
; byte, then we may have to change the CODE_ENTRY values or restore/set new OPCODE
|
|
|
|
; values, but not both.
|
|
|
|
|
2021-07-18 02:00:46 +00:00
|
|
|
; It's important to do _ApplyBG0YPos first because it calculates the value of StartY % 208 which is
|
|
|
|
; used in all of the other loops
|
2021-08-25 14:38:02 +00:00
|
|
|
_Render
|
2021-07-09 20:38:32 +00:00
|
|
|
jsr _ApplyBG0YPos ; Set stack addresses for the virtual lines to the physical screen
|
2021-08-19 06:22:36 +00:00
|
|
|
jsr _ApplyBG1YPos
|
2021-08-06 19:42:18 +00:00
|
|
|
|
|
|
|
; _ApplyBG0Xpos need to be split because we have to set the offsets, then draw in any updated tiles, and
|
|
|
|
; finally patch out the code field. Right now, the BRA operand is getting overwritten by tile data.
|
|
|
|
jsr _ApplyBG0XPosPre
|
2021-08-19 06:22:36 +00:00
|
|
|
jsr _ApplyBG1XPosPre
|
2021-08-06 19:42:18 +00:00
|
|
|
|
2021-10-31 20:42:59 +00:00
|
|
|
jsr _RenderSprites ; Once the BG0 X and Y positions are committed, update sprite data
|
|
|
|
|
2021-10-21 13:50:07 +00:00
|
|
|
jsr _UpdateBG0TileMap ; and the tile maps. These subroutines build up a list of tiles
|
|
|
|
jsr _UpdateBG1TileMap ; that need to be updated in the code field
|
2021-08-06 19:42:18 +00:00
|
|
|
|
2021-10-21 13:50:07 +00:00
|
|
|
jsr _ApplyTiles ; This function actually draws the new tiles into the code field
|
2021-07-09 20:38:32 +00:00
|
|
|
|
2021-10-21 13:50:07 +00:00
|
|
|
jsr _ApplyBG0XPos ; Patch the code field instructions with exit BRA opcode
|
|
|
|
jsr _ApplyBG1XPos ; Update the direct page value based on the horizontal position
|
|
|
|
|
|
|
|
; The code fields are locked in now and ready to be rendered
|
2021-07-20 03:42:51 +00:00
|
|
|
|
2021-10-06 12:10:09 +00:00
|
|
|
jsr _ShadowOff
|
2021-07-20 03:42:51 +00:00
|
|
|
|
2021-10-31 00:24:23 +00:00
|
|
|
; Shadowing is turned off. Render all of the scan lines that need a second pass. One
|
|
|
|
; optimization that can be done here is that the lines can be rendered in any order
|
|
|
|
; since it is not shown on-screen yet.
|
2021-10-21 13:50:07 +00:00
|
|
|
|
2021-11-15 18:23:38 +00:00
|
|
|
; ldx #0 ; Blit the full virtual buffer to the screen
|
|
|
|
; ldy #8
|
|
|
|
; jsr _BltRange
|
2021-10-21 13:50:07 +00:00
|
|
|
|
|
|
|
; Turn shadowing back on
|
2021-07-20 03:42:51 +00:00
|
|
|
|
2021-10-06 12:10:09 +00:00
|
|
|
jsr _ShadowOn
|
2021-07-20 03:42:51 +00:00
|
|
|
|
2021-10-21 13:50:07 +00:00
|
|
|
; Now render all of the remaining lines in top-to-bottom (or bottom-to-top) order
|
|
|
|
|
2021-11-14 01:45:27 +00:00
|
|
|
lda ScreenY0 ; pass the address of the first line of the overlay
|
|
|
|
clc
|
|
|
|
adc #0
|
|
|
|
asl
|
|
|
|
tax
|
|
|
|
lda ScreenAddr,x
|
|
|
|
clc
|
|
|
|
adc ScreenX0
|
2021-11-15 18:23:38 +00:00
|
|
|
; jsl Overlay
|
2021-10-31 00:24:23 +00:00
|
|
|
|
2021-11-15 18:23:38 +00:00
|
|
|
ldx #0 ; Blit the full virtual buffer to the screen
|
2021-07-09 20:38:32 +00:00
|
|
|
ldy ScreenHeight
|
|
|
|
jsr _BltRange
|
|
|
|
|
2021-11-21 02:33:27 +00:00
|
|
|
; ldx #0
|
|
|
|
; ldy ScreenHeight
|
|
|
|
; jsr _BltSCB
|
2021-11-15 18:23:38 +00:00
|
|
|
|
2021-07-09 20:38:32 +00:00
|
|
|
lda StartY ; Restore the fields back to their original state
|
|
|
|
ldx ScreenHeight
|
|
|
|
jsr _RestoreBG0Opcodes
|
|
|
|
|
2021-08-10 12:59:14 +00:00
|
|
|
lda StartY
|
|
|
|
sta OldStartY
|
|
|
|
lda StartX
|
|
|
|
sta OldStartX
|
|
|
|
|
2021-08-19 06:22:36 +00:00
|
|
|
lda BG1StartY
|
|
|
|
sta OldBG1StartY
|
|
|
|
lda BG1StartX
|
|
|
|
sta OldBG1StartX
|
|
|
|
|
2021-08-10 12:59:14 +00:00
|
|
|
stz DirtyBits
|
2021-07-08 12:46:35 +00:00
|
|
|
rts
|