changeset 18:7c4ca17c8436

Identify various variables for player stats and decode several routines Decode the USE routines for flasks and torches, identify several variables related to the player stats and inventory, decode several routines related to parsing, and name the all ones and all zeroes direct page variables more sensibly. Also, replace a mistaken variable label when handling the THEWS flask with the correct constant.
author William Astle <lost@l-w.ca>
date Wed, 24 Dec 2014 23:32:01 -0700
parents 972825b01d81
children e6d601bc9723
files dod.s
diffstat 1 files changed, 164 insertions(+), 165 deletions(-) [+]
line wrap: on
line diff
--- a/dod.s	Wed Dec 24 21:36:31 2014 -0700
+++ b/dod.s	Wed Dec 24 23:32:01 2014 -0700
@@ -213,9 +213,9 @@
 ; the direct page
 		org $200
 V1F4		equ $1f4
-V200		rmb 2				initialized to $0000
+zero		rmb 2				initialized to $0000
 V202		rmb 1
-V203		rmb 2				initialized to $ffff
+allones		rmb 2				initialized to $ffff
 V205		rmb 1
 V206		rmb 1
 V207		rmb 1
@@ -228,19 +228,19 @@
 V213		rmb 1
 V214		rmb 1
 V215		rmb 2
-V217		rmb 2
+powerlevel	rmb 2				; player power
 V219		rmb 1
 V21A		rmb 1
 V21B		rmb 1
 V21C		rmb 1
-V21D		rmb 2
-V21F		rmb 2
-V221		rmb 2
+lefthand	rmb 2				; pointer to object carried in left hand
+righthand	rmb 2				; pointer to object carried in right hand
+damagelevel	rmb 2				; player damage level
 V223		rmb 1
-V224		rmb 2
+V224		rmb 2				; pointer to currently mounted torch
 V226		rmb 2
 V228		rmb 1
-V229		rmb 2
+backpack	rmb 2
 V22B		rmb 1
 levbgmask	rmb 1				the current level background colour mask
 lightlevel	rmb 1				the current light level, $ff means dark
@@ -339,7 +339,7 @@
 keybuf		rmb 32				keyboard ring buffer
 V2F1		rmb 32
 V311		rmb 2
-V313		rmb 32
+wordbuff		rmb 32
 V333		rmb 2
 stringbuf	rmb 34				temporary buffer used for decoding immediate packed strings
 fontbuf		rmb 10				temporary buffer used for decoding font data
@@ -361,8 +361,7 @@
 V397		rmb 1				nonzero if main text should not be rendered on secondary screen
 V398		rmb 43
 V3C3		rmb 17
-V3D4		rmb 20
-V3E8		rmb $20c
+V3D4		rmb $220
 V5F4		rmb $400
 V9F4		rmb 9
 V9FD		rmb $10a
@@ -391,14 +390,14 @@
 		jsr setSAM			go set the SAM register
 		lda #$f8			value for "pmode 4", color set 1
 		sta 2,x				set VDG mode
-		ldx #V200			point to start of variables
+		ldx #zero			point to start of variables
 LC030		clr ,x+				clear a byte
 		cmpx #TOPRAM			are we at the top of memory?
 		blo LC030			brif not
 		stu ,--s			set return address to the game initialization routine
-		lda #V200/256			point to MSB of direct page
+		lda #zero/256			point to MSB of direct page
 		tfr a,dp			set DP appropriately
-		setdp V200/256			tell the assembler about DP
+		setdp zero/256			tell the assembler about DP
 		ldy #LD7E8			point to variable initialization table
 LC041		lda ,y+				fetch number of bytes in this initializer
 		beq LC086			brif zero - we're done
@@ -501,12 +500,12 @@
 LC124		bsr LC114
 		ldd #$100b
 		std V213
-		clr V217
+		clr powerlevel
 		clra
 		ldu #LD7D9
 LC131		showprepare
 		dod S1A
-		ldy #V229
+		ldy #backpack
 LC139		lda ,u+
 		bmi LC14F
 		dod S17
@@ -545,7 +544,7 @@
 		sta PIA1+3
 		stb PIA1+1
 		rts
-LC18B		ldx V200			; get long delay constant
+LC18B		ldx zero			; get long delay constant
 LC18D		leax -1,x			; have we reached 0?
 		bne LC18D			; brif not
 		rts
@@ -556,7 +555,7 @@
 		romcall BLKOUT
 		bsr LC18B			; delay for a bit
 		romcall WRTLDR			; write a leader for data area
-		ldx #V200			; point to start of game state
+		ldx #zero			; point to start of game state
 LC1A6		ldd #$0180			; set block type to data, size to 128 bytes
 		std BLKTYP
 		stx CBUFAD			; set start of buffer to write
