% Timing diagrams - R. French 10/11/88
%
% Made for 12 pt, but might work for 10 pt
%
% This is a really large kludge

\typeout{Timing diagrams (rfrench)}

\def\tpicture(#1,#2){\@ifnextchar({\@tpicture(#1,#2)}{\@tpicture(#1,#2)(0,0)}}

\def\@tpicture(#1,#2)(#3,#4){\@picht #2\tvunitlength
\setbox\@picbox\hbox to #1\thunitlength\bgroup 
\hskip -#3\thunitlength \lower #4\tvunitlength \hbox\bgroup}

\def\endtpicture{\endpicture}

\long\def\tput#1#2{\@killglue\raise #1\tvunitlength\hbox to \z@{\kern
\timecur #2\hss}\ignorespaces}

\newlength{\timeunitlength}
\setlength{\timeunitlength}{30pt}

\newlength{\tvunitlength}
\setlength{\tvunitlength}{\timeunitlength}

\newlength{\thunitlength}
\setlength{\thunitlength}{\timeunitlength}

\newlength{\timeinc}
\newlength{\timecur}
\newlength{\timetemp}

\def\timesethscale#1{
	\setlength{\thunitlength}{#1}
}

\def\begintiming#1#2{
	\setlength{\timeinc}{\thunitlength}
	\setlength{\unitlength}{\thunitlength}
	\setlength{\timecur}{0pt}
	\begin{tpicture}(#2,1)
	\tput{.5}{\makebox(0,0)[r]{#1}}
	\setlength{\timecur}{\thunitlength}
}

\def\begintiminglabeled#1#2{
	\setlength{\timeinc}{\thunitlength}
	\setlength{\timecur}{0pt}
	\setlength{\unitlength}{\tvunitlength}
	\begin{tpicture}(#2,1.5)
	\setlength{\unitlength}{\thunitlength}
	\tput{.5}{\makebox(0,0)[r]{#1}}
	\setlength{\timecur}{\thunitlength}
}

\def\endtiming{
	\setlength{\unitlength}{\tvunitlength}
	\end{tpicture}
	\vspace{.1\tvunitlength}
}

\def\timelabel#1#2{
	\setlength{\unitlength}{\tvunitlength}
	\tput{1.1}{\line(0,1){.5}}
	\setlength{\unitlength}{\thunitlength}
	\tput{1.2}{\makebox(#1,0)[b]{#2}}
	\setlength{\unitlength}{\tvunitlength}
	\setlength{\timetemp}{\timecur}
	\addtolength{\timecur}{#1\thunitlength}
	\tput{1.1}{\line(0,1){.5}}
	\setlength{\timecur}{\timetemp}
}

\def\timelabelmidrise#1#2{
	\setlength{\unitlength}{\tvunitlength}
	\setlength{\timetemp}{\timecur}
	\addtolength{\timecur}{.0833\thunitlength}
	\setlength{\unitlength}{\thunitlength}
	\tput{1.2}{\makebox(#1,0)[b]{#2}}
	\setlength{\unitlength}{\tvunitlength}
	\tput{1.1}{\line(0,1){.5}}
	\addtolength{\timecur}{#1\thunitlength}
	\tput{1.1}{\line(0,1){.5}}
	\setlength{\timecur}{\timetemp}
}

\def\timelabelarrow#1#2{
	\setlength{\unitlength}{\tvunitlength}
	\tput{1.1}{\line(0,1){.5}}
	\setlength{\unitlength}{\thunitlength}
	\tput{1.2}{\makebox(#1,0)[b]{$\leftarrow$\hfil #2 \hfil $\rightarrow$}}
	\setlength{\unitlength}{\tvunitlength}
	\setlength{\timetemp}{\timecur}
	\addtolength{\timecur}{#1\thunitlength}
	\tput{1.1}{\line(0,1){.5}}
	\setlength{\timecur}{\timetemp}
}

\def\timelabelmidrisearrow#1#2{
	\setlength{\unitlength}{\tvunitlength}
	\setlength{\timetemp}{\timecur}
	\addtolength{\timecur}{.0833\thunitlength}
	\setlength{\unitlength}{\thunitlength}
	\tput{1.2}{\makebox(#1,0)[b]{$\leftarrow$\hfil #2 \hfil $\rightarrow$}}
	\setlength{\unitlength}{\tvunitlength}
	\tput{1.1}{\line(0,1){.5}}
	\addtolength{\timecur}{#1\thunitlength}
	\tput{1.1}{\line(0,1){.5}}
	\setlength{\timecur}{\timetemp}
}

\def\high{
	\setlength{\unitlength}{\timeinc}
	\tput{1}{\line(1,0){1}}
	\addtolength{\timecur}{\timeinc}
	\setlength{\timeinc}{\thunitlength}
}

\def\highnum#1{
	\setlength{\unitlength}{\timeinc}
	\addtolength{\unitlength}{#1\thunitlength}
	\tput{1}{\line(1,0){1}}
	\addtolength{\timecur}{\unitlength}
	\setlength{\timeinc}{\thunitlength}
}

\def\low{
	\setlength{\unitlength}{\timeinc}
	\tput{0}{\line(1,0){1}}
	\addtolength{\timecur}{\timeinc}
	\setlength{\timeinc}{\thunitlength}
}

\def\lownum#1{
	\setlength{\unitlength}{\timeinc}
	\addtolength{\unitlength}{#1\thunitlength}
	\tput{0}{\line(1,0){1}}
	\addtolength{\timecur}{\unitlength}
	\setlength{\timeinc}{\thunitlength}
}

\def\validbus{
	\setlength{\unitlength}{\timeinc}
	\tput{0}{\line(1,0){1}}
	\tput{1}{\line(1,0){1}}
	\addtolength{\timecur}{\timeinc}
	\setlength{\timeinc}{\thunitlength}
}

\def\validbusnum#1{
	\setlength{\unitlength}{\timeinc}
	\addtolength{\unitlength}{#1\thunitlength}
	\tput{0}{\line(1,0){1}}
	\tput{1}{\line(1,0){1}}
	\addtolength{\timecur}{\unitlength}
	\setlength{\timeinc}{\thunitlength}
}

\def\validbuslabel#1#2{
	\setlength{\unitlength}{\thunitlength}
	\tput{.5}{\makebox(#1,0)[c]{#2}}
}
	
\def\busswitch{
	\setlength{\unitlength}{\tvunitlength}
	\tput{0}{\line(1,6){.1666}}
	\tput{1}{\line(1,-6){.1666}}
	\addtolength{\timecur}{.1666\tvunitlength}
	\addtolength{\timeinc}{-.1666\tvunitlength}
}
	
\def\tristate{
	\setlength{\unitlength}{\timeinc}
	\tput{.5}{\line(1,0){1}}
	\addtolength{\timecur}{\timeinc}
	\setlength{\timeinc}{\thunitlength}
}

\def\bustotri{
	\setlength{\unitlength}{\tvunitlength}
	\tput{0}{\line(1,6){.0833}}
	\tput{1}{\line(1,-6){.0833}}
	\addtolength{\timecur}{.0833\tvunitlength}
	\tput{.5}{\line(1,0){.0833}}
	\addtolength{\timeinc}{-.0833\tvunitlength}
}

\def\tritobus{
	\setlength{\unitlength}{\tvunitlength}
	\tput{.5}{\line(1,0){.0833}}
	\addtolength{\timecur}{.0833\tvunitlength}
	\tput{.5}{\line(1,6){.0833}}
	\tput{.5}{\line(1,-6){.0833}}
	\addtolength{\timecur}{.0833\tvunitlength}
	\addtolength{\timeinc}{-.1666\tvunitlength}
}

\def\timedotdot{
	\setlength{\unitlength}{\timeinc}
	\tput{.5}{\dashbox{3}(1,0){}}
	\addtolength{\timecur}{\timeinc}
	\setlength{\timeinc}{\thunitlength}
}

\def\vert{
	\setlength{\unitlength}{\tvunitlength}
	\tput{0}{\line(0,1){1}}
}

\def\rise{
	\setlength{\unitlength}{\tvunitlength}
	\tput{0}{\line(1,6){.1666}}
	\addtolength{\timecur}{.1666\tvunitlength}
	\addtolength{\timeinc}{-.1666\tvunitlength}
}

\def\fall{
	\setlength{\unitlength}{\tvunitlength}
	\tput{1}{\line(1,-6){.1666}}
	\addtolength{\timecur}{.1666\tvunitlength}
	\addtolength{\timeinc}{-.1666\tvunitlength}
}

% Usage:
%
% \begintiming{label}
%	Begin a timing diagram, with signal label ``label''
%
% \endtiming
%	End a timing diagram
%
% \high
%	High signal
%
% \low
%	Low signal
