2021-07-07 21:36:44 +00:00
|
|
|
; Implementation of a PEI Slammer that updates a rectangular screen area. The only tweak that
|
|
|
|
; this implementation does is that it does break up the slam into chunks of scan lines to allow
|
|
|
|
; time for interrupts to be serviced in a timely manner.
|
|
|
|
;
|
2021-07-08 02:13:18 +00:00
|
|
|
; This is a fairly basic slam in that it does not try to align the direct page. To enhance the
|
|
|
|
; slammer, note that page-aligned addresses repeat every 8 scan lines and some lines would need
|
|
|
|
; to be split into two slams to keep the direct page aligned.
|
|
|
|
;
|
|
|
|
; At best, this saves 1 cycles per word, or 80 cycles for a full screen -- which is only about
|
|
|
|
; 12 additional instructions, so this is an optimization that is unlikely to lead to a net
|
|
|
|
; improvement.
|
|
|
|
;
|
2021-07-20 03:42:51 +00:00
|
|
|
; X = first line (inclusive), valid range of 0 to 199
|
|
|
|
; Y = last line (exclusive), valid range >X up to 200
|
|
|
|
_PEISlam
|
|
|
|
lda ScreenWidth
|
|
|
|
dec
|
2022-05-19 02:00:06 +00:00
|
|
|
stal :screen_width_1 ; save the width-1 outside of the direct page
|
2021-07-20 03:42:51 +00:00
|
|
|
|
|
|
|
lda #:pei_end ; patch the PEI entry address
|
|
|
|
and #$FFFE ; should always be even, but....
|
|
|
|
sec
|
|
|
|
sbc ScreenWidth
|
2022-05-19 02:00:06 +00:00
|
|
|
stal :inner+1
|
2021-07-20 03:42:51 +00:00
|
|
|
|
|
|
|
phx
|
|
|
|
tya
|
|
|
|
sec
|
|
|
|
sbc 1,s
|
|
|
|
ply
|
|
|
|
tay ; get the number of lines in the y register
|
|
|
|
|
|
|
|
txa
|
|
|
|
asl
|
|
|
|
tax
|
|
|
|
lda RTable,x ; This is the right visible byte, so add one to get the
|
|
|
|
tax ; left visible byte (cache in x-reg)
|
|
|
|
sec
|
|
|
|
sbc ScreenWidth
|
|
|
|
inc
|
|
|
|
|
|
|
|
phd ; save the current direct page and assign the base
|
|
|
|
tcd ; screen address to the direct page register
|
|
|
|
|
|
|
|
tsc
|
2022-05-19 02:00:06 +00:00
|
|
|
stal :stk_save ; save the stack pointer to restore later
|
2021-07-20 03:42:51 +00:00
|
|
|
|
|
|
|
clc ; clear before the loop -- nothing in the loop affect the carry bit
|
|
|
|
brl :outer ; hop into the entry point.
|
|
|
|
|
|
|
|
]dp equ 158
|
|
|
|
lup 80 ; A full width screen is 160 bytes / 80 words
|
|
|
|
pei ]dp
|
|
|
|
]dp equ ]dp-2
|
|
|
|
--^
|
2021-07-08 02:13:18 +00:00
|
|
|
:pei_end
|
2021-07-20 03:42:51 +00:00
|
|
|
tdc ; Move to the next line
|
|
|
|
adc #160
|
|
|
|
tcd
|
2022-05-19 02:00:06 +00:00
|
|
|
adcl :screen_width_1
|
2021-07-20 03:42:51 +00:00
|
|
|
tcs
|
|
|
|
|
|
|
|
dey ; decrement the total counter, if zero then we're done
|
|
|
|
beq :exit
|
|
|
|
|
|
|
|
dex ; decrement the inner counter. Both counters are set
|
|
|
|
beq :restore ; up so that they fall-through by default to save a cycle
|
|
|
|
; per loop iteration.
|
|
|
|
|
|
|
|
:inner jmp $0000 ; 25 cycles of overhead per line. A full width slam executes all
|
|
|
|
; 80 of the PEI instructions which we expect to take 7 cycles
|
|
|
|
; since the direct page is not aligned. So total overhead is
|
|
|
|
; 25 / (25 + 7 * 80) = 4.27% of execution
|
|
|
|
;
|
|
|
|
; Without the interrupt breaks, we could remove the dex/beq test
|
|
|
|
; and save 4 cycles per loop which takes the overhead down to
|
|
|
|
; only 3.6%
|
2021-07-08 02:13:18 +00:00
|
|
|
|
|
|
|
:restore
|
2021-07-20 03:42:51 +00:00
|
|
|
tsx ; save the current stack
|
|
|
|
_R0W0 ; restore the execution environment and
|
2022-05-19 02:00:06 +00:00
|
|
|
ldal :stk_save ; give a few cycles to catch some interrupts
|
2021-07-20 03:42:51 +00:00
|
|
|
tcs
|
|
|
|
cli ; fall through here -- saves a BRA instruction
|
2021-07-07 21:36:44 +00:00
|
|
|
|
|
|
|
:outer
|
2021-07-20 03:42:51 +00:00
|
|
|
sei
|
|
|
|
txs ; set the stack address to the right edge
|
|
|
|
ldx #8 ; Enable interrupts at least once every 8 lines
|
|
|
|
_R1W1
|
|
|
|
bra :inner
|
2021-07-07 21:36:44 +00:00
|
|
|
|
|
|
|
:exit
|
2021-07-20 03:42:51 +00:00
|
|
|
_R0W0
|
2022-05-19 02:00:06 +00:00
|
|
|
ldal :stk_save
|
2021-07-20 03:42:51 +00:00
|
|
|
tcs
|
|
|
|
cli
|
|
|
|
|
|
|
|
pld
|
|
|
|
rts
|
|
|
|
|
|
|
|
:stk_save ds 2
|
|
|
|
:screen_width_1 ds 2
|