@@ -574,7 +573,7 @@
 		bsr LC16D			; read a block
 		bne LC1C6			; brif data block
 		ldx ,u				; get buffer pointer
-		ldu #V313			; point to requested file name
+		ldu #wordbuff			; point to requested file name
 		ldb #8				; 8 characters in file name
 LC1D5		lda ,x+				; does character match?
 		cmpa ,u+
@@ -582,7 +581,7 @@
 		decb				; end of file name?
 		bne LC1D5			; brif not - check another
 		romcall CSRDON			; start tape
-		ldx #V200			; point to game state area
+		ldx #zero			; point to game state area
 LC1E4		bsr LC16D			; read a block
 		bpl LC1E4			; brif it was still a data block
 		lds #STACK			; reset stack pointer
@@ -1080,7 +1079,7 @@
 		puls a,b,x,y,u,pc		restore registers and return
 ; swi 12 routine
 LC529		clr V2C1
-		ldd V217
+		ldd powerlevel
 		std V2C2
 		lda #6
 LC531		lsl V2C3
@@ -1089,12 +1088,12 @@
 		deca
 		bne LC531
 		clr V2C4
-		ldd V221
+		ldd damagelevel
 		std V2C5
 		lsl V2C6
 		rol V2C5
 		rol V2C4
-		ldd V217
+		ldd powerlevel
 		addd V2C5
 		std V2C5
 		ldb V2C4
@@ -1145,8 +1144,8 @@
 		ble LC599
 		clr V228
 		showprompt
-LC5AE		ldx V217
-		cmpx V221
+LC5AE		ldx powerlevel
+		cmpx damagelevel
 		blo LC5B5
 		rts
 ; This routine handles player death
@@ -1173,12 +1172,12 @@
 		clrb
 		bsr LC609
 		std 4,u
-		ldx V21D
+		ldx lefthand
 		bsr LC617
 		renderstr
 		ldd #17
 		bsr LC609
-		ldx V21F
+		ldx righthand
 		bsr LC617
 		tfr x,y
 		ldd #$21
@@ -1201,7 +1200,7 @@
 		bne LC622
 		ldx #LC650
 		bra LC63C
-LC622		ldu #V313
+LC622		ldu #wordbuff
 		tst 11,y
 		bne LC632
 		lda 9,y
@@ -1211,7 +1210,7 @@
 LC632		lda 10,y
 		ldx #kw_flask
 		bsr LC63E
-		ldx #V313
+		ldx #wordbuff
 LC63C		puls a,b,y,u,pc
 LC63E		pshs a,x
 LC640		decodestrsb
@@ -1463,7 +1462,7 @@
 		fdb LC827			sound 14
 		fdb LC8DA			sound 15
 		fdb LC8A6			sound 16
-		fdb LC8B2			sound 17
+		fdb LC8B2			sound 17 - torch sound
 		fdb LC93F			sound 18 - attack hit
 		fdb LC8E6			sound 19
 		fdb LC872			sound 20
@@ -1643,9 +1642,9 @@
 LC928		bsr LC97E
 		bls LC8C3			skip the caller to this routine and return to its caller
 		bra LC8C5
-LC92E		ldx V203
+LC92E		ldx allones
 		fcb $10
-LC931		ldx V200
+LC931		ldx zero
 LC933		stx V25B
 		ldx ,s
 		ldb ,x+
@@ -1763,7 +1762,7 @@
 		leax 1,x			move to next character position
 		rts				return to caller
 LC9BF		leax -1,x			move display pointer back one
-		cmpx V203			did we wrap around negative?			
+		cmpx allones			did we wrap around negative?			
 		bne LC9C9			brif not
 		ldx 2,u				get end of text area
 		leax -1,x			move back one position to be in the text area
@@ -2024,7 +2023,7 @@
 		fcb $08,$04,$02,$01		pixels 4, 5, 6, 7 (left to right) in byte
 LCB96		pshs a,x,u			; save registers
 		ldx V211			; get input buffer/line pointer
-		ldu #V313			; point to filename buffer
+		ldu #wordbuff			; point to word buffer
 LCB9D		lda ,x+				; get character from input
 		beq LCB9D			; brif end of line
 		bra LCBA5			; get on with things
@@ -2033,10 +2032,10 @@
 		sta ,u+				; save filename character
 		cmpu #V333			; are we at the end of the buffer?
 		blo LCBA3			; brif not - check another
-LCBAF		lda #$ff			; put end of filename marker
+LCBAF		lda #$ff			; put end of word marker
 		sta ,u+
 		stx V211			; save new input pointer location
