2022-05-19 02:00:06 +00:00
; Tile storage parameters
TILE_ D A T A _ S P A N e q u 4
TILE_ S T O R E _ W I D T H e q u 4 1
TILE_ S T O R E _ H E I G H T e q u 2 6
MAX_ T I L E S e q u { 2 6 * 4 1 } ; Number of tiles in the code field (41 columns * 26 rows)
TILE_ S T O R E _ S I Z E e q u { M A X _ T I L E S * 2 } ; The tile store contains a tile descriptor in each slot
TS_ T I L E _ I D e q u T I L E _ S T O R E _ S I Z E * 0 ; tile descriptor for this location
TS_ D I R T Y e q u T I L E _ S T O R E _ S I Z E * 1 ; Flag. Used to prevent a tile from being queued multiple times per frame
TS_ S P R I T E _ F L A G e q u T I L E _ S T O R E _ S I Z E * 2 ; Bitfield of all sprites that intersect this tile. 0 if no sprites.
TS_ T I L E _ A D D R e q u T I L E _ S T O R E _ S I Z E * 3 ; cached value, the address of the tiledata for this tile
TS_ C O D E _ A D D R _ L O W e q u T I L E _ S T O R E _ S I Z E * 4 ; const value, address of this tile in the code fields
TS_ C O D E _ A D D R _ H I G H e q u T I L E _ S T O R E _ S I Z E * 5
TS_ W O R D _ O F F S E T e q u T I L E _ S T O R E _ S I Z E * 6 ; const value, word offset value for this tile if LDA (dp),y instructions re used
TS_ B A S E _ A D D R e q u T I L E _ S T O R E _ S I Z E * 7 ; const value, because there are two rows of tiles per bank, this is set to $0000 ot $8000.
TS_ S C R E E N _ A D D R e q u T I L E _ S T O R E _ S I Z E * 8 ; cached value of on-screen location of tile. Used for DirtyRender.
2022-06-01 18:55:04 +00:00
; TODO: Move these arrays into the K bank to support direct dispatch via jmp (abs,x)
2022-05-19 02:00:06 +00:00
TS_ B A S E _ T I L E _ C O P Y e q u T I L E _ S T O R E _ S I Z E * 9 ; derived from TS_TILE_ID to optimize tile copy to support sprite rendering
TS_ B A S E _ T I L E _ D I S P e q u T I L E _ S T O R E _ S I Z E * 1 0 ; derived from TS_TILE_ID to optimize base (non-sprite) tile dispatch in the Render function
TS_ D I R T Y _ T I L E _ D I S P e q u T I L E _ S T O R E _ S I Z E * 1 1 ; derived from TS_TILE_ID to optimize dirty tile dispatch in the Render function
2022-05-31 13:43:26 +00:00
TILE_ S T O R E _ N U M e q u 1 2 ; Need this many parallel arrays
2022-05-19 02:00:06 +00:00
; Sprite data structures. We cache quite a few pieces of information about the sprite
; to make calculations faster, so this is hidden from the caller.
MAX_ S P R I T E S e q u 1 6
2022-05-31 13:43:26 +00:00
SPRITE_ R E C _ S I Z E e q u 4 2
2022-05-19 02:00:06 +00:00
; Mark each sprite as ADDED, UPDATED, MOVED, REMOVED depending on the actions applied to it
; on this frame. Quick note, the same Sprite ID cannot be removed and added in the same frame.
; A REMOVED sprite if removed from the sprite list during the Render call, so it's ID is not
; available to the AddSprite function until the next frame.
SPRITE_ S T A T U S _ E M P T Y e q u $ 0 0 0 0 ; If the status value is zero, this sprite slot is available
SPRITE_ S T A T U S _ O C C U P I E D e q u $ 8 0 0 0 ; Set the MSB to flag it as occupied
SPRITE_ S T A T U S _ A D D E D e q u $ 0 0 0 1 ; Sprite was just added (new sprite)
SPRITE_ S T A T U S _ M O V E D e q u $ 0 0 0 2 ; Sprite's position was changed
SPRITE_ S T A T U S _ U P D A T E D e q u $ 0 0 0 4 ; Sprite's non-position attributes were changed
SPRITE_ S T A T U S _ R E M O V E D e q u $ 0 0 0 8 ; Sprite has been removed.
2022-05-27 00:36:40 +00:00
; These values are set by the user
SPRITE_ S T A T U S e q u { M A X _ S P R I T E S * 0 }
SPRITE_ I D e q u { M A X _ S P R I T E S * 2 }
SPRITE_ X e q u { M A X _ S P R I T E S * 4 }
SPRITE_ Y e q u { M A X _ S P R I T E S * 6 }
2022-06-01 18:55:04 +00:00
VBUFF_ A D D R e q u { M A X _ S P R I T E S * 8 } ; Base address of the sprite's stamp in the data/mask banks
2022-05-27 00:36:40 +00:00
; These values are cached / calculated during the rendering process
TS_ L O O K U P _ I N D E X e q u { M A X _ S P R I T E S * 1 0 } ; The index from the TileStoreLookup table that corresponds to the top-left corner of the sprite
TS_ C O V E R A G E _ S I Z E e q u { M A X _ S P R I T E S * 1 2 } ; Representation of how many TileStore tiles (NxM) are covered by this sprite
OLD_ T S _ L O O K U P _ I N D E X e q u { M A X _ S P R I T E S * 1 4 } ; Copy of the values to support diffing
OLD_ T S _ C O V E R A G E _ S I Z E e q u { M A X _ S P R I T E S * 1 6 }
SPRITE_ D I S P e q u { M A X _ S P R I T E S * 1 8 } ; Cached address of the specific stamp based on sprite flags
SPRITE_ C L I P _ L E F T e q u { M A X _ S P R I T E S * 2 0 }
SPRITE_ C L I P _ R I G H T e q u { M A X _ S P R I T E S * 2 2 }
SPRITE_ C L I P _ T O P e q u { M A X _ S P R I T E S * 2 4 }
SPRITE_ C L I P _ B O T T O M e q u { M A X _ S P R I T E S * 2 6 }
IS_ O F F _ S C R E E N e q u { M A X _ S P R I T E S * 2 8 }
SPRITE_ W I D T H e q u { M A X _ S P R I T E S * 3 0 }
SPRITE_ H E I G H T e q u { M A X _ S P R I T E S * 3 2 }
SPRITE_ C L I P _ W I D T H e q u { M A X _ S P R I T E S * 3 4 }
SPRITE_ C L I P _ H E I G H T e q u { M A X _ S P R I T E S * 3 6 }
TS_ V B U F F _ B A S E e q u { M A X _ S P R I T E S * 3 8 } ; Finalized VBUFF address based on the sprite position and tile offsets
2022-05-31 13:43:26 +00:00
VBUFF_ A R R A Y _ A D D R e q u { M A X _ S P R I T E S * 4 0 } ; Fixed address where this sprite's VBUFF addresses are stores. The array is the same shape as TileStore, but much smaller
2022-05-27 00:36:40 +00:00
;TILE_DATA_OFFSET equ {MAX_SPRITES*2}
;TILE_STORE_ADDR_1 equ {MAX_SPRITES*12}
;TILE_STORE_ADDR_2 equ {MAX_SPRITES*14}
2022-05-19 02:00:06 +00:00
;TILE_STORE_ADDR_3 equ {MAX_SPRITES*16}
2022-05-27 00:36:40 +00:00
;TS_VBUFF_BASE_ADDR equ {MAX_SPRITES*16} ; Fixed address of the TS_VBUFF_X memory locations
2022-05-19 02:00:06 +00:00
;TILE_STORE_ADDR_4 equ {MAX_SPRITES*18}
;TILE_STORE_ADDR_5 equ {MAX_SPRITES*20}
;TILE_STORE_ADDR_6 equ {MAX_SPRITES*22}
;TILE_STORE_ADDR_7 equ {MAX_SPRITES*24}
;TILE_STORE_ADDR_8 equ {MAX_SPRITES*26}
;TILE_STORE_ADDR_9 equ {MAX_SPRITES*28}
;TILE_STORE_ADDR_10 equ {MAX_SPRITES*30}
2022-05-31 18:01:09 +00:00
; 51 rows by 81 columns + 2 extra rows and columns for sprite sizes
TS_ L O O K U P _ W I D T H e q u 8 1
TS_ L O O K U P _ H E I G H T e q u 5 1
TS_ L O O K U P _ B O R D E R e q u 2
TS_ L O O K U P _ S P A N e q u { T S _ L O O K U P _ W I D T H + T S _ L O O K U P _ B O R D E R }
TS_ L O O K U P _ R O W S e q u { T S _ L O O K U P _ H E I G H T + T S _ L O O K U P _ B O R D E R }
2022-05-19 02:00:06 +00:00
; Blitter template constancts
PER_ T I L E _ S I Z E e q u 3
SNIPPET_ S I Z E e q u 3 2
;----------------------------------------------------------------------
;
; Timer implementation
;
; The engire provides four timer slot that can be used by one-shot or
; recurring timers. Each timer is given an initial tick count, a
; reset tick count (0 = one-shot), and an action to perform.
;
; The timers handle overflow, so if a recurring timer has a tick count of 3
; and 7 VBL ticks have passed, then the timer will be fired twice and
; a tick count of 2 will be set.
;
; As such, the timers are appropriate to drive physical and other game
; behaviors at a frame-independent rate.
;
; A collection of 4 timers that are triggered when their countdown
; goes below zero. Each timer takes up 16 bytes
;
; A timer can fire multiple times during a singular evaluation. For example, if the
; timer delay is set to 1 and 3 VBL ticks happen, then the timer delta is -2, will fire,
; have the delay added and get -1, fire again, increment to zero, first again and then
; finally reset to 1.
;
; +0 counter decremented by the number of ticks since last run
; +2 reset copied into counter when triggered. 0 turns off the timer.
; +4 addr long address of timer routine
; +8 user 8 bytes of user data space for timer state
MAX_ T I M E R S e q u 4
TIMER_ R E C _ S I Z E e q u 1 6