	org $2000
	jmp main

porta 	equ $1000
tcnt 	equ $100E
tflg1	equ $1023
tmsk1 	equ $1022
tic2	equ $1012
tctl2	equ $1021
out2bsp equ $ffc1
outcrlf equ $ffc4

start	rmb 2
end 	rmb 2
ans	rmb 2	
main:	

loop:	ldaa #$40	; Trigger on PA6 set high - trigger pulse
	staa porta
	ldd tcnt	; capture present time
	std start	
	ldaa #$00	; turn off trigger pulse
	staa porta


	ldaa #$08	;capture falling edge of PA1 (IC2)
	staa tctl2	

	ldaa #$02	;clear flag for IC2
	staa tflg1
	
l2:	ldaa tflg1	;wait for flag to go high
	anda #$02
	beq l2

	ldd tic2	;get time of falling edge and store
	std end

	ldd end		;calculate time
	subd start
	std ans
	
	ldx #ans	;print time ticks in hex to screen
	jsr out2bsp
	jsr outcrlf
	
	jmp loop 