2 %% This is file `register.sty',
3 %% generated with the docstrip utility.
5 %% The original source files were:
7 %% register.dtx (with options: `package')
8 %% Register diagrams with field descriptions.
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.
14 %% Author: Matthew Lovell (lovell@indra.com)
19 \ProvidesPackage{register} [2007/03/08 v1.5 Register macros with
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}}
31 \DeclareOption*{% Emit a warning for other options
32 \PackageWarning{register}{Unknown option '\CurrentOption'}%
35 \newboolean{RegisterLyX}
36 \newboolean{RegisterHyperref}
37 \newboolean{RegisterTRFlags}
38 \newboolean{RegisterTRBoxed}
40 \setboolean{RegisterLyX}{false}
41 \setboolean{RegisterHyperref}{false}
42 \setboolean{RegisterTRFlags}{false}
43 \setboolean{RegisterTRBoxed}{false}
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}
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}
73 \newsavebox{\RotatedLabel}
76 \newenvironment{reglist}[1][M]
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}}}
89 \newenvironment{regdesc}[1][0.90\textwidth]%
91 \setlength{\regDescSkip}{\textwidth - #1}%
93 \ifthenelse{\boolean{RegisterLyX}}{%
94 \renewenvironment{lyxlist}[1]
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}}}
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})}}%
130 \parfillskip=\z@ plus 1fil%
131 \setlength{\regdescsep}{\oldregdescsep}%
132 \setboolean{RegisterContext}{false}%
134 \def\regUnderScore{_}%
135 \def\regFiller#1{\def\regInner{#1}%
136 \ifx\regInner\regUnderScore%
142 \advance\count0 by 1%
144 \def\regSpread#1{\count0=0{}\regSpreadaux#1\empty}
145 \def\regSpreadaux#1#2\empty{\def\aux{#1}%\show#1%
152 \regSpreadaux#2\empty%
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}%
169 \newcommand{\regMakeFieldName}[1]{%
170 % Create box to hold label
171 \savebox{\Label}{\regLabelSize\regLabelFamily #1}%
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}}}%
178 \newcommand{\typesetRegBits}[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}}}%
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}}}}%
194 \newcommand{\regfield}[4]{%
195 % Compute overall field length
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
206 \typesetRegReset{#4}%
207 % Typeset bit positions in a framebox
209 \hspace{-1\fboxrule}%
211 \newcommand{\regfieldb}[3]{%
212 % Compute overall field length
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
224 % Typeset bit positions
226 \hspace{-1\fboxrule}%
228 \newcommand{\regbits}[3]{%
229 % Compute overall field length
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
241 % Typeset field value
242 \framebox[\regFieldLen][c]%
243 {\tiny\regSpread{#3}}%
244 \hspace{-1\fboxrule}%
246 \newcommand{\regspace}[1]{%
247 % Compute overall field length
249 \setlength{\regFieldLen}{#1\regFieldLen + \fboxrule}%
250 \makebox[\regFieldLen]{}%
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}}%
260 \newcommand{\reglabelb}[1]{%
261 \settowidth{\regFieldLen}{\regLabelSize \regResetName}%
262 $\,$\raisebox{-0.5\fboxsep}{\makebox[\regFieldLen][l]%
263 {\regLabelSize\regBitFamily #1}}%
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}
270 % Define a bookmark level for Regfloats (for hyperref package)
271 \def\toclevel@Regfloat{0}
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
286 \refstepcounter{chapter}%
287 \typeout{\@chapapp\space\thechapter.}%
288 \addcontentsline{toc}{chapter}%
289 {\protect\numberline{\thechapter}#1}%
291 \addcontentsline{toc}{chapter}{#1}%
294 \addcontentsline{toc}{chapter}{#1}%
297 \addtocontents{lof}{\protect\addvspace{10\p@}}%
298 \addtocontents{lot}{\protect\addvspace{10\p@}}%
299 \addtocontents{rdf}{\protect\addvspace{10\p@}}% --- Add space ---
301 \@topnewpage[\@makechapterhead{#2}]%
303 \@makechapterhead{#2}%
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
316 \newcommand{\TRfamily}{\sffamily}
317 \newcounter{T@peReleaseTag}
319 \setlength{\TRwidth}{\marginparwidth}
320 \newlength{\T@peReleaseDepth}
322 \newcommand{\TRwriteout}[1]{%
323 \makebox[\TRwidth][c]{%
324 \raisebox{\T@peReleaseDepth}{%
325 \ifthenelse{\boolean{RegisterTRBoxed}}%
326 {\fbox{\TRfamily #1}}%
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}}}}}
336 \ifthenelse{\boolean{@twoside}}{
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}}}
343 % Otherwise, the command is the same as rightlabel
344 \newcommand{\TRleftlabel}[1]{%
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}}%
355 {\newcommand{\TR}[1]{}}
358 %% End of file `register.sty'.