Playstation TMD: Difference between revisions

From XentaxWiki
Jump to navigation Jump to search
imported>Rickomax
(This is the COMPLETE file format used at many Playstaion 1 (PSX) games)
imported>Rickomax
(This is the COMPLETE Playstation 1 (PSX) 3D model file format used in many games)
Line 1: Line 1:
'TMD FILE FORMAT
TMD FILE FORMAT
'
 
'HEADER                      - One per TMD
HEADER                      - One per TMD
{
  {
u_long  id;              - version of TMD. Always 0x00000041
  u_long  id;              - version of TMD. Always 0x00000041
u_long  flags;            - Indicates when addresses are relative or explicit
  u_long  flags;            - Indicates when addresses are relative or explicit
u_long  nobj;            - number of objects in the TMD
  u_long  nobj;            - number of objects in the TMD
} HEADER;
  } HEADER;
'
 
'OBJECT LIST                - One per object in the TMD
OBJECT LIST                - One per object in the TMD
{
  {
u_long  *vert_top;        - start address of vertex list
  u_long  *vert_top;        - start address of vertex list
u_long  n_vert;          - number of vertices in the object
  u_long  n_vert;          - number of vertices in the object
u_long  *normal_top;      - start address of normal list
  u_long  *normal_top;      - start address of normal list
u_long  n_normal;        - number of normals in the object
  u_long  n_normal;        - number of normals in the object
u_long  *primitive_top;  - start address of primitive list
  u_long  *primitive_top;  - start address of primitive list
u_long  n_primitive;      - number of primitives in the object
  u_long  n_primitive;      - number of primitives in the object
long  scale;              - ignored
  long  scale;              - ignored
} OBJECT;
  } OBJECT;
'
 
'PRIMITIVE LIST              - One per primitive per object in the TMD
PRIMITIVE LIST              - One per primitive per object in the TMD
{
  {
u_char  olen;            - word length of the drawing primitive created by GPU
  u_char  olen;            - word length of the drawing primitive created by GPU
u_char  ilen;            - word length of the packet data section
  u_char  ilen;            - word length of the packet data section
u_char  flag;            - options when rendering
  u_char  flag;            - options when rendering
u_char  mode;            - indicates type of primitive
  u_char  mode;            - indicates type of primitive
} PRIMITIVE_HEADER;
  } PRIMITIVE_HEADER;
'
 
??      PACKET;          - variable in length and content (see later for list)
  ??      PACKET;          - variable in length and content (see later for list)
'
 
'VERTEX LIST                - One per vertex per object in the TMD
VERTEX LIST                - One per vertex per object in the TMD
{
  {
short vx;                - X value of vertex
  short vx;                - X value of vertex
short vy;                - Y value of vertex
  short vy;                - Y value of vertex
short vz;                - Z value of vertex
  short vz;                - Z value of vertex
short pad;                - ignored
  short pad;                - ignored
}  VERTEX;
  }  VERTEX;
'
 
'NORMAL LIST                - One per normal per object in the TMD
NORMAL LIST                - One per normal per object in the TMD
{
  {
short nx;                - X value of normal
  short nx;                - X value of normal
short ny;                - Y value of normal
  short ny;                - Y value of normal
short nz;                - Z value of normal
  short nz;                - Z value of normal
short pad;                - ignored
  short pad;                - ignored
}  NORMAL;
  }  NORMAL;
'
 
'PACKET LIST FORMAT
PACKET LIST FORMAT
'
 
'
 
'Note
Note
'When mode and flag are set with the values shown here, they default
When mode and flag are set with the values shown here, they default
'to creating a one-sided primitive that will be rendered with no
to creating a one-sided primitive that will be rendered with no
'semitransparency. To alter these, see earlier notes.
semitransparency. To alter these, see earlier notes.
'Pigment refers to the inherent colour of the primitive, before
Pigment refers to the inherent colour of the primitive, before
'lightsources alter the appearance on screen. A gradient pigment has
lightsources alter the appearance on screen. A gradient pigment has
'a different RGB value at each vertex, and by using the same
a different RGB value at each vertex, and by using the same
'interpolation algorithm that gouraud shading uses, a smooth
interpolation algorithm that gouraud shading uses, a smooth
'transition between colours is achieved.
transition between colours is achieved.
'
 
'LIST OF PRIMITIVES INCLUDED SO FAR
LIST OF PRIMITIVES INCLUDED SO FAR
'3 SIDED, FLAT SHADING, FLAT PIGMENT
3 SIDED, FLAT SHADING, FLAT PIGMENT
'3 SIDED, GOURAUD SHADING, FLAT PIGMENT
3 SIDED, GOURAUD SHADING, FLAT PIGMENT
'3 SIDED, FLAT SHADING, GRADIENT PIGMENT
3 SIDED, FLAT SHADING, GRADIENT PIGMENT
'3 SIDED, GOURAUD SHADING, GRADIENT PIGMENT
3 SIDED, GOURAUD SHADING, GRADIENT PIGMENT
'3 SIDED, TEXTURED, FLAT SHADING, NO PIGMENT
3 SIDED, TEXTURED, FLAT SHADING, NO PIGMENT
'3 SIDED, TEXTURED, GOURAUD SHADING, NO PIGMENT
3 SIDED, TEXTURED, GOURAUD SHADING, NO PIGMENT
'3 SIDED, NO SHADING, FLAT PIGMENT
3 SIDED, NO SHADING, FLAT PIGMENT
'3 SIDED, NO SHADING, GRADIENT PIGMENT
3 SIDED, NO SHADING, GRADIENT PIGMENT
'3 SIDED, TEXTURED, NO SHADING, FLAT PIGMENT
3 SIDED, TEXTURED, NO SHADING, FLAT PIGMENT
'3 SIDED, TEXTURED, NO SHADING, GRADIENT PIGMENT
3 SIDED, TEXTURED, NO SHADING, GRADIENT PIGMENT
'
 
