;-----------------------------------------------------------------------------
;
; This file contains texture read functions.

; WARNING WARNING WARNING
; This asm file generated from mas file.
; EDIT THE MAS FILE.
; I warned you.
; WARNING WARNING WARNING
;
; Register useage for now.
;
; TODO  Optimization: make different cases for colorkey and no colorkey since
; I cant shift to the quad word since I need to compare with colorkey
;
; Is all of these register useages still true?
;
; In all routines, address of iU and iV will come in as eax
; mm5 is reserved for border mask.
; mm6 and mm7 are reserved for bilinear calculation taking place in
; texture address routines.
;
; iShiftU will generate a multiplier to generate texture address
; it will be in mm3
;
; edi = pBits for now.
; pTex will still be in esi or whatever register I gave it for Texaddr
; routines.
;
; Output will go to mm1 for use by texaddr routines.
; TBD make sure that alpha value is always set.
; TBD make sure that color is returned in bytes from low byte to high byte
; as b, 0, g, 0, r, 0, a, 0.  This will make it convient for the pmul.
;
;-----------------------------------------------------------------------------

INCLUDE iammx.inc
INCLUDE offs_acp.inc

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

.586
.model flat
.data
; Red and Blue are masked after the shifts.

  PUBLIC  SetAlphato0xffff
SetAlphato0xffff         dq  0ffff000000000000h

CheckLowTwo8BitSignbits   dq  08080h

Val0xffff00              dq  0ffff00h

Val0x00ff00ff            dq 000ff00ffh
Val0xff00ff00            dq 0ff00ff00h

    PUBLIC  MaskRed565to888
MaskRed565to888          dq  0000000000f80000h
    PUBLIC  MaskRed555to888
MaskRed555to888          dq  0000000000f80000h

    PUBLIC  MaskGreen565to888
MaskGreen565to888        dq  00000000000007e0h
    PUBLIC  MaskGreen555to888
MaskGreen555to888        dq  00000000000003e0h

    PUBLIC  MaskBlue565to888
MaskBlue565to888         dd  000000f8h
    PUBLIC  MaskBlue555to888
MaskBlue555to888         dd  000000f8h

MaskGreen444to888        dq  00000000000000f0h
MaskRedBlue444to888      dq  0000000000000f0fh

MaskAlphaGreen4444to8888 dq  000000000000f0f0h
MaskRedBlue4444to8888    dq  0000000000000f0fh

    PUBLIC MaskAlpha1555to8888
MaskAlpha1555to8888      dq  0000000000008000h
    PUBLIC MaskRed1555to8888
MaskRed1555to8888        dq  0000000000f80000h
    PUBLIC MaskBlue1555to8888
MaskBlue1555to8888       dq  000000f8h
    PUBLIC MaskGreen1555to8888
MaskGreen1555to8888      dd  0000f800h

    PUBLIC MaskL8A8ALPHA
MaskL8A8ALPHA            dd  000000ffh



EXTERN SetAlphato0xff:MMWORD

.code

RedShift565to888     equ 8
GreenShift565to888   equ 5
BlueShift565to888    equ 3

RedShift555to888     equ 9
GreenShift555to888   equ 6
BlueShift555to888    equ 3

AlphaShift1555to8888 equ 16
RedShift1555to8888   equ 9
GreenShift1555to8888 equ 6
BlueShift1555to8888  equ 3

EXTERN Zero:MMWORD

d_DoTex(`d_Palette8') dnl
d_DoTex(`d_Palette4') dnl
d_DoTex(`d_Palette8A') dnl
d_DoTex(`d_Palette4A') dnl
d_DoTex(`d_B8G8R8') dnl
d_DoTex(`d_B8G8R8A8') dnl
d_DoTex(`d_B5G6R5') dnl
d_DoTex(`d_B5G5R5') dnl
d_DoTex(`d_B5G5R5A1') dnl
d_DoTex(`d_B4G4R4A4') dnl
d_DoTex(`d_L8') dnl
d_DoTex(`d_L8A8') dnl

END