changeset 13:9fe448b9b09c

Disable PIA stuff during load/save. Disabling PIA stuff during load/save is probably a good thing to avoid weirdness.
author William Astle <lost@l-w.ca>
date Tue, 30 Dec 2014 13:32:56 -0700
parents aa3901cbe279
children 64a40f06d375
files dod.s
diffstat 1 files changed, 10 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/dod.s	Mon Dec 29 23:22:20 2014 -0700
+++ b/dod.s	Tue Dec 30 13:32:56 2014 -0700
@@ -611,12 +611,6 @@
 LC166		resetdisplay			; clear command and status areas and show the dungeon
 		showprompt			; show command prompt
 		jmp LC1F5			; go to main loop
-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
 disablepiairq	ldu #PIA0			; point to PIA0
 		ldd #$343c			; set up initializers for PIA
 		sta 3,u				; disable VSYNC interrupt, clear analogue mux msb
@@ -627,43 +621,6 @@
 busywait000	leax -1,x			; have we reached 0?
 		bne busywait000			; brif not
 		rts
-LC192		bsr disablepiairq		; set up PIA for cassette I/O
-		bsr busywait			; delay for a bit
-		bsr busywait
-		romcall WRTLDR			; write a file header
-		romcall BLKOUT
-		bsr busywait			; delay for a bit
-		romcall WRTLDR			; write a leader for data area
-		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
-		romcall BLKOUT			; write a data block
-		cmpx #datatop			; have we reached end of state?
-		blo LC1A6			; brif not
-		stu BLKTYP			; write trailing block
-		romcall BLKOUT
-		bsr busywait			; delay for a bit
-		bra LC1EC			; go init things and restart main loop
-LC1C1		bsr disablepiairq		; 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 #wordbuff			; point to requested file name
-		ldb #8				; 8 characters in file name
-LC1D5		lda ,x+				; does character match?
-		cmpa ,u+
-		bne LC1C1			; brif not - look for another header
-		decb				; end of file name?
-		bne LC1D5			; brif not - check another
-		romcall CSRDON			; start tape
-		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
 LC1EC		jsr enablepiairq		; make sure PIAs are set right
 		clr loadsaveflag		; flag regular operations
 		resetdisplay			; clear command and status areas, update appropriately
@@ -671,10 +628,7 @@
 LC1F5		ldu #schedlists+12		; point to ready list head
 		clr readylistchg		; mark ready list restart not needed
 LC1FA		tfr u,y				; save ready list pointer
-LC1FC		tst loadsaveflag		; are we loading or saving?
-		bgt LC192			; brif saving
-		bmi LC1C1			; brif loading
-		ldu ,u				; are we at the end of the ready list?
+LC1FC		ldu ,u				; are we at the end of the ready list?
 		beq LC1F5			; brif so
 		pshs y,u			; save registers
 		jsr [3,u]			; call the registered routine
@@ -4766,10 +4720,12 @@
 ; Exit with C clear if no error and C set if error.
 save_game	pshs d,x,y,u			; save registers
 		jsr loadsave_setfn		; set up file name
+		jsr disablepiairq		; turn off IRQs etc
 		ldd #$0100			; set to "binary data" format
 		jsr file_openo			; open file for output
 		beq save_game004		; brif no error opening file
-save_gameerr	coma				; flag error on save
+save_gameerr	jsr enablepiairq		; turn IRQs back on
+		coma				; flag error on save
 		puls d,x,y,u,pc			; return to caller
 file_writen	lda ,x+				; get byte to write
 		bsr file_write			; write byte to file
@@ -4854,6 +4810,7 @@
 		blo save_game018		; brif not
 		jsr file_close			; close the disk file
 		lbne save_gameerr		; brif error closing (writing buffer failed)
+		jsr enablepiairq		; turn IRQs back on
 		clra				; clear carry for success
 		puls d,x,y,u,pc			; restore registers and return
 save_writesched	subd #schedtab			; adjust to offset in scheduling table
@@ -4897,11 +4854,13 @@
 load_game	clrb				; mark current game still valid
 		pshs d,x,y,u			; save registers
 		bsr loadsave_setfn		; set up the file name correctly
+		jsr disablepiairq		; disable IRQs, etc.
 		jsr file_openi			; open file for output
 		beq load_game004		; brif no error opening file
 		bra load_gameerrx		; throw error if open failed
 load_gameerr	jsr file_close			; close the file if it's open
-load_gameerrx	coma				; flag error on save
+load_gameerrx	jsr enablepiairq		; turn IRQs back on
+		coma				; flag error on save
 		puls d,x,y,u,pc			; return to caller
 file_readn	jsr file_read			; read byte
 		bcs file_readn001		; brif error
@@ -4993,7 +4952,7 @@
 		jsr load_read			; read tick count value
 		lbcs load_gameerr		; brif read error
 		sta 2,y				; save ticks count
-		bsr load_readw			; read a word from file
+		jsr load_readw			; read a word from file
 		lbcs load_gameerr		; brif error
 		ldu #save_schedtab		; point to handler fixups
 load_game013	cmpd 2,u			; does the handler pointer match?
@@ -5030,6 +4989,7 @@
 		bpl load_game020		; brif we didn't consume a flag
 		decb				; are we at the right set of data for the level?
 		bpl load_game019		; brif not - save new pointer and search again
+		jsr enablepiairq		; turn IRQs back on
 		clra				; clear carry for success
 		puls d,x,y,u,pc			; restore registers and return
 load_readsched	ldd #schedtab			; set the bias for the read