'3 SIDED, FLAT SHADING, FLAT PIGMENT
3 SIDED, FLAT SHADING, FLAT PIGMENT
olen = 0x04;  ilen =0x03;  flag =0x00;    mode =0x20;
  olen = 0x04;  ilen =0x03;  flag =0x00;    mode =0x20;
{
  {
u_char  R, G, B;        - pigment of polygon
  u_char  R, G, B;        - pigment of polygon
u_char  mode2;          - same as mode (above)
  u_char  mode2;          - same as mode (above)
u_short Normal0;        - index value of normal element
  u_short Normal0;        - index value of normal element
u_short Vertex0;        - index value of vertex element
  u_short Vertex0;        - index value of vertex element
u_short Vertex1;
  u_short Vertex1;
u_short Vertex2;
  u_short Vertex2;
} TMD_3_FS_FP;
  } TMD_3_FS_FP;
'
 
'3 SIDED, GOURAUD SHADING, FLAT PIGMENT
3 SIDED, GOURAUD SHADING, FLAT PIGMENT
olen = 0x06;  ilen =0x04;  flag =0x00;    mode =0x30;
  olen = 0x06;  ilen =0x04;  flag =0x00;    mode =0x30;
{
  {
u_char  R, G, B;        - pigment of polygon
  u_char  R, G, B;        - pigment of polygon
u_char  mode2;          - same as mode (above)
  u_char  mode2;          - same as mode (above)
u_short Normal0;        - index value of normal element
  u_short Normal0;        - index value of normal element
u_short Vertex0;        - index value of vertex element
  u_short Vertex0;        - index value of vertex element
u_short Normal1;
  u_short Normal1;
u_short Vertex1;
  u_short Vertex1;
u_short Normal2;
  u_short Normal2;
u_short Vertex2;
  u_short Vertex2;
} TMD_3_GS_FP;
  } TMD_3_GS_FP;
'
 
'3 SIDED, FLAT SHADING, GRADIENT PIGMENT
3 SIDED, FLAT SHADING, GRADIENT PIGMENT
olen = 0x06;  ilen =0x05;  flag =0x04;    mode =0x20;
  olen = 0x06;  ilen =0x05;  flag =0x04;    mode =0x20;
{
  {
u_char  R0, G0, B0;    - pigment of polygon at Vertex0
  u_char  R0, G0, B0;    - pigment of polygon at Vertex0
u_char  mode2;          - same as mode (above)
  u_char  mode2;          - same as mode (above)
u_char  R1, G1, B1;    - pigment of polygon at Vertex1
  u_char  R1, G1, B1;    - pigment of polygon at Vertex1
u_char  pad1;          - ignored
  u_char  pad1;          - ignored
u_char  R2, G2, B2;    - pigment of polygon at Vertex2
  u_char  R2, G2, B2;    - pigment of polygon at Vertex2
u_char  pad2;          - ignored
  u_char  pad2;          - ignored
u_short Normal0;        - index value of normal element
  u_short Normal0;        - index value of normal element
u_short Vertex0;        - index value of vertex element
  u_short Vertex0;        - index value of vertex element
u_short Vertex1;
  u_short Vertex1;
u_short Vertex2;
  u_short Vertex2;
} TMD_3_FS_GP;
  } TMD_3_FS_GP;
'
 
'3 SIDED, GOURAUD SHADING, GRADIENT PIGMENT
3 SIDED, GOURAUD SHADING, GRADIENT PIGMENT
olen = 0x06;  ilen =0x06;  flag =0x04;    mode =0x30;
  olen = 0x06;  ilen =0x06;  flag =0x04;    mode =0x30;
{
  {
u_char  R0, G0, B0;    - pigment of polygon at Vertex0
  u_char  R0, G0, B0;    - pigment of polygon at Vertex0
u_char  mode2;          - same as mode (above)
  u_char  mode2;          - same as mode (above)
u_char  R1, G1, B1;    - pigment of polygon at Vertex1
  u_char  R1, G1, B1;    - pigment of polygon at Vertex1
u_char  pad1;          - ignored
  u_char  pad1;          - ignored
u_char  R2, G2, B2;    - pigment of polygon at Vertex2
  u_char  R2, G2, B2;    - pigment of polygon at Vertex2
u_char  pad2;          - ignored
  u_char  pad2;          - ignored
u_short Normal0;        - index value of normal element
  u_short Normal0;        - index value of normal element
u_short Vertex0;        - index value of vertex element
  u_short Vertex0;        - index value of vertex element
u_short Normal1;
  u_short Normal1;
u_short Vertex1;
  u_short Vertex1;
u_short Normal2;
  u_short Normal2;
u_short Vertex2;
  u_short Vertex2;
} TMD_3_GS_GP;
  } TMD_3_GS_GP;
