Skip to content

Commit 6010d89

Browse files
committed
Fix for issue #2, now capping inventory quantities to max, including integer overflow condition.
1 parent 17f500f commit 6010d89

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

engine/inventory.asm

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,26 @@ inv_add_item: ; A: item index
642642
lda (ZP_PTR_1),y
643643
adc __inv_quant+1
644644
sta (ZP_PTR_1),y
645+
bvs @max ; reset to maximum value if overflow
646+
ldy #(INV_ITEM_MAX+1)
647+
cmp (ZP_PTR_1),y
648+
bmi @check_inv_ctrl
649+
bne @max
650+
ldy #INV_ITEM_QUANT
651+
lda (ZP_PTR_1),y
652+
ldy #INV_ITEM_MAX
653+
cmp (ZP_PTR_1),y
654+
bmi @check_inv_ctrl
655+
@max:
656+
ldy #INV_ITEM_MAX
657+
lda (ZP_PTR_1),y
658+
ldy #INV_ITEM_QUANT
659+
sta (ZP_PTR_1),y
660+
ldy #(INV_ITEM_MAX+1)
661+
lda (ZP_PTR_1),y
662+
ldy #(INV_ITEM_QUANT+1)
663+
sta (ZP_PTR_1),y
664+
@check_inv_ctrl:
645665
ldx #0
646666
@loop:
647667
cpx __inv_num_items

0 commit comments

Comments
 (0)