summaryrefslogtreecommitdiff
path: root/home/items.asm
blob: 0edd72ba36144c225da6538bcc5944f315673b79 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
INCLUDE "constants.asm"

if DEBUG
SECTION "AddItemToInventory", ROM0[$3259]
else
SECTION "AddItemToInventory", ROM0[$321D]
endc

AddItemToInventory:: ; 3259
; function to add an item (in varying quantities) to the player's bag or PC box
; INPUT:
; HL = address of inventory (either wNumBagItems or wNumBoxItems)
; [wCurItem] = item ID
; [wItemQuantity] = item quantity
; sets carry flag if successful, unsets carry flag if unsuccessful
	push bc
	ldh a, [hROMBank]
	push af
	ld a, BANK(_ReceiveItem)
	call Bankswitch
	push hl
	push de
	call _ReceiveItem
	pop de
	pop hl
	pop bc
	ld a, b
	call Bankswitch
	pop bc
	ret

if DEBUG
SECTION "GiveItem", ROM0[$366C]
else
SECTION "GiveItem", ROM0[$3630]
endc

GiveItem::
; Give player quantity c of item b,
; and copy the item's name to wcf4b.
; Return carry on success.
	ld a, b
	ld [wce37], a
	ld [wCurItem], a
	ld a, c
	ld [wItemQuantity], a
	ld hl, wNumBagItems
	call AddItemToInventory
	ret nc
	call GetItemName
	call CopyStringToCD31
	scf
	ret

if DEBUG
SECTION "GetItemName", ROM0[$376F]
else
SECTION "GetItemName", ROM0[$3733]
endc

GetItemName:: ; 376F
; given an item ID at [wce37], store the name of the item into a string
; starting at wcd26
	push hl
	push bc
	ld a, [wce37]
	cp ITEM_HM01_RED
	jr nc, .machine

	ld [wcb5b], a
	ld a, ITEM_NAME
	ld [wNameCategory], a
	call GetName
	jr .finish

.machine
    call GetMachineName
.finish
	ld de, wcd26 ; pointer to where item name is stored in RAM
	pop bc
	pop hl
	ret

if DEBUG
SECTION "GetMachineName", ROM0[$378E]
else
SECTION "GetMachineName", ROM0[$3752]
endc

GetMachineName::
; copies the name of the TM/HM in [wce37] to wcd26
	push hl
	push de
	push bc
	ld a, [wce37]
	push af
	cp ITEM_TM01_RED
	jr nc, .WriteTM
; if HM, then write "HM" and add 5 to the item ID, so we can reuse the
; TM printing code
	add 5
	ld [wce37], a
	ld hl, HiddenPrefix
	ld bc, 6
	jr .WriteMachinePrefix
.WriteTM
	ld hl, TechnicalPrefix
	ld bc, 5
.WriteMachinePrefix
	ld de, wcd26
	call CopyBytes
; now get the machine number and convert it to text
	ld a, [wce37]
	sub ITEM_TM01_RED - 1
	ld b, "0"
.FirstDigit
	sub 10
	jr c, .SecondDigit
	inc b
	jr .FirstDigit
.SecondDigit
	add 10
	push af
	ld a, b
	ld [de], a
	inc de
	pop af
	ld b, "0"
	add b
	ld [de], a
	inc de
	ld a, "@"
	ld [de], a
	pop af
	ld [wce37], a
	pop bc
	pop de
	pop hl
	ret

TechnicalPrefix:
	db "わざマシン@"

HiddenPrefix:
	db "ひでんマシン@"