-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinventory.asm
1371 lines (1174 loc) · 42 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
;; +----------------------------------+
;; | INVENTORY UI STATE |
;; +----------------------------------+
invCrsrArea .byte $00 ; Currently Active Box - $00 = Backpack, $01 = Body, $02 = Floor
invCrsrAreaContentSize .byte $00
invSelArea .byte $ff ; Selection In Box - $00 = Backpack, $01 = Body, $02 = Floor, $ff = No selection
invSelPos .byte $00 ; Position of selected item in box
boxOffsets:
invBPOffset .byte $00 ; Offset in Backpack
invBDOffset .byte $00
invFLOffset .byte $00 ; Offset in Floor
boxPositions:
invBPPos .byte $00 ; Position in Backpack box
invBDPos .byte $00 ; Position in Body
invFLPos .byte $00 ; Position in Floor
boxSizes:
invBPSize .byte $08
invBDSize .byte $04
invFLSize .byte $02
boxScrlUp:
invBPScrlUp .byte $00
invBDScrlUp .byte $00
invFLScrlUp .byte $00
boxScrlDn:
invBPScrlDn .byte $00
invBDScrlDn .byte $00
invFLScrlDn .byte $00
boxTextWidth .byte $11
.byte $11
.byte $11
boxTableLo .byte <(backpackTable)
.byte <(bodyTable)
.byte <(floorTable)
boxTableHi .byte >(backpackTable)
.byte >(bodyTable)
.byte >(floorTable)
boxScreenLo .byte $3b
.byte $29
.byte $33
boxScreenHi .byte $04
.byte $04
.byte $07
boxColorHi .byte $d8
.byte $d8
.byte $db
boxCrsrTopOffsets
.byte $37
.byte $37
.byte $cf
.byte $cf
bodyPosTypes .byte $0b ; - Helmet
.byte $0c ; - Armor
.byte $06 ; - Melee
.byte $0a ; - Shield
floorTableOriginTable:
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
floorTableSize .byte $00
floorTable:
.byte $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00
backPackTop = $01
backPackLeft = $15
;; +----------------------------------+
;; | INITIALIZE INVENTORY MODE |
;; +----------------------------------+
enterInventory:
lda #$00
sta invCrsrArea
sta invBPPos
sta invBPOffset
sta invFLOffset
sta invFLPos
sta invBDPos
lda backpackSize
sta invCrsrAreaContentSize
lda #<inventory_enterupper_irq ; Disable game map interrupts
sta $0314
lda #>inventory_enterupper_irq
sta $0315
lda #$00 ; Set screen background color
sta $d021
jsr clearscreen
lda $d018 ; Remap tileset
ora #%00001110
sta $d018
lda #$09 ; Set character set color
sta $d022
lda #$1d
sta $d023
lda #$82 ; Set cursor sprite pointers
sta $07f8
lda #$83 ; Set cursor sprite pointers
sta $07f9
lda #$84 ; Set nav arrow sprite pointers
sta $07fa
sta $07fc
lda #$85
sta $07fb
sta $07fd
lda #$03 ; Set cursor sprites to multicolor
sta $d01c
lda #$02 ; Set up sprite colors
sta $d027
sta $d028
lda #$0a
sta $d025
lda #$0b ; Set nav sprites to dark grey
sta $d029
sta $d02a
sta $d02b
sta $d02c
lda #$0c ; Set body part sprites to gray
sta $d02d
sta $d02e
jsr populateFloorTable
jsr invPositionCrsr
lda #$3d ; Set arrows X POS
sta $d004
sta $d006
sta $d008
sta $d00a
lda #$38 ; Set BP nav sprite positions
sta $d005
lda #$af
sta $d007
lda #$d0 ; Set FL nav sprite positions
sta $d009
lda #$e0
sta $d00b
lda #$20 ; Set body part sprite locations
sta $d00c
sta $d00e
lda #%00111110 ; Set hi bits for bp nav sprites
sta $d010
lda #%11111111 ; Enable inventory sprites
sta $d015
lda #$00 ; Char/Body box
sta boxTop
sta boxLeft
lda #$12
sta boxWidth
lda #$13
sta boxHeight
jsr drawBox
lda #$12 ; BP Box
sta boxLeft
lda #$15
sta boxWidth
jsr drawBox
lda #$24
sta $0412
lda #$3c
sta $06e2
lda #$13 ; Floor Box
sta boxTop
lda #$06
sta boxHeight
jsr drawBox
lda #$00 ; Purse box
sta boxLeft
lda #$12
sta boxWidth
jsr drawBox
lda #$24
sta $070a
lda #$3c
sta $07d2
lda #$01
sta memcpy_rowSize
lda #<text_BACKPACK
sta $20
lda #>text_BACKPACK
sta $21
lda #$13
sta $22
lda #$04
sta $23
jsr memcpy_readRowsByte
lda #<text_FLOOR
sta $20
lda #>text_FLOOR
sta $21
lda #$0b
sta $22
lda #$07
sta $23
jsr memcpy_readRowsByte
lda #<text_PURSE
sta $20
lda #>text_PURSE
sta $21
lda #$f9
sta $22
lda #$06
sta $23
jsr memcpy_readRowsByte
lda #<text_GOLD
sta $20
lda #>text_GOLD
sta $21
lda #$4d
sta $22
lda #$07
sta $23
jsr memcpy_readRowsByte
lda #<text_WC
sta $20
lda #>text_WC
sta $21
lda #$92
sta $22
lda #$05
sta $23
jsr memcpy_readRowsByte
lda #<text_AC
sta $20
lda #>text_AC
sta $21
lda #$ba
sta $22
lda #$05
sta $23
jsr memcpy_readRowsByte
lda #<$0749
sta $20
lda #>$0749
sta $21
lda #<$db49
sta $24
lda #>$db49
sta $25
ldx #$42 ; Draw gold tile
clc
jsr drawItemTile
lda #$ff ; No selection on entry
sta invSelArea
jsr updateInventoryContents
jmp inventoryMainLoop
;; +----------------------------------+
;; | INVENTORY MAIN LOOP |
;; +----------------------------------+
key_INVENTORY_ACTION = #$20
inventoryMainLoop:
jsr inventoryReadKey
ilcont lda #$15 ; wait for raster retrace
cmp $d012
bne ilcont
lda screenDirty
cmp #$00
beq inventoryMainLoop
jsr invPositionCrsr
jsr updateInventoryContents
lda #$00
sta screenDirty
jmp inventoryMainLoop
exitInventory:
lda #%00000000 ; Disable all sprites
sta $d015
jsr clearscreen
lda #<enterstatusirq ; Interrupt vector
sta $0314
lda #>enterstatusirq
sta $0315
jsr enterMapMode
jsr initStatusArea
inc screenDirty
jmp mainloop
invPerformAction:
lda invSelArea
cmp #$ff
beq jmpSelectItem
jmp selectedItemAction
jmpSelectItem jmp selectItem
inventoryReadKey:
jsr $ffe4
and #$3f
inc screenDirty
cmp key_INVENTORY
beq exitInventory
cmp key_INVENTORY_ACTION
beq invPerformAction
cmp key_UP
beq moveItemContCrsrUp
cmp key_DOWN
beq moveItemContCrsrDn
cmp key_LEFT
beq moveItemContCrsrLeft
cmp key_RIGHT
beq moveItemContCrsrRight
dec screenDirty
rts
; CURSOR UP
moveItemContCrsrUp ldx invCrsrArea
lda boxPositions, x
beq moveItemContUpTop
dec boxPositions, x
rts
moveItemContUpTop lda boxOffsets, x
cmp #$00
beq leaveContUp
dec boxOffsets, x
rts
leaveContUp cpx #$02
beq invIntoBackPackArea
rts
; CURSOR DOWN
moveItemContCrsrDn ldx invCrsrArea
ldy boxPositions, x
iny
cpy invCrsrAreaContentSize
bcs leaveContDown
tya
cmp boxSizes, x
bcc incItemContCursor
lda #$01
cmp boxScrlDn, x
bne leaveContDown
inc boxOffsets, x
rts
incItemContCursor inc boxPositions, x
rts
leaveContDown cpx #$02
bcc invIntoFloorArea
rts
; CURSOR LEFT
moveItemContCrsrLeft:
lda invCrsrArea
cmp #$00
beq invIntoBodyArea
rts
; CURSOR RIGHT
moveItemContCrsrRight
cpx #$01
beq invIntoBackPackArea
moveInvNoAction rts
updCrsrAreaState:
lda invCrsrArea
cmp #$00
beq invIntoBackPackArea
cmp #$01
beq invIntoBodyArea
jmp invIntoFloorArea
invIntoBackPackArea:
lda #$00
sta invCrsrArea
lda backpackSize
sta invCrsrAreaContentSize
rts
invIntoFloorArea:
lda #$02
sta invCrsrArea
lda floorTableSize
sta invCrsrAreaContentSize
rts
invIntoBodyArea:
lda #$01
sta invCrsrArea
lda #$04
sta invCrsrAreaContentSize
rts
;; +----------------------------------+
;; | CURSOR POSITIONING |
;; +----------------------------------+
invPositionCrsr:
ldx invCrsrArea
lda boxPositions, x
sta num1
lda #$10
sta num2
jsr multiply
clc
ldx invCrsrArea
adc boxCrsrTopOffsets, x
cpx #$01
beq invPositionBDCrsr
invPositionRightCol:
sta $d001
sta $d003
lda #$a2
sta $d000
lda #$30
sta $d002
lda #%00111110
sta $d010
rts
invPositionBDCrsr:
sta $d001
sta $d003
lda #$12
sta $d000
lda #$9f
sta $d002
lda #%00111100
sta $d010
rts
;; +----------------------------------+
;; | INVENTORY ACTIONS |
;; +----------------------------------+
selectItem:
lda invCrsrArea
sta invSelArea
tax
lda boxPositions, x
clc
adc boxOffsets, x
sta invSelPos
jsr set20PtrToSelectedItem
ldy var_backpackItemModes
lda ($20), y
and #%10000000
cmp #%10000000
beq endSelectItem
lda #$ff
sta invSelArea
endSelectItem inc screenDirty
rts
selectedItemAction:
lda invCrsrArea ; branch to move item if origin and target area differ
cmp invSelArea
bne moveSelectedItem
tax ; Trade places if positions differ
lda boxPositions, x
clc
adc boxOffsets, x
cmp invSelPos
bne rearrangeItem
lda #$ff ; Else, deselect
sta invSelArea
sta invSelPos
inc screenDirty
rts
rearrangeItem
rts
moveSelectedItem
jsr set20PtrToSelectedItem ; Set container item pointers
jsr set22PtrToTargetItem
lda invCrsrArea
cmp #$01 ; Determine validity of move, if it's a wear/wield
beq preAttemptWield
cmp #$02 ; Just move for non-floor targets
bne mvItBetweenConts
jsr moveItemToFloor ; Go move to actual area item table if target is floor
jmp mvItPostCpy
preAttemptWield jsr attemptWield
cmp #$01
beq mvItBetweenConts
rts
mvItBetweenConts
lda #$01 ; Just copy to target
sta memcpy_rows
lda backpackRowSize
sta memcpy_rowSize
jsr memswitch_row
lda invSelArea ; If source was body, we can just flip the item mode of source pointer to 0
cmp #$01
bne notFromBD
jsr set20PtrToSelectedItem ; And set source item to off
ldy var_backpackItemModes
lda ($20), y
and #%01111111
sta ($20), y
notFromBD lda invSelArea ; If source was floor, we'll have to go remove it from area item table
cmp #$02
bne mvItPostCpy
jsr removeFromFloor
lda invCrsrArea
cmp #$01
bne mvItPostCpy
ldy var_backpackItemModes
lda ($20), y
and #%10000000
cmp #%10000000
bne mvItPostCpy
jsr moveItemToFloor
mvItPostCpy lda invCrsrArea ; If target was backpack, we'll have to increase the BP size
cmp #$00
beq mvItToBP
jmp endMvIt
mvItToBP inc backpackSize
jmp endMvIt
endMvIt jsr compactBackpack ; Update all containers upon successful move
jsr compactItemTable
jsr populateFloorTable
jsr updCrsrAreaState
lda #$ff
sta invSelArea
inc screenDirty
rts
moveItemToFloor lda #<itemTable ; Set Area Item Table as target
sta $22
lda #>itemTable
sta $23
lda itemTableRowSize
sta inc22ModVal
lda itemTableSize ; Forward to end of table
sta rollIterations
jsr roll22Ptr
ldy var_itemModes
lda ($20), y
sta ($22), y
and #%01111111
sta ($20), y
iny
lda playerX
sta ($22), y
iny
lda playerY
sta ($22), y
ldy var_backpackItemTileID
lda ($20), y
ldy var_itemTileID
sta ($22), y
ldy var_backpackItemTypeID
lda ($20), y
ldy var_itemTypeID
sta ($22), y
ldy var_backpackItemIdentifyToTypeID
lda ($20), y
ldy var_itemIdentifyToTypeID
sta ($22), y
ldy var_backpackItemValue
lda ($20), y
ldy var_itemValue
sta ($22), y
inc itemTableSize
rts
removeFromFloor ldx invSelPos
lda floorTableOriginTable, x
sta rollIterations
lda #<itemTable
sta $22
lda #>itemTable
sta $23
lda itemTableRowSize
sta inc22ModVal
jsr roll22Ptr
ldy var_itemModes
lda ($22), y
and #%01111111
sta ($22), y
rts
;; +----------------------------------+
;; | WEAR/WIELD CHECKS |
;; +----------------------------------+
attemptWield ldy var_backpackItemModes
lda ($20), y
and #%00011111
sta argItemModes
ldy boxPositions+1
lda bodyPosTypes, y
cmp argItemModes
bne attemptWieldFalse
lda #$01
rts
attemptWieldFalse lda #$00
rts
;; +----------------------------------+
;; | LOCATE ITEMS IN TABLES |
;; +----------------------------------+
set20PtrToSelectedItem ldx invSelArea
lda boxTableLo, x
sta $20
lda boxTableHi, x
sta $21
lda backpackRowSize
sta inc20ModVal
ldx #$00
forwardToSelItemLoop cpx invSelPos
beq forwardedToSelItem
jsr inc20Ptr
inx
jmp forwardToSelItemLoop
forwardedToSelItem rts
set22PtrToTargetItem ldx invCrsrArea
lda boxTableLo, x
sta $22
lda boxTableHi, x
sta $23
lda backpackRowSize
cpx #$00
beq forwardBPPos
cpx #$01
beq forwardBodyPos
forwardFLPos lda floorTableSize
jmp doForwardToTargetPos
forwardBPPos lda backpackSize
jmp doForwardToTargetPos
forwardBodyPos sta inc22ModVal
lda boxPositions, x
doForwardToTargetPos sta rollIterations
jsr roll22Ptr
rts
;; +----------------------------------+
;; | UPDATE INVENTORY CONTENTS |
;; +----------------------------------+
updateInventoryContents:
jsr drawBody
jsr drawBackPack
lda invBPScrlUp
sta $d029
lda invBPScrlDn
sta $d02a
jsr drawFloor
lda invFLScrlUp
sta $d02b
lda invFLScrlDn
sta $d02c
ldx playerGoldBalance
jsr byte_to_decimal
lda #<decBuffer
sta $20
lda #>decBuffer
sta $21
lda #$75
sta $22
lda #$07
sta $23
lda #$01
sta memcpy_rowSize
jsr memcpy_readRowsByte
jsr calcPlayerWC
ldx playerWC
jsr byte_to_decimal
lda #$96
sta $22
lda #$05
sta $23
jsr memcpy_readRowsByte
jsr calcPlayerAC
ldx playerAC
jsr byte_to_decimal
lda #$be
sta $22
lda #$05
sta $23
jsr memcpy_readRowsByte
rts
;; +----------------------------------+
;; | DRAW BACKPACK CONTENTS |
;; +----------------------------------+
drawBackPack lda #$00
sta itemContID
lda backpackSize
sta itemSourceSize
jmp drawItemContainer
;; +----------------------------------+
;; | DRAW BODY CONTENTS |
;; +----------------------------------+
drawBody lda #$01
sta itemContID
lda #$04
sta itemSourceSize
jmp drawItemContainer
;; +----------------------------------+
;; | DRAW FLOOR CONTENTS |
;; +----------------------------------+
drawFloor lda #$02
sta itemContID
lda floorTableSize
sta itemSourceSize
jmp drawItemContainer
;; +----------------------------------+
;; | DRAW ITEM CONTAINER |
;; +----------------------------------+
itemContSize .byte $00
itemSourceSize .byte $00
itemContOffset .byte $00
itemContTextWidth .byte $00
itemContID .byte $00
drawItemContainer:
ldx itemContID ; Read container configuration from tables
lda boxTableLo, x ; Source item table ptr
sta $22
lda boxTableHi, x
sta $23
lda backpackRowSize
sta inc22ModVal
lda boxTextWidth, x ; Container width
sta itemContTextWidth
lda boxSizes, x ; Look up source container size
sta itemContSize
lda boxScreenLo, x ; Screen ptr
sta $20
sta $24
lda boxScreenHi, x
sta $21
lda boxColorHi, x
sta $25
lda boxOffsets, x ; Roll item ptr to offset
sta rollIterations
sta itemContOffset
jsr roll22Ptr
ldx #$00
stx iter
jmp drawItemContLoop
itemContFillRemain cpx itemContSize ; Fill remaining rows in container with black
bcs drawItemContDone
ldy #$00
fillBLoop lda #$20
sta ($20), y
tya
clc
adc #$28
tay
lda #$20
sta ($20), y
tya
sbc #$27
tay
iny
cpy itemContTextWidth
bne fillBLoop
jsr incscreenoffset
inx
jmp itemContFillRemain
drawItemContDone jmp updateItemContainerArrows
rts
drawItemContLoop cpx itemSourceSize
beq itemContFillRemain
cpx itemContSize
beq drawItemContDone
ldy var_backpackItemModes ; Check if there is an item here (always true for non-body)
lda ($22), y
and #%10000000
sta argItemModes
bne itmContActTile
ldx #$00
jmp itmContDrawTile
itmContActTile ldy var_backpackItemTileID
lda ($22), y
tax ; Item Tile Index in X
itmContDrawTile ldy #$00 ; Horiz position of container items
jsr drawItemTile
lda $20
clc
adc #$03
sta print_target
lda $21
sta print_target+1
lda argItemModes
cmp #%10000000
beq doPrintItemName
doPrintNothing lda #<text_NOTHING
sta print_source
lda #>text_NOTHING
sta print_source+1
jmp doResolveNameLength
doPrintItemName ldy var_backpackItemTypeID ; Resolve item name from type
lda ($22), y
tax
lda itemNameLo, x
sta print_source
lda itemNameHi, x
sta print_source+1
doResolveNameLength ldy #$00
lda (print_source), y
sta print_source_length
lda itemContTextWidth ; Check if we need to truncate
clc
sbc #$02
cmp print_source_length
bcs noItemNameTrunc
sta print_source_length
noItemNameTrunc inc print_source
jsr print_string
lda itemContTextWidth
sbc #$03
sta num1
lda #$20
jsr pad_printed_string_to_num1
drawItemContinue
ldy invSelArea ; Check if area contains selection
cpy itemContID
bne drawItemNoSelect
ldy invSelPos ; Check if current position is selected
iny
tya
clc
sbc itemContOffset
cmp iter
bne drawItemNoSelect
lda #$03
sta target_color
jmp addItemNameColor
drawItemNoSelect lda #$01
sta target_color
addItemNameColor lda $24
clc
adc #$03
sta print_target
lda $25
sta print_target+1
jsr apply_text_color
jsr nextScreenRow
lda argItemModes
cmp #%10000000
beq drawItemSubLine
lda $20
sta print_target
lda $21
sta print_target+1
lda itemContTextWidth ; Clear subline if no item present
sta num1
ldy #$00
lda #$20
jsr pad_printed_string_to_num1
jmp drawICNextIter
drawItemSubLine lda $20 ; Keep pointer
sta tmpPtr1
lda $21
sta tmpPtr1+1
ldy var_backpackItemValue
lda ($22), y
sta argItemVal
ldy var_backpackItemModes
lda ($22), y
sta argItemModes
jsr itemSubLineToPrintSource
ldy #$00
lda (print_source), y
sta print_source_length
inc print_source
lda tmpPtr1 ; Restore kept pointer
sta $20
clc
adc #$03
sta print_target
lda tmpPtr1+1
sta $21
sta print_target+1
lda itemContTextWidth
clc
sbc #$01
sta print_rowsize
jsr print_string_right
lda $24
clc
adc #$03
sta print_target
lda $25
sta print_target+1
lda itemContTextWidth
clc
sbc #$02
sta print_source_length
jsr apply_text_color
drawICNextIter jsr nextScreenRow
jsr inc22Ptr
inc iter
ldx iter
jmp drawItemContLoop
drawItemTile:
lda tileChar1, x ; Draw upper row of tile chars to screen
sta ($20), y