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

\begin{document}
\begin{framed}

\pagehead{Colors}

Gameduino stores colors in an ARGB1555 format:

\vspace{12 pt}

\setlength{\bitwidth}{2em}
\setlength{\byteheight}{2em}

\begin{bytefield}{16}
\bitheader[b]{0-15} \\
\bitbox{1}{A} & \bitbox{5}{R} & \bitbox{5}{G} & \bitbox{5}{B} \\
\end{bytefield}

Each color field red (\textbf{R})
green (\textbf{G}) and
blue (\textbf{B}) has a range 0-31.  

Gameduino is little-endian, so a color stored in two bytes starting at address is:

\vspace{12 pt}

\newcommand{\subscript}[1]{\ensuremath{_{\textsf{#1}}}}
\newcommand{\0}[0]{\subscript{0}}
\newcommand{\1}[0]{\subscript{1}}
\newcommand{\2}[0]{\subscript{2}}
\newcommand{\3}[0]{\subscript{3}}
\newcommand{\4}[0]{\subscript{4}}

\begin{bytefield}{8}
\bitheader[b]{0-7} \\
\wordgroupl{address}
\bitbox[ltb]{1}{G\2} & \bitbox[tb]{1}{G\1} & \bitbox[tbr]{1}{G\0} & \bitbox[ltb]{1}{B\4} & \bitbox[tb]{1}{B\3} & \bitbox[tb]{1}{B\2} & \bitbox[tb]{1}{B\1} & \bitbox[rtb]{1}{B\0}
\endwordgroupl \\
\wordgroupl{address+1}
\bitbox{1}{A} & \bitbox[ltb]{1}{R\4} & \bitbox[tb]{1}{R\3} & \bitbox[tb]{1}{R\2} & \bitbox[tb]{1}{R\1} & \bitbox[tbr]{1}{R\0} & \bitbox[ltb]{1}{G\4} & \bitbox[rtb]{1}{G\3}
\endwordgroupl \\
\end{bytefield}

The \textbf{A} bit controls transparency.  When \textbf{A=1}
the pixel is transparent and the other fields are ignored.

For sprites, transparent pixels show through the background layer.
For the background layer, transparent pixels show BG\_COLOR.

\sample{bgcolor}

\end{framed}
\end{document}
