summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/register/register.sty
blob: 7c3b572183482714861872d494861dd628485e0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
%%
%% This is file `register.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% register.dtx  (with options: `package')
%% Register diagrams with field descriptions.
%% 
%% This program is provided under the terms of the
%% LaTeX Project Public License distributed from CTAN
%% archives in directory macros/latex/base/lppl.txt.
%% 
%% Author: Matthew Lovell (lovell@indra.com)
%% 



\ProvidesPackage{register} [2011/01/11 v1.6 Register macros with
hyperref/LyX support]

\RequirePackage{ifthen}[1997/11/02]
\RequirePackage{graphicx}[1997/06/09]
\RequirePackage{float}[2001/07/25]
\RequirePackage{calc}[1998/06/07]
\DeclareOption{LyX}{\setboolean{RegisterLyX}{true}}
\DeclareOption{hyperref}{\setboolean{RegisterHyperref}{true}}
\DeclareOption{TRflags}{\setboolean{RegisterTRFlags}{true}}
\DeclareOption{TRboxed}{\setboolean{RegisterTRBoxed}{true}}

\DeclareOption*{%  Emit a warning for other options
  \PackageWarning{register}{Unknown option '\CurrentOption'}%
}

\newboolean{RegisterLyX}
\newboolean{RegisterHyperref}
\newboolean{RegisterTRFlags}
\newboolean{RegisterTRBoxed}

\setboolean{RegisterLyX}{false}
\setboolean{RegisterHyperref}{false}
\setboolean{RegisterTRFlags}{false}
\setboolean{RegisterTRBoxed}{false}

\ProcessOptions\relax  % Process package options
\newboolean{RegisterContext}
\setboolean{RegisterContext}{false}
\floatstyle{plaintop} \@ifundefined{chapter}
{\newfloat{Regfloat}{tbp}{rdf}[section]}
{\newfloat{Regfloat}{tbp}{rdf}[chapter]}
\floatname{Regfloat}{Register}
\newlength{\regWidth}
\newlength{\regFieldLen}
\newlength{\regLabelAdjust}
\newlength{\regResetHeight}
\newlength{\regResetDepth}
\newlength{\regResetDrop}
\newlength{\regDescSkip}
\setlength{\regWidth}{0.95\textwidth}
\newcommand{\regBitWidth}{32}
\newcommand{\regResetName}{Reset}
\newcommand{\regBitSize}{\tiny}
\newcommand{\regBitFamily}{\sffamily}
\newcommand{\regResetSize}{\scriptsize}
\newcommand{\regLabelSize}{\footnotesize}
\newcommand{\regLabelFamily}{\rmfamily}
\newcommand{\regDescFamily}{\bf}
\newlength{\regdescsep}
\newlength{\oldregdescsep}
\setlength{\regdescsep}{-\medskipamount}

