changeset 24:966dd9bc8659

Identified several utility routines and keyboard handling Identified variables related to keyboard handling and also added descriptive names for various routines.
author William Astle <lost@l-w.ca>
date Fri, 26 Dec 2014 10:08:31 -0700
parents 7c2f57937862
children 5e2a87c2f9bc
files dod.s
diffstat 1 files changed, 58 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/dod.s	Fri Dec 26 01:01:12 2014 -0700
+++ b/dod.s	Fri Dec 26 10:08:31 2014 -0700
@@ -249,7 +249,7 @@
 V223		rmb 1
 curtorch	rmb 2				; pointer to currently mounted torch
 V226		rmb 2
-V228		rmb 1
+nokeyboard	rmb 1				; set if no keyboard operations should be done during IRQ
 backpack	rmb 2
 V22B		rmb 1
 levbgmask	rmb 1				the current level background colour mask
@@ -292,7 +292,7 @@
 V273		rmb 1
 V274		rmb 1
 V275		rmb 2
-V277		rmb 1
+waitnewgame	rmb 1				; set if waiting for keypress to start new game
 V278		rmb 1
 V279		rmb 2
 V27B		rmb 1
@@ -474,8 +474,8 @@
 		fcb $48
 		clr V2B7			reset text rendering to standard mode
 		rts					
-dodemo		dec V277			; flag demo game
-		bsr LC114			; set up interrupts and sound
+dodemo		dec waitnewgame			; flag demo game
+		bsr enablepiairq		; set up interrupts and sound
 		ldx #img_wizard			; point to wizard image
 		dec V29E
 		fadein				; fade the wizard in
@@ -499,14 +499,14 @@
 		lda #2				; create maze for level 3
 		ldu #startobjdemo		; point to demo game object list
 		bra LC131			; go start demo running
-LC114		ldd #$343c			; set up initializers for PIAs
+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
 		inca				; adjust to enable interrupt
 		sta PIA0+3			; set data mode, enable VSYNC, clear MSB of analog MUX
 		cwai #$ef			; enable IRQ and wait for one
 		rts				; return to caller
-dogame		bsr LC114			; set up interrupts and sound
+dogame		bsr enablepiairq		; set up interrupts and sound
 		ldd #$100b
 		std V213
 		clr powerlevel			; reset power level to new game level (keeps LSB of default value)
@@ -526,7 +526,7 @@
 		stx ,y				; save new object in backpack list
 		tfr x,y				; move list pointer to object just created
 		bra LC139			; go look for another object to create
-LC14F		tst V277			; are we doing a demo game?
+LC14F		tst waitnewgame			; are we doing a demo game?
 		beq LC166			; brif not
 		dec V29B
 		ldx #LCDB2			; set to scroll display
@@ -547,22 +547,22 @@
 		lbne RESVEC			; brif so - premature end, fail with a reset
 		ldb BLKTYP			; get type of block
 		rts
-LC17C		ldu #PIA0
-		ldd #$343c
-		sta 3,u
-		sta PIA1+3
-		stb PIA1+1
+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
 		rts
-LC18B		ldx zero			; get long delay constant
-LC18D		leax -1,x			; have we reached 0?
-		bne LC18D			; brif not
+busywait	ldx zero			; get long delay constant
+busywait000	leax -1,x			; have we reached 0?
+		bne busywait000			; brif not
 		rts
-LC192		bsr LC17C			; set up PIA for cassette I/O
-		bsr LC18B			; delay for a bit
-		bsr LC18B
+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 LC18B			; delay for a bit
+		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
@@ -573,9 +573,9 @@
 		blo LC1A6			; brif not
 		stu BLKTYP			; write trailing block
 		romcall BLKOUT
-		bsr LC18B			; delay for a bit
+		bsr busywait			; delay for a bit
 		bra LC1EC			; go init things and restart main loop
-LC1C1		bsr LC17C			; set up PIA for cassette I/O
+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
@@ -594,10 +594,10 @@
 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
+LC1EC		jsr enablepiairq		; make sure PIAs are set right
 		clr V2B8			; flag regular operations
-		dod S19
-		showprompt
+		dod S19				; clear command and status areas, update appropriately
+		showprompt			; show command prompt
 LC1F5		ldu #V2AB
 		clr V2BB
 LC1FA		tfr u,y
@@ -729,37 +729,40 @@
 		leau 2,u
 		jsr LC242
 		bra LC2E9
