Hi,
I've been (slowly) coding a Snake game as a fun way to learn assembler.
See
http://www.retrosoftware.co.uk/forum/viewtopic.php?f=19&t=745and
http://www.retrosoftware.co.uk/wiki/index.php/JSnakeDevDiaryI've encountered a bug that I can't work out. I have a delay loop which I use to slow down the movement of the Snake to a playable speed. At the moment, the loops always decrement from same start value, but in time I would like to be able to vary said start value (to change Snake movement speed). Meanwhile, I've been changing the the start values and then compiling/running just to see any visible differences in speed.
Two issues:
1: Main issue - when I only have the delay loop cycle round a few times (I can't determine the exact value as yet) .. the Snake speeds up when say Left key (Z) is held down, but all the other directions are unaffected. Sometimes two or three directions are affected. This seems to depend on the values entered.. but I haven't established an exact pattern. If I increase the start values above a certain threshold (that I haven't established exactly yet) .. the issue disappears.
2: Observed speed up of snake movement doesn't seem proportional to delay loop start values. i.e say I have outer loop start at 192 and inner loop at 128, I can't see a visible difference until inner loop starts at 64..
At the moment, I'm more bothered about first issue.
Here is the Delay routine
Code:
.Delay
ldx #48
.dxloop
ldy #32
.dyloop
dey
bne dyloop
dex
bne dxloop
lda #0 : ldx #0 : ldy #0
rts
This is called from a main loop which jumps to these subroutines, moving the snake along the screen one unit at a time until a collision occurs , i.e:
jsr Delay
jsr GetKeypress
jsr Move (animates the Snake!)
jsr CollisionDetect
I am wondering if it is something to do with the GetKeyPress routine being affected by preceding Delay routine - but if this is the case, why do I not encounter issue 1 regardless of values in the inner and outer loops?
Here is an excerpt of the GetKeyPress routine:
Code:
ldx #Key_Z
jsr inkey
bne LeftPressed
ldx #Key_X
jsr inkey
bne RightPressed
ldx #Key_Colon
jsr inkey
bne UpPressed
ldx #Key_ForwardSlash
jsr inkey
bne DownPressed
jmp GKPEnd ; no key pressed
.LeftPressed
lda SnakeDirection
cmp #DirRight
beq IgnoreLeftKey
lda #DirLeft
sta SnakeDirection
.IgnoreLeftKey
rts
.
.
.
same idea for rest of directions
.
.
And the inkey subroutine:
Code:
.inkey ; routine from Creative assembler book
PHA ;Save A
TYA ; Save Y
PHA
LDY #&FF ;Negative numbers
LDA #&81 ; osbyte &81 is INKEY
JSR osbyte ; Do it
PLA ;Restore Y
TAY
PLA ; Restore A
CPX #&00 ; Adjust zero flag
RTS ; and return
Any help or suggestions on troubleshooting this would be gratefully received.
Thanks,
jbnbeeb