changeset 15:58013a960ec6

Deciphered ZLOAD/ZSAVE handling Worked out how the ZLOAD/ZSAVE process works and added appropriate comments.
author William Astle <lost@l-w.ca>
date Mon, 22 Dec 2014 23:40:23 -0700
parents adfc4ab79eeb
children 03f9d6493148
files dod.s
diffstat 1 files changed, 72 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- a/dod.s	Mon Dec 22 23:11:19 2014 -0700
+++ b/dod.s	Mon Dec 22 23:40:23 2014 -0700
@@ -323,7 +323,7 @@
 V2B5		rmb 1
 V2B6		rmb 1
 V2B7		rmb 1				nonzero means nonstandard text location
-V2B8		rmb 1
+V2B8		rmb 1				load/save flag - <0 = ZLOAD, >0 = ZSAVE, 0 = regular init
 V2B9		rmb 2
 V2BB		rmb 1
 keybufread	rmb 1				keyboard buffer read offset
@@ -533,11 +533,11 @@
 LC166		dod S19
 		showprompt
 		jmp LC1F5
-LC16D		stx CBUFAD
-		romcall BLKIN
-		tsta
-		lbne RESVEC
-		ldb BLKTYP
+LC16D		stx CBUFAD			; set address to read to
+		romcall BLKIN			; read a block
+		tsta				; is it the end of the file?
+		lbne RESVEC			; brif so - premature end, fail with a reset
+		ldb BLKTYP			; get type of block
 		rts
 LC17C		ldu #PIA0
 		ldd #$343c
@@ -545,57 +545,57 @@
 		sta PIA1+3
 		stb PIA1+1
 		rts
-LC18B		ldx V200
-LC18D		leax -1,x
-		bne LC18D
+LC18B		ldx V200			; get long delay constant
+LC18D		leax -1,x			; have we reached 0?
+		bne LC18D			; brif not
 		rts
-LC192		bsr LC17C
-		bsr LC18B
-		bsr LC18B
-		romcall WRTLDR
-		romcall BLKOUT
-		bsr LC18B
-		romcall WRTLDR
-		ldx #V200
-LC1A6		ldd #$0180
-		std BLKTYP
-		stx CBUFAD
-		romcall BLKOUT
-		cmpx #VF05
-		blo LC1A6
-		stu BLKTYP
-		romcall BLKOUT
+LC192		bsr LC17C			; set up PIA for cassette I/O
+		bsr LC18B			; delay for a bit
 		bsr LC18B
-		bra LC1EC
-LC1C1		bsr LC17C
-		romcall CSRDON
-LC1C6		ldu screendraw
-		ldx ,u
-		bsr LC16D
-		bne LC1C6
-		ldx ,u
-		ldu #V313
-		ldb #8
-LC1D5		lda ,x+
+		romcall WRTLDR			; write a file header
+		romcall BLKOUT
+		bsr LC18B			; delay for a bit
+		romcall WRTLDR			; write a leader for data area
+		ldx #V200			; 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
+		romcall BLKOUT			; write a data block
+		cmpx #VF05			; have we reached end of state?
+		blo LC1A6			; brif not
+		stu BLKTYP			; write trailing block
+		romcall BLKOUT
+		bsr LC18B			; delay for a bit
+		bra LC1EC			; go init things and restart main loop
+LC1C1		bsr LC17C			; set up PIA for cassette I/O
+		romcall CSRDON			; start tape
+LC1C6		ldu screendraw			; point to drawing area
+		ldx ,u				; get pointer to screen data - use as a read buffer
+		bsr LC16D			; read a block
+		bne LC1C6			; brif data block
+		ldx ,u				; get buffer pointer
+		ldu #V313			; point to requested file name
+		ldb #8				; 8 characters in file name
+LC1D5		lda ,x+				; does character match?
 		cmpa ,u+
-		bne LC1C1
-		decb
-		bne LC1D5
-		romcall CSRDON
-		ldx #V200
-LC1E4		bsr LC16D
-		bpl LC1E4
-		lds #STACK
-LC1EC		jsr LC114
-		clr V2B8
+		bne LC1C1			; brif not - look for another header
+		decb				; end of file name?
+		bne LC1D5			; brif not - check another
+		romcall CSRDON			; start tape
+		ldx #V200			; 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
+LC1EC		jsr LC114			; make sure PIAs are set right
+		clr V2B8			; flag regular operations
 		dod S19
 		showprompt
 LC1F5		ldu #V2AB
 		clr V2BB
 LC1FA		tfr u,y
-LC1FC		tst V2B8
-		bgt LC192
-		bmi LC1C1
+LC1FC		tst V2B8			; are we loading or saving?
+		bgt LC192			; brif saving
+		bmi LC1C1			; brif loading
 		ldu ,u
 		beq LC1F5
 		pshs y,u
@@ -2019,22 +2019,22 @@
 		puls a,b,x,y,u,pc		restore registers and return
 LCB8E		fcb $80,$40,$20,$10		pixels 0, 1, 2, 3 (left to right) in byte
 		fcb $08,$04,$02,$01		pixels 4, 5, 6, 7 (left to right) in byte
-LCB96		pshs a,x,u
-		ldx V211
-		ldu #V313
-LCB9D		lda ,x+
-		beq LCB9D
-		bra LCBA5
-LCBA3		lda ,x+
-LCBA5		ble LCBAF
+LCB96		pshs a,x,u			; save registers
+		ldx V211			; get input buffer/line pointer
+		ldu #V313			; point to filename buffer
+LCB9D		lda ,x+				; get character from input
+		beq LCB9D			; brif end of line
+		bra LCBA5			; get on with things
+LCBA3		lda ,x+				; get new character from input
+LCBA5		ble LCBAF			; brif not valid character
+		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
 		sta ,u+
-		cmpu #V333
-		blo LCBA3
-LCBAF		lda #$ff
-		sta ,u+
-		stx V211
-		tst V313
-		puls a,x,u,pc
+		stx V211			; save new input pointer location
+		tst V313			; set flags for whether we have a filename
+		puls a,x,u,pc			; restore registers and return
 LCBBA		clr V290
 		ldx #LD96A
 		bsr LCBEC
@@ -3498,18 +3498,18 @@
 		stx V2B2
 		dod S0E
 LD7B6		rts
-cmd_zload	bsr LD7BC
-		dec V2B8
+cmd_zload	bsr LD7BC			; parse the file name
+		dec V2B8			; flag ZLOAD
 		rts
-LD7BC		ldx #V313			get start address to set to $ff
-		leau $20,x			set $20 bytes
-		setblock			go clear block to $ff
+LD7BC		ldx #V313			; get start address to set to $ff
+		leau $20,x			; set $20 bytes
+		setblock			; go clear block to $ff
 		jmp LCB96
-cmd_zsave	bsr LD7BC
-		stx CBUFAD
+cmd_zsave	bsr LD7BC			; parse the file name
+		stx CBUFAD			
 		ldd #$0f
 		std BLKTYP
-		inc V2B8
+		inc V2B8			; flag ZSAVE
 		rts
 LD7D5		fcb $0d,$0f,$10,$ff
 LD7D9		fcb $11,$0f