Use labels instead of constants for HRAM

Use explicit ldh instruction to access HRAM locations, don't rely on optimizing ld
This commit is contained in:
Rangi
2018-08-25 14:28:22 -04:00
parent 376c64468b
commit eb1e3636bb
243 changed files with 4706 additions and 4661 deletions

View File

@@ -3,36 +3,36 @@ ClearBGPalettes::
WaitBGMap::
; Tell VBlank to update BG Map
ld a, 1 ; BG Map 0 tiles
ld [hBGMapMode], a
ldh [hBGMapMode], a
; Wait for it to do its magic
ld c, 4
call DelayFrames
ret
WaitBGMap2::
ld a, [hCGB]
ldh a, [hCGB]
and a
jr z, .bg0
ld a, 2
ld [hBGMapMode], a
ldh [hBGMapMode], a
ld c, 4
call DelayFrames
.bg0
ld a, 1
ld [hBGMapMode], a
ldh [hBGMapMode], a
ld c, 4
call DelayFrames
ret
IsCGB::
ld a, [hCGB]
ldh a, [hCGB]
and a
ret
ApplyTilemap::
ld a, [hCGB]
ldh a, [hCGB]
and a
jr z, .dmg
@@ -41,19 +41,19 @@ ApplyTilemap::
jr z, .dmg
ld a, 1
ld [hBGMapMode], a
ldh [hBGMapMode], a
jr CopyTilemapAtOnce
.dmg
; WaitBGMap
ld a, 1
ld [hBGMapMode], a
ldh [hBGMapMode], a
ld c, 4
call DelayFrames
ret
CGBOnly_CopyTilemapAtOnce::
ld a, [hCGB]
ldh a, [hCGB]
and a
jr z, WaitBGMap
@@ -65,52 +65,52 @@ CopyTilemapAtOnce::
ret
.CopyTilemapAtOnce:
ld a, [hBGMapMode]
ldh a, [hBGMapMode]
push af
xor a
ld [hBGMapMode], a
ldh [hBGMapMode], a
ld a, [hMapAnims]
ldh a, [hMapAnims]
push af
xor a
ld [hMapAnims], a
ldh [hMapAnims], a
.wait
ld a, [rLY]
ldh a, [rLY]
cp $7f
jr c, .wait
di
ld a, BANK(vTiles3)
ld [rVBK], a
ldh [rVBK], a
hlcoord 0, 0, wAttrMap
call .StackPointerMagic
ld a, BANK(vTiles0)
ld [rVBK], a
ldh [rVBK], a
hlcoord 0, 0
call .StackPointerMagic
.wait2
ld a, [rLY]
ldh a, [rLY]
cp $7f
jr c, .wait2
ei
pop af
ld [hMapAnims], a
ldh [hMapAnims], a
pop af
ld [hBGMapMode], a
ldh [hBGMapMode], a
ret
.StackPointerMagic:
; Copy all tiles to vBGMap
ld [hSPBuffer], sp
ld sp, hl
ld a, [hBGMapAddress + 1]
ldh a, [hBGMapAddress + 1]
ld h, a
ld l, 0
ld a, SCREEN_HEIGHT
ld [hTilesPerCycle], a
ldh [hTilesPerCycle], a
ld b, 1 << 1 ; not in v/hblank
ld c, LOW(rSTAT)
@@ -131,14 +131,14 @@ endr
ld de, BG_MAP_WIDTH - SCREEN_WIDTH
add hl, de
ld a, [hTilesPerCycle]
ldh a, [hTilesPerCycle]
dec a
ld [hTilesPerCycle], a
ldh [hTilesPerCycle], a
jr nz, .loop
ld a, [hSPBuffer]
ldh a, [hSPBuffer]
ld l, a
ld a, [hSPBuffer + 1]
ldh a, [hSPBuffer + 1]
ld h, a
ld sp, hl
ret
@@ -146,14 +146,14 @@ endr
SetPalettes::
; Inits the Palettes
; depending on the system the monochromes palettes or color palettes
ld a, [hCGB]
ldh a, [hCGB]
and a
jr nz, .SetPalettesForGameBoyColor
ld a, %11100100
ld [rBGP], a
ldh [rBGP], a
ld a, %11010000
ld [rOBP0], a
ld [rOBP1], a
ldh [rOBP0], a
ldh [rOBP1], a
ret
.SetPalettesForGameBoyColor:
@@ -169,23 +169,23 @@ ClearPalettes::
; Make all palettes white
; CGB: make all the palette colors white
ld a, [hCGB]
ldh a, [hCGB]
and a
jr nz, .cgb
; DMG: just change palettes to 0 (white)
xor a
ld [rBGP], a
ld [rOBP0], a
ld [rOBP1], a
ldh [rBGP], a
ldh [rOBP0], a
ldh [rOBP1], a
ret
.cgb
ld a, [rSVBK]
ldh a, [rSVBK]
push af
ld a, BANK(wBGPals2)
ld [rSVBK], a
ldh [rSVBK], a
; Fill wBGPals2 and wOBPals2 with $ffff (white)
ld hl, wBGPals2
@@ -194,11 +194,11 @@ ClearPalettes::
call ByteFill
pop af
ld [rSVBK], a
ldh [rSVBK], a
; Request palette update
ld a, 1
ld [hCGBPalUpdate], a
ldh [hCGBPalUpdate], a
ret
GetMemSGBLayout::
@@ -206,11 +206,11 @@ GetMemSGBLayout::
GetSGBLayout::
; load sgb packets unless dmg
ld a, [hCGB]
ldh a, [hCGB]
and a
jr nz, .sgb
ld a, [hSGB]
ldh a, [hSGB]
and a
ret z