'
 
'3 SIDED, TEXTURED, FLAT SHADING, NO PIGMENT
3 SIDED, TEXTURED, FLAT SHADING, NO PIGMENT
olen = 0x07;  ilen =0x05;  flag =0x00;    mode =0x24;
  olen = 0x07;  ilen =0x05;  flag =0x00;    mode =0x24;
{
  {
u_char  U0, V0;        - X and Y coordinate of texture for Vertex0
  u_char  U0, V0;        - X and Y coordinate of texture for Vertex0
u_short CBA;            - position of CLUT for texture in VRAM (see earlier)
  u_short CBA;            - position of CLUT for texture in VRAM (see earlier)
u_char  U1, V1;        - X and Y coordinate of texture for Vertex1
  u_char  U1, V1;        - X and Y coordinate of texture for Vertex1
u_short TSB;            - information about texture in VRAM (see earlier)
  u_short TSB;            - information about texture in VRAM (see earlier)
u_char  U2, V2;        - X and Y coordinate of texture for Vertex2
  u_char  U2, V2;        - X and Y coordinate of texture for Vertex2
u_short pad;            - ignored
  u_short pad;            - ignored
u_short Normal;        - index value of normal element
  u_short Normal;        - index value of normal element
u_short Vertex0;        - index value of vertex element
  u_short Vertex0;        - index value of vertex element
u_short Vertex1;
  u_short Vertex1;
u_short Vertex2;
  u_short Vertex2;
} TMD_3_TX_FS_NP;
  } TMD_3_TX_FS_NP;
'
 
'3 SIDED, TEXTURED, GOURAUD SHADING, NO PIGMENT
3 SIDED, TEXTURED, GOURAUD SHADING, NO PIGMENT
olen = 0x9;  ilen =0x06;  flag =0x00;    mode =0x34;
  olen = 0x9;  ilen =0x06;  flag =0x00;    mode =0x34;
{
  {
u_char  U0, V0;        - X and Y coordinate of texture for Vertex0
  u_char  U0, V0;        - X and Y coordinate of texture for Vertex0
u_short CBA;            - position of CLUT for texture in VRAM (see earlier)
  u_short CBA;            - position of CLUT for texture in VRAM (see earlier)
u_char  U1, V1;        - X and Y coordinate of texture for Vertex1
  u_char  U1, V1;        - X and Y coordinate of texture for Vertex1
u_short TSB;            - information about texture in VRAM (see earlier)
  u_short TSB;            - information about texture in VRAM (see earlier)
u_char  U2, V2;        - X and Y coordinate of texture for Vertex2
  u_char  U2, V2;        - X and Y coordinate of texture for Vertex2
u_short pad;            - ignored
  u_short pad;            - ignored
u_short Normal0;        - index value of normal element
  u_short Normal0;        - index value of normal element
u_short Vertex0;        - index value of vertex element
  u_short Vertex0;        - index value of vertex element
u_short Normal1;
  u_short Normal1;
u_short Vertex1;
  u_short Vertex1;
u_short Normal2;
  u_short Normal2;
u_short Vertex2;
  u_short Vertex2;
} TMD_3_TX_GS_NP;
  } TMD_3_TX_GS_NP;
'
 
'3 SIDED, NO SHADING, FLAT PIGMENT
3 SIDED, NO SHADING, FLAT PIGMENT
olen = 0x04;  ilen =0x03;  flag =0x01;    mode =0x21;
  olen = 0x04;  ilen =0x03;  flag =0x01;    mode =0x21;
{
  {
u_char  R, G, B;        - pigment of polygon
  u_char  R, G, B;        - pigment of polygon
u_char  mode2;          - same as mode (above)
  u_char  mode2;          - same as mode (above)
u_short Vertex0;        - index value of vertex element
  u_short Vertex0;        - index value of vertex element
u_short Vertex1;
  u_short Vertex1;
u_short Vertex2;
  u_short Vertex2;
u_short pad;            - ignored
  u_short pad;            - ignored
} TMD_3_NS_FP;
  } TMD_3_NS_FP;
'
 
'3 SIDED, NO SHADING, GRADIENT PIGMENT
3 SIDED, NO SHADING, GRADIENT PIGMENT
olen = 0x06;  ilen =0x05;  flag =0x01;    mode =0x35;
  olen = 0x06;  ilen =0x05;  flag =0x01;    mode =0x35;
{
  {
u_char  R0, G0, B0;    - pigment of polygon at Vertex0
  u_char  R0, G0, B0;    - pigment of polygon at Vertex0
u_char  mode2;          - same as mode (above)
  u_char  mode2;          - same as mode (above)
u_char  R1, G1, B1;    - pigment of polygon at Vertex1
  u_char  R1, G1, B1;    - pigment of polygon at Vertex1
u_char  pad1;          - ignored
  u_char  pad1;          - ignored
u_char  R2, G2, B2;    - pigment of polygon at Vertex2
  u_char  R2, G2, B2;    - pigment of polygon at Vertex2
u_char  pad2;          - ignored
  u_char  pad2;          - ignored
u_short Vertex0;        - index value of vertex element
  u_short Vertex0;        - index value of vertex element
u_short Vertex1;
  u_short Vertex1;
u_short Vertex2;
  u_short Vertex2;
u_short pad;            - ignored
  u_short pad;            - ignored
} TMD_3_NS_GP;
  } TMD_3_NS_GP;
