summaryrefslogtreecommitdiff
path: root/home/tilemap.asm
diff options
context:
space:
mode:
Diffstat (limited to 'home/tilemap.asm')
-rw-r--r--home/tilemap.asm428
1 files changed, 200 insertions, 228 deletions
diff --git a/home/tilemap.asm b/home/tilemap.asm
index aceb00343..926ed8ac4 100644
--- a/home/tilemap.asm
+++ b/home/tilemap.asm
@@ -1,257 +1,229 @@
-PushWindow:: ; 1c00
- callfar _PushWindow
+ClearBGPalettes:: ; 31f3
+ call ClearPalettes
+WaitBGMap:: ; 31f6
+; Tell VBlank to update BG Map
+ ld a, 1 ; BG Map 0 tiles
+ ld [hBGMapMode], a
+; Wait for it to do its magic
+ ld c, 4
+ call DelayFrames
ret
-; 1c07
-
-ExitMenu:: ; 0x1c07
- push af
- callfar _ExitMenu
- pop af
+; 3200
+
+WaitBGMap2:: ; 0x3200
+ ld a, [hCGB]
+ and a
+ jr z, .bg0
+
+ ld a, 2
+ ld [hBGMapMode], a
+ ld c, 4
+ call DelayFrames
+
+.bg0
+ ld a, 1
+ ld [hBGMapMode], a
+ ld c, 4
+ call DelayFrames
ret
+; 0x3218
-InitVerticalMenuCursor:: ; 0x1c10
- callfar _InitVerticalMenuCursor
+IsCGB:: ; 3218
+ ld a, [hCGB]
+ and a
ret
-
-CloseWindow:: ; 0x1c17
- push af
- call ExitMenu
- call ApplyTilemap
- call UpdateSprites
- pop af
+; 321c
+
+ApplyTilemap:: ; 321c
+ ld a, [hCGB]
+ and a
+ jr z, .dmg
+
+ ld a, [wSpriteUpdatesEnabled]
+ cp 0
+ jr z, .dmg
+
+ ld a, 1
+ ld [hBGMapMode], a
+ jr CopyTilemapAtOnce
+
+.dmg
+; WaitBGMap
+ ld a, 1
+ ld [hBGMapMode], a
+ ld c, 4
+ call DelayFrames
ret
+; 3238
-RestoreTileBackup:: ; 0x1c23
- call MenuBoxCoord2Tile
- call .copy
- call MenuBoxCoord2Attr
- call .copy
- ret
-; 0x1c30
-
-.copy ; 0x1c30
- call GetMenuBoxDims
- inc b
- inc c
-
-.row
- push bc
- push hl
-
-.col
- ld a, [de]
- ld [hli], a
- dec de
- dec c
- jr nz, .col ; 0x1c3b $fa
-
- pop hl
- ld bc, SCREEN_WIDTH
- add hl, bc
- pop bc
- dec b
- jr nz, .row ; 0x1c44 $ef
+CGBOnly_CopyTilemapAtOnce:: ; 3238
+ ld a, [hCGB]
+ and a
+ jr z, WaitBGMap
- ret
+CopyTilemapAtOnce:: ; 323d
+ jr .CopyTilemapAtOnce
+; 323f
-PopWindow:: ; 0x1c47
- ld b, $10
- ld de, wMenuFlags
-.loop
- ld a, [hld]
- ld [de], a
- inc de
- dec b
- jr nz, .loop ; 0x1c50 $fa
+; unused
+ farcall HDMATransferAttrMapAndTileMapToWRAMBank3
ret
+; 3246
-GetMenuBoxDims:: ; 0x1c53
- ld a, [wMenuBorderTopCoord] ; top
- ld b, a
- ld a, [wMenuBorderBottomCoord] ; bottom
- sub b
- ld b, a
- ld a, [wMenuBorderLeftCoord] ; left
- ld c, a
- ld a, [wMenuBorderRightCoord] ; right
- sub c
- ld c, a
- ret
-; 0x1c66
+.CopyTilemapAtOnce: ; 3246
+ ld a, [hBGMapMode]
+ push af
+ xor a
+ ld [hBGMapMode], a
-CopyMenuData:: ; 1c66
- push hl
- push de
- push bc
+ ld a, [hMapAnims]
push af
- ld hl, wMenuDataPointer
- ld a, [hli]
- ld h, [hl]
- ld l, a
- ld de, wMenuDataFlags
- ld bc, wMenuDataEnd - wMenuDataFlags
- call CopyBytes
+ xor a
+ ld [hMapAnims], a
+
+.wait
+ ld a, [rLY]
+ cp $7f
+ jr c, .wait
+
+ di
+ ld a, BANK(vTiles3)
+ ld [rVBK], a
+ hlcoord 0, 0, wAttrMap
+ call .StackPointerMagic
+ ld a, BANK(vTiles0)
+ ld [rVBK], a
+ hlcoord 0, 0
+ call .StackPointerMagic
+
+.wait2
+ ld a, [rLY]
+ cp $7f
+ jr c, .wait2
+ ei
+
pop af
- pop bc
- pop de
- pop hl
+ ld [hMapAnims], a
+ pop af
+ ld [hBGMapMode], a
ret
-; 1c7e
+; 327b
+
+.StackPointerMagic: ; 327b
+; Copy all tiles to vBGMap
+ ld [hSPBuffer], sp
+ ld sp, hl
+ ld a, [hBGMapAddress + 1]
+ ld h, a
+ ld l, 0
+ ld a, SCREEN_HEIGHT
+ ld [hTilesPerCycle], a
+ ld b, 1 << 1 ; not in v/hblank
+ ld c, LOW(rSTAT)
-GetWindowStackTop:: ; 1c7e
- ld hl, wWindowStackPointer
- ld a, [hli]
- ld h, [hl]
- ld l, a
- inc hl
- ld a, [hli]
- ld h, [hl]
- ld l, a
- ret
-; 1c89
-
-PlaceVerticalMenuItems:: ; 1c89
- call CopyMenuData
- ld hl, wMenuDataPointer
- ld e, [hl]
- inc hl
- ld d, [hl]
- call GetMenuTextStartCoord
- call Coord2Tile ; hl now contains the tilemap address where we will start printing text.
- inc de
- ld a, [de] ; Number of items
- inc de
- ld b, a
.loop
- push bc
- call PlaceString
- inc de
- ld bc, 2 * SCREEN_WIDTH
- add hl, bc
- pop bc
- dec b
+rept SCREEN_WIDTH / 2
+ pop de
+; if in v/hblank, wait until not in v/hblank
+.loop\@
+ ld a, [$ff00+c]
+ and b
+ jr nz, .loop\@
+; load BGMap0
+ ld [hl], e
+ inc l
+ ld [hl], d
+ inc l
+endr
+
+ ld de, BG_MAP_WIDTH - SCREEN_WIDTH
+ add hl, de
+ ld a, [hTilesPerCycle]
+ dec a
+ ld [hTilesPerCycle], a
jr nz, .loop
- ld a, [wMenuDataFlags]
- bit 4, a
- ret z
-
- call MenuBoxCoord2Tile
- ld a, [de]
- ld c, a
- inc de
- ld b, $0
- add hl, bc
- jp PlaceString
-; 1cbb
-
-MenuBox:: ; 1cbb
- call MenuBoxCoord2Tile
- call GetMenuBoxDims
- dec b
- dec c
- jp TextBox
-; 1cc6
-
-GetMenuTextStartCoord:: ; 1cc6
- ld a, [wMenuBorderTopCoord]
- ld b, a
- inc b
- ld a, [wMenuBorderLeftCoord]
- ld c, a
- inc c
-; bit 6: if not set, leave extra room on top
- ld a, [wMenuDataFlags]
- bit 6, a
- jr nz, .bit_6_set
- inc b
-
-.bit_6_set
-; bit 7: if set, leave extra room on the left
- ld a, [wMenuDataFlags]
- bit 7, a
- jr z, .bit_7_clear
- inc c
-
-.bit_7_clear
- ret
-; 1ce1
-
-ClearMenuBoxInterior:: ; 1ce1
- call MenuBoxCoord2Tile
- ld bc, SCREEN_WIDTH + 1
- add hl, bc
- call GetMenuBoxDims
- dec b
- dec c
- call ClearBox
+ ld a, [hSPBuffer]
+ ld l, a
+ ld a, [hSPBuffer + 1]
+ ld h, a
+ ld sp, hl
ret
-; 1cf1
-
-ClearWholeMenuBox:: ; 1cf1
- call MenuBoxCoord2Tile
- call GetMenuBoxDims
- inc c
- inc b
- call ClearBox
+; 32f9
+
+SetPalettes:: ; 32f9
+; Inits the Palettes
+; depending on the system the monochromes palettes or color palettes
+ ld a, [hCGB]
+ and a
+ jr nz, .SetPalettesForGameBoyColor
+ ld a, %11100100
+ ld [rBGP], a
+ ld a, %11010000
+ ld [rOBP0], a
+ ld [rOBP1], a
ret
-; 1cfd
+.SetPalettesForGameBoyColor:
+ push de
+ ld a, %11100100
+ call DmgToCgbBGPals
+ lb de, %11100100, %11100100
+ call DmgToCgbObjPals
+ pop de
+ ret
+; 3317
-MenuBoxCoord2Tile:: ; 1cfd
- ld a, [wMenuBorderLeftCoord]
- ld c, a
- ld a, [wMenuBorderTopCoord]
- ld b, a
-; 1d05
+ClearPalettes:: ; 3317
+; Make all palettes white
+; CGB: make all the palette colors white
+ ld a, [hCGB]
+ and a
+ jr nz, .cgb
-Coord2Tile:: ; 1d05
-; Return the address of wTileMap(c, b) in hl.
- xor a
- ld h, a
- ld l, b
- ld a, c
- ld b, h
- ld c, l
- add hl, hl
- add hl, hl
- add hl, bc
- add hl, hl
- add hl, hl
- ld c, a
+; DMG: just change palettes to 0 (white)
xor a
- ld b, a
- add hl, bc
- bccoord 0, 0
- add hl, bc
+ ld [rBGP], a
+ ld [rOBP0], a
+ ld [rOBP1], a
ret
-; 1d19
-MenuBoxCoord2Attr:: ; 1d19
- ld a, [wMenuBorderLeftCoord]
- ld c, a
- ld a, [wMenuBorderTopCoord]
- ld b, a
+.cgb
+ ld a, [rSVBK]
+ push af
-Coord2Attr:: ; 1d21
-; Return the address of wAttrMap(c, b) in hl.
- xor a
- ld h, a
- ld l, b
- ld a, c
- ld b, h
- ld c, l
- add hl, hl
- add hl, hl
- add hl, bc
- add hl, hl
- add hl, hl
- ld c, a
- xor a
- ld b, a
- add hl, bc
- bccoord 0, 0, wAttrMap
- add hl, bc
+ ld a, BANK(wBGPals2)
+ ld [rSVBK], a
+
+; Fill wBGPals2 and wOBPals2 with $ffff (white)
+ ld hl, wBGPals2
+ ld bc, 16 palettes
+ ld a, $ff
+ call ByteFill
+
+ pop af
+ ld [rSVBK], a
+
+; Request palette update
+ ld a, 1
+ ld [hCGBPalUpdate], a
ret
-; 1d35
+; 333e
+
+GetMemSGBLayout:: ; 333e
+ ld b, SCGB_RAM
+GetSGBLayout:: ; 3340
+; load sgb packets unless dmg
+
+ ld a, [hCGB]
+ and a
+ jr nz, .sgb
+
+ ld a, [hSGB]
+ and a
+ ret z
+
+.sgb
+ predef_jump LoadSGBLayout
+; 334e