Skip to content

Commit

Permalink
Fix gfx corruption in first pokemart.
Browse files Browse the repository at this point in the history
This was caused by the vblank interrupt being triggered very late on one
frame. This was happening because I wrapped "PrepareOAMData" and
"ColorNonOverworldSprites" in a "disable interrupts" block. The latter
didn't matter, but I had to fix a function call in PrepareOAMData to
allow it to work with interrupts.
  • Loading branch information
Stewmath committed Jul 15, 2017
1 parent 1bfcf7a commit bfd0d7a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions color/refreshmaps.asm
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ DrawMapRow:
ret

.drawHalfPalette
ld b, $d2
ld b, W2_TilesetPaletteMap>>8
REPT 10
ld a,[hli]
ld c,a
Expand Down Expand Up @@ -388,7 +388,7 @@ jr nc,.noCarry
ld e,a
ld a,[hRedrawRowOrColumnDest + 1]
ld d,a
ld b,$d2
ld b, W2_TilesetPaletteMap>>8
REPT 18
ld a,[hli]
ld c,a
Expand Down
25 changes: 14 additions & 11 deletions home.asm
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,24 @@ _InitGbcMode:

; Called once for each sprite. This needs to preserve variables, so it can't use
; BankSwitch.
; Interrupts should be disabled when calling this since it doesn't properly update the
; "H_LOADEDROMBANK" variable...
_ColorOverworldSprite:
ld [H_SPTEMP],a ; Borrow this as memory not in use right now

ld a,[H_LOADEDROMBANK]
push af

ld a,BANK(ColorOverworldSprite)
ld [H_LOADEDROMBANK],a
ld [MBC1RomBank],a
pop af

ld a,[H_SPTEMP]
call ColorOverworldSprite
push af
ld a,[H_LOADEDROMBANK]
ld [MBC1RomBank],a

ld [H_SPTEMP],a
pop af
ld [H_LOADEDROMBANK],a
ld [MBC1RomBank],a
ld a,[H_SPTEMP]
ret


Expand Down Expand Up @@ -4817,15 +4823,12 @@ DelayFrameHook:
ld [rSVBK],a
push bc ; Save wram bank

; The "PrepareOamData" used to be run during vblank, so just to be safe, let's
; disable interrupts. Also, the "ColorNonOverworldSprites" function needs
; interrupts disabled.
di
; Calling "PrepareOAMData" here instead of at vblank to prevent sprite wobbliness
CALL_INDIRECT PrepareOAMData
jr z, .spritesDrawn

CALL_INDIRECT ColorNonOverworldSprites
.spritesDrawn
ei

pop af
ld [rSVBK],a ; Restore wram bank
Expand Down

0 comments on commit bfd0d7a

Please sign in to comment.