diff --git a/macros/GTE.Macs.s b/macros/GTE.Macs.s index 48a4a9f..137ffcf 100644 --- a/macros/GTE.Macs.s +++ b/macros/GTE.Macs.s @@ -59,4 +59,78 @@ _GTEGetSeconds MAC <<< _GTECopyTileToDynamic MAC UserTool $1500+GTEToolNum - <<< \ No newline at end of file + <<< +_GTESetPalette MAC + UserTool $1600+GTEToolNum + <<< +_GTECopyPicToBG1 MAC + UserTool $1700+GTEToolNum + <<< +_GTEBindSCBArray MAC + UserTool $1800+GTEToolNum + <<< +_GTEGetBG0TileMapInfo MAC + UserTool $1900+GTEToolNum + <<< +_GTEGetScreenInfo MAC + UserTool $1A00+GTEToolNum + <<< +_GTESetBG1Origin MAC + UserTool $1B00+GTEToolNum + <<< +_GTEGetTileAt MAC + UserTool $1C00+GTEToolNum + <<< +_GTESetBG0TileMapInfo MAC + UserTool $1D00+GTEToolNum + <<< +_GTESetBG1TileMapInfo MAC + UserTool $1E00+GTEToolNum + <<< + +; EngineMode definitions +; Script definition +YIELD equ $8000 +JUMP equ $4000 + +SET_PALETTE_ENTRY equ $0002 +SWAP_PALETTE_ENTRY equ $0004 +SET_DYN_TILE equ $0006 +CALLBACK equ $0010 + +; ReadControl return value bits +PAD_BUTTON_B equ $01 +PAD_BUTTON_A equ $02 +PAD_KEY_DOWN equ $04 +ENGINE_MODE_TWO_LAYER equ $0001 +ENGINE_MODE_DYN_TILES equ $0002 +ENGINE_MODE_BNK0_BUFF equ $0004 + +; Tile constants +; TILE_RESERVED_BIT equ $8000 +TILE_PRIORITY_BIT equ $4000 ; Put tile on top of sprite +TILE_FRINGE_BIT equ $2000 ; Unused +TILE_SOLID_BIT equ $1000 ; Hint bit used in TWO_LAYER_MODE to optimize rendering +TILE_DYN_BIT equ $0800 ; Is this a Dynamic Tile? +TILE_VFLIP_BIT equ $0400 +TILE_HFLIP_BIT equ $0200 +TILE_ID_MASK equ $01FF +TILE_CTRL_MASK equ $FE00 + + +; Sprite constants +SPRITE_HIDE equ $2000 +SPRITE_16X16 equ $1800 +SPRITE_16X8 equ $1000 +SPRITE_8X16 equ $0800 +SPRITE_8X8 equ $0000 +SPRITE_VFLIP equ $0400 +SPRITE_HFLIP equ $0200 + +; Stamp storage parameters +VBUFF_STRIDE_BYTES equ {12*4} ; Each line has 4 slots of 16 pixels + 8 buffer pixels +VBUFF_TILE_ROW_BYTES equ {8*VBUFF_STRIDE_BYTES} ; Each row is comprised of 8 lines +VBUFF_TILE_COL_BYTES equ 4 +VBUFF_SPRITE_STEP equ {VBUFF_TILE_ROW_BYTES*3} ; Allocate space for 16 rows + 8 rows of buffer +VBUFF_SPRITE_START equ {VBUFF_TILE_ROW_BYTES+4} ; Start at an offset so $0000 can be used as an empty value +VBUFF_SLOT_COUNT equ 48 ; Have space for this many stamps diff --git a/src/GTE.s b/src/GTE.s index dd30f36..cc08f42 100644 --- a/src/GTE.s +++ b/src/GTE.s @@ -25,7 +25,7 @@ Render EXT ; SCB/Palette binding (high bit of array point indicates whether to bind to BG0 Y position (0) ; or BG1 Y position (1). -SetSCBArray EXT +; SetSCBArray EXT BltSCB EXT ; Rotation diff --git a/src/Render.s b/src/Render.s index 2c046dd..98c5403 100644 --- a/src/Render.s +++ b/src/Render.s @@ -20,6 +20,8 @@ ; It's important to do _ApplyBG0YPos first because it calculates the value of StartY % 208 which is ; used in all of the other loops _Render + jsr _DoTimers ; Run any pending timer tasks + stz SpriteRemovedFlag ; If we remove a sprite, then we need to flag a rebuild for the next frame jsr _ApplyBG0YPos ; Set stack addresses for the virtual lines to the physical screen diff --git a/src/Timer.s b/src/Timer.s index a1ca960..be34162 100644 --- a/src/Timer.s +++ b/src/Timer.s @@ -107,33 +107,48 @@ RemoveTimer ENT rtl ; Execute the timer functions -DoTimers ENT - phb - jsr _SetDataBank +;DoTimers ENT +; phb +; jsr _SetDataBank +; +; jsr _GetVBLTicks +; +; cmp LastTick ; Throttle to 60 fps +; beq :exit +; tax ; Calculate the increment +; sec +; sbc LastTick +; stx LastTick +; We don't want times to fire excessively. If the timer hasn't been evaluated for over +; one second, then just skip processing and wait for the next call. +; cmp #60 +; bcs :exit + +; jsr _DoTimers + +;:exit plb +; rtl + +; Countdown the timers +_DoTimers jsr _GetVBLTicks cmp LastTick ; Throttle to 60 fps beq :exit + tax ; Calculate the increment sec sbc LastTick stx LastTick -; We don't want times to fire excessively. If the timer has nt been evaluated for over +; We don't want times to fire excessively. If the timer hasn't been evaluated for over ; one second, then just skip processing and wait for the next call. cmp #60 - bcs :exit + bcc :do_timer +:exit rts - jsr _DoTimers - -:exit plb - rtl - -; Countdown the timers -; -; A = number of elapsed ticks -_DoTimers +:do_timer pha ldx #0 :loop diff --git a/src/Tool.s b/src/Tool.s index 2d76117..d18d614 100644 --- a/src/Tool.s +++ b/src/Tool.s @@ -60,6 +60,17 @@ _CallTable adrl _TSGetSeconds-1 adrl _TSCopyTileToDynamic-1 + + adrl _TSSetPalette-1 + adrl _TSCopyPicToBG1-1 + adrl _TSBindSCBArray-1 + adrl _TSGetBG0TileMapInfo-1 + adrl _TSGetScreenInfo-1 + adrl _TSSetBG1Origin-1 + adrl _TSGetTileAt-1 + + adrl _TSSetBG0TileMapInfo-1 + adrl _TSSetBG1TileMapInfo-1 _CTEnd _GTEAddSprite MAC UserTool $1000+GTEToolNum @@ -371,6 +382,171 @@ _TSCopyTileToDynamic :notEnabled _TSExit #0;#4 + +_TSSetPalette +:ptr equ FirstParam+0 +:palNum equ FirstParam+4 + + _TSEntry + + phb + lda :ptr+2 + pha + plb + plb + + lda :ptr + tax + lda :palNum + jsr _SetPalette + plb + + _TSExit #0;#6 + +_TSCopyPicToBG1 +:ptr equ FirstParam+0 + + _TSEntry + + lda BG1DataBank + tay + lda :ptr+2,s + tax + lda :ptr,s + jsr _CopyPicToBG1 + + _TSExit #0;#4 + +_TSBindSCBArray +:ptr equ FirstParam+0 + + _TSEntry + + lda :ptr,s + tax + lda :ptr+2,s + jsr _BindSCBArray + + _TSExit #0;#4 + +_TSGetBG0TileMapInfo +:ptr equ FirstParam+4 +:height equ FirstParam+2 +:width equ FirstParam+0 + _TSEntry + + lda TileMapWidth + sta :width,s + lda TileMapHeight + sta :height,s + lda TileMapPtr + sta :ptr,s + lda TileMapPtr+2 + sta :ptr+2,s + + _TSExit #0;#0 + + +_TSGetScreenInfo +:height equ FirstParam+4 +:width equ FirstParam+4 +:y equ FirstParam+2 +:x equ FirstParam+0 + _TSEntry + + lda ScreenX0 + sta :x,s + lda ScreenY0 + sta :y,s + sta :width,s + lda ScreenWidth + sta :width,s + lda ScreenHeight + sta :height,s + + _TSExit #0;#0 + +; SetBG1Origin(x, y) +_TSSetBG1Origin +:y equ FirstParam +:x equ FirstParam+2 + + _TSEntry + + lda :x,s + jsr _SetBG1XPos + lda :y,s + jsr _SetBG1YPos + + _TSExit #0;#4 + +; GetTileAt(x, y) +_TSGetTileAt +:y equ FirstParam +:x equ FirstParam+2 +:output equ FirstParam+4 + + _TSEntry + +; Convert the x, y coordinated to tile store block coordinates + lda :x,s + tax + lda :y,s + tay + jsr _GetTileAt + bcc :ok + lda #0 + bra :out + +; Load the tile at that tile store location + +:ok + jsr _GetTileStoreOffset0 ; Get the address of the X,Y tile position + tax + lda TileStore+TS_TILE_ID,x +:out + sta :output,s + + _TSExit #0;#4 + +; SetBG0TileMapInfo(width, height, ptr) +_TSSetBG0TileMapInfo +:ptr equ FirstParam+0 +:height equ FirstParam+4 +:width equ FirstParam+6 + + _TSEntry + + lda :width,s + sta TileMapWidth + lda :height,s + sta TileMapHeight + lda :ptr,s + sta TileMapPtr + lda :ptr+2,s + sta TileMapPtr+2 + + _TSExit #0;#8 + +; SetBG1TileMapInfo(width, height, ptr) +_TSSetBG1TileMapInfo +:ptr equ FirstParam+0 +:height equ FirstParam+4 +:width equ FirstParam+6 + + _TSEntry + + lda :width,s + sta BG1TileMapWidth + lda :height,s + sta BG1TileMapHeight + lda :ptr,s + sta BG1TileMapPtr + lda :ptr+2,s + sta TileMapPtr+2 + + _TSExit #0;#8 + ; Insert the GTE code put Math.s @@ -391,6 +567,7 @@ _TSCopyTileToDynamic put render/Sprite1.s put render/Sprite2.s put tiles/DirtyTileQueue.s + put blitter/SCB.s put blitter/Horz.s put blitter/Vert.s put blitter/BG0.s diff --git a/src/blitter/SCB.s b/src/blitter/SCB.s index 361018a..266010b 100644 --- a/src/blitter/SCB.s +++ b/src/blitter/SCB.s @@ -76,11 +76,11 @@ _BltSCB ; Quick helper to set the pointer (X = low word, A = high work) -SetSCBArray ENT - jsr _SetSCBArray - rtl +;SetSCBArray ENT +; jsr _SetSCBArray +; rtl -_SetSCBArray +_BindSCBArray stx SCBArrayPtr sta SCBArrayPtr+2 rts