//
// Project UnReality: The First Nintendo 64 Emulator
// Copyright (C) 1997-1998, Cold Fusion Entertainment
// All rights reserved
//
// This source code is unpublished propietary information of Cold Fusion Entertainment.  No portion of this software
// may be disclosed to any third party or copied or duplicated in any form, in whole or in part, without the prior
// written consent of Cold Fusion Entertainment.
// 

//
// $Log: GFX.H $
// Revision 1.3  1998/03/08 19:12:29  BREAKPOINT
// Version 0.3b.3 checkin... I need to really check this stuff in more often..
// Revision 1.2  1998/01/31 19:58:41  BREAKPOINT
// Added Convert5551to555()...
// Revision 1.1  1998/01/10 01:27:19  BREAKPOINT
// Initial revision
//

//---------------------------------------------------------------------------------------------------------------------

#ifndef GFX_H
#define GFX_H

#include <types.h>
#include <windows.h>

typedef struct
{
    ushort xsize;
    ushort ysize;
    uchar *image;
} blitbuf;

extern uint   DD_Xsize, DD_Ysize, DD_FullXsize;
extern uchar  DD_Depth, *DD_Surfptr, vga_pal[768];
extern ulong *DD_RowOffsets;

// Test for a mode and get surface RGB (in form of, say, 0x0565 or 0x0888).
bool ModeExist(uint xsize, uint ysize, uchar bpp);
ushort GetSurfaceRGB(void);

// DirectDraw stuff...
bool InitDirectDraw(HWND hwnd, uint xsize, uint ysize, uchar bpp, bool use_offbuffer, bool use_window);
void DeinitDirectDraw(void);
void ChangeResolution(uint xsize, uint ysize, uchar bpp);
bool UsingWindow(void);
void SwitchToWindow(void);
void SwitchToFullscreen(void);
bool RestoreSurfaces(void);

// For DirectDraw...
void SwapPages(void);
void BlitOffBuffer(void);
void ClearPage(void);
void ClearOffBuffer(void);
uchar *LockPage(void);
void UnlockPage(void);
uchar *LockBuffer(void);
void UnlockBuffer(void);

// For Windoze...
void BlitToWindow(void);
void ClearWindowBuffer(void);
uchar *LockWindowBuffer(void);
void UnlockWindowBuffer(void);

// Function pointers to call, regardless of off-screen buffer usage.  Lock and Unlock must be called manually,
// and PutPixel/Line/Poly functions will GPF if the surface is not locked.
extern void (*Flip)(void);
extern void (*Clear)(void);
extern uchar *(*Lock)(void);
extern void (*Unlock)(void);

// Palette stuff...
void LoadPal(uchar *pal);
void CreateShadePal(void);

// Simple drawing stuff...
void PutPixel(uint x, uint y, uchar color);
void Line(uint x1, uint y1, uint x2, uint y2, uchar color);

// Saves current framebuffer to a PCX file.
void SaveFrame(char *fname);

// Load PCX and blit routines...
void UnpackPCX(blitbuf *buf, int xsize, int ysize, uchar *image);
void BlitBuf(uint xpos, uint ypos, blitbuf *buf);

// Bitdepth conversion functions.
void Convert5551to555_Dswap(void *sptr, void *dptr, ulong count);
void Convert5551to565_Dswap(void *sptr, void *dptr, ulong count);
void Convert8888to8888_Dswap(void *sptr, void *dptr, ulong count);
void Convert5551to555_Dswap_DoubleUp(void *sptr, void *dptr, ulong count);
void Convert5551to565_Dswap_DoubleUp(void *sptr, void *dptr, ulong count);
void Convert8888to8888_Dswap_DoubleUp(void *sptr, void *dptr, ulong count);

#endif
