changeset 2:4e01eb6d6989

Added an introduction and various comments to the source code. Added an introduction which duplicates the apparent license grant from the original creators of the game with an explanation of what this source code actually is. Also added various comments for several routines, including the text rendering routines. Also replaced several "dod xxx" macro calls with more descriptive macros.
author William Astle <lost@l-w.ca>
date Fri, 24 May 2013 22:30:36 -0600
parents 0f6f31ed2ebe
children 969c3d833728
files dod.s
diffstat 1 files changed, 255 insertions(+), 203 deletions(-) [+]
line wrap: on
line diff
--- a/dod.s	Fri May 24 20:28:30 2013 -0600
+++ b/dod.s	Fri May 24 22:30:36 2013 -0600
@@ -1,3 +1,57 @@
+; Dungeons of Daggorath
+;
+; Original game copyright © 1982 by Dyna Micro
+;
+; The code contained in this file is not the original source code to Dungeons of Daggorath. It was
+; constructed by William Astle in 2013 by disassembling the Dungeons of Daggorath ROM.
+;
+; According to a web page retrieved from http://frodpod.tripod.com/lisence.html on May 24, 2013,
+; this endeavour is permitted. In case the web page becomes unavailable, and because it contains what
+; I believe to be important credit information, I have reproduced the text of it below:
+;
+;***********************************************************************************************************
+;* Grant of license to reproduce Dungeons of Daggorath
+;*
+;* My name is Douglas J. Morgan.  I was the president of DynaMicro, Inc. (since dissolved), the company
+;* which conceived, created and wrote Dungeons of Daggorath, a best selling Radio Shack Color Computer
+;* adventure game. 
+;*
+;* I have examined the contract I signed with Radio Shack for their license of the game.  The contract
+;* provides that Radio Shack shall have an exclusive license to manufacture and produce the game, but
+;* that said exclusive license shall revert to a non-exclusive license should Radio Shack cease to
+;* produce and sell the game.  To the best of my knowledge, they have not produced the game for many
+;* years.  Thus, it is my belief that the right to grant a license for the game has reverted to me. 
+;*
+;* I hereby grant a non-exclusive permanent world-wide license to any and all Color Computer site
+;* administrators, emulator developers, programmers or any other person or persons who wish to develop,
+;* produce, duplicate, emulate, or distribute the game on the sole condition that they exercise every
+;* effort to preserve the game insofar as possible in its original and unaltered form. 
+;*
+;* The game was a labor of love.  Additional credits to Phillip C. Landmeier - who was my partner and
+;* who originally conceived the vision of the game and was responsible for the (then) state of the art
+;* sounds and realism, to April Landmeier, his wife - the artist who drew all the creatures as well as
+;* all the artwork for the manual and game cover, and to Keith Kiyohara - a gifted programmer who helped
+;* write the original game and then contributed greatly to compressing a 16K game into 8K so that it
+;* could be carried and produced by Radio Shack.
+;*
+;* The game did very well for us.  I give it to the world with thanks to all who bought it, played it
+;* or enjoyed it. 
+;*
+;* There is one existing copy of the original source code.  Anyone willing to pay for the copying of
+;* the listing (at Kinko's) and shipment to them, who intends to use it to enhance or improve the emulator
+;* versions of the game is welcome to it. 
+;*
+;* Verification of this license grant or requests for the listing can be made by contacting Louis Jordan,
+;* Thank you.
+;***********************************************************************************************************
+;
+; Louis Jordan's email address is given as louisgjordan@yahoo.com in a hyperlink in the above statement.
+;
+; It is my belief that this endeavor to disassemble Dungeons of Daggorath is in compliance with the above
+; license grant. I have done so for my own amusement and for the challenge. I have also done so because
+; I failed to elicit a response from Louis Jordan as described in the license grant. I am not surprised
+; that I received no reply given that the page above was put online during or prior to 2006.
+
 ; some utility macros
 dod		macro noexpand
 		swi
@@ -18,6 +72,15 @@
 		fcb \1
 		endm
 
+; decode a 5 bit packed string from (X) to (U)
+decodestr	macro noexpand
+		dod S06
+		endm
+; decode a 5 bit packed string from (X) to V335
+decodestrsb	macro noexpand
+		dod S05
+		endm
+
 ; ROM call numbers
 POLCAT		equ 0
 CSRDON		equ 4
@@ -187,12 +250,12 @@
 V2B4		rmb 1
 V2B5		rmb 1
 V2B6		rmb 1
-V2B7		rmb 1
+V2B7		rmb 1				nonzero means nonstandard text location
 V2B8		rmb 1
 V2B9		rmb 2
 V2BB		rmb 1
-V2BC		rmb 1			keyboard buffer read offset
-V2BD		rmb 1			keyboard buffer write offset
+V2BC		rmb 1				keyboard buffer read offset
+V2BD		rmb 1				keyboard buffer write offset
 		rmb 3
 V2C1		rmb 1
 V2C2		rmb 1
@@ -201,7 +264,7 @@
 V2C5		rmb 1
 V2C6		rmb 1
 V2C7		rmb 10
-V2D1		rmb 32			keyboard ring buffer
+V2D1		rmb 32				keyboard ring buffer
 V2F1		rmb 32
 V311		rmb 2
 V313		rmb 32
@@ -215,7 +278,9 @@
 V386		rmb 2
 V388		rmb 6
 V38E		rmb 2
-V390		rmb 6
+V390		rmb 2
+V392		rmb 2				current end of screen address
+V394		rmb 2				current system text display location
 V396		rmb 2
 V398		rmb 43
 V3C3		rmb 17
@@ -230,45 +295,45 @@
 
 
 		org $c000
-START		ldu #LC0D1
-		bra LC008
-LC005		ldu #LC124
-LC008		lds #STACK
-		ldx #PIA0
-		ldd #$34fa
-		sta 3,x
-		sta 1,x
-		ldx #PIA1
-		sta 1,x
-		clr 3,x
-		stb 2,x
-		lda #$3c
-		sta 3,x
-		ldd #$2046
-		jsr LC266
-		lda #$f8
-		sta 2,x
-		ldx #V200
-LC030		clr ,x+
-		cmpx #TOPRAM
-		blo LC030
-		stu ,--s
-		lda #2
-		tfr a,dp
-		setdp 2
-		ldy #LD7E8
-LC041		lda ,y+
-		beq LC086
-		ldx ,y++
-		bsr LC04B
-		bra LC041
-LC04B		ldb ,y+
-		stb ,x+
-		deca
-		bne LC04B
-		rts
-LC053		pshs cc,a,b,x,y,u
-		orcc #$10
+START		ldu #LC0D1			point to the demo setup routine
+		bra LC008			go handle the game
+LC005		ldu #LC124			point to the real game setup routine
+LC008		lds #STACK			put the stack somewhere safe
+		ldx #PIA0			point at PIA0
+		ldd #$34fa			initializers for the PIA
+		sta 3,x				set data mode, interrupts disabled (side B)
+		sta 1,x				set data mode, interrupts disabled (side A)
+		ldx #PIA1			point at PIA1
+		sta 1,x				set data mode, interrupts disabled (side A)
+		clr 3,x				set direction mode for side B
+		stb 2,x				set VDG and single bit sound to output
+		lda #$3c			flags for data mode, no interrupts, sound enabled
+		sta 3,x				set side B for data mode
+		ldd #$2046			SAM value for "pmode 4" graphics, screen at $1000
+		jsr LC266			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
+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
+		tfr a,dp			set DP appropriately
+		setdp V200/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
+		ldx ,y++			get address to copy bytes to
+		bsr LC04B			go copy bytes
+		bra LC041			go handle another initializer
+LC04B		ldb ,y+				fetch source byte
+		stb ,x+				stow at destination
+		deca				are we done yet?
+		bne LC04B			brif not
+		rts				return to caller
+LC053		pshs cc,a,b,x,y,u		save registers and interrupt status
+		orcc #$10			disable IRQ
 		ldx #V29F
 LC05A		clr ,x+
 		cmpx #V2AD
@@ -503,18 +568,18 @@
 		leax 7,u
 		stx V2B9
 		puls x,pc
-LC266		pshs x,b,a
-		ldx #SAMREG
-LC26B		lsra
-		rorb
-		bcs LC272
-		sta ,x
-		skip2
-LC272		sta 1,x
-		leax 2,x
-		cmpx #SAMREG+$14
-		blo LC26B
-		puls a,b,x,pc
+LC266		pshs x,b,a			save registers
+		ldx #SAMREG			point to SAM register
+LC26B		lsra				; shift the bit value to set to carry
+		rorb				;
+		bcs LC272			brif bit set
+		sta ,x				clear the bit
+		skip2				skip next instruction
+LC272		sta 1,x				set the bit
+		leax 2,x			move to next SAM register bit
+		cmpx #SAMREG+$14		are we at the end of the register?
+		blo LC26B			brif not
+		puls a,b,x,pc			restore registers and return
 ; IRQ service routine
 LC27D		ldx #PIA1
 		lda -29,x
@@ -753,28 +818,28 @@
 ; swi 2 routine
 ; fetch a packed string immediately following the call and display it
 LC448		ldx 12,s			fetch return address - string address
-		dod S05				go decode string
+		decodestrsb			go decode string
 		stx 12,s			save new return address - after string
 		ldx #V335			point to decoded string
 		skip2
 LC452		dod S04				display character in A
 ; swi 3 routine
-; display an unpacked  string pointed to by X
+; display an unpacked string pointed to by X
 LC454		lda ,x+				fetch byte from string
 		bpl LC452			brif not end of string - display it
 		rts
 ; swi 4 routine
 ; display character in A
-LC459		tst V2B7
-		bne LC460
-		ldu #V390
-LC460		ldx 4,u
-		jsr LC9B2
-		cmpx 2,u
-		blo LC46C
-		jsr LC9D4
-LC46C		stx 4,u
-		rts
+LC459		tst V2B7			are we looking for standard text mode?
+		bne LC460			brif not
+		ldu #V390			point to display state information
+LC460		ldx 4,u				fetch current screen location
+		jsr LC9B2			actually display the appropriate character
+		cmpx 2,u			are we at the end of the screen?
+		blo LC46C			brif not
+		jsr LC9D4			go scroll the text area
+LC46C		stx 4,u				save new screen location
+		rts				return to caller
 ; swi 5 routine - decode packed string at X to V335
 LC46F		ldu #V335			point to output buffer
 ; swi 6 routine - decode a packed string at X to U
@@ -1029,7 +1094,7 @@
 		ldx #V313
 LC63C		puls a,b,y,u,pc
 LC63E		pshs a,x
-LC640		dod S05
+LC640		decodestrsb
 		deca
 		bpl LC640
 		ldx #V336
@@ -1535,48 +1600,49 @@
 		fcb LC759-LC743
 		fcb LC7C8-LC759
 		fcb LC7D0-LC7C8
-LC9B2		cmpa #$24
-		beq LC9BF
-		cmpa #$1f
-		beq LC9CA
-		bsr LCA17
-		leax 1,x
-		rts
-LC9BF		leax -1,x
-		cmpx V203
-		bne LC9C9
-		ldx 2,u
-		leax -1,x
-LC9C9		rts
-LC9CA		leax $20,x
-		exg d,x
-		andb #$e0
-		exg d,x
-		rts
-LC9D4		pshs a,b,x,y
-		ldx ,u
-		ldd 2,u
-		subd #$20
-		std 2,s
-		bsr LCA10
-		tfr d,y
-LC9E3		ldd $100,x
-		tst 7,u
-		bne LC9EF
-		std $1800,x
-LC9EF		std ,x++
-		leay -2,y
-		bne LC9E3
-		ldb 6,u
-		sex
-		ldy #$100
-LC9FC		tst 7,u
-		bne LCA04
-		std $1800,x
-LCA04		std ,x++
-		leay -2,y
-		bne LC9FC
-		puls a,b,x,y,pc
+; Display the character in A on the screen at X
+LC9B2		cmpa #$24			is it backspace?	
+		beq LC9BF			brif so
+		cmpa #$1f			vertical spacer?
+		beq LC9CA			brif so
+		bsr LCA17			go handle a glyph
+		leax 1,x			move to next character position
+		rts				return to caller
+LC9BF		leax -1,x			move display pointer back one
+		cmpx V203			
+		bne LC9C9			
+		ldx 2,u				get end of text area
+		leax -1,x			move back one position
+LC9C9		rts				return to caller
+LC9CA		leax $20,x			move pointer forward one character row
+		exg d,x				move pointer so we can do math
+		andb #$e0			force pointer to the start of the line
+		exg d,x				put pointer back where it belongs
+		rts				return to caller
+LC9D4		pshs a,b,x,y			save registers
+		ldx ,u				get start of screen address
+		ldd 2,u				get end of screen address
+		subd #$20			knock one pixel row off it
+		std 2,s				save new display location
+		bsr LCA10			multiply by 8 - 8 rows
+		tfr d,y				save counter
+LC9E3		ldd $100,x			get bytes 8 screen rows ahead
+		tst 7,u				do we need to skip the second screen?
+		bne LC9EF			brif so
+		std $1800,x			save scroll data on second screen
+LC9EF		std ,x++			save scroll data and move pointer ahead
+		leay -2,y			are we done yet?
+		bne LC9E3			brif not
+		ldb 6,u				fetch current background colour
+		sex				and make A match
+		ldy #$100			number of bytes to blank bottom row
+LC9FC		tst 7,u				are we doing second screen too?
+		bne LCA04			brif not
+		std $1800,x			blank pixels in second screen
+LCA04		std ,x++			blank pixels and move pointer forward
+		leay -2,y			are we done yet?
+		bne LC9FC			brif not
+		puls a,b,x,y,pc			restore registers and return
 LCA0C		lslb
 		rola
 		lslb
@@ -1588,45 +1654,45 @@
 		lslb
 		rola
 		rts
-LCA17		pshs a,b,x,y,u
-		cmpa #$20
-		blo LCA29
-		suba #$20
-		ldb #7
-		mul
-		addd #LDBB6
-		tfr d,x
-		bra LCA44
-LCA29		ldb #5
-		mul
-		addd #LDB1B
-		tfr d,x
-		ldu #V357
-		dod S06
-		ldx #V35E
-LCA39		lsl ,-x
-		lsl ,x
-		cmpx #V357
-		bhi LCA39
-		ldu 6,s
-LCA44		ldd 4,u
-		bsr LCA10
-		lsrb
-		lsrb
-		lsrb
-		addd ,u
-		tfr d,y
-		ldb #7
-LCA51		lda ,x+
-		eora 6,u
-		sta ,y
-		tst 7,u
-		bne LCA5F
-		sta $1800,y
-LCA5F		leay $20,y
-		decb
-		bne LCA51
-		puls a,b,x,y,u,pc
+LCA17		pshs a,b,x,y,u			save registers
+		cmpa #$20			is it a printing character?
+		blo LCA29			brif so
+		suba #$20			mask off printing characters
+		ldb #7				7 bytes per font table entry
+		mul				get offset in table
+		addd #LDBB6			add in base address of table
+		tfr d,x				put font pointer somewhere useful
+		bra LCA44			go draw glyph
+LCA29		ldb #5				5 bytes per font table entry
+		mul				get offset in table
+		addd #LDB1B			add in base address of table
+		tfr d,x				put pointer somewhere useful
+		ldu #V357			point to buffer to decode glyph data
+		decodestr			go decode a packed string
+		ldx #V357+7			point one past end of buffer
+LCA39		lsl ,-x				; centre glyph data in byte
+		lsl ,x				;
+		cmpx #V357			at start of buffer?
+		bhi LCA39			brif not - keep centring
+		ldu 6,s				get back U value
+LCA44		ldd 4,u				get display address location
+		bsr LCA10			multiply by 8 - gets start of row in 11..8
+		lsrb				; and divide lsb by 8 again to get offset within
+		lsrb				; the row to bits 4..0
+		lsrb				; and force to top of character cell
+		addd ,u				add in start of text area
+		tfr d,y				put pointer somewhere useful
+		ldb #7				seven bytes to copy
+LCA51		lda ,x+				get byte from font data
+		eora 6,u			merge with background colour
+		sta ,y				save it on the screen
+		tst 7,u				do we need to update second screen?
+		bne LCA5F			brif not
+		sta $1800,y			save pixels on second screen
+LCA5F		leay $20,y			move display pointer down one pixel row
+		decb				are we done yet?
+		bne LCA51			brif not - do another
+		puls a,b,x,y,u,pc		restore registers and return
 LCA67		pshs a,b,x
 		clr ,s
 		clr 1,s
@@ -1828,7 +1894,7 @@
 		ldb ,x+
 		stb V279
 LCBFC		ldu #V313
-		dod S05
+		decodestrsb
 		ldy #V336
 LCC05		ldb ,u+
 		bmi LCC17
@@ -2580,7 +2646,7 @@
 		jmp START
 LD229		ldx ,y++
 		ldu #V361
-		dod S06
+		decodestr
 		leau 1,u
 		dod S10
 		skip2
@@ -3518,57 +3584,43 @@
 LDB14		fcb $40,$FF,$06,$FF
 LDB18		fcb $00,$0D,$07
 
-LDB1B		fcb $30
-
-LDB1C		fcb $00,$00,$00,$00
-LDB20		fcb $31,$15,$18,$FE
-LDB24		fcb $31,$37,$A3,$1F
-LDB28		fcb $46,$3E,$33,$A3
-LDB2C		fcb $08,$42,$2E,$37
-LDB30		fcb $A3,$18,$C6,$3E
-LDB34		fcb $37,$E1,$0F,$42
-LDB38		fcb $1F,$37,$E1,$0F
-LDB3C		fcb $42,$10,$33,$E3
-LDB40		fcb $08,$4E,$2F,$34
-LDB44		fcb $63,$1F,$C6,$31
-LDB48		fcb $33,$88,$42,$10
-LDB4C		fcb $8E,$30,$42,$10
-LDB50		fcb $86,$2E,$34,$65
-LDB54		fcb $4C,$52,$51,$34
-LDB58		fcb $21,$08,$42,$1F
-LDB5C		fcb $34,$77,$5A,$D6
-LDB60		fcb $31,$34,$63,$9A
-LDB64		fcb $CE,$31,$33,$A3
-LDB68		fcb $18,$C6,$2E,$37
-LDB6C		fcb $A3,$1F,$42,$10
-LDB70		fcb $33,$A3,$18,$D6
-LDB74		fcb $4D,$37,$A3,$1F
-LDB78		fcb $52,$51,$33,$A3
-LDB7C		fcb $07,$06,$2E,$37
-LDB80		fcb $EA,$42,$10,$84
-LDB84		fcb $34,$63,$18,$C6
-LDB88		fcb $2E,$34,$63,$15
-LDB8C		fcb $28,$84,$34,$63
-LDB90		fcb $1A,$D7,$71,$34
-LDB94		fcb $62,$A2,$2A,$31
-LDB98		fcb $34,$62,$A2,$10
-LDB9C		fcb $84,$37,$C2,$22
-LDBA0		fcb $22,$1F,$31,$08
-LDBA4		fcb $42,$10,$04,$30
-LDBA8		fcb $00,$00,$00,$1F
-LDBAC		fcb $33,$A2,$13,$10
-LDBB0		fcb $04,$30,$00,$00
-LDBB4		fcb $00,$04
-
-LDBB6		fcb $00,$00
-
-LDBB8		fcb $01,$01,$00,$00
-LDBBC		fcb $00,$00,$A0,$F0
-LDBC0		fcb $F0,$E0,$40,$00
-LDBC4		fcb $00,$01,$03,$03
-LDBC8		fcb $01,$00,$00,$00
-LDBCC		fcb $B0,$F8,$F8,$F0
-LDBD0		fcb $E0,$40
+; This is the text font - these values are in packed format
+LDB1B		fcb $30,$00,$00,$00,$00		char code 0 - space
+		fcb $31,$15,$18,$fe,$31		char code 1 - A
+		fcb $37,$a3,$1f,$46,$3e		char code 2 - B
+		fcb $33,$a3,$08,$42,$2e		char code 3 - C
+		fcb $37,$a3,$18,$c6,$3e		char code 4 - D	
+		fcb $37,$e1,$0f,$42,$1f		char code 5 - E
+		fcb $37,$e1,$0f,$42,$10		char code 6 - F
+		fcb $33,$e3,$08,$4e,$2f		char code 7 - G
+		fcb $34,$63,$1f,$c6,$31		char code 8 - H
+		fcb $33,$88,$42,$10,$8e		char code 9 - I
+		fcb $30,$42,$10,$86,$2e		char code 10 - J
+		fcb $34,$65,$4c,$52,$51		char code 11 - K
+		fcb $34,$21,$08,$42,$1f		char code 12 - L
+		fcb $34,$77,$5a,$d6,$31		char code 13 - M
+		fcb $34,$63,$9a,$ce,$31		char code 14 - N
+		fcb $33,$a3,$18,$c6,$2e		char code 15 - O
+		fcb $37,$a3,$1f,$42,$10		char code 16 - P
+		fcb $33,$a3,$18,$d6,$4d		char code 17 - Q
+		fcb $37,$a3,$1f,$52,$51		char code 18 - R
+		fcb $33,$a3,$07,$06,$2e		char code 19 - S
+		fcb $37,$ea,$42,$10,$84		char code 20 - T
+		fcb $34,$63,$18,$c6,$2e		char code 21 - U
+		fcb $34,$63,$15,$28,$84		char code 22 - V
+		fcb $34,$63,$1a,$d7,$71		char code 23 - W
+		fcb $34,$62,$a2,$2a,$31		char code 24 - X
+		fcb $34,$62,$a2,$10,$84		char code 25 - Y
+		fcb $37,$c2,$22,$22,$1f		char code 26 - Z
+		fcb $31,$08,$42,$10,$04		char code 27 - !
+		fcb $30,$00,$00,$00,$1f		char code 28 - underscore
+		fcb $33,$a2,$13,$10,$04		char code 29 - ?
+		fcb $30,$00,$00,$00,$04		char code 30 - .
+; some special characters
+LDBB6		fcb $00,$00,$01,$01,$00,$00,$00	char code 32
+		fcb $00,$a0,$f0,$f0,$e0,$40,$00	char code 33
+		fcb $00,$01,$03,$03,$01,$00,$00	char code 34
+		fcb $00,$b0,$f8,$f8,$f0,$e0,$40	char code 35
 
 LDBD2		fcb $00,$80