\newsavebox{\Label}
\newsavebox{\RotatedLabel}
\newcounter{upperbit}
\newcounter{lowerbit}
\newenvironment{reglist}[1][M]
  {\begin{list}{}
    {\settowidth{\labelwidth}{\regDescFamily #1}
     \addtolength{\labelwidth}{\labelsep}
     \setlength{\leftmargin}{\labelwidth}
     \addtolength{\leftmargin}{\labelsep}
     \addtolength{\leftmargin}{0.5\regDescSkip}
     \addtolength{\rightmargin}{0.5\regDescSkip}
     \setlength{\topsep}{0pt}
     \setlength{\itemsep}{0pt}
     \setlength{\parsep}{0.5\baselineskip}
     \renewcommand{\makelabel}[1]{\regDescFamily ##1 \hfill}}}
  {\end{list}}
\newenvironment{regdesc}[1][0.90\textwidth]%
{%
 \setlength{\regDescSkip}{\textwidth - #1}%
 \vspace{\regdescsep}%
\ifthenelse{\boolean{RegisterLyX}}{%
  \renewenvironment{lyxlist}[1]
    {\begin{list}{}
      {\settowidth{\labelwidth}{\regDescFamily ##1}
       \addtolength{\labelwidth}{\labelsep}
       \setlength{\leftmargin}{\labelwidth}
       \addtolength{\leftmargin}{\labelsep}
       \addtolength{\leftmargin}{0.5\regDescSkip}
       \addtolength{\rightmargin}{0.5\regDescSkip}
       \setlength{\topsep}{0pt}
       %\setlength{\partopsep}{0pt}
       \renewcommand{\makelabel}[1]{\regDescFamily ####1 \hfill}}}
    {\end{list}}}{}%
 % endif
 % set spacing appropriately
 \leftskip 0.5\regDescSkip%
 \rightskip 0.5\regDescSkip%
 \parfillskip=\z@ plus 1fil%
 \parskip=0.5\baselineskip \advance\parskip by 0pt plus 2pt%
}% end begin{regdesc}
{\vskip\baselineskip}
\newcommand{\regnewline}{\\*}
\newenvironment{register}[3]
{\begin{Regfloat}[#1]%
  \setlength{\leftskip}{0pt}%
  \setlength{\oldregdescsep}{\regdescsep}%
  \setlength{\regdescsep}{0.5\baselineskip}%
  \setlength{\partopsep}{0pt}%
  \setlength{\topsep}{0pt}%
  \setboolean{RegisterContext}{true}%
  \ifthenelse{\equal{#3}{}}%
  {\caption[#2]{\textsc{#2}}}% else
  {\caption[#2]{\textsc{#2} ({#3})}}%
  \centering}
{% restore lengths
  \leftskip\z@%
  \rightskip\z@%
  \parfillskip=\z@ plus 1fil%
  \setlength{\regdescsep}{\oldregdescsep}%
  \setboolean{RegisterContext}{false}%
  \end{Regfloat}}
\def\regUnderScore{_}%
\def\regFiller#1{\def\regInner{#1}%
\ifx\regInner\regUnderScore%
\else%
\ifnum\count0>0%
\hfill#1%
\else#1\fi%
\fi%
\advance\count0 by 1%
}
\def\regSpread#1{\count0=0{}\regSpreadaux#1\empty}
\def\regSpreadaux#1#2\empty{\def\aux{#1}%\show#1%
\ifx\aux\empty%
\else%
\def\aux{#2}%
\regFiller{#1}%
\ifx\aux\empty%
\else%
\regSpreadaux#2\empty%
\fi\fi}
\newcommand{\setRegLengths}{%
  % Compute basic width of a single bit
  \settowidth{\regFieldLen}{\regLabelSize \regResetName}%
  \setlength{\regFieldLen}{\regWidth - \regFieldLen}%
  \setlength{\regFieldLen}{\regFieldLen / \regBitWidth}%
  % Figure out height and depth of reset field in current font
  % Is there a more ``official'' method to do this?
  \settodepth{\regResetDepth}{\regResetSize ()jgpq}%
  \settoheight{\regResetHeight}{\regResetSize ()ABCjkl}%
  \addtolength{\regResetHeight}{\regResetDepth}%
  % Compute how far to drop the reset fields down.  The value at
  % the end is effectively the separation between the bit position
  % box and the reset value box.
  \setlength{\regResetDrop}{\regResetHeight + 2\fboxsep - 2\fboxrule + 3pt}%
}
\newcommand{\regMakeFieldName}[1]{%
  % Create box to hold label
  \savebox{\Label}{\regLabelSize\regLabelFamily #1}%
}
\newcommand{\regRotateFieldName}{%
  \savebox{\RotatedLabel}{\rotatebox[origin=lB]{45}{\usebox{\Label}}}%
  \makebox[0pt][l]{\raisebox{\regResetHeight + \fboxsep + \depth + 1pt}%
        {\hspace{\regLabelAdjust}\usebox{\RotatedLabel}}}%
}
\newcommand{\typesetRegBits}[1]{%
  \ifthenelse{#1 > 1}%
    {\framebox[\regFieldLen][c]%
        {\regBitSize \rule[-1\regResetDepth]{0pt}{\regResetHeight}%
           \regBitFamily\arabic{upperbit} \hfill \arabic{lowerbit}}}%
    {\framebox[\regFieldLen][c]%
        {\regBitSize \rule[-1\regResetDepth]{0pt}{\regResetHeight}%
           \regBitFamily\arabic{lowerbit}}}%
}
\newcommand{\typesetRegReset}[1]{%
 % Typeset reset value in a framebox
  \makebox[0pt][l]{\raisebox{-1\regResetDrop}{\framebox[\regFieldLen][c]%
        % Place an invisible rule to control the box
        % surrounding the reset field
        {\regResetSize \rule[-1\regResetDepth]{0pt}{\regResetHeight}\regSpread{#1}}}}%
}
\newcommand{\regfield}[4]{%
  % Compute overall field length
  \setRegLengths%
  \setlength{\regFieldLen}{#2\regFieldLen + \fboxrule}%
  % Figure out bit positions
  \setcounter{lowerbit}{#3}%
  \setcounter{upperbit}{#3 + #2 - 1}%
  \regMakeFieldName{#1}%
  % Figure out how far over to place label, accounting for height
  \setlength{\regLabelAdjust}{0.5\regFieldLen - 0.707107\ht\Label}%
  % Now, rotate and type the label
  \regRotateFieldName%
  \typesetRegReset{#4}%
  % Typeset bit positions in a framebox
  \typesetRegBits{#2}%
  \hspace{-1\fboxrule}%
}
\newcommand{\regfieldb}[3]{%
  % Compute overall field length
  \setRegLengths%
  \setlength{\regFieldLen}{#2\regFieldLen + \fboxrule}%
  % Figure out bit positions
  \setcounter{lowerbit}{#3}%
  \setcounter{upperbit}{#3 + #2 - 1}%
  % Create box to hold label
  \regMakeFieldName{#1}%
  % Figure out how far over to place label, accounting for height
  \setlength{\regLabelAdjust}{0.5\regFieldLen - 0.707107\ht\Label}%
  % Now, rotate and typeset the label
  \regRotateFieldName%
  % Typeset bit positions
  \typesetRegBits{#2}%
  \hspace{-1\fboxrule}%
}
\newcommand{\regbits}[3]{%
  % Compute overall field length
  \setRegLengths%
  \setlength{\regFieldLen}{#2\regFieldLen + \fboxrule}%
  % Figure out bit positions
  \setcounter{lowerbit}{#3}%
  \setcounter{upperbit}{#3 + #2 - 1}%
  % Create box to hold label
  \regMakeFieldName{#1}%
  % Figure out how far over to place label, accounting for height
  \setlength{\regLabelAdjust}{0.5\regFieldLen - 0.707107\ht\Label}%
  % Now, rotate and typeset the label
  \regRotateFieldName%
  % Typeset field value
  \framebox[\regFieldLen][c]%
        {\tiny\regSpread{#3}}%
  \hspace{-1\fboxrule}%
}
\newcommand{\regspace}[1]{%
  % Compute overall field length
  \setRegLengths%
  \setlength{\regFieldLen}{#1\regFieldLen + \fboxrule}%
  \makebox[\regFieldLen]{}%
}

\newcommand{\reglabel}[1]{%
  \settowidth{\regFieldLen}{\regLabelSize \regResetName}%
  \setlength{\regResetDrop}{\regResetDrop + 0.5\fboxsep}%
  $\,$\raisebox{-1\regResetDrop}{\makebox[\regFieldLen][l]%
    {\regLabelSize\regBitFamily #1}}%
}

\newcommand{\reglabelb}[1]{%
  \settowidth{\regFieldLen}{\regLabelSize \regResetName}%
  $\,$\raisebox{-0.5\fboxsep}{\makebox[\regFieldLen][l]%
    {\regLabelSize\regBitFamily #1}}%
}
\ifthenelse{\boolean{RegisterHyperref}}{%
  % Define a counter for the hyperref package.  Otherwise,
  % the hyperlinks to registers don't work correctly
  \@namedef{theHRegfloat}{\theRegfloat}

  % Define a bookmark level for Regfloats (for hyperref package)
  \def\toclevel@Regfloat{0}
}{}
\newcommand{\listofregisters}{%
  \@ifundefined{ext@Regfloat}{\float@error{Regfloat}}{%
    \@ifundefined{chapter}{\def\@tempa{\section*}}%
      {\def\@tempa{\chapter*}}%
    \@tempa{List of Registers\@mkboth{\uppercase{List of Registers}}%
       {\uppercase{List of Registers}}}%
    \addcontentsline{toc}{chapter}{List of Registers}%
    \@starttoc{\@nameuse{ext@Regfloat}}}}
\newcommand\l@Regfloat{\@dottedtocline{1}{1.5em}{2.3em}}
\@ifundefined{@mainmatter}{\newif\if@mainmatter \@mainmattertrue}{}
\@ifundefined{chapter}{}
{% Adjust chapter definition slightly for Regfloats
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
  \if@mainmatter
    \refstepcounter{chapter}%
    \typeout{\@chapapp\space\thechapter.}%
    \addcontentsline{toc}{chapter}%
    {\protect\numberline{\thechapter}#1}%
  \else
    \addcontentsline{toc}{chapter}{#1}%
  \fi
  \else
    \addcontentsline{toc}{chapter}{#1}%
  \fi
  \chaptermark{#1}%
    \addtocontents{lof}{\protect\addvspace{10\p@}}%
    \addtocontents{lot}{\protect\addvspace{10\p@}}%
    \addtocontents{rdf}{\protect\addvspace{10\p@}}% --- Add space ---
  \if@twocolumn
    \@topnewpage[\@makechapterhead{#2}]%
  \else
    \@makechapterhead{#2}%
    \@afterheading
  \fi}
}
\newcommand\@GetTRSecondParam{}
\long\def\@GetTRSecondParam#1#2#3\@nil{#2}
\newcommand*{\GetTRPageRef}[1]{%
  \expandafter\expandafter\expandafter\@GetTRSecondParam
    \csname r@#1\endcsname
    0% dummy, if the reference is undefined
    \@nil
}

\newcommand{\TRfamily}{\sffamily}
\newcounter{T@peReleaseTag}
\newlength{\TRwidth}
\setlength{\TRwidth}{\marginparwidth}
\newlength{\T@peReleaseDepth}

\newcommand{\TRwriteout}[1]{%
  \makebox[\TRwidth][c]{%
    \raisebox{\T@peReleaseDepth}{%
     \ifthenelse{\boolean{RegisterTRBoxed}}%
       {\fbox{\TRfamily #1}}%
       {\TRfamily #1}}}%
}

\newcommand{\TRrightlabel}[1]{%
  % Place a strut in order to set line depth
  \mbox{}\strut\settodepth{\T@peReleaseDepth}{\strut}%
   \vadjust{\hspace{\textwidth}\hspace{\marginparsep}%
   \smash{\rlap{\TRwriteout{#1}}}}}

\ifthenelse{\boolean{@twoside}}{
  % Two-sided document
  \newcommand{\TRleftlabel}[1]{%
    % Place a strut in order to set line depth
    \mbox{}\strut\settodepth{\T@peReleaseDepth}{\strut}%
    \vadjust{\smash{\llap{\TRwriteout{#1}}\kern\marginparsep}}}
}{
  % Otherwise, the command is the same as rightlabel
  \newcommand{\TRleftlabel}[1]{%
    \TRrightlabel{#1}}
}
\ifthenelse{\boolean{RegisterTRFlags}}{
\newcommand{\TR}[1]{%
  \stepcounter{T@peReleaseTag}%
  \label{TapeReleaseTag-\theT@peReleaseTag}%
  \ifthenelse{\isodd{\GetTRPageRef{TapeReleaseTag-\theT@peReleaseTag}}}%
   {\TRrightlabel{TR\hspace{1pt}#1}}%
   {\TRleftlabel{TR\hspace{1pt}#1}}%
}}
{\newcommand{\TR}[1]{}}
\endinput
%%
%% End of file `register.sty'.