diff --git a/demos/sprites/App.Main.s b/demos/sprites/App.Main.s index e789f5f..87ce52e 100644 --- a/demos/sprites/App.Main.s +++ b/demos/sprites/App.Main.s @@ -40,13 +40,13 @@ DOWN_ARROW equ $0A ; Set up our level data jsr BG0SetUp - jsr TileAnimInit +; jsr TileAnimInit ; Allocate room to load data - jsr MovePlayerToOrigin ; Put the player at the beginning of the map +; jsr MovePlayerToOrigin ; Put the player at the beginning of the map ; Add a player sprite - lda #0 ; tile id + lda #32 ; tile id ldx #10 ; x-pos relative to playfield upper-left corner ldy #10 ; y-pos relative to playfield upper-left corner jsl AddSprite @@ -54,8 +54,10 @@ DOWN_ARROW equ $0A lda #DIRTY_BIT_BG0_REFRESH ; Redraw all of the tiles on the next Render tsb DirtyBits - lda #$FFFF +; lda #$FFFF jsl Render + + brl Exit EvtLoop jsl DoTimers jsl Render diff --git a/src/Core.s b/src/Core.s index 77d08ff..f9bd969 100644 --- a/src/Core.s +++ b/src/Core.s @@ -8,7 +8,7 @@ use .\Defs.s ; Feature flags -NO_INTERRUPTS equ 0 ; turn off for crossrunner debugging +NO_INTERRUPTS equ 1 ; turn off for crossrunner debugging NO_MUSIC equ 1 ; turn music + tool loading off ; External data provided by the main program segment @@ -387,6 +387,15 @@ ReadControl ENT put blitter/Template.s put blitter/Tiles.s put blitter/Tiles00000.s +; put blitter/Tiles00001.s +; put blitter/Tiles00010.s +; put blitter/Tiles00011.s +; put blitter/Tiles10000.s +; put blitter/Tiles10001.s +; put blitter/Tiles10010.s +; put blitter/Tiles10011.s +; put blitter/Tiles11000.s + put blitter/TilesBG1.s put blitter/Vert.s put blitter/BG0.s put blitter/BG1.s diff --git a/src/Sprite.s b/src/Sprite.s index 5f57e52..966dee6 100644 --- a/src/Sprite.s +++ b/src/Sprite.s @@ -75,98 +75,18 @@ _RenderSprites lsr lsr lsr - pha -; We have the code field tile that needs to be filled; calculate the address of the corresponding -; location in the sprite plane -; -; Corner_X = -StartXMod164; if < -3, add 164 -; Corner_Y = -StartYMod208; if < -7, add 208 +; Mark the tile as dirty -; lda StartXMod164 -; cmp #4 -; bcc *+5 -; sbc #164 -; eor #$FFFF -; inc -; pha - -; lda StartYMod208 -; cmp #8 -; bcc *+5 -; sbc #208 -; eor #$FFFF -; inc -; clc -; adc #NUM_BUFF_LINES -; xba -; clc -; adc 1,s - -; Copy the tile from the direct page scratch space into the playfield - ply + tay plx - lda #$FFFF ; Sentinel value to pick direct page rendering + jsr _GetTileStoreOffset ; Get the tile store value jsr _PushDirtyTile ; Enqueue for processing -; jsr _CopyBG0Tile +; TODO: Mark adjacent tiles as dirty based on tmp0 and tmp1 values + brl :next -; X = address of sprite _plane -; Y = address of tile -_ComposeSpriteAndTileNoMask - phb - pea #^tiledata - plb - -]line equ 0 - lup 8 - lda: tiledata+{]line*4},y - andl spritemask+{]line*SPRITE_PLANE_SPAN},x - oral spritedata+{]line*SPRITE_PLANE_SPAN},x - sta blttmp+{]line*4} - - lda: tiledata+{]line*4}+2,y - andl spritemask+{]line*SPRITE_PLANE_SPAN}+2,x - oral spritedata+{]line*SPRITE_PLANE_SPAN}+2,x - sta blttmp+{]line*4}+2 - --^ - - plb - plb - rts - -; X = address of sprite plane -; Y = address of tile -_ComposeSpriteAndTileWithMask - phb - pea #^tiledata - plb - - -]line equ 0 - lup 8 - lda: tiledata+{]line*4},y - andl spritemask+{]line*SPRITE_PLANE_SPAN},x - oral spritedata+{]line*SPRITE_PLANE_SPAN},x - sta blttmp+{]line*4} - lda: tiledata+{]line*4}+32,y - andl spritemask+{]line*SPRITE_PLANE_SPAN},x - sta blttmp+{]line*4}+32 - - lda: tiledata+{]line*4}+2,y - andl spritemask+{]line*SPRITE_PLANE_SPAN}+2,x - oral spritedata+{]line*SPRITE_PLANE_SPAN}+2,x - sta blttmp+{]line*4}+2 - lda: tiledata+{]line*4}+32+2,y - andl spritemask+{]line*SPRITE_PLANE_SPAN}+2,x - sta blttmp+{]line*4}+32+2 - --^ - - plb - plb - rts - ; _GetTileAt ; ; Given a relative playfield coordinate [0, ScreenWidth), [0, ScreenHeight) return the @@ -245,8 +165,8 @@ _DrawTileSprite stal spritemask+{]line*256},x ldal spritedata+{]line*SPRITE_PLANE_SPAN},x - ora: tiledata+{]line*4},y and: tiledata+32+{]line*4},y + ora: tiledata+{]line*4},y stal spritedata+{]line*SPRITE_PLANE_SPAN},x lda: tiledata+32+{]line*4}+2,y @@ -254,8 +174,8 @@ _DrawTileSprite stal spritemask+{]line*SPRITE_PLANE_SPAN}+2,x ldal spritedata+{]line*SPRITE_PLANE_SPAN}+2,x - ora: tiledata+{]line*4}+2,y and: tiledata+32+{]line*4}+2,y + ora: tiledata+{]line*4}+2,y stal spritedata+{]line*SPRITE_PLANE_SPAN}+2,x ]line equ ]line+1 --^ diff --git a/src/TileMap.s b/src/TileMap.s index 4457c51..8808188 100644 --- a/src/TileMap.s +++ b/src/TileMap.s @@ -307,7 +307,8 @@ _UpdateBG0TileMap ; X = Tile column (0 - 40) ; Y = Tile row (0 - 25) - pei :BlkX ; cache the starting X-block index to restore later + pha +; pei :BlkX ; cache the starting X-block index to restore later pei :Width ; cache the Width value to restore later :yloop :xloop @@ -335,8 +336,7 @@ _UpdateBG0TileMap ldx :BlkX ldy :BlkY -; jsr _CopyBG0Tile - jsr _PushDirtyTile ; queue this tile for processing + jsr _SetTile ; set the value in the tile store lda :BlkX inc diff --git a/src/blitter/Tiles.s b/src/blitter/Tiles.s index 7fd3493..bf9cd5b 100644 --- a/src/blitter/Tiles.s +++ b/src/blitter/Tiles.s @@ -477,8 +477,9 @@ TILE_STORE_SIZE equ {MAX_TILES*2} ; The tile store contains a tile descri ; TIleStore+TS_CODE_ADDR_LOW : Low word of the address in the code field that receives the tile ; TileStore+TS_CODE_ADDR_HIGH : High word of the address in the code field that receives the tile ; TileStore+TS_WORD_OFFSET : Logical number of word for this location +; TileStore+TS_BASE_ADDR : Copy of BTableAddrLow -TileStore ds TILE_STORE_SIZE*7 +TileStore ds TILE_STORE_SIZE*8 TS_TILE_ID equ TILE_STORE_SIZE*0 TS_DIRTY equ TILE_STORE_SIZE*1 TS_SPRITE_FLAG equ TILE_STORE_SIZE*2 @@ -486,6 +487,7 @@ TS_TILE_ADDR equ TILE_STORE_SIZE*3 ; const value TS_CODE_ADDR_LOW equ TILE_STORE_SIZE*4 ; const value TS_CODE_ADDR_HIGH equ TILE_STORE_SIZE*5 ; const value TS_WORD_OFFSET equ TILE_STORE_SIZE*6 +TS_BASE_ADDR equ TILE_STORE_SIZE*7 ; A list of dirty tiles that need to be updated in a given frame DirtyTileCount ds 2 @@ -494,25 +496,68 @@ DirtyTiles ds TILE_STORE_SIZE ; At most this many tiles can possibly ; Initialize the tile storage data structures. This takes care of populating the tile records with the ; appropriate constant values. _InitDirtyTiles - ldx #TILE_STORE_SIZE-2 ; Initialize the tile backing store with zeros +:col equ tmp0 +:row equ tmp1 -:loop lda #0 - sta TileStore+TS_TILE_ID,x - lda #$FFFF + ldx #TILE_STORE_SIZE-2 ; Initialize the tile backing store with zeros + lda #25 + sta :row + lda #40 + sta :col + +:loop + +; The first set of values in the Tile Store are changed during each frame based on the actions +; that are happening + + stz TileStore+TS_TILE_ID,x ; clear the tile store with the special zero tile + stz TileStore+TS_TILE_ADDR,x + + stz TileStore+TS_SPRITE_FLAG,x ; no sprites are set at the beginning + lda #$FFFF ; none of the tiles are dirty sta TileStore+TS_DIRTY +; The next set of values are constants that are simply used as cached parameters to avoid needing to +; calculate any of these values during tile rendering + + lda :row ; Set the long address of where this tile + asl ; exists in the code fields + tay + lda BRowTableHigh,y + sta TileStore+TS_CODE_ADDR_HIGH,x ; High word of the tile address (just the bank) + lda BRowTableLow,y + sta TileStore+TS_BASE_ADDR,x ; May not be needed later if we can figure out the right constant... + + lda :col ; Set the offset values based on the column + asl ; of this tile + asl + sta TileStore+TS_WORD_OFFSET,x ; This is the offset from 0 to 82, used in LDA (dp),y instruction + + tay + lda Col2CodeOffset+2,y + clc + adc TileStore+TS_BASE_ADDR,x + sta TileStore+TS_CODE_ADDR_LOW,x ; Low word of the tile address in the code field + + dec :col + bpl :hop + dec :row + lda #40 + sta :col +:hop + dex dex bpl :loop rts _ClearDirtyTiles + bra :hop :loop - lda DirtyTileCount - beq :done jsr _PopDirtyTile - bra :loop -:done +:hop + lda DirtyTileCount + bne :loop rts ; Helper function to get the address offset into the tile cachce / tile backing store @@ -588,10 +633,7 @@ _PushDirtyTile inx inx stx DirtyTileCount ; Commit - rts - :occupied - ply rts ; Remove a dirty tile from the list and return it in state ready to be rendered. It is important @@ -611,7 +653,7 @@ _PopDirtyTile2 ; alternate entry point ldy DirtyTiles,x ; load the offset into the Tile Store lda #$FFFF - sta DirtyTileCache,y ; clear the occupied backlink + sta TileStore+TS_DIRTY,y ; clear the occupied backlink rts ; Run through the dirty tile list and render them into the code field diff --git a/src/blitter/TilesBG1.s b/src/blitter/TilesBG1.s index caadbe8..5345830 100644 --- a/src/blitter/TilesBG1.s +++ b/src/blitter/TilesBG1.s @@ -1,4 +1,3 @@ - _TBSolidBG1_00 ]line equ 0 lup 8