'
 
'3 SIDED, TEXTURED, NO SHADING, FLAT PIGMENT
3 SIDED, TEXTURED, NO SHADING, FLAT PIGMENT
olen = 0x07;  ilen =0x06;  flag =0x01;    mode =0x25;
  olen = 0x07;  ilen =0x06;  flag =0x01;    mode =0x25;
{
  {
u_char  U0, V0;        - X and Y coordinate of texture for Vertex0
  u_char  U0, V0;        - X and Y coordinate of texture for Vertex0
u_short CBA;            - position of CLUT for texture in VRAM (see earlier)
  u_short CBA;            - position of CLUT for texture in VRAM (see earlier)
u_char  U1, V1;        - X and Y coordinate of texture for Vertex1
  u_char  U1, V1;        - X and Y coordinate of texture for Vertex1
u_short TSB;            - information about texture in VRAM (see earlier)
  u_short TSB;            - information about texture in VRAM (see earlier)
u_char  U2, V2;        - X and Y coordinate of texture for Vertex2
  u_char  U2, V2;        - X and Y coordinate of texture for Vertex2
u_short pad1;          - ignored
  u_short pad1;          - ignored
u_char  R, G, B;        - pigment of polygon
  u_char  R, G, B;        - pigment of polygon
u_char  pad2;          - ignored
  u_char  pad2;          - ignored
u_short Vertex0;        - index value of vertex element
  u_short Vertex0;        - index value of vertex element
u_short Vertex1;
  u_short Vertex1;
u_short Vertex2;
  u_short Vertex2;
u_short pad;            - ignored
  u_short pad;            - ignored
} TMD_3_TX_NS_FP;
  } TMD_3_TX_NS_FP;
'
 
'3 SIDED, TEXTURED, NO SHADING, GRADIENT PIGMENT
3 SIDED, TEXTURED, NO SHADING, GRADIENT PIGMENT
olen = 0x9;  ilen =0x08;  flag =0x01;    mode =0x35;
  olen = 0x9;  ilen =0x08;  flag =0x01;    mode =0x35;
{
  {
u_char  U0, V0;        - X and Y coordinate of texture for Vertex0
  u_char  U0, V0;        - X and Y coordinate of texture for Vertex0
u_short CBA;            - position of CLUT for texture in VRAM (see earlier)
  u_short CBA;            - position of CLUT for texture in VRAM (see earlier)
u_char  U1, V1;        - X and Y coordinate of texture for Vertex1
  u_char  U1, V1;        - X and Y coordinate of texture for Vertex1
u_short TSB;            - information about texture in VRAM (see earlier)
  u_short TSB;            - information about texture in VRAM (see earlier)
u_char  U2, V2;        - X and Y coordinate of texture for Vertex2
  u_char  U2, V2;        - X and Y coordinate of texture for Vertex2
u_short pad1;          - ignored
  u_short pad1;          - ignored
u_char  R0, G0, B0;    - pigment of polygon at Vertex0
  u_char  R0, G0, B0;    - pigment of polygon at Vertex0
u_char  pad2;          - ignored
  u_char  pad2;          - ignored
u_char  R1, G1, B1;    - pigment of polygon at Vertex1
  u_char  R1, G1, B1;    - pigment of polygon at Vertex1
u_char  pad3;          - ignored
  u_char  pad3;          - ignored
u_char  R2, G2, B2;    - pigment of polygon at Vertex2
  u_char  R2, G2, B2;    - pigment of polygon at Vertex2
u_char  pad4;          - ignored
  u_char  pad4;          - ignored
u_short Vertex0;        - index value of vertex element
  u_short Vertex0;        - index value of vertex element
u_short Vertex1;
  u_short Vertex1;
u_short Vertex2;
  u_short Vertex2;
u_short pad;            - ignored
  u_short pad;            - ignored
} TMD_3_TX_NS_GP;
  } TMD_3_TX_NS_GP;
'
 
'primitive List 'S MEMBER VARIABLES FORMAT
primitive List S MEMBER VARIABLES FORMAT
'
 
'
 
'U_CHAR FLAG          - options for primitive
U_CHAR FLAG          - options for primitive
{
  {
bit  0;            - LGT. Light source calculation
  bit  0;            - LGT. Light source calculation
'                        0 - On.  Light source calculation is carried out
                        0 - On.  Light source calculation is carried out
'                        1 - Off.  Light source calculation is not carried out
                        1 - Off.  Light source calculation is not carried out
bit  1;            - FCE. Determines if primitive is one or two faced
  bit  1;            - FCE. Determines if primitive is one or two faced
'                        0 - Primitive has one face
                        0 - Primitive has one face
'                        1 - Primitive has two faces
                        1 - Primitive has two faces
bit  2;            - GRD. Determines single or gradient pigment
  bit  2;            - GRD. Determines single or gradient pigment
'                        0 - Primitive has one solid pigment
                        0 - Primitive has one solid pigment
'                        1 - Primitive has different pigments at each vertex
                        1 - Primitive has different pigments at each vertex
bits  3-7;          - ignored
  bits  3-7;          - ignored
}
  }
