; ChatAudioA.asm -- interval timer interrupt for Chat audio stuff
; Copyright Xerox Corporation 1979

;	Last modified April 24, 1979  1:44 PM

.ent IntervalTimerInterrupt, SwatContextProc
.ent acb

.zrel
acb:	.acb

.srel
IntervalTimerInterrupt: .IntervalTimerInterrupt
SwatContextProc: .SwatContextProc

.nrel


; Interval timer interrupt routine

.IntervalTimerInterrupt:
	sta 0 save0
	sta 3 save3
	movr 0 0		; save carry
	sta 0 saveC
	dsz duration		; time to end this signal?
	 jmp more		; no, continue it

next:	lda 0 write		; compare write and read pointers
	lda 3 read
	sub# 0 3 snr
	 jmp exit		; equal, buffer is empty
	lda 0 0 3		; not empty, get next timer interval
	sta 0 interval
	lda 0 1 3		; get next duration
	sta 0 duration
	inc 3 3			; advance read pointer
	inc 3 3
	lda 0 end
	sub# 0 3 snr		; at end of buffer?
	 lda 3 base		; yes, reset to start
	sta 3 read

more:	lda 3 data		; complement output data
	com 3 3
	sta 3 data
	lda 0 interval		; get timer interval
	mov# 0 0 szr		; nonzero?
	 sta 3 @pUtilOut	; yes, cram data into Diablo printer interface
	lda 3 @pITTime		; compute time of next interrupt
	add 0 3
	lda 0 timeMask		; mask as appropriate for this type of Alto
	and 0 3
	sta 3 @pITTime
	subzl 0 0		; enable for next interrupt
	sit

exit:	lda 0 saveC		; restore carry
	movl 0 0
	lda 0 save0
	lda 3 save3
	bri			; dismiss interrupt

pITTime: 525
pUtilOut: 177016
save0:	.blk 1
save3:	.blk 1
saveC:	.blk 1


; Audio Control block
; offsets in ACB structure must match Bcpl version

.acb:
base:	.blk 1
end:	.blk 1
read:	.blk 1
write:	.blk 1
duration: .blk 1
interval: .blk 1
data:	.blk 1
timeMask: .blk 1
sitShiftCount: .blk 1


; Swat context-switching procedure.
; Kicks interval timer back to life if it is supposed to be on.

.SwatContextProc:
	lda 1 duration
	mov# 0 0 szr		; Leaving Swat?
	mov# 1 1 snr		; Yes, audio signal in progress?
	 jmp 1 3		; No
	subzl 0 0		; Yes, restart interval timer
	sit
	jmp 1 3


.end