From 61a1c140f42defc1e24ca631bf85edb695176768 Mon Sep 17 00:00:00 2001 From: giomba Date: Fri, 22 Dec 2017 12:30:42 +0100 Subject: [PATCH] Probably fixed rare bug: the pseudo-random routine pseudo-randomly generated X,Y for new piece of food that corresponded to immediately next snake head position. This X,Y resulted empty when checked in the routine, but suddenly after it is overwritten with snake head, so food simply disappears. This leads to impossible game play, because no new pieces of food are generated if no food is previously eaten, but there is no food to eat, so... Hope to have fixed. --- BUGS | 1 - snake.asm | 12 +++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/BUGS b/BUGS index 448467b..96b7653 100644 --- a/BUGS +++ b/BUGS @@ -1,2 +1 @@ -- Fix random-eaten food that prevents from playng - Search for proper SID song diff --git a/snake.asm b/snake.asm index c6e7dec..2f7efca 100644 --- a/snake.asm +++ b/snake.asm @@ -342,11 +342,21 @@ genFood: sec ; if value is > 18, then subtract 18; now it sbc #18 ; surely is less than 18 foodNoMod: + cmp #0 bne foodNoLow ; if it is 0, then set 1 (avoid first line) lda #1 foodNoLow: sta calcTileY ; use this new value as tile Y-coordinate - jsr calcTileMem ; calc its address in memory + ; Now I have X and Y coordinate for food stored in calcTileX, calcTileY + ; and I must check it is not the location that I am going to overwrite + ; with the head in draw snake head... + cmp snakeY + bne foodOK + lda snakeX + cmp snakeX + beq genFood +foodOK: + jsr calcTileMem ; calc food address in memory lda (tileMem),y ; check if memory is empty cmp #$20 ; is there a space? bne genFood ; if not, must generate another number