;-----------------------------------------------------------------------------
;
; This file contains the output buffer color writing routines.
;
; Copyright (C) Microsoft Corporation, 1997.
;
; Need to change this from Segment asm method to be same as other files.
; This is the only file that is doing it this way.
;
;-----------------------------------------------------------------------------

INCLUDE iammx.inc
INCLUDE offs_acp.inc

include(`m4hdr.mh')dnl
include(`cvars.mh')dnl
include(`bufwrite.mh')dnl

.586p
.model flat
.data
    PUBLIC  g_uDitherValue
g_uDitherValue         dq  ?

    PUBLIC  SetAlphato0x00
SetAlphato0x00          dq  0000000000ffffffh
    PUBLIC  SetAlphato0xff
SetAlphato0xff          dq  00000000ff000000h

; 565 values.  Too bad that there are 5 values.  4 values would fit into one cache line.
    PUBLIC  u888to565RedBlueMask
u888to565RedBlueMask        dq  00f800f800f800f8h

    PUBLIC  u888to565GreenMask
u888to565GreenMask          dq  0000fc000000fc00h

    PUBLIC  u888to565Multiplier
u888to565Multiplier         dq  2000000420000004h

    PUBLIC  uVal0x000007ff03ff07ff
uVal0x000007ff03ff07ff      dq  000007ff03ff07ffh  ; Or mask to increase 565 color value

    PUBLIC  uVal0x0000078003c00780
uVal0x0000078003c00780      dq  0000078003c00780h  ; Bits to test for dithering in 565

; 555 values
    PUBLIC  u888to555RedBlueMask
u888to555RedBlueMask        dq  00f800f800f800f8h

    PUBLIC  u888to555GreenMask
u888to555GreenMask          dq  0000f8000000f800h

    PUBLIC  u888to555Multiplier
u888to555Multiplier         dq  2000000820000008h

    PUBLIC  uVal0x000007ff07ff07ff
uVal0x000007ff07ff07ff      dq  000007ff07ff07ffh  ; Or mask to increase 555 color value

    PUBLIC  uVal0x0000078007800780
uVal0x0000078007800780      dq  0000078007800780h  ; Bits to test for dithering in 555


Val0x008000800080           dq  0000008000800080h
Val0x002400060001           dq  0000002400060001h
Val0x000500050005           dq  0000000500050005h

.code

; Names are read LSB to MSB, so B5G6R5 means five bits of blue starting
; at the LSB, then six bits of green, then five bits of red.


;-----------------------------------------------------------------------------
;
; Write_B8G8R8X8_NoDither
;
; Writes output in BGR-888 format.
;
;-----------------------------------------------------------------------------
;void Write_B8G8R8X8_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
;{
    PUBLIC _MMX_BufWrite_B8G8R8X8_NoDither
_MMX_BufWrite_B8G8R8X8_NoDither:

d_BufWrite_B8G8R8X8_NoDither(NotMonolithic)

    ;; just returns for C, since we really cant loop with function calls
    ;ret
    jmp     dword ptr XpCtx(pfnPixelEnd)
;}

;-----------------------------------------------------------------------------
;
; Write_B8G8R8A8_NoDither
;
; Writes output in BGRA-8888 format.
;
;-----------------------------------------------------------------------------
;void Write_B8G8R8A8_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
;{
    PUBLIC _MMX_BufWrite_B8G8R8A8_NoDither
_MMX_BufWrite_B8G8R8A8_NoDither:

d_BufWrite_B8G8R8A8_NoDither(NotMonolithic)

    ; just returns for C, since we really cant loop with function calls
    ;ret
    jmp     dword ptr XpCtx(pfnPixelEnd)
;}

;-----------------------------------------------------------------------------
;
; Write_B5G6R5_NoDither
;
; Writes output in BGR-565 format.
;
;-----------------------------------------------------------------------------
;void Write_B5G6R5_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
;{
    PUBLIC _MMX_BufWrite_B5G6R5_NoDither
_MMX_BufWrite_B5G6R5_NoDither:

d_BufWrite_B5G6R5_NoDither(NotMonolithic)

    ; just returns for C, since we really cant loop with function calls
    jmp     dword ptr XpCtx(pfnPixelEnd)
;}

;-----------------------------------------------------------------------------
;
; Write_B5G6R5_Dither
;
; Writes output in BGR-565 format, dithered.
;
;-----------------------------------------------------------------------------
;void Write_B5G6R5_Dither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
;{
    PUBLIC _MMX_BufWrite_B5G6R5_Dither
_MMX_BufWrite_B5G6R5_Dither:


d_BufWrite_B5G6R5_Dither(NotMonolithic)

    ; just returns for C, since we really cant loop with function calls
    ;ret
    jmp     dword ptr XpCtx(pfnPixelEnd)

;}

;-----------------------------------------------------------------------------
;
; Write_B5G5R5_NoDither
;
; Writes output in BGR-555 format.
;
;-----------------------------------------------------------------------------
;void Write_B5G5R5_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
;{
    PUBLIC _MMX_BufWrite_B5G5R5_NoDither
_MMX_BufWrite_B5G5R5_NoDither:

d_BufWrite_B5G5R5_NoDither(NotMonolithic)

    ; just returns for C, since we really cant loop with function calls
    ;ret
    jmp     dword ptr XpCtx(pfnPixelEnd)
;}

;-----------------------------------------------------------------------------
;
; Write_B5G5R5_Dither
;
; Writes output in BGR-555 format, dithered.
;
;-----------------------------------------------------------------------------
;void Write_B5G5R5_Dither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
;{
    PUBLIC _MMX_BufWrite_B5G5R5_Dither
_MMX_BufWrite_B5G5R5_Dither:

d_BufWrite_B5G5R5_Dither(NotMonolithic)

    ; just returns for C, since we really cant loop with function calls
    ;ret
    jmp     dword ptr XpCtx(pfnPixelEnd)
;}

;-----------------------------------------------------------------------------
;
; Write_B5G5R5A1_NoDither
;
; Writes output in BGRA-1555 format.
;
;-----------------------------------------------------------------------------
;void Write_B5G5R5A1_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
;{
    PUBLIC _MMX_BufWrite_B5G5R5A1_NoDither
_MMX_BufWrite_B5G5R5A1_NoDither:

d_BufWrite_B5G5R5A1_NoDither(NotMonolithic)

    ; just returns for C, since we really cant loop with function calls
    ;ret
    jmp     dword ptr XpCtx(pfnPixelEnd)
;}

;-----------------------------------------------------------------------------
;
; Write_B5G5R5A1_Dither
;
; Writes output in BGRA-1555 format, dithered.
;
;-----------------------------------------------------------------------------
;void Write_B5G5R5A1_Dither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
;{
    PUBLIC _MMX_BufWrite_B5G5R5A1_Dither
_MMX_BufWrite_B5G5R5A1_Dither:


d_BufWrite_B5G5R5A1_Dither(NotMonolithic)
    ; just returns for C, since we really cant loop with function calls
    ;ret
    jmp     dword ptr XpCtx(pfnPixelEnd)
;}


;-----------------------------------------------------------------------------
;
; Write_B8G8R8_NoDither
;
; Writes output in BGR-888 format.
;
;-----------------------------------------------------------------------------
;void Write_B8G8R8_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
;{
    PUBLIC _MMX_BufWrite_B8G8R8_NoDither
_MMX_BufWrite_B8G8R8_NoDither:

d_BufWrite_B8G8R8_NoDither(NotMonolithic)
    jmp     dword ptr XpCtx(pfnPixelEnd)
;}

;-----------------------------------------------------------------------------
;
; Write_Palette8_NoDither
;
; Writes output in Palette8 format.
;
;-----------------------------------------------------------------------------
;void Write_Palette8_NoDither(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
;{
    PUBLIC _MMX_BufWrite_Palette8_NoDither
_MMX_BufWrite_Palette8_NoDither:

d_BufWrite_Palette8_Dither(NotMonolithic)

    jmp     dword ptr XpCtx(pfnPixelEnd)
;}

END