Skip to content

Tool Reference

Lucas Scharenbroich edited this page Jun 7, 2022 · 4 revisions

GTE Tool Set Routines

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 described 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).

Table 1
GTE Tool Set routines and their functions
Routine Description
Housekeeping Routines
GTEBootInit Initializes the GTE Tool Set; called only by the Tool Locator — must not be called by an application
GTEStartUp Starts up the GTE Tool Set for use by an application
GTEShutDown Shuts down the GTE Tool Set when an application quits
GTEVersion Returns the version number of the GTE Tool Set
GTEReset Resets the GTE Tool Set; called only when the system is reset — must not be called by an application
GTEStatus Indicates whether the GTE Tool Set is active
Sprite Routines
GTECreateSpriteStamp Creates a sprite stamp from the tile set
GTEAddSprite Add a active sprite to the scene
GTEMoveSprite Changes a sprite's location
GTEUpdateSprite Changes a sprite's tile set
GTERemoveSprite Removes a sprite from the scene
Tile Routines
GTELoadTileSet Copies a tileset into the GTE tileset memory
GTESetTile Assigns a tile to a tile map index
Primary Background Routines
GTESetBG0Origin Sets the upper-left origin point in the primary background
GTERender Draws the current scene to the graphics screen
Functions affecting the global state
GTESetScreenMode Sets the playing field's port rectangle to a pre-defined size, or a specified width and height
Misc. Functions
GTEReadControl Reads the keyboard and returns key events in a gamepad structure
GTEGetSeconds Returns the number of seconds elapsed since the toolset was started

GTEStartUp(Word dPageAddr, Word capFlags, Word userId)

Starts up the engine and allocates and initialized any memory needed based of the specified capabilities.

  • dPageAddr: 16-bit address of two pages of page-aligned Bank 0 memory
  • capFlags: Capability flags to set the engine mode
  • userId: Application word returned by the Memory Manager. All memory allocated by GTE will use this userId
capFlags
ENGINE_MODE_TWO_LAYER $0001 Enables the second background layer. This will have a moderate impact on rendering performance.
ENGINE_MODE_DYN_TILES $0002 Enables the use of dynamic (animated) tiles. This will have a small impact on performance and requires allocating 8 pages of Bank 0 memory
ENGINE_MODE_BNK0_BUFF $0004 Allocates a 32KB buffer in Bank 0 for advanced graphical effects and customizations.

GTEShutDown(void)

Shuts down the engine. No arguments.

GTECreateSpriteStamp(Word spriteDescriptor, Word vBuffAddr)

Pre-renders a sprite into the virtual sprite buffer. This must be done prior to calling GTEAddSprite since that function takes a vbuffAddr.

The spriteDescritor word has the following structure

Bits
0 - 8 Holds a TileId that corresponds to the top-left corner of the sprite
9 Horizontal flip. Ignored for creating the stamp. Used in GTEUpdateSprite
10 Vertical flip. Ignored for creating the stamp. Used in GTEUpdateSprite
11 - 12 Sprite Size Selector
00 - 8x8 (1x1 tile)
01 - 8x16 (1x2 tiles)
10 - 16x8 (2x1 tiles)
11 - 16x16 (2x2 tiles)
13 - 15 Reserved. Must be zero

The cbuffAddr is an address in the virtual sprite buffer. This memory is structured and will be fully documented at a later date. For now, user are encouraged to use the VBUFF_* definitions to calculate an address for each sprite, e.g. slot_n = VBUFF_SPRITE_START + n * VBUFF_SPRITE_STEP.

GTEAddSprite(Word spriteDescriptor, Word xPos, Word yPos, Word spriteSlot)

Add a sprite to the scene at a specific position in the designated sprite slot.

  • spriteDescriptor: Defined above. Only the Horizontal and Vertical bits are evaluated.
  • xPos: Initial on-screen position. Only unsigned values from 0 to 255 are allows.
  • yPos: Initial on-screen position. Only unsigned values from 0 to 255 are allows.
  • spritesSlot: Which sprite slot to use. Valid values of 0 to 15. Sprites in a lower sprite slot are drawn on top of higher sprite slot numbers.

GTEMoveSprite(Word spriteSlot, Word xPos, Word yPos)

Set the position of a sprite. Unlike GTEAddSprite, the xPos and yPos values are signed and not limited to values <256.

GTEUpdateSprite(Word spriteSlot, Word spriteFlags, Word vbuffAddr)

Set the attributes of a sprite. The horizontal and vertical bits of the sprite flag can be changes. This function can also repoint the sprite to a different vBuff address to provide a different frame of animation for the sprite.

GTERemoveSprite(Word spriteSlot)

Removes a sprite from the scene.

GTELoadTileSet(Pointer tileSetPtr)

Copies a tile set from the pointer into GTE internal memory. A tileset is a 64kb block of memory with each tile taking up 128 bytes. The first 128 bytes must be set to zero. Afterward, each 128-byte tile record is comprised of 4 32-byte 8x8 tile records.

  • +0 : 8x8 tile
  • +32: 8x8 tile mask
  • +64: 8x8 tile, horizontally flipped
  • +96: 8x8 tile mask, horizontally flipped

GTESetTile(Word tileId, Word x, Word y)

Sets a tile in the backing Tile Store. The tileId is defined below. The range of x is [0, 40] and y is [0, 25].

 Bit  15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
     |xx|xx|FF|MM|DD|VV|HH|  |  |  |  |  |  |  |  |  |
     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
      \____/ |  |  |  |  | \________________________/
        |    |  |  |  |  |      Tile ID (0 to 511)
        |    |  |  |  |  |
        |    |  |  |  |  +-- H : Flip tile horizontally
        |    |  |  |  +----- V : Flip tile vertically
        |    |  |  +-------- D : Render as a Dynamic Tile (Tile ID < 32, V and H have no effect)
        |    |  +----------- M : Apply tile mask
        |    +-------------- F : Overlay a fringe tile
        +------------------- Reserved (must be zero)

GTESetBG0Origin(Word x, Word y)

Sets the origin of the background. Any unsigned values are allowed.

GTERender()

Render the current scene to the screen.