-
Notifications
You must be signed in to change notification settings - Fork 20
/
inventory.asm
1569 lines (1331 loc) · 21.8 KB
/
inventory.asm
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; This file is part of Pwn Adventure Z.
; Pwn Adventure Z is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
; Pwn Adventure Z is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
; You should have received a copy of the GNU General Public License
; along with Pwn Adventure Z. If not, see <http://www.gnu.org/licenses/>.
.include "defines.inc"
.code
PROC show_inventory
ldx #0
palettesaveloop:
lda active_palette, x
sta saved_palette, x
inx
cpx #32
bne palettesaveloop
lda ppu_settings
sta saved_ppu_settings
jsr fade_out
lda #PPUCTRL_ENABLE_NMI | PPUCTRL_SPRITE_SIZE | PPUCTRL_NAMETABLE_2000
sta ppu_settings
jmp show_inventory_tab
.endproc
PROC show_inventory_tab
jsr clear_alt_screen
LOAD_ALL_TILES $000, inventory_ui_tiles
lda #0
sta selection
lda #0
sta scroll
jsr render_inventory_screen
lda #30
sta repeat_time
lda inventory_count
bne selectloop
jmp emptyloop
selectloop:
jsr update_controller
jsr wait_for_vblank
lda controller
and #JOY_DOWN
bne downpressed
lda controller
and #JOY_UP
bne up
lda controller
and #JOY_A
bne usepressed
lda controller
and #JOY_LEFT
bne salvage
lda controller
and #JOY_RIGHT
bne craft
lda controller
and #JOY_SELECT | JOY_START
beq nobutton
jmp done
salvage:
lda horde_active
bne nosalvage
PLAY_SOUND_EFFECT effect_uimove
jsr fade_out
jmp show_salvage_tab
nosalvage:
jmp waitfordepress
craft:
lda horde_active
bne nocraft
PLAY_SOUND_EFFECT effect_uimove
jsr fade_out
jmp show_crafting_tab
nocraft:
jmp waitfordepress
nobutton:
lda #30
sta repeat_time
jmp selectloop
downpressed:
jmp down
usepressed:
jmp use
up:
lda selection
beq attop
PLAY_SOUND_EFFECT effect_uimove
jsr deselect_inventory_item
lda selection
sec
sbc scroll
cmp #2
bcs noupscroll
lda scroll
beq noupscroll
dec scroll
lda controller
and #JOY_B
bne moveup
jsr render_inventory_items
dec selection
jsr select_inventory_item
jmp shortwaitfordepress
noupscroll:
lda controller
and #JOY_B
bne moveup
dec selection
jsr select_inventory_item
attop:
jmp waitfordepress
moveup:
lda selection
asl
tax
lda inventory - 2, x
sta temp
lda inventory - 1, x
sta temp + 1
lda inventory, x
sta inventory - 2, x
lda inventory + 1, x
sta inventory - 1, x
lda temp
sta inventory, x
lda temp + 1
sta inventory + 1, x
jsr render_inventory_items
dec selection
jsr select_inventory_item
jmp shortwaitfordepress
down:
lda selection
clc
adc #1
cmp inventory_count
beq atbottom
PLAY_SOUND_EFFECT effect_uimove
jsr deselect_inventory_item
lda selection
sec
sbc scroll
cmp #4
bcc nodownscroll
lda scroll
clc
adc #6
cmp inventory_count
bcs nodownscroll
inc scroll
lda controller
and #JOY_B
bne movedown
jsr render_inventory_items
inc selection
jsr select_inventory_item
jmp shortwaitfordepress
nodownscroll:
lda controller
and #JOY_B
bne movedown
inc selection
jsr select_inventory_item
atbottom:
jmp waitfordepress
movedown:
lda selection
asl
tax
lda inventory + 2, x
sta temp
lda inventory + 3, x
sta temp + 1
lda inventory, x
sta inventory + 2, x
lda inventory + 1, x
sta inventory + 3, x
lda temp
sta inventory, x
lda temp + 1
sta inventory + 1, x
jsr render_inventory_items
inc selection
jsr select_inventory_item
jmp shortwaitfordepress
use:
lda selection
asl
tax
lda inventory + 1, x
jsr get_item_type
cmp #ITEM_TYPE_GUN
beq equipweapon
cmp #ITEM_TYPE_MELEE
beq equipweapon
cmp #ITEM_TYPE_GRENADE
beq equipweapon
cmp #ITEM_TYPE_OUTFIT
beq equipwearable
jmp performuse
equipweapon:
PLAY_SOUND_EFFECT effect_equip
lda selection
asl
tax
lda inventory + 1, x
cmp equipped_weapon
beq uneqipweapon
sta equipped_weapon
jmp updateequip
uneqipweapon:
lda #$ff
sta equipped_weapon
jmp updateequip
equipwearable:
PLAY_SOUND_EFFECT effect_equip
lda selection
asl
tax
lda inventory + 1, x
cmp equipped_armor
beq unequiparmor
sta equipped_armor
jmp updateequip
unequiparmor:
lda #$ff
sta equipped_armor
updateequip:
jsr wait_for_vblank
lda equipped_weapon
ldx #$18
jsr load_item_sprite_tiles
jsr prepare_for_rendering
jsr wait_for_vblank
lda equipped_armor
ldx #$1c
jsr load_item_sprite_tiles
jsr prepare_for_rendering
jmp waitfordepress
performuse:
lda selection
asl
tax
lda inventory + 1, x
jsr use_item
bne validuse
jmp invaliduse
validuse:
PLAY_SOUND_EFFECT_NO_OVERRIDE effect_select
jsr deselect_inventory_item
lda selection
asl
tax
dec inventory, x
beq usedall
jsr update_inventory_status
jsr render_inventory_items
jsr select_inventory_item
jmp waitfordepress
usedall:
lda selection
sta arg0
deleteloop:
lda arg0
clc
adc #1
cmp inventory_count
beq deletedone
lda arg0
asl
tax
lda inventory + 2, x
sta inventory, x
lda inventory + 3, x
sta inventory + 1, x
inc arg0
jmp deleteloop
deletedone:
dec inventory_count
beq deleteempty
lda scroll
clc
adc #5
cmp inventory_count
bcc deletescrollok
lda scroll
beq deletelast
dec selection
dec scroll
jmp deletescrollok
deleteempty:
jsr clear_last_inventory_item
jsr wait_for_vblank_if_rendering
LOAD_PTR no_items_str
ldx #11
ldy #32 + 11
jsr write_string
jsr prepare_for_rendering
jsr wait_for_vblank_if_rendering
LOAD_PTR clear_item_description_str
ldx #2
ldy #32 + 21
jsr write_string
jsr prepare_for_rendering
jmp emptyloop
deletelast:
lda selection
cmp inventory_count
bne nochangeselect
dec selection
nochangeselect:
jsr clear_last_inventory_item
deletescrollok:
jsr update_inventory_status
jsr render_inventory_items
jsr select_inventory_item
jmp waitfordepress
invaliduse:
jmp waitfordepress
shortwaitfordepress:
lda repeat_time
cmp #30
bne nowait
ldx #6
jsr wait_for_frame_count
lda #3
sta repeat_time
jmp selectloop
nowait:
jmp selectloop
waitfordepress:
lda repeat_time
sta arg0
waitfordepressloop:
dec arg0
beq waitfordepresstimeout
jsr update_controller
jsr wait_for_vblank
lda controller
bne waitfordepressloop
jmp selectloop
waitfordepresstimeout:
lda #3
sta repeat_time
jmp selectloop
emptyloop:
jsr update_controller
jsr wait_for_vblank
lda controller
and #JOY_LEFT
bne emptysalvage
lda controller
and #JOY_RIGHT
bne emptycrafting
lda controller
and #JOY_SELECT
beq emptyloop
jmp done
emptysalvage:
jmp salvage
emptycrafting:
jmp craft
done:
jmp end_inventory_screen
.endproc
PROC end_inventory_screen
PLAY_SOUND_EFFECT effect_select
jsr fade_out
lda saved_ppu_settings
sta ppu_settings
jsr update_equipped_item_slots
jsr back_to_game_from_alternate_screen
LOAD_PTR saved_palette
jsr fade_in
rts
.endproc
.segment "FIXED"
PROC render_inventory_screen
lda current_bank
pha
lda #^do_render_inventory_screen
jsr bankswitch
jsr do_render_inventory_screen & $ffff
pla
jsr bankswitch
rts
.endproc
PROC render_inventory_status_bar
lda current_bank
pha
lda #^do_render_inventory_status_bar
jsr bankswitch
jsr do_render_inventory_status_bar & $ffff
pla
jsr bankswitch
rts
.endproc
PROC update_inventory_status
lda current_bank
pha
lda #^do_update_inventory_status
jsr bankswitch
jsr do_update_inventory_status & $ffff
pla
jsr bankswitch
rts
.endproc
PROC render_inventory_items
lda current_bank
pha
lda #^do_render_inventory_items
jsr bankswitch
jsr do_render_inventory_items & $ffff
pla
jsr bankswitch
rts
.endproc
PROC clear_last_inventory_item
lda current_bank
pha
lda #^do_clear_last_inventory_item
jsr bankswitch
jsr do_clear_last_inventory_item & $ffff
pla
jsr bankswitch
rts
.endproc
PROC select_inventory_item
lda current_bank
pha
lda #^do_select_inventory_item
jsr bankswitch
jsr do_select_inventory_item & $ffff
pla
jsr bankswitch
rts
.endproc
PROC deselect_inventory_item
lda current_bank
pha
lda #^do_deselect_inventory_item
jsr bankswitch
jsr do_deselect_inventory_item & $ffff
pla
jsr bankswitch
rts
.endproc
.segment "UI"
PROC do_render_inventory_screen
; Draw box around inventory screen
lda #1
sta arg0
lda #32 + 1
sta arg1
lda #28
sta arg2
lda #32 + 22
sta arg3
jsr draw_large_box
lda horde_active
beq craft
LOAD_PTR no_craft_inventory_str
ldx #3
ldy #32 + 1
jsr write_string
jmp titledone & $ffff
craft:
LOAD_PTR inventory_str
ldx #3
ldy #32 + 1
jsr write_string
; Set palette for title
lda #1
sta arg0
lda #16 + 0
sta arg1
lda #4
sta arg2
lda #16 + 0
sta arg3
lda #2
sta arg4
jsr set_box_palette
lda #10
sta arg0
lda #16 + 0
sta arg1
lda #13
sta arg2
lda #16 + 0
sta arg3
lda #2
sta arg4
jsr set_box_palette
titledone:
; Set palette for inside of box
lda #1
sta arg0
lda #16 + 1
sta arg1
lda #13
sta arg2
lda #16 + 10
sta arg3
lda #1
sta arg4
jsr set_box_palette
; Set palette for status area
lda #0
sta arg0
lda #16 + 12
sta arg1
lda #14
sta arg2
lda #16 + 13
sta arg3
lda #1
sta arg4
jsr set_box_palette
; Draw initial items
lda inventory_count
bne notempty
LOAD_PTR no_items_str
ldx #11
ldy #32 + 11
jsr write_string
jmp itemend & $ffff
notempty:
jsr render_inventory_items
itemend:
jsr render_inventory_status_bar
; Draw help text
LOAD_PTR inventory_help_str
ldx #1
ldy #32 + 23
jsr write_string
lda inventory_count
beq nosetupselect
jsr select_inventory_item
nosetupselect:
LOAD_PTR inventory_palette
jsr fade_in
rts
.endproc
PROC do_render_inventory_status_bar
jsr load_area_name_tiles
; Render health bar outline
LOAD_PTR inventory_health_bar_top_tiles
ldx #1
ldy #32 + 24
lda #14
jsr write_tiles
ldx #1
ldy #32 + 25
lda #14
jsr write_tiles
ldx #1
ldy #32 + 26
lda #14
jsr write_tiles
ldx #2
ldy #32 + 27
lda #11
jsr write_tiles
jsr do_update_inventory_status & $ffff
; Render item boxes for equipped item
LOAD_PTR two_items_top_tiles
ldx #15
ldy #32 + 24
lda #8
jsr write_tiles
ldx #15
ldy #32 + 25
lda #8
jsr write_tiles
ldx #15
ldy #32 + 26
lda #8
jsr write_tiles
ldx #15
ldy #32 + 27
lda #8
jsr write_tiles
; Show key count and gold
LOAD_ALL_TILES $7b, inventory_key_tiles
lda key_count
cmp #1
beq one
cmp #2
beq two
cmp #3
beq three
cmp #4
beq four
cmp #5
beq five
cmp #6
beq six
LOAD_ALL_TILES $7b, zero_key_tiles
jmp keydone & $ffff
five:
jmp dofive & $ffff
six:
jmp dosix & $ffff
one:
LOAD_ALL_TILES $7b, one_key_tiles
jmp keydone & $ffff
two:
LOAD_ALL_TILES $7b, two_key_tiles
jmp keydone & $ffff
three:
LOAD_ALL_TILES $7b, three_key_tiles
jmp keydone & $ffff
four:
LOAD_ALL_TILES $7b, four_key_tiles
jmp keydone & $ffff
dofive:
LOAD_ALL_TILES $7b, five_key_tiles
jmp keydone & $ffff
dosix:
LOAD_ALL_TILES $7b, six_key_tiles
jmp keydone & $ffff
keydone:
LOAD_PTR inventory_keys
ldx #24
ldy #32 + 25
lda #5
jsr write_tiles
jsr generate_gold_string
LOAD_PTR gold_str
ldx #24
ldy #32 + 26
jsr write_string
; Render currently equipped items
lda equipped_weapon
ldx #$18
jsr load_item_sprite_tiles
lda #207
sta sprites + SPRITE_OAM_EQUIP_WEAPON
lda #$19
sta sprites + SPRITE_OAM_EQUIP_WEAPON + 1
lda #2
sta sprites + SPRITE_OAM_EQUIP_WEAPON + 2
lda #168
sta sprites + SPRITE_OAM_EQUIP_WEAPON + 3
lda #207
sta sprites + SPRITE_OAM_EQUIP_WEAPON + 4
lda #$1b
sta sprites + SPRITE_OAM_EQUIP_WEAPON + 5
lda #2
sta sprites + SPRITE_OAM_EQUIP_WEAPON + 6
lda #176
sta sprites + SPRITE_OAM_EQUIP_WEAPON + 7
lda equipped_armor
ldx #$1c
jsr load_item_sprite_tiles
lda #207
sta sprites + SPRITE_OAM_EQUIP_ARMOR
lda #$1d
sta sprites + SPRITE_OAM_EQUIP_ARMOR + 1
lda #2
sta sprites + SPRITE_OAM_EQUIP_ARMOR + 2
lda #136
sta sprites + SPRITE_OAM_EQUIP_ARMOR + 3
lda #207
sta sprites + SPRITE_OAM_EQUIP_ARMOR + 4
lda #$1f
sta sprites + SPRITE_OAM_EQUIP_ARMOR + 5
lda #2
sta sprites + SPRITE_OAM_EQUIP_ARMOR + 6
lda #144
sta sprites + SPRITE_OAM_EQUIP_ARMOR + 7
rts
.endproc
PROC do_update_inventory_status
jsr wait_for_vblank_if_rendering
; Render health bar according to player health
LOAD_PTR inventory_full_health_tiles
lda player_health
lsr
lsr
lsr
beq nofulltiles
ldx #2
ldy #32 + 25
jsr write_tiles
nofulltiles:
lda player_health
cmp #96
bcs fullhealth
LOAD_PTR inventory_partial_health_tile
lda player_health
lsr
lsr
lsr
clc
adc #2
tax
ldy #32 + 25
lda #1
jsr write_tiles
lda player_health
and #7
tay
lda PPUSTATUS
lda #$02
sta PPUADDR
lda #$e8
sta PPUADDR
lda health_bar_mask, y
sta PPUDATA
sta PPUDATA
sta PPUDATA
sta PPUDATA
sta PPUDATA
sta PPUDATA
sta PPUDATA
sta PPUDATA
fullhealth:
jsr prepare_for_rendering
rts
.endproc
PROC do_render_inventory_items
lda #0
sta arg0
itemloop:
lda arg0
clc
adc scroll
cmp inventory_count
bne hasitem
jmp itemend & $ffff
hasitem:
lda arg0
beq first
LOAD_PTR inventory_item_second_box_tiles
jmp drawitem & $ffff
first:
LOAD_PTR inventory_item_first_box_tiles
drawitem:
lda rendering_enabled
bne count
; Draw box around item graphic
ldx #2
lda arg0
asl
clc
adc arg0
adc #32 + 2
sta arg1
tay
lda #4
jsr write_tiles
ldx #2
inc arg1
ldy arg1
lda #4
jsr write_tiles
ldx #2
inc arg1
ldy arg1
lda #4
jsr write_tiles
ldx #2
inc arg1
ldy arg1
lda #4
jsr write_tiles
count:
; Load icon for the item
jsr wait_for_vblank_if_rendering
lda arg0
asl
asl
tax
lda arg0
clc
adc scroll
asl
tay
lda inventory + 1, y
jsr load_item_sprite_tiles
jsr prepare_for_rendering
lda arg0
asl
asl
asl
clc
adc #16
tay
lda arg0
asl
clc
adc arg0
asl
asl
asl
adc #31
sta sprites, y
sta sprites + 4, y
lda arg0
asl
asl
clc
adc #1
sta sprites + 1, y
adc #2
sta sprites + 5, y
lda #1
sta sprites + 2, y
sta sprites + 6, y
lda #32
sta sprites + 3, y
lda #40
sta sprites + 7, y
jsr wait_for_vblank_if_rendering
; Get string with item count
lda arg0
clc
adc scroll
asl
tax
lda inventory, x
jsr byte_to_padded_str
; Get the item type
lda arg0
clc
adc scroll
asl
tax
lda inventory + 1, x
jsr get_item_type
sta arg2