changeset 21:0a6eb8cabe1d

Correct interpretation of the LD436 routine The LD436 multiplication takes an 8 bit fixed point fraction as the mulplier in A, with the binary point to the right of bit 7.
author William Astle <lost@l-w.ca>
date Thu, 25 Dec 2014 22:38:14 -0700
parents d41997416b3c
children b54feb3d64eb
files dod.s
diffstat 1 files changed, 42 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/dod.s	Thu Dec 25 00:21:56 2014 -0700
+++ b/dod.s	Thu Dec 25 22:38:14 2014 -0700
@@ -240,7 +240,7 @@
 righthand	rmb 2				; pointer to object carried in right hand
 damagelevel	rmb 2				; player damage level
 V223		rmb 1
-V224		rmb 2				; pointer to currently mounted torch
+curtorch	rmb 2				; pointer to currently mounted torch
 V226		rmb 2
 V228		rmb 1
 backpack	rmb 2
@@ -1229,13 +1229,13 @@
 LC656		tst V228
 		bne LC65F
 		bsr LC660
-		dec pageswap			flag graphics swap required
-		sync				wait for swap to happen
+		dec pageswap			; flag graphics swap required
+		sync				; wait for swap to happen
 LC65F		rts
 LC660		pshs a,b,x,y,u
 		ldd V226
-		ldu V224
-		beq LC66C
+		ldu curtorch			; is there a torch lit?
+		beq LC66C			; brif not
 		adda 7,u
 		addb 8,u
 LC66C		std V26E
@@ -1460,10 +1460,10 @@
 		fdb LC877			sound 10
 		fdb LC877			sound 11
 		fdb LC80A			sound 12 - flask sound
-		fdb LC811			sound 13
+		fdb LC811			sound 13 - ring sound
 		fdb LC827			sound 14 - scroll sound
-		fdb LC8DA			sound 15
-		fdb LC8A6			sound 16
+		fdb LC8DA			sound 15 - shield sound
+		fdb LC8A6			sound 16 - sword sound
 		fdb LC8B2			sound 17 - torch sound
 		fdb LC93F			sound 18 - attack hit
 		fdb LC8E6			sound 19
@@ -2751,7 +2751,7 @@
 LD196		dec V2B5
 LD198		clra
 LD199		puls a,b,x,pc
-LD19B		ldu V224
+LD19B		ldu curtorch
 		beq LD1BC
 		lda 6,u
 		beq LD1BC
@@ -2907,20 +2907,20 @@
 		jsr LD436
 		addd damagelevel
 		std damagelevel
-		lda 10,u
-		adda #12
+		lda 10,u			; get object type
+		adda #12			; offset into sound table
 		ldb #$ff			; set full volume
-		playsound			; play the attack sound
-		lda 9,u
-		cmpa #$13
-		blt LD2F7
-		cmpa #$15
-		bgt LD2F7
-		dec 6,u
-		bne LD2F7
-		lda #$16
-		sta 9,u
-		jsr LD638
+		playsound			; play the attack sound for the object
+		lda 9,u				; get object subtype
+		cmpa #$13			; is it less than "ENERGY"?
+		blt LD2F7			; brif so - not an expiring ring
+		cmpa #$15			; is it more than "FIRE"?
+		bgt LD2F7			; brif so - not an expiring ring
+		dec 6,u				; count down ring usages
+		bne LD2F7			; brif not used up
+		lda #$16			; type for "GOLD"
+		sta 9,u				; set to GOLD ring
+		jsr LD638			; update object stats appropriately
 LD2F7		ldd V213
 		jsr LCF82
 		beq LD375
@@ -2931,14 +2931,14 @@
 		beq LD31F			; go do successful attack if so - rings never miss
 		jsr LD3D7
 		bmi LD375
-		ldy V224
-		beq LD319
-		lda 9,y
-		cmpa #$18
-		bne LD31F
-LD319		dod S07
-		anda #3
-		bne LD375
+		ldy curtorch			; do we have a torch burning?
+		beq LD319			; brif not
+		lda 9,y				; get torch type
+		cmpa #$18			; is it "DEAD"?
+		bne LD31F			; brif not
+LD319		dod S07				; get random number
+		anda #3				; 1 in 4 chance of a hit in the dark
+		bne LD375			; brif we didn't hit
 LD31F		playsoundimm $12		; play the "HIT" sound
 		renderstrimmp			; display the "!!!" for a successful hit
 		fcb $16,$f7,$b0			; packed "!!!" string
@@ -2975,7 +2975,7 @@
 		stx V20F
 		ldd zero
 		std backpack
-		std V224
+		std curtorch
 		std righthand
 		std lefthand
 		dod S19
@@ -3011,7 +3011,7 @@
 		fcb $0a,$23,$20,$23
 		fcb $de,$dd,$ef,$60
 		delay
-		ldu V224
+		ldu curtorch
 		stu backpack
 		beq LD3C4
 		clra
@@ -3074,7 +3074,8 @@
 		ldx ,u
 		cmpx 10,u
 		puls a,b,x,y,u,pc
-; Multiply X by the value in A, where the binary point in A is to the left of bit 7.
+; Multiply X by the value in A, where the binary point in A is to the left of bit 6. Return only the
+; integer result in D (rounded down).
 LD436		pshs a,b,x			; save parameters and registers
 		clr V2C1			; blank out temp storage area
 		ldb 3,s				; get LSB of X
@@ -3084,8 +3085,8 @@
 		ldb 2,s				; fetch MSB of X
 		mul				; multiply it
 		addd V2C1			; add in partial product
-		lsl V2C3			; shift product left (adjust for binary point in A)
-		rolb
+		lsl V2C3			;* shift product left so binary point is to the right of
+		rolb				;* of the upper 16 bits - leave interger result in D.
 		rola
 		std ,s				; save integer result for return
 		puls a,b,x,pc			; clean up parameters, fetch product, and return
@@ -3162,7 +3163,7 @@
 		ldx #backpack			; point to backpack head pointer
 LD4ED		ldx ,x				; get next item in backpack
 		beq LD4FB			; brif nothing else in backpack
-		cmpx V224			; is the object the currently burning torch?			
+		cmpx curtorch			; is the object the currently burning torch?			
 		bne LD4F7			; brif not
 		com 6,u				; invert video if it is
 LD4F7		bsr LD505			; display ojbect name
@@ -3259,9 +3260,9 @@
 		stx ,u
 LD5AF		clra
 		clrb
-		cmpx V224
+		cmpx curtorch
 		bne LD5B7
-		std V224
+		std curtorch
 LD5B7		updatestatus
 		dod S0E
 		rts
@@ -3448,7 +3449,7 @@
 		ldd 9,x				; fetch object type and subtype
 		cmpb #5				; is it a torch?
 		bne LD757			; brif not
-		stx V224			; set object as currently mounted
+		stx curtorch			; set object as currently mounted
 		jsr LD57D			; go place the object in the backpack
 		playsoundimm $11		; play the torch sound
 		dod S0E
@@ -3480,8 +3481,8 @@
 		clrb
 		bra LD790			; go set damage level and clean up flask
 LD787		ldx powerlevel			; fetch player power level
-		lda #$66			; roughly 0.4
-		jsr LD436			; go calculate 0.4 of player power level
+		lda #$66			; roughly 0.8
+		jsr LD436			; go calculate 80% of player power level
 		addd damagelevel		; add that to the current damage level
 LD790		std damagelevel			; save new damage level
 LD792		ldb #$17			; type for "EMPTY"