'
 
'Note
Note
'Most of these bits are set or cleared according to which type of primitive
Most of these bits are set or cleared according to which type of primitive
'is being created. Messing around with these may cause unexpected drawing or
is being created. Messing around with these may cause unexpected drawing or
'crashes. The only bit you may want to edit manually is FCE.
crashes. The only bit you may want to edit manually is FCE.
'
 
'U_CHAR MODE          - options for primitive
U_CHAR MODE          - options for primitive
{
  {
bit  0;            - TGE. Brightness calculation at time of calculation
  bit  0;            - TGE. Brightness calculation at time of calculation
'                        0 - On.  Calculates light
                        0 - On.  Calculates light
'                        1 - Off.  Draws texture as is (without lighting)
                        1 - Off.  Draws texture as is (without lighting)
bit  1;            - ABE. Activates translucency when rendered
  bit  1;            - ABE. Activates translucency when rendered
'                        0 - Off.  Primitive is rendered solid.
                        0 - Off.  Primitive is rendered solid.
'                        1 - On.  Primitive is rendered semitranslucent.
                        1 - On.  Primitive is rendered semitranslucent.
bit  2;            - TME. Sets whether a texture is used or not
  bit  2;            - TME. Sets whether a texture is used or not
'                        0 - Off.  No texture is rendered.
                        0 - Off.  No texture is rendered.
'                        1 - On.  A texture is rendered.
                        1 - On.  A texture is rendered.
bit  3;            - displays whether a 3 or 4 sided polygon
  bit  3;            - displays whether a 3 or 4 sided polygon
'                        0 - 3 sided polygon
                        0 - 3 sided polygon
'                        1 - 4 sided polygon
                        1 - 4 sided polygon
bit  4;            - IIP. Shading mode
  bit  4;            - IIP. Shading mode
'                        0 - Flat shading
                        0 - Flat shading
'                        1 - Gouraud shading
                        1 - Gouraud shading
bits  5-7;          - Code. Defines which sort of entity to draw.
  bits  5-7;          - Code. Defines which sort of entity to draw.
'                        0 - Polygon (3 sided or 4 sided)
                        0 - Polygon (3 sided or 4 sided)
'                        1 - Straight line
                        1 - Straight line
'                        2 - Sprite
                        2 - Sprite
}
  }
'
 
'Possible values of ABR (semitransparency method)
Possible values of ABR (semitransparency method)
'Note
Note
'Most of these bits are set or cleared according to which type of
Most of these bits are set or cleared according to which type of
'primitive is being created. Messing around with these may cause
primitive is being created. Messing around with these may cause
'unexpected drawing or crashes. The only bit you may want to edit
unexpected drawing or crashes. The only bit you may want to edit
'manually is ABE.
manually is ABE.
'For semitransparency to be used when the TMD is rendered, bit 30
For semitransparency to be used when the TMD is rendered, bit 30
'of the GsDOBJ's attribute member must be set. To control the
of the GsDOBJs attribute member must be set. To control the
'semitransparency method, alter the ABR bits of the primitive's TSB
semitransparency method, alter the ABR bits of the primitives TSB
'member (see below).
member (see below).
'
 
'U_SHORT CBA          - position of CLUT in VRAM for primitives with textures
U_SHORT CBA          - position of CLUT in VRAM for primitives with textures
{
  {
bits  0-5;          - upper 6 bits of 10 bits of X coordinate value
  bits  0-5;          - upper 6 bits of 10 bits of X coordinate value
'                        for CLUT in VRAM
                        for CLUT in VRAM
bits  6-14;        - 9 bits of Y coordinate value for CLUT in VRAM
  bits  6-14;        - 9 bits of Y coordinate value for CLUT in VRAM
bit 15;            - ignored
  bit 15;            - ignored
}
  }
'
 
'For example -
For example -
u_long  CLUT_X_POS = 640;
  u_long  CLUT_X_POS = 640;
u_long  CLUT_Y_POS = 480;
  u_long  CLUT_Y_POS = 480;
u_short CBA = (CLUT_X_POS >> 4) + (CLUT_Y_POS << 6);
  u_short CBA = (CLUT_X_POS >> 4) + (CLUT_Y_POS << 6);
'
 
'U_SHORT TSB          - information about image for primitives with textures
U_SHORT TSB          - information about image for primitives with textures
{
  {
bits  0-4;          - texture page number of texture
  bits  0-4;          - texture page number of texture
bits  5-6;          - ABR. Semitransparency method (see below)
  bits  5-6;          - ABR. Semitransparency method (see below)
bits  7-8;          - TPF. Colour mode of the texture (see below)
  bits  7-8;          - TPF. Colour mode of the texture (see below)
bits  9-15;        - ignored
  bits  9-15;        - ignored
}
  }
'
 
