Language…
18 users online:  Atari2.0, DanMario24YT, derv82, drkrdnk, eltiolavara9, h.carrell, Isikoro, krizeth, masl, Maw, MorrieTheMagpie, Red2010, Serena, Shomi, sinseiga, sparksplit-smw, steelsburg, trihex - Guests: 278 - Bots: 334
Users: 64,795 (2,375 active)
Latest user: mathew

[Solved] Layer 1 background scrolling problem in Mode 3

This is used in 8BPP 512×1024 Background
Here, layer 1 is background and layer 2 is foreground.

Code
init:
;er-nobr">
LDA.b #%00010011	; \ mode 3, Set Layer 1 Tile as 16×16
STA.b $3E		; /
LDA.b #%00010010	; \  sprites & layer 2
STA.w $212C		;  | on MainScreen
STA.w $212E		; /
LDA.b #%00000001	; \  layer 1
STA.w $212D		;  | on SubScreen
STA.w $212F		; /

LDA #%00111010 : STA $2107	;  Swap Layer 1 and Layer 1 tilemap, Set 512×1024 BG
LDA #%00110001 : STA $2108	;  Swap Layer 2 and Layer 1 tilemap

LDA #$00
STA $1417|!addr

LDA #%10100011 : STA $44


RTL

main:

; Layer 1 H-Scroll = Layer 3 H-Scroll
REP #$20 : LDA $22 : SEP #$20
STA $210D : XBA : STA $210D
	
; Layer 1 V-Scroll = Layer 3 V-Scroll. But this code stains the top of the background.
REP #$20 : LDA $24 : SEP #$20
STA $210E : XBA : STA $210E

RTL


in this code

Code
; Layer 1 H-Scroll = Layer 3 H-Scroll
REP #$20 : LDA $22 : SEP #$20
STA $210D : XBA : STA $210D
	
; Layer 1 V-Scroll = Layer 3 V-Scroll. But this code stains the top of the background.
REP #$20 : LDA $24 : SEP #$20
STA $210E : XBA : STA $210E


This code positions layer 1 the same as layer 3 (though it doesn't use layer 3 because it's mode 3).
This part messes up the top of the screen.



Is there any way to scroll layer 1 slower than layer 2 without messing up the top of the screen?(Without using parallax)
"main" is not running during a blank. as a general rule of thumb, you shouldnt write to PPU registers unless youre in at least h-blank, but preferrably v-blank (or f-blank). theres an "nmi" label you can stick that code in, but iirc it runs at the beginning of nmi, so itll get overwritten by smw's later writes to 210d/e. easiest solution thus would be a basic hdma (setup in init)

Code
REP #$20
LDA #$0D43
STA $4330
LDA.w #.table
STA $4332
SEP #$20
LDA.b #.table>>16
STA $4334
STA $4337
LDA #$08
TSB $0D9F|!addr
RTL

.table
db $01 : dw $0022|!dp
db $00


alternatively, if you make sure smw's nmi runs quickly, then you can get "main" to run during the latter end of v-blank and you wont need to do any shenanigans. i do not recommend this solution tho; berry unreliable