changeset 31:5a661416e322

Decoded scroll display routine. Decoded the routine used for displaying scrolls. Also decoded some variables related to players, objects, and creatures.
author William Astle <lost@l-w.ca>
date Fri, 26 Dec 2014 18:55:05 -0700
parents ce4bf9bde1f0
children 8a94218c2a4c
files dod.s
diffstat 1 files changed, 154 insertions(+), 137 deletions(-) [+]
line wrap: on
line diff
--- a/dod.s	Fri Dec 26 13:16:48 2014 -0700
+++ b/dod.s	Fri Dec 26 18:55:05 2014 -0700
@@ -237,8 +237,8 @@
 V20D		rmb 2				; pointer to demo game command sequence
 objectfree	rmb 2				; pointer to next free object data slot
 V211		rmb 2
-V213		rmb 1
-V214		rmb 1
+playerloc	rmb 1				; current player position in maze (Y)
+V214		rmb 1				; current player position in maze (X)
 carryweight	rmb 2
 powerlevel	rmb 2				; player power
 V219		rmb 1
@@ -302,7 +302,7 @@
 currentlevel	rmb 1				; currently playing dungeon level
 creaturecountptr rmb 2				; pointer to creature count table for the current level
 V284		rmb 2
-V286		rmb 2
+holetabptr	rmb 2				; pointer to the hole table for this level
 V288		rmb 2
 V28A		rmb 1
 V28B		rmb 1
@@ -311,8 +311,8 @@
 parseobjtype	rmb 1
 parseobjtypegen	rmb 1
 parsegenobj	rmb 1
-V291		rmb 1
-V292		rmb 2
+V291		rmb 1				; for iterating over object list, zero means start, nonzero means underway
+V292		rmb 2				; current object pointer for iteration
 V294		rmb 1				; nonzero means to show creatures when displaying a scroll
 V295		rmb 2
 V297		rmb 3
@@ -511,8 +511,8 @@
 		cwai #$ef			; enable IRQ and wait for one
 		rts				; return to caller
 dogame		bsr enablepiairq		; set up interrupts and sound
-		ldd #$100b
-		std V213
+		ldd #$100b			; maze position (11,16)
+		std playerloc			; set start position there
 		clr powerlevel			; reset power level to new game level (keeps LSB of default value)
 		clra				; create maze for level 1
 		ldu #startobj			; point to new game backpack object list
@@ -533,7 +533,7 @@
 LC14F		tst waitnewgame			; are we doing a demo game?
 		beq LC166			; brif not
 		dec V29B
-		ldx #LCDB2			; set to scroll display
+		ldx #displayscroll		; set to scroll display
 		stx displayptr
 		dec V294			; set to show creatures on map
 		dod S0E				; show the dungeon map
@@ -1405,12 +1405,12 @@
 		addd #creaturecounts		; point to correct creature count table for this level
 		std creaturecountptr		; save pointer to creature count table
 		ldb currentlevel		; get back current level number
-		ldx #LCFFD
-LC768		stx V286
-LC76A		lda ,x+
-		bpl LC76A
-		decb
-		bpl LC768
+		ldx #holetab			; point to hole/ladder table
+LC768		stx holetabptr			; save hole/ladder data pointer
+LC76A		lda ,x+				; fetch flag
+		bpl LC76A			; brif we didn't consume a flag
+		decb				; are we at the right set of data for the level?
+		bpl LC768			; brif not - save new pointer and search again
 		ldx #V3D4			; get start address to clear
 		ldu #mazedata			; get end address to clear
 		clearblock			; go clear area to zeros
@@ -1427,7 +1427,7 @@
 		bpl LC783			; brif not finished all creatures
 		ldu #V3D4-17			; point to creature table
 		clr V291
-LC795		jsr LCF63
+LC795		jsr LCF63			
 		beq LC7B6
 		tst 5,x
 		bpl LC795
@@ -2310,76 +2310,82 @@
 dirmasks	fcb $03,$0c,$30,$c0		; direction masks
 doormasks	fcb $01,$04,$10,$40		; direction masks to create doors
 mdoormasks	fcb $02,$08,$20,$80		; direction masks to create magic doors
-LCDB2		ldu screendraw
-		ldd #$1f1f
-		std V27C
-LCDB9		ldd V27C
-		bsr LCE11
-		jsr LCC7B
-		clrb
-		lda ,x
-		inca
-		bne LCDC7
-		decb
-LCDC7		lda #6
-LCDC9		stb ,y
-		leay $20,y
-		deca
-		bne LCDC9
-		dec V27D
-		bpl LCDB9
-		lda #$1f
-		sta V27D
-		dec V27C
-		bpl LCDB9
-		tst V294
-		beq LCE2B
-		clr V291
-LCDE3		jsr LCF63
-		beq LCDF7
-		tst 5,x
-		bne LCDE3
-		ldd 2,x
-		bsr LCE11
-		ldd #8
-		bsr LCE1D
-		bra LCDE3
-LCDF7		ldx #V3D4-17
-LCDFA		leax $11,x
-		cmpx #mazedata
-		beq LCE2B
-		tst 12,x
-		beq LCDFA
-		ldd 15,x
-		bsr LCE11
-		ldd #$1054
-		bsr LCE1D
-		bra LCDFA
-LCE11		tfr d,y
-		ldb #$c0
-		mul
-		addd ,u
-		exg d,y
-		leay b,y
-		rts
-LCE1D		sta $20,y
-		stb $40,y
-		stb $60,y
-		sta $80,y
-LCE2A		rts
-LCE2B		ldd V213
-		bsr LCE11
-		ldd #$2418
-		bsr LCE1D
-		ldx V286
-		bsr LCE38
-LCE38		lda ,x+
-		bmi LCE2A
-		ldd ,x++
-		bsr LCE11
-		ldd #$3c24
-		bsr LCE1D
-		bra LCE38
+; This routine draws the display for a scroll.
+;
+; If V294 is set to nonzero, it displays creature and object information (SEER SCROLL)
+; otherwise it shows only the maze, holes, and player location (VISION SCROLL).
+;
+; V27C is used as a temporary scratch counter for displaying the maze itself.
+displayscroll	ldu screendraw			; point to screen we're using to draw on
+		ldd #$1f1f			; maximum X and Y coordinates
+		std V27C			; save coordinates
+LCDB9		ldd V27C			; fetch current coordinates
+		bsr LCE11			; calculate absolute pointer to screen location
+		jsr LCC7B			; fetch pointer to room data
+		clrb				; initialize to black
+		lda ,x				; fetch room data
+		inca				; is it an empty room?
+		bne LCDC7			; brif not
+		decb				; set to white
+LCDC7		lda #6				; set 6 rows
+LCDC9		stb ,y				; set a row
+		leay $20,y			; move to next row
+		deca				; done all rows?
+		bne LCDC9			; brif not
+		dec V27D			; move left one space
+		bpl LCDB9			; brif not at left yet
+		lda #$1f			; max right coord
+		sta V27D			; reset X coordinate to far right
+		dec V27C			; move back a row
+		bpl LCDB9			; brif still in map
+		tst V294			; are we showing creatures and objects?
+		beq LCE2B			; brif not
+		clr V291			; start iteration from scratch
+LCDE3		jsr LCF63			; go fetch object
+		beq LCDF7			; brif no more objects
+		tst 5,x				; is the object equipped/carried?
+		bne LCDE3			; brif so
+		ldd 2,x				; get coordinates of object
+		bsr LCE11			; get absolute address of location
+		ldd #8				; object location symbol
+		bsr LCE1D			; display symbol
+		bra LCDE3			; go check another object
+LCDF7		ldx #V3D4-17			; point to creature table
+LCDFA		leax $11,x			; move to next creature
+		cmpx #mazedata			; are we at the end of the creature table?
+		beq LCE2B			; brif so
+		tst 12,x			; is creature alive?
+		beq LCDFA			; brif not
+		ldd 15,x			; get current creature location
+		bsr LCE11			; turn location into pointer
+		ldd #$1054			; symbol for creature
+		bsr LCE1D			; go display symbol
+		bra LCDFA			; go check another creature
+LCE11		tfr d,y				; save requested coordinates
+		ldb #$c0			; calculate row offset based on display height of 6 px
+		mul				; now we have the offset from the start of the screen
+		addd ,u				; now D has the absolute address of the start of the line
+		exg d,y				; put pointer in Y and get back coordinates
+		leay b,y			; offset in the X direction for real pointer
+		rts				; return to caller
+LCE1D		sta $20,y			; set top row of symbol
+		stb $40,y			; set second row of symbol
+		stb $60,y			; set third row of symbol
+		sta $80,y			; set bottom row of symbol
+LCE2A		rts				; return to caller
+LCE2B		ldd playerloc			; get current player position
+		bsr LCE11			; calculate absolute address
+		ldd #$2418			; bit patterns to create a *
+		bsr LCE1D			; go mark the player position
+		ldx holetabptr			; point to the hole table for this level
+		bsr LCE38			; go display holes going up then fall through for holes going down
+LCE38		lda ,x+				; get hole type flag
+		bmi LCE2A			; brif end of this table (return)
+		ldd ,x++			; get coordinates
+		bsr LCE11			; calculate absolute address
+		ldd #$3c24			; symbol for displaying a hole
+		bsr LCE1D			; go display symbol
+		bra LCE38			; go check another entry
 LCE47		pshs a,x
 		ldx #LCF48
 		tst V273
