The <em>Generic Tile Engine (GTE)</em> Tool Set enables tile-based games to be implemented in an efficient manner. The tool set provides support for sprites, animations, large scrolling backgrounds and special effects.
</p>
<p>
To effectively use this tool set, a user should be familiar with the following
</p><ul>
<li>The IIgs Hardware Reference</li>
<li>The QuickDraw II tool set</li>
<li>IIgs Technical Note #70</li>
</ul>
<p></p>
<h2>A preview of the GTE Tool Set routines</h2>
<p>
To introduce you to the capabilities of the GTE Tool Set the routines are grouped by function and briefly described in Table 1. These routines are descibed in detail later where they are separated into housekeeping routines (discussed in routine number order) and the rest of the GTE Tool Set routines (discussed in alphabetical order).
</p>
<tableclass="intro">
<tbody>
<tr>
<thcolspan="2">Table 1</th>
</tr>
<tr>
<thcolspan="2"style="font-weight: normal;">GTE Tool Set routines and their functions</th>
</tr>
<trclass="intro_header">
<th>Routine</th>
<th>Description</th>
</tr>
<tr>
<thcolspan="2">Housekeeping Routines</th>
</tr>
<tr><td>GTEBootInit</td><td>Initializes the GTE Tool Set; called only by the Tool Locator — must not be called by an application</td></tr>
<tr><td>GTEStartUp</td><td>Starts up the GTE Tool Set for use by an application</td></tr>
<tr><td>GTEShutDown</td><td>Shuts down the GTE Tool Set when an application quits</td></tr>
<tr><td>GTEVersion</td><td>Returns the version number of the GTE Tool Set</td></tr>
<tr><td>GTEReset</td><td>Resets the GTE Tool Set; called only when the system is reset — must not be called by an application</td></tr>
<tr><td>GTEStatus</td><td>Indicates whether the GTE Tool Set is active</td></tr>
<tr><td>GTESetTile</td><td>Assigns a tile to a tile store</td></tr>
<tr><td>GTEGetTileAt</td><td>Retrieves the tile ID stored in the tile store</td></tr>
<tr><td>GTECopyTileToDynamic</td><td>Copies a tile from the tileset memory into the managed dynamic tile memory. Changing the dynamic tile data will result in all of the tiles updating
on the next call the <tt>GTERender()</tt></td></tr>
<tr><td>GTEGetTileDataAddr</td><td>Returns the base address of the tiledata memory</td></tr>
<tr><td>GTEFillTileStore</td><td>Fills the entire tile store with a tile ID.</td></tr>
<tr><td>GTEGetBG0TileMapInfo</td><td>Returns a record describing the number of tiles in the primary tilemap and a pointer to the tilemap data.</td></tr>
<tr><td>GTESetBG0TileMapInfo</td><td>Defines a tile map for the primary background</td></tr>
<tr><td>GTERefresh</td><td>Forces all of the tiles in the tile store to be refreshed on the next render.</td></tr>
<tr><td>GTEReadControl</td><td>Reads the keyboard and returns key events in a gamepad structure</td></tr>
<tr><td>GTEGetSeconds</td><td>Returns the number of seconds elapsed since the toolset was started</td></tr>
</tbody></table>
<h2>Using the GTE Tool Set</h2>
<p>
This section discusses how the GTE Tool Set routines fit into the general flow of an application and gives you an idea of which routines you'll need to use under normal circumstances. Each routine is described in detail later in this chapter.
The GTE Tool Set depends on the presence of the tool sets shown in Table 2 and requires at least the indicated version of each tool set be present.
</p>
<tableclass="intro">
<tbody><tr><thcolspan="4">Table 2</th></tr>
<tr><thcolspan="4"style="font-weight: normal;">GTE Tool Set — other tool sets required</th></tr>
<trclass="intro_header"><thcolspan="2">Tool set number</th><th>Tool set name</th><th>Minimal version needed</th></tr>
To use the GTE Tool Set routines, your application must call the GTEStartUp routine before making any other GTE calls. To save memory, the GTE Tool Set may be started up with some features disabled. See the section <ahref="#GTEStartUp">GTEStartUp</a> in this chapter for further details.
</p>
<p>
Your application should also make the GTEShutDown call when the application quits.
</p>
</div>
<divclass="api">
<h4class="tn">$01XX</h4>
<h4>GTEBootInit</h4>
<p>
Initializes the GTE Tool Set; called only by the Tool Locator.
</p>
<divclass="warning">
<p>
An application must never make this call
</p>
</div>
<divclass="section">
<h5>Parameters</h5>
<p>
The stack is not affected by this call. There are no input or output parameters.
</p>
</div>
<divclass="section">
<h5>Errors</h5>
<p>None</p>
</div>
<divclass="section">
<h5>C</h5>
<p>Call must not be made by an application.</p>
</div>
</div>
<divclass="api">
<h4class="tn">$02XX</h4>
<h4>GTEStartUp</h4>
<p>
Starts up the GTE Tool Set for use by an application.
</p>
<divclass="important">
<p>
Your application must make this call before it makes any other GTE Tool Set calls.
</p>
</div>
<p>
The GTE Tool Set uses two consecutive pages of bank zero for its direct page space starting at <it>dPageAddr</it>. If the <tt>ENGINE_MODE_DYN_TILES</tt> flag is set in the <it>capFlags</it>, the GTE will attempt to allocate an <em>additional</em> eight pages of bank zero space. If the <tt>ENGINE_MODE_BNK0_BUFF</tt> flag is set, then GTE will attempt to allocate an ~32KB buffer from $2000 to $9CFF in Bank 0.
</p>
<divclass="section">
<h5>Parameters</h5>
<tableclass="stack">
<colgroup>
<col>
<colstyle="width: 2em">
</colgroup>
<tbody><tr><th>Stack before call</th></tr>
<tr><tdclass="top">previous contents</td></tr>
<tr><tdclass="bot">dPageAddr</td><td></td><td><em>Word</em></td><td>16-bit address of two pages of page-aligned Bank 0 memory</td></tr>
<tr><tdclass="bot">capFlags</td><td></td><td><em>Word</em></td><td>Capability flags to set the engine mode</td></tr>
<tr><tdclass="bot">userID</td><td></td><td><em>Word</em></td><td>Application word returned by the Memory Manager. All memory allocated by GTE will use this userId</td></tr>
<tbody><tr><td>$XX04</td><td>gteBadAddress</td><td>The id is invalid</td></tr>
</tbody></table>
</div>
<divclass="section">
<h5>C</h5>
<pre>extern pascal Pointer GTEGetAddress(id)
Word id
</pre>
</div>
</div>
<divclass="api">
<h4class="tn">$0CXX</h4>
<h4>GTENewSprite</h4>
<p>
Allocates space for a new sprite and compiles it based on the pixel data in the locInfoPtr arguement. The sprite flags word is used to enable or disable certain capabilities. If an application does not need the all the features enabled, features may be disabled to save memory and slightly increase performance.
</p>
<!--
<p>
The general structure of a compiled sprite is shown in Listing ??. There is a small header followed by a up to four jump tables.
</p>
<pre>
return JML rtn_from_sprite
remove JML remove_sprite
header TAX
JMP (disp,x)
guard0 dc a2'remove'
right0 dc a2'rline00'
dc a2'rline01'
.
.
dc a2'rline0N'
guard1 dc a2'remove'
left0 dc a2'lline00'
dc a2'lline01'
.
.
dc a2'lline0N'
guard2 dc a2'remove'
right1 dc a2'rline10'
dc a2'rline11'
.
.
dc a2'rline1N'
guard3 dc a2'remove'
left1 dc a2'lline10'
dc a2'lline11'
.
.
dc a2'lline1N'
guard4 dc a2'remove'
rline00 brl return
rline01 brl return
.
.
rline0N brl return
</pre>
-->
<divclass="section">
<h5>Parameters</h5>
<tableclass="stack">
<tbody><tr><th>Stack before call</th></tr>
<tr><tdclass="top">previous contents</td></tr>
<tr><tdclass="bot">ptrToDataLocInfo</td><td></td><td><em>Long</em> — POINTER to data location information.</td></tr>
<tr><tdclass="bot">ptrToDataRect</td><td></td><td><em>Long</em> — POINTER to a Rect that defines the sprite bounds.</td></tr>
<tr><tdclass="bot">ptrToMaskLocInfo</td><td></td><td><em>Long</em> — POINTER to mask location information; may be nil.</td></tr>
<tr><tdclass="bot">ptrToMaskRect</td><td></td><td><em>Long</em> — POINTER to a Rect that defines the sprite bounds; may be nil.</td></tr>
<tr><td>Bits 0</td><td><em>spriteType</em></td><td>Reserved; must be zero</td></tr>
<tr><td>Bit 1</td><td>fNoHFlip</td><td>Do not create a horizontally flipped version of the sprite. Setting the horizontal flip bit in the Object Attribute Memory will have no effect.</td></tr>
<tr><td>Bit 2</td><td>fNoVFlip</td><td>Do not create a vertically flipped version of the sprite. Setting the vertical flip bit in the Object Attribute Memory will have no effect.</td></tr>
<tr><td>Bit 3</td><td><em>fNoPriority</em></td><td>Do not generate code to honor the field mask. Seting the priority bit in the Object Attribute Memory will have no effect.</td></tr>
<tr><td>Bit 4</td><td><em>fNoMask</em></td><td> This sprite will not clip itself to the playing fields. This is potentially dangerous since, if the sprite move off screen, it may corrupt system memory. Only use this bit if the sprite will never leave the playing field.</td></tr>
<tr><td>Bits 5-15</td><td>Reserved</td><td>must be zero.</td></tr>
</tbody></table>
</div>
<divclass="api">
<h4class="tn">$0DXX</h4>
<h4>GTEDisposeSprite</h4>
<divclass="section">
<h5>Parameters</h5>
<tableclass="stack">
<tbody><tr><th>Stack before call</th></tr>
<tr><tdclass="top">previous contents</td></tr>
<tr><tdclass="bot">spriteHandle</td><td></td><td><em>Long</em> — Handle to a sprite returned by GTENewSprite.</td></tr>
Allocates space for a new tile and compiles it based on the pixel data referenced by the locInfoPtr arguements. If the mask infoRecPtr is nil, then the mask is computed using the current backgound color. The mask is only used when the tile map specifies the tile to be drawn at high priority.
</p>
<divclass="section">
<h5>Parameters</h5>
<tableclass="stack">
<tbody><tr><th>Stack before call</th></tr>
<tr><tdclass="top">previous contents</td></tr>
<tr><tdclass="bot">ptrToDataLocInfo</td><td></td><td><em>Long</em> — POINTER to data location information.</td></tr>
<tr><tdclass="bot">ptrToDataOrigin</td><td></td><td><em>Long</em> — POINTER to Point that marks the top-left corner.</td></tr>
<tr><tdclass="bot">ptrToMaskLocInfo</td><td></td><td><em>Long</em> — POINTER to mask location information; may be nil.</td></tr>
<tr><tdclass="bot">ptrToMaskOrigin</td><td></td><td><em>Long</em> — POINTER to Point that marks the top-left corner; may be nil.</td></tr>
<tr><tdclass="bot">longspace</td><td></td><td><em>Long</em> — Space for result</td></tr>