Ophis/book/c259.html
2012-06-16 02:07:47 -07:00

251 lines
4.4 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Headers, Libraries, and Macros</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="Programming with Ophis"
HREF="book1.html"><LINK
REL="UP"
TITLE="Using the Ophis Assembler"
HREF="p50.html"><LINK
REL="PREVIOUS"
TITLE="Aliasing"
HREF="x248.html"><LINK
REL="NEXT"
TITLE="Macros"
HREF="x284.html"></HEAD
><BODY
CLASS="CHAPTER"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Programming with Ophis</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x248.html"
ACCESSKEY="P"
>&#60;&#60;&#60; Previous</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x284.html"
ACCESSKEY="N"
>Next &#62;&#62;&#62;</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="CH3-LINK"
></A
>Headers, Libraries, and Macros</H1
><P
> In this chapter we will split away parts of our <SPAN
CLASS="QUOTE"
>"Hello
World"</SPAN
> program into reusable header files and libraries.
We will also abstract away our string printing technique into a
macro which may be invoked at will, on arbitrary strings. We will
then multiply the output of our program tenfold.
</P
><DIV
CLASS="SECTION"
><H1
CLASS="SECTION"
><A
NAME="AEN263"
>Header files and libraries</A
></H1
><P
> The prelude to our program&#8212;the <TT
CLASS="FILENAME"
>PRG</TT
>
information and the BASIC program&#8212;are going to be the same
in many, many programs. Thus, we should put them into a header
file to be included later. The <TT
CLASS="LITERAL"
>.include</TT
>
directive will load a file and insert it as source at the
designated point.
</P
><P
> A related directive, <TT
CLASS="LITERAL"
>.require</TT
>, will include
the file as long as it hasn't been included yet elsewhere. It
is useful for ensuring a library is linked in.
</P
><P
> For pre-assembled code or raw binary data,
the <TT
CLASS="LITERAL"
>.incbin</TT
> directive lets you include the
contents of a binary file directly in the output. This is handy
for linking in pre-created graphics or sound data.
</P
><P
> If you only wish to include part of a binary
file, <TT
CLASS="LITERAL"
>.incbin</TT
> takes up to two optional
arguments, naming the file offset at which to start reading and
the number of characters to read.
</P
><P
> As a sample library, we will expand the definition of
the <TT
CLASS="LITERAL"
>chrout</TT
> routine to include the standard
names for every KERNAL routine. Our header file will
then <TT
CLASS="LITERAL"
>.require</TT
> it.
</P
><P
> We'll also add some convenience aliases for things like reverse
video, color changes, and shifting between upper case/graphics
and mixed case text. We'd feed those to
the <TT
CLASS="LITERAL"
>chrout</TT
> routine to get their effects.
</P
><P
> Since there have been no interesting changes to the prelude, and
the KERNAL values are standard, we do not reproduce them here.
(The files in question are <A
HREF="x986.html"
><I
><I
>c64-1.oph</I
></I
></A
> and <A
HREF="x990.html"
><I
><I
>c64kernal.oph</I
></I
></A
>.) The <TT
CLASS="FILENAME"
>c64kernal.oph</TT
>
header is likely to be useful in your own projects, and it is
available in the <TT
CLASS="LITERAL"
>platform/</TT
> directory for easy
inclusion.
</P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x248.html"
ACCESSKEY="P"
>&#60;&#60;&#60; Previous</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="book1.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x284.html"
ACCESSKEY="N"
>Next &#62;&#62;&#62;</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Aliasing</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="p50.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Macros</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>