'Possible values of ABR (semitransparency method)
Possible values of ABR (semitransparency method)
'Note
Note
'For semitransparency to be used when the TMD is rendered, bit 30 of
For semitransparency to be used when the TMD is rendered, bit 30 of
'the GsDOBJ 's attribute member must be set, and the ABE bit of the
the GsDOBJ s attribute member must be set, and the ABE bit of the
'primitive 's mode member must be set (see above).
primitive s mode member must be set (see above).
0    - 50% background  +50% polygon
  0    - 50% background  +50% polygon
1    - 100% background +100% polygon
  1    - 100% background +100% polygon
2    - 100% background - 100% polygon
  2    - 100% background - 100% polygon
3    - 100% background + 25% polygon
  3    - 100% background + 25% polygon
'Possible values of TPF (colour mode)
Possible values of TPF (colour mode)
0    - 4 bit texture and CLUT
  0    - 4 bit texture and CLUT
1    - 8 bit texture and CLUT
  1    - 8 bit texture and CLUT
2    - 15 bit texture with no CLUT
  2    - 15 bit texture with no CLUT
'For example -
For example -
u_long  IMG_X_POS = 640;
  u_long  IMG_X_POS = 640;
u_long  IMG_Y_POS = 0;
  u_long  IMG_Y_POS = 0;
u_long  ABR = 1;  // 100% back + 100% polygon
  u_long  ABR = 1;  // 100% back + 100% polygon
u_long  TPF = 0;  // 16 colour texture
  u_long  TPF = 0;  // 16 colour texture
u_short TXT_TPAGE;
  u_short TXT_TPAGE;
TXT_TPAGE = GetTPage((int) TPF, (int) ABR, IMG_X_POS, IMG_Y_POS);
  TXT_TPAGE = GetTPage((int) TPF, (int) ABR, IMG_X_POS, IMG_Y_POS);
u_short TSB = (TXT_TPAGE) + (ABR << 5) + (TPF << 7);
  u_short TSB = (TXT_TPAGE) + (ABR << 5) + (TPF << 7);

Revision as of 04:36, 18 August 2007

TMD FILE FORMAT

HEADER - One per TMD

 {
 u_long  id;               - version of TMD. Always 0x00000041
 u_long  flags;            - Indicates when addresses are relative or explicit
 u_long  nobj;             - number of objects in the TMD
 } HEADER;

OBJECT LIST - One per object in the TMD

 {
 u_long  *vert_top;        - start address of vertex list
 u_long  n_vert;           - number of vertices in the object
 u_long  *normal_top;      - start address of normal list
 u_long  n_normal;         - number of normals in the object
 u_long  *primitive_top;   - start address of primitive list
 u_long  n_primitive;      - number of primitives in the object
 long  scale;              - ignored
 } OBJECT;

PRIMITIVE LIST - One per primitive per object in the TMD

 {
 u_char  olen;             - word length of the drawing primitive created by GPU
 u_char  ilen;             - word length of the packet data section
 u_char  flag;             - options when rendering
 u_char  mode;             - indicates type of primitive
 } PRIMITIVE_HEADER;
 ??      PACKET;           - variable in length and content (see later for list)

VERTEX LIST - One per vertex per object in the TMD

 {
 short vx;                 - X value of vertex
 short vy;                 - Y value of vertex
 short vz;                 - Z value of vertex
 short pad;                - ignored
 }   VERTEX;

NORMAL LIST - One per normal per object in the TMD

 {
 short nx;                 - X value of normal
 short ny;                 - Y value of normal
 short nz;                 - Z value of normal
 short pad;                - ignored
 }   NORMAL;

PACKET LIST FORMAT


Note When mode and flag are set with the values shown here, they default to creating a one-sided primitive that will be rendered with no semitransparency. To alter these, see earlier notes. Pigment refers to the inherent colour of the primitive, before lightsources alter the appearance on screen. A gradient pigment has a different RGB value at each vertex, and by using the same interpolation algorithm that gouraud shading uses, a smooth transition between colours is achieved.

LIST OF PRIMITIVES INCLUDED SO FAR 3 SIDED, FLAT SHADING, FLAT PIGMENT 3 SIDED, GOURAUD SHADING, FLAT PIGMENT 3 SIDED, FLAT SHADING, GRADIENT PIGMENT 3 SIDED, GOURAUD SHADING, GRADIENT PIGMENT 3 SIDED, TEXTURED, FLAT SHADING, NO PIGMENT 3 SIDED, TEXTURED, GOURAUD SHADING, NO PIGMENT 3 SIDED, NO SHADING, FLAT PIGMENT 3 SIDED, NO SHADING, GRADIENT PIGMENT 3 SIDED, TEXTURED, NO SHADING, FLAT PIGMENT 3 SIDED, TEXTURED, NO SHADING, GRADIENT PIGMENT

3 SIDED, FLAT SHADING, FLAT PIGMENT

 olen = 0x04;   ilen =0x03;   flag =0x00;    mode =0x20;
 {
 u_char  R, G, B;        - pigment of polygon
 u_char  mode2;          - same as mode (above)
 u_short Normal0;        - index value of normal element
 u_short Vertex0;        - index value of vertex element
 u_short Vertex1;
 u_short Vertex2;
 } TMD_3_FS_FP;

