Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; whenever calling player.s functions, put the player struct address for the player we are manipulating in the
- ; ZP_ADDRESS
- .local playfield
- playfield:
- .repeat 768
- .byte 0
- .endrepeat
- playfield_offset:
- .word $0000
- playerAddress:
- .word $00
- tempSpriteIndex:
- .byte $00
- ; write the players head to playfield and also draw to screen
- writeHead:
- jsr savePlayerAddress
- lda #$0
- sta playfield_offset
- sta playfield_offset+1
- ldy #$0
- lda (ZP_ADDRESS), Y ; get id and save to stack
- ; form the correct sprite index
- ; in the form of 00gpbbdd where
- ; gp - is a combined player id from having gold, and player id (saved in stack in this case)
- ; bb - is body part 0 - head, 1 - straight, 2 - bend, 3 - tail
- ; dd - is forwards direction 0 - right, 1 - down, 2 - left, 3 - up
- ; in this case, bb is 0 and we'll assume direction is left (0b10)
- ; and we just got the id, OR 0b10 with ID and save to stack
- ora #%10
- sta gpuIndex
- iny
- ; send set index command with proper arguments to GPU
- lda (ZP_ADDRESS), Y ; get head_x
- sta gpuX
- sta playfield_offset+1 ; save x to playfield_offset
- iny
- lda (ZP_ADDRESS), Y ; get head_y
- sta gpuY
- ldy #32
- jsr ROM_mul8x8 ; multiply A * Y (or head_y * 32)
- clc
- adc playfield_offset+1
- sta playfield_offset+1
- tya
- sta playfield_offset ; save 32 (width) times Y added to X in playfield offset
- clc ; add playfield baseaddress to playfield offset to get absolute address in playfield_offset
- lda #<playfield
- adc playfield_offset+1
- sta ZP_ADDRESS ; save in ZP_ADDRESS
- lda #>playfield
- adc playfield_offset
- sta ZP_ADDRESS+1
- lda gpuIndex
- sta (ZP_ADDRESS),Y
- jsr gpuSetIndex
- jsr loadPlayerAddress
- rts
- writeTail:
- jsr savePlayerAddress
- ldy #$0
- lda (ZP_ADDRESS), Y ; get id and save to stack
- ; form the correct sprite index
- ; in the form of 00gpbbdd where
- ; gp - is a combined player id from having gold, and player id (saved in stack in this case)
- ; bb - is body part 0 - head, 1 - straight, 2 - bend, 3 - tail
- ; dd - is forwards direction 0 - right, 1 - down, 2 - left, 3 - up
- ; in this case, bb is 3 (0b11) and we'll assume direction is 2 or left (0b10)
- ; let's OR the id in A with 0b1111 to get the proper sprite index
- ; and save it to stack
- ora #%1110
- sta gpuIndex
- ldy #3
- ; send set index command with proper arguments to GPU
- lda (ZP_ADDRESS), Y ; get tail_x
- sta gpuX
- sta playfield_offset+1 ; save x to playfield_offset
- iny
- lda (ZP_ADDRESS), Y ; get tail_y
- sta gpuY
- ldy #32
- jsr ROM_mul8x8 ; multiply A * Y (or tail_y * 32)
- clc
- adc playfield_offset+1
- sta playfield_offset+1
- tya
- sta playfield_offset ; save 32 (width) times Y added to X in playfield offset
- clc ; add playfield baseaddress to playfield offset to get absolute address in playfield_offset
- lda #<playfield
- adc playfield_offset+1
- sta ZP_ADDRESS ; save in ZP_ADDRESS
- lda #>playfield
- adc playfield_offset
- sta ZP_ADDRESS+1
- lda gpuIndex
- sta (ZP_ADDRESS),Y
- jsr gpuSetIndex
- jsr loadPlayerAddress
- rts
- moveHead:
- jsr savePlayerAddress
- ; get player id and save to stack
- ; get player data at head location
- ldy #1
- lda (ZP_ADDRESS), Y ; get head_x
- sta gpuX
- sta playfield_offset+1 ; save x to playfield_offset
- iny
- lda (ZP_ADDRESS), Y ; get head_y
- sta gpuY
- ldy #32
- jsr ROM_mul8x8 ; multiply A * Y (or head_y * 32)
- clc
- adc playfield_offset+1
- sta playfield_offset+1
- tya
- sta playfield_offset ; save 32 (width) times Y added to X in playfield offset
- clc ; add playfield baseaddress to playfield offset to get absolute address in playfield_offset
- lda #<playfield
- adc playfield_offset+1
- sta ZP_ADDRESS
- lda #>playfield
- adc playfield_offset
- sta ZP_ADDRESS+1
- ldy #0
- lda (ZP_ADDRESS),Y
- ; change spriteindex to be a straight part
- and #%11110011
- ora #%00000100
- sta (ZP_ADDRESS),Y
- sta gpuIndex
- jsr gpuSetIndex
- lda gpuIndex
- and #%11 ; And the direction
- beq moveHeadRight
- cmp #01
- beq moveHeadDown
- cmp #02
- beq moveHeadLeft
- ; move head up
- ; TODO: add code
- jsr loadPlayerAddress
- rts
- moveHeadRight:
- ; TODO: add code
- jsr loadPlayerAddress
- rts
- moveHeadDown:
- ; TODO: add code
- jsr loadPlayerAddress
- rts
- moveHeadLeft:
- jsr loadPlayerAddress
- ldy #1
- lda (ZP_ADDRESS),Y ; read X
- sec
- sbc #1
- and #%11111 ; scrap carry, ie. % 32
- sta (ZP_ADDRESS),Y ; save new X
- jsr loadPlayerAddress
- jsr writeHead
- rts
- moveTail:
- jsr savePlayerAddress
- ; get player id and save to stack
- ; get player data at tail location
- ldy #3
- lda (ZP_ADDRESS), Y ; get tail_x
- sta playfield_offset+1 ; save x to playfield_offset
- iny
- lda (ZP_ADDRESS), Y ; get tail_y
- ldy #32
- jsr ROM_mul8x8 ; multiply A * Y (or tail_y * 32)
- clc
- adc playfield_offset+1
- sta playfield_offset+1
- tya
- sta playfield_offset ; save 32 (width) times Y added to X in playfield offset
- clc ; add playfield baseaddress to playfield offset to get absolute address in playfield_offset
- lda #<playfield
- adc playfield_offset+1
- sta ZP_ADDRESS
- lda #>playfield
- adc playfield_offset
- sta ZP_ADDRESS+1
- ldy #0
- lda (ZP_ADDRESS),Y
- pha
- lda #$ff
- sta (ZP_ADDRESS),Y
- pla
- and #%11 ; And the direction
- beq moveTailRight
- cmp #01
- beq moveTailDown
- cmp #02
- beq moveTailLeft
- ; move tail up
- ; TODO: add code
- jsr loadPlayerAddress
- rts
- moveTailRight:
- ; TODO: add code
- jsr loadPlayerAddress
- rts
- moveTailDown:
- ; TODO: add code
- jsr loadPlayerAddress
- rts
- moveTailLeft:
- lda #$ff
- sta (ZP_ADDRESS), Y
- sta gpuIndex
- jsr loadPlayerAddress
- ldy #3
- lda (ZP_ADDRESS), Y ; get tail_x
- sta gpuX
- iny
- lda (ZP_ADDRESS), Y ; get tail_y
- sta gpuY
- jsr gpuSetIndex
- jsr loadPlayerAddress
- ldy #3
- lda (ZP_ADDRESS), Y ; get tail_x
- sec
- sbc #1
- and #%11111 ; scrap carry, ie. % 32
- sta (ZP_ADDRESS), Y ; save new head_x
- jsr loadPlayerAddress
- jsr writeTail
- rts
- loadPlayerAddress:
- lda playerAddress
- sta ZP_ADDRESS
- lda playerAddress+1
- sta ZP_ADDRESS+1
- rts
- savePlayerAddress:
- lda ZP_ADDRESS
- sta playerAddress
- lda ZP_ADDRESS+1
- sta playerAddress+1
- rts
- gpuX:
- .byte $00
- gpuY:
- .byte $00
- gpuIndex:
- .byte $00
- gpuSetIndex:
- lda #CF_CMD_SET_INDEX
- sta GPU_CMDQ_ADDRESS
- lda gpuX
- sta GPU_CMDQ_ADDRESS
- lda gpuY
- sta GPU_CMDQ_ADDRESS
- lda gpuIndex
- sta GPU_CMDQ_ADDRESS
- rts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement