//=================================================================
//
// Copyright (c) Microsoft Corporation 1999 - All Rights Reserved.
//
//=================================================================

#ifndef _SPAN_
#define _SPAN_

#define USE_C   0   // set to 1 to build with C code, 0 to build with ASM

// # of span vectors in pspanfnWorking[] -- all the vectors that can possibly be
// run while drawing a span
#define NUM_SPAN_VECTORS        5
// # of span vectors in bSpanProcessor[] in master table (fog is handled separately)
#define NUM_TABLE_SPAN_VECTORS  4

// keep in sync with highest entry number in rgpspanfn[]
#define MAX_SPAN_FN             26

#define MAX_SPAN_BLOCK_LEN      16
#define MAX_SPAN_BLOCK_SHIFT    4

#define MAX_ALPHA               0x1F

// entry in pspanfnWorking[] containing address of "after munge" routine
// NOTE mikeab this is a #define instead of a const int because inline asm
// didn't think the const int was a constant expression
#define SPAN_MUNGE  2

// entry in rgpspanfnTrivialZAndBackend[] containing address of current
// native-one-pass chunk processor
// NOTE mikeab this is a #define instead of a const int because inline asm
// didn't think the const int was a constant expression
#define NATIVE_SINGLE_PASS  0

extern int cTrivialAccept;
extern int cTrivialPartial;
extern int cTrivialReject;

// Fixed point formats.
typedef long    FIX16_16;
typedef long    FIX28_4;
typedef long    FIX6_26;  
typedef long    FIX12_20;
typedef short   FIX0_16;

typedef long    FIX5_5;
typedef long    FIX5_16;

// special format for non-textured Gouraud shading:
// bits 0-9: B in 5.5
// bits 10-19: pad
// bits 20-29: R in 5.5
// bits 30-31: not used
typedef unsigned long   GOURAUD_RB;

// special format for non-textured Gouraud shading:
// bits 0-9: pad
// bits 10-19: B in 5.5
// bit  20: pad
// bits 21-30: A in 5.5
// bit 31: not used
typedef unsigned long   GOURAUD_AG;

// special format for textured Gouraud shading:
// bits 0-9: B in 5.5
// bit 10: pad
// bits 11-20: G in 5.5
// bits 21-31: not used
typedef unsigned long   GOURAUD_GB;

// special format for textured Gouraud shading:
// bits 0-9: R in 5.5
// bit 10:: pad
// bits 11-20: A in 5.5
// bits 21-31: not used
typedef unsigned long   GOURAUD_AR;

// special format for paired-multiply (2 pixels RGB shaded with
// 3 MULs) textured Gouraud shading:
// bits 0-9: B in 5.5
// bit 10: pad
// bits 11-20: G in 5.5
// bit 21: pad
// bits 22-31: R in 5.5
typedef unsigned long   GOURAUD_RGB;

// special format for textured I Gouraud shading:
// bits 0-9: I in 5.5
// bits 10-31: pad
typedef unsigned long   GOURAUD_I;

// special format for textured A (in conjunction with I) Gouraud shading:
// bits 0-24: A in 8.16
// bits 25-31: pad
typedef unsigned long   GOURAUD_A;

// masks to apply after adding to GOURAUD_RB and GOURAUD_AG, to clear
// carry from negative iteration
#define GOURAUD_RB_CARRY_MASK   ~0x40000400
#define GOURAUD_AG_CARRY_MASK   ~0x80100000

// masks to apply after adding to GOURAUD_GB, GOURAUD_AR, and GOURAUD_RGB
// to clear carry from negative iteration
#define GOURAUD_GB_CARRY_MASK   ~0x00200400
#define GOURAUD_AR_CARRY_MASK   ~0x00200400
#define GOURAUD_RGB_CARRY_MASK  ~0x00200400

// RGB stored in munged format for loading as dword for intensity
// multiplication (multiplication by a single value).
// Format:
//  B:   bits 0-4
//  Pad: bits 5-9
//  G:   bits 10-14
//  Pad: bits 15-19
//  R:   bits 20-24
//  Pad: bits 25-31
typedef unsigned long   MUNGED3;

// AR or GB stored in munged color for loading as dword for RGBA
// multiplication (multiplication by 4 separate components).
// Format:
//  B/R: bits 0-4
//  Pad: bits 5-9
//  G/A: bits 10-14
//  Pad: bits 15-31
typedef unsigned long   MUNGED2;

// AR or GB stored in munged color for loading as dword for RGBA
// multiplication. (Extended version with an extra bit of padding, needed
// so Gouraud iterpolators have enough bits; all RGB shading colors are
// in this format for consistency.)
// NOTE: these may be bumped up by adding 1, in which case they
// can take up one pad bit, but the largest value then is 0x20 (effectively 1),
// so the result of multiplying two 5-bit fields together still fits in 10 bits.
// Format:
//  B/R: bits 0-4
//  Pad: bits 5-10
//  G/A: bits 11-15
//  Pad: bits 16-31
typedef unsigned long   MUNGED2X;

// a single color or alpha component stored as a 5-bit value. Really just
// a DWORD, but named MUNGED1 because it's compatible with MUNGED2 and MUNGED3.
typedef unsigned long   MUNGED1;

typedef void (*PSPANFN)(void);

extern PSPANFN rgpspanfn[MAX_SPAN_FN + 1];

#define PSPANFN_AFTER_TRIVIALZ  0
#define PSPANFN_AFTER_TEXTURING 1
#define PSPANFN_AFTER_MUNGING   2
#define PSPANFN_AFTER_SHADING   3
#define PSPANFN_AFTER_FOG       4

#endif // _SPAN_

