2020-02-13 09:30:13 -08:00
|
|
|
HDMATransferTilemapToWRAMBank3::
|
2015-12-22 19:19:33 -08:00
|
|
|
ld hl, .Function
|
2015-12-09 15:25:44 -08:00
|
|
|
jp CallInSafeGFXMode
|
2015-11-30 08:04:14 -08:00
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.Function:
|
2015-11-30 08:04:14 -08:00
|
|
|
decoord 0, 0
|
2020-02-13 09:30:13 -08:00
|
|
|
ld hl, wScratchTilemap
|
2017-12-24 12:03:20 -08:00
|
|
|
call PadTilemapForHDMATransfer
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, $0
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rVBK], a
|
2020-02-13 09:30:13 -08:00
|
|
|
ld hl, wScratchTilemap
|
2016-05-04 19:34:09 -07:00
|
|
|
call HDMATransferToWRAMBank3
|
2015-11-30 08:04:14 -08:00
|
|
|
ret
|
|
|
|
|
2020-02-13 09:30:13 -08:00
|
|
|
HDMATransferAttrmapToWRAMBank3:
|
2015-12-22 19:19:33 -08:00
|
|
|
ld hl, .Function
|
2015-12-09 15:25:44 -08:00
|
|
|
jp CallInSafeGFXMode
|
2015-11-30 08:04:14 -08:00
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.Function:
|
2020-02-13 09:30:13 -08:00
|
|
|
decoord 0, 0, wAttrmap
|
|
|
|
ld hl, wScratchAttrmap
|
|
|
|
call PadAttrmapForHDMATransfer
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, $1
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rVBK], a
|
2020-02-13 09:30:13 -08:00
|
|
|
ld hl, wScratchAttrmap
|
2016-05-04 19:34:09 -07:00
|
|
|
call HDMATransferToWRAMBank3
|
2015-11-30 08:04:14 -08:00
|
|
|
ret
|
|
|
|
|
2024-02-10 15:16:00 -08:00
|
|
|
HDMATransferTilemapAndAttrmap_Overworld::
|
2015-12-22 19:19:33 -08:00
|
|
|
ld hl, .Function
|
2015-12-09 15:25:44 -08:00
|
|
|
jp CallInSafeGFXMode
|
2015-11-30 08:04:14 -08:00
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.Function:
|
2023-08-28 04:30:13 -07:00
|
|
|
; Pad BG attrs with $00
|
|
|
|
; Pad BG tiles with " "
|
2020-02-13 09:30:13 -08:00
|
|
|
decoord 0, 0, wAttrmap
|
|
|
|
ld hl, wScratchAttrmap
|
|
|
|
call PadAttrmapForHDMATransfer
|
2015-11-30 08:04:14 -08:00
|
|
|
decoord 0, 0
|
2020-02-13 09:30:13 -08:00
|
|
|
ld hl, wScratchTilemap
|
2017-12-24 12:03:20 -08:00
|
|
|
call PadTilemapForHDMATransfer
|
2015-11-30 08:04:14 -08:00
|
|
|
call DelayFrame
|
2016-05-04 19:34:09 -07:00
|
|
|
|
2023-08-29 09:33:20 -07:00
|
|
|
ldh a, [hWindowHUDLY]
|
2023-08-28 08:31:39 -07:00
|
|
|
and a
|
|
|
|
jr z, .go
|
2023-08-29 09:33:20 -07:00
|
|
|
; wait until LCD interrupt has ocurred this frame ([rLY] - [hWindowHUDLY] >= 0)
|
2023-08-28 08:31:39 -07:00
|
|
|
.wait_lcd
|
2023-08-29 09:33:20 -07:00
|
|
|
; ldh a, [hWindowHUDLY]
|
2023-08-28 08:31:39 -07:00
|
|
|
ld b, a
|
|
|
|
ldh a, [rLY]
|
|
|
|
sub b
|
|
|
|
jr c, .wait_lcd
|
|
|
|
|
|
|
|
.go
|
2023-08-28 04:30:13 -07:00
|
|
|
; Transfer Attrmap and Tilemap to BG map
|
2015-11-30 08:04:14 -08:00
|
|
|
di
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [rVBK]
|
2015-11-30 08:04:14 -08:00
|
|
|
push af
|
|
|
|
ld a, $1
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rVBK], a
|
2020-02-13 09:30:13 -08:00
|
|
|
ld hl, wScratchAttrmap
|
2024-02-10 15:16:00 -08:00
|
|
|
call HDMATransfer_WaitForScanline128_toBGMap
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, $0
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rVBK], a
|
2020-02-13 09:30:13 -08:00
|
|
|
ld hl, wScratchTilemap
|
2024-02-10 15:16:00 -08:00
|
|
|
call HDMATransfer_WaitForScanline128_toBGMap
|
2015-11-30 08:04:14 -08:00
|
|
|
pop af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rVBK], a
|
2015-11-30 08:04:14 -08:00
|
|
|
ei
|
2016-05-04 19:34:09 -07:00
|
|
|
|
2015-11-30 08:04:14 -08:00
|
|
|
ret
|
|
|
|
|
2024-02-10 15:16:00 -08:00
|
|
|
_HDMATransferTilemapAndAttrmap_Menu::
|
2015-12-22 19:19:33 -08:00
|
|
|
ld hl, .Function
|
2015-12-09 15:25:44 -08:00
|
|
|
jp CallInSafeGFXMode
|
2015-11-30 08:04:14 -08:00
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.Function:
|
2023-08-28 04:30:13 -07:00
|
|
|
; Pad BG attrs with $00
|
|
|
|
; Pad BG tiles with " "
|
2020-02-13 09:30:13 -08:00
|
|
|
decoord 0, 0, wAttrmap
|
|
|
|
ld hl, wScratchAttrmap
|
|
|
|
call PadAttrmapForHDMATransfer
|
2015-11-30 08:04:14 -08:00
|
|
|
decoord 0, 0
|
2020-02-13 09:30:13 -08:00
|
|
|
ld hl, wScratchTilemap
|
2017-12-24 12:03:20 -08:00
|
|
|
call PadTilemapForHDMATransfer
|
2015-11-30 08:04:14 -08:00
|
|
|
call DelayFrame
|
2015-12-09 15:25:44 -08:00
|
|
|
|
2023-08-29 09:33:20 -07:00
|
|
|
ldh a, [hWindowHUDLY]
|
2023-08-28 08:31:39 -07:00
|
|
|
and a
|
|
|
|
jr z, .go
|
2023-08-29 09:33:20 -07:00
|
|
|
; wait until LCD interrupt has ocurred this frame ([rLY] - [hWindowHUDLY] >= 0)
|
2023-08-28 08:31:39 -07:00
|
|
|
.wait_lcd
|
2023-08-29 09:33:20 -07:00
|
|
|
; ldh a, [hWindowHUDLY]
|
2023-08-28 08:31:39 -07:00
|
|
|
ld b, a
|
|
|
|
ldh a, [rLY]
|
|
|
|
sub b
|
|
|
|
jr c, .wait_lcd
|
|
|
|
|
|
|
|
.go
|
2023-08-28 04:30:13 -07:00
|
|
|
; Transfer Attrmap and Tilemap to BG map
|
2015-11-30 08:04:14 -08:00
|
|
|
di
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [rVBK]
|
2015-11-30 08:04:14 -08:00
|
|
|
push af
|
|
|
|
ld a, $1
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rVBK], a
|
2020-02-13 09:30:13 -08:00
|
|
|
ld hl, wScratchAttrmap
|
2024-02-10 15:16:00 -08:00
|
|
|
call HDMATransfer_WaitForScanline124_toBGMap
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, $0
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rVBK], a
|
2020-02-13 09:30:13 -08:00
|
|
|
ld hl, wScratchTilemap
|
2024-02-10 15:16:00 -08:00
|
|
|
call HDMATransfer_WaitForScanline124_toBGMap
|
2015-11-30 08:04:14 -08:00
|
|
|
pop af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rVBK], a
|
2015-11-30 08:04:14 -08:00
|
|
|
ei
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CallInSafeGFXMode:
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hBGMapMode]
|
2015-11-30 08:04:14 -08:00
|
|
|
push af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMapAnims]
|
2015-11-30 08:04:14 -08:00
|
|
|
push af
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hBGMapMode], a
|
|
|
|
ldh [hMapAnims], a
|
|
|
|
ldh a, [rSVBK]
|
2015-11-30 08:04:14 -08:00
|
|
|
push af
|
2020-02-13 09:30:13 -08:00
|
|
|
ld a, BANK(wScratchTilemap)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSVBK], a
|
|
|
|
ldh a, [rVBK]
|
2015-11-30 08:04:14 -08:00
|
|
|
push af
|
2015-12-09 15:25:44 -08:00
|
|
|
|
2015-11-30 08:04:14 -08:00
|
|
|
call ._hl_
|
2015-12-09 15:25:44 -08:00
|
|
|
|
2015-11-30 08:04:14 -08:00
|
|
|
pop af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rVBK], a
|
2015-11-30 08:04:14 -08:00
|
|
|
pop af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSVBK], a
|
2015-11-30 08:04:14 -08:00
|
|
|
pop af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMapAnims], a
|
2015-11-30 08:04:14 -08:00
|
|
|
pop af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hBGMapMode], a
|
2015-11-30 08:04:14 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
._hl_
|
2017-06-09 14:01:10 -07:00
|
|
|
jp hl
|
2015-11-30 08:04:14 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
HDMATransferToWRAMBank3:
|
2016-05-04 19:34:09 -07:00
|
|
|
call _LoadHDMAParameters
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, $23
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hDMATransfer], a
|
2015-11-30 08:04:14 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
WaitDMATransfer:
|
2015-12-22 19:19:33 -08:00
|
|
|
.loop
|
2015-11-30 08:04:14 -08:00
|
|
|
call DelayFrame
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hDMATransfer]
|
2015-11-30 08:04:14 -08:00
|
|
|
and a
|
2015-12-22 19:19:33 -08:00
|
|
|
jr nz, .loop
|
2015-11-30 08:04:14 -08:00
|
|
|
ret
|
|
|
|
|
2024-02-10 15:16:00 -08:00
|
|
|
HDMATransfer_WaitForScanline128_toBGMap:
|
2016-05-04 19:34:09 -07:00
|
|
|
; HDMA transfer from hl to [hBGMapAddress]
|
|
|
|
; hBGMapAddress -> de
|
|
|
|
; 2 * SCREEN_HEIGHT -> c
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hBGMapAddress + 1]
|
2015-11-30 08:04:14 -08:00
|
|
|
ld d, a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hBGMapAddress]
|
2015-11-30 08:04:14 -08:00
|
|
|
ld e, a
|
2016-05-04 19:34:09 -07:00
|
|
|
ld c, 2 * SCREEN_HEIGHT
|
2024-02-10 15:16:00 -08:00
|
|
|
jr HDMATransfer_WaitForScanline128
|
2015-11-30 08:04:14 -08:00
|
|
|
|
2024-02-10 15:16:00 -08:00
|
|
|
HDMATransfer_WaitForScanline124_toBGMap:
|
2016-05-04 19:34:09 -07:00
|
|
|
; HDMA transfer from hl to [hBGMapAddress]
|
2015-12-09 15:25:44 -08:00
|
|
|
; hBGMapAddress -> de
|
2016-05-04 19:34:09 -07:00
|
|
|
; 2 * SCREEN_HEIGHT -> c
|
2015-12-09 15:25:44 -08:00
|
|
|
; $7b --> b
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hBGMapAddress + 1]
|
2015-11-30 08:04:14 -08:00
|
|
|
ld d, a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hBGMapAddress]
|
2015-11-30 08:04:14 -08:00
|
|
|
ld e, a
|
2016-05-04 19:34:09 -07:00
|
|
|
ld c, 2 * SCREEN_HEIGHT
|
2024-02-10 15:16:00 -08:00
|
|
|
jr HDMATransfer_WaitForScanline124
|
2015-11-30 08:04:14 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
HDMATransfer_NoDI:
|
2016-05-04 19:34:09 -07:00
|
|
|
; HDMA transfer from hl to [hBGMapAddress]
|
|
|
|
; [hBGMapAddress] --> de
|
|
|
|
; 2 * SCREEN_HEIGHT --> c
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hBGMapAddress + 1]
|
2015-11-30 08:04:14 -08:00
|
|
|
ld d, a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hBGMapAddress]
|
2015-11-30 08:04:14 -08:00
|
|
|
ld e, a
|
2016-05-04 19:34:09 -07:00
|
|
|
ld c, 2 * SCREEN_HEIGHT
|
|
|
|
|
|
|
|
; [rHDMA1, rHDMA2] = hl & $fff0
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, h
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rHDMA1], a
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, l
|
|
|
|
and $f0
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rHDMA2], a
|
2016-05-04 19:34:09 -07:00
|
|
|
; [rHDMA3, rHDMA4] = de & $1ff0
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, d
|
|
|
|
and $1f
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rHDMA3], a
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, e
|
|
|
|
and $f0
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rHDMA4], a
|
2016-05-04 19:34:09 -07:00
|
|
|
; b = c | %10000000
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, c
|
|
|
|
dec c
|
|
|
|
or $80
|
|
|
|
ld b, a
|
2016-05-04 19:34:09 -07:00
|
|
|
; d = $7f - c + 1
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, $7f
|
|
|
|
sub c
|
|
|
|
ld d, a
|
2016-05-04 19:34:09 -07:00
|
|
|
; while [rLY] >= d: pass
|
2015-11-30 08:04:14 -08:00
|
|
|
.loop1
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [rLY]
|
2015-11-30 08:04:14 -08:00
|
|
|
cp d
|
|
|
|
jr nc, .loop1
|
2016-05-04 19:34:09 -07:00
|
|
|
; while not [rSTAT] & 3: pass
|
2015-11-30 08:04:14 -08:00
|
|
|
.loop2
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [rSTAT]
|
2023-08-27 07:27:11 -07:00
|
|
|
and rSTAT_STATUS_FLAGS
|
2015-11-30 08:04:14 -08:00
|
|
|
jr z, .loop2
|
2016-05-04 19:34:09 -07:00
|
|
|
; load the 5th byte of HDMA
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, b
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rHDMA5], a
|
2016-05-04 19:34:09 -07:00
|
|
|
; wait until rLY advances (c + 1) times
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [rLY]
|
2015-11-30 08:04:14 -08:00
|
|
|
inc c
|
|
|
|
ld hl, rLY
|
|
|
|
.loop3
|
|
|
|
cp [hl]
|
|
|
|
jr z, .loop3
|
|
|
|
ld a, [hl]
|
|
|
|
dec c
|
|
|
|
jr nz, .loop3
|
|
|
|
ld hl, rHDMA5
|
|
|
|
res 7, [hl]
|
|
|
|
ret
|
|
|
|
|
2024-02-10 15:16:00 -08:00
|
|
|
HDMATransfer_WaitForScanline124:
|
2023-08-28 04:30:13 -07:00
|
|
|
ld b, 124 - 1
|
2016-05-04 19:34:09 -07:00
|
|
|
jr _continue_HDMATransfer
|
2015-11-30 08:04:14 -08:00
|
|
|
|
2024-02-10 15:16:00 -08:00
|
|
|
HDMATransfer_WaitForScanline128:
|
2023-08-28 04:30:13 -07:00
|
|
|
ld b, 128 - 1
|
2016-05-04 19:34:09 -07:00
|
|
|
_continue_HDMATransfer:
|
|
|
|
; a lot of waiting around for hardware registers
|
|
|
|
; [rHDMA1, rHDMA2] = hl & $fff0
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, h
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rHDMA1], a
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, l
|
|
|
|
and $f0 ; high nybble
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rHDMA2], a
|
2016-05-04 19:34:09 -07:00
|
|
|
; [rHDMA3, rHDMA4] = de & $1ff0
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, d
|
|
|
|
and $1f ; lower 5 bits
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rHDMA3], a
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, e
|
|
|
|
and $f0 ; high nybble
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rHDMA4], a
|
2016-05-04 19:34:09 -07:00
|
|
|
; e = c | %10000000
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, c
|
|
|
|
dec c
|
2016-05-04 19:34:09 -07:00
|
|
|
or $80
|
2015-11-30 08:04:14 -08:00
|
|
|
ld e, a
|
2016-05-04 19:34:09 -07:00
|
|
|
; d = b - c + 1
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, b
|
|
|
|
sub c
|
|
|
|
ld d, a
|
2016-05-04 19:34:09 -07:00
|
|
|
; while [rLY] >= d: pass
|
2015-11-30 08:04:14 -08:00
|
|
|
.ly_loop
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [rLY]
|
2015-11-30 08:04:14 -08:00
|
|
|
cp d
|
|
|
|
jr nc, .ly_loop
|
|
|
|
|
2023-08-29 09:33:20 -07:00
|
|
|
ldh a, [hWindowHUDLY]
|
2023-08-28 08:31:39 -07:00
|
|
|
and a
|
|
|
|
jr z, .go
|
2023-08-29 09:33:20 -07:00
|
|
|
; wait until LCD interrupt has ocurred this frame ([rLY] - [hWindowHUDLY] >= 0)
|
2023-08-28 08:31:39 -07:00
|
|
|
.wait_lcd
|
2023-08-29 09:33:20 -07:00
|
|
|
; ldh a, [hWindowHUDLY]
|
2023-08-28 08:31:39 -07:00
|
|
|
ld b, a
|
|
|
|
ldh a, [rLY]
|
|
|
|
sub b
|
|
|
|
jr c, .wait_lcd
|
|
|
|
|
|
|
|
.go
|
2015-11-30 08:04:14 -08:00
|
|
|
di
|
2016-05-04 19:34:09 -07:00
|
|
|
; while [rSTAT] & 3: pass
|
2015-11-30 08:04:14 -08:00
|
|
|
.rstat_loop_1
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [rSTAT]
|
2023-08-27 07:27:11 -07:00
|
|
|
and rSTAT_STATUS_FLAGS
|
2015-11-30 08:04:14 -08:00
|
|
|
jr nz, .rstat_loop_1
|
2016-05-04 19:34:09 -07:00
|
|
|
; while not [rSTAT] & 3: pass
|
2015-11-30 08:04:14 -08:00
|
|
|
.rstat_loop_2
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [rSTAT]
|
2023-08-27 07:27:11 -07:00
|
|
|
and rSTAT_STATUS_FLAGS
|
2015-11-30 08:04:14 -08:00
|
|
|
jr z, .rstat_loop_2
|
2016-05-04 19:34:09 -07:00
|
|
|
; load the 5th byte of HDMA
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, e
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rHDMA5], a
|
2016-05-04 19:34:09 -07:00
|
|
|
; wait until rLY advances (c + 1) times
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [rLY]
|
2015-11-30 08:04:14 -08:00
|
|
|
inc c
|
|
|
|
ld hl, rLY
|
|
|
|
.final_ly_loop
|
|
|
|
cp [hl]
|
|
|
|
jr z, .final_ly_loop
|
|
|
|
ld a, [hl]
|
|
|
|
dec c
|
|
|
|
jr nz, .final_ly_loop
|
|
|
|
ld hl, rHDMA5
|
|
|
|
res 7, [hl]
|
|
|
|
ei
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
_LoadHDMAParameters:
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, h
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rHDMA1], a
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, l
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rHDMA2], a
|
|
|
|
ldh a, [hBGMapAddress + 1]
|
2015-11-30 08:04:14 -08:00
|
|
|
and $1f
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rHDMA3], a
|
|
|
|
ldh a, [hBGMapAddress]
|
|
|
|
ldh [rHDMA4], a
|
2015-11-30 08:04:14 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
PadTilemapForHDMATransfer:
|
2015-11-30 08:04:14 -08:00
|
|
|
ld c, " "
|
2017-12-24 12:03:20 -08:00
|
|
|
jr PadMapForHDMATransfer
|
2015-11-30 08:04:14 -08:00
|
|
|
|
2020-02-13 09:30:13 -08:00
|
|
|
PadAttrmapForHDMATransfer:
|
2015-11-30 08:04:14 -08:00
|
|
|
ld c, $0
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
PadMapForHDMATransfer:
|
2017-12-24 12:03:20 -08:00
|
|
|
; pad a 20x18 map to 32x18 for HDMA transfer
|
2020-12-23 13:54:28 -08:00
|
|
|
; back up the padding value in c to hMapObjectIndex
|
|
|
|
ldh a, [hMapObjectIndex]
|
2015-11-30 08:04:14 -08:00
|
|
|
push af
|
|
|
|
ld a, c
|
2020-12-23 13:54:28 -08:00
|
|
|
ldh [hMapObjectIndex], a
|
2015-11-30 08:04:14 -08:00
|
|
|
|
|
|
|
; for each row on the screen
|
|
|
|
ld c, SCREEN_HEIGHT
|
|
|
|
.loop1
|
|
|
|
; for each tile in the row
|
|
|
|
ld b, SCREEN_WIDTH
|
|
|
|
.loop2
|
|
|
|
; copy from de to hl
|
|
|
|
ld a, [de]
|
|
|
|
inc de
|
|
|
|
ld [hli], a
|
|
|
|
dec b
|
|
|
|
jr nz, .loop2
|
|
|
|
|
2017-12-24 12:03:20 -08:00
|
|
|
; load the original padding value of c into hl for 32 - 20 = 12 rows
|
2020-12-23 13:54:28 -08:00
|
|
|
ldh a, [hMapObjectIndex]
|
2016-05-04 19:34:09 -07:00
|
|
|
ld b, BG_MAP_WIDTH - SCREEN_WIDTH
|
2015-11-30 08:04:14 -08:00
|
|
|
.loop3
|
|
|
|
ld [hli], a
|
|
|
|
dec b
|
|
|
|
jr nz, .loop3
|
|
|
|
|
|
|
|
dec c
|
|
|
|
jr nz, .loop1
|
|
|
|
|
2020-12-23 13:54:28 -08:00
|
|
|
; restore the original value of hMapObjectIndex
|
2015-11-30 08:04:14 -08:00
|
|
|
pop af
|
2020-12-23 13:54:28 -08:00
|
|
|
ldh [hMapObjectIndex], a
|
2015-11-30 08:04:14 -08:00
|
|
|
ret
|
|
|
|
|
2020-05-17 17:59:15 -07:00
|
|
|
HDMATransfer2bpp::
|
2015-11-30 08:04:14 -08:00
|
|
|
; 2bpp when [rLCDC] & $80
|
|
|
|
; switch to WRAM bank 6
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [rSVBK]
|
2015-11-30 08:04:14 -08:00
|
|
|
push af
|
2020-02-13 09:30:13 -08:00
|
|
|
ld a, BANK(wScratchTilemap)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSVBK], a
|
2015-11-30 08:04:14 -08:00
|
|
|
|
|
|
|
push bc
|
|
|
|
push hl
|
|
|
|
|
2020-02-13 09:30:13 -08:00
|
|
|
; Copy c tiles of the 2bpp from b:de to wScratchTilemap
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, b ; bank
|
|
|
|
ld l, c ; number of tiles
|
|
|
|
ld h, $0
|
2016-05-08 11:11:24 -07:00
|
|
|
; multiply by 16 (16 bytes of a 2bpp = 8 x 8 tile)
|
|
|
|
add hl, hl
|
|
|
|
add hl, hl
|
|
|
|
add hl, hl
|
|
|
|
add hl, hl
|
2015-11-30 08:04:14 -08:00
|
|
|
ld b, h
|
|
|
|
ld c, l
|
|
|
|
ld h, d ; address
|
|
|
|
ld l, e
|
2020-02-13 09:30:13 -08:00
|
|
|
ld de, wScratchTilemap
|
2015-11-30 08:04:14 -08:00
|
|
|
call FarCopyBytes
|
2016-04-10 11:42:14 -07:00
|
|
|
|
2015-11-30 08:04:14 -08:00
|
|
|
pop hl
|
|
|
|
pop bc
|
|
|
|
|
|
|
|
push bc
|
|
|
|
call DelayFrame
|
|
|
|
pop bc
|
|
|
|
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
2020-02-13 09:30:13 -08:00
|
|
|
ld hl, wScratchTilemap
|
2024-02-10 15:16:00 -08:00
|
|
|
call HDMATransfer_WaitForScanline128
|
2015-11-30 08:04:14 -08:00
|
|
|
|
|
|
|
; restore the previous bank
|
|
|
|
pop af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSVBK], a
|
2015-11-30 08:04:14 -08:00
|
|
|
ret
|
|
|
|
|
2020-05-17 17:59:15 -07:00
|
|
|
HDMATransfer1bpp::
|
2015-11-30 08:04:14 -08:00
|
|
|
; 1bpp when [rLCDC] & $80
|
|
|
|
.loop
|
|
|
|
ld a, c
|
|
|
|
cp $10
|
|
|
|
jp c, .bankswitch
|
|
|
|
jp z, .bankswitch
|
|
|
|
push bc
|
|
|
|
push hl
|
|
|
|
push de
|
|
|
|
ld c, $10
|
|
|
|
call .bankswitch
|
|
|
|
pop de
|
|
|
|
ld hl, $80
|
|
|
|
add hl, de
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
|
|
|
pop hl
|
|
|
|
lb bc, 1, 0
|
|
|
|
add hl, bc
|
|
|
|
pop bc
|
|
|
|
ld a, c
|
|
|
|
sub $10
|
|
|
|
ld c, a
|
|
|
|
jr .loop
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.bankswitch
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [rSVBK]
|
2015-11-30 08:04:14 -08:00
|
|
|
push af
|
2020-02-13 09:30:13 -08:00
|
|
|
ld a, BANK(wScratchTilemap)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSVBK], a
|
2015-11-30 08:04:14 -08:00
|
|
|
|
|
|
|
push bc
|
|
|
|
push hl
|
|
|
|
|
|
|
|
ld a, b
|
|
|
|
ld l, c
|
|
|
|
ld h, $0
|
|
|
|
add hl, hl ; multiply by 8
|
2016-05-10 09:31:49 -07:00
|
|
|
add hl, hl ; multiply by 8
|
|
|
|
add hl, hl ; multiply by 8
|
2015-11-30 08:04:14 -08:00
|
|
|
ld c, l
|
|
|
|
ld b, h
|
|
|
|
ld h, d
|
|
|
|
ld l, e
|
2020-02-13 09:30:13 -08:00
|
|
|
ld de, wScratchTilemap
|
2015-11-30 08:04:14 -08:00
|
|
|
call FarCopyBytesDouble_DoubleBankSwitch
|
|
|
|
|
|
|
|
pop hl
|
|
|
|
pop bc
|
|
|
|
|
|
|
|
push bc
|
|
|
|
call DelayFrame
|
|
|
|
pop bc
|
|
|
|
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
2020-02-13 09:30:13 -08:00
|
|
|
ld hl, wScratchTilemap
|
2024-02-10 15:16:00 -08:00
|
|
|
call HDMATransfer_WaitForScanline128
|
2015-11-30 08:04:14 -08:00
|
|
|
|
|
|
|
pop af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSVBK], a
|
2015-11-30 08:04:14 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
HDMATransfer_OnlyTopFourRows:
|
2016-05-04 19:34:09 -07:00
|
|
|
ld hl, .Function
|
2015-12-09 15:25:44 -08:00
|
|
|
jp CallInSafeGFXMode
|
2015-11-30 08:04:14 -08:00
|
|
|
|
2016-05-04 19:34:09 -07:00
|
|
|
.Function:
|
2020-02-13 09:30:13 -08:00
|
|
|
ld hl, wScratchTilemap
|
2015-11-30 08:04:14 -08:00
|
|
|
decoord 0, 0
|
2016-05-04 19:34:09 -07:00
|
|
|
call .Copy
|
2020-02-13 09:30:13 -08:00
|
|
|
ld hl, wScratchTilemap + $80
|
|
|
|
decoord 0, 0, wAttrmap
|
2016-05-04 19:34:09 -07:00
|
|
|
call .Copy
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, $1
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rVBK], a
|
2015-11-30 08:04:14 -08:00
|
|
|
ld c, $8
|
2020-02-13 09:30:13 -08:00
|
|
|
ld hl, wScratchTilemap + $80
|
2017-12-28 04:32:33 -08:00
|
|
|
debgcoord 0, 0, vBGMap1
|
2024-02-10 15:16:00 -08:00
|
|
|
call HDMATransfer_WaitForScanline128
|
2015-11-30 08:04:14 -08:00
|
|
|
ld a, $0
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rVBK], a
|
2015-11-30 08:04:14 -08:00
|
|
|
ld c, $8
|
2020-02-13 09:30:13 -08:00
|
|
|
ld hl, wScratchTilemap
|
2017-12-28 04:32:33 -08:00
|
|
|
debgcoord 0, 0, vBGMap1
|
2024-02-10 15:16:00 -08:00
|
|
|
call HDMATransfer_WaitForScanline128
|
2015-11-30 08:04:14 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.Copy:
|
2015-11-30 08:04:14 -08:00
|
|
|
ld b, 4
|
|
|
|
.outer_loop
|
|
|
|
ld c, SCREEN_WIDTH
|
|
|
|
.inner_loop
|
|
|
|
ld a, [de]
|
|
|
|
ld [hli], a
|
|
|
|
inc de
|
|
|
|
dec c
|
|
|
|
jr nz, .inner_loop
|
|
|
|
ld a, l
|
2016-05-04 19:34:09 -07:00
|
|
|
add BG_MAP_WIDTH - SCREEN_WIDTH
|
2015-11-30 08:04:14 -08:00
|
|
|
ld l, a
|
|
|
|
ld a, h
|
2018-02-04 10:16:40 -08:00
|
|
|
adc 0
|
2015-11-30 08:04:14 -08:00
|
|
|
ld h, a
|
|
|
|
dec b
|
|
|
|
jr nz, .outer_loop
|
|
|
|
ret
|