; SwatFailSysA.asm - companion to SwatFailSysB.bcpl
; Copyright Xerox Corporation 1979
; Last modified December 4, 1978  9:27 PM by Boggs

; outgoing
.bext	SwatTrap, SwatInterrupt

; incoming
.bext	Fail, TrapHandler, UpdateTimer, failAC2

	.srel

SwatTrap:	.SwatTrap
SwatInterrupt:	.SwatInterrupt

	.nrel

.SwatTrap:
	sta 0 @.userAC0		; so we can debug swat when we break it
	sta 1 @.userAC1
	sta 2 @.userAC2
	sta 3 @.userAC3
	lda 0 @.trapPC
	mkone 1 1
	sub 1 0
	sta 0 @.userPC
	lda 2 @.failAC2
	jsrii .TrapHandler
	 0
.userPC:	700
.userAC0:	701
.userAC1:	702
.userAC2:	703
.userAC3:	704
.trapPC:	527

.failAC2:	failAC2
.TrapHandler:	TrapHandler
.Fail:		Fail

.SwatInterrupt:			; catch swat key (User bored of printing)
	sta 0 intAC0
	sta 1 intAC1
	sta 3 intAC3
	subcl 0 0
	sta 0 intCry

	lda 0 @.kbdAd3
	lda 1 c4
	and 1 0
	lda 1 keyState
	sta 0 keyState
	sz 0 0			; <Swat> key down?
	 jmp Dismiss		; no
	snz 1 1			; heavy fingers?
	 jmp Dismiss		; yes

	lda 0 intAC0		; Fail
	sta 0 @.userAC0
	lda 0 intAC1
	sta 0 @.userAC1
	sta 2 @.userAC2
	lda 0 intAC3
	sta 0 @.userAC3
	lda 0 @.intPC
	sta 0 @.userPC
	lda 2 @.failAC2
	jsrii .Fail
	 0

Dismiss:jsrii .+1
	 UpdateTimer
	lda 1 intCry
	movr 1 1
	lda 0 intAC0
	lda 1 intAC1
	lda 3 intAC3
	bri

intAC0:		.blk 1
intAC1:		.blk 1
intAC3:		.blk 1
intCry:		.blk 1

.intPC:		500
.kbdAd3:	177037		; kbd word with <swat> key in it
c4:		4		; <swat> key bit mask
keyState:	0		; state of <swat> key 16 ms ago

	.end