A little help, maybe?
Posted: Sat Apr 14, 2018 11:53 pm
Hi. I've only recently started to learn 6502 code and decided to start off by breaking down the classic snake game found herehttps://skilldrick.github.io/easy6502/#snake . I'm trying to break it down into simple parts first by just making two pixels go down the assembler and then stop without any user input but am having trouble making it work as I described. Can anybody assist me in making it work at this basic level? Here is what i have so far which only creates 4 pixels and then stops.
Code: Select all
define snakeLength $00
define snakeHeadL $10
define snakeHeadH $11
define snakeBodyStart $12
init: ;initialize the values of the lo and hi bytes
;of the snake head and its length
lda #$04
sta snakeLength
lda #$21
sta snakeHeadL
lda #$01
sta snakeBodyStart
lda #$14
sta $02
lda #$22
sta snakeHeadH
sta $13
sta $15
loop: ;this is the main game loop
jsr shiftValues
jsr updateHead
jsr incHead
jsr gameCheck
jsr drawSnake
jmp loop
gameCheck:
ldx #2
lda snakeHeadL, x
cmp snakeHeadL
lda snakeHeadH,x
cmp snakeHeadH
beq gameOver
inx
inx
cpx snakeLength
beq drawSnake
jmp gameCheck
incHead:
inc snakeHeadH
lda #$6
cmp snakeHeadH
beq gameOver
rts
updateHead: ;this will move the head one row down
;the assembler
LDA snakeHeadL
CLC
ADC #$20
STA snakeHeadL
rts
shiftValues: ;this will shift the values of the
;snakeHead to the body
LDX snakeLength
DEX
LDA snakeHeadL, X ;will give body pixel
STA snakeBodyStart, X
rts
drawSnake: ;this will draw the snake at the current
;position after the updates
ldx snakeLength
lda #$01
sta (snakeHeadL,x)
ldx #$00
lda #$01
sta (snakeHeadL,x)
rts
gameOver: