changeset 20:d41997416b3c

Identified SWI 13 routine and decoded EXAMINE display routine Decoded the routine that handles displaying the inventory screen. Also decoded the routine that calculates the object name strings. Also, the routine that updates the status line (left and right hands) was decoded due to proximity to the object name decoder.
author William Astle <lost@l-w.ca>
date Thu, 25 Dec 2014 00:21:56 -0700
parents e6d601bc9723
children 0a6eb8cabe1d
files dod.s
diffstat 1 files changed, 122 insertions(+), 120 deletions(-) [+]
line wrap: on
line diff
--- a/dod.s	Wed Dec 24 23:48:31 2014 -0700
+++ b/dod.s	Thu Dec 25 00:21:56 2014 -0700
@@ -113,7 +113,10 @@
 clearcommand	macro noexpand
 		dod S0B
 		endm
-
+; update the inventory on the status line
+updatestatus	macro noexpand
+		dod S0D
+		endm
 ; do a newline, show prompt, and cursor
 showprompt	macro noexpand
 		dod S0F
@@ -318,7 +321,7 @@
 V2AF		rmb 1
 V2B0		rmb 1
 V2B1		rmb 1
-V2B2		rmb 2
+displayptr	rmb 2				; pointer to routine to display the main dungeon area
 pageswap	rmb 1				nonzero means we're ready to swap graphics screens during IRQ
 V2B5		rmb 1
 V2B6		rmb 1
@@ -521,7 +524,7 @@
 		beq LC166
 		dec V29B
 		ldx #LCDB2
-		stx V2B2
+		stx displayptr
 		dec V294
 		dod S0E
 		delay
@@ -1119,9 +1122,9 @@
 		lda V26E
 		sta V270
 LC578		dec V26F
-		jsr [V2B2]
-		dec pageswap			set graphics swap required
-		sync				wait for swap to happen
+		jsr [displayptr]		; update the main display area
+		dec pageswap			; set graphics swap required
+		sync				; wait for swap to happen
 		dec V26E
 		lda V26E
 		cmpa #$f8
@@ -1134,9 +1137,9 @@
 		bra LC5AE
 LC595		cmpa #4
 		ble LC5AE
-LC599		jsr [V2B2]
-		dec pageswap			set graphics swap required
-		sync				wait for swap to happen
+LC599		jsr [displayptr]		; update the main display area
+		dec pageswap			; set graphics swap required
+		sync				; wait for swap to happen
 		inc V26F
 		inc V26E
 		lda V26E
@@ -1163,66 +1166,65 @@
 		dec V277
 LC5D7		bra LC5D7			wait forever (or until the IRQ does something)
 ; swi 13 routine
-LC5D9		ldu #V388
-		dec V2B7			set to nonstandard text area
-		lda levbgmask
-		coma
-		sta 6,u
-		clra
+LC5D9		ldu #V388			; point to parameters for status line
+		dec V2B7			; set to nonstandard text area
+		lda levbgmask			; get current level background
+		coma				; invert it for status line
+		sta 6,u				; set up for displaying status line
+		clra				; set position to start clearing (start of line)
 		clrb
-		bsr LC609
-		std 4,u
-		ldx lefthand
-		bsr LC617
-		renderstr
-		ldd #17
-		bsr LC609
-		ldx righthand
-		bsr LC617
-		tfr x,y
-		ldd #$21
-LC5FD		decb
-		tst ,y+
-		bpl LC5FD
-		std 4,u
-		renderstr
-		clr V2B7			reset to standard text rendering
+		bsr LC609			; clear half the line
+		std 4,u				; save display position
+		ldx lefthand			; fetch object in left hand
+		bsr LC617			; get name of object
+		renderstr			; display left hand object
+		ldd #17				; set position to start clearing
+		bsr LC609			; go clear half the line
+		ldx righthand			; fetch object in right hand
+		bsr LC617			; get name of object
+		tfr x,y				; save start pointer
+		ldd #$21			; set up offset for displaying right justified
+LC5FD		decb				; move cursor point left
+		tst ,y+				; end of string yet?
+		bpl LC5FD			; brif not - keep moving left
+		std 4,u				; save render position
+		renderstr			; display the right hand object
+		clr V2B7			; reset to standard text rendering
 		rts
