Added sprite and background disable control bits

This commit is contained in:
Lucas Scharenbroich 2023-05-28 07:49:37 -05:00
parent cc36fcc0f8
commit aeb620fb7b
6 changed files with 138 additions and 14 deletions

View File

@ -138,6 +138,12 @@ _GTESetAddress MAC
_GTEUpdateOverlay MAC
UserTool $2F00+GTEToolNum
<<<
_GTEEnableSprites MAC
UserTool $3000+GTEToolNum
<<<
_GTEEnableBackground MAC
UserTool $3100+GTEToolNum
<<<
; EngineMode definitions
; Script definition

View File

@ -218,8 +218,9 @@ EngineReset
stz TileMapHeight
stz TileMapPtr
stz TileMapPtr+2
stz FringeMapPtr
stz FringeMapPtr+2
; stz FringeMapPtr
; stz FringeMapPtr+2
stz GTEControlBits
stz BG1TileMapWidth
stz BG1TileMapHeight

View File

@ -76,7 +76,8 @@ OldBG1TileOriginY equ 68
TileMapWidth equ 70 ; Pointer to memory holding the tile map for the primary background
TileMapHeight equ 72
TileMapPtr equ 74
FringeMapPtr equ 78
; FringeMapPtr equ 78
GTEControlBits equ 78 ; Enable / disable things
BG1TileMapWidth equ 82
BG1TileMapHeight equ 84
@ -215,6 +216,10 @@ PAD_BUTTON_B equ $0100
PAD_BUTTON_A equ $0200
PAD_KEY_DOWN equ $0400
; GTE Control Bits
CTRL_SPRITE_DISABLE equ $0001
CTRL_BKGND_DISABLE equ $0002
; Tile constants
TILE_DAMAGED_BIT equ $8000 ; Mark a tile as damaged (internal only)
TILE_PRIORITY_BIT equ $4000 ; Put tile on top of sprite (unimplemented)

View File

@ -205,6 +205,10 @@ _RenderNES
; This is handled by the callback in two phases. We pass pointers to the internal function the callback needs
; access to. If there is no function defined, do nothing
lda GTEControlBits
bit #CTRL_SPRITE_DISABLE
bne :no_render
lda ExtSpriteRenderer
ora ExtSpriteRenderer+2
beq :no_render

View File

@ -102,6 +102,9 @@ _CallTable
adrl _TSSetAddress-1
adrl _TSUpdateOverlay-1
adrl _TSEnableSprites-1
adrl _TSEnableBackground-1
_CTEnd
_GTEAddSprite MAC
UserTool $1000+GTEToolNum
@ -1029,6 +1032,42 @@ _TSCompileSpriteStamp
_TSExit #0;#4
; EnableSprites(bool)
_TSEnableSprites
:enable equ FirstParam
_TSEntry
lda :enable
beq :turn_off
lda #CTRL_SPRITE_DISABLE
trb GTEControlBits
bra :done
:turn_off
lda #CTRL_SPRITE_DISABLE
tsb GTEControlBits
:done
_TSExit #0;#2
; EnableBackground(bool)
_TSEnableBackground
:enable equ FirstParam
_TSEntry
lda :enable,s
beq :turn_off
lda #CTRL_BKGND_DISABLE
trb GTEControlBits
bra :done
:turn_off
lda #CTRL_BKGND_DISABLE
tsb GTEControlBits
:done
_TSExit #0;#2
; Insert the GTE code
put Math.s

View File

@ -18,6 +18,14 @@ _BltRange
bcc *+3
rts
; If the background is disabled, jump to a specialized BG routine
lda GTEControlBits
bit #CTRL_BKGND_DISABLE
beq :normal
brl DisabledBG
:normal
phb ; preserve the bank register
clc`
@ -63,17 +71,8 @@ _BltRange
bit #ENGINE_MODE_TWO_LAYER
beq :skip_bank
; TODO: Switch to loading the selected BG1 bank. No special "Alt" bank
;
; lda RenderFlags
; bit #RENDER_ALT_BG1
; beq :primary
;
; lda BG1AltBank
; bra :alt
;
;:primary lda BG1DataBank
;:alt
; Load the BG1 data bank
lda BG1DataBank
pha
plb
@ -108,6 +107,76 @@ stk_save lda #0000 ; load the stack
plb ; restore the bank
rts
; Specialize routine that just slams a bunch of PHA instructions when background rendering is disabled
DisabledBG
stx tmp15
tya
sec
sbc tmp15
tay ; Put the count in the y register
lda ScreenWidth ; Screen width in bytes (0 - 159)
lsr ; Convert to number of word
eor #$FFFF
adc #:blkend ; subtract from the end of the PHA array
stal :patch+1
lda #8 ; Enable interrups at least this many lines
sta tmp14
txa ; multiply starting line by 2 for indexing
asl
tax
php ; save the current processor flags
sei ; disable interrupts
tsc ; save the stack pointer
sta tmp15
_R0W1
:loop
lda RTable,x ; Load the screen right edge
tcs
lda #0
:patch jmp $0000
lup 80
pha
--^
:blkend
dec tmp14
bmi :enable_int
:next
inx
inx
dey
bne :loop
_R0W0
lda tmp15
tcs
plp
rts
:enable_int
lda #8 ; Reset the counter
sta tmp14
lda tmp15 ; restore the stack
tcs
sep #$30 ; 8-bit mode
ldal STATE_REG
tax ; Save the value
and #$CF ; Read Bank 0 / Write Bank 0
stal STATE_REG
cli
nop ; Give a couple of cycles
sei
txa ; Restore the state
stal STATE_REG
rep #$30
bra :next
; External entry point. Can be called directly from another bank
BltRange
phd