; FasterTimer.asm - Assembly routines for dealing with low order RTC bits

; asm fasttimer.asm

	.titl Fastertimer


.ent ReadFasterClock
.ent ReportEvent
.bext events, eventIndex, maxEvents
	.srel
ReadFasterClock: .ReadFasterClock
ReportEvent: .ReportEvent
	.nrel

getframe=370	; BCPL runtime routines
storeargs=367
return=366
VERS = 61014
EMaskVal = 160000	; Engineering number ge 2



;------------------------------------------------------------------
 ;ReadFasterClock() -- current value of real time clock in 10 ms. units (9.7 ms.)
;------------------------------------------------------------------

.ReadFasterClock:
	sta 3 r3Save	;save return -- non-reentrant
	sta 1 r1Save
	VERS
	lda 3 EngMask
	and 0 3		;non-zero for Alto II
	RCLK
	snz 3 3		;shift left 4 for Alto II
	 jmp A1
	movl 1 1
	movl 1 1
	movl 1 1
	movl 1 1
A1: ; 0 is RTC, in 40- ms. units
	movl 1 1
	movl 0 0		; 0 is RTC, in 20 ms. units
	movl 1 1
	movl 0 0		; 0 is RTC, in 10 ms. units
	movl 1 1
	movl 0 0		; 0 is RTC, in 5 ms. units
	movl 1 1
	movl 0 0		; 0 is RTC, in 2+ ms. units
	movl 1 1
	movl 0 0		; 0 is RTC, in 1+ ms. units
	lda 1 r1Save
	lda 3 r3Save
	jmp 1 3

r1Save: 0
r3Save: 0
EngMask: EMaskVal

.ReportEvent:
	inc 3 3
	sta 3 1 2
	sta 1 2 2
	lda 3 @.events
	snz 3,3
	jmp @1 2
	lda 3 @.eventIndex
	lda 1 @.maxEvents
	sle 3,1
	jmp @1 2
	lda 1 @.events
	add 1 3
	lda 1 mlh
	movs 0 0
	and 1 0
	sta 0 3 2
	RCLK
	sta 1 1 3
	lda 1 mrh
	and 1 0
	lda 1 3 2
	add 1 0
	sta 0 0 3
	lda 0 2 2
	sta 0 2 3
	lda 0 @.eventIndex
	lda 1 c3
	add 1 0
	sta 0 @.eventIndex
	jmp @1 2

.events: events
.eventIndex: eventIndex
.maxEvents: maxEvents

mrh: 377
mlh: 177400
c3: 3
	.end