3 SIDED, GOURAUD SHADING, FLAT PIGMENT

 olen = 0x06;   ilen =0x04;   flag =0x00;    mode =0x30;
 {
 u_char  R, G, B;        - pigment of polygon
 u_char  mode2;          - same as mode (above)
 u_short Normal0;        - index value of normal element
 u_short Vertex0;        - index value of vertex element
 u_short Normal1;
 u_short Vertex1;
 u_short Normal2;
 u_short Vertex2;
 } TMD_3_GS_FP;

3 SIDED, FLAT SHADING, GRADIENT PIGMENT

 olen = 0x06;   ilen =0x05;   flag =0x04;    mode =0x20;
 {
 u_char  R0, G0, B0;     - pigment of polygon at Vertex0
 u_char  mode2;          - same as mode (above)
 u_char  R1, G1, B1;     - pigment of polygon at Vertex1
 u_char  pad1;           - ignored
 u_char  R2, G2, B2;     - pigment of polygon at Vertex2
 u_char  pad2;           - ignored
 u_short Normal0;        - index value of normal element
 u_short Vertex0;        - index value of vertex element
 u_short Vertex1;
 u_short Vertex2;
 } TMD_3_FS_GP;

3 SIDED, GOURAUD SHADING, GRADIENT PIGMENT

 olen = 0x06;   ilen =0x06;   flag =0x04;    mode =0x30;
 {
 u_char  R0, G0, B0;     - pigment of polygon at Vertex0
 u_char  mode2;          - same as mode (above)
 u_char  R1, G1, B1;     - pigment of polygon at Vertex1
 u_char  pad1;           - ignored
 u_char  R2, G2, B2;     - pigment of polygon at Vertex2
 u_char  pad2;           - ignored
 u_short Normal0;        - index value of normal element
 u_short Vertex0;        - index value of vertex element
 u_short Normal1;
 u_short Vertex1;
 u_short Normal2;
 u_short Vertex2;
 } TMD_3_GS_GP;

3 SIDED, TEXTURED, FLAT SHADING, NO PIGMENT

 olen = 0x07;   ilen =0x05;   flag =0x00;    mode =0x24;
 {
 u_char  U0, V0;         - X and Y coordinate of texture for Vertex0
 u_short CBA;            - position of CLUT for texture in VRAM (see earlier)
 u_char  U1, V1;         - X and Y coordinate of texture for Vertex1
 u_short TSB;            - information about texture in VRAM (see earlier)
 u_char  U2, V2;         - X and Y coordinate of texture for Vertex2
 u_short pad;            - ignored
 u_short Normal;         - index value of normal element
 u_short Vertex0;        - index value of vertex element
 u_short Vertex1;
 u_short Vertex2;
 } TMD_3_TX_FS_NP;

3 SIDED, TEXTURED, GOURAUD SHADING, NO PIGMENT

 olen = 0x9;   ilen =0x06;   flag =0x00;    mode =0x34;
 {
 u_char  U0, V0;         - X and Y coordinate of texture for Vertex0
 u_short CBA;            - position of CLUT for texture in VRAM (see earlier)
 u_char  U1, V1;         - X and Y coordinate of texture for Vertex1
 u_short TSB;            - information about texture in VRAM (see earlier)
 u_char  U2, V2;         - X and Y coordinate of texture for Vertex2
 u_short pad;            - ignored
 u_short Normal0;        - index value of normal element
 u_short Vertex0;        - index value of vertex element
 u_short Normal1;
 u_short Vertex1;
 u_short Normal2;
 u_short Vertex2;
 } TMD_3_TX_GS_NP;

3 SIDED, NO SHADING, FLAT PIGMENT

 olen = 0x04;   ilen =0x03;   flag =0x01;    mode =0x21;
 {
 u_char  R, G, B;        - pigment of polygon
 u_char  mode2;          - same as mode (above)
 u_short Vertex0;        - index value of vertex element
 u_short Vertex1;
 u_short Vertex2;
 u_short pad;            - ignored
 } TMD_3_NS_FP;

3 SIDED, NO SHADING, GRADIENT PIGMENT

 olen = 0x06;   ilen =0x05;   flag =0x01;    mode =0x35;
 {
 u_char  R0, G0, B0;     - pigment of polygon at Vertex0
 u_char  mode2;          - same as mode (above)
 u_char  R1, G1, B1;     - pigment of polygon at Vertex1
 u_char  pad1;           - ignored
 u_char  R2, G2, B2;     - pigment of polygon at Vertex2
 u_char  pad2;           - ignored
 u_short Vertex0;        - index value of vertex element
 u_short Vertex1;
 u_short Vertex2;
 u_short pad;            - ignored
 } TMD_3_NS_GP;

3 SIDED, TEXTURED, NO SHADING, FLAT PIGMENT

 olen = 0x07;   ilen =0x06;   flag =0x01;    mode =0x25;
 {
 u_char  U0, V0;         - X and Y coordinate of texture for Vertex0
 u_short CBA;            - position of CLUT for texture in VRAM (see earlier)
 u_char  U1, V1;         - X and Y coordinate of texture for Vertex1
 u_short TSB;            - information about texture in VRAM (see earlier)
 u_char  U2, V2;         - X and Y coordinate of texture for Vertex2
 u_short pad1;           - ignored
 u_char  R, G, B;        - pigment of polygon
 u_char  pad2;           - ignored
 u_short Vertex0;        - index value of vertex element
 u_short Vertex1;
 u_short Vertex2;
 u_short pad;            - ignored
 } TMD_3_TX_NS_FP;

