\documentclass{article}
\usepackage{common}
\usepackage{array}

\begin{document}
\begin{framed}

\pagehead{Sprite rotate}

Each sprite has a 3-bit ROT field that applies a simple rotation and flip
to the sprite image.

\vspace{10 pt}

\setlength{\bitwidth}{5em}
\setlength{\byteheight}{3em}

\begin{bytefield}{3}
\bitheader[b]{0-2} \\
\bitbox{1}{Y flip} & \bitbox{1}{X flip} & \bitbox{1}{XY swap}
\end{bytefield}

\begin{description}
\item[Y flip] flip the image top-to-bottom
\item[X flip] flip the image left-to-right
\item[XY swap] flip the image diagonally
\end{description}

By using these in combination, the sprite image can be rotated:

\begin{tabular}{|c|c|c|c|c|}
\hline
\textbf{ROT} & \textbf{Y Flip} & \textbf{X flip} & \textbf{XY swap} & \textbf{result} \\
\hline
0 & 0 & 0 & 0 & \includegraphics[width=18pt]{r0.png} \\
\hline
1 & 0 & 0 & 1 & \includegraphics[width=18pt]{r1.png} \\
\hline
2 & 0 & 1 & 0 & \includegraphics[width=18pt]{r2.png} \\
\hline
3 & 0 & 1 & 1 & \includegraphics[width=18pt]{r3.png} \\
\hline
4 & 1 & 0 & 0 & \includegraphics[width=18pt]{r4.png} \\
\hline
5 & 1 & 0 & 1 & \includegraphics[width=18pt]{r5.png} \\
\hline
6 & 1 & 1 & 0 & \includegraphics[width=18pt]{r6.png} \\
\hline
7 & 1 & 1 & 1 & \includegraphics[width=18pt]{r7.png} \\
\hline
\end{tabular}

For example, to rotate the sprite image clockwise by quarter-turns,
set R to 0, 5, 6, 3.

\sample{rotate}

\end{framed}
\end{document}
