Implement fix for scanline mode compensation in BG1

This commit is contained in:
Lucas Scharenbroich 2023-03-10 19:00:26 -06:00
parent 9021ee4506
commit 7dd690ac04
1 changed files with 39 additions and 12 deletions

View File

@ -37,9 +37,9 @@ _ResetBG1YTable
:stride equ tmp1 :stride equ tmp1
cmp #1 ; scanline mode? cmp #1 ; scanline mode?
bne :default bne :default
lda #$A0 lda #0
sta :base sta :base
lda #324 lda #327
sta :stride sta :stride
bra :begin bra :begin
:default :default
@ -96,22 +96,25 @@ _CopyToBG1
:src_flags equ tmp9 :src_flags equ tmp9
:dstptr2 equ tmp10 :dstptr2 equ tmp10
; scanline mode is tricky -- there's not enough space to make two full copies of a 328x200 bitmap buffer, but we can
; *barely* fit a (164 + 163) x 200 buffer. And, since the zero offset could use either end, this covers all of the cases.
sta :srcptr sta :srcptr
stx :srcptr+2 stx :srcptr+2
sty :dstptr+2 ; Everything goes into this bank sty :dstptr+2 ; Everything goes into this bank
sty :dstptr2+2 sty :dstptr2+2
lda #$00A0 lda #0 ; Start a byte 1 because odd offsets might go back 1 byte and don't want to wrap around
sta :dstptr sta :dstptr
clc clc
adc #164 ; leave a 4-byte gap in the middle adc #164 ; The first part is 1-byte short, the second part is a full 164 bytes
sta :dstptr2 sta :dstptr2
; "Normal" BG1 mode as a stride of 164 bytes and mirrors the BG0 size (328 x 208) ; "Normal" BG1 mode as a stride of 164 bytes and mirrors the BG0 size (328 x 208)
; In "Scanline" mode, the BG1 is treated as a 320x200 bitfield with each horizontal line doubled ; In "Scanline" mode, the BG1 is treated as a 320x200 bitfield with each horizontal line doubled
lda :src_width lda :src_width
min #160 min #164
sta :src_width sta :src_width
lda :src_height lda :src_height
@ -121,12 +124,22 @@ _CopyToBG1
stz :line_cnt stz :line_cnt
:rloop :rloop
ldy #0 ; move forward in the image data and image data ldy #0 ; move forward in the image data and image data
; Handle first word as a special case
lda [:srcptr],y
sta [:dstptr2],y ; copy directly into the 164-byte buffer
iny
xba
sep #$20
sta [:dstptr],y ; only copy the high byte because the previous line occupies the low byte
rep #$20
iny
:cloop :cloop
lda [:srcptr],y lda [:srcptr],y
sta [:dstptr],y sta [:dstptr],y
sta [:dstptr2],y sta [:dstptr2],y
:skip
iny iny
iny iny
@ -135,7 +148,7 @@ _CopyToBG1
lda :dstptr lda :dstptr
clc clc
adc #324 adc #327
sta :dstptr sta :dstptr
adc #164 adc #164
sta :dstptr2 sta :dstptr2
@ -203,7 +216,8 @@ _ApplyScanlineBG1XPos
tcd tcd
ldx #0 ldx #0
tya ; tya
lda #0
:loop :loop
sta 00,x ; store the value sta 00,x ; store the value
inc inc
@ -364,12 +378,25 @@ _ApplyScanlineBG1YPos
rts rts
:_ApplyConstBG1YPos :_ApplyConstBG1YPos
lda #164
sec lda #164
sbc :shift_value sec
sbc :shift_value
clc
adc BG1StartXMod164
cmp #164+1
bcc *+5
sbc #164
; sec
; sbc BG1StartXMod164
; bpl *+6 ; bpl *+6
; clc ; clc
; adc #160 ; adc #164
; cmp #164
; bcc *+3
; sbc #164
; clc ; clc
; adc :shift_value ; adc :shift_value
sta :shift_value sta :shift_value