/*
Copyright (C) 2003 - Derek John Evans 

This file is part of Yeti3D Portable Engine

Yeti3D is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

Original Source: 2003 - Derek J. Evans <derek@theteahouse.com.au>
Prepared for public release: 10/24/2003 - Derek J. Evans <derek@theteahouse.com.au>
*/

/*
** Name: Yeti3D
** Desc: Portable GameBoy Advanced 3D Engine
** Auth: Derek J. Evans <derek@theteahouse.com.au>
**
** Copyright (C) 2003 Derek J. Evans. All Rights Reserved.
**
** YY  YY EEEEEE TTTTTT IIIIII 33333  DDDDD
** YY  YY EE       TT     II       33 DD  DD
**  YYYY  EEEE     TT     II     333  DD  DD
**   YY   EE       TT     II       33 DD  DD
**   YY   EEEEEE   TT   IIIIII 33333  DDDDD
*/

#ifndef __VIEWPORTS_H__
#define __VIEWPORTS_H__

#include "../message_id.h"

/******************************************************************************/

/*
** Some Porting Notes:
**
** - The standard pixel format is 5:5:5. There is a function in yeti.c which
**   will copy the viewport to a video display that supports a different pixel
**   format.
** - Define YETI_ROM as const for all ROM based ports.
** - You can patch functions by using the __PATCH?????__ macros.
** - Make sure you define the platform macro in your IDE/make scripts.
** - Viewports larger than 320x240 are not recommended unless you patch the
**   default texture mapper. The standard DDA code is limited to small displays.
**   Look at the OpenGL port for how todo this.
**
*/

