changeset 14:1f5ce2f5e9aa

Remove unused tape code and reset PIAs to Basic mode before load/save Remove unused tape code now that saving to disk is supported. Also, change the default PIA setting to make the RS232 output bit to an input. This should prevent junk on the serial port duing the game and may improve the situation with drivewire on the bitbanger versions of Disk Basic. Additional changes to the routines used to set up for calls to and returns from Disk Basic ROMs were required to re-enable the RS232 output. Also, to prevent weird sounds during Drivewire bitbanger operations, set the single bit sound to an input during save/load and reset to output afterward.
author William Astle <lost@l-w.ca>
date Thu, 01 Jan 2015 11:02:58 -0700
parents aa3901cbe279
children 64a40f06d375
files dod.s
diffstat 1 files changed, 44 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/dod.s	Mon Dec 29 23:22:20 2014 -0700
+++ b/dod.s	Thu Jan 01 11:02:58 2015 -0700
@@ -455,20 +455,20 @@
 		bra LC008			; go handle the game
 LC005		ldu #dogame			; 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 #$34fc			; initializers for the PIA
+		sta PIA0+3			; set data mode, interrupts disabled (side B)
+		sta PIA0+1			; set data mode, interrupts disabled (side A)
+		clr PIA1+1			; set PIA1 A to direction mode
+		stb PIA1			; set sound to output, RS232 and cassette to input
+		sta PIA1+1			; set data mode, interrupts disabled (side A)
+		clr PIA1+3			; set direction mode for PIA1 B
+		ldd #$3cfa			; more initializers
+		stb PIA1+2			; set PIA1 B to output except for RS232 input and RAM Size
+		sta PIA1+3			; set PIA B to data mode, no interrupts, sound endabled
 		ldd #SAMSCR0			; SAM value for "pmode 4" graphics, screen at $1000
 		jsr setSAM			; go set the SAM register
 		lda #$f8			; value for "pmode 4", color set 1
-		sta 2,x				; set VDG mode
+		sta PIA1+2			; set VDG mode
 		ldx #zero			; point to start of variables
 LC030		clr ,x+				; clear a byte
 		cmpx #TOPRAM			; are we at the top of memory?
@@ -569,11 +569,18 @@
 		lda #2				; create maze for level 3
 		ldu #startobjdemo		; point to demo game object list
 		bra LC131			; go start demo running
-enablepiairq	ldd #$343c			; set up initializers for PIAs
-		sta PIA1+1			; set data mode, no interrupts, cassette off
-		stb PIA1+3			; set data mode, no interrupts, sound on
+; This routine sets up PIA1 for DoD mode. This means single bit sound
+; is set to output, rs232 output is set to input, andVSYNC is enabled.
+enablepiairq	ldd #$34fc			; initializer for side A
+		clr PIA1+1			; set direction mode for side A
+		stb PIA1			; set direction properly
+		sta PIA1+1			; set back to data mode, no interrupts, cassette off
 		inca				; adjust to enable interrupt
-		sta PIA0+3			; set data mode, enable VSYNC, clear MSB of analog MUX
+		sta PIA0+3			; set data mode, enable VSYNC, enable LSB of analog MUX
+		ldd #$3cfa			; initializer for side B
+		clr PIA1+3			; set direction mode for side B
+		stb PIA1+2			; set direction properly
+		sta PIA1+3			; set back to data mode, no interrupts, sound on
 		cwai #$ef			; enable IRQ and wait for one
 		rts				; return to caller
 dogame		bsr enablepiairq		; set up interrupts and sound
@@ -617,64 +624,27 @@
 		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
-		sta PIA1+3			; disable interrupts on PIA1, cassette off
-		stb PIA1+1			; disable interrupts on PIA1, sound on
+; This routine sets up PIA1 for Basic (with interrupts disabled)
+disablepiairq	ldd #$34fe			; initializer for side A
+		sta PIA0+3			; disable VSYNC interrupt, clear analogue mux MSB
+		clr PIA1+1			; set direction mode for side A
+		stb PIA1			; set direction properly (sets RS232 to output)
+		sta PIA1+1			; set back to data mode, no interrupts, cassette off
+		ldb #2				; set RS232 to "marking"
+		stb PIA1
+		ldd #$3cf8			; initializer for side B
+		clr PIA1+3			; set direction mode for side B
+		stb PIA1+2			; set direction properly, disable sound, one bit sound as input
+		sta PIA1+3			; set back to data mode, no interrupts, sound on
 		rts
 busywait	ldx zero			; get long delay constant
 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
-		showprompt			; show command prompt
 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 +4736,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		; reset PIAs to Basic mode
 		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		; restore PIAs to daggorath mode
+		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 +4826,7 @@
 		blo save_game018		; brif not
 		jsr file_close			; close the disk file
 		lbne save_gameerr		; brif error closing (writing buffer failed)
+		jsr enablepiairq		; restore PIAs to daggorath mode
 		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 +4870,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		; set up PIA for Basic I/O
 		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		; reset PIAs to DoD mode
+		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 +4968,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 +5005,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		; reset PIA to DoD mode
 		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