GSCats/inventory.s

136 lines
2.1 KiB
ArmAsm
Raw Normal View History

2018-04-20 20:04:39 +00:00
;
; inventory
; Code and data structures related to the weapons inventory and store
;
; Created by Quinn Dunki on 8/13/17
;
2018-07-30 19:36:44 +00:00
INVENTORY_ITEMS = 3
2018-04-20 20:04:39 +00:00
ITEM_WIDTH = 16 ; In pixels
ITEM_HEIGHT = 16 ; In pixels
2018-04-20 20:04:39 +00:00
ICON_WIDTH = 8 ; In pixels
ICON_ORIGIN = (ITEM_WIDTH-ICON_WIDTH)/4 ; In bytes
2018-04-20 20:04:39 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; renderInventory
;
2018-06-10 02:29:00 +00:00
; Renders inventory for current player
;
; Trashes PARAML0
2018-04-20 20:04:39 +00:00
;
renderInventory:
SAVE_AXY
2018-06-10 02:29:00 +00:00
; Find inventory we need to render
ldy currentPlayer
PLAYERPTR_Y
2018-06-10 23:43:51 +00:00
tya
clc
adc #playerData
adc #PD_INVENTORY
sta PARAML1
2018-06-10 02:29:00 +00:00
; Compute initial VRAM position ($E1-relative)
2018-04-20 20:04:39 +00:00
ldy #(8192 + (160*10 + (160*ICON_ORIGIN + ICON_ORIGIN)))
ldx #0
2018-06-10 02:29:00 +00:00
2018-04-20 20:04:39 +00:00
renderInventoryLoop:
jsr renderInventoryItem
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
2018-04-20 20:04:39 +00:00
;
renderInventoryItem:
SAVE_AXY
2018-06-10 23:43:51 +00:00
stx renderInventoryItemIndex
2018-04-20 20:04:39 +00:00
phy
2018-06-10 02:29:00 +00:00
lda #2 ; Frame
2018-04-20 20:04:39 +00:00
clc
jsr DrawSpriteBank
2018-06-10 02:29:00 +00:00
; Find projectile type data
2018-06-10 23:43:51 +00:00
ldy renderInventoryItemIndex
2018-06-10 02:29:00 +00:00
PROJECTILETYPEPTR_Y
; Render projectile
lda projectileTypes+PT_FRAME1,y
2018-04-20 20:04:39 +00:00
ply
phy
clc
jsr DrawSpriteBank
2018-06-11 00:05:20 +00:00
; Render selection
ldy currentPlayer
PLAYERPTR_Y
lda playerData+PD_CURRWEAPON,y
cmp renderInventoryItemIndex
bne renderInventoryItem_unselected
ply
phy
lda #11
2018-06-11 00:05:20 +00:00
clc
jsr DrawSpriteBank
renderInventoryItem_unselected:
2018-06-10 23:43:51 +00:00
lda renderInventoryItemIndex
beq renderInventoryItem_abort ; First item shows no counter
; Render counter background
2018-04-20 20:04:39 +00:00
clc
pla
adc #ITEM_HEIGHT*160
pha
tay
lda #10
2018-04-20 20:04:39 +00:00
jsr DrawSpriteBank
; Render counter
2018-06-11 00:05:20 +00:00
lda renderInventoryItemIndex
asl
tay
2018-06-10 23:43:51 +00:00
lda (PARAML1),y
sta PARAML0
jsr intToString
sec
pla
sbc #($2000 - 160*2)-1 ; Font engine wants VRAM-relative
tax
lda #intToStringResult
jsr DrawNumber
2018-06-10 23:43:51 +00:00
renderInventoryItem_done:
RESTORE_AXY
2018-04-20 20:04:39 +00:00
rts
2018-06-10 23:43:51 +00:00
renderInventoryItem_abort:
ply ; Balance stack
bra renderInventoryItem_done
renderInventoryItemIndex:
.word 0
2018-04-20 20:04:39 +00:00