-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem.s
214 lines (199 loc) · 4.2 KB
/
item.s
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
.include "global.inc"
.export feature_at
.export rand_feature
.export rand_drop
.segment "BSS"
; store map of item -> appearance
potion_map: .res 5 ; amount of potions
scroll_map: .res 5 ; amount of scrolls
features: .res .sizeof(Feature)*maxfeatures
items: .res .sizeof(ItemDrop)*maxdrops
.segment "CODE"
; get feature at xpos and ypos
; out: 0 on success
; updates: y register to feature index
; todo if x matches, huge performance hit here (in loop label)
.proc feature_at
ldy #0
loop:
lda features + Feature::coords + Coord::xcoord, y
cmp xpos
bne continue
lda features + Feature::coords + Coord::ycoord, y
cmp ypos
beq success
continue:
tya
clc
adc #.sizeof(Feature)
cmp #maxfeatures * .sizeof(Feature)
tay
bne loop
; failure
lda #1
rts
success:
lda #0
rts
.endproc
; generate random dungeon feature at xpos and ypos
; stores feature in features array at index y
;
; clobbers: x
.proc rand_feature
lda xpos
sta features + Feature::coords + Coord::xcoord, y
; for some reason, if we lda twice we get grey screen bug
lda ypos
sta features + Feature::coords + Coord::ycoord, y
; random number 0-255
jsr prng
; roughly 2% chance to spawn chest
cmp #5
bcc chest
; failure
lda #Features::none
sta features + Feature::type, y
rts
chest:
lda #Features::chest
sta features + Feature::type, y
rts
.endproc
; generate random drop at index y
;
; in: rarity (1-10) (todo doesn't do anything atm)
.proc rand_drop
jsr d2
cmp #1
beq rand_potion
jmp rand_scroll
.endproc
; store random potion in items var at index y
; clobbers x and accum
.proc rand_potion
; prepare item
lda #ItemTypes::potion
sta items+Item::type, y
; generate random potion
jsr d6
cmp #1
beq pot_1
cmp #2
beq pot_2
cmp #3
beq pot_3
cmp #4
beq pot_4
cmp #5
beq pot_5
cmp #6
beq pot_6
rts
; healing pot
pot_1:
pot_2:
lda #Potions::heal
sta items+Item::item, y
jsr item_appearance
rts
; full healing pot
pot_3:
lda #Potions::fullheal
sta items+Item::item, y
jsr item_appearance
rts
; poison pot
pot_4:
lda #Potions::poison
sta items+Item::item, y
jsr item_appearance
rts
; confusion pot
pot_5:
lda #Potions::confusion
sta items+Item::item, y
jsr item_appearance
rts
; power pot
pot_6:
lda #Potions::power
sta items+Item::item, y
jsr item_appearance
rts
.endproc
; todo store random scroll in items var at index y
; clobbers x and accum
.proc rand_scroll
.endproc
; loads the item appearance pointer of items var at index y
; todo lookup in map first, otherwise randomize appearance
.proc item_appearance
lda items+Item::type, y
cmp #ItemTypes::potion
beq potion_appearance
; todo scrolls
rts
potion_appearance:
lda items+Item::item, y
cmp #Potions::heal
beq heal
cmp #Potions::fullheal
beq fullheal
cmp #Potions::poison
beq poison
cmp #Potions::confusion
beq confusion
cmp #Potions::power
beq power
rts
heal:
lda #<txt_heal
sta items+Item::appearance, y
lda #>txt_heal
sta items+Item::appearance+1, y
rts
fullheal:
lda #<txt_fullheal
sta items+Item::appearance, y
lda #>txt_fullheal
sta items+Item::appearance+1, y
rts
poison:
lda #<txt_poison
sta items+Item::appearance, y
lda #>txt_poison
sta items+Item::appearance+1, y
rts
confusion:
lda #<txt_confusion
sta items+Item::appearance, y
lda #>txt_confusion
sta items+Item::appearance+1, y
rts
power:
lda #<txt_power
sta items+Item::appearance, y
lda #>txt_power
sta items+Item::appearance+1, y
rts
.endproc
.segment "RODATA"
; todo will need to translate these into NES color palette
txt_colors:
.asciiz "Black"
.asciiz "Blue"
.asciiz "Green"
.asciiz "Yellow"
.asciiz "Grey"
txt_heal: .asciiz "Healing"
txt_fullheal: .asciiz "Full Healing"
txt_poison: .asciiz "Poison"
txt_confusion: .asciiz "Confusion"
txt_power: .asciiz "Power"
txt_names:
.asciiz "READ ME"
.asciiz "ABRACADABRA"
.asciiz "ASDF ZSDF"
.asciiz "BLAH"
.asciiz "DONT READ"