-		tst V313			; set flags for whether we have a filename
+		tst wordbuff			; set flags for whether we have a word
 		puls a,x,u,pc			; restore registers and return
 LCBBA		clr V290
 		ldx #kwlist_obj
@@ -2056,57 +2055,57 @@
 		cmpb V28F
 		bne LCBDF
 		rts
-LCBDF		leas 2,s
-LCBE1		renderstrimmp
-		fcb $17,$7b,$d0			packed "???" string
-		rts
+LCBDF		leas 2,s			; don't return to caller - we're bailing out
+LCBE1		renderstrimmp			; display "???" for unknown command
+		fcb $17,$7b,$d0			; packed "???" string
+		rts				; return to caller's caller
 LCBE7		pshs a,b,x,y,u
 		clra
 		bra LCBF4
-LCBEC		pshs a,b,x,y,u
+LCBEC		pshs a,b,x,y,u			; save registers
 		clra
 		clrb
-		bsr LCB96
-		bmi LCC2D
-LCBF4		clr V278
-		clr V27B
-		ldb ,x+
-		stb V279
-LCBFC		ldu #V313
-		decodestrsb
-		ldy #stringbuf+1
-LCC05		ldb ,u+
-		bmi LCC17
-		cmpb ,y+
-		bne LCC22
-		tst ,y
-		bpl LCC05
-		tst ,u
-		bpl LCC22
+		bsr LCB96			; parse a word from the input line
+		bmi LCC2D			; brif no word present
+LCBF4		clr V278			; flag no match
+		clr V27B			; 
+		ldb ,x+				; fetch number of keywords in list
+		stb V279			; save it in temp counter
+LCBFC		ldu #wordbuff			; point to decode buffer
+		decodestrsb			; decode the keyword string
+		ldy #stringbuf+1		; point to decoded keyword string (past the object code)
+LCC05		ldb ,u+				; get a character from word string
+		bmi LCC17			; brif end of string
+		cmpb ,y+			; does it match?
+		bne LCC22			; brif not
+		tst ,y				; are we at the end of the keyword?
+		bpl LCC05			; brif not
+		tst ,u				; are we at the end of the word?
+		bpl LCC22			; brif not
 LCC15		dec V27B
-LCC17		tst V278
-		bne LCC2B
-		inc V278
-		ldb stringbuf
-		std ,s
-LCC22		inca
-		dec V279
-		bne LCBFC
-		tst V278
-		bne LCC2F
-LCC2B		ldd V203
-LCC2D		std ,s
-LCC2F		puls a,b,x,y,u,pc
-LCC31		ldx #kwlist_dir
-		bsr LCBEC
-		ble LCBDF
-		ldu #V21F
-		cmpa #1
-		beq LCC46
-		ldu #V21D
-		cmpa #0
-		bne LCBDF
-LCC46		ldx ,u
+LCC17		tst V278			; do we already have a match?
+		bne LCC2B			; brif so
+		inc V278			; mark match found
+		ldb stringbuf			; get the keyword code
+		std ,s				; save keyword number and object code
+LCC22		inca				; bump keyword count
+		dec V279			; have we reached the end of the list?
+		bne LCBFC			; brif not - check another keyword
+		tst V278			; do we have a match?
+		bne LCC2F			; brif so
+LCC2B		ldd allones			; flag error (-1)
+LCC2D		std ,s				; save result
+LCC2F		puls a,b,x,y,u,pc		; restore registers and return value, return
+LCC31		ldx #kwlist_dir			; point to direction keywords
+		bsr LCBEC			; evaluate the specified keyword
+		ble LCBDF			; brif no matching keyword
+		ldu #righthand			; point to right hand contents
+		cmpa #1				; is it right hand wanted?
+		beq LCC46			; brif so - return pointer
+		ldu #lefthand			; point to left hand contents
+		cmpa #0				; is it left hand wanted?
+		bne LCBDF			; brif not - error
+LCC46		ldx ,u				; fetch object pointer to X (and set Z if nothing)
 		rts
 LCC49		pshs a,b,x,u
 		deca
@@ -2608,14 +2607,14 @@
 		ldb #$ff
 		playsound
 		ldd #$8080
-		ldx V21D
+		ldx lefthand
 		bsr LD09E
-		ldx V21F
+		ldx righthand
 		bsr LD09E
 		sta V21A
 		stb V21C
 		tfr y,x
-		ldu #V217
+		ldu #powerlevel
 		jsr LD3D7
 		bmi LD099
 		playsoundimm $13
@@ -2781,13 +2780,13 @@
 		rts
 LD1D5		clra
 		clrb