/*
** Note: When adding support for Saturn, a lot of stuff have changed.
**  Hence, the platforms I can't test (all, except WIN32 and Saturn)
**  are disabled, and their settings may need to be updated.
**  I try not to keep compatibility with the previous engine, but I don't guarantee it.
*/
///******************************************************************************/
//
//#ifdef __GBA__
//
//#define YETI_RGB555
//#define YETI_LOW_QUALITY_WALLS
//
//#define YETI_ROM const
//
//#define YETI_VIEWPORT_INTERVAL 14
//#define YETI_VIEWPORT_INTERVAL_ERROR 7
//
//#define YETI_VIEWPORT_X1 0
//#define YETI_VIEWPORT_Y1 0
//#define YETI_VIEWPORT_X2 160
//#define YETI_VIEWPORT_Y2 128
//#define YETI_VIEWPORT_WIDTH 160
//#define YETI_VIEWPORT_HEIGHT 128
//
////#define __PATCH_DRAW_POLY__
//
//#define CODE_IN_IWRAM __attribute__ ((section (".iwram"), long_call))
//#define CODE_IN_ROM __attribute__ ((section (".text"), long_call))
//#define IN_IWRAM __attribute__ ((section (".iwram")))
//#define IN_EWRAM __attribute__ ((section (".ewram")))
//
//#define yeti_logout(string, ...)     printf(string, __VA_ARGS__)
//#define yeti_msgout(id, string, ...) printf(string, __VA_ARGS__)
//#endif
//
///******************************************************************************/
//
//#ifdef __SERIES60__
//
//#define YETI_RGB444
//#define YETI_LOW_QUALITY_WALLS
//
//#define YETI_ROM const
//
//#define YETI_VIEWPORT_INTERVAL 35
//#define YETI_VIEWPORT_X1 0
//#define YETI_VIEWPORT_Y1 0
//#define YETI_VIEWPORT_X2 320
//#define YETI_VIEWPORT_Y2 240
//#define YETI_VIEWPORT_WIDTH 320
//#define YETI_VIEWPORT_HEIGHT 240
//
//#define CODE_IN_IWRAM
//#define CODE_IN_ROM
//#define IN_IWRAM
//#define IN_EWRAM
//
//#define yeti_logout(string, ...)     printf(string, __VA_ARGS__)
//#define yeti_msgout(id, string, ...) printf(string, __VA_ARGS__)
//#endif
//
///******************************************************************************/
//
//#ifdef __GP32__
//
//#define YETI_RGB565
//#define YETI_LOW_QUALITY_WALLS
//
//#define YETI_ROM
//
//#define YETI_VIEWPORT_INTERVAL 35
//#define YETI_VIEWPORT_X1 0
//#define YETI_VIEWPORT_Y1 0
//#define YETI_VIEWPORT_X2 320
//#define YETI_VIEWPORT_Y2 240
//#define YETI_VIEWPORT_WIDTH 320
//#define YETI_VIEWPORT_HEIGHT 240
//
//#define CODE_IN_IWRAM
//#define CODE_IN_ROM
//#define IN_IWRAM
//#define IN_EWRAM
//
//#define yeti_logout(string, ...)     printf(string, __VA_ARGS__)
//#define yeti_msgout(id, string, ...) printf(string, __VA_ARGS__)
//#endif
//
///******************************************************************************/
//
//#ifdef __POCKETPC__
//
//#define YETI_RGB565
//#define YETI_LOW_QUALITY_WALLS
//#define YETI_ROM
//
//#define YETI_VIEWPORT_INTERVAL 35
//#define YETI_VIEWPORT_X1 0
//#define YETI_VIEWPORT_Y1 0
//#define YETI_VIEWPORT_X2 320
//#define YETI_VIEWPORT_Y2 240
//#define YETI_VIEWPORT_WIDTH 320
//#define YETI_VIEWPORT_HEIGHT 240
//
//#define CODE_IN_IWRAM
//#define CODE_IN_ROM
//#define IN_IWRAM
//#define IN_EWRAM
//
//#define yeti_logout(string, ...)     printf(string, __VA_ARGS__)
//#define yeti_msgout(id, string, ...) printf(string, __VA_ARGS__)
//#endif
//
///******************************************************************************/
//
//#ifdef __SVGALIB__
//
//#define YETI_RGB555
//#define YETI_ROM
//
//#define YETI_VIEWPORT_INTERVAL 35
//#define YETI_VIEWPORT_X1 0
//#define YETI_VIEWPORT_Y1 0
//#define YETI_VIEWPORT_X2 320
//#define YETI_VIEWPORT_Y2 240
//#define YETI_VIEWPORT_WIDTH 320
//#define YETI_VIEWPORT_HEIGHT 240
//
//#define CODE_IN_IWRAM
//#define CODE_IN_ROM
//#define IN_IWRAM
//#define IN_EWRAM
//
//#define yeti_logout(string, ...)     printf(string, __VA_ARGS__)
//#define yeti_msgout(id, string, ...) printf(string, __VA_ARGS__)
//#endif
//
///******************************************************************************/
//
//#ifdef __GAMECUBE__
//
//#define YETI_RGB565
//#define YETI_ROM
//
//#define YETI_VIEWPORT_INTERVAL 35
//#define YETI_VIEWPORT_X1 0
//#define YETI_VIEWPORT_Y1 0
//#define YETI_VIEWPORT_X2 320
//#define YETI_VIEWPORT_Y2 240
//#define YETI_VIEWPORT_WIDTH 320
//#define YETI_VIEWPORT_HEIGHT 240
//
//#define CODE_IN_IWRAM
//#define CODE_IN_ROM
//#define IN_IWRAM
//#define IN_EWRAM
//
//#define yeti_logout(string, ...)     printf(string, __VA_ARGS__)
//#define yeti_msgout(id, string, ...) printf(string, __VA_ARGS__)
//#endif
//
//
//
///******************************************************************************/
//
//#ifdef __MSDOS__
//
//#define YETI_RGB555
//#define YETI_ROM
//
//#define YETI_VIEWPORT_INTERVAL 35
//#define YETI_VIEWPORT_X1 0
//#define YETI_VIEWPORT_Y1 0
//#define YETI_VIEWPORT_X2 320
//#define YETI_VIEWPORT_Y2 240
//#define YETI_VIEWPORT_WIDTH 320
//#define YETI_VIEWPORT_HEIGHT 240
//
//#define CODE_IN_IWRAM
//#define CODE_IN_ROM
//#define IN_IWRAM
//#define IN_EWRAM
//
//#define yeti_logout(string, ...)     printf(string, __VA_ARGS__)
//#define yeti_msgout(id, string, ...) printf(string, __VA_ARGS__)
//#endif
//
///******************************************************************************/
//
//#ifdef __PSONE__
//
//#define YETI_RGB555
//#define YETI_ROM
//
//#define YETI_VIEWPORT_INTERVAL 3
//#define YETI_VIEWPORT_INTERVAL_ERROR 1
//
//#define YETI_VIEWPORT_X1 0
//#define YETI_VIEWPORT_Y1 0
//#define YETI_VIEWPORT_X2 320
//#define YETI_VIEWPORT_Y2 240
//#define YETI_VIEWPORT_WIDTH 320
//#define YETI_VIEWPORT_HEIGHT 240
//
//#define __PATCH_DRAW_CLIPPED_POLY__
//
//#define CODE_IN_IWRAM
//#define CODE_IN_ROM
//#define IN_IWRAM
//#define IN_EWRAM
//
//#define yeti_logout(string, ...)     printf(string, __VA_ARGS__)
//#define yeti_msgout(id, string, ...) printf(string, __VA_ARGS__)
//#endif
//
///******************************************************************************/
//
//#ifdef __APPLE__
//
//#define YETI_RGB555
//#define YETI_ROM 
//
//#define YETI_VIEWPORT_INTERVAL 35
//#define YETI_VIEWPORT_X1 0
//#define YETI_VIEWPORT_Y1 0
//#define YETI_VIEWPORT_X2 640
//#define YETI_VIEWPORT_Y2 480
//#define YETI_VIEWPORT_WIDTH 640
//#define YETI_VIEWPORT_HEIGHT 480
//#define YETI_VIDEO_LUT
//
//#define CODE_IN_IWRAM
//#define CODE_IN_ROM
//#define IN_IWRAM
//#define IN_EWRAM
//
//#define yeti_logout(string, ...)     printf(string, __VA_ARGS__)
//#define yeti_msgout(id, string, ...) printf(string, __VA_ARGS__)
//#endif
//
///******************************************************************************/
//#ifdef _arch_dreamcast
//
//#define YETI_RGB555
//#define YETI_ROM 
//
//#define YETI_VIEWPORT_INTERVAL 35
//#define YETI_VIEWPORT_X1 0
//#define YETI_VIEWPORT_Y1 0
//#define YETI_VIEWPORT_X2 320
//#define YETI_VIEWPORT_Y2 240
//#define YETI_VIEWPORT_WIDTH 320
//#define YETI_VIEWPORT_HEIGHT 240
//#define YETI_VIDEO_LUT
//
//#define CODE_IN_IWRAM
//#define CODE_IN_ROM
//#define IN_IWRAM
//#define IN_EWRAM
//
//#define yeti_logout(string, ...)     printf(string, __VA_ARGS__)
//#define yeti_msgout(id, string, ...) printf(string, __VA_ARGS__)
//#endif
//
///******************************************************************************/

