
# Copyright Tom Jennings 1999-2002, tomj@wps.com

# Teletype I/O. Uses exact drum geometry
# for critical drum timing!

# 200uS/word
# 132 words/track
# 26.4 mS/rotation
# skew=4, so sequential word access=800uS

RETURN	eq 0
VAR	eq 0

# Note that for critical timing I and O are
# interspersed around the drum.

	sector 0
	add 0
	ld C+2
	jump tti	# call TTI
	halt 0

ttchar:	0		# character buffer/arg

#
# Teletype input. Returns with ttchar and A
# containing the inputted character.
#
	sector 10
tti:	sta ttiret	# save return address,
	stz		# test TTY Rx input
#	stnz		# test TTY Rx input
	jump tti	# wait for start bit
	ldm tti		# delay 25mS (1 rev)
	and 0		# clear A
ttix:	jump tti0	# go read bit0

	sector 50	# 8mS after ttix (33mS after start)
tti0:	stz		# test tty in
	or 1		# add in data bit,
	jump tti1	# go read bit1

	sector 28	# 22mS after ttr1
tti1:	rlc		# shift bits L,
	stz		# if line high,
	or 1		# add data bit,
	jump tti2

	sector 6
tti2:	rlc
	stz
	or 1
	jump tti3

	sector 116
tti3:	rlc
	stz
	or 1
	jump tti4

	sector 94
tti4:	rlc
	stz
	or 1
	sto ttchar
ttiret:	jump RETURN


#
# TTY output. Call with ttchar containing
# the character to be output (in the least
# 6 digits), returns with A containing
# ttchar shifted 6 digits right.
# 

	sector 17
tto:	sto ttoret
	ld 0
	tto			# assert start bit,
	ldm ttchar		# pre-load char (delay xxmS)
	jump tto0

	sector 53
tto0:	sr 0			# shift next bit,
	tto			# assert,
	jump tto1		# delay 22 mS,

	sector 80
	sr 0
	tto			# output each bit


