Skip to content

Commit

Permalink
Fix flickering with item menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Stewmath committed Jul 15, 2017
1 parent 994bdee commit 1bfcf7a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
18 changes: 17 additions & 1 deletion color/refreshmaps.asm
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,33 @@ ENDR
ld bc, -$c0
add hl,bc

; BEGIN loading palettes
; BEGIN loading palette maps

ld a,1
ld [rVBK],a
inc a
ld [rSVBK],a

; Skip palette update if the pre-vblank routine updated a different portion of
; the window... I guess this can happen due to lag? If this is omitted, there's
; corruption when scrolling throw the item menu.
ld a,[W2_PreVBlankWindowPortion]
inc a
cp $03
jr nz,.checkPortion
xor a
.checkPortion
ld b,a
ld a,[H_AUTOBGTRANSFERPORTION]
cp b
jr nz,.palettesDone

; Always update if using tile-based palettes
ld a,[W2_TileBasedPalettes]
and a
jr nz,.continue

; If using static palettes, we can check whether that's been updated
ld a,[W2_StaticPaletteMapChanged_vbl]
and a
jr z, .palettesDone
Expand Down
15 changes: 8 additions & 7 deletions color/vblank.asm
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,14 @@ RefreshWindowPalettesPreVBlank:
and a
ret z

ld a,[rSVBK]
ld b,a
ld a,$02
ld [rSVBK],a
push bc ; Push last wram bank

ld a,[H_AUTOBGTRANSFERPORTION]
ld [W2_PreVBlankWindowPortion],a
and a
jr z,.firstThird
dec a
Expand All @@ -161,12 +168,6 @@ RefreshWindowPalettesPreVBlank:

; BEGIN loading palettes

ld a,[rSVBK]
ld b,a
ld a,$02
ld [rSVBK],a
push bc ; Push last wram bank

ld hl, W2_ScreenPalettesBuffer

ld b,6
Expand All @@ -175,8 +176,8 @@ RefreshWindowPalettesPreVBlank:
and a
jr nz,.tileBasedPalettes

; TODO: delete this?
.staticMapPalettes: ; Palettes are loaded from a 20x18 grid of palettes
; If the window transfer destination changed, we'll need to rewrite everything
ld a,[W2_LastAutoCopyDest]
ld b,a
ld a,[H_AUTOBGTRANSFERDEST+1]
Expand Down
8 changes: 6 additions & 2 deletions color/wram.asm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ W2_TilesetPaletteMap EQU $d200
W2_SpritePaletteMap EQU $d400

; Palette calculations for wTileMap are stored here before vblank.
W2_ScreenPalettesBuffer EQU $d500 ; 32x6 bytes (DMA-able), $d500-$d5c0
W2_ScreenPalettesBuffer EQU $d500 ; 32x6 bytes (DMA-able), $d500-$d5c0

W2_TownMapLoaded EQU $d700
W2_TileBasedPalettes EQU $d701
Expand All @@ -30,10 +30,14 @@ W2_SprPaletteDataModified EQU $d785
; actual-vblank routines.
W2_StaticPaletteMapChanged_vbl EQU $d786

; Former value of [H_AUTOBGTRANSFERDEST+1]. Should be $98 or $9c.
W2_LastAutoCopyDest EQU $d787

W2_ForceBGPUpdate EQU $d788
W2_ForceOBPUpdate EQU $d789
W2_ForceOBPUpdate EQU $d789

; The value of H_AUTOBGTRANSFERPORTION that the pre-vblank routine operated with
W2_PreVBlankWindowPortion EQU $d78a

; In bank 1, the stack starts at $dfff. So, that's also the stack here when bank 2 is
; loaded. Don't use anything too close to there.

0 comments on commit 1bfcf7a

Please sign in to comment.