@@ -2395,7 +2401,7 @@
 		puls a,x,pc
 LCE66		cleargfx2
 		clr V28B
-		ldd V213
+		ldd playerloc
 		std V27C
 LCE6E		bsr LCE47
 		ldd V27C
@@ -2509,21 +2515,21 @@
 		bne LCF53
 		andcc #$fb
 LCF62		rts
-LCF63		pshs a
-		lda currentlevel
-		ldx V292
-		tst V291
-		bne LCF72
-		ldx #emptyhand
-		dec V291
-LCF72		leax 14,x
-		stx V292
-		cmpx objectfree
-		beq LCF80
-		cmpa 4,x
-		bne LCF72
-		andcc #$fb
-LCF80		puls a,pc
+LCF63		pshs a				; save register
+		lda currentlevel		; fetch current level
+		ldx V292			; fetch object pointer
+		tst V291			; are we starting at beginning?
+		bne LCF72			; brif not
+		ldx #objecttab-14		; point to start of table
+		dec V291			; mark not at beginning any more
+LCF72		leax 14,x			; move to next object
+		stx V292			; save object pointer for iteration
+		cmpx objectfree			; are we at the end of the table?
+		beq LCF80			; brif so - return
+		cmpa 4,x			; is the object on this level?
+		bne LCF72			; brif not - look for another object
+		andcc #$fb			; turn off Z flag for object found
+LCF80		puls a,pc			; restore registers and return
 LCF82		ldx #V3D4-17
 LCF85		leax $11,x
 		cmpx #mazedata
@@ -2568,7 +2574,7 @@
 		jsr LC21D
 		puls a,b,x,y,u,pc
 LCFE1		pshs a,b,x,u
-		ldu V286
+		ldu holetabptr
 		bsr LCFF2
 		tsta
 		bpl LCFEE
@@ -2582,17 +2588,29 @@
 		cmpx 2,s
 		bne LCFF2
 LCFFC		rts
-LCFFD		fcb $80,$01,$00,$17
-LD001		fcb $00,$0f,$04,$00
-LD005		fcb $14,$11,$01,$1c
-LD009		fcb $1e,$80,$01,$02
-LD00D		fcb $03,$00,$03,$1f
-LD011		fcb $00,$13,$14,$00
-LD015		fcb $1f,$00,$80,$80
-LD019		fcb $00,$00,$1f,$00
-LD01D		fcb $05,$00,$00,$16
-LD021		fcb $1c,$00,$1f,$10
-LD025		fcb $80,$80
+; This is the "hole/ladder" table. Each entry is suffixed by $80. Each set specifies the
+; holes and ladders between two levels. The first is between levels 1 and 2. The second is
+; between levels 2 and 3. And so on. You will not that the table includes references to
+; level 0 (above the dungeon) and level 6 (below the dungeon) - they are simply empty
+; table entries which prevents having to have special cases to handle them.
+holetab		fcb $80				; marker for end of "level 0" to level 1
+		fcb 1,0,23
+		fcb 0,15,4
+		fcb 0,20,17
+		fcb 1,28,30
+		fcb $80				; marker for end of level 1-2
+		fcb 1,2,3
+		fcb 0,3,31
+		fcb 0,19,20
+		fcb 0,31,0
+		fcb $80				; marker for end of level 2-3
+		fcb $80				; marker for end of level 3-4
+		fcb 0,0,31
+		fcb 0,5,0
+		fcb 0,20,28
+		fcb 0,31,16
+		fcb $80				; marker for end of level 4-5
+		fcb $80				; marker for end of level 5-6
 LD027		ldx creaturecountptr
 		ldb #11
 		clra
@@ -2629,7 +2647,7 @@
 		dod S0E
 LD06A		jmp LD103
 LD06D		ldd 15,y
-		cmpd V213
+		cmpd playerloc
 		bne LD0B2
 		lda 13,y
 		ldb #$ff
@@ -2659,26 +2677,26 @@
 		bhs LD0B0
 		stx ,s
 LD0B0		puls a,b,x,pc
-LD0B2		cmpa V213
+LD0B2		cmpa playerloc
 		bne LD0C3
 		lda 16,y
 		ldb #1
-		suba V214
+		suba playerloc+1
 		bmi LD0D0
 		ldb #3
 		bra LD0D0
 LD0C3		ldd 15,y
