changeset 12:aa3901cbe279

Make sure creature table can't overflow on level creation. To guard against corrupted save games, make sure creature table cannot overflow on level creation. If it is going to overflow, the most powerful creatures will be the ones that are generated on level creation.
author William Astle <>
date Mon, 29 Dec 2014 23:22:20 -0700
parents e007731b20bd
children 9fe448b9b09c 1f5ce2f5e9aa
files dod.s
diffstat 1 files changed, 5 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/dod.s	Mon Dec 29 13:49:37 2014 -0700
+++ b/dod.s	Mon Dec 29 23:22:20 2014 -0700
@@ -1499,14 +1499,19 @@
 		jsr LC053			; initialize data for new level
 		jsr createmaze			; create the maze
 		ldu creaturecntptr		; point to creature counts for this level
+		ldb #32				; maximum number of creatures to make
+		pshs b				; save for later
 		lda #11				; offset for wizard
 LC783		ldb a,u				; get number of creatures required
 		beq LC78D			; brif none
 LC787		jsr LCFA5			; create a creature
+		dec ,s				; created maximum number of creatures?
+		beq LC78Dx			; brif max created
 		decb				; created enough creatures?
 		bne LC787			; brif not
 LC78D		deca				; move on to next creature
 		bpl LC783			; brif not finished all creatures
+LC78Dx		leas 1,s			; clean up stack
 		ldu #creaturetab-17		; point to creature table
 		clr objiterstart		; set to iterate from beginning of object table
 LC795		jsr LCF63			; go fetch object