Assembly Language Fundamentals

Intermediate
Version:
4.0

Sprite Drawing

Introduction

Sprites are among the most powerful features of the Tatung Einstein’s graphics system. They are small, independently controlled graphic objects that the Video Display Processor (VDP) can draw over the background automatically and continuously, without any help from your program once defined.

Instead of plotting pixels manually every time an object moves, you define two things in memory:

Once written to video RAM (VRAM), the VDP reads this data every frame and redraws the sprite automatically. You never need to refresh it manually.

Sprites are essential for animated game displays. They can move horizontally, vertically, or diagonally and are entirely independent of the background graphics. Each sprite can be drawn in any of the 15 available colours plus transparency. Multi-coloured effects can be achieved by overlaying multiple sprites, but since the VDP can only display four sprites per scanline, exceeding that may cause the so-called “fifth sprite syndrome”, where overlapping sprites become invisible or cause unpredictable results.

How Sprites Work

Sprites use two key memory regions in VRAM:

TablePurposeStart AddressSprite Generator TableStores the shape of each sprite (8 bytes per pattern)6144Sprite Attribute TableStores position, colour, and pattern link (4 bytes per sprite)15104

Each sprite’s attribute block consists of four bytes:

Each pattern is 8 bytes, one per row of pixels. A bit set to 1 lights a pixel, while 0 leaves it blank.

Examples:
%11111111 lights all eight pixels in a row.
%10000001 lights only the leftmost and rightmost pixels.

These eight bytes together form a complete 8×8 shape.

Important Sprite Concepts

Before coding, keep these key facts in mind about sprites on the TMS9129 VDP (the Einstein’s video processor):

The Early Clock Bit

The most significant bit (bit 7) of the sprite’s colour byte is known as the Early Clock Bit.

This is useful for smooth horizontal scrolling and off-screen animation entry or exit.

If the bit is set and the X-coordinate is between 0 and 31, the sprite is partially or fully off-screen to the left. This bit must be reset before moving the sprite fully back onto the display area.

Sprite Priority and Overlap

Each sprite has a hardware priority index, assigned automatically by the VDP according to its order in the Sprite Attribute Table:

Thus, sprites with lower numbers always appear in front of those with higher numbers when they overlap.

Defining the Sprite Pattern

This program draws a white smiley face near the centre of the screen. All numbers are in decimal for clarity.

ORG 256

      ; -----------------------
      ; Enable Graphics Mode II
      ; ----------------------

       ; Set Register 0 values

       LD   A,2
       OUT  (9),A
       LD   A,128
       OUT  (9),A

       ; Set Register 1 values

       LD   A,224
       OUT  (9),A
       LD   A,129
       OUT  (9),A

      ; ---------------------------
      ; Set Foreground / Background
      ; ---------------------------

      LD   A,240        ; 11110000 (white foreground, black background)
      OUT  (9),A
      LD   A,135        ; 128 (bit 7 set) + 7 (register 7)
      OUT  (9),A

      ; -----------------
      ; Write Blank Tiles
      ; -----------------

      ; Top Third Blank Tile

      LD   A,0
      OUT  (9),A
      LD   A,64
      OUT  (9),A

      LD A,0
      OUT (8),A
      OUT (8),A
      OUT (8),A
      OUT (8),A
      OUT (8),A
      OUT (8),A
      OUT (8),A
      OUT (8),A

      ; Middle Third Blank Tile

      LD   A,0
      OUT  (9),A
      LD   A,72
      OUT  (9),A

      LD A,0
      OUT (8),A
      OUT (8),A
      OUT (8),A
      OUT (8),A
      OUT (8),A
      OUT (8),A
      OUT (8),A
      OUT (8),A

      ; Bottom Third Blank Tile

      LD   A,0
      OUT  (9),A
      LD   A,80
      OUT  (9),A

      LD A,0
      OUT (8),A
      OUT (8),A
      OUT (8),A
      OUT (8),A
      OUT (8),A
      OUT (8),A
      OUT (8),A
      OUT (8),A


      ; --------------------------------
      ; Clear Name Table with Blank Tile
      ; --------------------------------

      LD A,0
      OUT (9),A
      LD A,120
      OUT (9),A

      LD BC,768

ClearLoop:
      LD A,0
      OUT (8),A
      DEC BC
      LD A,B
      OR C
      JR NZ,ClearLoop


       ; ---------------------
       ; Define Sprite Pattern
       ; ---------------------

       ; Smiley Face Pattern

       LD A,0
       OUT (9),A
       LD A,88
       OUT (9),A

       LD A,%00111100 : OUT (8),A
       LD A,%01000010 : OUT (8),A
       LD A,%10100101 : OUT (8),A
       LD A,%10000001 : OUT (8),A
       LD A,%10100101 : OUT (8),A
       LD A,%10011001 : OUT (8),A
       LD A,%01000010 : OUT (8),A
       LD A,%00111100 : OUT (8),A

       ; ------------------------
       ; Define Sprite Attributes
       ; ------------------------

       ; Smiley Face Attributes

       LD A,0
       OUT (9),A
       LD A,123
       OUT (9),A

       ; Sprite 0

       LD A,100
       OUT (8),A
       LD A,120
       OUT (8),A
       LD A,0
       OUT (8),A
       LD A,15
       OUT (8),A

       JP $            ; Loop indefinitely

Result

When run, this program produces:

Try adjusting the X and Y values in the attribute section to reposition the sprite, or define an additional pattern and attribute block to create a second sprite.

Sprite Animation

Animation is achieved by changing the pattern number in the sprite’s attribute table to cycle through a sequence of stored patterns. According to The Source (page 6), smooth animation relies heavily on timing — if pattern changes occur too quickly or inconsistently, motion will appear jerky.

For example, by maintaining a timing loop or using interrupts, you can display pattern 0, then 1, 2, 3, before looping back. Adjusting the loop delay creates faster or slower animation effects.

Summary

Previous Module
Next Module