remove bee2-selectmap/.svn
[fleet.git] / doc / register.sty
1 %%
2 %% This is file `register.sty',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% register.dtx  (with options: `package')
8 %% Register diagrams with field descriptions.
9 %% 
10 %% This program is provided under the terms of the
11 %% LaTeX Project Public License distributed from CTAN
12 %% archives in directory macros/latex/base/lppl.txt.
13 %% 
14 %% Author: Matthew Lovell (lovell@indra.com)
15 %% 
16
17
18
19 \ProvidesPackage{register} [2007/03/08 v1.5 Register macros with
20 hyperref/LyX support]
21
22 \RequirePackage{ifthen}[1997/11/02]
23 \RequirePackage{graphicx}[1997/06/09]
24 \RequirePackage{float}[2001/07/25]
25 \RequirePackage{calc}[1998/06/07]
26 \DeclareOption{LyX}{\setboolean{RegisterLyX}{true}}
27 \DeclareOption{hyperref}{\setboolean{RegisterHyperref}{true}}
28 \DeclareOption{TRflags}{\setboolean{RegisterTRFlags}{true}}
29 \DeclareOption{TRboxed}{\setboolean{RegisterTRBoxed}{true}}
30
31 \DeclareOption*{%  Emit a warning for other options
32   \PackageWarning{register}{Unknown option '\CurrentOption'}%
33 }
34
35 \newboolean{RegisterLyX}
36 \newboolean{RegisterHyperref}
37 \newboolean{RegisterTRFlags}
38 \newboolean{RegisterTRBoxed}
39
40 \setboolean{RegisterLyX}{false}
41 \setboolean{RegisterHyperref}{false}
42 \setboolean{RegisterTRFlags}{false}
43 \setboolean{RegisterTRBoxed}{false}
44
45 \ProcessOptions\relax  % Process package options
46 \newboolean{RegisterContext}
47 \setboolean{RegisterContext}{false}
48 \floatstyle{plaintop} \@ifundefined{chapter}
49 {\newfloat{Regfloat}{tbp}{rdf}[section]}
50 {\newfloat{Regfloat}{tbp}{rdf}[chapter]}
51 \floatname{Regfloat}{Register}
52 \newlength{\regWidth}
53 \newlength{\regFieldLen}
54 \newlength{\regLabelAdjust}
55 \newlength{\regResetHeight}
56 \newlength{\regResetDepth}
57 \newlength{\regResetDrop}
58 \newlength{\regDescSkip}
59 \setlength{\regWidth}{0.95\textwidth}
60 \newcommand{\regBitWidth}{32}
61 \newcommand{\regResetName}{Reset}
62 \newcommand{\regBitSize}{\tiny}
63 \newcommand{\regBitFamily}{\sffamily}
64 \newcommand{\regResetSize}{\scriptsize}
65 \newcommand{\regLabelSize}{\footnotesize}
66 \newcommand{\regLabelFamily}{\rmfamily}
67 \newcommand{\regDescFamily}{\bf}
68 \newlength{\regdescsep}
69 \newlength{\oldregdescsep}
70 \setlength{\regdescsep}{-\medskipamount}
71
72 \newsavebox{\Label}
73 \newsavebox{\RotatedLabel}
74 \newcounter{upperbit}
75 \newcounter{lowerbit}
76 \newenvironment{reglist}[1][M]
77   {\begin{list}{}
78     {\settowidth{\labelwidth}{\regDescFamily #1}
79      \addtolength{\labelwidth}{\labelsep}
80      \setlength{\leftmargin}{\labelwidth}
81      \addtolength{\leftmargin}{\labelsep}
82      \addtolength{\leftmargin}{0.5\regDescSkip}
83      \addtolength{\rightmargin}{0.5\regDescSkip}
84      \setlength{\topsep}{0pt}
85      \setlength{\itemsep}{0pt}
86      \setlength{\parsep}{0.5\baselineskip}
87      \renewcommand{\makelabel}[1]{\regDescFamily ##1 \hfill}}}
88   {\end{list}}
89 \newenvironment{regdesc}[1][0.90\textwidth]%
90 {%
91  \setlength{\regDescSkip}{\textwidth - #1}%
92  \vspace{\regdescsep}%
93 \ifthenelse{\boolean{RegisterLyX}}{%
94   \renewenvironment{lyxlist}[1]
95     {\begin{list}{}
96       {\settowidth{\labelwidth}{\regDescFamily ##1}
97        \addtolength{\labelwidth}{\labelsep}
98        \setlength{\leftmargin}{\labelwidth}
99        \addtolength{\leftmargin}{\labelsep}
100        \addtolength{\leftmargin}{0.5\regDescSkip}
101        \addtolength{\rightmargin}{0.5\regDescSkip}
102        \setlength{\topsep}{0pt}
103        %\setlength{\partopsep}{0pt}
104        \renewcommand{\makelabel}[1]{\regDescFamily ####1 \hfill}}}
105     {\end{list}}}{}%
106  % endif
107  % set spacing appropriately
108  \leftskip 0.5\regDescSkip%
109  \rightskip 0.5\regDescSkip%
110  \parfillskip=\z@ plus 1fil%
111  \parskip=0.5\baselineskip \advance\parskip by 0pt plus 2pt%
112 }% end begin{regdesc}
113 {\vskip\baselineskip}
114 \newcommand{\regnewline}{\\*}
115 \newenvironment{register}[3]
116 {\begin{Regfloat}[#1]%
117   \setlength{\leftskip}{0pt}%
118   \setlength{\oldregdescsep}{\regdescsep}%
119   \setlength{\regdescsep}{0.5\baselineskip}%
120   \setlength{\partopsep}{0pt}%
121   \setlength{\topsep}{0pt}%
122   \setboolean{RegisterContext}{true}%
123   \ifthenelse{\equal{#3}{}}%
124   {\caption[#2]{\textsc{#2}}}% else
125   {\caption[#2]{\textsc{#2} ({#3})}}%
126   \centering}
127 {% restore lengths
128   \leftskip\z@%
129   \rightskip\z@%
130   \parfillskip=\z@ plus 1fil%
131   \setlength{\regdescsep}{\oldregdescsep}%
132   \setboolean{RegisterContext}{false}%
133   \end{Regfloat}}
134 \def\regUnderScore{_}%
135 \def\regFiller#1{\def\regInner{#1}%
136 \ifx\regInner\regUnderScore%
137 \else%
138 \ifnum\count0>0%
139 \hfill#1%
140 \else#1\fi%
141 \fi%
142 \advance\count0 by 1%
143 }
144 \def\regSpread#1{\count0=0{}\regSpreadaux#1\empty}
145 \def\regSpreadaux#1#2\empty{\def\aux{#1}%\show#1%
146 \ifx\aux\empty%
147 \else%
148 \def\aux{#2}%
149 \regFiller{#1}%
150 \ifx\aux\empty%
151 \else%
152 \regSpreadaux#2\empty%
153 \fi\fi}
154 \newcommand{\setRegLengths}{%
155   % Compute basic width of a single bit
156   \settowidth{\regFieldLen}{\regLabelSize \regResetName}%
157   \setlength{\regFieldLen}{\regWidth - \regFieldLen}%
158   \setlength{\regFieldLen}{\regFieldLen / \regBitWidth}%
159   % Figure out height and depth of reset field in current font
160   % Is there a more ``official'' method to do this?
161   \settodepth{\regResetDepth}{\regResetSize ()jgpq}%
162   \settoheight{\regResetHeight}{\regResetSize ()ABCjkl}%
163   \addtolength{\regResetHeight}{\regResetDepth}%
164   % Compute how far to drop the reset fields down.  The value at
165   % the end is effectively the separation between the bit position
166   % box and the reset value box.
167   \setlength{\regResetDrop}{\regResetHeight + 2\fboxsep - 2\fboxrule + 3pt}%
168 }
169 \newcommand{\regMakeFieldName}[1]{%
170   % Create box to hold label
171   \savebox{\Label}{\regLabelSize\regLabelFamily #1}%
172 }
173 \newcommand{\regRotateFieldName}{%
174   \savebox{\RotatedLabel}{\rotatebox[origin=lB]{45}{\usebox{\Label}}}%
175   \makebox[0pt][l]{\raisebox{\regResetHeight + \fboxsep + \depth + 1pt}%
176         {\hspace{\regLabelAdjust}\usebox{\RotatedLabel}}}%
177 }
178 \newcommand{\typesetRegBits}[1]{%
179   \ifthenelse{#1 > 1}%
180     {\framebox[\regFieldLen][c]%
181         {\regBitSize \rule[-1\regResetDepth]{0pt}{\regResetHeight}%
182            \regBitFamily\arabic{upperbit} \hfill \arabic{lowerbit}}}%
183     {\framebox[\regFieldLen][c]%
184         {\regBitSize \rule[-1\regResetDepth]{0pt}{\regResetHeight}%
185            \regBitFamily\arabic{lowerbit}}}%
186 }
187 \newcommand{\typesetRegReset}[1]{%
188  % Typeset reset value in a framebox
189   \makebox[0pt][l]{\raisebox{-1\regResetDrop}{\framebox[\regFieldLen][c]%
190         % Place an invisible rule to control the box
191         % surrounding the reset field
192         {\regResetSize \rule[-1\regResetDepth]{0pt}{\regResetHeight}\regSpread{#1}}}}%
193 }
194 \newcommand{\regfield}[4]{%
195   % Compute overall field length
196   \setRegLengths%
197   \setlength{\regFieldLen}{#2\regFieldLen + \fboxrule}%
198   % Figure out bit positions
199   \setcounter{lowerbit}{#3}%
200   \setcounter{upperbit}{#3 + #2 - 1}%
201   \regMakeFieldName{#1}%
202   % Figure out how far over to place label, accounting for height
203   \setlength{\regLabelAdjust}{0.5\regFieldLen - 0.707107\ht\Label}%
204   % Now, rotate and type the label
205   \regRotateFieldName%
206   \typesetRegReset{#4}%
207   % Typeset bit positions in a framebox
208   \typesetRegBits{#2}%
209   \hspace{-1\fboxrule}%
210 }
211 \newcommand{\regfieldb}[3]{%
212   % Compute overall field length
213   \setRegLengths%
214   \setlength{\regFieldLen}{#2\regFieldLen + \fboxrule}%
215   % Figure out bit positions
216   \setcounter{lowerbit}{#3}%
217   \setcounter{upperbit}{#3 + #2 - 1}%
218   % Create box to hold label
219   \regMakeFieldName{#1}%
220   % Figure out how far over to place label, accounting for height
221   \setlength{\regLabelAdjust}{0.5\regFieldLen - 0.707107\ht\Label}%
222   % Now, rotate and typeset the label
223   \regRotateFieldName%
224   % Typeset bit positions
225   \typesetRegBits{#2}%
226   \hspace{-1\fboxrule}%
227 }
228 \newcommand{\regbits}[3]{%
229   % Compute overall field length
230   \setRegLengths%
231   \setlength{\regFieldLen}{#2\regFieldLen + \fboxrule}%
232   % Figure out bit positions
233   \setcounter{lowerbit}{#3}%
234   \setcounter{upperbit}{#3 + #2 - 1}%
235   % Create box to hold label
236   \regMakeFieldName{#1}%
237   % Figure out how far over to place label, accounting for height
238   \setlength{\regLabelAdjust}{0.5\regFieldLen - 0.707107\ht\Label}%
239   % Now, rotate and typeset the label
240   \regRotateFieldName%
241   % Typeset field value
242   \framebox[\regFieldLen][c]%
243         {\tiny\regSpread{#3}}%
244   \hspace{-1\fboxrule}%
245 }
246 \newcommand{\regspace}[1]{%
247   % Compute overall field length
248   \setRegLengths%
249   \setlength{\regFieldLen}{#1\regFieldLen + \fboxrule}%
250   \makebox[\regFieldLen]{}%
251 }
252
253 \newcommand{\reglabel}[1]{%
254   \settowidth{\regFieldLen}{\regLabelSize \regResetName}%
255   \setlength{\regResetDrop}{\regResetDrop + 0.5\fboxsep}%
256   $\,$\raisebox{-1\regResetDrop}{\makebox[\regFieldLen][l]%
257     {\regLabelSize\regBitFamily #1}}%
258 }
259
260 \newcommand{\reglabelb}[1]{%
261   \settowidth{\regFieldLen}{\regLabelSize \regResetName}%
262   $\,$\raisebox{-0.5\fboxsep}{\makebox[\regFieldLen][l]%
263     {\regLabelSize\regBitFamily #1}}%
264 }
265 \ifthenelse{\boolean{RegisterHyperref}}{%
266   % Define a counter for the hyperref package.  Otherwise,
267   % the hyperlinks to registers don't work correctly
268   \@namedef{theHRegfloat}{\theRegfloat}
269
270   % Define a bookmark level for Regfloats (for hyperref package)
271   \def\toclevel@Regfloat{0}
272 }{}
273 \newcommand{\listofregisters}{%
274   \@ifundefined{ext@Regfloat}{\float@error{Regfloat}}{%
275     \@ifundefined{chapter}{\def\@tempa{\section*}}%
276       {\def\@tempa{\chapter*}}%
277     \@tempa{List of Registers\@mkboth{\uppercase{List of Registers}}%
278        {\uppercase{List of Registers}}}%
279     \addcontentsline{toc}{chapter}{List of Registers}%
280     \@starttoc{\@nameuse{ext@Regfloat}}}}
281 \newcommand\l@Regfloat{\@dottedtocline{1}{1.5em}{2.3em}}
282 \@ifundefined{chapter}{}
283 {% Adjust chapter definition slightly for Regfloats
284 \def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
285   \if@mainmatter
286     \refstepcounter{chapter}%
287     \typeout{\@chapapp\space\thechapter.}%
288     \addcontentsline{toc}{chapter}%
289     {\protect\numberline{\thechapter}#1}%
290   \else
291     \addcontentsline{toc}{chapter}{#1}%
292   \fi
293   \else
294     \addcontentsline{toc}{chapter}{#1}%
295   \fi
296   \chaptermark{#1}%
297     \addtocontents{lof}{\protect\addvspace{10\p@}}%
298     \addtocontents{lot}{\protect\addvspace{10\p@}}%
299     \addtocontents{rdf}{\protect\addvspace{10\p@}}% --- Add space ---
300   \if@twocolumn
301     \@topnewpage[\@makechapterhead{#2}]%
302   \else
303     \@makechapterhead{#2}%
304     \@afterheading
305   \fi}
306 }
307 \newcommand\@GetTRSecondParam{}
308 \long\def\@GetTRSecondParam#1#2#3\@nil{#2}
309 \newcommand*{\GetTRPageRef}[1]{%
310   \expandafter\expandafter\expandafter\@GetTRSecondParam
311     \csname r@#1\endcsname
312     0% dummy, if the reference is undefined
313     \@nil
314 }
315
316 \newcommand{\TRfamily}{\sffamily}
317 \newcounter{T@peReleaseTag}
318 \newlength{\TRwidth}
319 \setlength{\TRwidth}{\marginparwidth}
320 \newlength{\T@peReleaseDepth}
321
322 \newcommand{\TRwriteout}[1]{%
323   \makebox[\TRwidth][c]{%
324     \raisebox{\T@peReleaseDepth}{%
325      \ifthenelse{\boolean{RegisterTRBoxed}}%
326        {\fbox{\TRfamily #1}}%
327        {\TRfamily #1}}}%
328 }
329
330 \newcommand{\TRrightlabel}[1]{%
331   % Place a strut in order to set line depth
332   \mbox{}\strut\settodepth{\T@peReleaseDepth}{\strut}%
333    \vadjust{\hspace{\textwidth}\hspace{\marginparsep}%
334    \smash{\rlap{\TRwriteout{#1}}}}}
335
336 \ifthenelse{\boolean{@twoside}}{
337   % Two-sided document
338   \newcommand{\TRleftlabel}[1]{%
339     % Place a strut in order to set line depth
340     \mbox{}\strut\settodepth{\T@peReleaseDepth}{\strut}%
341     \vadjust{\smash{\llap{\TRwriteout{#1}}\kern\marginparsep}}}
342 }{
343   % Otherwise, the command is the same as rightlabel
344   \newcommand{\TRleftlabel}[1]{%
345     \TRrightlabel{#1}}
346 }
347 \ifthenelse{\boolean{RegisterTRFlags}}{
348 \newcommand{\TR}[1]{%
349   \stepcounter{T@peReleaseTag}%
350   \label{TapeReleaseTag-\theT@peReleaseTag}%
351   \ifthenelse{\isodd{\GetTRPageRef{TapeReleaseTag-\theT@peReleaseTag}}}%
352    {\TRrightlabel{TR\hspace{1pt}#1}}%
353    {\TRleftlabel{TR\hspace{1pt}#1}}%
354 }}
355 {\newcommand{\TR}[1]{}}
356 \endinput
357 %%
358 %% End of file `register.sty'.