-LC609		pshs a,b
-		std 4,u
-		ldd #15
-LC610		renderchar
-		decb
-		bne LC610
-		puls a,b,pc
-LC617		pshs a,b,y,u
-		leay ,x
-		bne LC622
-		ldx #LC650
-		bra LC63C
-LC622		ldu #wordbuff
-		tst 11,y
-		bne LC632
-		lda 9,y
-		ldx #kw_supreme
-		bsr LC63E
-		clr -1,u
-LC632		lda 10,y
-		ldx #kw_flask
-		bsr LC63E
-		ldx #wordbuff
-LC63C		puls a,b,y,u,pc
-LC63E		pshs a,x
-LC640		decodestrsb
-		deca
-		bpl LC640
-		ldx #stringbuf+1
-LC648		lda ,x+
-		sta ,u+
-		bpl LC648
-		puls a,x,pc
-LC650		fcb $05,$0d,$10,$14		unpacked string "EMPTY"
-		fcb $19,$ff
+LC609		pshs a,b			; save registers
+		std 4,u				; save the start position
+		ldd #15				; set up for a space (code 0) 15 times
+LC610		renderchar			; render a space
+		decb				; done yet?
+		bne LC610			; brif not
+		puls a,b,pc			; restore registers and return
+LC617		pshs a,b,y,u			; save registers
+		leay ,x				; point to object data
+		bne LC622			; brif there is object data
+		ldx #LC650			; point to "EMPTY" string
+		bra LC63C			; return result
+LC622		ldu #wordbuff			; point to word buffer
+		tst 11,y			; has it been revealed?
+		bne LC632			; brif not
+		lda 9,y				; fetch sub type
+		ldx #kw_supreme			; point to first "adjective" keyword
+		bsr LC63E			; copy correct string into buffer
+		clr -1,u			; make a space after adjective
+LC632		lda 10,y			; get base type
+		ldx #kw_flask			; point to first base type keyword
+		bsr LC63E			; copy correct string into buffer
+		ldx #wordbuff			; point to start of string
+LC63C		puls a,b,y,u,pc			; restore registers and return
+LC63E		pshs a,x			; save registers
+LC640		decodestrsb			; decode the current string into buffer
+		deca				; are we there yet?
+		bpl LC640			; brif not
+		ldx #stringbuf+1		; point to actual string (past object type)
+LC648		lda ,x+				; fetch character from decoded keyword
+		sta ,u+				; save in output buffer
+		bpl LC648			; brif not end of string yet
+		puls a,x,pc			; restore registers and return
+LC650		fcb $05,$0d,$10,$14,$19,$ff	; unpacked string "EMPTY"
 ; swi 14 routine
 LC656		tst V228
 		bne LC65F
@@ -1237,7 +1239,7 @@
 		adda 7,u
 		addb 8,u
 LC66C		std V26E
-		jsr [V2B2]
+		jsr [displayptr]		; update the main display area
 		puls a,b,x,y,u,pc
 ; swi 15 routine
 LC674		ldx #LC67A			point to newline followed by prompt
@@ -1373,9 +1375,9 @@
 		inc V2AE
 		dec V2AD
 		dec V2B1
-		dod S0D
+		updatestatus
 cmd_look	ldx #LCE66
-		stx V2B2
+		stx displayptr
 		dod S0E
 		rts
 ; swi 26 routine
@@ -2772,7 +2774,7 @@
 LD1C2		tst V2B5
 		bne LD1CD
 		ldx #LCDB2
-		cmpx V2B2
+		cmpx displayptr
 		bne LD1D1
 LD1CD		clr V2B5
 		dod S0E
@@ -3111,22 +3113,22 @@
 		dod S1A
 		dod S19
 		rts
-cmd_examine	ldx #LD495
-		stx V2B2
-		dod S0E
+cmd_examine	ldx #LD495			; pointer to the inventory display routine
+		stx displayptr			; set up the display update routine
+		dod S0E				; update the display
 		rts
-LD489		cleargfx2
+LD489		cleargfx2			; clear graphics
 		ldx ,u
 		ldu #V380
 		stx ,u
 		dec V2B7			set to nonstandard text rendering
 		rts
-LD495		bsr LD489
-		clr V2B6
-		ldd #10
+LD495		bsr LD489			; clear the graphics area and set up for text rendering
+		clr V2B6			; flag column zero in object list
+		ldd #10				; set up to centre "IN THIS ROOM"
 		std 4,u
-		renderstrimmp
-		fcb $62,$5c,$0a,$21		packed string "IN THIS ROOM"
+		renderstrimmp			; show the "IN THIS ROOM" heading
+		fcb $62,$5c,$0a,$21		; packed string "IN THIS ROOM"
 		fcb $33,$04,$9e,$f6
 		fcb $fc
 		ldd V213
@@ -3135,8 +3137,8 @@
 		ldx 4,u
 		leax 11,x
 		stx 4,u