#ifdef __WIN32__

#ifndef __YETI_EDITOR__
/*--- WINTEST ---*/

    /* Sega Saturn display library */
#   include "shared.h"
    /* Use VDP logger instead of software renderer. */
#   define __PATCH_DRAW_TEXTURE__

#else
/*--- Yeti editor ---*/

#endif


#define YETI_RGB555
#define YETI_ROM 

#define YETI_LOW_QUALITY_WALLS

#define YETI_VIEWPORT_INTERVAL 35
#define YETI_VIEWPORT_X1 0
#define YETI_VIEWPORT_Y1 0
#define YETI_VIEWPORT_X2 320
#define YETI_VIEWPORT_Y2 224
#define YETI_VIEWPORT_WIDTH 320
#define YETI_VIEWPORT_HEIGHT 224

#define YETI_VIDEO_LUT
#define CODE_IN_IWRAM
#define CODE_IN_ROM
#define IN_IWRAM
#define IN_EWRAM

//#ifdef __YETI_EDITOR__
///* Tweak to avoid the entity */
//#define __YETI_NOENTITY__
//#endif
/* If not defined, draw entity as 3D model */
//#define YETI_SPRITE_ENTITY

/* Endianness: use my PC as a reference. */
#define SWAP_SHORT(_VAL_) (_VAL_)
#define SWAP_LONG(_VAL_)  (_VAL_)