-		subd V221
+		subd damagelevel
 		jsr LD379
-		addd V221
+		addd damagelevel
 		bgt LD1E2
 		clra
 		clrb
-LD1E2		std V221
+LD1E2		std damagelevel
 		dod S0C
 		lda V2AF
 		ldb #2
@@ -2859,7 +2858,7 @@
 		bne LD2B4
 LD26F		clra
 		renderchar
-		ldd V203
+		ldd allones
 		std ,u++
 		ldu #V2F1
 		stu V211
@@ -2889,12 +2888,12 @@
 		showprompt
 LD2B4		stu V211
 		puls a,b,x,y,u,pc
-cmd_attack	jsr LCC31
-		ldu ,u
-		bne LD2C2
-		ldu #VB07
-LD2C2		tfr u,y
-		lda 12,u
+cmd_attack	jsr LCC31			; get pointer to specified hand
+		ldu ,u				; fetch item in specified hand
+		bne LD2C2			; brif item there
+		ldu #VB07			; point to data for emtpy hand
+LD2C2		tfr u,y				; save object data pointer
+		lda 12,u			
 		sta V219
 		lda 13,u
 		sta V21B
@@ -2902,14 +2901,14 @@
 		rora
 		lsra
 		lsra
-		ldx V217
+		ldx powerlevel
 		jsr LD436
-		addd V221
-		std V221
+		addd damagelevel
+		std damagelevel
 		lda 10,u
 		adda #12
-		ldb #$ff
-		playsound
+		ldb #$ff			; set full volume
+		playsound			; play the attack sound
 		lda 9,u
 		cmpa #$13
 		blt LD2F7
@@ -2923,11 +2922,11 @@
 LD2F7		ldd V213
 		jsr LCF82
 		beq LD375
-		ldu #V217
+		ldu #powerlevel
 		exg x,u
-		lda 10,y
-		cmpa #1
-		beq LD31F
+		lda 10,y			; fetch object type
+		cmpa #1				; is it a ring?
+		beq LD31F			; go do successful attack if so - rings never miss
 		jsr LD3D7
 		bmi LD375
 		ldy V224
@@ -2938,9 +2937,9 @@
 LD319		dod S07
 		anda #3
 		bne LD375
-LD31F		playsoundimm $12
-		renderstrimmp
-		fcb $16,$f7,$b0			packed "!!!" string
+LD31F		playsoundimm $12		; play the "HIT" sound
+		renderstrimmp			; display the "!!!" for a successful hit
+		fcb $16,$f7,$b0			; packed "!!!" string
 		jsr LD40C
 		bhi LD375
 		leax 8,u
@@ -2958,10 +2957,10 @@
 		playsoundimm $15
 		ldd ,u
 		bsr LD37F
-		addd V217
+		addd powerlevel
 		bpl LD351
 		lda #$7f
-LD351		std V217
+LD351		std powerlevel
 		lda 13,u
 		cmpa #10
 		beq LD386
@@ -2972,11 +2971,11 @@
 		std V226
 		ldx #$b23
 		stx V20F
-		ldd V200
-		std V229
+		ldd zero
+		std backpack
 		std V224
-		std V21F
-		std V21D
+		std righthand
+		std lefthand
 		dod S19
 LD375		dod S0C
 LD377		asra
@@ -3011,7 +3010,7 @@
 		fcb $de,$dd,$ef,$60
 		delay
 		ldu V224
-		stu V229
+		stu backpack
 		beq LD3C4
 		clra
 		clrb
@@ -3157,7 +3156,7 @@
 		renderstrimmp
 		fcb $40,$82,$35,$c0		packed string "BACKPACK"
 		fcb $23,$5f,$c0
-		ldx #V229
+		ldx #backpack
 LD4ED		ldx ,x
 		beq LD4FB
 		cmpx V224
@@ -3228,19 +3227,19 @@
 		bra LD5B7
 LD573		jmp LCBE1
 LD576		jmp LCC31
-cmd_stow	bsr LD576
-		beq LD573
-LD57D		ldd V229
+cmd_stow	bsr LD576			; get pointer to object in requested hand
+		beq LD573			; brif no object in the hand
+LD57D		ldd backpack			; add this item to the start of the backpack list
 		std ,x
-		stx V229
-		clra
+		stx backpack
+		clra				; mark the selected hand as empty
 		clrb
 		std ,u
-		bra LD5B7
+		bra LD5B7			; update status line, etc.
 cmd_pull	bsr LD576
 		bne LD573
 		jsr LCBBA
-		ldx #V229
+		ldx #backpack
 LD593		tfr x,y
 		ldx ,x
 		beq LD573