-LC2FF		tst V228
-		bne LC320
-		tst V277
-		beq LC318
-		clr PIA0+2			strobe all keyboard columns
-		lda PIA0			fetch row data
-		anda #$7f			mask off comparator input
-		cmpa #$7f			did we have any keys down?
-		beq LC320			brif not
-		ldx #LC005			; stop any demo game active; start a game
-		stx 10,s			;
-LC318		romcall POLCAT			poll the keyboard
-		tsta				was a key down?
-		beq LC320			brif not
-		bsr LC340			go process keyboard input
-LC320		lda PIA0+2			clear interrupt status
+LC2FF		tst nokeyboard			; are we polling the keyboard?
+		bne LC320			; brif not
+		tst waitnewgame			; are we running a demo/waiting for keypress for game start?
+		beq LC318			; brif not
+		clr PIA0+2			; strobe all keyboard columns
+		lda PIA0			; fetch row data
+		anda #$7f			; mask off comparator input
+		cmpa #$7f			; did we have any keys down?
+		beq LC320			; brif not
+		ldx #LC005			; pointer to game start routine
+		stx 10,s			; set return to game start routine
+LC318		romcall POLCAT			; poll the keyboard
+		tsta				; was a key down?
+		beq LC320			; brif not
+		bsr writekeybuf			; go process keyboard input
+LC320		lda PIA0+2			; clear interrupt status
 		rti
 LC324		fcb $06,$0a,$3c,$3c,$18
-LC329		pshs cc,b,x			save registers and interrupt status
+readkeybuf	pshs cc,b,x			save registers and interrupt status
 		orcc #$10			disable IRQ
 		clra				flag no key pressed
 		ldx #keybuf			point to keyboard ring buffer
 		ldb keybufread			get buffer read offset
 		cmpb keybufwrite		same as buffer write offset?
-		beq LC33E			brif so - no key available
+		beq readkeybuf000		brif so - no key available
 		lda b,x				fetch key from buffer
 		incb				bump buffer pointer
 		andb #$1f			wrap around if needed
 		stb keybufread			save new buffer read offset
-LC33E		puls cc,b,x,pc			restore registers and interrupts
-LC340		pshs cc,b,x			save registers and interrupt status
+readkeybuf000	puls cc,b,x,pc			restore registers and interrupts
+; Add a keypress to the keyboard buffer. NOTE: this does not check for buffer overflow
+; which means when the buffer gets full, it just rolls over and overwrites the previous
+; data.
+writekeybuf	pshs cc,b,x			save registers and interrupt status
 		orcc #$10			disable IRQ
 		ldx #keybuf			point to keyboard ring buffer
 		ldb keybufwrite			get buffer write offset
@@ -1120,7 +1123,7 @@
 		lda V2C7
 		suba #19
 		sta V2AF
-		tst V228
+		tst nokeyboard
 		bne LC595
 		cmpa #3
 		bgt LC5AE
@@ -1137,7 +1140,7 @@
 		bgt LC578
 		cleargfx2
 		dec pageswap			set graphics swap required
-		dec V228
+		dec nokeyboard
 		clr keybufread			; reset keyboard buffer
 		clr keybufwrite			;
 		bra LC5AE
@@ -1151,7 +1154,7 @@
 		lda V26E
 		cmpa V270
 		ble LC599
-		clr V228
+		clr nokeyboard
 		showprompt
 LC5AE		ldx powerlevel
 		cmpx damagelevel
@@ -1168,9 +1171,9 @@
 		fcb $07,$3e,$80,$91
 		fcb $69,$59,$3b,$de
 		fcb $f0
-		clr V228
-		dec V277
-LC5D7		bra LC5D7			wait forever (or until the IRQ does something)
+		clr nokeyboard			; enable keyboard polling in IRQ
+		dec waitnewgame			; set up to wait for keypress to start new game
+LC5D7		bra LC5D7			; wait forever (or until the IRQ does something)
 ; swi 13 routine
 LC5D9		ldu #V388			; point to parameters for status line
 		dec V2B7			; set to nonstandard text area
@@ -1232,7 +1235,7 @@
 		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
+LC656		tst nokeyboard
 		bne LC65F
 		bsr LC660			; go update the display
 		dec pageswap			; flag graphics swap required
@@ -2803,12 +2806,12 @@
 		lda V2AF
 		ldb #2
 		rts
-LD1EB		tst V277
+LD1EB		tst waitnewgame
 		bne LD21B
-LD1EF		jsr LC329
+LD1EF		jsr readkeybuf
 		tsta
 		beq LD248
-		tst V228
+		tst nokeyboard
 		bne LD1EF
 		cmpa #$20
 		beq LD215
@@ -2895,7 +2898,7 @@
 LD2A7		ldu #V2F1
 		tst V2AD
 		beq LD2B4
-		tst V228
+		tst nokeyboard
 		bne LD2B4
 		showprompt
 LD2B4		stu V211