mirror of
https://github.com/lscharen/iigs-game-engine.git
synced 2025-02-18 07:30:30 +00:00
Streamline restore BG0; experiment with more aggressive inlining
This commit is contained in:
parent
0f920acd03
commit
fa731f4b2d
@ -20,6 +20,7 @@ _RestoreBG0Opcodes
|
|||||||
:lines_left_x2 equ tmp2
|
:lines_left_x2 equ tmp2
|
||||||
:draw_count_x2 equ tmp3
|
:draw_count_x2 equ tmp3
|
||||||
:exit_offset equ tmp4
|
:exit_offset equ tmp4
|
||||||
|
:stk_save equ tmp5
|
||||||
|
|
||||||
phb ; Save data bank
|
phb ; Save data bank
|
||||||
|
|
||||||
@ -33,16 +34,17 @@ _RestoreBG0Opcodes
|
|||||||
lda LastPatchOffset ; If zero, there are no saved opcodes
|
lda LastPatchOffset ; If zero, there are no saved opcodes
|
||||||
sta :exit_offset
|
sta :exit_offset
|
||||||
|
|
||||||
ldx :virt_line_x2
|
tsc
|
||||||
|
sta :stk_save
|
||||||
|
|
||||||
:loop
|
:loop
|
||||||
|
ldx :virt_line_x2
|
||||||
ldal BTableLow,x ; Get the address of the first code field line
|
ldal BTableLow,x ; Get the address of the first code field line
|
||||||
tay
|
tay
|
||||||
|
|
||||||
sep #$20
|
ldal BTableHigh,x ; This intentionally leaks one byte on the stack
|
||||||
ldal BTableHigh,x
|
|
||||||
pha
|
pha
|
||||||
plb ; This is the bank that will receive the updates
|
plb ; This is the bank that will receive the updates
|
||||||
rep #$20
|
|
||||||
|
|
||||||
txa ; lda :virt_line_x2
|
txa ; lda :virt_line_x2
|
||||||
and #$001E
|
and #$001E
|
||||||
@ -54,18 +56,15 @@ _RestoreBG0Opcodes
|
|||||||
|
|
||||||
; y is already set to :base_address
|
; y is already set to :base_address
|
||||||
tax ; :draw_count * 2
|
tax ; :draw_count * 2
|
||||||
|
clc
|
||||||
|
adc :virt_line_x2
|
||||||
|
sta :virt_line_x2
|
||||||
|
|
||||||
tya
|
tya
|
||||||
clc
|
|
||||||
adc :exit_offset ; Add some offsets to get the base address in the code field line
|
adc :exit_offset ; Add some offsets to get the base address in the code field line
|
||||||
|
|
||||||
jsr (RestoreOpcode,x)
|
jmp (:tgt,x)
|
||||||
|
:tgt RestoreOpcode
|
||||||
lda :virt_line_x2 ; advance to the virtual line after the segment we just
|
|
||||||
clc ; filled in
|
|
||||||
adc :draw_count_x2
|
|
||||||
sta :virt_line_x2
|
|
||||||
tax
|
|
||||||
|
|
||||||
lda :lines_left_x2 ; subtract the number of lines we just completed
|
lda :lines_left_x2 ; subtract the number of lines we just completed
|
||||||
sec
|
sec
|
||||||
@ -73,9 +72,11 @@ _RestoreBG0Opcodes
|
|||||||
sta :lines_left_x2
|
sta :lines_left_x2
|
||||||
|
|
||||||
jne :loop
|
jne :loop
|
||||||
|
|
||||||
stz LastPatchOffset ; Clear the value once completed
|
stz LastPatchOffset ; Clear the value once completed
|
||||||
|
|
||||||
:out
|
lda :stk_save
|
||||||
|
tcs
|
||||||
plb
|
plb
|
||||||
rts
|
rts
|
||||||
|
|
||||||
@ -334,14 +335,12 @@ _ApplyBG0XPos
|
|||||||
|
|
||||||
sep #$20
|
sep #$20
|
||||||
|
|
||||||
; ldx :draw_count_x2
|
|
||||||
lda :entry_offset
|
lda :entry_offset
|
||||||
ldy :base_address
|
ldy :base_address
|
||||||
jsr (SetCodeEntry,x) ; All registers are preserved
|
jsr (SetCodeEntry,x) ; All registers are preserved
|
||||||
|
|
||||||
; Now, patch in the opcode
|
; Now, patch in the opcode
|
||||||
|
|
||||||
; ldx :draw_count_x2
|
|
||||||
lda :opcode
|
lda :opcode
|
||||||
jsr (SetCodeEntryOpcode,x) ; All registers are preserved
|
jsr (SetCodeEntryOpcode,x) ; All registers are preserved
|
||||||
|
|
||||||
@ -350,12 +349,7 @@ _ApplyBG0XPos
|
|||||||
lda :odd_entry_offset
|
lda :odd_entry_offset
|
||||||
beq :not_odd
|
beq :not_odd
|
||||||
|
|
||||||
; NOTE: SetOddCodeEntry and SaveHighOperand can probably be combined to eliminate call/return overhead
|
|
||||||
|
|
||||||
; ldx :draw_count_x2
|
|
||||||
jsr (SetOddCodeEntry,x) ; All registers are preserved
|
jsr (SetOddCodeEntry,x) ; All registers are preserved
|
||||||
|
|
||||||
; ldx :draw_count_x2
|
|
||||||
jmp (:SaveHighOperand,x) ; Only used once, so "inline" it
|
jmp (:SaveHighOperand,x) ; Only used once, so "inline" it
|
||||||
:save_high_op_rtn
|
:save_high_op_rtn
|
||||||
|
|
||||||
@ -544,77 +538,78 @@ SaveOpcode
|
|||||||
; X = number of lines * 2, 0 to 32
|
; X = number of lines * 2, 0 to 32
|
||||||
; Y = starting line * $1000
|
; Y = starting line * $1000
|
||||||
; A = code field location * $1000
|
; A = code field location * $1000
|
||||||
RestoreOpcode
|
RestoreOpcode mac
|
||||||
da :bottom
|
da bottom
|
||||||
da :do01,:do02,:do03,:do04
|
da do01,do02,do03,do04
|
||||||
da :do05,:do06,:do07,:do08
|
da do05,do06,do07,do08
|
||||||
da :do09,:do10,:do11,:do12
|
da do09,do10,do11,do12
|
||||||
da :do13,:do14,:do15,:do16
|
da do13,do14,do15,do16
|
||||||
|
|
||||||
:do15 tax
|
do15 tax
|
||||||
bra :x15
|
bra x15
|
||||||
:do14 tax
|
do14 tax
|
||||||
bra :x14
|
bra x14
|
||||||
:do13 tax
|
do13 tax
|
||||||
bra :x13
|
bra x13
|
||||||
:do12 tax
|
do12 tax
|
||||||
bra :x12
|
bra x12
|
||||||
:do11 tax
|
do11 tax
|
||||||
bra :x11
|
bra x11
|
||||||
:do10 tax
|
do10 tax
|
||||||
bra :x10
|
bra x10
|
||||||
:do09 tax
|
do09 tax
|
||||||
bra :x09
|
bra x09
|
||||||
:do08 tax
|
do08 tax
|
||||||
bra :x08
|
bra x08
|
||||||
:do07 tax
|
do07 tax
|
||||||
bra :x07
|
bra x07
|
||||||
:do06 tax
|
do06 tax
|
||||||
bra :x06
|
bra x06
|
||||||
:do05 tax
|
do05 tax
|
||||||
bra :x05
|
bra x05
|
||||||
:do04 tax
|
do04 tax
|
||||||
bra :x04
|
bra x04
|
||||||
:do03 tax
|
do03 tax
|
||||||
bra :x03
|
bra x03
|
||||||
:do02 tax
|
do02 tax
|
||||||
bra :x02
|
bra x02
|
||||||
:do01 tax
|
do01 tax
|
||||||
bra :x01
|
bra x01
|
||||||
:do16 tax
|
do16 tax
|
||||||
:x16 lda OPCODE_SAVE+$F000,y
|
x16 lda OPCODE_SAVE+$F000,y
|
||||||
sta $F000,x
|
sta $F000,x
|
||||||
:x15 lda OPCODE_SAVE+$E000,y
|
x15 lda OPCODE_SAVE+$E000,y
|
||||||
sta $E000,x
|
sta $E000,x
|
||||||
:x14 lda OPCODE_SAVE+$D000,y
|
x14 lda OPCODE_SAVE+$D000,y
|
||||||
sta $D000,x
|
sta $D000,x
|
||||||
:x13 lda OPCODE_SAVE+$C000,y
|
x13 lda OPCODE_SAVE+$C000,y
|
||||||
sta $C000,x
|
sta $C000,x
|
||||||
:x12 lda OPCODE_SAVE+$B000,y
|
x12 lda OPCODE_SAVE+$B000,y
|
||||||
sta $B000,x
|
sta $B000,x
|
||||||
:x11 lda OPCODE_SAVE+$A000,y
|
x11 lda OPCODE_SAVE+$A000,y
|
||||||
sta $A000,x
|
sta $A000,x
|
||||||
:x10 lda OPCODE_SAVE+$9000,y
|
x10 lda OPCODE_SAVE+$9000,y
|
||||||
sta $9000,x
|
sta $9000,x
|
||||||
:x09 lda OPCODE_SAVE+$8000,y
|
x09 lda OPCODE_SAVE+$8000,y
|
||||||
sta $8000,x
|
sta $8000,x
|
||||||
:x08 lda OPCODE_SAVE+$7000,y
|
x08 lda OPCODE_SAVE+$7000,y
|
||||||
sta $7000,x
|
sta $7000,x
|
||||||
:x07 lda OPCODE_SAVE+$6000,y
|
x07 lda OPCODE_SAVE+$6000,y
|
||||||
sta $6000,x
|
sta $6000,x
|
||||||
:x06 lda OPCODE_SAVE+$5000,y
|
x06 lda OPCODE_SAVE+$5000,y
|
||||||
sta $5000,x
|
sta $5000,x
|
||||||
:x05 lda OPCODE_SAVE+$4000,y
|
x05 lda OPCODE_SAVE+$4000,y
|
||||||
sta $4000,x
|
sta $4000,x
|
||||||
:x04 lda OPCODE_SAVE+$3000,y
|
x04 lda OPCODE_SAVE+$3000,y
|
||||||
sta $3000,x
|
sta $3000,x
|
||||||
:x03 lda OPCODE_SAVE+$2000,y
|
x03 lda OPCODE_SAVE+$2000,y
|
||||||
sta $2000,x
|
sta $2000,x
|
||||||
:x02 lda OPCODE_SAVE+$1000,y
|
x02 lda OPCODE_SAVE+$1000,y
|
||||||
sta $1000,x
|
sta $1000,x
|
||||||
:x01 lda: OPCODE_SAVE+$0000,y
|
x01 lda: OPCODE_SAVE+$0000,y
|
||||||
sta: $0000,x
|
sta: $0000,x
|
||||||
:bottom rts
|
bottom
|
||||||
|
<<<
|
||||||
|
|
||||||
; SetCodeEntry
|
; SetCodeEntry
|
||||||
;
|
;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user