@@ -3269,9 +3268,9 @@
 		tst V27B
 		beq LD5EF
 		std V28E
-		ldu V21D
+		ldu lefthand
 		bsr LD5D0
-		ldu V21F
+		ldu righthand
 LD5D0		beq LD5EF
 		lda 10,u
 		cmpa #1
@@ -3312,7 +3311,7 @@
 		beq LD63E
 		ldb #$19
 		mul
-		cmpd V217
+		cmpd powerlevel
 		bgt LD63E
 		lda 9,u
 LD638		dod S18
@@ -3420,8 +3419,8 @@
 LD70E		ldd V215
 		jsr LD37F
 		addd #3
-		addd V221
-		std V221
+		addd damagelevel
+		std damagelevel
 		dod S0C
 		dec pageswap			set graphics swap required
 		sync				wait for swap to happen
@@ -3441,51 +3440,51 @@
 		jsr LC660
 		tst ,s+
 		puls a,b,pc
-cmd_use		jsr LCC31
-		beq LD767
-		ldd 9,x
-		cmpb #5
-		bne LD757
-		stx V224
-		jsr LD57D
-		playsoundimm $11
+cmd_use		jsr LCC31			; fetch pointer to object in specified hand
+		beq LD767			; brif nothing in the hand
+		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
+		jsr LD57D			; go place the object in the backpack
+		playsoundimm $11		; play the torch sound
 		dod S0E
 		rts
-LD757		tfr x,u
-		ldx #LD76B
-LD75C		cmpa ,x
-		beq LD768
-		leax 3,x
-		cmpx #LD77A
-		blo LD75C
-LD767		rts
-LD768		jmp [1,x]
-LD76B		fcb $05
+LD757		tfr x,u				; save object pointer
+		ldx #LD76B			; point to jump table
+LD75C		cmpa ,x				; does the sub type match?
+		beq LD768			; brif so
+		leax 3,x			; move to next entry
+		cmpx #LD77A			; end of table?
+		blo LD75C			; brif not - try another
+LD767		rts				; no match - do nothing
+LD768		jmp [1,x]			; transfer control to specified routine
+LD76B		fcb $05				; "THEWS" (thews flask)
 		fdb LD77A
-		fcb $09
+		fcb $09				; "HALE" (hale flask)
 		fdb LD783
-		fcb $08
+		fcb $08				; "ABYE" (abye flask)
 		fdb LD787
-		fcb $04
+		fcb $04				; "SEER" (seer scroll)
 		fdb LD7A2
-		fcb $07
+		fcb $07				; "VISION" (vision scroll)
 		fdb LD7A0
-LD77A		ldd #V3E8
-		addd V217
-		std V217
-		bra LD792
-LD783		clra
+LD77A		ldd #1000			; thews increases player power by 1000
+		addd powerlevel			; add to existing power value
+		std powerlevel			; save new power value
+		bra LD792			; go empty the flask and update things
+LD783		clra				; new damage level = 0
 		clrb
-		bra LD790
-LD787		ldx V217
-		lda #$66
-		jsr LD436
-		addd V221
-LD790		std V221
-LD792		ldb #$17
-		stb 9,u
+		bra LD790			; go set damage level and clean up flask
+LD787		ldx powerlevel			; fetch player power level
+		lda #$66			; 2/3 fraction
+		jsr LD436			; go calculate 2/3 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"
+		stb 9,u				; change flask to EMPTY
 		clr 11,u
-		playsoundimm $0c
+		playsoundimm $0c		; play the flask sound
 		dod S0D
 		dod S0C
 		rts
@@ -3504,7 +3503,7 @@
 cmd_zload	bsr LD7BC			; parse the file name
 		dec V2B8			; flag ZLOAD
 		rts
-LD7BC		ldx #V313			; get start address to set to $ff
+LD7BC		ldx #wordbuff			; get start address to set to $ff
 		leau $20,x			; set $20 bytes
 		setblock			; go clear block to $ff
 		jmp LCB96
@@ -3533,7 +3532,7 @@
 		fcb $17
 		fdb V202
 		fcb $01				V202
-		fdb $ffff			V203 - 16 bit all ones value, or -1
+		fdb $ffff			allones - 16 bit all ones value, or -1
 		fcb $00				V205
 		fcb $80				V206
 		fcb 0				V207
@@ -3546,7 +3545,7 @@
 		fcb $0c				V213
 		fcb $16				V214
 		fdb $23				V215
-		fdb $17a0			V217
+		fdb $17a0			powerlevel - player power level
 		fcb $54	
 		fdb V380
 		fdb $1000			V380 - text area starts at top of screen