-		cmpb V214
+		cmpb playerloc+1
 		bne LD0E4
 		ldb #2
-		suba V213
+		suba playerloc
 		bmi LD0D0
 		clrb
 LD0D0		stb V28A
 		ldd 15,y
 LD0D4		bsr LD136
 		bne LD0E4
-		cmpd V213
+		cmpd playerloc
 		bne LD0D4
 		ldb V28A
 		stb 14,y
@@ -2702,7 +2720,7 @@
 LD101		bsr LD14F
 LD103		lda 6,y
 		ldx 15,y
-		cmpx V213
+		cmpx playerloc
 		bne LD111
 		dod S0E
 		clr V2B5
@@ -2750,10 +2768,10 @@
 		ldb V28A
 		stb 14,y
 		ldd 15,y
-		suba V213
+		suba playerloc
 		bpl LD16F
 		nega
-LD16F		subb V214
+LD16F		subb playerloc+1
 		bpl LD174
 		negb
 LD174		stb V2C1
@@ -2799,7 +2817,7 @@
 		rts
 LD1C2		tst V2B5
 		bne LD1CD
-		ldx #LCDB2
+		ldx #displayscroll
 		cmpx displayptr
 		bne LD1D1
 LD1CD		clr V2B5
@@ -2947,7 +2965,7 @@
 		lda #$16			; type for "GOLD"
 		sta 9,u				; set to GOLD ring
 		jsr LD638			; update object stats appropriately
-LD2F7		ldd V213
+LD2F7		ldd playerloc
 		jsr LCF82
 		beq LD375
 		ldu #powerlevel
@@ -3048,7 +3066,7 @@
 		lda #3				
 		dod S1A
 		jsr LCF97
-		std V213
+		std playerloc
 		fadeout				; fade out the wizard
 		dod S19
 		rts
@@ -3116,7 +3134,7 @@
 		rola
 		std ,s				; save integer result for return
 		puls a,b,x,pc			; clean up parameters, fetch product, and return
-cmd_climb	ldd V213
+cmd_climb	ldd playerloc
 		jsr LCFE1
 		bmi LD46F
 		sta V2C1
@@ -3158,7 +3176,7 @@
 		fcb $62,$5c,$0a,$21		; packed string "IN THIS ROOM"
 		fcb $33,$04,$9e,$f6
 		fcb $fc
-		ldd V213
+		ldd playerloc
 		jsr LCF82
 		beq LD4C0
 		ldx 4,u
@@ -3168,7 +3186,7 @@
 		fcb $56,$c7,$22,$86		; packed string "!CREATURE!"
 		fcb $95,$91,$77,$f0
 LD4C0		clr V291
-LD4C2		ldd V213
+LD4C2		ldd playerloc
 		jsr LCF53
 		beq LD4CD
 		bsr LD505
@@ -3218,7 +3236,7 @@
 		bne LD573
 		jsr parseobj
 		clr V291
-LD52B		ldd V213
+LD52B		ldd playerloc
 		jsr LCF53
 		beq LD573
 		tst parsegenobj
@@ -3242,7 +3260,7 @@
 		clrb
 		std ,u
 		clr 5,x
-		ldd V213
+		ldd playerloc
 		std 2,x
 		lda currentlevel
 		sta 4,x
@@ -3460,13 +3478,13 @@
 		addb V223
 		andb #3
 		stb V28A
-		ldd V213
+		ldd playerloc
 		jsr LD136
 		beq LD738
 		playsoundimm $14
 		dec ,s
-		ldd V213
-LD738		std V213
+		ldd playerloc
+LD738		std playerloc
 		jsr LC660
 		tst ,s+
 		puls a,b,pc
@@ -3526,8 +3544,8 @@
 		bne LD7B6
 		playsoundimm $0e		; play the scroll sound
 		clr V2AD
-		ldx #LCDB2
-		stx displayptr
+		ldx #displayscroll		; point to scroll display routine
+		stx displayptr			; set the display handler
 		dod S0E
 LD7B6		rts
 cmd_zload	bsr LD7BC			; parse the file name
@@ -3578,8 +3596,7 @@
 		fdb demogame			; V20D - pointer to demo game command sequence
 		fdb objecttab			; objectfree - next free object entry
 		fdb V2F1			; V211
-		fcb $0c				; V213
-		fcb $16				; V214
+		fcb 12,22			; playerloc - starting coordinates in maze (y, x)
 		fdb $23				; carryweight - the weight of objects the player is carrying
 		fdb $17a0			; powerlevel - player power level
 		fcb $54