summaryrefslogtreecommitdiff
path: root/common/battle_e_transfer.asm
blob: bc4f4e023060faf43d3945f8af37df6dc102d1a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
TransferData:
	LD_IND_HL SomeVar2
	push de
	ld hl, $BBBB
	LD_IND_HL Space_1 ; Space_1 = $BBBB
	EX_DE_HL
	LD_IND_HL Space_2 ; store transfer length in Space_2, which is odd,
	                  ; because we never refer to it again
	API_0C7 Space_1

	wait 1
	pop hl ; number of bytes to transfer

	; calculate number of words to transfer:
	; de = (hl + 1) >> 1
	inc hl
	ld b, 1
	call WordShiftRight
	EX_DE_HL

.asm_18FE
	ld a, e
	or d
	ret z
	; while de > 0…

	ld hl, $8888
	LD_IND_HL Space_1 ; Space_1 = $8888
	ld a, $01
	LD_IND_A SomeVar1 ; SomeVar1 = 1

.asm_190C
	LD_A_IND SomeVar1 ; a = SomeVar1
	cp $08
	jr nc, .asm_193B

	push de
	LD_HL_IND SomeVar2
	ld c, [hl]
	inc hl
	ld b, [hl]
	inc hl
	LD_IND_HL SomeVar2
	ld hl, SomeVar1
	ld l, [hl]
	ld h, $00
	add hl, hl
	ld de, Space_1
	add hl, de
	ld [hl], c
	inc hl
	ld [hl], b
	pop de
	dec de
	ld a, e
	or d
	jr z, .asm_193B

	ld hl, SomeVar1
	ld a, $01
	add a, [hl]
	ld [hl], a
	jr .asm_190C

.asm_193B ; if SomeVar1 > 8
	push de
	API_0C7 Space_1 ; this must be the data transfer? it’s the only API function called

	wait 1
	pop de
	jr .asm_18FE