/**
 * Texture pixel format:
 * Use paletted textures (this is the format used in the original engine).
 * Some restrictions:
 *  Fixed texture size (64x64): texture data are resized on sartup.
 *  Paletted colors, so that they need to be converted from RGB555 on startup.
 *   (The RGB555->256 colors palette provided in original yeti3d engine is used)
**/
#define YETI_TEX_PALETTE


/* Define log functions ... Dirty kludge (partly due to Borland C++ Builder), but it works ... */
#define yeti_logout     MyLog
#define yeti_msgout     MyMsgOut
#endif



/******************************************************************************/
#ifdef __SEGA_SATURN__

/* Sega Saturn display library */
#include "../shared.h"

/* Use VDP instead of software renderer. */
#define __PATCH_DRAW_TEXTURE__
/* Remove software renderer code, which reduces binary size from ~20KB. */
#define __PATCH_DRAW_SPRITE__
#define __PATCH_DRAW_FILLED_POLY__
#define __PATCH_DRAW_POLY__
#define __PATCH_DRAW_CLIPPED_POLY__
#define __PATCH_MD2_TMAP__

/* Don't use texture coordinates, because not supported by HW. */
#define YETI_NO_TEXUV
/* Don't use software framebuffer, because it would too sloooow ! */
#define YETI_NO_FRAMEBUFFER
/* Don't use lighting (saves 32KB). */
#define YETI_NO_LUA

/* Specifies that we will use only quads in the
 * drawing engine. (thus, save memory and maybe speed)
 */
#define YETI_QUAD_ONLY


/**
 * Texture pixel format:
 * Use RGB555 textures, i.e. texture data as-is.
 * (this format is a little better than palette format, and
 *  supported by Saturn HW, so let's use it !)
**/
#define YETI_RGB555

#define YETI_ROM 

/* Use only one texture per wall. Fast ... but ugly. */
#define YETI_LOW_QUALITY_WALLS

#define YETI_VIEWPORT_INTERVAL 35
#define YETI_VIEWPORT_X1 0
#define YETI_VIEWPORT_Y1 0
#define YETI_VIEWPORT_X2 320
#define YETI_VIEWPORT_Y2 224
#define YETI_VIEWPORT_WIDTH 320
#define YETI_VIEWPORT_HEIGHT 224

//#define YETI_VIDEO_LUT
#define CODE_IN_IWRAM
#define CODE_IN_ROM
#define IN_IWRAM
#define IN_EWRAM

///* Tweak to avoid the entity */
#define __YETI_NOENTITY__
/* If not defined, draw entity as 3D model */
//#define YETI_SPRITE_ENTITY

/* Endianness: convert x86 data to Saturn's big-endian format. */
#define SWAP_SHORT(_VAL_) ( (((_VAL_) & 0x00FF) << 8) | (((_VAL_) & 0xFF00) >> 8) )
#define SWAP_LONG(_VAL_) ( (((_VAL_) << 24) & 0xFF000000) | (((_VAL_) << 8) & 0x00FF0000) | (((_VAL_) >> 8) & 0x0000FF00) | (((_VAL_) >> 24) & 0x000000FF) )



/* Define log functions. */
#if 0
// For time-accurate debug
#   define yeti_logout(string, ...)     scd_logout(string, __VA_ARGS__);     scd_logflush()
#   define yeti_msgout(id, string, ...) scd_msgout(id, string, __VA_ARGS__); scd_logflush()
#else
// For "casual" debug
#   define yeti_logout(string, ...)     scd_logout(string, __VA_ARGS__)
#   define yeti_msgout(id, string, ...) scd_msgout(id, string, __VA_ARGS__)
#endif // DBG

#endif




/******************************************************************************/
// Stuff for debug (windows/Saturn shared)
#define YETI_DEFPOS_X 1664
#define YETI_DEFPOS_Y 9447
#define YETI_DEFPOS_Z 400
#define YETI_DEFPOS_T 1493490
#define YETI_DEFPOS_R 0
#define YETI_DEFPOS_P 0

/******************************************************************************/
#endif

