-
Notifications
You must be signed in to change notification settings - Fork 2
/
inventory.s
178 lines (144 loc) · 2.8 KB
/
inventory.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
;
; inventory
; Code and data structures related to the weapons inventory and store
;
; Created by Quinn Dunki on 8/13/17
;
INVENTORY_ITEMS = 5
ITEM_WIDTH = 16 ; In pixels
ITEM_HEIGHT = 16 ; In pixels
ICON_WIDTH = 8 ; In pixels
ICON_ORIGIN = (ITEM_WIDTH-ICON_WIDTH)/4 ; In bytes
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; renderInventory
;
; Renders inventory for current player
;
; Trashes PARAML0
;
renderInventory:
SAVE_AXY
; Find inventory we need to render
ldy currentPlayer
PLAYERPTR_Y
tya
clc
adc #playerData
adc #PD_PRICES
sta PARAML1
; Compute initial VRAM position ($E1-relative)
ldy #(8192 + (160*10 + (160*ICON_ORIGIN + ICON_ORIGIN)))
ldx #0
renderInventoryLoop:
lda PARAML1 ; renderInventory item trashes this so we need to preserve it
pha
jsr renderInventoryItem
pla
sta PARAML1
tya ; Advance VRAM pointer
clc
adc #ITEM_WIDTH/2
tay
inx
cpx #INVENTORY_ITEMS
bne renderInventoryLoop
RESTORE_AXY
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; renderInventoryItem
;
; X = Item index
; Y = VRAM pos ($E1-relative)
; PARAML1 = Inventory state
;
renderInventoryItem:
SAVE_AXY
stx renderInventoryItemIndex
phy
lda #2 ; Frame
clc
jsr DrawSpriteBank
; Find projectile type data
ldy renderInventoryItemIndex
PROJECTILETYPEPTR_Y
; Render projectile
lda projectileTypes+PT_FRAME1,y
ply
phy
clc
jsr DrawSpriteBank
; Render selection
ldy currentPlayer
PLAYERPTR_Y
lda playerData+PD_CURRWEAPON,y
cmp renderInventoryItemIndex
bne renderInventoryItem_unselected
ply
phy
lda #11
clc
jsr DrawSpriteBank
renderInventoryItem_unselected:
lda renderInventoryItemIndex
beq renderInventoryItem_abort ; First item shows no counter
; Render counter background
clc
pla
adc #ITEM_HEIGHT*160
pha
tay
lda #10
jsr DrawSpriteBank
; Render counter
lda renderInventoryItemIndex
asl
tay
lda (PARAML1),y
sta PARAML0
jsr intToString
; Prepend currency prefix to counter string
BITS8A
lda intToStringResult
inc
sta intToStringPrefix
lda #':' ; Colon maps to dollar sign in tiny number font
sta intToStringResult
BITS16
; Render tiny numbers
pla
clc
adc #6*160+2
tay
lda #intToStringPrefix
sta PARAML0
lda #0
jsl renderStringFar
renderInventoryItem_done:
RESTORE_AXY
rts
renderInventoryItem_abort:
ply ; Balance stack
bra renderInventoryItem_done
renderInventoryItemIndex:
.word 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; awardTreats
;
; PARAML0 = Amount to award
;
awardTreats:
SAVE_AY
ldy currentPlayer
PLAYERPTR_Y
clc
lda playerData+PD_TREATS,y
adc PARAML0
cmp #999
bmi awardTreatsStore
lda #999 ; Clamp treats at 3 digits
awardTreatsStore:
sta playerData+PD_TREATS,y
ldy currentPlayer
jsr renderPlayerHeader
RESTORE_AY
rts