2020-02-13 17:30:13 +00:00
|
|
|
HDMATransferAttrmapAndTilemapToWRAMBank3::
|
2015-12-23 03:19:33 +00:00
|
|
|
ld hl, .Function
|
2015-12-09 23:25:44 +00:00
|
|
|
jp CallInSafeGFXMode
|
2015-11-30 16:04:14 +00:00
|
|
|
|
2016-04-10 18:42:14 +00:00
|
|
|
.Function:
|
2020-02-13 17:30:13 +00:00
|
|
|
decoord 0, 0, wAttrmap
|
|
|
|
ld hl, wScratchAttrmap
|
|
|
|
call PadAttrmapForHDMATransfer
|
2015-11-30 16:04:14 +00:00
|
|
|
decoord 0, 0
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchTilemap
|
2017-12-24 20:03:20 +00:00
|
|
|
call PadTilemapForHDMATransfer
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, $0
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchTilemap
|
2016-05-05 02:34:09 +00:00
|
|
|
call HDMATransferToWRAMBank3
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, $1
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchAttrmap
|
2016-05-05 02:34:09 +00:00
|
|
|
call HDMATransferToWRAMBank3
|
2015-11-30 16:04:14 +00:00
|
|
|
ret
|
|
|
|
|
2020-02-13 17:30:13 +00:00
|
|
|
HDMATransferTilemapToWRAMBank3::
|
2015-12-23 03:19:33 +00:00
|
|
|
ld hl, .Function
|
2015-12-09 23:25:44 +00:00
|
|
|
jp CallInSafeGFXMode
|
2015-11-30 16:04:14 +00:00
|
|
|
|
2016-04-10 18:42:14 +00:00
|
|
|
.Function:
|
2015-11-30 16:04:14 +00:00
|
|
|
decoord 0, 0
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchTilemap
|
2017-12-24 20:03:20 +00:00
|
|
|
call PadTilemapForHDMATransfer
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, $0
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchTilemap
|
2016-05-05 02:34:09 +00:00
|
|
|
call HDMATransferToWRAMBank3
|
2015-11-30 16:04:14 +00:00
|
|
|
ret
|
|
|
|
|
2020-02-13 17:30:13 +00:00
|
|
|
HDMATransferAttrmapToWRAMBank3:
|
2015-12-23 03:19:33 +00:00
|
|
|
ld hl, .Function
|
2015-12-09 23:25:44 +00:00
|
|
|
jp CallInSafeGFXMode
|
2015-11-30 16:04:14 +00:00
|
|
|
|
2016-04-10 18:42:14 +00:00
|
|
|
.Function:
|
2020-02-13 17:30:13 +00:00
|
|
|
decoord 0, 0, wAttrmap
|
|
|
|
ld hl, wScratchAttrmap
|
|
|
|
call PadAttrmapForHDMATransfer
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, $1
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchAttrmap
|
2016-05-05 02:34:09 +00:00
|
|
|
call HDMATransferToWRAMBank3
|
2015-11-30 16:04:14 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
ReloadMapPart::
|
2015-12-23 03:19:33 +00:00
|
|
|
ld hl, .Function
|
2015-12-09 23:25:44 +00:00
|
|
|
jp CallInSafeGFXMode
|
2015-11-30 16:04:14 +00:00
|
|
|
|
2016-04-10 18:42:14 +00:00
|
|
|
.Function:
|
2020-02-13 17:30:13 +00:00
|
|
|
decoord 0, 0, wAttrmap
|
|
|
|
ld hl, wScratchAttrmap
|
|
|
|
call PadAttrmapForHDMATransfer
|
2015-11-30 16:04:14 +00:00
|
|
|
decoord 0, 0
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchTilemap
|
2017-12-24 20:03:20 +00:00
|
|
|
call PadTilemapForHDMATransfer
|
2015-11-30 16:04:14 +00:00
|
|
|
call DelayFrame
|
2016-05-05 02:34:09 +00:00
|
|
|
|
2015-11-30 16:04:14 +00:00
|
|
|
di
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [rVBK]
|
2015-11-30 16:04:14 +00:00
|
|
|
push af
|
|
|
|
ld a, $1
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchAttrmap
|
2016-05-05 02:34:09 +00:00
|
|
|
call HDMATransfer_Wait127Scanlines_toBGMap
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, $0
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchTilemap
|
2016-05-05 02:34:09 +00:00
|
|
|
call HDMATransfer_Wait127Scanlines_toBGMap
|
2015-11-30 16:04:14 +00:00
|
|
|
pop af
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ei
|
2016-05-05 02:34:09 +00:00
|
|
|
|
2015-11-30 16:04:14 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
Mobile_ReloadMapPart:
|
2015-11-30 16:04:14 +00:00
|
|
|
ld hl, ReloadMapPart ; useless
|
2015-12-23 03:19:33 +00:00
|
|
|
ld hl, .Function
|
2015-12-09 23:25:44 +00:00
|
|
|
jp CallInSafeGFXMode
|
2015-11-30 16:04:14 +00:00
|
|
|
|
2016-04-10 18:42:14 +00:00
|
|
|
.Function:
|
2020-02-13 17:30:13 +00:00
|
|
|
decoord 0, 0, wAttrmap
|
|
|
|
ld hl, wScratchAttrmap
|
|
|
|
call PadAttrmapForHDMATransfer
|
2015-11-30 16:04:14 +00:00
|
|
|
decoord 0, 0
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchTilemap
|
2017-12-24 20:03:20 +00:00
|
|
|
call PadTilemapForHDMATransfer
|
2015-11-30 16:04:14 +00:00
|
|
|
call DelayFrame
|
2016-05-05 02:34:09 +00:00
|
|
|
|
2015-11-30 16:04:14 +00:00
|
|
|
di
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [rVBK]
|
2015-11-30 16:04:14 +00:00
|
|
|
push af
|
|
|
|
ld a, $1
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchAttrmap
|
2016-05-05 02:34:09 +00:00
|
|
|
call HDMATransfer_NoDI
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, $0
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchTilemap
|
2016-05-05 02:34:09 +00:00
|
|
|
call HDMATransfer_NoDI
|
2015-11-30 16:04:14 +00:00
|
|
|
pop af
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ei
|
2016-05-05 02:34:09 +00:00
|
|
|
|
2015-11-30 16:04:14 +00:00
|
|
|
ret
|
|
|
|
|
2018-01-02 12:24:05 +00:00
|
|
|
; unused
|
2016-05-05 02:34:09 +00:00
|
|
|
ld hl, .unreferenced_1040da
|
2015-12-09 23:25:44 +00:00
|
|
|
jp CallInSafeGFXMode
|
2015-11-30 16:04:14 +00:00
|
|
|
|
2016-05-05 02:34:09 +00:00
|
|
|
.unreferenced_1040da
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, $1
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2018-01-04 20:06:11 +00:00
|
|
|
ld a, BANK(w3_d800)
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rSVBK], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ld de, w3_d800
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hBGMapAddress + 1]
|
|
|
|
ldh [rHDMA1], a
|
|
|
|
ldh a, [hBGMapAddress]
|
|
|
|
ldh [rHDMA2], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, d
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rHDMA3], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, e
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rHDMA4], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, $23
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hDMATransfer], a
|
2015-12-23 03:19:33 +00:00
|
|
|
call WaitDMATransfer
|
2015-11-30 16:04:14 +00:00
|
|
|
ret
|
|
|
|
|
2018-01-02 12:24:05 +00:00
|
|
|
; unused
|
2016-05-05 02:34:09 +00:00
|
|
|
ld hl, .unreferenced_104101
|
2015-12-09 23:25:44 +00:00
|
|
|
jp CallInSafeGFXMode
|
2015-11-30 16:04:14 +00:00
|
|
|
|
2016-05-05 02:34:09 +00:00
|
|
|
.unreferenced_104101
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, $1
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2018-01-04 00:12:45 +00:00
|
|
|
ld a, BANK(w3_d800)
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rSVBK], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ld hl, w3_d800
|
2016-05-05 02:34:09 +00:00
|
|
|
call HDMATransferToWRAMBank3
|
2015-11-30 16:04:14 +00:00
|
|
|
ret
|
|
|
|
|
2020-02-13 17:30:13 +00:00
|
|
|
OpenAndCloseMenu_HDMATransferTilemapAndAttrmap::
|
2015-12-09 23:25:44 +00:00
|
|
|
; OpenText
|
2015-12-23 03:19:33 +00:00
|
|
|
ld hl, .Function
|
2015-12-09 23:25:44 +00:00
|
|
|
jp CallInSafeGFXMode
|
2015-11-30 16:04:14 +00:00
|
|
|
|
2016-04-10 18:42:14 +00:00
|
|
|
.Function:
|
2020-02-13 17:30:13 +00:00
|
|
|
; Transfer wAttrmap and Tilemap to BGMap
|
2016-05-05 02:34:09 +00:00
|
|
|
; Fill vBGAttrs with $00
|
|
|
|
; Fill vBGTiles with " "
|
2020-02-13 17:30:13 +00:00
|
|
|
decoord 0, 0, wAttrmap
|
|
|
|
ld hl, wScratchAttrmap
|
|
|
|
call PadAttrmapForHDMATransfer
|
2015-11-30 16:04:14 +00:00
|
|
|
decoord 0, 0
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchTilemap
|
2017-12-24 20:03:20 +00:00
|
|
|
call PadTilemapForHDMATransfer
|
2015-11-30 16:04:14 +00:00
|
|
|
call DelayFrame
|
2015-12-09 23:25:44 +00:00
|
|
|
|
2015-11-30 16:04:14 +00:00
|
|
|
di
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [rVBK]
|
2015-11-30 16:04:14 +00:00
|
|
|
push af
|
|
|
|
ld a, $1
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchAttrmap
|
2016-05-05 02:34:09 +00:00
|
|
|
call HDMATransfer_Wait123Scanlines_toBGMap
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, $0
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchTilemap
|
2016-05-05 02:34:09 +00:00
|
|
|
call HDMATransfer_Wait123Scanlines_toBGMap
|
2015-11-30 16:04:14 +00:00
|
|
|
pop af
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ei
|
|
|
|
ret
|
|
|
|
|
2020-02-13 17:30:13 +00:00
|
|
|
Mobile_OpenAndCloseMenu_HDMATransferTilemapAndAttrmap:
|
2015-12-23 03:19:33 +00:00
|
|
|
ld hl, .Function
|
2015-12-09 23:25:44 +00:00
|
|
|
jp CallInSafeGFXMode
|
2015-11-30 16:04:14 +00:00
|
|
|
|
2016-04-10 18:42:14 +00:00
|
|
|
.Function:
|
2020-02-13 17:30:13 +00:00
|
|
|
; Transfer wAttrmap and Tilemap to BGMap
|
2016-05-05 02:34:09 +00:00
|
|
|
; Fill vBGAttrs with $00
|
|
|
|
; Fill vBGTiles with $ff
|
2020-02-13 17:30:13 +00:00
|
|
|
decoord 0, 0, wAttrmap
|
|
|
|
ld hl, wScratchAttrmap
|
|
|
|
call PadAttrmapForHDMATransfer
|
2015-11-30 16:04:14 +00:00
|
|
|
ld c, $ff
|
|
|
|
decoord 0, 0
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchTilemap
|
2017-12-24 20:03:20 +00:00
|
|
|
call PadMapForHDMATransfer
|
2016-05-05 02:34:09 +00:00
|
|
|
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, $1
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchAttrmap
|
2016-05-05 02:34:09 +00:00
|
|
|
call HDMATransfer_Wait127Scanlines_toBGMap
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, $0
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchTilemap
|
2016-05-05 02:34:09 +00:00
|
|
|
call HDMATransfer_Wait127Scanlines_toBGMap
|
2015-11-30 16:04:14 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CallInSafeGFXMode:
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hBGMapMode]
|
2015-11-30 16:04:14 +00:00
|
|
|
push af
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hMapAnims]
|
2015-11-30 16:04:14 +00:00
|
|
|
push af
|
|
|
|
xor a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hBGMapMode], a
|
|
|
|
ldh [hMapAnims], a
|
|
|
|
ldh a, [rSVBK]
|
2015-11-30 16:04:14 +00:00
|
|
|
push af
|
2020-02-13 17:30:13 +00:00
|
|
|
ld a, BANK(wScratchTilemap)
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rSVBK], a
|
|
|
|
ldh a, [rVBK]
|
2015-11-30 16:04:14 +00:00
|
|
|
push af
|
2015-12-09 23:25:44 +00:00
|
|
|
|
2015-11-30 16:04:14 +00:00
|
|
|
call ._hl_
|
2015-12-09 23:25:44 +00:00
|
|
|
|
2015-11-30 16:04:14 +00:00
|
|
|
pop af
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2015-11-30 16:04:14 +00:00
|
|
|
pop af
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rSVBK], a
|
2015-11-30 16:04:14 +00:00
|
|
|
pop af
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hMapAnims], a
|
2015-11-30 16:04:14 +00:00
|
|
|
pop af
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hBGMapMode], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
._hl_
|
2017-06-09 21:01:10 +00:00
|
|
|
jp hl
|
2015-11-30 16:04:14 +00:00
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
HDMATransferToWRAMBank3:
|
2016-05-05 02:34:09 +00:00
|
|
|
call _LoadHDMAParameters
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, $23
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hDMATransfer], a
|
2015-11-30 16:04:14 +00:00
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
WaitDMATransfer:
|
2015-12-23 03:19:33 +00:00
|
|
|
.loop
|
2015-11-30 16:04:14 +00:00
|
|
|
call DelayFrame
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hDMATransfer]
|
2015-11-30 16:04:14 +00:00
|
|
|
and a
|
2015-12-23 03:19:33 +00:00
|
|
|
jr nz, .loop
|
2015-11-30 16:04:14 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
HDMATransfer_Wait127Scanlines_toBGMap:
|
2016-05-05 02:34:09 +00:00
|
|
|
; HDMA transfer from hl to [hBGMapAddress]
|
|
|
|
; hBGMapAddress -> de
|
|
|
|
; 2 * SCREEN_HEIGHT -> c
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hBGMapAddress + 1]
|
2015-11-30 16:04:14 +00:00
|
|
|
ld d, a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hBGMapAddress]
|
2015-11-30 16:04:14 +00:00
|
|
|
ld e, a
|
2016-05-05 02:34:09 +00:00
|
|
|
ld c, 2 * SCREEN_HEIGHT
|
|
|
|
jr HDMATransfer_Wait127Scanlines
|
2015-11-30 16:04:14 +00:00
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
HDMATransfer_Wait123Scanlines_toBGMap:
|
2016-05-05 02:34:09 +00:00
|
|
|
; HDMA transfer from hl to [hBGMapAddress]
|
2015-12-09 23:25:44 +00:00
|
|
|
; hBGMapAddress -> de
|
2016-05-05 02:34:09 +00:00
|
|
|
; 2 * SCREEN_HEIGHT -> c
|
2015-12-09 23:25:44 +00:00
|
|
|
; $7b --> b
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hBGMapAddress + 1]
|
2015-11-30 16:04:14 +00:00
|
|
|
ld d, a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hBGMapAddress]
|
2015-11-30 16:04:14 +00:00
|
|
|
ld e, a
|
2016-05-05 02:34:09 +00:00
|
|
|
ld c, 2 * SCREEN_HEIGHT
|
|
|
|
jr HDMATransfer_Wait123Scanlines
|
2015-11-30 16:04:14 +00:00
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
HDMATransfer_NoDI:
|
2016-05-05 02:34:09 +00:00
|
|
|
; HDMA transfer from hl to [hBGMapAddress]
|
|
|
|
; [hBGMapAddress] --> de
|
|
|
|
; 2 * SCREEN_HEIGHT --> c
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hBGMapAddress + 1]
|
2015-11-30 16:04:14 +00:00
|
|
|
ld d, a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hBGMapAddress]
|
2015-11-30 16:04:14 +00:00
|
|
|
ld e, a
|
2016-05-05 02:34:09 +00:00
|
|
|
ld c, 2 * SCREEN_HEIGHT
|
|
|
|
|
|
|
|
; [rHDMA1, rHDMA2] = hl & $fff0
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, h
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rHDMA1], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, l
|
|
|
|
and $f0
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rHDMA2], a
|
2016-05-05 02:34:09 +00:00
|
|
|
; [rHDMA3, rHDMA4] = de & $1ff0
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, d
|
|
|
|
and $1f
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rHDMA3], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, e
|
|
|
|
and $f0
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rHDMA4], a
|
2016-05-05 02:34:09 +00:00
|
|
|
; b = c | %10000000
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, c
|
|
|
|
dec c
|
|
|
|
or $80
|
|
|
|
ld b, a
|
2016-05-05 02:34:09 +00:00
|
|
|
; d = $7f - c + 1
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, $7f
|
|
|
|
sub c
|
|
|
|
ld d, a
|
2016-05-05 02:34:09 +00:00
|
|
|
; while [rLY] >= d: pass
|
2015-11-30 16:04:14 +00:00
|
|
|
.loop1
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [rLY]
|
2015-11-30 16:04:14 +00:00
|
|
|
cp d
|
|
|
|
jr nc, .loop1
|
2016-05-05 02:34:09 +00:00
|
|
|
; while not [rSTAT] & 3: pass
|
2015-11-30 16:04:14 +00:00
|
|
|
.loop2
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [rSTAT]
|
2015-11-30 16:04:14 +00:00
|
|
|
and $3
|
|
|
|
jr z, .loop2
|
2016-05-05 02:34:09 +00:00
|
|
|
; load the 5th byte of HDMA
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, b
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rHDMA5], a
|
2016-05-05 02:34:09 +00:00
|
|
|
; wait until rLY advances (c + 1) times
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [rLY]
|
2015-11-30 16:04:14 +00: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
|
|
|
|
|
2016-05-05 02:34:09 +00:00
|
|
|
HDMATransfer_Wait123Scanlines:
|
2015-11-30 16:04:14 +00:00
|
|
|
ld b, $7b
|
2016-05-05 02:34:09 +00:00
|
|
|
jr _continue_HDMATransfer
|
2015-11-30 16:04:14 +00:00
|
|
|
|
2016-05-05 02:34:09 +00:00
|
|
|
HDMATransfer_Wait127Scanlines:
|
2015-11-30 16:04:14 +00:00
|
|
|
ld b, $7f
|
2016-05-05 02:34:09 +00:00
|
|
|
_continue_HDMATransfer:
|
|
|
|
; a lot of waiting around for hardware registers
|
|
|
|
; [rHDMA1, rHDMA2] = hl & $fff0
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, h
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rHDMA1], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, l
|
|
|
|
and $f0 ; high nybble
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rHDMA2], a
|
2016-05-05 02:34:09 +00:00
|
|
|
; [rHDMA3, rHDMA4] = de & $1ff0
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, d
|
|
|
|
and $1f ; lower 5 bits
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rHDMA3], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, e
|
|
|
|
and $f0 ; high nybble
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rHDMA4], a
|
2016-05-05 02:34:09 +00:00
|
|
|
; e = c | %10000000
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, c
|
|
|
|
dec c
|
2016-05-05 02:34:09 +00:00
|
|
|
or $80
|
2015-11-30 16:04:14 +00:00
|
|
|
ld e, a
|
2016-05-05 02:34:09 +00:00
|
|
|
; d = b - c + 1
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, b
|
|
|
|
sub c
|
|
|
|
ld d, a
|
2016-05-05 02:34:09 +00:00
|
|
|
; while [rLY] >= d: pass
|
2015-11-30 16:04:14 +00:00
|
|
|
.ly_loop
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [rLY]
|
2015-11-30 16:04:14 +00:00
|
|
|
cp d
|
|
|
|
jr nc, .ly_loop
|
|
|
|
|
|
|
|
di
|
2016-05-05 02:34:09 +00:00
|
|
|
; while [rSTAT] & 3: pass
|
2015-11-30 16:04:14 +00:00
|
|
|
.rstat_loop_1
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [rSTAT]
|
2015-11-30 16:04:14 +00:00
|
|
|
and $3
|
|
|
|
jr nz, .rstat_loop_1
|
2016-05-05 02:34:09 +00:00
|
|
|
; while not [rSTAT] & 3: pass
|
2015-11-30 16:04:14 +00:00
|
|
|
.rstat_loop_2
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [rSTAT]
|
2015-11-30 16:04:14 +00:00
|
|
|
and $3
|
|
|
|
jr z, .rstat_loop_2
|
2016-05-05 02:34:09 +00:00
|
|
|
; load the 5th byte of HDMA
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, e
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rHDMA5], a
|
2016-05-05 02:34:09 +00:00
|
|
|
; wait until rLY advances (c + 1) times
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [rLY]
|
2015-11-30 16:04:14 +00: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 14:09:41 +00:00
|
|
|
_LoadHDMAParameters:
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, h
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rHDMA1], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, l
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rHDMA2], a
|
|
|
|
ldh a, [hBGMapAddress + 1]
|
2015-11-30 16:04:14 +00:00
|
|
|
and $1f
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rHDMA3], a
|
|
|
|
ldh a, [hBGMapAddress]
|
|
|
|
ldh [rHDMA4], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
PadTilemapForHDMATransfer:
|
2015-11-30 16:04:14 +00:00
|
|
|
ld c, " "
|
2017-12-24 20:03:20 +00:00
|
|
|
jr PadMapForHDMATransfer
|
2015-11-30 16:04:14 +00:00
|
|
|
|
2020-02-13 17:30:13 +00:00
|
|
|
PadAttrmapForHDMATransfer:
|
2015-11-30 16:04:14 +00:00
|
|
|
ld c, $0
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
PadMapForHDMATransfer:
|
2017-12-24 20:03:20 +00:00
|
|
|
; pad a 20x18 map to 32x18 for HDMA transfer
|
|
|
|
; back up the padding value in c to hMapObjectIndexBuffer
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hMapObjectIndexBuffer]
|
2015-11-30 16:04:14 +00:00
|
|
|
push af
|
|
|
|
ld a, c
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hMapObjectIndexBuffer], a
|
2015-11-30 16:04:14 +00: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 20:03:20 +00:00
|
|
|
; load the original padding value of c into hl for 32 - 20 = 12 rows
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hMapObjectIndexBuffer]
|
2016-05-05 02:34:09 +00:00
|
|
|
ld b, BG_MAP_WIDTH - SCREEN_WIDTH
|
2015-11-30 16:04:14 +00:00
|
|
|
.loop3
|
|
|
|
ld [hli], a
|
|
|
|
dec b
|
|
|
|
jr nz, .loop3
|
|
|
|
|
|
|
|
dec c
|
|
|
|
jr nz, .loop1
|
|
|
|
|
|
|
|
; restore the original value of hMapObjectIndexBuffer
|
|
|
|
pop af
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hMapObjectIndexBuffer], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
_Get2bpp::
|
2015-11-30 16:04:14 +00:00
|
|
|
; 2bpp when [rLCDC] & $80
|
|
|
|
; switch to WRAM bank 6
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [rSVBK]
|
2015-11-30 16:04:14 +00:00
|
|
|
push af
|
2020-02-13 17:30:13 +00:00
|
|
|
ld a, BANK(wScratchTilemap)
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rSVBK], a
|
2015-11-30 16:04:14 +00:00
|
|
|
|
|
|
|
push bc
|
|
|
|
push hl
|
|
|
|
|
2020-02-13 17:30:13 +00:00
|
|
|
; Copy c tiles of the 2bpp from b:de to wScratchTilemap
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, b ; bank
|
|
|
|
ld l, c ; number of tiles
|
|
|
|
ld h, $0
|
2016-05-08 18:11:24 +00: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 16:04:14 +00:00
|
|
|
ld b, h
|
|
|
|
ld c, l
|
|
|
|
ld h, d ; address
|
|
|
|
ld l, e
|
2020-02-13 17:30:13 +00:00
|
|
|
ld de, wScratchTilemap
|
2015-11-30 16:04:14 +00:00
|
|
|
call FarCopyBytes
|
2016-04-10 18:42:14 +00:00
|
|
|
|
2015-11-30 16:04:14 +00:00
|
|
|
pop hl
|
|
|
|
pop bc
|
|
|
|
|
|
|
|
push bc
|
|
|
|
call DelayFrame
|
|
|
|
pop bc
|
|
|
|
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchTilemap
|
2016-05-05 02:34:09 +00:00
|
|
|
call HDMATransfer_Wait127Scanlines
|
2015-11-30 16:04:14 +00:00
|
|
|
|
|
|
|
; restore the previous bank
|
|
|
|
pop af
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rSVBK], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
_Get1bpp::
|
2015-11-30 16:04:14 +00: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 14:09:41 +00:00
|
|
|
.bankswitch
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [rSVBK]
|
2015-11-30 16:04:14 +00:00
|
|
|
push af
|
2020-02-13 17:30:13 +00:00
|
|
|
ld a, BANK(wScratchTilemap)
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rSVBK], a
|
2015-11-30 16:04:14 +00:00
|
|
|
|
|
|
|
push bc
|
|
|
|
push hl
|
|
|
|
|
|
|
|
ld a, b
|
|
|
|
ld l, c
|
|
|
|
ld h, $0
|
|
|
|
add hl, hl ; multiply by 8
|
2016-05-10 16:31:49 +00:00
|
|
|
add hl, hl ; multiply by 8
|
|
|
|
add hl, hl ; multiply by 8
|
2015-11-30 16:04:14 +00:00
|
|
|
ld c, l
|
|
|
|
ld b, h
|
|
|
|
ld h, d
|
|
|
|
ld l, e
|
2020-02-13 17:30:13 +00:00
|
|
|
ld de, wScratchTilemap
|
2015-11-30 16:04:14 +00:00
|
|
|
call FarCopyBytesDouble_DoubleBankSwitch
|
|
|
|
|
|
|
|
pop hl
|
|
|
|
pop bc
|
|
|
|
|
|
|
|
push bc
|
|
|
|
call DelayFrame
|
|
|
|
pop bc
|
|
|
|
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchTilemap
|
2016-05-05 02:34:09 +00:00
|
|
|
call HDMATransfer_Wait127Scanlines
|
2015-11-30 16:04:14 +00:00
|
|
|
|
|
|
|
pop af
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rSVBK], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
HDMATransfer_OnlyTopFourRows:
|
2016-05-05 02:34:09 +00:00
|
|
|
ld hl, .Function
|
2015-12-09 23:25:44 +00:00
|
|
|
jp CallInSafeGFXMode
|
2015-11-30 16:04:14 +00:00
|
|
|
|
2016-05-05 02:34:09 +00:00
|
|
|
.Function:
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchTilemap
|
2015-11-30 16:04:14 +00:00
|
|
|
decoord 0, 0
|
2016-05-05 02:34:09 +00:00
|
|
|
call .Copy
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchTilemap + $80
|
|
|
|
decoord 0, 0, wAttrmap
|
2016-05-05 02:34:09 +00:00
|
|
|
call .Copy
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, $1
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ld c, $8
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchTilemap + $80
|
2017-12-28 12:32:33 +00:00
|
|
|
debgcoord 0, 0, vBGMap1
|
2016-05-05 02:34:09 +00:00
|
|
|
call HDMATransfer_Wait127Scanlines
|
2015-11-30 16:04:14 +00:00
|
|
|
ld a, $0
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2015-11-30 16:04:14 +00:00
|
|
|
ld c, $8
|
2020-02-13 17:30:13 +00:00
|
|
|
ld hl, wScratchTilemap
|
2017-12-28 12:32:33 +00:00
|
|
|
debgcoord 0, 0, vBGMap1
|
2016-05-05 02:34:09 +00:00
|
|
|
call HDMATransfer_Wait127Scanlines
|
2015-11-30 16:04:14 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
.Copy:
|
2015-11-30 16:04:14 +00: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-05 02:34:09 +00:00
|
|
|
add BG_MAP_WIDTH - SCREEN_WIDTH
|
2015-11-30 16:04:14 +00:00
|
|
|
ld l, a
|
|
|
|
ld a, h
|
2018-02-04 18:16:40 +00:00
|
|
|
adc 0
|
2015-11-30 16:04:14 +00:00
|
|
|
ld h, a
|
|
|
|
dec b
|
|
|
|
jr nz, .outer_loop
|
|
|
|
ret
|