-		renderstrimmp
-		fcb $56,$c7,$22,$86		packed string "!CREATURE!"
+		renderstrimmp			; show the "!CREATURE!" string if a creature is present
+		fcb $56,$c7,$22,$86		; packed string "!CREATURE!"
 		fcb $95,$91,$77,$f0
 LD4C0		clr V291
 LD4C2		ldd V213
@@ -3147,44 +3149,44 @@
 LD4CD		tst V2B6
 		beq LD4D3
 		bsr LD4FE
-LD4D3		ldd #$1b20
-LD4D6		renderchar
-		decb
-		bne LD4D6
-		ldx 4,u
+LD4D3		ldd #$1b20			; set up for displaying a row of !!!!
+LD4D6		renderchar			; display a !
+		decb				; done enough of them?
+		bne LD4D6			; brif not
+		ldx 4,u				; set up to centre "BACKPACK"
 		leax 12,x
 		stx 4,u
-		renderstrimmp
-		fcb $40,$82,$35,$c0		packed string "BACKPACK"
+		renderstrimmp			; display "BACKPACK" heading
+		fcb $40,$82,$35,$c0		; packed string "BACKPACK"
 		fcb $23,$5f,$c0
-		ldx #backpack
-LD4ED		ldx ,x
-		beq LD4FB
-		cmpx V224
-		bne LD4F7
-		com 6,u
-LD4F7		bsr LD505
-		bra LD4ED
-LD4FB		clr V2B7			reset to standard text rendering
+		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?			
+		bne LD4F7			; brif not
+		com 6,u				; invert video if it is
+LD4F7		bsr LD505			; display ojbect name
+		bra LD4ED			; go display another object
+LD4FB		clr V2B7			; reset to standard text rendering
 		rts
-LD4FE		lda #$1f
-		renderchar
-		clr V2B6
+LD4FE		lda #$1f			; character code for newline
+		renderchar			; go move to next line
+		clr V2B6			; flag column 1
 		rts
-LD505		pshs a,b,x
-		jsr LC617
-		renderstr
-		lda levbgmask
+LD505		pshs a,b,x			; save registers
+		jsr LC617			; fetch object name string (decoded)
+		renderstr			; display object name
+		lda levbgmask			; restore the proper text coloring
 		sta 6,u
-		com V2B6
-		beq LD51E
-		ldd 4,u
-		addd #$10
-		andb #$f0
-		std 4,u
-		skip2
-LD51E		bsr LD4FE
-		puls a,b,x,pc
+		com V2B6			; are we on column 1 or 2?
+		beq LD51E			; brif back at column 1
+		ldd 4,u				; get cursor position
+		addd #$10			; move right 16 cells
+		andb #$f0			; round down to multiple of 16
+		std 4,u				; save new cursor position
+		skip2				; move on with routine
+LD51E		bsr LD4FE			; do a newline
+		puls a,b,x,pc			; restore registers and return
 cmd_get		bsr LD576
 		bne LD573
 		jsr LCBBA
@@ -3260,7 +3262,7 @@
 		cmpx V224
 		bne LD5B7
 		std V224
-LD5B7		dod S0D
+LD5B7		updatestatus
 		dod S0E
 		rts
 cmd_incant	ldx #kwlist_adj
@@ -3283,7 +3285,7 @@
 		sta 9,u
 		dod S18
 		playsoundimm $0D
-		dod S0D
+		updatestatus
 		clr 7,u
 		cmpa #$12
 		beq LD5F0
@@ -3317,7 +3319,7 @@
 		lda 9,u
 LD638		dod S18
 		clr 11,u
-		dod S0D
+		updatestatus
 LD63E		rts
 cmd_turn	ldx #kwlist_dir
 		jsr LCBEC
@@ -3362,7 +3364,7 @@
 		bpl LD68B
 LD692		rts
 LD693		jmp LCBE1
-LD696		ldu V2B2
+LD696		ldu displayptr
 		cmpu #LCE66
 		bne LD6B9
 		ldx #$8080
@@ -3486,7 +3488,7 @@
 		stb 9,u				; change flask to EMPTY
 		clr 11,u
 		playsoundimm $0c		; play the flask sound
-		dod S0D
+		updatestatus			; update status line to reflect changed flask state
 		dod S0C
 		rts
 LD7A0		clra				; flag for not showing creatures
@@ -3498,7 +3500,7 @@
 		playsoundimm $0e		; play the scroll sound
 		clr V2AD
 		ldx #LCDB2
-		stx V2B2
+		stx displayptr
 		dod S0E
 LD7B6		rts
 cmd_zload	bsr LD7BC			; parse the file name