3 SIDED, TEXTURED, NO SHADING, GRADIENT PIGMENT

 olen = 0x9;   ilen =0x08;   flag =0x01;    mode =0x35;
 {
 u_char  U0, V0;         - X and Y coordinate of texture for Vertex0
 u_short CBA;            - position of CLUT for texture in VRAM (see earlier)
 u_char  U1, V1;         - X and Y coordinate of texture for Vertex1
 u_short TSB;            - information about texture in VRAM (see earlier)
 u_char  U2, V2;         - X and Y coordinate of texture for Vertex2
 u_short pad1;           - ignored
 u_char  R0, G0, B0;     - pigment of polygon at Vertex0
 u_char  pad2;           - ignored
 u_char  R1, G1, B1;     - pigment of polygon at Vertex1
 u_char  pad3;           - ignored
 u_char  R2, G2, B2;     - pigment of polygon at Vertex2
 u_char  pad4;           - ignored
 u_short Vertex0;        - index value of vertex element
 u_short Vertex1;
 u_short Vertex2;
 u_short pad;            - ignored
 } TMD_3_TX_NS_GP;

primitive List S MEMBER VARIABLES FORMAT


U_CHAR FLAG - options for primitive

 {
 bit   0;            - LGT. Light source calculation
                       0 - On.   Light source calculation is carried out
                       1 - Off.  Light source calculation is not carried out
 bit   1;            - FCE. Determines if primitive is one or two faced
                       0 - Primitive has one face
                       1 - Primitive has two faces
 bit   2;            - GRD. Determines single or gradient pigment
                       0 - Primitive has one solid pigment
                       1 - Primitive has different pigments at each vertex
 bits  3-7;          - ignored
 }

Note Most of these bits are set or cleared according to which type of primitive is being created. Messing around with these may cause unexpected drawing or crashes. The only bit you may want to edit manually is FCE.

U_CHAR MODE - options for primitive

 {
 bit   0;            - TGE. Brightness calculation at time of calculation
                       0 - On.   Calculates light
                       1 - Off.  Draws texture as is (without lighting)
 bit   1;            - ABE. Activates translucency when rendered
                       0 - Off.  Primitive is rendered solid.
                       1 - On.   Primitive is rendered semitranslucent.
 bit   2;            - TME. Sets whether a texture is used or not
                       0 - Off.  No texture is rendered.
                       1 - On.   A texture is rendered.
 bit   3;            - displays whether a 3 or 4 sided polygon
                       0 - 3 sided polygon
                       1 - 4 sided polygon
 bit   4;            - IIP. Shading mode
                       0 - Flat shading
                       1 - Gouraud shading
 bits  5-7;          - Code. Defines which sort of entity to draw.
                       0 - Polygon (3 sided or 4 sided)
                       1 - Straight line
                       2 - Sprite
 }

Possible values of ABR (semitransparency method) Note Most of these bits are set or cleared according to which type of primitive is being created. Messing around with these may cause unexpected drawing or crashes. The only bit you may want to edit manually is ABE. For semitransparency to be used when the TMD is rendered, bit 30 of the GsDOBJs attribute member must be set. To control the semitransparency method, alter the ABR bits of the primitives TSB member (see below).

U_SHORT CBA - position of CLUT in VRAM for primitives with textures

 {
 bits  0-5;          - upper 6 bits of 10 bits of X coordinate value
                       for CLUT in VRAM
 bits  6-14;         - 9 bits of Y coordinate value for CLUT in VRAM
 bit 15;             - ignored
 }

For example -

 u_long  CLUT_X_POS = 640;
 u_long  CLUT_Y_POS = 480;
 u_short CBA = (CLUT_X_POS >> 4) + (CLUT_Y_POS << 6);

U_SHORT TSB - information about image for primitives with textures

 {
 bits  0-4;          - texture page number of texture
 bits  5-6;          - ABR. Semitransparency method (see below)
 bits  7-8;          - TPF. Colour mode of the texture (see below)
 bits  9-15;         - ignored
 }

Possible values of ABR (semitransparency method) Note For semitransparency to be used when the TMD is rendered, bit 30 of the GsDOBJ s attribute member must be set, and the ABE bit of the primitive s mode member must be set (see above).

 0     - 50% background  +50% polygon
 1     - 100% background +100% polygon
 2     - 100% background - 100% polygon
 3     - 100% background + 25% polygon

Possible values of TPF (colour mode)

 0     - 4 bit texture and CLUT
 1     - 8 bit texture and CLUT
 2     - 15 bit texture with no CLUT

For example -

 u_long  IMG_X_POS = 640;
 u_long  IMG_Y_POS = 0;
 u_long  ABR = 1;  // 100% back + 100% polygon
 u_long  TPF = 0;  // 16 colour texture
 u_short TXT_TPAGE;
 TXT_TPAGE = GetTPage((int) TPF, (int) ABR, IMG_X_POS, IMG_Y_POS);
 u_short TSB = (TXT_TPAGE) + (ABR << 5) + (TPF << 7);