2023-10-13 06:37:21 +00:00
|
|
|
IF !DEF(SPRITES_ASM)
|
|
|
|
DEF SPRITES_ASM EQU 1
|
|
|
|
|
|
|
|
|
2023-10-16 05:47:11 +00:00
|
|
|
INCLUDE "globals.asm"
|
|
|
|
|
|
|
|
|
2023-10-11 06:18:12 +00:00
|
|
|
SECTION "Shadow OAM", WRAM0, ALIGN[8]
|
|
|
|
UNION
|
|
|
|
wShadowOAM:: ds 160
|
|
|
|
NEXTU
|
|
|
|
wSPRNext1:: ds 4
|
|
|
|
wSPRNext2:: ds 4
|
|
|
|
wSPRNext3:: ds 4
|
|
|
|
wSPRNext4:: ds 4
|
|
|
|
wSPRHold1:: ds 4
|
|
|
|
wSPRHold2:: ds 4
|
|
|
|
wSPRHold3:: ds 4
|
|
|
|
wSPRHold4:: ds 4
|
|
|
|
wSPRScore1:: ds 4
|
|
|
|
wSPRScore2:: ds 4
|
|
|
|
wSPRScore3:: ds 4
|
|
|
|
wSPRScore4:: ds 4
|
|
|
|
wSPRScore5:: ds 4
|
|
|
|
wSPRScore6:: ds 4
|
|
|
|
wSPRCLevel1:: ds 4
|
|
|
|
wSPRCLevel2:: ds 4
|
|
|
|
wSPRCLevel3:: ds 4
|
|
|
|
wSPRCLevel4:: ds 4
|
|
|
|
wSPRNLevel1:: ds 4
|
|
|
|
wSPRNLevel2:: ds 4
|
|
|
|
wSPRNLevel3:: ds 4
|
|
|
|
wSPRNLevel4:: ds 4
|
2023-10-16 05:47:11 +00:00
|
|
|
wSPRUnused:: ds (16 * 4)
|
2023-10-11 06:18:12 +00:00
|
|
|
ENDU
|
|
|
|
|
|
|
|
|
|
|
|
SECTION "OAM DMA Code", ROM0
|
|
|
|
OAMDMA::
|
|
|
|
LOAD "OAM DMA", HRAM
|
|
|
|
hOAMDMA::
|
|
|
|
ld a, HIGH(wShadowOAM)
|
|
|
|
ldh [rDMA], a
|
|
|
|
ld a, 40
|
|
|
|
: dec a
|
|
|
|
jr nz, :-
|
|
|
|
ret
|
|
|
|
ENDL
|
|
|
|
OAMDMAEnd::
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SECTION "OAM Functions", ROM0
|
|
|
|
CopyOAMHandler::
|
|
|
|
ld de, OAMDMA
|
|
|
|
ld hl, hOAMDMA
|
|
|
|
ld bc, OAMDMAEnd - OAMDMA
|
|
|
|
call UnsafeMemCopy
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
ClearOAM::
|
|
|
|
ld hl, _OAMRAM
|
|
|
|
ld bc, $9F
|
|
|
|
ld d, 0
|
|
|
|
call UnsafeMemSet
|
|
|
|
ld hl, wShadowOAM
|
|
|
|
ld bc, $9F
|
|
|
|
ld d, 0
|
|
|
|
call UnsafeMemSet
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SECTION "Domain Specific Functions", ROM0
|
|
|
|
; Index of next piece in A.
|
|
|
|
ApplyNext::
|
|
|
|
; Correct tile
|
|
|
|
add a, TILE_PIECE_0
|
|
|
|
ld [wSPRNext1+2], a
|
|
|
|
ld [wSPRNext2+2], a
|
|
|
|
ld [wSPRNext3+2], a
|
|
|
|
ld [wSPRNext4+2], a
|
|
|
|
sub a, TILE_PIECE_0
|
|
|
|
|
|
|
|
; X positions
|
|
|
|
ld hl, sPieceXOffsets
|
|
|
|
ld de, sPieceYOffsets
|
|
|
|
cp 0
|
2023-10-13 06:37:21 +00:00
|
|
|
jr z, .skipoffn
|
2023-10-11 06:18:12 +00:00
|
|
|
.getoffn
|
|
|
|
inc hl
|
2023-10-13 06:37:21 +00:00
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
inc de
|
|
|
|
inc de
|
|
|
|
inc de
|
2023-10-11 06:18:12 +00:00
|
|
|
inc de
|
|
|
|
dec a
|
2023-10-13 06:37:21 +00:00
|
|
|
jr nz, .getoffn
|
2023-10-11 06:18:12 +00:00
|
|
|
.skipoffn
|
|
|
|
ld a, [hl+]
|
|
|
|
add a, NEXT_BASE_X
|
|
|
|
ld [wSPRNext1+1], a
|
|
|
|
ld a, [hl+]
|
|
|
|
add a, NEXT_BASE_X
|
|
|
|
ld [wSPRNext2+1], a
|
|
|
|
ld a, [hl+]
|
|
|
|
add a, NEXT_BASE_X
|
|
|
|
ld [wSPRNext3+1], a
|
|
|
|
ld a, [hl]
|
|
|
|
add a, NEXT_BASE_X
|
|
|
|
ld [wSPRNext4+1], a
|
|
|
|
|
|
|
|
; Y positions
|
|
|
|
ld h, d
|
|
|
|
ld l, e
|
|
|
|
ld a, [hl+]
|
|
|
|
add a, NEXT_BASE_Y
|
|
|
|
ld [wSPRNext1+0], a
|
|
|
|
ld a, [hl+]
|
|
|
|
add a, NEXT_BASE_Y
|
|
|
|
ld [wSPRNext2+0], a
|
|
|
|
ld a, [hl+]
|
|
|
|
add a, NEXT_BASE_Y
|
|
|
|
ld [wSPRNext3+0], a
|
|
|
|
ld a, [hl]
|
|
|
|
add a, NEXT_BASE_Y
|
|
|
|
ld [wSPRNext4+0], a
|
|
|
|
ret
|
|
|
|
|
|
|
|
; Index of hold piece in A.
|
|
|
|
ApplyHold::
|
|
|
|
cp 255
|
2023-10-13 09:26:40 +00:00
|
|
|
jr nz, .doApplyHold
|
2023-10-11 06:18:12 +00:00
|
|
|
ld hl, wSPRHold1
|
|
|
|
ld bc, 16
|
|
|
|
ld d, 0
|
|
|
|
call UnsafeMemSet
|
|
|
|
ret
|
|
|
|
|
|
|
|
.doApplyHold
|
|
|
|
; Correct tile
|
|
|
|
add a, TILE_PIECE_0
|
|
|
|
ld [wSPRHold1+2], a
|
|
|
|
ld [wSPRHold2+2], a
|
|
|
|
ld [wSPRHold3+2], a
|
|
|
|
ld [wSPRHold4+2], a
|
|
|
|
sub a, TILE_PIECE_0
|
|
|
|
|
|
|
|
; X positions
|
|
|
|
ld hl, sPieceXOffsets
|
|
|
|
ld de, sPieceYOffsets
|
|
|
|
cp 0
|
2023-10-13 06:37:21 +00:00
|
|
|
jr z, .skipoffh
|
2023-10-11 06:18:12 +00:00
|
|
|
.getoffh
|
|
|
|
inc hl
|
2023-10-13 06:37:21 +00:00
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
inc de
|
|
|
|
inc de
|
|
|
|
inc de
|
2023-10-11 06:18:12 +00:00
|
|
|
inc de
|
|
|
|
dec a
|
2023-10-13 06:37:21 +00:00
|
|
|
jr nz, .getoffh
|
2023-10-11 06:18:12 +00:00
|
|
|
.skipoffh
|
|
|
|
ld a, [hl+]
|
|
|
|
add a, HOLD_BASE_X
|
|
|
|
ld [wSPRHold1+1], a
|
|
|
|
ld a, [hl+]
|
|
|
|
add a, HOLD_BASE_X
|
|
|
|
ld [wSPRHold2+1], a
|
|
|
|
ld a, [hl+]
|
|
|
|
add a, HOLD_BASE_X
|
|
|
|
ld [wSPRHold3+1], a
|
|
|
|
ld a, [hl]
|
|
|
|
add a, HOLD_BASE_X
|
|
|
|
ld [wSPRHold4+1], a
|
|
|
|
|
|
|
|
; Y positions
|
|
|
|
ld h, d
|
|
|
|
ld l, e
|
|
|
|
ld a, [hl+]
|
|
|
|
add a, HOLD_BASE_Y
|
|
|
|
ld [wSPRHold1+0], a
|
|
|
|
ld a, [hl+]
|
|
|
|
add a, HOLD_BASE_Y
|
|
|
|
ld [wSPRHold2+0], a
|
|
|
|
ld a, [hl+]
|
|
|
|
add a, HOLD_BASE_Y
|
|
|
|
ld [wSPRHold3+0], a
|
|
|
|
ld a, [hl]
|
|
|
|
add a, HOLD_BASE_Y
|
|
|
|
ld [wSPRHold4+0], a
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
; Address of first sprite in hl.
|
|
|
|
; Address of first digit in de.
|
|
|
|
ApplyNumbers::
|
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
ld bc, 4
|
|
|
|
|
|
|
|
ld a, [de]
|
|
|
|
add a, TILE_0
|
|
|
|
ld [hl], a
|
|
|
|
add hl, bc
|
|
|
|
inc de
|
|
|
|
|
|
|
|
ld a, [de]
|
|
|
|
add a, TILE_0
|
|
|
|
ld [hl], a
|
|
|
|
add hl, bc
|
|
|
|
inc de
|
|
|
|
|
|
|
|
ld a, [de]
|
|
|
|
add a, TILE_0
|
|
|
|
ld [hl], a
|
|
|
|
add hl, bc
|
|
|
|
inc de
|
|
|
|
|
|
|
|
ld a, [de]
|
|
|
|
add a, TILE_0
|
|
|
|
ld [hl], a
|
|
|
|
add hl, bc
|
|
|
|
inc de
|
|
|
|
|
|
|
|
ld a, [de]
|
|
|
|
add a, TILE_0
|
|
|
|
ld [hl], a
|
|
|
|
add hl, bc
|
|
|
|
inc de
|
|
|
|
|
|
|
|
ld a, [de]
|
|
|
|
add a, TILE_0
|
|
|
|
ld [hl], a
|
|
|
|
add hl, bc
|
|
|
|
inc de
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
SetNumberSpritePositions::
|
2023-10-16 05:47:11 +00:00
|
|
|
ld a, SCORE_BASE_X
|
2023-10-11 06:18:12 +00:00
|
|
|
ld hl, wSPRScore1
|
|
|
|
ld [hl], SCORE_BASE_Y
|
|
|
|
inc hl
|
|
|
|
ld [hl], a
|
2023-10-13 09:20:28 +00:00
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
ld b, a
|
|
|
|
ld a, OAMF_PAL1
|
|
|
|
ld [hl], a
|
|
|
|
ld a, b
|
2023-10-11 06:18:12 +00:00
|
|
|
add a, 8
|
2023-10-13 09:20:28 +00:00
|
|
|
|
2023-10-11 06:18:12 +00:00
|
|
|
ld hl, wSPRScore2
|
|
|
|
ld [hl], SCORE_BASE_Y
|
|
|
|
inc hl
|
|
|
|
ld [hl], a
|
2023-10-13 09:20:28 +00:00
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
ld b, a
|
|
|
|
ld a, OAMF_PAL1
|
|
|
|
ld [hl], a
|
|
|
|
ld a, b
|
2023-10-11 06:18:12 +00:00
|
|
|
add a, 8
|
2023-10-13 09:20:28 +00:00
|
|
|
|
2023-10-11 06:18:12 +00:00
|
|
|
ld hl, wSPRScore3
|
|
|
|
ld [hl], SCORE_BASE_Y
|
|
|
|
inc hl
|
|
|
|
ld [hl], a
|
2023-10-13 09:20:28 +00:00
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
ld b, a
|
|
|
|
ld a, OAMF_PAL1
|
|
|
|
ld [hl], a
|
|
|
|
ld a, b
|
2023-10-11 06:18:12 +00:00
|
|
|
add a, 8
|
2023-10-13 09:20:28 +00:00
|
|
|
|
2023-10-11 06:18:12 +00:00
|
|
|
ld hl, wSPRScore4
|
|
|
|
ld [hl], SCORE_BASE_Y
|
|
|
|
inc hl
|
|
|
|
ld [hl], a
|
2023-10-13 09:20:28 +00:00
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
ld b, a
|
|
|
|
ld a, OAMF_PAL1
|
|
|
|
ld [hl], a
|
|
|
|
ld a, b
|
2023-10-11 06:18:12 +00:00
|
|
|
add a, 8
|
2023-10-13 09:20:28 +00:00
|
|
|
|
2023-10-11 06:18:12 +00:00
|
|
|
ld hl, wSPRScore5
|
|
|
|
ld [hl], SCORE_BASE_Y
|
|
|
|
inc hl
|
|
|
|
ld [hl], a
|
2023-10-13 09:20:28 +00:00
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
ld b, a
|
|
|
|
ld a, OAMF_PAL1
|
|
|
|
ld [hl], a
|
|
|
|
ld a, b
|
2023-10-11 06:18:12 +00:00
|
|
|
add a, 8
|
2023-10-13 09:20:28 +00:00
|
|
|
|
2023-10-11 06:18:12 +00:00
|
|
|
ld hl, wSPRScore6
|
|
|
|
ld [hl], SCORE_BASE_Y
|
|
|
|
inc hl
|
|
|
|
ld [hl], a
|
2023-10-13 09:20:28 +00:00
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
ld a, OAMF_PAL1
|
|
|
|
ld [hl], a
|
|
|
|
|
2023-10-16 05:47:11 +00:00
|
|
|
ld a, LEVEL_BASE_X
|
2023-10-11 06:18:12 +00:00
|
|
|
ld hl, wSPRCLevel1
|
|
|
|
ld [hl], CLEVEL_BASE_Y
|
|
|
|
inc hl
|
|
|
|
ld [hl], a
|
2023-10-13 09:20:28 +00:00
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
ld b, a
|
|
|
|
ld a, OAMF_PAL1
|
|
|
|
ld [hl], a
|
|
|
|
ld a, b
|
2023-10-11 06:18:12 +00:00
|
|
|
add a, 8
|
2023-10-13 09:20:28 +00:00
|
|
|
|
2023-10-11 06:18:12 +00:00
|
|
|
ld hl, wSPRCLevel2
|
|
|
|
ld [hl], CLEVEL_BASE_Y
|
|
|
|
inc hl
|
|
|
|
ld [hl], a
|
2023-10-13 09:20:28 +00:00
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
ld b, a
|
|
|
|
ld a, OAMF_PAL1
|
|
|
|
ld [hl], a
|
|
|
|
ld a, b
|
2023-10-11 06:18:12 +00:00
|
|
|
add a, 8
|
2023-10-13 09:20:28 +00:00
|
|
|
|
2023-10-11 06:18:12 +00:00
|
|
|
ld hl, wSPRCLevel3
|
|
|
|
ld [hl], CLEVEL_BASE_Y
|
|
|
|
inc hl
|
|
|
|
ld [hl], a
|
2023-10-13 09:20:28 +00:00
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
ld b, a
|
|
|
|
ld a, OAMF_PAL1
|
|
|
|
ld [hl], a
|
|
|
|
ld a, b
|
2023-10-11 06:18:12 +00:00
|
|
|
add a, 8
|
2023-10-13 09:20:28 +00:00
|
|
|
|
2023-10-11 06:18:12 +00:00
|
|
|
ld hl, wSPRCLevel4
|
|
|
|
ld [hl], CLEVEL_BASE_Y
|
|
|
|
inc hl
|
|
|
|
ld [hl], a
|
2023-10-13 09:20:28 +00:00
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
ld a, OAMF_PAL1
|
|
|
|
ld [hl], a
|
|
|
|
|
2023-10-16 05:47:11 +00:00
|
|
|
ld a, LEVEL_BASE_X
|
2023-10-11 06:18:12 +00:00
|
|
|
ld hl, wSPRNLevel1
|
|
|
|
ld [hl], NLEVEL_BASE_Y
|
|
|
|
inc hl
|
|
|
|
ld [hl], a
|
2023-10-13 09:20:28 +00:00
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
ld b, a
|
|
|
|
ld a, OAMF_PAL1
|
|
|
|
ld [hl], a
|
|
|
|
ld a, b
|
2023-10-11 06:18:12 +00:00
|
|
|
add a, 8
|
2023-10-13 09:20:28 +00:00
|
|
|
|
2023-10-11 06:18:12 +00:00
|
|
|
ld hl, wSPRNLevel2
|
|
|
|
ld [hl], NLEVEL_BASE_Y
|
|
|
|
inc hl
|
|
|
|
ld [hl], a
|
2023-10-13 09:20:28 +00:00
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
ld b, a
|
|
|
|
ld a, OAMF_PAL1
|
|
|
|
ld [hl], a
|
|
|
|
ld a, b
|
2023-10-11 06:18:12 +00:00
|
|
|
add a, 8
|
2023-10-13 09:20:28 +00:00
|
|
|
|
2023-10-11 06:18:12 +00:00
|
|
|
ld hl, wSPRNLevel3
|
|
|
|
ld [hl], NLEVEL_BASE_Y
|
|
|
|
inc hl
|
|
|
|
ld [hl], a
|
2023-10-13 09:20:28 +00:00
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
ld b, a
|
|
|
|
ld a, OAMF_PAL1
|
|
|
|
ld [hl], a
|
|
|
|
ld a, b
|
2023-10-11 06:18:12 +00:00
|
|
|
add a, 8
|
2023-10-13 09:20:28 +00:00
|
|
|
|
2023-10-11 06:18:12 +00:00
|
|
|
ld hl, wSPRNLevel4
|
|
|
|
ld [hl], NLEVEL_BASE_Y
|
|
|
|
inc hl
|
|
|
|
ld [hl], a
|
2023-10-13 09:20:28 +00:00
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
ld a, OAMF_PAL1
|
|
|
|
ld [hl], a
|
2023-10-11 06:18:12 +00:00
|
|
|
ret
|
2023-10-13 06:37:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
ENDC
|